mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
int and float setting nodes
This commit is contained in:
parent
5263483b0a
commit
6ed6b32669
5 changed files with 442 additions and 148 deletions
|
@ -47,6 +47,10 @@ namespace geode {
|
||||||
* Get the name of this setting
|
* Get the name of this setting
|
||||||
*/
|
*/
|
||||||
std::optional<std::string> getName() const;
|
std::optional<std::string> getName() const;
|
||||||
|
/**
|
||||||
|
* Get the name of this setting, or its key if it has no name
|
||||||
|
*/
|
||||||
|
std::string getDisplayName() const;
|
||||||
/**
|
/**
|
||||||
* Get the description of this setting
|
* Get the description of this setting
|
||||||
*/
|
*/
|
||||||
|
@ -413,15 +417,16 @@ namespace geode {
|
||||||
* the value in some sort of global manager
|
* the value in some sort of global manager
|
||||||
*/
|
*/
|
||||||
virtual void onCommit() = 0;
|
virtual void onCommit() = 0;
|
||||||
|
virtual void onResetToDefault() = 0;
|
||||||
|
|
||||||
void onDescription(CCObject*);
|
void onDescription(CCObject*);
|
||||||
void onReset(CCObject*);
|
void onReset(CCObject*);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void commit();
|
void commit();
|
||||||
|
void resetToDefault();
|
||||||
virtual bool hasUncommittedChanges() const = 0;
|
virtual bool hasUncommittedChanges() const = 0;
|
||||||
virtual bool hasNonDefaultValue() const = 0;
|
virtual bool hasNonDefaultValue() const = 0;
|
||||||
virtual void resetToDefault() = 0;
|
|
||||||
|
|
||||||
cocos2d::CCLabelBMFont* getNameLabel() const;
|
cocos2d::CCLabelBMFont* getNameLabel() const;
|
||||||
cocos2d::CCMenu* getNameMenu() const;
|
cocos2d::CCMenu* getNameMenu() const;
|
||||||
|
|
|
@ -1,6 +1,27 @@
|
||||||
#include "SettingNodeV3.hpp"
|
#include "SettingNodeV3.hpp"
|
||||||
#include <Geode/loader/SettingNode.hpp>
|
#include <Geode/loader/SettingNode.hpp>
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
static float valueToSlider(std::shared_ptr<T> setting, typename T::ValueType value) {
|
||||||
|
auto min = setting->getMinValue().value_or(-100);
|
||||||
|
auto max = setting->getMaxValue().value_or(+100);
|
||||||
|
auto range = max - min;
|
||||||
|
return static_cast<float>(clamp(static_cast<double>(value - min) / range, 0.0, 1.0));
|
||||||
|
}
|
||||||
|
template<class T>
|
||||||
|
static typename T::ValueType valueFromSlider(std::shared_ptr<T> setting, float num) {
|
||||||
|
auto min = setting->getMinValue().value_or(-100);
|
||||||
|
auto max = setting->getMaxValue().value_or(+100);
|
||||||
|
auto range = max - min;
|
||||||
|
auto value = static_cast<typename T::ValueType>(num * range + min);
|
||||||
|
if (auto step = setting->getSliderSnap()) {
|
||||||
|
value = static_cast<typename T::ValueType>(
|
||||||
|
round(value / *step) * (*step)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
class SettingNodeSizeChangeEventV3::Impl final {
|
class SettingNodeSizeChangeEventV3::Impl final {
|
||||||
public:
|
public:
|
||||||
SettingNodeV3* node;
|
SettingNodeV3* node;
|
||||||
|
@ -52,10 +73,7 @@ bool SettingNodeV3::init(std::shared_ptr<SettingV3> setting, float width) {
|
||||||
m_impl->nameMenu = CCMenu::create();
|
m_impl->nameMenu = CCMenu::create();
|
||||||
m_impl->nameMenu->setContentWidth(width / 2 - 20);
|
m_impl->nameMenu->setContentWidth(width / 2 - 20);
|
||||||
|
|
||||||
m_impl->nameLabel = CCLabelBMFont::create(
|
m_impl->nameLabel = CCLabelBMFont::create(setting->getDisplayName().c_str(), "bigFont.fnt");
|
||||||
setting->getName().value_or(setting->getKey()).c_str(),
|
|
||||||
"bigFont.fnt"
|
|
||||||
);
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -96,7 +114,7 @@ void SettingNodeV3::updateState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingNodeV3::onDescription(CCObject*) {
|
void SettingNodeV3::onDescription(CCObject*) {
|
||||||
auto title = m_impl->setting->getName().value_or(m_impl->setting->getKey());
|
auto title = m_impl->setting->getDisplayName();
|
||||||
FLAlertLayer::create(
|
FLAlertLayer::create(
|
||||||
nullptr,
|
nullptr,
|
||||||
title.c_str(),
|
title.c_str(),
|
||||||
|
@ -106,8 +124,19 @@ void SettingNodeV3::onDescription(CCObject*) {
|
||||||
)->show();
|
)->show();
|
||||||
}
|
}
|
||||||
void SettingNodeV3::onReset(CCObject*) {
|
void SettingNodeV3::onReset(CCObject*) {
|
||||||
this->resetToDefault();
|
createQuickPopup(
|
||||||
this->updateState();
|
"Reset",
|
||||||
|
fmt::format(
|
||||||
|
"Are you sure you want to <cr>reset</c> <cl>{}</c> to <cy>default</c>?",
|
||||||
|
this->getSetting()->getDisplayName()
|
||||||
|
),
|
||||||
|
"Cancel", "Reset",
|
||||||
|
[this](auto, bool btn2) {
|
||||||
|
if (btn2) {
|
||||||
|
this->resetToDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingNodeV3::markChanged() {
|
void SettingNodeV3::markChanged() {
|
||||||
|
@ -119,6 +148,12 @@ void SettingNodeV3::commit() {
|
||||||
this->updateState();
|
this->updateState();
|
||||||
SettingNodeValueChangeEventV3(true).post();
|
SettingNodeValueChangeEventV3(true).post();
|
||||||
}
|
}
|
||||||
|
void SettingNodeV3::resetToDefault() {
|
||||||
|
m_impl->setting->reset();
|
||||||
|
this->onResetToDefault();
|
||||||
|
this->updateState();
|
||||||
|
SettingNodeValueChangeEventV3(false).post();
|
||||||
|
}
|
||||||
|
|
||||||
void SettingNodeV3::setContentSize(CCSize const& size) {
|
void SettingNodeV3::setContentSize(CCSize const& size) {
|
||||||
CCNode::setContentSize(size);
|
CCNode::setContentSize(size);
|
||||||
|
@ -156,6 +191,18 @@ bool TitleSettingNodeV3::init(std::shared_ptr<TitleSettingV3> setting, float wid
|
||||||
|
|
||||||
void TitleSettingNodeV3::onCommit() {}
|
void TitleSettingNodeV3::onCommit() {}
|
||||||
|
|
||||||
|
bool TitleSettingNodeV3::hasUncommittedChanges() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool TitleSettingNodeV3::hasNonDefaultValue() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void TitleSettingNodeV3::onResetToDefault() {}
|
||||||
|
|
||||||
|
std::shared_ptr<TitleSettingV3> TitleSettingNodeV3::getSetting() const {
|
||||||
|
return std::static_pointer_cast<TitleSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
}
|
||||||
|
|
||||||
TitleSettingNodeV3* TitleSettingNodeV3::create(std::shared_ptr<TitleSettingV3> setting, float width) {
|
TitleSettingNodeV3* TitleSettingNodeV3::create(std::shared_ptr<TitleSettingV3> setting, float width) {
|
||||||
auto ret = new TitleSettingNodeV3();
|
auto ret = new TitleSettingNodeV3();
|
||||||
if (ret && ret->init(setting, width)) {
|
if (ret && ret->init(setting, width)) {
|
||||||
|
@ -166,18 +213,6 @@ TitleSettingNodeV3* TitleSettingNodeV3::create(std::shared_ptr<TitleSettingV3> s
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TitleSettingNodeV3::hasUncommittedChanges() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool TitleSettingNodeV3::hasNonDefaultValue() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void TitleSettingNodeV3::resetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<TitleSettingV3> TitleSettingNodeV3::getSetting() const {
|
|
||||||
return std::static_pointer_cast<TitleSettingV3>(SettingNodeV3::getSetting());
|
|
||||||
}
|
|
||||||
|
|
||||||
// BoolSettingNodeV3
|
// BoolSettingNodeV3
|
||||||
|
|
||||||
bool BoolSettingNodeV3::init(std::shared_ptr<BoolSettingV3> setting, float width) {
|
bool BoolSettingNodeV3::init(std::shared_ptr<BoolSettingV3> setting, float width) {
|
||||||
|
@ -209,6 +244,20 @@ void BoolSettingNodeV3::onToggle(CCObject*) {
|
||||||
this->markChanged();
|
this->markChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BoolSettingNodeV3::hasUncommittedChanges() const {
|
||||||
|
return m_toggle->isToggled() != this->getSetting()->getValue();
|
||||||
|
}
|
||||||
|
bool BoolSettingNodeV3::hasNonDefaultValue() const {
|
||||||
|
return m_toggle->isToggled() != this->getSetting()->getDefaultValue();
|
||||||
|
}
|
||||||
|
void BoolSettingNodeV3::onResetToDefault() {
|
||||||
|
m_toggle->toggle(this->getSetting()->getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<BoolSettingV3> BoolSettingNodeV3::getSetting() const {
|
||||||
|
return std::static_pointer_cast<BoolSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
}
|
||||||
|
|
||||||
BoolSettingNodeV3* BoolSettingNodeV3::create(std::shared_ptr<BoolSettingV3> setting, float width) {
|
BoolSettingNodeV3* BoolSettingNodeV3::create(std::shared_ptr<BoolSettingV3> setting, float width) {
|
||||||
auto ret = new BoolSettingNodeV3();
|
auto ret = new BoolSettingNodeV3();
|
||||||
if (ret && ret->init(setting, width)) {
|
if (ret && ret->init(setting, width)) {
|
||||||
|
@ -219,33 +268,134 @@ BoolSettingNodeV3* BoolSettingNodeV3::create(std::shared_ptr<BoolSettingV3> sett
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BoolSettingNodeV3::hasUncommittedChanges() const {
|
|
||||||
return m_toggle->isToggled() != this->getSetting()->getValue();
|
|
||||||
}
|
|
||||||
bool BoolSettingNodeV3::hasNonDefaultValue() const {
|
|
||||||
return m_toggle->isToggled() != this->getSetting()->getDefaultValue();
|
|
||||||
}
|
|
||||||
void BoolSettingNodeV3::resetToDefault() {
|
|
||||||
this->getSetting()->reset();
|
|
||||||
m_toggle->toggle(this->getSetting()->getDefaultValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<BoolSettingV3> BoolSettingNodeV3::getSetting() const {
|
|
||||||
return std::static_pointer_cast<BoolSettingV3>(SettingNodeV3::getSetting());
|
|
||||||
}
|
|
||||||
|
|
||||||
// IntSettingNodeV3
|
// IntSettingNodeV3
|
||||||
|
|
||||||
bool IntSettingNodeV3::init(std::shared_ptr<IntSettingV3> setting, float width) {
|
bool IntSettingNodeV3::init(std::shared_ptr<IntSettingV3> setting, float width) {
|
||||||
if (!SettingNodeV3::init(setting, width))
|
if (!SettingNodeV3::init(setting, width))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
auto bigArrowLeftSpr = CCSprite::create();
|
||||||
|
auto bigArrowLeftSpr1 = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");
|
||||||
|
auto bigArrowLeftSpr2 = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");
|
||||||
|
|
||||||
// todo
|
bigArrowLeftSpr->setContentSize(bigArrowLeftSpr1->getContentSize() + ccp(20, 0));
|
||||||
|
bigArrowLeftSpr->addChildAtPosition(bigArrowLeftSpr2, Anchor::Center, ccp(10, 0));
|
||||||
|
bigArrowLeftSpr->addChildAtPosition(bigArrowLeftSpr1, Anchor::Center, ccp(-10, 0));
|
||||||
|
bigArrowLeftSpr->setScale(.45f);
|
||||||
|
|
||||||
|
auto bigArrowLeftBtn = CCMenuItemSpriteExtra::create(
|
||||||
|
bigArrowLeftSpr, this, menu_selector(IntSettingNodeV3::onArrow)
|
||||||
|
);
|
||||||
|
bigArrowLeftBtn->setTag(-setting->getBigArrowStepSize());
|
||||||
|
bigArrowLeftBtn->setVisible(setting->isBigArrowsEnabled());
|
||||||
|
this->getButtonMenu()->addChild(bigArrowLeftBtn);
|
||||||
|
|
||||||
|
auto arrowLeftSpr = CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png");
|
||||||
|
arrowLeftSpr->setScale(.65f);
|
||||||
|
auto arrowLeftBtn = CCMenuItemSpriteExtra::create(
|
||||||
|
arrowLeftSpr, this, menu_selector(IntSettingNodeV3::onArrow)
|
||||||
|
);
|
||||||
|
arrowLeftBtn->setTag(-setting->getArrowStepSize());
|
||||||
|
arrowLeftBtn->setVisible(setting->isArrowsEnabled());
|
||||||
|
this->getButtonMenu()->addChild(arrowLeftBtn);
|
||||||
|
|
||||||
|
m_input = TextInput::create(width / 2 - 70, "Num");
|
||||||
|
m_input->setCallback([this](auto const&) {
|
||||||
|
this->markChanged();
|
||||||
|
});
|
||||||
|
if (!setting->isInputEnabled()) {
|
||||||
|
m_input->getBGSprite()->setVisible(false);
|
||||||
|
m_input->setEnabled(false);
|
||||||
|
}
|
||||||
|
this->getButtonMenu()->addChild(m_input);
|
||||||
|
|
||||||
|
auto arrowRightSpr = CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png");
|
||||||
|
arrowRightSpr->setFlipX(true);
|
||||||
|
arrowRightSpr->setScale(.65f);
|
||||||
|
auto arrowRightBtn = CCMenuItemSpriteExtra::create(
|
||||||
|
arrowRightSpr, this, menu_selector(IntSettingNodeV3::onArrow)
|
||||||
|
);
|
||||||
|
arrowRightBtn->setTag(setting->getArrowStepSize());
|
||||||
|
arrowRightBtn->setVisible(setting->isArrowsEnabled());
|
||||||
|
this->getButtonMenu()->addChild(arrowRightBtn);
|
||||||
|
|
||||||
|
auto bigArrowRightSpr = CCSprite::create();
|
||||||
|
auto bigArrowRightSpr1 = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");
|
||||||
|
bigArrowRightSpr1->setFlipX(true);
|
||||||
|
auto bigArrowRightSpr2 = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");
|
||||||
|
bigArrowRightSpr2->setFlipX(true);
|
||||||
|
|
||||||
|
bigArrowRightSpr->setContentSize(bigArrowRightSpr1->getContentSize() + ccp(20, 0));
|
||||||
|
bigArrowRightSpr->addChildAtPosition(bigArrowRightSpr1, Anchor::Center, ccp(-10, 0));
|
||||||
|
bigArrowRightSpr->addChildAtPosition(bigArrowRightSpr2, Anchor::Center, ccp(10, 0));
|
||||||
|
bigArrowRightSpr->setScale(.45f);
|
||||||
|
|
||||||
|
auto bigArrowRightBtn = CCMenuItemSpriteExtra::create(
|
||||||
|
bigArrowRightSpr, this, menu_selector(IntSettingNodeV3::onArrow)
|
||||||
|
);
|
||||||
|
bigArrowRightBtn->setTag(setting->getBigArrowStepSize());
|
||||||
|
bigArrowRightBtn->setVisible(setting->isBigArrowsEnabled());
|
||||||
|
this->getButtonMenu()->addChild(bigArrowRightBtn);
|
||||||
|
|
||||||
|
if (setting->isSliderEnabled()) {
|
||||||
|
this->setContentHeight(45);
|
||||||
|
this->getButtonMenu()->updateAnchoredPosition(Anchor::Right, ccp(0, 7));
|
||||||
|
|
||||||
|
m_slider = Slider::create(this, menu_selector(IntSettingNodeV3::onSlider));
|
||||||
|
m_slider->setScale(.5f);
|
||||||
|
this->addChildAtPosition(m_slider, Anchor::Right, ccp(-75, -12), ccp(0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
this->setCurrentValue(setting->getValue());
|
||||||
|
this->getButtonMenu()->updateLayout();
|
||||||
|
this->updateState();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntSettingNodeV3::onCommit() {}
|
void IntSettingNodeV3::updateState() {
|
||||||
|
SettingNodeV3::updateState();
|
||||||
|
m_slider->m_touchLogic->m_thumb->setValue(valueToSlider(
|
||||||
|
this->getSetting(), this->getCurrentValue()
|
||||||
|
));
|
||||||
|
m_slider->updateBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t IntSettingNodeV3::getCurrentValue() const {
|
||||||
|
return numFromString<int64_t>(m_input->getString()).value_or(this->getSetting()->getDefaultValue());
|
||||||
|
}
|
||||||
|
void IntSettingNodeV3::setCurrentValue(int64_t value) {
|
||||||
|
m_input->setString(std::to_string(value));
|
||||||
|
this->markChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntSettingNodeV3::onCommit() {
|
||||||
|
this->getSetting()->setValue(this->getCurrentValue());
|
||||||
|
}
|
||||||
|
void IntSettingNodeV3::onArrow(CCObject* sender) {
|
||||||
|
this->setCurrentValue(this->getCurrentValue() + sender->getTag());
|
||||||
|
this->updateState();
|
||||||
|
}
|
||||||
|
void IntSettingNodeV3::onSlider(CCObject* sender) {
|
||||||
|
this->setCurrentValue(valueFromSlider(
|
||||||
|
this->getSetting(),
|
||||||
|
m_slider->m_touchLogic->m_thumb->getValue()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IntSettingNodeV3::hasUncommittedChanges() const {
|
||||||
|
return this->getSetting()->getValue() != this->getCurrentValue();
|
||||||
|
}
|
||||||
|
bool IntSettingNodeV3::hasNonDefaultValue() const {
|
||||||
|
return this->getSetting()->getDefaultValue() != this->getCurrentValue();
|
||||||
|
}
|
||||||
|
void IntSettingNodeV3::onResetToDefault() {
|
||||||
|
this->setCurrentValue(this->getSetting()->getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<IntSettingV3> IntSettingNodeV3::getSetting() const {
|
||||||
|
return std::static_pointer_cast<IntSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
}
|
||||||
|
|
||||||
IntSettingNodeV3* IntSettingNodeV3::create(std::shared_ptr<IntSettingV3> setting, float width) {
|
IntSettingNodeV3* IntSettingNodeV3::create(std::shared_ptr<IntSettingV3> setting, float width) {
|
||||||
auto ret = new IntSettingNodeV3();
|
auto ret = new IntSettingNodeV3();
|
||||||
|
@ -257,30 +407,133 @@ IntSettingNodeV3* IntSettingNodeV3::create(std::shared_ptr<IntSettingV3> setting
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IntSettingNodeV3::hasUncommittedChanges() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool IntSettingNodeV3::hasNonDefaultValue() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void IntSettingNodeV3::resetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<IntSettingV3> IntSettingNodeV3::getSetting() const {
|
|
||||||
return std::static_pointer_cast<IntSettingV3>(SettingNodeV3::getSetting());
|
|
||||||
}
|
|
||||||
|
|
||||||
// FloatSettingNodeV3
|
// FloatSettingNodeV3
|
||||||
|
|
||||||
bool FloatSettingNodeV3::init(std::shared_ptr<FloatSettingV3> setting, float width) {
|
bool FloatSettingNodeV3::init(std::shared_ptr<FloatSettingV3> setting, float width) {
|
||||||
if (!SettingNodeV3::init(setting, width))
|
if (!SettingNodeV3::init(setting, width))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// todo
|
auto bigArrowLeftSpr = CCSprite::create();
|
||||||
|
auto bigArrowLeftSpr1 = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");
|
||||||
|
auto bigArrowLeftSpr2 = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");
|
||||||
|
|
||||||
|
bigArrowLeftSpr->setContentSize(bigArrowLeftSpr1->getContentSize() + ccp(20, 0));
|
||||||
|
bigArrowLeftSpr->addChildAtPosition(bigArrowLeftSpr2, Anchor::Center, ccp(10, 0));
|
||||||
|
bigArrowLeftSpr->addChildAtPosition(bigArrowLeftSpr1, Anchor::Center, ccp(-10, 0));
|
||||||
|
bigArrowLeftSpr->setScale(.45f);
|
||||||
|
|
||||||
|
auto bigArrowLeftBtn = CCMenuItemSpriteExtra::create(
|
||||||
|
bigArrowLeftSpr, this, menu_selector(FloatSettingNodeV3::onArrow)
|
||||||
|
);
|
||||||
|
bigArrowLeftBtn->setTag(-setting->getBigArrowStepSize());
|
||||||
|
bigArrowLeftBtn->setVisible(setting->isBigArrowsEnabled());
|
||||||
|
this->getButtonMenu()->addChild(bigArrowLeftBtn);
|
||||||
|
|
||||||
|
auto arrowLeftSpr = CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png");
|
||||||
|
arrowLeftSpr->setScale(.65f);
|
||||||
|
auto arrowLeftBtn = CCMenuItemSpriteExtra::create(
|
||||||
|
arrowLeftSpr, this, menu_selector(FloatSettingNodeV3::onArrow)
|
||||||
|
);
|
||||||
|
arrowLeftBtn->setTag(-setting->getArrowStepSize());
|
||||||
|
arrowLeftBtn->setVisible(setting->isArrowsEnabled());
|
||||||
|
this->getButtonMenu()->addChild(arrowLeftBtn);
|
||||||
|
|
||||||
|
m_input = TextInput::create(width / 2 - 70, "Num");
|
||||||
|
m_input->setCallback([this](auto const&) {
|
||||||
|
this->markChanged();
|
||||||
|
});
|
||||||
|
if (!setting->isInputEnabled()) {
|
||||||
|
m_input->getBGSprite()->setVisible(false);
|
||||||
|
m_input->setEnabled(false);
|
||||||
|
}
|
||||||
|
this->getButtonMenu()->addChild(m_input);
|
||||||
|
|
||||||
|
auto arrowRightSpr = CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png");
|
||||||
|
arrowRightSpr->setFlipX(true);
|
||||||
|
arrowRightSpr->setScale(.65f);
|
||||||
|
auto arrowRightBtn = CCMenuItemSpriteExtra::create(
|
||||||
|
arrowRightSpr, this, menu_selector(FloatSettingNodeV3::onArrow)
|
||||||
|
);
|
||||||
|
arrowRightBtn->setTag(setting->getArrowStepSize());
|
||||||
|
arrowRightBtn->setVisible(setting->isArrowsEnabled());
|
||||||
|
this->getButtonMenu()->addChild(arrowRightBtn);
|
||||||
|
|
||||||
|
auto bigArrowRightSpr = CCSprite::create();
|
||||||
|
auto bigArrowRightSpr1 = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");
|
||||||
|
bigArrowRightSpr1->setFlipX(true);
|
||||||
|
auto bigArrowRightSpr2 = CCSprite::createWithSpriteFrameName("GJ_arrow_03_001.png");
|
||||||
|
bigArrowRightSpr2->setFlipX(true);
|
||||||
|
|
||||||
|
bigArrowRightSpr->setContentSize(bigArrowRightSpr1->getContentSize() + ccp(20, 0));
|
||||||
|
bigArrowRightSpr->addChildAtPosition(bigArrowRightSpr1, Anchor::Center, ccp(-10, 0));
|
||||||
|
bigArrowRightSpr->addChildAtPosition(bigArrowRightSpr2, Anchor::Center, ccp(10, 0));
|
||||||
|
bigArrowRightSpr->setScale(.45f);
|
||||||
|
|
||||||
|
auto bigArrowRightBtn = CCMenuItemSpriteExtra::create(
|
||||||
|
bigArrowRightSpr, this, menu_selector(FloatSettingNodeV3::onArrow)
|
||||||
|
);
|
||||||
|
bigArrowRightBtn->setTag(setting->getBigArrowStepSize());
|
||||||
|
bigArrowRightBtn->setVisible(setting->isBigArrowsEnabled());
|
||||||
|
this->getButtonMenu()->addChild(bigArrowRightBtn);
|
||||||
|
|
||||||
|
if (setting->isSliderEnabled()) {
|
||||||
|
this->setContentHeight(45);
|
||||||
|
this->getButtonMenu()->updateAnchoredPosition(Anchor::Right, ccp(0, 7));
|
||||||
|
|
||||||
|
m_slider = Slider::create(this, menu_selector(FloatSettingNodeV3::onSlider));
|
||||||
|
m_slider->setScale(.5f);
|
||||||
|
this->addChildAtPosition(m_slider, Anchor::Right, ccp(-75, -12), ccp(0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
this->setCurrentValue(setting->getValue());
|
||||||
|
this->getButtonMenu()->updateLayout();
|
||||||
|
this->updateState();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatSettingNodeV3::onCommit() {}
|
void FloatSettingNodeV3::updateState() {
|
||||||
|
SettingNodeV3::updateState();
|
||||||
|
m_slider->m_touchLogic->m_thumb->setValue(valueToSlider(
|
||||||
|
this->getSetting(), this->getCurrentValue()
|
||||||
|
));
|
||||||
|
m_slider->updateBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
double FloatSettingNodeV3::getCurrentValue() const {
|
||||||
|
return numFromString<double>(m_input->getString()).value_or(this->getSetting()->getDefaultValue());
|
||||||
|
}
|
||||||
|
void FloatSettingNodeV3::setCurrentValue(double value) {
|
||||||
|
m_input->setString(numToString(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void FloatSettingNodeV3::onCommit() {
|
||||||
|
this->getSetting()->setValue(this->getCurrentValue());
|
||||||
|
}
|
||||||
|
void FloatSettingNodeV3::onArrow(CCObject* sender) {
|
||||||
|
this->setCurrentValue(this->getCurrentValue() + sender->getTag());
|
||||||
|
this->updateState();
|
||||||
|
}
|
||||||
|
void FloatSettingNodeV3::onSlider(CCObject* sender) {
|
||||||
|
this->setCurrentValue(valueFromSlider(
|
||||||
|
this->getSetting(),
|
||||||
|
m_slider->m_touchLogic->m_thumb->getValue()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FloatSettingNodeV3::hasUncommittedChanges() const {
|
||||||
|
return this->getSetting()->getValue() != this->getCurrentValue();
|
||||||
|
}
|
||||||
|
bool FloatSettingNodeV3::hasNonDefaultValue() const {
|
||||||
|
return this->getSetting()->getDefaultValue() != this->getCurrentValue();
|
||||||
|
}
|
||||||
|
void FloatSettingNodeV3::onResetToDefault() {
|
||||||
|
this->setCurrentValue(this->getSetting()->getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<FloatSettingV3> FloatSettingNodeV3::getSetting() const {
|
||||||
|
return std::static_pointer_cast<FloatSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
}
|
||||||
|
|
||||||
FloatSettingNodeV3* FloatSettingNodeV3::create(std::shared_ptr<FloatSettingV3> setting, float width) {
|
FloatSettingNodeV3* FloatSettingNodeV3::create(std::shared_ptr<FloatSettingV3> setting, float width) {
|
||||||
auto ret = new FloatSettingNodeV3();
|
auto ret = new FloatSettingNodeV3();
|
||||||
|
@ -292,18 +545,6 @@ FloatSettingNodeV3* FloatSettingNodeV3::create(std::shared_ptr<FloatSettingV3> s
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FloatSettingNodeV3::hasUncommittedChanges() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool FloatSettingNodeV3::hasNonDefaultValue() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void FloatSettingNodeV3::resetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<FloatSettingV3> FloatSettingNodeV3::getSetting() const {
|
|
||||||
return std::static_pointer_cast<FloatSettingV3>(SettingNodeV3::getSetting());
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringSettingNodeV3
|
// StringSettingNodeV3
|
||||||
|
|
||||||
bool StringSettingNodeV3::init(std::shared_ptr<StringSettingV3> setting, float width) {
|
bool StringSettingNodeV3::init(std::shared_ptr<StringSettingV3> setting, float width) {
|
||||||
|
@ -317,6 +558,18 @@ bool StringSettingNodeV3::init(std::shared_ptr<StringSettingV3> setting, float w
|
||||||
|
|
||||||
void StringSettingNodeV3::onCommit() {}
|
void StringSettingNodeV3::onCommit() {}
|
||||||
|
|
||||||
|
bool StringSettingNodeV3::hasUncommittedChanges() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool StringSettingNodeV3::hasNonDefaultValue() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void StringSettingNodeV3::onResetToDefault() {}
|
||||||
|
|
||||||
|
std::shared_ptr<StringSettingV3> StringSettingNodeV3::getSetting() const {
|
||||||
|
return std::static_pointer_cast<StringSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
}
|
||||||
|
|
||||||
StringSettingNodeV3* StringSettingNodeV3::create(std::shared_ptr<StringSettingV3> setting, float width) {
|
StringSettingNodeV3* StringSettingNodeV3::create(std::shared_ptr<StringSettingV3> setting, float width) {
|
||||||
auto ret = new StringSettingNodeV3();
|
auto ret = new StringSettingNodeV3();
|
||||||
if (ret && ret->init(setting, width)) {
|
if (ret && ret->init(setting, width)) {
|
||||||
|
@ -327,18 +580,6 @@ StringSettingNodeV3* StringSettingNodeV3::create(std::shared_ptr<StringSettingV3
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringSettingNodeV3::hasUncommittedChanges() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool StringSettingNodeV3::hasNonDefaultValue() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void StringSettingNodeV3::resetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<StringSettingV3> StringSettingNodeV3::getSetting() const {
|
|
||||||
return std::static_pointer_cast<StringSettingV3>(SettingNodeV3::getSetting());
|
|
||||||
}
|
|
||||||
|
|
||||||
// FileSettingNodeV3
|
// FileSettingNodeV3
|
||||||
|
|
||||||
bool FileSettingNodeV3::init(std::shared_ptr<FileSettingV3> setting, float width) {
|
bool FileSettingNodeV3::init(std::shared_ptr<FileSettingV3> setting, float width) {
|
||||||
|
@ -352,6 +593,18 @@ bool FileSettingNodeV3::init(std::shared_ptr<FileSettingV3> setting, float width
|
||||||
|
|
||||||
void FileSettingNodeV3::onCommit() {}
|
void FileSettingNodeV3::onCommit() {}
|
||||||
|
|
||||||
|
bool FileSettingNodeV3::hasUncommittedChanges() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool FileSettingNodeV3::hasNonDefaultValue() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void FileSettingNodeV3::onResetToDefault() {}
|
||||||
|
|
||||||
|
std::shared_ptr<FileSettingV3> FileSettingNodeV3::getSetting() const {
|
||||||
|
return std::static_pointer_cast<FileSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
}
|
||||||
|
|
||||||
FileSettingNodeV3* FileSettingNodeV3::create(std::shared_ptr<FileSettingV3> setting, float width) {
|
FileSettingNodeV3* FileSettingNodeV3::create(std::shared_ptr<FileSettingV3> setting, float width) {
|
||||||
auto ret = new FileSettingNodeV3();
|
auto ret = new FileSettingNodeV3();
|
||||||
if (ret && ret->init(setting, width)) {
|
if (ret && ret->init(setting, width)) {
|
||||||
|
@ -362,18 +615,6 @@ FileSettingNodeV3* FileSettingNodeV3::create(std::shared_ptr<FileSettingV3> sett
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileSettingNodeV3::hasUncommittedChanges() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool FileSettingNodeV3::hasNonDefaultValue() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void FileSettingNodeV3::resetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<FileSettingV3> FileSettingNodeV3::getSetting() const {
|
|
||||||
return std::static_pointer_cast<FileSettingV3>(SettingNodeV3::getSetting());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Color3BSettingNodeV3
|
// Color3BSettingNodeV3
|
||||||
|
|
||||||
bool Color3BSettingNodeV3::init(std::shared_ptr<Color3BSettingV3> setting, float width) {
|
bool Color3BSettingNodeV3::init(std::shared_ptr<Color3BSettingV3> setting, float width) {
|
||||||
|
@ -387,6 +628,18 @@ bool Color3BSettingNodeV3::init(std::shared_ptr<Color3BSettingV3> setting, float
|
||||||
|
|
||||||
void Color3BSettingNodeV3::onCommit() {}
|
void Color3BSettingNodeV3::onCommit() {}
|
||||||
|
|
||||||
|
bool Color3BSettingNodeV3::hasUncommittedChanges() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool Color3BSettingNodeV3::hasNonDefaultValue() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void Color3BSettingNodeV3::onResetToDefault() {}
|
||||||
|
|
||||||
|
std::shared_ptr<Color3BSettingV3> Color3BSettingNodeV3::getSetting() const {
|
||||||
|
return std::static_pointer_cast<Color3BSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
}
|
||||||
|
|
||||||
Color3BSettingNodeV3* Color3BSettingNodeV3::create(std::shared_ptr<Color3BSettingV3> setting, float width) {
|
Color3BSettingNodeV3* Color3BSettingNodeV3::create(std::shared_ptr<Color3BSettingV3> setting, float width) {
|
||||||
auto ret = new Color3BSettingNodeV3();
|
auto ret = new Color3BSettingNodeV3();
|
||||||
if (ret && ret->init(setting, width)) {
|
if (ret && ret->init(setting, width)) {
|
||||||
|
@ -397,18 +650,6 @@ Color3BSettingNodeV3* Color3BSettingNodeV3::create(std::shared_ptr<Color3BSettin
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Color3BSettingNodeV3::hasUncommittedChanges() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool Color3BSettingNodeV3::hasNonDefaultValue() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void Color3BSettingNodeV3::resetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<Color3BSettingV3> Color3BSettingNodeV3::getSetting() const {
|
|
||||||
return std::static_pointer_cast<Color3BSettingV3>(SettingNodeV3::getSetting());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Color4BSettingNodeV3
|
// Color4BSettingNodeV3
|
||||||
|
|
||||||
bool Color4BSettingNodeV3::init(std::shared_ptr<Color4BSettingV3> setting, float width) {
|
bool Color4BSettingNodeV3::init(std::shared_ptr<Color4BSettingV3> setting, float width) {
|
||||||
|
@ -422,6 +663,18 @@ bool Color4BSettingNodeV3::init(std::shared_ptr<Color4BSettingV3> setting, float
|
||||||
|
|
||||||
void Color4BSettingNodeV3::onCommit() {}
|
void Color4BSettingNodeV3::onCommit() {}
|
||||||
|
|
||||||
|
bool Color4BSettingNodeV3::hasUncommittedChanges() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool Color4BSettingNodeV3::hasNonDefaultValue() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void Color4BSettingNodeV3::onResetToDefault() {}
|
||||||
|
|
||||||
|
std::shared_ptr<Color4BSettingV3> Color4BSettingNodeV3::getSetting() const {
|
||||||
|
return std::static_pointer_cast<Color4BSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
}
|
||||||
|
|
||||||
Color4BSettingNodeV3* Color4BSettingNodeV3::create(std::shared_ptr<Color4BSettingV3> setting, float width) {
|
Color4BSettingNodeV3* Color4BSettingNodeV3::create(std::shared_ptr<Color4BSettingV3> setting, float width) {
|
||||||
auto ret = new Color4BSettingNodeV3();
|
auto ret = new Color4BSettingNodeV3();
|
||||||
if (ret && ret->init(setting, width)) {
|
if (ret && ret->init(setting, width)) {
|
||||||
|
@ -432,18 +685,6 @@ Color4BSettingNodeV3* Color4BSettingNodeV3::create(std::shared_ptr<Color4BSettin
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Color4BSettingNodeV3::hasUncommittedChanges() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool Color4BSettingNodeV3::hasNonDefaultValue() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void Color4BSettingNodeV3::resetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<Color4BSettingV3> Color4BSettingNodeV3::getSetting() const {
|
|
||||||
return std::static_pointer_cast<Color4BSettingV3>(SettingNodeV3::getSetting());
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnresolvedCustomSettingNodeV3
|
// UnresolvedCustomSettingNodeV3
|
||||||
|
|
||||||
bool UnresolvedCustomSettingNodeV3::init(std::shared_ptr<LegacyCustomSettingV3> setting, float width) {
|
bool UnresolvedCustomSettingNodeV3::init(std::shared_ptr<LegacyCustomSettingV3> setting, float width) {
|
||||||
|
@ -464,6 +705,18 @@ bool UnresolvedCustomSettingNodeV3::init(std::shared_ptr<LegacyCustomSettingV3>
|
||||||
|
|
||||||
void UnresolvedCustomSettingNodeV3::onCommit() {}
|
void UnresolvedCustomSettingNodeV3::onCommit() {}
|
||||||
|
|
||||||
|
bool UnresolvedCustomSettingNodeV3::hasUncommittedChanges() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool UnresolvedCustomSettingNodeV3::hasNonDefaultValue() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void UnresolvedCustomSettingNodeV3::onResetToDefault() {}
|
||||||
|
|
||||||
|
std::shared_ptr<LegacyCustomSettingV3> UnresolvedCustomSettingNodeV3::getSetting() const {
|
||||||
|
return std::static_pointer_cast<LegacyCustomSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
}
|
||||||
|
|
||||||
UnresolvedCustomSettingNodeV3* UnresolvedCustomSettingNodeV3::create(std::shared_ptr<LegacyCustomSettingV3> setting, float width) {
|
UnresolvedCustomSettingNodeV3* UnresolvedCustomSettingNodeV3::create(std::shared_ptr<LegacyCustomSettingV3> setting, float width) {
|
||||||
auto ret = new UnresolvedCustomSettingNodeV3();
|
auto ret = new UnresolvedCustomSettingNodeV3();
|
||||||
if (ret && ret->init(setting, width)) {
|
if (ret && ret->init(setting, width)) {
|
||||||
|
@ -474,18 +727,6 @@ UnresolvedCustomSettingNodeV3* UnresolvedCustomSettingNodeV3::create(std::shared
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UnresolvedCustomSettingNodeV3::hasUncommittedChanges() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool UnresolvedCustomSettingNodeV3::hasNonDefaultValue() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
void UnresolvedCustomSettingNodeV3::resetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<LegacyCustomSettingV3> UnresolvedCustomSettingNodeV3::getSetting() const {
|
|
||||||
return std::static_pointer_cast<LegacyCustomSettingV3>(SettingNodeV3::getSetting());
|
|
||||||
}
|
|
||||||
|
|
||||||
// LegacyCustomSettingToV3Node
|
// LegacyCustomSettingToV3Node
|
||||||
|
|
||||||
bool LegacyCustomSettingToV3Node::init(std::shared_ptr<LegacyCustomSettingV3> original, float width) {
|
bool LegacyCustomSettingToV3Node::init(std::shared_ptr<LegacyCustomSettingV3> original, float width) {
|
||||||
|
@ -503,6 +744,16 @@ void LegacyCustomSettingToV3Node::onCommit() {
|
||||||
m_original->commit();
|
m_original->commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LegacyCustomSettingToV3Node::hasUncommittedChanges() const {
|
||||||
|
return m_original->hasUncommittedChanges();
|
||||||
|
}
|
||||||
|
bool LegacyCustomSettingToV3Node::hasNonDefaultValue() const {
|
||||||
|
return m_original->hasNonDefaultValue();
|
||||||
|
}
|
||||||
|
void LegacyCustomSettingToV3Node::onResetToDefault() {
|
||||||
|
m_original->resetToDefault();
|
||||||
|
}
|
||||||
|
|
||||||
LegacyCustomSettingToV3Node* LegacyCustomSettingToV3Node::create(std::shared_ptr<LegacyCustomSettingV3> original, float width) {
|
LegacyCustomSettingToV3Node* LegacyCustomSettingToV3Node::create(std::shared_ptr<LegacyCustomSettingV3> original, float width) {
|
||||||
auto ret = new LegacyCustomSettingToV3Node();
|
auto ret = new LegacyCustomSettingToV3Node();
|
||||||
if (ret && ret->init(original, width)) {
|
if (ret && ret->init(original, width)) {
|
||||||
|
@ -512,13 +763,3 @@ LegacyCustomSettingToV3Node* LegacyCustomSettingToV3Node::create(std::shared_ptr
|
||||||
CC_SAFE_DELETE(ret);
|
CC_SAFE_DELETE(ret);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyCustomSettingToV3Node::hasUncommittedChanges() const {
|
|
||||||
return m_original->hasUncommittedChanges();
|
|
||||||
}
|
|
||||||
bool LegacyCustomSettingToV3Node::hasNonDefaultValue() const {
|
|
||||||
return m_original->hasNonDefaultValue();
|
|
||||||
}
|
|
||||||
void LegacyCustomSettingToV3Node::resetToDefault() {
|
|
||||||
m_original->resetToDefault();
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
|
|
||||||
std::shared_ptr<TitleSettingV3> getSetting() const;
|
std::shared_ptr<TitleSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
@ -32,7 +32,6 @@ protected:
|
||||||
bool init(std::shared_ptr<BoolSettingV3> setting, float width);
|
bool init(std::shared_ptr<BoolSettingV3> setting, float width);
|
||||||
|
|
||||||
void onCommit() override;
|
void onCommit() override;
|
||||||
|
|
||||||
void onToggle(CCObject*);
|
void onToggle(CCObject*);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -40,39 +39,59 @@ public:
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
|
|
||||||
std::shared_ptr<BoolSettingV3> getSetting() const;
|
std::shared_ptr<BoolSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IntSettingNodeV3 : public SettingNodeV3 {
|
class IntSettingNodeV3 : public SettingNodeV3 {
|
||||||
protected:
|
protected:
|
||||||
|
TextInput* m_input;
|
||||||
|
Slider* m_slider;
|
||||||
|
|
||||||
bool init(std::shared_ptr<IntSettingV3> setting, float width);
|
bool init(std::shared_ptr<IntSettingV3> setting, float width);
|
||||||
|
|
||||||
|
void updateState() override;
|
||||||
|
|
||||||
void onCommit() override;
|
void onCommit() override;
|
||||||
|
void onArrow(CCObject* sender);
|
||||||
|
void onSlider(CCObject*);
|
||||||
|
|
||||||
|
int64_t getCurrentValue() const;
|
||||||
|
void setCurrentValue(int64_t value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static IntSettingNodeV3* create(std::shared_ptr<IntSettingV3> setting, float width);
|
static IntSettingNodeV3* create(std::shared_ptr<IntSettingV3> setting, float width);
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
|
|
||||||
std::shared_ptr<IntSettingV3> getSetting() const;
|
std::shared_ptr<IntSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FloatSettingNodeV3 : public SettingNodeV3 {
|
class FloatSettingNodeV3 : public SettingNodeV3 {
|
||||||
protected:
|
protected:
|
||||||
|
TextInput* m_input;
|
||||||
|
Slider* m_slider;
|
||||||
|
|
||||||
bool init(std::shared_ptr<FloatSettingV3> setting, float width);
|
bool init(std::shared_ptr<FloatSettingV3> setting, float width);
|
||||||
|
|
||||||
|
void updateState() override;
|
||||||
|
|
||||||
void onCommit() override;
|
void onCommit() override;
|
||||||
|
void onArrow(CCObject* sender);
|
||||||
|
void onSlider(CCObject*);
|
||||||
|
|
||||||
|
double getCurrentValue() const;
|
||||||
|
void setCurrentValue(double value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static FloatSettingNodeV3* create(std::shared_ptr<FloatSettingV3> setting, float width);
|
static FloatSettingNodeV3* create(std::shared_ptr<FloatSettingV3> setting, float width);
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
|
|
||||||
std::shared_ptr<FloatSettingV3> getSetting() const;
|
std::shared_ptr<FloatSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
@ -88,7 +107,7 @@ public:
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
|
|
||||||
std::shared_ptr<StringSettingV3> getSetting() const;
|
std::shared_ptr<StringSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
@ -104,7 +123,7 @@ public:
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
|
|
||||||
std::shared_ptr<FileSettingV3> getSetting() const;
|
std::shared_ptr<FileSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
@ -120,7 +139,7 @@ public:
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
|
|
||||||
std::shared_ptr<Color3BSettingV3> getSetting() const;
|
std::shared_ptr<Color3BSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
@ -136,7 +155,7 @@ public:
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
|
|
||||||
std::shared_ptr<Color4BSettingV3> getSetting() const;
|
std::shared_ptr<Color4BSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
@ -152,7 +171,7 @@ public:
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
|
|
||||||
std::shared_ptr<LegacyCustomSettingV3> getSetting() const;
|
std::shared_ptr<LegacyCustomSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
@ -172,5 +191,5 @@ public:
|
||||||
|
|
||||||
bool hasUncommittedChanges() const override;
|
bool hasUncommittedChanges() const override;
|
||||||
bool hasNonDefaultValue() const override;
|
bool hasNonDefaultValue() const override;
|
||||||
void resetToDefault() override;
|
void onResetToDefault() override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,6 +47,9 @@ std::string SettingV3::getModID() const {
|
||||||
std::optional<std::string> SettingV3::getName() const {
|
std::optional<std::string> SettingV3::getName() const {
|
||||||
return m_impl->name;
|
return m_impl->name;
|
||||||
}
|
}
|
||||||
|
std::string SettingV3::getDisplayName() const {
|
||||||
|
return m_impl->name.value_or(m_impl->key);
|
||||||
|
}
|
||||||
std::optional<std::string> SettingV3::getDescription() const {
|
std::optional<std::string> SettingV3::getDescription() const {
|
||||||
return m_impl->description;
|
return m_impl->description;
|
||||||
}
|
}
|
||||||
|
@ -217,11 +220,11 @@ public:
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
// 0 means not enabled
|
// 0 means not enabled
|
||||||
size_t arrowStepSize;
|
size_t arrowStepSize = 1;
|
||||||
size_t bigArrowStepSize;
|
size_t bigArrowStepSize = 5;
|
||||||
bool sliderEnabled;
|
bool sliderEnabled = true;
|
||||||
std::optional<int64_t> sliderSnap;
|
std::optional<int64_t> sliderSnap;
|
||||||
bool textInputEnabled;
|
bool textInputEnabled = true;
|
||||||
} controls;
|
} controls;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -247,6 +250,18 @@ Result<std::shared_ptr<IntSettingV3>> IntSettingV3::parse(std::string const& key
|
||||||
controls.has("slider").into(ret->m_impl->controls.sliderEnabled);
|
controls.has("slider").into(ret->m_impl->controls.sliderEnabled);
|
||||||
controls.has("slider-step").into(ret->m_impl->controls.sliderSnap);
|
controls.has("slider-step").into(ret->m_impl->controls.sliderSnap);
|
||||||
controls.has("input").into(ret->m_impl->controls.textInputEnabled);
|
controls.has("input").into(ret->m_impl->controls.textInputEnabled);
|
||||||
|
// Without "min" or "max" slider makes no sense
|
||||||
|
if (!ret->m_impl->minValue || !ret->m_impl->maxValue) {
|
||||||
|
if (ret->m_impl->controls.sliderEnabled) {
|
||||||
|
log::warn(
|
||||||
|
"Setting '{}' has \"controls.slider\" enabled but doesn't "
|
||||||
|
"have both \"min\" and \"max\" defined - the slider has "
|
||||||
|
"been force-disabled!",
|
||||||
|
key
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ret->m_impl->controls.sliderEnabled = false;
|
||||||
|
}
|
||||||
controls.checkUnknownKeys();
|
controls.checkUnknownKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,6 +396,18 @@ Result<std::shared_ptr<FloatSettingV3>> FloatSettingV3::parse(std::string const&
|
||||||
controls.has("slider").into(ret->m_impl->controls.sliderEnabled);
|
controls.has("slider").into(ret->m_impl->controls.sliderEnabled);
|
||||||
controls.has("slider-step").into(ret->m_impl->controls.sliderSnap);
|
controls.has("slider-step").into(ret->m_impl->controls.sliderSnap);
|
||||||
controls.has("input").into(ret->m_impl->controls.textInputEnabled);
|
controls.has("input").into(ret->m_impl->controls.textInputEnabled);
|
||||||
|
// Without "min" or "max" slider makes no sense
|
||||||
|
if (!ret->m_impl->minValue || !ret->m_impl->maxValue) {
|
||||||
|
if (ret->m_impl->controls.sliderEnabled) {
|
||||||
|
log::warn(
|
||||||
|
"Setting '{}' has \"controls.slider\" enabled but doesn't "
|
||||||
|
"have both \"min\" and \"max\" defined - the slider has "
|
||||||
|
"been force-disabled!",
|
||||||
|
key
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ret->m_impl->controls.sliderEnabled = false;
|
||||||
|
}
|
||||||
controls.checkUnknownKeys();
|
controls.checkUnknownKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,8 @@ void ModSettingsPopup::onResetAll(CCObject*) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModSettingsPopup::updateState() {
|
void ModSettingsPopup::updateState() {
|
||||||
|
m_applyBtnSpr->setCascadeColorEnabled(true);
|
||||||
|
m_applyBtnSpr->setCascadeOpacityEnabled(true);
|
||||||
if (this->hasUncommitted()) {
|
if (this->hasUncommitted()) {
|
||||||
m_applyBtnSpr->setColor(ccWHITE);
|
m_applyBtnSpr->setColor(ccWHITE);
|
||||||
m_applyBtnSpr->setOpacity(255);
|
m_applyBtnSpr->setOpacity(255);
|
||||||
|
|
Loading…
Reference in a new issue