Skip to content

Commit

Permalink
show invalid values in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Sep 9, 2024
1 parent d5718be commit b66bcca
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
11 changes: 11 additions & 0 deletions loader/include/Geode/loader/SettingV3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ namespace geode {
void setDefaultBGColor(cocos2d::ccColor4B color);

cocos2d::CCLabelBMFont* getNameLabel() const;
cocos2d::CCLabelBMFont* getStatusLabel() const;
cocos2d::CCMenu* getNameMenu() const;
cocos2d::CCMenu* getButtonMenu() const;
cocos2d::CCLayerColor* getBG() const;
Expand Down Expand Up @@ -656,6 +657,16 @@ namespace geode {
return true;
}

void updateState(cocos2d::CCNode* invoker) {
SettingNodeV3::updateState(invoker);
auto validate = this->getSetting()->isValid(m_impl->currentValue);
if (!validate) {
this->getStatusLabel()->setVisible(true);
this->getStatusLabel()->setString(validate.unwrapErr().c_str());
this->getStatusLabel()->setColor(cocos2d::ccc3(235, 35, 52));
}
}

void onCommit() override {
this->getSetting()->setValue(m_impl->currentValue);
}
Expand Down
35 changes: 19 additions & 16 deletions loader/src/loader/SettingNodeV3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SettingNodeV3::Impl final {
CCMenu* nameMenu;
CCMenu* buttonMenu;
CCMenuItemSpriteExtra* resetButton;
CCLabelBMFont* errorLabel;
CCLabelBMFont* statusLabel;
ccColor4B bgColor = ccc4(0, 0, 0, 0);
bool committed = false;
};
Expand All @@ -75,9 +75,9 @@ bool SettingNodeV3::init(std::shared_ptr<SettingV3> setting, float width) {
m_impl->nameLabel->setLayoutOptions(AxisLayoutOptions::create()->setScaleLimits(.1f, .4f)->setScalePriority(1));
m_impl->nameMenu->addChild(m_impl->nameLabel);

m_impl->errorLabel = CCLabelBMFont::create("", "bigFont.fnt");
m_impl->errorLabel->setScale(.25f);
this->addChildAtPosition(m_impl->errorLabel, Anchor::Left, ccp(10, -10), ccp(0, .5f));
m_impl->statusLabel = CCLabelBMFont::create("", "bigFont.fnt");
m_impl->statusLabel->setScale(.25f);
this->addChildAtPosition(m_impl->statusLabel, Anchor::Left, ccp(10, -10), ccp(0, .5f));

if (setting && setting->getDescription()) {
auto descSpr = CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png");
Expand Down Expand Up @@ -111,7 +111,7 @@ bool SettingNodeV3::init(std::shared_ptr<SettingV3> setting, float width) {
}

void SettingNodeV3::updateState(CCNode* invoker) {
m_impl->errorLabel->setVisible(false);
m_impl->statusLabel->setVisible(false);

m_impl->nameLabel->setColor(this->hasUncommittedChanges() ? ccc3(17, 221, 0) : ccWHITE);
m_impl->resetButton->setVisible(this->hasNonDefaultValue());
Expand All @@ -122,15 +122,15 @@ void SettingNodeV3::updateState(CCNode* invoker) {
if (m_impl->setting && !m_impl->setting->shouldEnable()) {
if (auto desc = m_impl->setting->getEnableIfDescription()) {
m_impl->nameLabel->setColor(ccGRAY);
m_impl->errorLabel->setVisible(true);
m_impl->errorLabel->setColor("mod-list-errors-found"_cc3b);
m_impl->errorLabel->setString(desc->c_str());
m_impl->statusLabel->setVisible(true);
m_impl->statusLabel->setColor("mod-list-errors-found"_cc3b);
m_impl->statusLabel->setString(desc->c_str());
}
}
if (m_impl->setting && m_impl->setting->requiresRestart() && m_impl->committed) {
m_impl->errorLabel->setVisible(true);
m_impl->errorLabel->setColor("mod-list-restart-required-label"_cc3b);
m_impl->errorLabel->setString("Restart Required");
m_impl->statusLabel->setVisible(true);
m_impl->statusLabel->setColor("mod-list-restart-required-label"_cc3b);
m_impl->statusLabel->setString("Restart Required");
m_impl->bg->setColor("mod-list-restart-required-label-bg"_cc3b);
m_impl->bg->setOpacity(75);
}
Expand Down Expand Up @@ -199,6 +199,9 @@ void SettingNodeV3::setContentSize(CCSize const& size) {
CCLabelBMFont* SettingNodeV3::getNameLabel() const {
return m_impl->nameLabel;
}
CCLabelBMFont* SettingNodeV3::getStatusLabel() const {
return m_impl->statusLabel;
}
CCMenu* SettingNodeV3::getNameMenu() const {
return m_impl->nameMenu;
}
Expand Down Expand Up @@ -276,7 +279,7 @@ bool BoolSettingNodeV3::init(std::shared_ptr<BoolSettingV3> setting, float width
}

void BoolSettingNodeV3::updateState(CCNode* invoker) {
SettingNodeV3::updateState(invoker);
SettingValueNodeV3::updateState(invoker);
auto enable = this->getSetting()->shouldEnable();
m_toggle->toggle(this->getValue());
m_toggle->setCascadeColorEnabled(true);
Expand Down Expand Up @@ -345,7 +348,7 @@ bool StringSettingNodeV3::init(std::shared_ptr<StringSettingV3> setting, float w
}

void StringSettingNodeV3::updateState(CCNode* invoker) {
SettingNodeV3::updateState(invoker);
SettingValueNodeV3::updateState(invoker);

if (invoker != m_input) {
m_input->setString(this->getValue());
Expand Down Expand Up @@ -417,7 +420,7 @@ bool FileSettingNodeV3::init(std::shared_ptr<FileSettingV3> setting, float width
}

void FileSettingNodeV3::updateState(CCNode* invoker) {
SettingNodeV3::updateState(invoker);
SettingValueNodeV3::updateState(invoker);
m_fileIcon->setDisplayFrame(CCSpriteFrameCache::get()->spriteFrameByName(
this->getSetting()->isFolder() ? "folderIcon_001.png" : "file.png"_spr
));
Expand Down Expand Up @@ -502,7 +505,7 @@ bool Color3BSettingNodeV3::init(std::shared_ptr<Color3BSettingV3> setting, float
}

void Color3BSettingNodeV3::updateState(CCNode* invoker) {
SettingNodeV3::updateState(invoker);
SettingValueNodeV3::updateState(invoker);
m_colorSprite->setColor(this->getValue());

auto enable = this->getSetting()->shouldEnable();
Expand Down Expand Up @@ -549,7 +552,7 @@ bool Color4BSettingNodeV3::init(std::shared_ptr<Color4BSettingV3> setting, float
}

void Color4BSettingNodeV3::updateState(CCNode* invoker) {
SettingNodeV3::updateState(invoker);
SettingValueNodeV3::updateState(invoker);
m_colorSprite->setColor(to3B(this->getValue()));
m_colorSprite->updateOpacity(this->getValue().a / 255.f);

Expand Down
2 changes: 1 addition & 1 deletion loader/src/loader/SettingNodeV3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class NumberSettingNodeV3 : public SettingValueNodeV3<S> {
}

void updateState(CCNode* invoker) override {
SettingNodeV3::updateState(invoker);
SettingValueNodeV3<S>::updateState(invoker);
auto enable = this->getSetting()->shouldEnable();
if (this->getSetting()->isInputEnabled()) {
m_input->setEnabled(enable);
Expand Down
2 changes: 1 addition & 1 deletion loader/src/loader/SettingV3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void SettingV3::init(std::string const& key, std::string const& modID, JsonExpec
// Keys every setting must have
json.needs("type");
for (auto& plat : json.has("platforms").items()) {
m_impl->platforms.push_back(PlatformID::from(plat.template get<std::string>()));
ranges::push(m_impl->platforms, PlatformID::getCovered(plat.template get<std::string>()));
}
}

Expand Down

0 comments on commit b66bcca

Please sign in to comment.