From 5ee7eaed1fee71b0afa9f5639a8d6c13f98b4258 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Mon, 8 Jan 2024 03:38:05 -0500 Subject: [PATCH] Split default input mappings by device, disabled input while menu is open, made config menu open with escape/select, made config menu close with escape --- include/recomp_input.h | 5 ++- include/recomp_ui.h | 1 + src/game/controls.cpp | 91 ++++++++++++++++++++++++++++++------------ src/game/input.cpp | 82 ++++++++++++++++++++++++++++--------- src/ui/ui_config.cpp | 14 +++++++ src/ui/ui_renderer.cpp | 28 ++++++++++++- 6 files changed, 174 insertions(+), 47 deletions(-) diff --git a/include/recomp_input.h b/include/recomp_input.h index 266bffd..3e9af3f 100644 --- a/include/recomp_input.h +++ b/include/recomp_input.h @@ -43,10 +43,13 @@ namespace recomp { std::vector analog_down; }; - extern const DefaultN64Mappings default_n64_mappings; + extern const DefaultN64Mappings default_n64_keyboard_mappings; + extern const DefaultN64Mappings default_n64_controller_mappings; void get_n64_input(uint16_t* buttons_out, float* x_out, float* y_out); void handle_events(); + + bool game_input_disabled(); } #endif diff --git a/include/recomp_ui.h b/include/recomp_ui.h index e023db3..f4d99c4 100644 --- a/include/recomp_ui.h +++ b/include/recomp_ui.h @@ -42,6 +42,7 @@ namespace recomp { }; void set_current_menu(Menu menu); + Menu get_current_menu(); enum class ConfigSubmenu { Graphics, diff --git a/src/game/controls.cpp b/src/game/controls.cpp index ce91d9b..2380dbf 100644 --- a/src/game/controls.cpp +++ b/src/game/controls.cpp @@ -42,24 +42,44 @@ void recomp::get_n64_input(uint16_t* buttons_out, float* x_out, float* y_out) { float cur_x = 0.0f; float cur_y = 0.0f; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.a) ? N64Inputs::A : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.b) ? N64Inputs::B : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.l) ? N64Inputs::L : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.r) ? N64Inputs::R : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.z) ? N64Inputs::Z : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.start) ? N64Inputs::START : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_left) ? N64Inputs::C_LEFT : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_right) ? N64Inputs::C_RIGHT : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_up) ? N64Inputs::C_UP : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_down) ? N64Inputs::C_DOWN : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0; + if (!recomp::game_input_disabled()) { + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.a) ? N64Inputs::A : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.b) ? N64Inputs::B : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.l) ? N64Inputs::L : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.r) ? N64Inputs::R : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.z) ? N64Inputs::Z : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.start) ? N64Inputs::START : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_left) ? N64Inputs::C_LEFT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_right) ? N64Inputs::C_RIGHT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_up) ? N64Inputs::C_UP : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_down) ? N64Inputs::C_DOWN : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0; + + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.a) ? N64Inputs::A : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.b) ? N64Inputs::B : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.l) ? N64Inputs::L : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.r) ? N64Inputs::R : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.z) ? N64Inputs::Z : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.start) ? N64Inputs::START : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_left) ? N64Inputs::C_LEFT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_right) ? N64Inputs::C_RIGHT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_up) ? N64Inputs::C_UP : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_down) ? N64Inputs::C_DOWN : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0; + + cur_x = recomp::get_input_analog(recomp::default_n64_keyboard_mappings.analog_right) - recomp::get_input_analog(recomp::default_n64_keyboard_mappings.analog_left); + cur_y = recomp::get_input_analog(recomp::default_n64_keyboard_mappings.analog_up) - recomp::get_input_analog(recomp::default_n64_keyboard_mappings.analog_down); + cur_x += recomp::get_input_analog(recomp::default_n64_controller_mappings.analog_right) - recomp::get_input_analog(recomp::default_n64_controller_mappings.analog_left); + cur_y += recomp::get_input_analog(recomp::default_n64_controller_mappings.analog_up) - recomp::get_input_analog(recomp::default_n64_controller_mappings.analog_down); + } *buttons_out = cur_buttons; - cur_x = recomp::get_input_analog(recomp::default_n64_mappings.analog_right) - recomp::get_input_analog(recomp::default_n64_mappings.analog_left); - cur_y = recomp::get_input_analog(recomp::default_n64_mappings.analog_up) - recomp::get_input_analog(recomp::default_n64_mappings.analog_down); *x_out = cur_x; *y_out = cur_y; } @@ -69,14 +89,25 @@ extern "C" void recomp_get_item_inputs(uint8_t* rdram, recomp_context* ctx) { uint32_t cur_buttons = 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.b) ? N64Inputs::B : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_left) ? N64Inputs::C_LEFT : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_right) ? N64Inputs::C_RIGHT : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_down) ? N64Inputs::C_DOWN : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0; - cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0; + if (!recomp::game_input_disabled()) { + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.b) ? N64Inputs::B : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_left) ? N64Inputs::C_LEFT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_right) ? N64Inputs::C_RIGHT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_down) ? N64Inputs::C_DOWN : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0; + + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.b) ? N64Inputs::B : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_left) ? N64Inputs::C_LEFT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_right) ? N64Inputs::C_RIGHT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_down) ? N64Inputs::C_DOWN : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0; + cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0; + } *buttons_out = cur_buttons; } @@ -108,8 +139,16 @@ extern "C" void recomp_get_camera_inputs(uint8_t* rdram, recomp_context* ctx) { float* x_out = _arg<0, float*>(rdram, ctx); float* y_out = _arg<1, float*>(rdram, ctx); - float x_val = recomp::get_input_analog(recomp::default_n64_mappings.c_right) - recomp::get_input_analog(recomp::default_n64_mappings.c_left); - float y_val = recomp::get_input_analog(recomp::default_n64_mappings.c_up) - recomp::get_input_analog(recomp::default_n64_mappings.c_down); + float x_val = 0; + float y_val = 0; + + if (!recomp::game_input_disabled()) { + x_val += recomp::get_input_analog(recomp::default_n64_keyboard_mappings.c_right) - recomp::get_input_analog(recomp::default_n64_keyboard_mappings.c_left); + y_val += recomp::get_input_analog(recomp::default_n64_keyboard_mappings.c_up) - recomp::get_input_analog(recomp::default_n64_keyboard_mappings.c_down); + + x_val += recomp::get_input_analog(recomp::default_n64_controller_mappings.c_right) - recomp::get_input_analog(recomp::default_n64_controller_mappings.c_left); + y_val += recomp::get_input_analog(recomp::default_n64_controller_mappings.c_up) - recomp::get_input_analog(recomp::default_n64_controller_mappings.c_down); + } *x_out = x_val; *y_out = y_val; diff --git a/src/game/input.cpp b/src/game/input.cpp index 55df084..e37b24d 100644 --- a/src/game/input.cpp +++ b/src/game/input.cpp @@ -83,80 +83,119 @@ constexpr SDL_GameControllerButton SDL_CONTROLLER_BUTTON_EAST = SDL_CONTROLLER_B constexpr SDL_GameControllerButton SDL_CONTROLLER_BUTTON_WEST = SDL_CONTROLLER_BUTTON_X; constexpr SDL_GameControllerButton SDL_CONTROLLER_BUTTON_NORTH = SDL_CONTROLLER_BUTTON_Y; -const recomp::DefaultN64Mappings recomp::default_n64_mappings = { +const recomp::DefaultN64Mappings recomp::default_n64_keyboard_mappings = { + .a = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_SPACE} + }, + .b = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_LSHIFT} + }, + .l = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_E} + }, + .r = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_R} + }, + .z = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_Q} + }, + .start = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_RETURN} + }, + .c_left = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_LEFT} + }, + .c_right = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_RIGHT} + }, + .c_up = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_UP} + }, + .c_down = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_DOWN} + }, + .dpad_left = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_J} + }, + .dpad_right = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_L} + }, + .dpad_up = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_I} + }, + .dpad_down = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_K} + }, + .analog_left = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_A} + }, + .analog_right = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_D} + }, + .analog_up = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_W} + }, + .analog_down = { + {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_S} + }, +}; + +const recomp::DefaultN64Mappings recomp::default_n64_controller_mappings = { .a = { {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_SOUTH}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_SPACE} }, .b = { {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_EAST}, {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_WEST}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_LSHIFT} }, .l = { {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_E} }, .r = { {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_TRIGGERRIGHT + 1}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_R} }, .z = { {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_TRIGGERLEFT + 1}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_Q} }, .start = { {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_START}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_RETURN} }, .c_left = { {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = -(SDL_CONTROLLER_AXIS_RIGHTX + 1)}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_LEFT} }, .c_right = { {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_RIGHTX + 1}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_RIGHT} }, .c_up = { {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = -(SDL_CONTROLLER_AXIS_RIGHTY + 1)}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_UP} }, .c_down = { {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_RIGHTY + 1}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_DOWN} }, .dpad_left = { {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_DPAD_LEFT}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_J} }, .dpad_right = { {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_L} }, .dpad_up = { {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_DPAD_UP}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_I} }, .dpad_down = { {.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_DPAD_DOWN}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_K} }, .analog_left = { {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = -(SDL_CONTROLLER_AXIS_LEFTX + 1)}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_A} }, .analog_right = { {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_LEFTX + 1}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_D} }, .analog_up = { {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = -(SDL_CONTROLLER_AXIS_LEFTY + 1)}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_W} }, .analog_down = { {.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_LEFTY + 1}, - {.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_S} }, }; @@ -272,3 +311,8 @@ bool recomp::get_input_digital(const std::span fields) } return ret; } + +bool recomp::game_input_disabled() { + // Disable input if any menu is open. + return recomp::get_current_menu() != recomp::Menu::None; +} diff --git a/src/ui/ui_config.cpp b/src/ui/ui_config.cpp index 276e17d..a544233 100644 --- a/src/ui/ui_config.cpp +++ b/src/ui/ui_config.cpp @@ -1,5 +1,6 @@ #include "recomp_ui.h" #include "../../ultramodern/config.hpp" +#include "../../ultramodern/ultramodern.hpp" #include "RmlUi/Core.h" ultramodern::GraphicsConfig cur_options; @@ -67,6 +68,19 @@ public: options_handle.DirtyVariable("options_changed"); update_graphics_config(new_options); }); + recomp::register_event(listener, "config_keydown", + [](const std::string& param, Rml::Event& event) { + if (event.GetId() == Rml::EventId::Keydown) { + if (event.GetParameter("key_identifier", Rml::Input::KeyIdentifier::KI_UNKNOWN) == Rml::Input::KeyIdentifier::KI_ESCAPE) { + if (ultramodern::is_game_started()) { + recomp::set_current_menu(recomp::Menu::None); + } + else { + recomp::set_current_menu(recomp::Menu::Launcher); + } + } + } + }); } void make_bindings(Rml::Context* context) override { Rml::DataModelConstructor constructor = context->CreateDataModel("graphics_model"); diff --git a/src/ui/ui_renderer.cpp b/src/ui/ui_renderer.cpp index 5d89bcb..13036f2 100644 --- a/src/ui/ui_renderer.cpp +++ b/src/ui/ui_renderer.cpp @@ -602,7 +602,6 @@ namespace recomp { std::unordered_map listener_map_; public: Rml::EventListener* InstanceEventListener(const Rml::String& value, Rml::Element* element) override { - printf("Instancing event listener for %s\n", value.c_str()); // Check if a listener has already been made for the full event string and return it if so. auto find_listener_it = listener_map_.find(value); if (find_listener_it != listener_map_.end()) { @@ -878,6 +877,29 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderTexture* swap_ break; } } + // If no menu is open and the game has been started and either the escape key or select button are pressed, open the config menu. + if (cur_menu == recomp::Menu::None && ultramodern::is_game_started()) { + bool open_config = false; + + switch (cur_event.type) { + case SDL_EventType::SDL_KEYDOWN: + if (cur_event.key.keysym.scancode == SDL_Scancode::SDL_SCANCODE_ESCAPE) { + open_config = true; + } + break; + case SDL_EventType::SDL_CONTROLLERBUTTONDOWN: + if (cur_event.cbutton.button == SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_BACK) { + open_config = true; + } + break; + } + + if (open_config) { + cur_menu = recomp::Menu::Config; + open_menu.store(recomp::Menu::Config); + UIContext.rml.swap_document(cur_menu); + } + } } UIContext.rml.update_focus(mouse_moved); @@ -926,3 +948,7 @@ void recomp::destroy_ui() { Rml::Shutdown(); UIContext.rml.unload(); } + +recomp::Menu recomp::get_current_menu() { + return open_menu.load(); +}