From 0fcc366a355ba0fae6c24173bae80cc714e6eb0a Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Mon, 8 Jan 2024 01:28:50 -0500 Subject: [PATCH] Hooked up controls and settings buttons in launcher --- assets/config_menu.rml | 2 +- assets/launcher.rml | 4 ++-- include/recomp_ui.h | 10 ++++++++++ src/ui/ui_launcher.cpp | 11 +++++++++++ src/ui/ui_renderer.cpp | 26 ++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/assets/config_menu.rml b/assets/config_menu.rml index e7c78f7..6ae1090 100644 --- a/assets/config_menu.rml +++ b/assets/config_menu.rml @@ -31,7 +31,7 @@
- +
Graphics
diff --git a/assets/launcher.rml b/assets/launcher.rml index 75ed030..9b1c93b 100644 --- a/assets/launcher.rml +++ b/assets/launcher.rml @@ -36,11 +36,11 @@ - - diff --git a/include/recomp_ui.h b/include/recomp_ui.h index 49a58e7..e023db3 100644 --- a/include/recomp_ui.h +++ b/include/recomp_ui.h @@ -42,6 +42,16 @@ namespace recomp { }; void set_current_menu(Menu menu); + + enum class ConfigSubmenu { + Graphics, + Controls, + Audio, + Count + }; + + void set_config_submenu(ConfigSubmenu submenu); + void destroy_ui(); void apply_color_hack(); } diff --git a/src/ui/ui_launcher.cpp b/src/ui/ui_launcher.cpp index f690479..8787353 100644 --- a/src/ui/ui_launcher.cpp +++ b/src/ui/ui_launcher.cpp @@ -17,6 +17,17 @@ public: recomp::register_event(listener, "start_game", [](const std::string& param, Rml::Event& event) { ultramodern::start_game(0); + recomp::set_current_menu(recomp::Menu::None); + } + ); + recomp::register_event(listener, "open_controls", + [](const std::string& param, Rml::Event& event) { + recomp::set_current_menu(recomp::Menu::Config); + recomp::set_config_submenu(recomp::ConfigSubmenu::Controls); + } + ); + recomp::register_event(listener, "open_settings", + [](const std::string& param, Rml::Event& event) { recomp::set_current_menu(recomp::Menu::Config); } ); diff --git a/src/ui/ui_renderer.cpp b/src/ui/ui_renderer.cpp index 6015edb..5d89bcb 100644 --- a/src/ui/ui_renderer.cpp +++ b/src/ui/ui_renderer.cpp @@ -665,6 +665,18 @@ struct { } } + void swap_config_menu(recomp::ConfigSubmenu submenu) { + if (current_document != nullptr) { + Rml::Element* config_tabset_base = current_document->GetElementById("config_tabset"); + if (config_tabset_base != nullptr) { + Rml::ElementTabSet* config_tabset = rmlui_dynamic_cast(config_tabset_base); + if (config_tabset != nullptr) { + config_tabset->SetActiveTab(static_cast(submenu)); + } + } + } + } + void load_documents() { if (!documents.empty()) { Rml::Factory::RegisterEventListenerInstancer(nullptr); @@ -703,6 +715,9 @@ struct { } void update_focus(bool mouse_moved) { + if (current_document == nullptr) { + return; + } Rml::Element* focused = current_document->GetFocusLeafNode(); // If there was mouse motion, get the current hovered element (or its target if it points to one) and focus that if applicable. @@ -817,6 +832,7 @@ bool recomp::try_deque_event(SDL_Event& out) { } std::atomic open_menu = recomp::Menu::Launcher; +std::atomic open_config_submenu = recomp::ConfigSubmenu::Count; void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderTexture* swap_chain_texture) { int num_keys; @@ -839,6 +855,12 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderTexture* swap_ UIContext.rml.swap_document(cur_menu); } + recomp::ConfigSubmenu config_submenu = open_config_submenu.load(); + if (config_submenu != recomp::ConfigSubmenu::Count) { + UIContext.rml.swap_config_menu(config_submenu); + open_config_submenu.store(recomp::ConfigSubmenu::Count); + } + prev_menu = cur_menu; SDL_Event cur_event{}; @@ -896,6 +918,10 @@ void recomp::set_current_menu(Menu menu) { open_menu.store(menu); } +void recomp::set_config_submenu(recomp::ConfigSubmenu submenu) { + open_config_submenu.store(submenu); +} + void recomp::destroy_ui() { Rml::Shutdown(); UIContext.rml.unload();