Allow configuring menu accept/apply buttons (#385)

* feat: allow configuring menu accept/apply buttons

* Update assets/icons/Reset.svg

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

---------

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>
This commit is contained in:
briaguya
2024-07-06 03:19:31 +02:00
committed by GitHub
parent 79fc56f1fd
commit 19d2e38499
9 changed files with 160 additions and 38 deletions
+39 -4
View File
@@ -163,6 +163,10 @@ static bool cont_active = true;
static recomp::InputDevice cur_device = recomp::InputDevice::Controller;
int recomp::get_scanned_input_index() {
return scanned_input_index;
}
void recomp::finish_scanning_input(recomp::InputField scanned_field) {
recomp::set_input_binding(static_cast<recomp::GameInput>(scanned_input_index), scanned_binding_index, cur_device, scanned_field);
scanned_input_index = -1;
@@ -170,6 +174,9 @@ void recomp::finish_scanning_input(recomp::InputField scanned_field) {
controls_model_handle.DirtyVariable("inputs");
controls_model_handle.DirtyVariable("active_binding_input");
controls_model_handle.DirtyVariable("active_binding_slot");
nav_help_model_handle.DirtyVariable("nav_help__accept");
nav_help_model_handle.DirtyVariable("nav_help__exit");
graphics_model_handle.DirtyVariable("gfx_help__apply");
}
void recomp::cancel_scanning_input() {
@@ -179,6 +186,9 @@ void recomp::cancel_scanning_input() {
controls_model_handle.DirtyVariable("inputs");
controls_model_handle.DirtyVariable("active_binding_input");
controls_model_handle.DirtyVariable("active_binding_slot");
nav_help_model_handle.DirtyVariable("nav_help__accept");
nav_help_model_handle.DirtyVariable("nav_help__exit");
graphics_model_handle.DirtyVariable("gfx_help__apply");
}
void recomp::config_menu_set_cont_or_kb(bool cont_interacted) {
@@ -687,9 +697,17 @@ public:
constructor.BindFunc("gfx_help__apply", [](Rml::Variant& out) {
if (cont_active) {
out = PF_GAMEPAD_X " " PF_GAMEPAD_START;
out = \
(recomp::get_input_binding(recomp::GameInput::APPLY_MENU, 0, recomp::InputDevice::Controller).to_string() != "" ?
" " + recomp::get_input_binding(recomp::GameInput::APPLY_MENU, 0, recomp::InputDevice::Controller).to_string() :
""
) + \
(recomp::get_input_binding(recomp::GameInput::APPLY_MENU, 1, recomp::InputDevice::Controller).to_string() != "" ?
" " + recomp::get_input_binding(recomp::GameInput::APPLY_MENU, 1, recomp::InputDevice::Controller).to_string() :
""
);
} else {
out = PF_KEYBOARD_F;
out = " " PF_KEYBOARD_F;
}
});
@@ -735,6 +753,9 @@ public:
zelda64::reset_kb_input_bindings();
}
model_handle.DirtyAllVariables();
nav_help_model_handle.DirtyVariable("nav_help__accept");
nav_help_model_handle.DirtyVariable("nav_help__exit");
graphics_model_handle.DirtyVariable("gfx_help__apply");
});
constructor.BindEventCallback("clear_input_bindings",
@@ -744,6 +765,16 @@ public:
recomp::set_input_binding(input, binding_index, cur_device, recomp::InputField{});
}
model_handle.DirtyVariable("inputs");
graphics_model_handle.DirtyVariable("gfx_help__apply");
});
constructor.BindEventCallback("reset_single_input_binding_to_default",
[](Rml::DataModelHandle model_handle, Rml::Event& event, const Rml::VariantList& inputs) {
recomp::GameInput input = static_cast<recomp::GameInput>(inputs.at(0).Get<size_t>());
zelda64::reset_single_input_binding(cur_device, input);
model_handle.DirtyVariable("inputs");
nav_help_model_handle.DirtyVariable("nav_help__accept");
nav_help_model_handle.DirtyVariable("nav_help__exit");
});
constructor.BindEventCallback("set_input_row_focus",
@@ -868,7 +899,9 @@ public:
constructor.BindFunc("nav_help__accept", [](Rml::Variant& out) {
if (cont_active) {
out = PF_GAMEPAD_A;
out = \
recomp::get_input_binding(recomp::GameInput::ACCEPT_MENU, 0, recomp::InputDevice::Controller).to_string() + \
recomp::get_input_binding(recomp::GameInput::ACCEPT_MENU, 1, recomp::InputDevice::Controller).to_string();
} else {
out = PF_KEYBOARD_ENTER;
}
@@ -876,7 +909,9 @@ public:
constructor.BindFunc("nav_help__exit", [](Rml::Variant& out) {
if (cont_active) {
out = PF_XBOX_VIEW;
out = \
recomp::get_input_binding(recomp::GameInput::TOGGLE_MENU, 0, recomp::InputDevice::Controller).to_string() + \
recomp::get_input_binding(recomp::GameInput::TOGGLE_MENU, 1, recomp::InputDevice::Controller).to_string();
} else {
out = PF_KEYBOARD_ESCAPE;
}
+27 -14
View File
@@ -1183,6 +1183,33 @@ std::atomic<recompui::Menu> open_menu = recompui::Menu::Launcher;
std::atomic<recompui::ConfigSubmenu> open_config_submenu = recompui::ConfigSubmenu::Count;
int cont_button_to_key(SDL_ControllerButtonEvent& button) {
// Configurable accept button in menu
auto menuAcceptBinding0 = recomp::get_input_binding(recomp::GameInput::ACCEPT_MENU, 0, recomp::InputDevice::Controller);
auto menuAcceptBinding1 = recomp::get_input_binding(recomp::GameInput::ACCEPT_MENU, 1, recomp::InputDevice::Controller);
// note - magic number: 0 is InputType::None
if ((menuAcceptBinding0.input_type != 0 && button.button == menuAcceptBinding0.input_id) ||
(menuAcceptBinding1.input_type != 0 && button.button == menuAcceptBinding1.input_id)) {
return SDLK_RETURN;
}
// Configurable apply button in menu
auto menuApplyBinding0 = recomp::get_input_binding(recomp::GameInput::APPLY_MENU, 0, recomp::InputDevice::Controller);
auto menuApplyBinding1 = recomp::get_input_binding(recomp::GameInput::APPLY_MENU, 1, recomp::InputDevice::Controller);
// note - magic number: 0 is InputType::None
if ((menuApplyBinding0.input_type != 0 && button.button == menuApplyBinding0.input_id) ||
(menuApplyBinding1.input_type != 0 && button.button == menuApplyBinding1.input_id)) {
return SDLK_f;
}
// Allows closing the menu
auto menuToggleBinding0 = recomp::get_input_binding(recomp::GameInput::TOGGLE_MENU, 0, recomp::InputDevice::Controller);
auto menuToggleBinding1 = recomp::get_input_binding(recomp::GameInput::TOGGLE_MENU, 1, recomp::InputDevice::Controller);
// note - magic number: 0 is InputType::None
if ((menuToggleBinding0.input_type != 0 && button.button == menuToggleBinding0.input_id) ||
(menuToggleBinding1.input_type != 0 && button.button == menuToggleBinding1.input_id)) {
return SDLK_ESCAPE;
}
switch (button.button) {
case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_DPAD_UP:
return SDLK_UP;
@@ -1192,20 +1219,6 @@ int cont_button_to_key(SDL_ControllerButtonEvent& button) {
return SDLK_LEFT;
case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
return SDLK_RIGHT;
case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_A:
return SDLK_RETURN;
case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_X:
case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_START:
return SDLK_f;
}
// Allows closing the menu
auto menuToggleBinding0 = recomp::get_input_binding(recomp::GameInput::TOGGLE_MENU, 0, recomp::InputDevice::Controller);
auto menuToggleBinding1 = recomp::get_input_binding(recomp::GameInput::TOGGLE_MENU, 1, recomp::InputDevice::Controller);
// note - magic number: 0 is InputType::None
if ((menuToggleBinding0.input_type != 0 && button.button == menuToggleBinding0.input_id) ||
(menuToggleBinding1.input_type != 0 && button.button == menuToggleBinding1.input_id)) {
return SDLK_ESCAPE;
}
return 0;