mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
show invalid values in the UI
This commit is contained in:
parent
d5718be422
commit
b66bcca2a6
4 changed files with 32 additions and 18 deletions
|
@ -621,6 +621,7 @@ namespace geode {
|
||||||
void setDefaultBGColor(cocos2d::ccColor4B color);
|
void setDefaultBGColor(cocos2d::ccColor4B color);
|
||||||
|
|
||||||
cocos2d::CCLabelBMFont* getNameLabel() const;
|
cocos2d::CCLabelBMFont* getNameLabel() const;
|
||||||
|
cocos2d::CCLabelBMFont* getStatusLabel() const;
|
||||||
cocos2d::CCMenu* getNameMenu() const;
|
cocos2d::CCMenu* getNameMenu() const;
|
||||||
cocos2d::CCMenu* getButtonMenu() const;
|
cocos2d::CCMenu* getButtonMenu() const;
|
||||||
cocos2d::CCLayerColor* getBG() const;
|
cocos2d::CCLayerColor* getBG() const;
|
||||||
|
@ -656,6 +657,16 @@ namespace geode {
|
||||||
return true;
|
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 {
|
void onCommit() override {
|
||||||
this->getSetting()->setValue(m_impl->currentValue);
|
this->getSetting()->setValue(m_impl->currentValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
CCMenu* nameMenu;
|
CCMenu* nameMenu;
|
||||||
CCMenu* buttonMenu;
|
CCMenu* buttonMenu;
|
||||||
CCMenuItemSpriteExtra* resetButton;
|
CCMenuItemSpriteExtra* resetButton;
|
||||||
CCLabelBMFont* errorLabel;
|
CCLabelBMFont* statusLabel;
|
||||||
ccColor4B bgColor = ccc4(0, 0, 0, 0);
|
ccColor4B bgColor = ccc4(0, 0, 0, 0);
|
||||||
bool committed = false;
|
bool committed = false;
|
||||||
};
|
};
|
||||||
|
@ -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->nameLabel->setLayoutOptions(AxisLayoutOptions::create()->setScaleLimits(.1f, .4f)->setScalePriority(1));
|
||||||
m_impl->nameMenu->addChild(m_impl->nameLabel);
|
m_impl->nameMenu->addChild(m_impl->nameLabel);
|
||||||
|
|
||||||
m_impl->errorLabel = CCLabelBMFont::create("", "bigFont.fnt");
|
m_impl->statusLabel = CCLabelBMFont::create("", "bigFont.fnt");
|
||||||
m_impl->errorLabel->setScale(.25f);
|
m_impl->statusLabel->setScale(.25f);
|
||||||
this->addChildAtPosition(m_impl->errorLabel, Anchor::Left, ccp(10, -10), ccp(0, .5f));
|
this->addChildAtPosition(m_impl->statusLabel, Anchor::Left, ccp(10, -10), ccp(0, .5f));
|
||||||
|
|
||||||
if (setting && setting->getDescription()) {
|
if (setting && setting->getDescription()) {
|
||||||
auto descSpr = CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png");
|
auto descSpr = CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png");
|
||||||
|
@ -111,7 +111,7 @@ bool SettingNodeV3::init(std::shared_ptr<SettingV3> setting, float width) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingNodeV3::updateState(CCNode* invoker) {
|
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->nameLabel->setColor(this->hasUncommittedChanges() ? ccc3(17, 221, 0) : ccWHITE);
|
||||||
m_impl->resetButton->setVisible(this->hasNonDefaultValue());
|
m_impl->resetButton->setVisible(this->hasNonDefaultValue());
|
||||||
|
@ -122,15 +122,15 @@ void SettingNodeV3::updateState(CCNode* invoker) {
|
||||||
if (m_impl->setting && !m_impl->setting->shouldEnable()) {
|
if (m_impl->setting && !m_impl->setting->shouldEnable()) {
|
||||||
if (auto desc = m_impl->setting->getEnableIfDescription()) {
|
if (auto desc = m_impl->setting->getEnableIfDescription()) {
|
||||||
m_impl->nameLabel->setColor(ccGRAY);
|
m_impl->nameLabel->setColor(ccGRAY);
|
||||||
m_impl->errorLabel->setVisible(true);
|
m_impl->statusLabel->setVisible(true);
|
||||||
m_impl->errorLabel->setColor("mod-list-errors-found"_cc3b);
|
m_impl->statusLabel->setColor("mod-list-errors-found"_cc3b);
|
||||||
m_impl->errorLabel->setString(desc->c_str());
|
m_impl->statusLabel->setString(desc->c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_impl->setting && m_impl->setting->requiresRestart() && m_impl->committed) {
|
if (m_impl->setting && m_impl->setting->requiresRestart() && m_impl->committed) {
|
||||||
m_impl->errorLabel->setVisible(true);
|
m_impl->statusLabel->setVisible(true);
|
||||||
m_impl->errorLabel->setColor("mod-list-restart-required-label"_cc3b);
|
m_impl->statusLabel->setColor("mod-list-restart-required-label"_cc3b);
|
||||||
m_impl->errorLabel->setString("Restart Required");
|
m_impl->statusLabel->setString("Restart Required");
|
||||||
m_impl->bg->setColor("mod-list-restart-required-label-bg"_cc3b);
|
m_impl->bg->setColor("mod-list-restart-required-label-bg"_cc3b);
|
||||||
m_impl->bg->setOpacity(75);
|
m_impl->bg->setOpacity(75);
|
||||||
}
|
}
|
||||||
|
@ -199,6 +199,9 @@ void SettingNodeV3::setContentSize(CCSize const& size) {
|
||||||
CCLabelBMFont* SettingNodeV3::getNameLabel() const {
|
CCLabelBMFont* SettingNodeV3::getNameLabel() const {
|
||||||
return m_impl->nameLabel;
|
return m_impl->nameLabel;
|
||||||
}
|
}
|
||||||
|
CCLabelBMFont* SettingNodeV3::getStatusLabel() const {
|
||||||
|
return m_impl->statusLabel;
|
||||||
|
}
|
||||||
CCMenu* SettingNodeV3::getNameMenu() const {
|
CCMenu* SettingNodeV3::getNameMenu() const {
|
||||||
return m_impl->nameMenu;
|
return m_impl->nameMenu;
|
||||||
}
|
}
|
||||||
|
@ -276,7 +279,7 @@ bool BoolSettingNodeV3::init(std::shared_ptr<BoolSettingV3> setting, float width
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoolSettingNodeV3::updateState(CCNode* invoker) {
|
void BoolSettingNodeV3::updateState(CCNode* invoker) {
|
||||||
SettingNodeV3::updateState(invoker);
|
SettingValueNodeV3::updateState(invoker);
|
||||||
auto enable = this->getSetting()->shouldEnable();
|
auto enable = this->getSetting()->shouldEnable();
|
||||||
m_toggle->toggle(this->getValue());
|
m_toggle->toggle(this->getValue());
|
||||||
m_toggle->setCascadeColorEnabled(true);
|
m_toggle->setCascadeColorEnabled(true);
|
||||||
|
@ -345,7 +348,7 @@ bool StringSettingNodeV3::init(std::shared_ptr<StringSettingV3> setting, float w
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringSettingNodeV3::updateState(CCNode* invoker) {
|
void StringSettingNodeV3::updateState(CCNode* invoker) {
|
||||||
SettingNodeV3::updateState(invoker);
|
SettingValueNodeV3::updateState(invoker);
|
||||||
|
|
||||||
if (invoker != m_input) {
|
if (invoker != m_input) {
|
||||||
m_input->setString(this->getValue());
|
m_input->setString(this->getValue());
|
||||||
|
@ -417,7 +420,7 @@ bool FileSettingNodeV3::init(std::shared_ptr<FileSettingV3> setting, float width
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSettingNodeV3::updateState(CCNode* invoker) {
|
void FileSettingNodeV3::updateState(CCNode* invoker) {
|
||||||
SettingNodeV3::updateState(invoker);
|
SettingValueNodeV3::updateState(invoker);
|
||||||
m_fileIcon->setDisplayFrame(CCSpriteFrameCache::get()->spriteFrameByName(
|
m_fileIcon->setDisplayFrame(CCSpriteFrameCache::get()->spriteFrameByName(
|
||||||
this->getSetting()->isFolder() ? "folderIcon_001.png" : "file.png"_spr
|
this->getSetting()->isFolder() ? "folderIcon_001.png" : "file.png"_spr
|
||||||
));
|
));
|
||||||
|
@ -502,7 +505,7 @@ bool Color3BSettingNodeV3::init(std::shared_ptr<Color3BSettingV3> setting, float
|
||||||
}
|
}
|
||||||
|
|
||||||
void Color3BSettingNodeV3::updateState(CCNode* invoker) {
|
void Color3BSettingNodeV3::updateState(CCNode* invoker) {
|
||||||
SettingNodeV3::updateState(invoker);
|
SettingValueNodeV3::updateState(invoker);
|
||||||
m_colorSprite->setColor(this->getValue());
|
m_colorSprite->setColor(this->getValue());
|
||||||
|
|
||||||
auto enable = this->getSetting()->shouldEnable();
|
auto enable = this->getSetting()->shouldEnable();
|
||||||
|
@ -549,7 +552,7 @@ bool Color4BSettingNodeV3::init(std::shared_ptr<Color4BSettingV3> setting, float
|
||||||
}
|
}
|
||||||
|
|
||||||
void Color4BSettingNodeV3::updateState(CCNode* invoker) {
|
void Color4BSettingNodeV3::updateState(CCNode* invoker) {
|
||||||
SettingNodeV3::updateState(invoker);
|
SettingValueNodeV3::updateState(invoker);
|
||||||
m_colorSprite->setColor(to3B(this->getValue()));
|
m_colorSprite->setColor(to3B(this->getValue()));
|
||||||
m_colorSprite->updateOpacity(this->getValue().a / 255.f);
|
m_colorSprite->updateOpacity(this->getValue().a / 255.f);
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateState(CCNode* invoker) override {
|
void updateState(CCNode* invoker) override {
|
||||||
SettingNodeV3::updateState(invoker);
|
SettingValueNodeV3<S>::updateState(invoker);
|
||||||
auto enable = this->getSetting()->shouldEnable();
|
auto enable = this->getSetting()->shouldEnable();
|
||||||
if (this->getSetting()->isInputEnabled()) {
|
if (this->getSetting()->isInputEnabled()) {
|
||||||
m_input->setEnabled(enable);
|
m_input->setEnabled(enable);
|
||||||
|
|
|
@ -482,7 +482,7 @@ void SettingV3::init(std::string const& key, std::string const& modID, JsonExpec
|
||||||
// Keys every setting must have
|
// Keys every setting must have
|
||||||
json.needs("type");
|
json.needs("type");
|
||||||
for (auto& plat : json.has("platforms").items()) {
|
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>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue