[jak2] Fix "Select controller" (#3191)

Co-authored-by: Martino Fontana <tinozzo123@gmail.com>
This commit is contained in:
SuperSamus
2023-12-02 21:20:26 +01:00
committed by GitHub
parent dfa6622544
commit 37069e2f8e
5 changed files with 23 additions and 6 deletions
+10 -2
View File
@@ -664,7 +664,14 @@ u64 pc_get_controller_count() {
return 0;
}
void pc_get_controller(u32 controller_id, u32 port) {
u64 pc_get_controller_index(u32 port) {
if (Display::GetMainDisplay()) {
return Display::GetMainDisplay()->get_input_manager()->get_controller_index(port);
}
return 0;
}
void pc_set_controller(u32 controller_id, u32 port) {
if (Display::GetMainDisplay()) {
Display::GetMainDisplay()->get_input_manager()->set_controller_for_port(controller_id, port);
}
@@ -913,7 +920,8 @@ void init_common_pc_port_functions(
make_func_symbol_func("pc-get-controller-name", (void*)pc_get_controller_name);
make_func_symbol_func("pc-get-current-bind", (void*)pc_get_current_bind);
make_func_symbol_func("pc-get-controller-count", (void*)pc_get_controller_count);
make_func_symbol_func("pc-set-controller!", (void*)pc_get_controller);
make_func_symbol_func("pc-get-controller-index", (void*)pc_get_controller_index);
make_func_symbol_func("pc-set-controller!", (void*)pc_set_controller);
make_func_symbol_func("pc-set-keyboard-enabled!", (void*)pc_set_keyboard_enabled);
make_func_symbol_func("pc-set-mouse-options!", (void*)pc_set_mouse_options);
make_func_symbol_func("pc-set-mouse-camera-sens!", (void*)pc_set_mouse_camera_sens);
+7
View File
@@ -323,6 +323,13 @@ std::string InputManager::get_current_bind(const int port,
return binding_info.front().host_name;
}
int InputManager::get_controller_index(const int port) {
if (m_controller_port_mapping.find(port) == m_controller_port_mapping.end()) {
return 0;
}
return m_controller_port_mapping.at(port);
}
void InputManager::set_controller_for_port(const int controller_id, const int port) {
if (controller_id < (int)m_available_controllers.size()) {
// Reset inputs as this device won't be able to be read from again!
+1
View File
@@ -86,6 +86,7 @@ class InputManager {
const bool buttons,
const int input_idx,
const bool analog_for_minimum);
int get_controller_index(const int port);
void set_controller_for_port(const int controller_id, const int port);
bool controller_has_led(const int port);
bool controller_has_rumble(const int port);
+1
View File
@@ -181,6 +181,7 @@
(define-extern pc-waiting-for-bind? (function symbol))
(define-extern pc-set-waiting-for-bind! (function int symbol symbol int none))
(define-extern pc-stop-waiting-for-bind! (function none))
(define-extern pc-get-controller-index (function int int))
(define-extern pc-set-controller! (function int int none))
(define-extern pc-set-keyboard-enabled! (function symbol none))
(define-extern pc-set-mouse-options! (function symbol symbol symbol none))
@@ -134,8 +134,8 @@ This gives us more freedom to write code how we want.
:get-item-label-fn (lambda ((index int))
(pc-get-controller-name index *pc-cpp-temp-string*)
*pc-cpp-temp-string*)
:get-item-index-fn (lambda () 0)
:on-confirm (lambda ((index int)) (pc-set-controller! 0 index)))
:get-item-index-fn (lambda () (pc-get-controller-index 0))
:on-confirm (lambda ((index int)) (pc-set-controller! index 0)))
(new 'static 'menu-generic-boolean-option
:name (text-id progress-vibration)
:should-disable? (lambda () (not (pc-current-controller-has-rumble?)))
@@ -391,8 +391,8 @@ This gives us more freedom to write code how we want.
:get-item-label-fn (lambda ((index int))
(pc-get-controller-name index *pc-cpp-temp-string*)
*pc-cpp-temp-string*)
:get-item-index-fn (lambda () 0)
:on-confirm (lambda ((index int)) (pc-set-controller! 0 index)))
:get-item-index-fn (lambda () (pc-get-controller-index 0))
:on-confirm (lambda ((index int)) (pc-set-controller! index 0)))
(new 'static 'menu-generic-boolean-option
:name (text-id progress-vibration)
:should-disable? (lambda () (not (pc-current-controller-has-rumble?)))