From 8853fc0d7b77106bd51bfd29799dfd603fc2ec1c Mon Sep 17 00:00:00 2001 From: thecozies <79979276+thecozies@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:02:03 -0500 Subject: [PATCH] swap nav icons between kb and cont --- assets/config_menu.rml | 7 ++++--- include/recomp_input.h | 1 + src/ui/ui_config.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++ src/ui/ui_renderer.cpp | 12 ++++++++++- 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/assets/config_menu.rml b/assets/config_menu.rml index a0d81bb..eac2c66 100644 --- a/assets/config_menu.rml +++ b/assets/config_menu.rml @@ -85,18 +85,19 @@
diff --git a/include/recomp_input.h b/include/recomp_input.h index fbbbef7..ad9aced 100644 --- a/include/recomp_input.h +++ b/include/recomp_input.h @@ -77,6 +77,7 @@ namespace recomp { void stop_scanning_input(); void finish_scanning_input(InputField scanned_field); void cancel_scanning_input(); + void set_cont_or_kb(bool cont_interacted); InputField get_scanned_input(); struct DefaultN64Mappings { diff --git a/src/ui/ui_config.cpp b/src/ui/ui_config.cpp index e623bc4..27b9b01 100644 --- a/src/ui/ui_config.cpp +++ b/src/ui/ui_config.cpp @@ -3,11 +3,13 @@ #include "recomp_sound.h" #include "recomp_config.h" #include "recomp_debug.h" +#include "promptfont.h" #include "../../ultramodern/config.hpp" #include "../../ultramodern/ultramodern.hpp" #include "RmlUi/Core.h" ultramodern::GraphicsConfig new_options; +Rml::DataModelHandle nav_help_model_handle; Rml::DataModelHandle general_model_handle; Rml::DataModelHandle controls_model_handle; Rml::DataModelHandle graphics_model_handle; @@ -63,6 +65,7 @@ void bind_atomic(Rml::DataModelConstructor& constructor, Rml::DataModelHandle ha static int scanned_binding_index = -1; static int scanned_input_index = -1; static int focused_input_index = -1; +static bool cont_active = true; static recomp::InputDevice cur_device = recomp::InputDevice::Controller; @@ -84,6 +87,15 @@ void recomp::cancel_scanning_input() { controls_model_handle.DirtyVariable("active_binding_slot"); } +void recomp::set_cont_or_kb(bool cont_interacted) { + if (nav_help_model_handle && cont_active != cont_interacted) { + cont_active = cont_interacted; + nav_help_model_handle.DirtyVariable("nav_help__navigate"); + nav_help_model_handle.DirtyVariable("nav_help__accept"); + nav_help_model_handle.DirtyVariable("nav_help__exit"); + } +} + void close_config_menu() { recomp::save_config(); @@ -443,6 +455,39 @@ public: controls_model_handle = constructor.GetModelHandle(); } + void make_nav_help_bindings(Rml::Context* context) { + Rml::DataModelConstructor constructor = context->CreateDataModel("nav_help_model"); + if (!constructor) { + throw std::runtime_error("Failed to make RmlUi data model for nav help"); + } + + constructor.BindFunc("nav_help__navigate", [](Rml::Variant& out) { + if (cont_active) { + out = PF_DPAD; + } else { + out = PF_KEYBOARD_ARROWS PF_KEYBOARD_TAB; + } + }); + + constructor.BindFunc("nav_help__accept", [](Rml::Variant& out) { + if (cont_active) { + out = PF_GAMEPAD_A; + } else { + out = PF_KEYBOARD_ENTER; + } + }); + + constructor.BindFunc("nav_help__exit", [](Rml::Variant& out) { + if (cont_active) { + out = PF_XBOX_VIEW; + } else { + out = PF_KEYBOARD_ESCAPE; + } + }); + + nav_help_model_handle = constructor.GetModelHandle(); + } + void make_general_bindings(Rml::Context* context) { Rml::DataModelConstructor constructor = context->CreateDataModel("general_model"); if (!constructor) { @@ -493,6 +538,7 @@ public: } void make_bindings(Rml::Context* context) override { + make_nav_help_bindings(context); make_general_bindings(context); make_controls_bindings(context); make_graphics_bindings(context); diff --git a/src/ui/ui_renderer.cpp b/src/ui/ui_renderer.cpp index 19a2ea6..28f8bee 100644 --- a/src/ui/ui_renderer.cpp +++ b/src/ui/ui_renderer.cpp @@ -1120,6 +1120,8 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderFramebuffer* s bool mouse_moved = false; bool non_mouse_interacted = false; + bool cont_interacted = false; + bool kb_interacted = false; while (recomp::try_deque_event(cur_event)) { bool menu_is_open = cur_menu != recomp::Menu::None; @@ -1175,10 +1177,13 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderFramebuffer* s if (menu_is_open && rml_key) { ui_context->rml.context->ProcessKeyDown(RmlSDL::ConvertKey(rml_key), 0); } + non_mouse_interacted = true; + cont_interacted = true; + break; } - // fallthrough case SDL_EventType::SDL_KEYDOWN: non_mouse_interacted = true; + kb_interacted = true; break; case SDL_EventType::SDL_CONTROLLERAXISMOTION: SDL_ControllerAxisEvent* axis_event = &cur_event.caxis; @@ -1200,6 +1205,7 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderFramebuffer* s } } non_mouse_interacted = true; + cont_interacted = true; } else if (*await_stick_return && fabsf(axis_value) < 0.15f) { *await_stick_return = false; @@ -1237,6 +1243,10 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderFramebuffer* s } } // end dequeue event loop + if (cont_interacted || kb_interacted) { + recomp::set_cont_or_kb(cont_interacted); + } + recomp::InputField scanned_field = recomp::get_scanned_input(); if (scanned_field != recomp::InputField{}) { recomp::finish_scanning_input(scanned_field);