From 11c7493b680ea9ee04bbd96953ce4cd0d3793d50 Mon Sep 17 00:00:00 2001 From: The Motherfucking Bearodactyl Date: Tue, 21 May 2024 12:47:08 -0500 Subject: [PATCH] improve on mod settings --- CMakeLists.txt | 1 + mod.json | 7 ++ src/main.cpp | 5 ++ src/settings/section_setting.cpp | 9 +++ src/settings/section_setting.hpp | 123 +++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 src/settings/section_setting.cpp create mode 100644 src/settings/section_setting.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a09d714..59b76d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ file(GLOB_RECURSE SOURCES src/*.cpp src/utils/*.cpp src/trail_customization/*.cpp + src/settings/*.cpp ) add_library(${PROJECT_NAME} SHARED ${SOURCES}) diff --git a/mod.json b/mod.json index 97f1475..3d06916 100644 --- a/mod.json +++ b/mod.json @@ -57,6 +57,13 @@ "type": "bool", "default": true }, + "gaydient-title-section": { + "name": "Gaydient Settings", + "type": "custom", + "description": "Settings for the gaydient\n(custom colors)", + "scale": 300, + "x_pos": 80 + }, "use-gradient": { "name": "Enable the GAYDIENT", "description": "now with 4 colors! full 256\ncolor rainbow NO MORE\n(enables the usage of\nthe below custom colors\ninstead of a vanilla rainbow)", diff --git a/src/main.cpp b/src/main.cpp index cb65191..94344ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include #include "trail_customization/rainbow_trail.hpp" +#include "settings/section_setting.hpp" using namespace geode::prelude; using namespace cocos2d; @@ -90,3 +91,7 @@ class $modify(PlayLayer) { } } }; + +$on_mod(Loaded) { + Mod::get()->addCustomSetting("gaydient-title-section", "none"); +} \ No newline at end of file diff --git a/src/settings/section_setting.cpp b/src/settings/section_setting.cpp new file mode 100644 index 0000000..b38366b --- /dev/null +++ b/src/settings/section_setting.cpp @@ -0,0 +1,9 @@ +#include "section_setting.hpp" +#include +#include + +using namespace geode::prelude; + +SettingNode* SectionValue::createNode(float width) { + return SectionNode::create(this, width); +} \ No newline at end of file diff --git a/src/settings/section_setting.hpp b/src/settings/section_setting.hpp new file mode 100644 index 0000000..945f4dc --- /dev/null +++ b/src/settings/section_setting.hpp @@ -0,0 +1,123 @@ +// Based on similar code by TpdeaX +#pragma once + +#include +#include + +#include +#include + +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()->json->get("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()->json->get("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(sender); + + if (node == nullptr) return; + + auto info_name = Mod::get()->getSettingDefinition(node->getID())->get()->json->get("name").c_str(); + auto info_desc = Mod::get()->getSettingDefinition(node->getID())->get()->json->get("description").c_str(); + auto scale = Mod::get()->getSettingDefinition(node->getID())->get()->json->get("scale"); + + auto alert = FLAlertLayer::create( + info_name, + info_desc, + "OK" + ); + + auto scale_as_f = static_cast(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; + } +}; \ No newline at end of file