mirror of
https://github.com/Mr-Wiseguy/Zelda64Recomp.git
synced 2024-11-25 14:16:58 +01:00
Add active_binding_input and active_binding_slot bindings in controls UI
This commit is contained in:
parent
23f0235996
commit
d0e01cdec1
@ -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>
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user