diff --git a/src/game/recomp_api.cpp b/src/game/recomp_api.cpp index 1969fe8..00c8f34 100644 --- a/src/game/recomp_api.cpp +++ b/src/game/recomp_api.cpp @@ -2,7 +2,6 @@ #include "recomp.h" #include "librecomp/overlays.hpp" -#include "librecomp/config.hpp" #include "zelda_config.h" #include "recomp_input.h" #include "recomp_ui.h" diff --git a/src/ui/ui_config_sub_menu.cpp b/src/ui/ui_config_sub_menu.cpp index ff0d12c..8af58d9 100644 --- a/src/ui/ui_config_sub_menu.cpp +++ b/src/ui/ui_config_sub_menu.cpp @@ -53,11 +53,12 @@ void ConfigOptionSlider::slider_value_changed(double 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) { - slider = get_current_context().create_element(SliderType::Percent, this); +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(percent ? SliderType::Percent : SliderType::Double, this); slider->set_value(value); slider->set_min_value(min_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)); } @@ -79,7 +80,7 @@ void ConfigOptionRadio::index_changed(uint32_t index) { printf("%s changed to %d.\n", name.c_str(), index); } -ConfigOptionRadio::ConfigOptionRadio(const std::initializer_list &options, Element *parent) : ConfigOptionElement(parent) { +ConfigOptionRadio::ConfigOptionRadio(const std::vector &options, Element *parent) : ConfigOptionElement(parent) { radio = get_current_context().create_element(this); radio->add_index_changed_callback(std::bind(&ConfigOptionRadio::index_changed, this, std::placeholders::_1)); 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); } -void ConfigSubMenu::add_slider_option(std::string_view name, std::string_view description, double min, double max) { - ConfigOptionSlider *option_slider = get_current_context().create_element((min + max) / 2.0, min, max, config_scroll_container); +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((min + max) / 2.0, min, max, step, percent, config_scroll_container); 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); } -void ConfigSubMenu::add_radio_option(std::string_view name, std::string_view description, const std::initializer_list &options) { +void ConfigSubMenu::add_radio_option(std::string_view name, std::string_view description, const std::vector &options) { ConfigOptionRadio *option_radio = get_current_context().create_element(options, config_scroll_container); add_option(option_radio, name, description); } diff --git a/src/ui/ui_config_sub_menu.h b/src/ui/ui_config_sub_menu.h index 3f4ba73..1a2e2f9 100644 --- a/src/ui/ui_config_sub_menu.h +++ b/src/ui/ui_config_sub_menu.h @@ -36,7 +36,7 @@ protected: void slider_value_changed(double v); 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 { @@ -54,7 +54,7 @@ protected: void index_changed(uint32_t index); public: - ConfigOptionRadio(const std::initializer_list &options, Element *parent); + ConfigOptionRadio(const std::vector &options, Element *parent); }; class ConfigSubMenu : public Element { @@ -80,9 +80,9 @@ public: virtual ~ConfigSubMenu(); void enter(std::string_view title); 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_radio_option(std::string_view name, std::string_view description, const std::initializer_list &options); + void add_radio_option(std::string_view name, std::string_view description, const std::vector &options); void set_enter_sub_menu_callback(std::function callback); void set_quit_sub_menu_callback(std::function callback); }; diff --git a/src/ui/ui_elements.cpp b/src/ui/ui_elements.cpp index 816e58d..740e981 100644 --- a/src/ui/ui_elements.cpp +++ b/src/ui/ui_elements.cpp @@ -1,14 +1,13 @@ #include "ui_elements.h" -#include "librecomp/config.hpp" -struct RecompElementConfig { +struct RecompCustomElement { Rml::String tag; std::unique_ptr instancer; }; #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-config-sub-menu", recompui::ElementConfigSubMenu), }; diff --git a/src/ui/ui_mod_menu.cpp b/src/ui/ui_mod_menu.cpp index 0b0f1ab..a1c2cbb 100644 --- a/src/ui/ui_mod_menu.cpp +++ b/src/ui/ui_mod_menu.cpp @@ -99,9 +99,30 @@ void ModMenu::mod_toggled(bool enabled) { void ModMenu::mod_configure_requested() { if (active_mod_index >= 0) { 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."); - ext_config_sub_menu->add_radio_option("Radio Option", "Description for radio option.", { "First", "Second", "Third" }); + + const recomp::mods::ConfigSchema &config_schema = recomp::mods::get_mod_config_schema(mod_details[active_mod_index].mod_id); + 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(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(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); } } diff --git a/src/ui/ui_state.cpp b/src/ui/ui_state.cpp index 8627b06..50cc4cc 100644 --- a/src/ui/ui_state.cpp +++ b/src/ui/ui_state.cpp @@ -23,7 +23,6 @@ #include "ui_elements.h" #include "ui_mod_menu.h" #include "ui_renderer.h" -#include "librecomp/config.hpp" bool can_focus(Rml::Element* element) { return element->GetOwnerDocument() != nullptr && element->GetProperty(Rml::PropertyId::TabIndex)->Get() != Rml::Style::TabIndex::None;