mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
revert one-of
This commit is contained in:
parent
84a9dfa9d5
commit
cf2c089e09
5 changed files with 11 additions and 93 deletions
|
@ -101,11 +101,6 @@ namespace geode {
|
|||
*/
|
||||
std::optional<std::string> filter;
|
||||
|
||||
/**
|
||||
* A list of options the user can choose from
|
||||
*/
|
||||
std::optional<std::vector<std::string>> options;
|
||||
|
||||
static Result<StringSetting> parse(JsonMaybeObject& obj);
|
||||
};
|
||||
|
||||
|
|
|
@ -102,6 +102,7 @@ void EventListenerProtocol::disable() {
|
|||
}
|
||||
|
||||
EventListenerProtocol::~EventListenerProtocol() {
|
||||
log::debug("Destroying listener {}", (void*)this);
|
||||
this->disable();
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,6 @@ Result<StringSetting> StringSetting::parse(JsonMaybeObject& obj) {
|
|||
parseCommon(sett, obj);
|
||||
obj.has("match").into(sett.match);
|
||||
obj.has("filter").into(sett.filter);
|
||||
obj.has("one-of").into(sett.options);
|
||||
return Ok(sett);
|
||||
}
|
||||
|
||||
|
@ -377,21 +376,6 @@ IMPL_TO_VALID(String) {
|
|||
};
|
||||
}
|
||||
}
|
||||
else if (m_definition.options) {
|
||||
if (std::find(
|
||||
m_definition.options.value().begin(),
|
||||
m_definition.options.value().end(),
|
||||
value
|
||||
) == m_definition.options.value().end()) {
|
||||
return {
|
||||
m_definition.defaultValue,
|
||||
fmt::format(
|
||||
"Value must be one of {}",
|
||||
fmt::join(m_definition.options.value(), ", ")
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
return { value, std::nullopt };
|
||||
}
|
||||
|
||||
|
|
|
@ -310,11 +310,8 @@ bool FloatSettingNode::setup(FloatSettingValue* setting, float width) {
|
|||
// StringSettingNode
|
||||
|
||||
void StringSettingNode::updateLabel() {
|
||||
if (m_input) m_input->setString(m_uncommittedValue, false);
|
||||
if (m_label) {
|
||||
m_label->setString(m_uncommittedValue.c_str());
|
||||
m_label->limitLabelWidth(m_width / 2 - 80.f, .65f, .1f);
|
||||
}
|
||||
// hacky way to make setString not called textChanged
|
||||
m_input->setString(m_uncommittedValue, false);
|
||||
}
|
||||
|
||||
void StringSettingNode::textChanged(CCTextInputNode* input) {
|
||||
|
@ -327,68 +324,17 @@ void StringSettingNode::valueChanged(bool updateText) {
|
|||
this->updateLabel();
|
||||
}
|
||||
|
||||
void StringSettingNode::onArrow(CCObject* sender) {
|
||||
m_selectedOption += sender->getTag();
|
||||
if (m_selectedOption < 0) {
|
||||
m_selectedOption = m_options.size() - 1;
|
||||
}
|
||||
else if (m_selectedOption >= m_options.size()) {
|
||||
m_selectedOption = 0;
|
||||
}
|
||||
m_uncommittedValue = m_options[m_selectedOption];
|
||||
this->valueChanged(true);
|
||||
}
|
||||
|
||||
bool StringSettingNode::setup(StringSettingValue* setting, float width) {
|
||||
m_width = width;
|
||||
if (setting->castDefinition().options && setting->castDefinition().options->size() > 0) {
|
||||
m_options = setting->castDefinition().options.value();
|
||||
m_input = TextInput::create(width / 2 - 10.f, "Text", "chatFont.fnt");
|
||||
m_input->setPosition({ -(width / 2 - 70.f) / 2, .0f });
|
||||
m_input->setScale(.65f);
|
||||
|
||||
m_selectedOption = 0;
|
||||
for (size_t i = 0; i < m_options.size(); i++) {
|
||||
if (m_options[i] == setting->castDefinition().defaultValue) {
|
||||
m_selectedOption = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
auto prevArrowSpr = CCSprite::createWithSpriteFrameName("navArrowBtn_001.png");
|
||||
prevArrowSpr->setFlipX(true);
|
||||
prevArrowSpr->setScale(.3f);
|
||||
|
||||
m_prevBtn = CCMenuItemSpriteExtra::create(
|
||||
prevArrowSpr, this, menu_selector(StringSettingNode::onArrow)
|
||||
);
|
||||
m_prevBtn->setPosition(-width / 2 + 65.f, 0.f);
|
||||
m_prevBtn->setTag(-1);
|
||||
m_menu->addChild(m_prevBtn);
|
||||
|
||||
auto nextArrowSpr = CCSprite::createWithSpriteFrameName("navArrowBtn_001.png");
|
||||
nextArrowSpr->setScale(.3f);
|
||||
|
||||
m_nextBtn = CCMenuItemSpriteExtra::create(
|
||||
nextArrowSpr, this, menu_selector(StringSettingNode::onArrow)
|
||||
);
|
||||
m_nextBtn->setTag(1);
|
||||
m_nextBtn->setPosition(5.f, 0.f);
|
||||
m_menu->addChild(m_nextBtn);
|
||||
|
||||
m_label = CCLabelBMFont::create("", "bigFont.fnt");
|
||||
m_label->setPosition({ -(width / 2 - 70.f) / 2, .0f });
|
||||
m_menu->addChild(m_label);
|
||||
if (setting->castDefinition().filter.has_value()) {
|
||||
m_input->setFilter(setting->castDefinition().filter.value());
|
||||
}
|
||||
else {
|
||||
m_input = TextInput::create(width / 2 - 10.f, "Text", "chatFont.fnt");
|
||||
m_input->setPosition({ -(width / 2 - 70.f) / 2, .0f });
|
||||
m_input->setScale(.65f);
|
||||
|
||||
if (setting->castDefinition().filter.has_value()) {
|
||||
m_input->setFilter(setting->castDefinition().filter.value());
|
||||
}
|
||||
|
||||
m_input->setDelegate(this);
|
||||
m_menu->addChild(m_input);
|
||||
}
|
||||
m_input->setDelegate(this);
|
||||
m_menu->addChild(m_input);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -266,19 +266,11 @@ class StringSettingNode :
|
|||
public TextInputDelegate
|
||||
{
|
||||
protected:
|
||||
TextInput* m_input = nullptr;
|
||||
CCLabelBMFont* m_label = nullptr;
|
||||
CCMenuItemSpriteExtra* m_prevBtn = nullptr;
|
||||
CCMenuItemSpriteExtra* m_nextBtn = nullptr;
|
||||
std::vector<std::string> m_options;
|
||||
int m_selectedOption = 0;
|
||||
float m_width;
|
||||
TextInput* m_input;
|
||||
|
||||
void textChanged(CCTextInputNode* input) override;
|
||||
void valueChanged(bool updateText) override;
|
||||
void updateLabel();
|
||||
|
||||
void onArrow(CCObject* sender);
|
||||
|
||||
bool setup(StringSettingValue* setting, float width) override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue