Add active_binding_input and active_binding_slot bindings in controls UI

This commit is contained in:
Mr-Wiseguy 2024-01-17 02:22:36 -05:00
parent 23f0235996
commit d0e01cdec1
4 changed files with 37 additions and 7 deletions

View File

@ -139,7 +139,7 @@
<div class="input-config__visual-wrapper">
<div class="input-config__visual-aspect">
<div class="input-config__visual">
<h3>Insert visual here</h3>
<h3>Insert visual here:{{active_binding_input}}:{{active_binding_slot}}</h3>
</div>
</div>
</div>

View File

@ -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<std::string>& 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);

View File

@ -64,6 +64,14 @@ static const std::array n64_button_values = {
static const std::vector<std::string> 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<std::string> 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<std::string>& 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.

View File

@ -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<size_t>())};
return Rml::Variant{recomp::get_input_name(inputs.at(0).Get<size_t>())};
});
constructor.BindEventCallback("set_input_binding",
@ -150,6 +154,8 @@ public:
scanned_input_index = inputs.at(0).Get<size_t>();
scanned_binding_index = inputs.at(1).Get<size_t>();
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<int>("active_binding_slot", &scanned_binding_index);
controls_model_handle = constructor.GetModelHandle();
}