diff --git a/assets/config_menu.rml b/assets/config_menu.rml index 8ff4dae..ee4f32f 100644 --- a/assets/config_menu.rml +++ b/assets/config_menu.rml @@ -139,7 +139,7 @@
-

Insert visual here

+

Insert visual here:{{active_binding_input}}:{{active_binding_slot}}

diff --git a/include/recomp_input.h b/include/recomp_input.h index 0f8ecf4..0eb1488 100644 --- a/include/recomp_input.h +++ b/include/recomp_input.h @@ -64,7 +64,8 @@ namespace recomp { // Loads the user's saved controller mapping if one exists, loads the default mappings if no saved mapping exists. void init_control_mappings(); size_t get_num_inputs(); - const std::vector& get_input_names(); + const std::string& get_input_name(size_t input_index); + const std::string& get_input_enum_name(size_t input_index); InputField& get_input_binding(size_t input_index, size_t binding_index, InputDevice device); void set_input_binding(size_t input_index, size_t binding_index, InputDevice device, InputField value); diff --git a/src/game/controls.cpp b/src/game/controls.cpp index e7a7c00..d0e2ef6 100644 --- a/src/game/controls.cpp +++ b/src/game/controls.cpp @@ -64,6 +64,14 @@ static const std::array n64_button_values = { static const std::vector input_names = { DEFINE_ALL_INPUTS() }; +#undef DEFINE_INPUT + +// Make the input enum name array. +#define DEFINE_INPUT(name, value, readable) #name, +static const std::vector input_enum_names = { + DEFINE_ALL_INPUTS() +}; +#undef DEFINE_INPUT void recomp::init_control_mappings() { // TODO load from a file if one exists. @@ -104,8 +112,12 @@ size_t recomp::get_num_inputs() { return (size_t)GameInput::COUNT; } -const std::vector& recomp::get_input_names() { - return input_names; +const std::string& recomp::get_input_name(size_t input_index) { + return input_names.at(input_index); +} + +const std::string& recomp::get_input_enum_name(size_t input_index) { + return input_enum_names.at(input_index); } // Due to an RmlUi limitation this can't be const. Ideally it would return a const reference or even just a straight up copy. diff --git a/src/ui/ui_config.cpp b/src/ui/ui_config.cpp index 0f32f1a..bf3bace 100644 --- a/src/ui/ui_config.cpp +++ b/src/ui/ui_config.cpp @@ -54,14 +54,18 @@ void bind_option(Rml::DataModelConstructor& constructor, const std::string& name ); }; -static size_t scanned_binding_index; -static size_t scanned_input_index; +static int scanned_binding_index = -1; +static int scanned_input_index = -1; constexpr recomp::InputDevice cur_device = recomp::InputDevice::Controller; void recomp::finish_scanning_input(recomp::InputField scanned_field) { recomp::set_input_binding(scanned_input_index, scanned_binding_index, cur_device, scanned_field); + scanned_input_index = -1; + scanned_binding_index = -1; controls_model_handle.DirtyVariable("inputs"); + controls_model_handle.DirtyVariable("active_binding_input"); + controls_model_handle.DirtyVariable("active_binding_slot"); } class ConfigMenu : public recomp::MenuController { @@ -142,7 +146,7 @@ public: constructor.BindFunc("input_count", [](Rml::Variant& out) { out = recomp::get_num_inputs(); } ); constructor.RegisterTransformFunc("get_input_name", [](const Rml::VariantList& inputs) { - return Rml::Variant{recomp::get_input_names().at(inputs.at(0).Get())}; + return Rml::Variant{recomp::get_input_name(inputs.at(0).Get())}; }); constructor.BindEventCallback("set_input_binding", @@ -150,6 +154,8 @@ public: scanned_input_index = inputs.at(0).Get(); scanned_binding_index = inputs.at(1).Get(); recomp::start_scanning_input(cur_device); + model_handle.DirtyVariable("active_binding_input"); + model_handle.DirtyVariable("active_binding_slot"); }); constructor.BindEventCallback("clear_input_bindings", @@ -209,6 +215,17 @@ public: static InputContainer dummy_container; constructor.Bind("inputs", &dummy_container); + constructor.BindFunc("active_binding_input", [](Rml::Variant& out) { + if (scanned_input_index == -1) { + out = "NONE"; + } + else { + out = recomp::get_input_enum_name(scanned_input_index); + } + }); + + constructor.Bind("active_binding_slot", &scanned_binding_index); + controls_model_handle = constructor.GetModelHandle(); }