-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef01513
commit 11c7493
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "section_setting.hpp" | ||
#include <Geode/loader/Dirs.hpp> | ||
#include <filesystem> | ||
|
||
using namespace geode::prelude; | ||
|
||
SettingNode* SectionValue::createNode(float width) { | ||
return SectionNode::create(this, width); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Based on similar code by TpdeaX | ||
#pragma once | ||
|
||
#include <Geode/loader/SettingNode.hpp> | ||
#include <Geode/modify/FLAlertLayer.hpp> | ||
|
||
#include <matjson.hpp> | ||
#include <string> | ||
|
||
using namespace geode::prelude; | ||
|
||
using String = std::string; | ||
using CRString = String const &; | ||
using Val = matjson::Value; | ||
using CRVal = Val const &; | ||
|
||
class SectionValue; | ||
|
||
class SectionValue : public SettingValue { | ||
protected: | ||
String m_placeholder; | ||
|
||
public: | ||
SectionValue(CRString key, CRString modID, CRString placeholder) | ||
: SettingValue(key, modID), m_placeholder(placeholder) {} | ||
|
||
bool load(CRVal json) override { | ||
return true; | ||
} | ||
|
||
bool save(Val &json) const override { | ||
return true; | ||
} | ||
|
||
SettingNode *createNode(float width) override; | ||
}; | ||
|
||
class SectionNode : public SettingNode { | ||
protected: | ||
bool init(SectionValue *value, float width) { | ||
if (!SettingNode::init(value)) { | ||
return false; | ||
} | ||
|
||
CCMenu *menu = CCMenu::create(); | ||
CCSprite *info_spr = CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png"); | ||
String section_name = Mod::get()->getSettingDefinition( | ||
value->getKey())->get<CustomSetting>()->json->get<String>("name"); | ||
|
||
this->setContentSize({width, 40.f}); | ||
info_spr->setScale(0.7f); | ||
|
||
auto info_btn = CCMenuItemSpriteExtra::create( | ||
info_spr, | ||
this, | ||
menu_selector(SectionNode::on_info_btn) | ||
); | ||
|
||
info_btn->setID(value->getKey()); | ||
info_btn->setPositionX(Mod::get()->getSettingDefinition(value->getKey())->get<CustomSetting>()->json->get<int>("x_pos")); | ||
|
||
auto label = CCLabelBMFont::create(section_name.c_str(), "goldFont.fnt"); | ||
|
||
label->setScale(0.6f); | ||
|
||
menu->setPosition(width / 2, 23.f); | ||
menu->addChild(label); | ||
menu->addChild(info_btn); | ||
|
||
this->addChild(menu); | ||
|
||
return true; | ||
} | ||
|
||
void on_info_btn(CCObject *sender) { | ||
auto *node = reinterpret_cast<CCMenuItemSpriteExtra *>(sender); | ||
|
||
if (node == nullptr) return; | ||
|
||
auto info_name = Mod::get()->getSettingDefinition(node->getID())->get<CustomSetting>()->json->get<std::string>("name").c_str(); | ||
auto info_desc = Mod::get()->getSettingDefinition(node->getID())->get<CustomSetting>()->json->get<std::string>("description").c_str(); | ||
auto scale = Mod::get()->getSettingDefinition(node->getID())->get<CustomSetting>()->json->get<int>("scale"); | ||
|
||
auto alert = FLAlertLayer::create( | ||
info_name, | ||
info_desc, | ||
"OK" | ||
); | ||
|
||
auto scale_as_f = static_cast<float>(scale); | ||
alert->setScale(scale_as_f); | ||
|
||
alert->show(); | ||
} | ||
|
||
public: | ||
void commit() override { | ||
this->dispatchCommitted(); | ||
} | ||
|
||
bool hasUncommittedChanges() override { | ||
return false; | ||
} | ||
|
||
bool hasNonDefaultValue() override { | ||
return true; | ||
} | ||
|
||
void resetToDefault() override {} | ||
|
||
static SectionNode* create(SectionValue* value, float width) { | ||
auto ret = new SectionNode; | ||
|
||
if (ret->init(value, width)) { | ||
ret->autorelease(); | ||
return ret; | ||
} | ||
|
||
CC_SAFE_DELETE(ret); | ||
|
||
return nullptr; | ||
} | ||
}; |