swap nav icons between kb and cont

This commit is contained in:
thecozies 2024-03-27 15:02:03 -05:00
parent e57e52c4f7
commit 8853fc0d7b
4 changed files with 62 additions and 4 deletions

View File

@ -85,18 +85,19 @@
</div> </div>
<div <div
class="centered-page__controls" class="centered-page__controls"
data-model="nav_help_model"
> >
<label> <label>
<span>Navigate</span> <span>Navigate</span>
<span class="prompt-font-sm">&#x2424;&#x242B;</span> <span class="prompt-font-sm">{{nav_help__navigate}}</span>
</label> </label>
<label> <label>
<span>Accept</span> <span>Accept</span>
<span class="prompt-font-sm">&#x242E;</span> <span class="prompt-font-sm">{{nav_help__accept}}</span>
</label> </label>
<label> <label>
<span>Exit</span> <span>Exit</span>
<span class="prompt-font-sm">&#x242F;</span> <span class="prompt-font-sm">{{nav_help__exit}}</span>
</label> </label>
<!-- <label><span style="font-family:promptfont;">&#x21F3;</span> Navigate</label> <!-- <label><span style="font-family:promptfont;">&#x21F3;</span> Navigate</label>
<label><span style="font-family:promptfont;">&#x21A7;</span> Accept</label> --> <label><span style="font-family:promptfont;">&#x21A7;</span> Accept</label> -->

View File

@ -77,6 +77,7 @@ namespace recomp {
void stop_scanning_input(); void stop_scanning_input();
void finish_scanning_input(InputField scanned_field); void finish_scanning_input(InputField scanned_field);
void cancel_scanning_input(); void cancel_scanning_input();
void set_cont_or_kb(bool cont_interacted);
InputField get_scanned_input(); InputField get_scanned_input();
struct DefaultN64Mappings { struct DefaultN64Mappings {

View File

@ -3,11 +3,13 @@
#include "recomp_sound.h" #include "recomp_sound.h"
#include "recomp_config.h" #include "recomp_config.h"
#include "recomp_debug.h" #include "recomp_debug.h"
#include "promptfont.h"
#include "../../ultramodern/config.hpp" #include "../../ultramodern/config.hpp"
#include "../../ultramodern/ultramodern.hpp" #include "../../ultramodern/ultramodern.hpp"
#include "RmlUi/Core.h" #include "RmlUi/Core.h"
ultramodern::GraphicsConfig new_options; ultramodern::GraphicsConfig new_options;
Rml::DataModelHandle nav_help_model_handle;
Rml::DataModelHandle general_model_handle; Rml::DataModelHandle general_model_handle;
Rml::DataModelHandle controls_model_handle; Rml::DataModelHandle controls_model_handle;
Rml::DataModelHandle graphics_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_binding_index = -1;
static int scanned_input_index = -1; static int scanned_input_index = -1;
static int focused_input_index = -1; static int focused_input_index = -1;
static bool cont_active = true;
static recomp::InputDevice cur_device = recomp::InputDevice::Controller; static recomp::InputDevice cur_device = recomp::InputDevice::Controller;
@ -84,6 +87,15 @@ void recomp::cancel_scanning_input() {
controls_model_handle.DirtyVariable("active_binding_slot"); 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() { void close_config_menu() {
recomp::save_config(); recomp::save_config();
@ -443,6 +455,39 @@ public:
controls_model_handle = constructor.GetModelHandle(); 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) { void make_general_bindings(Rml::Context* context) {
Rml::DataModelConstructor constructor = context->CreateDataModel("general_model"); Rml::DataModelConstructor constructor = context->CreateDataModel("general_model");
if (!constructor) { if (!constructor) {
@ -493,6 +538,7 @@ public:
} }
void make_bindings(Rml::Context* context) override { void make_bindings(Rml::Context* context) override {
make_nav_help_bindings(context);
make_general_bindings(context); make_general_bindings(context);
make_controls_bindings(context); make_controls_bindings(context);
make_graphics_bindings(context); make_graphics_bindings(context);

View File

@ -1120,6 +1120,8 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderFramebuffer* s
bool mouse_moved = false; bool mouse_moved = false;
bool non_mouse_interacted = false; bool non_mouse_interacted = false;
bool cont_interacted = false;
bool kb_interacted = false;
while (recomp::try_deque_event(cur_event)) { while (recomp::try_deque_event(cur_event)) {
bool menu_is_open = cur_menu != recomp::Menu::None; 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) { if (menu_is_open && rml_key) {
ui_context->rml.context->ProcessKeyDown(RmlSDL::ConvertKey(rml_key), 0); ui_context->rml.context->ProcessKeyDown(RmlSDL::ConvertKey(rml_key), 0);
} }
non_mouse_interacted = true;
cont_interacted = true;
break;
} }
// fallthrough
case SDL_EventType::SDL_KEYDOWN: case SDL_EventType::SDL_KEYDOWN:
non_mouse_interacted = true; non_mouse_interacted = true;
kb_interacted = true;
break; break;
case SDL_EventType::SDL_CONTROLLERAXISMOTION: case SDL_EventType::SDL_CONTROLLERAXISMOTION:
SDL_ControllerAxisEvent* axis_event = &cur_event.caxis; 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; non_mouse_interacted = true;
cont_interacted = true;
} }
else if (*await_stick_return && fabsf(axis_value) < 0.15f) { else if (*await_stick_return && fabsf(axis_value) < 0.15f) {
*await_stick_return = false; *await_stick_return = false;
@ -1237,6 +1243,10 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderFramebuffer* s
} }
} // end dequeue event loop } // end dequeue event loop
if (cont_interacted || kb_interacted) {
recomp::set_cont_or_kb(cont_interacted);
}
recomp::InputField scanned_field = recomp::get_scanned_input(); recomp::InputField scanned_field = recomp::get_scanned_input();
if (scanned_field != recomp::InputField{}) { if (scanned_field != recomp::InputField{}) {
recomp::finish_scanning_input(scanned_field); recomp::finish_scanning_input(scanned_field);