diff --git a/loader/include/Geode/loader/SettingV3.hpp b/loader/include/Geode/loader/SettingV3.hpp index d4968644..f7796346 100644 --- a/loader/include/Geode/loader/SettingV3.hpp +++ b/loader/include/Geode/loader/SettingV3.hpp @@ -432,7 +432,7 @@ namespace geode { size_t getArrowStepSize() const; size_t getBigArrowStepSize() const; bool isSliderEnabled() const; - std::optional getSliderSnap() const; + int64_t getSliderSnap() const; bool isInputEnabled() const; SettingNodeV3* createNode(float width) override; @@ -464,7 +464,7 @@ namespace geode { double getArrowStepSize() const; double getBigArrowStepSize() const; bool isSliderEnabled() const; - std::optional getSliderSnap() const; + double getSliderSnap() const; bool isInputEnabled() const; SettingNodeV3* createNode(float width) override; @@ -669,6 +669,9 @@ namespace geode { void onCommit() override { this->getSetting()->setValue(m_impl->currentValue); + // The value may be different, if the current value was an invalid + // value for the setting + this->setValue(this->getSetting()->getValue(), nullptr); } bool hasUncommittedChanges() const override { return m_impl->currentValue != this->getSetting()->getValue(); diff --git a/loader/src/loader/SettingNodeV3.cpp b/loader/src/loader/SettingNodeV3.cpp index 06d495ed..2e57c85f 100644 --- a/loader/src/loader/SettingNodeV3.cpp +++ b/loader/src/loader/SettingNodeV3.cpp @@ -311,8 +311,8 @@ bool StringSettingNodeV3::init(std::shared_ptr setting, float w return false; m_input = TextInput::create(setting->getEnumOptions() ? width / 2 - 50 : width / 2, "Text"); - m_input->setCallback([this](auto const&) { - this->markChanged(m_input); + m_input->setCallback([this](auto const& str) { + this->setValue(str, m_input); }); m_input->setScale(.7f); m_input->setString(this->getSetting()->getValue()); diff --git a/loader/src/loader/SettingNodeV3.hpp b/loader/src/loader/SettingNodeV3.hpp index 945ef24d..89569931 100644 --- a/loader/src/loader/SettingNodeV3.hpp +++ b/loader/src/loader/SettingNodeV3.hpp @@ -67,8 +67,9 @@ protected: auto max = this->getSetting()->getMaxValue().value_or(+100); auto range = max - min; auto value = static_cast(num * range + min); - if (auto step = this->getSetting()->getSliderSnap()) { - value = static_cast(round(value / *step) * (*step)); + auto step = this->getSetting()->getSliderSnap(); + if (step > 0) { + value = static_cast(round(value / step) * step); } return value; } @@ -106,8 +107,8 @@ protected: m_input = TextInput::create(this->getButtonMenu()->getContentWidth() - 40, "Num"); m_input->setScale(.7f); - m_input->setCallback([this](auto const&) { - this->markChanged(m_input); + m_input->setCallback([this, setting](auto const& str) { + this->setValue(numFromString(str).unwrapOr(setting->getDefaultValue()), m_input); }); if (!setting->isInputEnabled()) { m_input->getBGSprite()->setVisible(false); diff --git a/loader/src/loader/SettingV3.cpp b/loader/src/loader/SettingV3.cpp index 54c7052d..5418e844 100644 --- a/loader/src/loader/SettingV3.cpp +++ b/loader/src/loader/SettingV3.cpp @@ -487,7 +487,7 @@ void SettingV3::init(std::string const& key, std::string const& modID, JsonExpec } void SettingV3::parseNameAndDescription(JsonExpectedValue& json) { - json.needs("name").into(m_impl->name); + json.has("name").into(m_impl->name); json.has("description").into(m_impl->description); } void SettingV3::parseEnableIf(JsonExpectedValue& json) { @@ -711,7 +711,7 @@ public: size_t arrowStepSize = 1; size_t bigArrowStepSize = 5; bool sliderEnabled = true; - std::optional sliderSnap; + int64_t sliderSnap = 1; bool textInputEnabled = true; } controls; }; @@ -797,7 +797,7 @@ size_t IntSettingV3::getBigArrowStepSize() const { bool IntSettingV3::isSliderEnabled() const { return m_impl->controls.sliderEnabled; } -std::optional IntSettingV3::getSliderSnap() const { +int64_t IntSettingV3::getSliderSnap() const { return m_impl->controls.sliderSnap; } bool IntSettingV3::isInputEnabled() const { @@ -842,7 +842,7 @@ public: double arrowStepSize = 1; double bigArrowStepSize = 5; bool sliderEnabled = true; - std::optional sliderSnap; + double sliderSnap = 0.1; bool textInputEnabled = true; } controls; }; @@ -926,7 +926,7 @@ double FloatSettingV3::getBigArrowStepSize() const { bool FloatSettingV3::isSliderEnabled() const { return m_impl->controls.sliderEnabled; } -std::optional FloatSettingV3::getSliderSnap() const { +double FloatSettingV3::getSliderSnap() const { return m_impl->controls.sliderSnap; } bool FloatSettingV3::isInputEnabled() const {