mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp.git
synced 2026-05-03 15:41:46 +00:00
Add support for config schema.
This commit is contained in:
parent
a087731f96
commit
590273c070
6 changed files with 37 additions and 18 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include "recomp.h"
|
#include "recomp.h"
|
||||||
#include "librecomp/overlays.hpp"
|
#include "librecomp/overlays.hpp"
|
||||||
#include "librecomp/config.hpp"
|
|
||||||
#include "zelda_config.h"
|
#include "zelda_config.h"
|
||||||
#include "recomp_input.h"
|
#include "recomp_input.h"
|
||||||
#include "recomp_ui.h"
|
#include "recomp_ui.h"
|
||||||
|
|
|
||||||
|
|
@ -53,11 +53,12 @@ void ConfigOptionSlider::slider_value_changed(double v) {
|
||||||
printf("%s changed to %f.\n", name.c_str(), v);
|
printf("%s changed to %f.\n", name.c_str(), v);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigOptionSlider::ConfigOptionSlider(double value, double min_value, double max_value, Element *parent) : ConfigOptionElement(parent) {
|
ConfigOptionSlider::ConfigOptionSlider(double value, double min_value, double max_value, double step_value, bool percent, Element *parent) : ConfigOptionElement(parent) {
|
||||||
slider = get_current_context().create_element<Slider>(SliderType::Percent, this);
|
slider = get_current_context().create_element<Slider>(percent ? SliderType::Percent : SliderType::Double, this);
|
||||||
slider->set_value(value);
|
slider->set_value(value);
|
||||||
slider->set_min_value(min_value);
|
slider->set_min_value(min_value);
|
||||||
slider->set_max_value(max_value);
|
slider->set_max_value(max_value);
|
||||||
|
slider->set_step_value(step_value);
|
||||||
slider->add_value_changed_callback(std::bind(&ConfigOptionSlider::slider_value_changed, this, std::placeholders::_1));
|
slider->add_value_changed_callback(std::bind(&ConfigOptionSlider::slider_value_changed, this, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,7 +80,7 @@ void ConfigOptionRadio::index_changed(uint32_t index) {
|
||||||
printf("%s changed to %d.\n", name.c_str(), index);
|
printf("%s changed to %d.\n", name.c_str(), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigOptionRadio::ConfigOptionRadio(const std::initializer_list<std::string_view> &options, Element *parent) : ConfigOptionElement(parent) {
|
ConfigOptionRadio::ConfigOptionRadio(const std::vector<std::string> &options, Element *parent) : ConfigOptionElement(parent) {
|
||||||
radio = get_current_context().create_element<Radio>(this);
|
radio = get_current_context().create_element<Radio>(this);
|
||||||
radio->add_index_changed_callback(std::bind(&ConfigOptionRadio::index_changed, this, std::placeholders::_1));
|
radio->add_index_changed_callback(std::bind(&ConfigOptionRadio::index_changed, this, std::placeholders::_1));
|
||||||
for (std::string_view option : options) {
|
for (std::string_view option : options) {
|
||||||
|
|
@ -166,8 +167,8 @@ void ConfigSubMenu::add_option(ConfigOptionElement *option, std::string_view nam
|
||||||
config_option_elements.emplace_back(option);
|
config_option_elements.emplace_back(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigSubMenu::add_slider_option(std::string_view name, std::string_view description, double min, double max) {
|
void ConfigSubMenu::add_slider_option(std::string_view name, std::string_view description, double min, double max, double step, bool percent) {
|
||||||
ConfigOptionSlider *option_slider = get_current_context().create_element<ConfigOptionSlider>((min + max) / 2.0, min, max, config_scroll_container);
|
ConfigOptionSlider *option_slider = get_current_context().create_element<ConfigOptionSlider>((min + max) / 2.0, min, max, step, percent, config_scroll_container);
|
||||||
add_option(option_slider, name, description);
|
add_option(option_slider, name, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,7 +177,7 @@ void ConfigSubMenu::add_text_option(std::string_view name, std::string_view desc
|
||||||
add_option(option_text_input, name, description);
|
add_option(option_text_input, name, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigSubMenu::add_radio_option(std::string_view name, std::string_view description, const std::initializer_list<std::string_view> &options) {
|
void ConfigSubMenu::add_radio_option(std::string_view name, std::string_view description, const std::vector<std::string> &options) {
|
||||||
ConfigOptionRadio *option_radio = get_current_context().create_element<ConfigOptionRadio>(options, config_scroll_container);
|
ConfigOptionRadio *option_radio = get_current_context().create_element<ConfigOptionRadio>(options, config_scroll_container);
|
||||||
add_option(option_radio, name, description);
|
add_option(option_radio, name, description);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ protected:
|
||||||
|
|
||||||
void slider_value_changed(double v);
|
void slider_value_changed(double v);
|
||||||
public:
|
public:
|
||||||
ConfigOptionSlider(double value, double min_value, double max_value, Element *parent);
|
ConfigOptionSlider(double value, double min_value, double max_value, double step_value, bool percent, Element *parent);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigOptionTextInput : public ConfigOptionElement {
|
class ConfigOptionTextInput : public ConfigOptionElement {
|
||||||
|
|
@ -54,7 +54,7 @@ protected:
|
||||||
|
|
||||||
void index_changed(uint32_t index);
|
void index_changed(uint32_t index);
|
||||||
public:
|
public:
|
||||||
ConfigOptionRadio(const std::initializer_list<std::string_view> &options, Element *parent);
|
ConfigOptionRadio(const std::vector<std::string> &options, Element *parent);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigSubMenu : public Element {
|
class ConfigSubMenu : public Element {
|
||||||
|
|
@ -80,9 +80,9 @@ public:
|
||||||
virtual ~ConfigSubMenu();
|
virtual ~ConfigSubMenu();
|
||||||
void enter(std::string_view title);
|
void enter(std::string_view title);
|
||||||
void clear_options();
|
void clear_options();
|
||||||
void add_slider_option(std::string_view name, std::string_view description, double min, double max);
|
void add_slider_option(std::string_view name, std::string_view description, double min, double max, double step, bool percent);
|
||||||
void add_text_option(std::string_view name, std::string_view description);
|
void add_text_option(std::string_view name, std::string_view description);
|
||||||
void add_radio_option(std::string_view name, std::string_view description, const std::initializer_list<std::string_view> &options);
|
void add_radio_option(std::string_view name, std::string_view description, const std::vector<std::string> &options);
|
||||||
void set_enter_sub_menu_callback(std::function<void()> callback);
|
void set_enter_sub_menu_callback(std::function<void()> callback);
|
||||||
void set_quit_sub_menu_callback(std::function<void()> callback);
|
void set_quit_sub_menu_callback(std::function<void()> callback);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
#include "ui_elements.h"
|
#include "ui_elements.h"
|
||||||
#include "librecomp/config.hpp"
|
|
||||||
|
|
||||||
struct RecompElementConfig {
|
struct RecompCustomElement {
|
||||||
Rml::String tag;
|
Rml::String tag;
|
||||||
std::unique_ptr<Rml::ElementInstancer> instancer;
|
std::unique_ptr<Rml::ElementInstancer> instancer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CUSTOM_ELEMENT(s, e) { s, std::make_unique< Rml::ElementInstancerGeneric< e > >() }
|
#define CUSTOM_ELEMENT(s, e) { s, std::make_unique< Rml::ElementInstancerGeneric< e > >() }
|
||||||
|
|
||||||
static RecompElementConfig custom_elements[] = {
|
static RecompCustomElement custom_elements[] = {
|
||||||
CUSTOM_ELEMENT("recomp-mod-menu", recompui::ElementModMenu),
|
CUSTOM_ELEMENT("recomp-mod-menu", recompui::ElementModMenu),
|
||||||
CUSTOM_ELEMENT("recomp-config-sub-menu", recompui::ElementConfigSubMenu),
|
CUSTOM_ELEMENT("recomp-config-sub-menu", recompui::ElementConfigSubMenu),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,30 @@ void ModMenu::mod_toggled(bool enabled) {
|
||||||
void ModMenu::mod_configure_requested() {
|
void ModMenu::mod_configure_requested() {
|
||||||
if (active_mod_index >= 0) {
|
if (active_mod_index >= 0) {
|
||||||
ext_config_sub_menu->clear_options();
|
ext_config_sub_menu->clear_options();
|
||||||
ext_config_sub_menu->add_slider_option("Slider Option", "Description for slider option.", 0.0, 100.0);
|
|
||||||
ext_config_sub_menu->add_text_option("Text Option", "Description for simple option.");
|
const recomp::mods::ConfigSchema &config_schema = recomp::mods::get_mod_config_schema(mod_details[active_mod_index].mod_id);
|
||||||
ext_config_sub_menu->add_radio_option("Radio Option", "Description for radio option.", { "First", "Second", "Third" });
|
for (const recomp::mods::ConfigOption &option : config_schema.options) {
|
||||||
|
switch (option.type) {
|
||||||
|
case recomp::mods::ConfigOptionType::Enum: {
|
||||||
|
const recomp::mods::ConfigOptionEnum &option_enum = std::get<recomp::mods::ConfigOptionEnum>(option.variant);
|
||||||
|
ext_config_sub_menu->add_radio_option(option.name, option.description, option_enum.options);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case recomp::mods::ConfigOptionType::Number: {
|
||||||
|
const recomp::mods::ConfigOptionNumber &option_number = std::get<recomp::mods::ConfigOptionNumber>(option.variant);
|
||||||
|
ext_config_sub_menu->add_slider_option(option.name, option.description, option_number.min, option_number.max, option_number.step, option_number.percent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case recomp::mods::ConfigOptionType::String: {
|
||||||
|
ext_config_sub_menu->add_text_option(option.name, option.description);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
assert(false && "Unknown config option type.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ext_config_sub_menu->enter(mod_details[active_mod_index].mod_id);
|
ext_config_sub_menu->enter(mod_details[active_mod_index].mod_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
#include "ui_elements.h"
|
#include "ui_elements.h"
|
||||||
#include "ui_mod_menu.h"
|
#include "ui_mod_menu.h"
|
||||||
#include "ui_renderer.h"
|
#include "ui_renderer.h"
|
||||||
#include "librecomp/config.hpp"
|
|
||||||
|
|
||||||
bool can_focus(Rml::Element* element) {
|
bool can_focus(Rml::Element* element) {
|
||||||
return element->GetOwnerDocument() != nullptr && element->GetProperty(Rml::PropertyId::TabIndex)->Get<Rml::Style::TabIndex>() != Rml::Style::TabIndex::None;
|
return element->GetOwnerDocument() != nullptr && element->GetProperty(Rml::PropertyId::TabIndex)->Get<Rml::Style::TabIndex>() != Rml::Style::TabIndex::None;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue