diff --git a/changelog.md b/changelog.md index 7a5e6f3..85ab08d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,7 @@ # Changelog +## v1.3.10 (2024-09-15) +* Updated settings to the new V3 ones for custom settings. + ## v1.3.9 (2024-08-19) * Added Ko-Fi Supporter badge on profile + link to get it on the "gift button" ([or also here](https://ko-fi.com/gdutils)) * Added GD moderators leaderboards diff --git a/mod.json b/mod.json index 91e134f..61dfa7f 100644 --- a/mod.json +++ b/mod.json @@ -1,6 +1,6 @@ { - "geode": "3.4.0", - "version": "v1.3.9", + "geode": "3.7.0", + "version": "v1.3.10", "gd": { "win": "2.206", "mac": "2.206", @@ -20,12 +20,12 @@ "dependencies": [ { "id": "geode.node-ids", - "version": ">=v1.13.1", + "version": ">=v1.14.0", "importance": "required" }, { "id": "jouca.badgesapi", - "version": ">=v1.0.7", + "version": ">=v1.1.0", "importance": "required" } ], @@ -51,14 +51,11 @@ "notification-section": { "name": "Notifications", "description": "This category is for where it should show notifications, and also what notifications precisely.", - "type": "custom", - "scale": 300, - "posX": 65 + "type": "title" }, "test-notification": { "name": "Test", - "description": "NONE", - "type": "custom" + "type": "custom:test-notification" }, "everywhereElse": { "name": "Everywhere Else", @@ -147,21 +144,18 @@ "notification-placement-section": { "name": "Notification Placement", "description": "This category is for where to show the notification in the screen on a specific corner.", - "type": "custom", - "scale": 300, - "posX": 100 + "type": "title" }, "notificationPlacement": { "name": "Placement", - "description": "Where the notification should be placed.\n1 = Top Left | 2 = Top Right\n3 = Bottom Left | 4 = Bottom Right", - "type": "custom" + "descriptionold": "Where the notification should be placed.\n1 = Top Left | 2 = Top Right\n3 = Bottom Left | 4 = Bottom Right", + "type": "custom:notification-placement", + "default": 4 }, "notification-appearance-section": { "name": "Notification Appearance", "description": "This category is for setting notification boxes for how it should appear.\nYou can also use decimals in these options, such as 0.5 size, or 3.5 seconds.", - "type": "custom", - "scale": 350, - "posX": 105 + "type": "title" }, "size": { "name": "Size", @@ -189,34 +183,46 @@ "spotify-section": { "name": "Spotify", "description": "This category is for determining when Spotify should toggle mute.\nThis only works if you currently have the Spotify App open.\n\nIf your music volume is set to 0, Spotify\nwill not be affected.", - "type": "custom", - "scale": 350, - "posX": 40 + "type": "title", + "platforms": ["win","mac"] }, "inEditorSpotify": { "name": "In Editor", "description": "Disabling this will not auto-mute Spotify when you are playing music in the Editor.", "type": "bool", - "default": false + "default": false, + "platforms": ["win","mac"] }, "inLevelsSpotify": { "name": "In Levels", "description": "Disabling this will not auto-mute Spotify when you are playing a level, and music is playing.", "type": "bool", - "default": false + "default": false, + "platforms": ["win","mac"] }, "spotifyApp": { "name": "Application", "description": "This will decide what application should be auto-muted.", - "type": "custom", - "default": "Spotify.exe" + "type": "file", + "default": { + "win": "Spotify.exe", + "mac": "Spotify.app" + }, + "platforms": ["win","mac"], + "control": { + "dialog": "open", + "filters": [ + { + "files": ["*.exe", "*.app", "*.*"], + "description": "Executable programs" + } + ] + } }, "misc-section": { "name": "Miscellaneous", "description": "This category is for any other feature for GDUtils.\nYou can choose whether to enable or disable some options if you do not want them.", - "type": "custom", - "scale": 300, - "posX": 65 + "type": "title" }, "friendSearch": { "name": "Search Friends", @@ -233,7 +239,9 @@ "demonListSelection": { "name": "Demon List Selection", "description": "Whether or not to select between Pointercrate or AreDL for placements.", - "type": "custom" + "type": "string", + "default": "Pointercrate", + "one-of": ["Pointercrate", "AreDL"] }, "levelsProtocol": { "name": "Allow Levels Protocol", @@ -268,9 +276,7 @@ "background-section": { "name": "Backgrounds", "description": "This category is for changing the background colors.", - "type": "custom", - "scale": 350, - "posX": 60 + "type": "title" }, "activate-background": { "name": "Activate Background", @@ -282,31 +288,36 @@ "name": "Background", "description": "Change the color of GD backgrounds.", "type": "color", - "default": "#0066FF" + "default": "#0066FF", + "enable-if": "activate-background" }, "child-background": { "name": "Child Background", "description": "Change the color of GD child backgrounds (associated with GD backgrounds).", "type": "color", - "default": "#00388D" + "default": "#00388D", + "enable-if": "activate-background" }, "syncBGcolor": { "name": "Sync BG Color", "description": "Allows you to synchronise the GD backgrounds with child backgrounds.", "type": "bool", - "default": true + "default": true, + "enable-if": "activate-background" }, "addChildBDGradient": { "name": "Add child BG Gradient", "description": "Adds a gradient to child backgrounds (only for level browsing).", "type": "bool", - "default": true + "default": true, + "enable-if": "activate-background" }, "bgchild-transparency": { "name": "BG Child Transparency", "description": "Change the transparency of child backgrounds.", "type": "bool", - "default": false + "default": false, + "enable-if": "activate-background" }, "bgchild-transparency-scroll": { "name": "Transparency Opacity", @@ -317,18 +328,17 @@ "max": 255, "control": { "slider": true - } + }, + "enable-if": "activate-background" }, "credits-section": { "name": "Credits", "description": "Below are the credits for those that developed the mod, and beta-tested the mod!", - "type": "custom", - "scale": 300, - "posX": 40 + "type": "title" }, "credit-buttons": { "name": "Credit Buttons", - "type": "custom" + "type": "custom:credit-buttons" } } } diff --git a/src/Notifications/EventsPush.cpp b/src/Notifications/EventsPush.cpp index eb97ed3..e3f6be8 100644 --- a/src/Notifications/EventsPush.cpp +++ b/src/Notifications/EventsPush.cpp @@ -416,12 +416,12 @@ bool EventsPush::init(sio::message::ptr const& data) { auto menu = CCMenu::create(); - bool newRate = Mod::get()->getSettingValue("newRate"); - bool daily = Mod::get()->getSettingValue("daily"); - bool weekly = Mod::get()->getSettingValue("weekly"); - bool smallChest = Mod::get()->getSettingValue("smallChest"); - bool largeChest = Mod::get()->getSettingValue("largeChest"); - bool list = Mod::get()->getSettingValue("newListRate"); + bool newRate = Mod::get()->template getSettingValue("newRate"); + bool daily = Mod::get()->template getSettingValue("daily"); + bool weekly = Mod::get()->template getSettingValue("weekly"); + bool smallChest = Mod::get()->template getSettingValue("smallChest"); + bool largeChest = Mod::get()->template getSettingValue("largeChest"); + bool list = Mod::get()->template getSettingValue("newListRate"); switch (type) { case 0: // Rate eventType = EventType::Rate; @@ -471,7 +471,7 @@ bool EventsPush::init(sio::message::ptr const& data) { auto winSize = director->getWinSize(); auto bg = cocos2d::extension::CCScale9Sprite::create(sprite_name.c_str(), { .0f, .0f, 80.0f, 80.0f, }); auto bg_click_spr = cocos2d::extension::CCScale9Sprite::create(sprite_name.c_str(), { .0f, .0f, 80.0f, 80.0f, }); - float lrScale = (float)Mod::get()->getSettingValue("size"); + float lrScale = (float)Mod::get()->template getSettingValue("size"); auto LrSize = CCSize{ 240, 70 }; // * lrScale for both bg->setScale(lrScale); this->setZOrder(zOrder); @@ -560,7 +560,7 @@ bool EventsPush::init(sio::message::ptr const& data) { bg->addChild(legendary); bg->addChild(diffFace); - if (Mod::get()->getSettingValue("customDifficultyFaces")) { + if (Mod::get()->template getSettingValue("customDifficultyFaces")) { CCSprite* legendaryFace = nullptr; if (isDemon == 0) { if (starsum >= 10) { @@ -591,7 +591,7 @@ bool EventsPush::init(sio::message::ptr const& data) { case 4: // Mythic bg->addChild(mythic); - if (Mod::get()->getSettingValue("customDifficultyFaces")) { + if (Mod::get()->template getSettingValue("customDifficultyFaces")) { CCSprite* mythicFace = nullptr; if (isDemon == 0) { if (starsum >= 10) { @@ -830,24 +830,24 @@ bool EventsPush::init(sio::message::ptr const& data) { // Move action //CCDelayTime - float delayTime = (float)Mod::get()->getSettingValue("time"); + float delayTime = (float)Mod::get()->template getSettingValue("time"); - int cornerId = Mod::get()->getSettingValue("notificationPlacement").m_pos;//ConfigHandler::readConfigInt("notificationPlacement"); + auto cornerId = Mod::get()->getSettingValue("notificationPlacement"); float moveX = .0F; switch (cornerId) { - case 1: // top left + case SettingPosEnum::TopLeft: // top left bg->setPosition((-(bg->getContentSize().width / 2)) * lrScale, ((winSize.height - (bg->getContentSize().height / 2)) - (20 * lrScale))); moveX = (bg->getContentSize().width) * lrScale; break; - case 2: // top right + case SettingPosEnum::TopRight: // top right bg->setPosition(winSize.width + ((bg->getContentSize().width / 2) * lrScale), ((winSize.height - (bg->getContentSize().height / 2)) - (20 * lrScale))); moveX = -(bg->getContentSize().width * lrScale); break; - case 3: // bottom left + case SettingPosEnum::BottomLeft: // bottom left bg->setPosition((-(bg->getContentSize().width / 2)) * lrScale, (bg->getContentSize().height / 2) * lrScale); moveX = (bg->getContentSize().width) * lrScale; break; - case 4: // bottom right + case SettingPosEnum::BottomRight: // bottom right bg->setPosition({ winSize.width + ((bg->getContentSize().width / 2) * lrScale), (bg->getContentSize().height / 2) * lrScale}); moveX = -((bg->getContentSize().width) * lrScale); break; @@ -863,14 +863,14 @@ bool EventsPush::init(sio::message::ptr const& data) { )); float volume = 0.0f; - if (Mod::get()->getSettingValue("sfx-link")) { + if (Mod::get()->template getSettingValue("sfx-link")) { volume = GameManager::get()->m_sfxVolume; } else { - volume = Mod::get()->getSettingValue("sfx-volume"); + volume = Mod::get()->template getSettingValue("sfx-volume"); } - if (Mod::get()->getSettingValue("sfx") && type != 3 && type != 4) FMODAudioEngine::sharedEngine()->playEffect("crystal01.ogg", 1, 1, volume); - if (Mod::get()->getSettingValue("sfx") && (type == 3 || type == 4)) FMODAudioEngine::sharedEngine()->playEffect("reward01.ogg", 1, 1, volume); + if (Mod::get()->template getSettingValue("sfx") && type != 3 && type != 4) FMODAudioEngine::sharedEngine()->playEffect("crystal01.ogg", 1, 1, volume); + if (Mod::get()->template getSettingValue("sfx") && (type == 3 || type == 4)) FMODAudioEngine::sharedEngine()->playEffect("reward01.ogg", 1, 1, volume); return true; } diff --git a/src/Settings/CustomSettings.cpp b/src/Settings/CustomSettings.cpp index 54f5522..2d0d152 100644 --- a/src/Settings/CustomSettings.cpp +++ b/src/Settings/CustomSettings.cpp @@ -1,96 +1,17 @@ #include "CustomSettings.hpp" #include -#include #include "../Notifications/EventsPush.h" #include "../includes.h" int cycleTypes = -1; -SettingNode* SettingSectionValue::createNode(float width) { - return SettingSectionNode::create(this, width); +SettingNodeV3* SettingTestValue::createNode(float width) { + return SettingTestNode::create(static_pointer_cast(shared_from_this()), width); } -SettingNode* SettingTestValue::createNode(float width) { - return SettingTestNode::create(this, width); +SettingNodeV3* SettingPosValue::createNode(float width) { + return SettingPosNode::create(static_pointer_cast(shared_from_this()), width); } -SettingNode* SettingAppValue::createNode(float width) { - return SettingAppNode::create(this, width); -} -SettingNode* SettingPosValue::createNode(float width) { - return SettingPosNode::create(this, width); -} -SettingNode* SettingDLPosValue::createNode(float width) { - return SettingDLNode::create(this, width); -} -SettingNode* SettingCreditsValue::createNode(float width) { - return SettingCreditsNode::create(this, width); -} -#ifdef GEODE_IS_WINDOWS -std::string GetOpenFileName() { - OPENFILENAME ofn; - char szFile[MAX_PATH] = { 0 }; - - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = NULL; - ofn.lpstrFilter = "Executable Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0"; - ofn.lpstrFile = szFile; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrInitialDir = "\%appdata\%\\Spotify"; // Set your desired default path here - ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; - if (GetOpenFileName(&ofn)) - return std::string(szFile); - else - return ""; - return ""; -} -#endif -void SettingAppNode::onPickFile(CCObject*) { - #ifdef GEODE_IS_MACOS - // thanks catto - file::pick( - file::PickMode::OpenFile, - { - "/Applications", // sorry mac users but idk the path for spotify - {} - } - - ).listen( - [this](Result* result) { - if (!result->isOk()) return; - - auto path = result->unwrap(); - std::string strPath = path.string(); - size_t lastBackslashPos = strPath.find_last_of('/'); - if (lastBackslashPos != std::string::npos) { - std::string lastPart = strPath.substr(lastBackslashPos + 1); - m_currentApp = lastPart; - defaultApp_input->setString(lastPart.c_str()); - this->dispatchChanged(); - } - - }, - [](auto const&){} - ); - #else - #ifdef GEODE_IS_WINDOWS // i get an error, i so badly want to use elif but it gives me an error - std::string filePath = GetOpenFileName(); - if (!filePath.empty()) { - std::filesystem::path fullPath(filePath); - std::string appName = fullPath.filename().string(); - if (!appName.empty()) { - m_currentApp = appName; - defaultApp_input->setString(appName.c_str()); - this->dispatchChanged(); - } - } - #else - FLAlertLayer::create(nullptr, - "Error", - "This setting is not supported on this platform.", - "OK", - nullptr - )->show(); - #endif - #endif +SettingNodeV3* SettingCreditsValue::createNode(float width) { + return SettingCreditsNode::create(static_pointer_cast(shared_from_this()), width); } void SettingTestNode::onTestBtn(CCObject*) { @@ -190,5 +111,4 @@ void SettingTestNode::onTestBtn(CCObject*) { break; } EventsPush::pushRateLevel(scene, data); - } diff --git a/src/Settings/CustomSettings.hpp b/src/Settings/CustomSettings.hpp index 93a24f8..a1f79d6 100644 --- a/src/Settings/CustomSettings.hpp +++ b/src/Settings/CustomSettings.hpp @@ -9,14 +9,16 @@ using namespace geode::prelude; --- Test --- */ -class SettingTestValue; - -class SettingTestValue : public SettingValue { -protected: - std::string m_placeholder; +class SettingTestValue : public SettingV3 { public: - SettingTestValue(std::string const& key, std::string const& modID, std::string const& placeholder) - : SettingValue(key, modID), m_placeholder(placeholder) {} + static Result> parse(std::string const& key, std::string const& modID, matjson::Value const& json) { + auto res = std::make_shared(); + auto root = checkJson(json, "SettingTestValue"); + res->init(key, modID, root); + res->parseNameAndDescription(root); + root.checkUnknownKeys(); + return root.ok(res); + } bool load(matjson::Value const& json) override { return true; @@ -24,64 +26,50 @@ class SettingTestValue : public SettingValue { bool save(matjson::Value& json) const override { return true; } - SettingNode* createNode(float width) override; + bool isDefaultValue() const override { + return true; + } + void reset() override {} + SettingNodeV3* createNode(float width) override; }; -class SettingTestNode : public SettingNode { +class SettingTestNode : public SettingNodeV3 { protected: - bool init(SettingTestValue* value, float width) { - if (!SettingNode::init(value)) + bool init(std::shared_ptr setting, float width) { + if (!SettingNodeV3::init(setting, width)) return false; this->setContentSize({ width, 35.f }); - auto menu = CCMenu::create(); auto label = CCLabelBMFont::create("Test", "bigFont.fnt"); label->setScale(.6F); - label->setPositionX(-130); auto playSpr = CCSprite::createWithSpriteFrameName("GJ_playBtn2_001.png"); playSpr->setScale(.4F); - //auto infoBtn auto testBtn = CCMenuItemSpriteExtra::create( playSpr, this, menu_selector(SettingTestNode::onTestBtn) ); - testBtn->setPositionX(140); - menu->setPosition(width / 2, 18.f); - menu->addChild(label); - menu->addChild(testBtn); - this->addChild(menu); + getButtonMenu()->setContentWidth(width); + getButtonMenu()->addChildAtPosition(label, Anchor::Left, {42, 0}); + getButtonMenu()->addChildAtPosition(testBtn, Anchor::Right, {-15, 0}); + getButtonMenu()->updateLayout(); + getNameLabel()->setVisible(false); return true; } + void onCommit() override {} + void onResetToDefault() override {} public: - // because for some reason SettingNode doesnt expose description, i have to do all of this, smh. void onTestBtn(CCObject*); - - void commit() override { - // Let the UI know you have committed the value - this->dispatchCommitted(); - } - - // Geode calls this to query if the setting value has been changed, - // and those changes haven't been committed - bool hasUncommittedChanges() override { + bool hasUncommittedChanges() const override { return false; } - - // Geode calls this to query if the setting has a value that is - // different from its default value - bool hasNonDefaultValue() override { - return true; - } - - // Geode calls this to reset the setting's value back to default - void resetToDefault() override { - + bool hasNonDefaultValue() const override { + return false; } - static SettingTestNode* create(SettingTestValue* value, float width) { - auto ret = new SettingTestNode; - if (ret && ret->init(value, width)) { + static SettingTestNode* create(std::shared_ptr setting, float width) { + auto ret = new SettingTestNode(); + if (ret && ret->init(setting, width)) { ret->autorelease(); return ret; } @@ -91,368 +79,107 @@ class SettingTestNode : public SettingNode { }; /* - --- Section --- + Notification Position */ -class SettingSectionValue; - -class SettingSectionValue : public SettingValue { -protected: - std::string m_placeholder; -public: - SettingSectionValue(std::string const& key, std::string const& modID, std::string const& placeholder) - : SettingValue(key, modID), m_placeholder(placeholder) {} - - bool load(matjson::Value const& json) override { - return true; - } - bool save(matjson::Value& json) const override { - return true; - } - SettingNode* createNode(float width) override; -}; - -class SettingSectionNode : public SettingNode { -protected: - bool init(SettingSectionValue* value, float width) { - if (!SettingNode::init(value)) - return false; - this->setContentSize({ width, 40.f }); - auto menu = CCMenu::create(); - std::string sectionName = Mod::get()->getSettingDefinition(value->getKey())->get()->json->get("name"); - auto infoSpr = CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png"); - infoSpr->setScale(.7F); - //auto infoBtn - auto infoBtn = CCMenuItemSpriteExtra::create( - infoSpr, - this, - menu_selector(SettingSectionNode::onInfoBtn) - ); - infoBtn->setID(value->getKey()); - infoBtn->setPositionX(Mod::get()->getSettingDefinition(value->getKey())->get()->json->get("posX")); - auto label = CCLabelBMFont::create(sectionName.c_str(), "goldFont.fnt"); - - label->setScale(.6F); - menu->setPosition(width / 2, 23.f); - menu->addChild(label); - menu->addChild(infoBtn); - this->addChild(menu); - return true; - } - - void onInfoBtn(CCObject* sender) { - // i dont want to deal with template hell - auto node = reinterpret_cast(sender); - if (node == nullptr) return; - FLAlertLayer::create(nullptr, - Mod::get()->getSettingDefinition(node->getID())->get()->json->get("name").c_str(), - Mod::get()->getSettingDefinition(node->getID())->get()->json->get("description").c_str(), - "OK", - nullptr, - Mod::get()->getSettingDefinition(node->getID())->get()->json->get("scale") - )->show(); - } - -public: - void commit() override { - // Let the UI know you have committed the value - this->dispatchCommitted(); - } - - // Geode calls this to query if the setting value has been changed, - // and those changes haven't been committed - bool hasUncommittedChanges() override { - return false; - } - - // Geode calls this to query if the setting has a value that is - // different from its default value - bool hasNonDefaultValue() override { - return true; - } - - // Geode calls this to reset the setting's value back to default - void resetToDefault() override { - - } - static SettingSectionNode* create(SettingSectionValue* value, float width) { - auto ret = new SettingSectionNode; - if (ret && ret->init(value, width)) { - ret->autorelease(); - return ret; - } - CC_SAFE_DELETE(ret); - return nullptr; - } -}; - -// Pointercrate / AreDL setting - -const int DEFAULT_DL_POS = 2; - -struct SettingDLPosStruct { - int m_pos; -}; - -class SettingDLPosValue; - -class SettingDLPosValue : public SettingValue { -protected: - int m_pos; -public: - SettingDLPosValue(std::string const& key, std::string const& modID, int const& position) - : SettingValue(key, modID), m_pos(position) {} +const int DEFAULT_POS = 4; - bool load(matjson::Value const& json) override { - try { - m_pos = static_cast(json.as()); - return true; - } catch(...) { - return false; - } - } - bool save(matjson::Value& json) const override { - json = static_cast(m_pos); - return true; - } - SettingNode* createNode(float width) override; - void setPos(int pos) { - m_pos = pos; - } - int getPos() const { - return m_pos; - } +enum class SettingPosEnum : int { + TopLeft, + TopRight, + BottomLeft, + BottomRight }; -template<> -struct SettingValueSetter { - static SettingDLPosStruct get(SettingValue* setting) { - auto posSetting = static_cast(setting); - struct SettingDLPosStruct defaultStruct = { posSetting->getPos() }; - return defaultStruct; - }; - static void set(SettingDLPosValue* setting, SettingDLPosStruct const& value) { - setting->setPos(value.m_pos); - }; -}; - -class SettingDLNode : public SettingNode { - protected: - int m_currentPos; - CCMenuItemToggler* pcBtn; - CCMenuItemToggler* aredlBtn; - - int getActiveCornerTag(int corner) { - switch (corner) { - case 1: // AreDL - return 2008; - case 2: // Pointercrate - default: - return 2009; - } - } - int tagToCorner(int tag) { - switch (tag) { - case 2008: // AreDL +template <> +struct matjson::Serialize { + static matjson::Value to_json(SettingPosEnum const& value) { + log::info("to_json {}", static_cast(value)); + switch (value) { + case SettingPosEnum::TopLeft: return 1; - default: - case 2009: // Pointercrate + case SettingPosEnum::TopRight: return 2; + case SettingPosEnum::BottomLeft: + return 3; + default: + case SettingPosEnum::BottomRight: + return 4; } } - - bool init(SettingDLPosValue* value, float width) { - if (!SettingNode::init(value)) - return false; - - auto pointercrate_text = CCLabelBMFont::create("Pointercrate", "goldFont.fnt"); - pointercrate_text->setScale(.6F); - pointercrate_text->setPosition(161, 16); - this->addChild(pointercrate_text); - - auto aredl_text = CCLabelBMFont::create("AreDL", "goldFont.fnt"); - aredl_text->setScale(.6F); - aredl_text->setPosition(276, 16); - this->addChild(aredl_text); - - m_currentPos = value->getPos(); - this->setContentSize({ width, 30.f }); - auto menu = CCMenu::create(); - CCSprite* toggleOn = CCSprite::createWithSpriteFrameName("GJ_checkOn_001.png"); - CCSprite* toggleOff = CCSprite::createWithSpriteFrameName("GJ_checkOff_001.png"); - toggleOn->setScale(.7F); - toggleOff->setScale(.7F); - menu->setPosition(width / 2, 23.f); - pcBtn = CCMenuItemToggler::create( - toggleOn, - toggleOff, - this, - menu_selector(SettingDLNode::onCornerClick) - ); - aredlBtn = CCMenuItemToggler::create( - toggleOn, - toggleOff, - this, - menu_selector(SettingDLNode::onCornerClick) - ); - pcBtn->setPosition({ -80, -8 }); - aredlBtn->setPosition({ 60, -8 }); - - pcBtn->setTag(getActiveCornerTag(2)); - aredlBtn->setTag(getActiveCornerTag(1)); - int currentCorner = m_currentPos; - pcBtn->toggle(!(pcBtn->getTag() == getActiveCornerTag(currentCorner))); - aredlBtn->toggle(!(aredlBtn->getTag() == getActiveCornerTag(currentCorner))); - - menu->addChild(pcBtn); - menu->addChild(aredlBtn); - - this->addChild(menu); - return true; - } - - void onCornerClick(CCObject* sender) { - pcBtn->toggle(true); - aredlBtn->toggle(true); - m_currentPos = tagToCorner(sender->getTag()); - this->dispatchChanged(); - }; - - void onInfoBtn(CCObject* sender) { - FLAlertLayer::create( - Mod::get()->getSettingDefinition(this->m_value->getKey())->get()->json->get("name").c_str(), - Mod::get()->getSettingDefinition(this->m_value->getKey())->get()->json->get("description").c_str(), - "OK" - )->show(); - } - public: - void commit() override { - static_cast(m_value)->setPos(m_currentPos); - this->dispatchCommitted(); - } - - bool hasUncommittedChanges() override { - return m_currentPos != static_cast(m_value)->getPos(); - } - - bool hasNonDefaultValue() override { - return m_currentPos != DEFAULT_DL_POS; - } - - void resetToDefault() override { - pcBtn->toggle(true); - aredlBtn->toggle(false); - m_currentPos = DEFAULT_DL_POS; - } - - static SettingDLNode* create(SettingDLPosValue* value, float width) { - auto ret = new SettingDLNode; - if (ret && ret->init(value, width)) { - ret->autorelease(); - return ret; + static SettingPosEnum from_json(matjson::Value const& value) { + switch (value.as_int()) { + case 1: return SettingPosEnum::TopLeft; + case 2: return SettingPosEnum::TopRight; + case 3: return SettingPosEnum::BottomLeft; + case 4: return SettingPosEnum::BottomRight; + default: throw matjson::JsonException(fmt::format("invalid SettingPosEnum value '{}'", value)); } - CC_SAFE_DELETE(ret); - return nullptr; + } + static bool is_json(matjson::Value const& json) { + return json.is_number() || json.is_string(); } }; -/* - Notification Position -*/ - -const int DEFAULT_POS = 4; - -struct SettingPosStruct { - int m_pos; -}; - -class SettingPosValue; - -class SettingPosValue : public SettingValue { -protected: - int m_pos; +class SettingPosValue : public SettingBaseValueV3 { public: - SettingPosValue(std::string const& key, std::string const& modID, int const& position) - : SettingValue(key, modID), m_pos(position) {} - - bool load(matjson::Value const& json) override { - try { - m_pos = static_cast(json.as()); - return true; - } catch(...) { - return false; - } - } - bool save(matjson::Value& json) const override { - json = static_cast(m_pos); - return true; - } - SettingNode* createNode(float width) override; - void setPos(int pos) { - m_pos = pos; - } - int getPos() const { - return m_pos; - } + static Result> parse(std::string const& key, std::string const& modID, matjson::Value const& json) { + auto res = std::make_shared(); + auto root = checkJson(json, "SettingPosValue"); + res->parseBaseProperties(key, modID, root); + root.checkUnknownKeys(); + return root.ok(res); + } + SettingNodeV3* createNode(float width) override; }; -template<> -struct SettingValueSetter { - static SettingPosStruct get(SettingValue* setting) { - auto posSetting = static_cast(setting); - struct SettingPosStruct defaultStruct = { posSetting->getPos() }; - return defaultStruct; - }; - static void set(SettingPosValue* setting, SettingPosStruct const& value) { - setting->setPos(value.m_pos); - }; +template <> +struct geode::SettingTypeForValueType { + using SettingType = SettingPosValue; }; -class SettingPosNode : public SettingNode { +class SettingPosNode : public SettingValueNodeV3 { protected: - int m_currentPos; CCMenuItemToggler* tlBtn; CCMenuItemToggler* trBtn; CCMenuItemToggler* blBtn; CCMenuItemToggler* brBtn; - int getActiveCornerTag(int corner) { + int getActiveCornerTag(SettingPosEnum corner) { switch (corner) { - case 1: // Top Left + case SettingPosEnum::TopLeft: // Top Left return 2004; - case 2: // Top Right + case SettingPosEnum::TopRight: // Top Right return 2005; - case 3: // Bottom Left + case SettingPosEnum::BottomLeft: // Bottom Left return 2006; - case 4: // Bottom Right + case SettingPosEnum::BottomRight: // Bottom Right default: return 2007; } } - int tagToCorner(int tag) { + SettingPosEnum tagToCorner(int tag) { switch (tag) { case 2004: // Top Left - return 1; + return SettingPosEnum::TopLeft; case 2005: // Top Right - return 2; + return SettingPosEnum::TopRight; case 2006: // Bottom Left - return 3; + return SettingPosEnum::BottomLeft; default: case 2007: // Bottom Right - return 4; + return SettingPosEnum::BottomRight; } } - bool init(SettingPosValue* value, float width) { - if (!SettingNode::init(value)) + + bool init(std::shared_ptr setting, float width) { + if (!SettingValueNodeV3::init(setting, width)) return false; - m_currentPos = value->getPos(); this->setContentSize({ width, 70.f }); - auto menu = CCMenu::create(); CCSprite* toggleOn = CCSprite::createWithSpriteFrameName("GJ_checkOn_001.png"); CCSprite* toggleOff = CCSprite::createWithSpriteFrameName("GJ_checkOff_001.png"); toggleOn->setScale(.7F); toggleOff->setScale(.7F); - menu->setPosition(width / 2, 23.f); tlBtn = CCMenuItemToggler::create( toggleOn, toggleOff, @@ -477,242 +204,51 @@ class SettingPosNode : public SettingNode { this, menu_selector(SettingPosNode::onCornerClick) ); - tlBtn->setPosition({ -100, 35 }); - trBtn->setPosition({ 100, 35 }); - blBtn->setPosition({ -100, -10 }); - brBtn->setPosition({ 100, -10 }); - - tlBtn->setTag(getActiveCornerTag(1)); - trBtn->setTag(getActiveCornerTag(2)); - blBtn->setTag(getActiveCornerTag(3)); - brBtn->setTag(getActiveCornerTag(4)); - int currentCorner = m_currentPos; + tlBtn->setTag(getActiveCornerTag(SettingPosEnum::TopLeft)); + trBtn->setTag(getActiveCornerTag(SettingPosEnum::TopRight)); + blBtn->setTag(getActiveCornerTag(SettingPosEnum::BottomLeft)); + brBtn->setTag(getActiveCornerTag(SettingPosEnum::BottomRight)); + getButtonMenu()->setContentSize({width / 2, 45.F}); + getButtonMenu()->addChildAtPosition(tlBtn, Anchor::TopLeft); + getButtonMenu()->addChildAtPosition(trBtn, Anchor::TopRight); + getButtonMenu()->addChildAtPosition(blBtn, Anchor::BottomLeft); + getButtonMenu()->addChildAtPosition(brBtn, Anchor::BottomRight); + getButtonMenu()->updateLayout(); + getButtonMenu()->setAnchorPoint({0.5, 0.5}); + getButtonMenu()->updateAnchoredPosition(Anchor::Center, {0, 0}); + this->getNameLabel()->setVisible(false); + auto currentCorner = static_cast(this->getValue()); tlBtn->toggle(!(tlBtn->getTag() == getActiveCornerTag(currentCorner))); trBtn->toggle(!(trBtn->getTag() == getActiveCornerTag(currentCorner))); blBtn->toggle(!(blBtn->getTag() == getActiveCornerTag(currentCorner))); brBtn->toggle(!(brBtn->getTag() == getActiveCornerTag(currentCorner))); - - menu->addChild(tlBtn); - menu->addChild(trBtn); - menu->addChild(blBtn); - menu->addChild(brBtn); - - this->addChild(menu); + this->updateState(nullptr); return true; } + + void updateState(CCNode* invoker) override { + SettingValueNodeV3::updateState(invoker); + auto currentCorner = static_cast(this->getValue()); + } void onCornerClick(CCObject* sender) { tlBtn->toggle(true); trBtn->toggle(true); blBtn->toggle(true); brBtn->toggle(true); - m_currentPos = tagToCorner(sender->getTag()); - this->dispatchChanged(); + SettingPosEnum value = tagToCorner(sender->getTag()); + this->setValue(value, static_cast(sender)); }; - void onInfoBtn(CCObject* sender) { - FLAlertLayer::create( - Mod::get()->getSettingDefinition(this->m_value->getKey())->get()->json->get("name").c_str(), - Mod::get()->getSettingDefinition(this->m_value->getKey())->get()->json->get("description").c_str(), - "OK" - )->show(); - } -public: - void commit() override { - static_cast(m_value)->setPos(m_currentPos); - this->dispatchCommitted(); - } - bool hasUncommittedChanges() override { - return m_currentPos != static_cast(m_value)->getPos(); - } - bool hasNonDefaultValue() override { - return m_currentPos != DEFAULT_POS; - } - - // Geode calls this to reset the setting's value back to default - void resetToDefault() override { + void onResetToDefault() override { tlBtn->toggle(true); trBtn->toggle(true); blBtn->toggle(true); brBtn->toggle(false); - m_currentPos = DEFAULT_POS; - } - static SettingPosNode* create(SettingPosValue* value, float width) { - auto ret = new SettingPosNode; - if (ret && ret->init(value, width)) { - ret->autorelease(); - return ret; - } - CC_SAFE_DELETE(ret); - return nullptr; - } -}; - -/* - Application -*/ - -const std::string DEFAULT_APP = "Spotify.exe"; - -struct SettingAppStruct { - std::string m_application; -}; - -class SettingAppValue; - -class SettingAppValue : public SettingValue { -protected: - std::string m_application; -public: - SettingAppValue(std::string const& key, std::string const& modID, std::string const& application) - : SettingValue(key, modID), m_application(application) {} - - bool load(matjson::Value const& json) override { - try { - m_application = static_cast(json.as()); - return true; - } catch(...) { - return false; - } - } - bool save(matjson::Value& json) const override { - json = static_cast(m_application); - return true; - } - SettingNode* createNode(float width) override; - void setApp(std::string app) { - m_application = app; - } - std::string getApp() const { - return m_application; - } -}; - -template<> -struct SettingValueSetter { - static SettingAppStruct get(SettingValue* setting) { - auto appSetting = static_cast(setting); - struct SettingAppStruct defaultStruct = { appSetting->getApp() }; - return defaultStruct; - }; - static void set(SettingAppValue* setting, SettingAppStruct const& value) { - setting->setApp(value.m_application); - }; -}; - - -// I LOVE TEMPLATES - -class SettingAppNode : public SettingNode { -protected: - std::string m_currentApp; - CCMenuItemSpriteExtra* m_resetBtn; - bool init(SettingAppValue* value, float width) { - if (!SettingNode::init(value)) - return false; - m_currentApp = value->getApp(); - this->setContentSize({ width, 40.f }); - auto menu = CCMenu::create(); - auto label = CCLabelBMFont::create("Application", "bigFont.fnt"); - label->setScale(.55F); - label->setPositionX(-100); - auto infoSpr = CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png"); - infoSpr->setScale(.6F); - - //auto infoBtn - auto infoBtn = CCMenuItemSpriteExtra::create( - infoSpr, - this, - menu_selector(SettingAppNode::onInfoBtn) - ); - infoBtn->setPositionX(-30); - defaultApp_input->setString(m_currentApp); - defaultApp_input->setScale(.65F); - - auto fileBtnSpr = CCSprite::createWithSpriteFrameName("gj_folderBtn_001.png"); - fileBtnSpr->setScale(.5f); - - auto fileBtn = CCMenuItemSpriteExtra::create( - fileBtnSpr, this, menu_selector(SettingAppNode::onPickFile) - ); - fileBtn->setPosition(.0f, .0f); - fileBtn->setPositionX(143); - defaultApp_input->setPosition(70 + (width / 2), 23.f); - menu->setPosition(width / 2, 23.f); - menu->addChild(label); - menu->addChild(infoBtn); - this->addChild(defaultApp_input); - menu->addChild(fileBtn); - this->addChild(menu); - - // Revert button - /*auto resetBtnSpr = CCSprite::createWithSpriteFrameName("geode/reset-gold.png"); - resetBtnSpr->setScale(.5f); - - m_resetBtn = CCMenuItemSpriteExtra::create( - resetBtnSpr, this, menu_selector(SettingAppNode::onReset) - ); - m_resetBtn->setPosition( - -10, - .0f - ); - //if (m_resetBtn) m_resetBtn->setVisible(this->hasNonDefaultValue()); - menu->addChild(m_resetBtn);*/ - return true; - } - void onReset(CCObject*) { - createQuickPopup( - "Reset", - "Are you sure you want to reset " + - Mod::get()->getSettingDefinition(this->m_value->getKey())->get()->json->get("name") + - " to default?", - "Cancel", "Reset", - [this](auto, bool btn2) { - if (btn2) { - this->resetToDefault(); - } - } - ); - } - void onPickFile(CCObject*); - // nvm cant use this because stupid geode, how are we supposed to get the desc for custom settings??? whats the point of custom settings?? - void onInfoBtn(CCObject* sender) { - /*FLAlertLayer::create( - setting()->getDefinition().getDisplayName().c_str(), - setting()->castDefinition().description.value(), - "OK" - )->show();*/ - FLAlertLayer::create( - Mod::get()->getSettingDefinition(this->m_value->getKey())->get()->json->get("name").c_str(), - Mod::get()->getSettingDefinition(this->m_value->getKey())->get()->json->get("description").c_str(), - "OK" - )->show(); + this->setValue(SettingPosEnum::BottomRight, nullptr); } public: - TextInput* defaultApp_input = TextInput::create(180.0F, "Application", "bigFont.fnt"); - void commit() override { - static_cast(m_value)->setApp(m_currentApp); - this->dispatchCommitted(); - } - // Geode calls this to query if the setting value has been changed, - // and those changes haven't been committed - bool hasUncommittedChanges() override { - return m_currentApp != static_cast(m_value)->getApp(); - } - - // Geode calls this to query if the setting has a value that is - // different from its default value - bool hasNonDefaultValue() override { - return m_currentApp != DEFAULT_APP; - } - - // Geode calls this to reset the setting's value back to default - void resetToDefault() override { - m_currentApp = DEFAULT_APP; - static_cast(m_value)->setApp(m_currentApp); - defaultApp_input->setString(DEFAULT_APP); - } - static SettingAppNode* create(SettingAppValue* value, float width) { - auto ret = new SettingAppNode; - if (ret && ret->init(value, width)) { + static SettingPosNode* create(std::shared_ptr setting, float width) { + auto ret = new SettingPosNode(); + if (ret && ret->init(setting, width)) { ret->autorelease(); return ret; } @@ -725,14 +261,16 @@ class SettingAppNode : public SettingNode { Credits */ -class SettingCreditsValue; - -class SettingCreditsValue : public SettingValue { -protected: - std::string m_placeholder; +class SettingCreditsValue : public SettingV3 { public: - SettingCreditsValue(std::string const& key, std::string const& modID, std::string const& placeholder) - : SettingValue(key, modID), m_placeholder(placeholder) {} + static Result> parse(std::string const& key, std::string const& modID, matjson::Value const& json) { + auto res = std::make_shared(); + auto root = checkJson(json, "SettingCreditsValue"); + res->init(key, modID, root); + res->parseNameAndDescription(root); + root.checkUnknownKeys(); + return root.ok(res); + } bool load(matjson::Value const& json) override { return true; @@ -740,17 +278,20 @@ class SettingCreditsValue : public SettingValue { bool save(matjson::Value& json) const override { return true; } - SettingNode* createNode(float width) override; + bool isDefaultValue() const override { + return true; + } + void reset() override {} + SettingNodeV3* createNode(float width) override; }; -class SettingCreditsNode : public SettingNode { +class SettingCreditsNode : public SettingNodeV3 { protected: - bool init(SettingCreditsValue* value, float width) { - if (!SettingNode::init(value)) + bool init(std::shared_ptr setting, float width) { + if (!SettingNodeV3::init(setting, width)) return false; this->setContentSize({ width, 40.f }); - auto menu = CCMenu::create(); auto creditsSpr = ButtonSprite::create("Credits", "bigFont.fnt", "GJ_button_01.png"); creditsSpr->setScale(.6F); auto creditsBtn = CCMenuItemSpriteExtra::create( @@ -758,7 +299,6 @@ class SettingCreditsNode : public SettingNode { this, menu_selector(SettingCreditsNode::onCreditsBtn) ); - creditsBtn->setPositionX(-115); auto betaTestersSpr = ButtonSprite::create("Beta Testers", "bigFont.fnt", "GJ_button_01.png"); betaTestersSpr->setScale(.6F); auto betaTestersBtn = CCMenuItemSpriteExtra::create( @@ -766,13 +306,15 @@ class SettingCreditsNode : public SettingNode { this, menu_selector(SettingCreditsNode::onBetaBtn) ); - betaTestersBtn->setPositionX(90); - menu->setPosition(width / 2, 20.f); - menu->addChild(creditsBtn); - menu->addChild(betaTestersBtn); - this->addChild(menu); + getButtonMenu()->setContentWidth(width); + getButtonMenu()->addChildAtPosition(creditsBtn, Anchor::Center, {-55, 0}); + getButtonMenu()->addChildAtPosition(betaTestersBtn, Anchor::Center, {85, 0}); + getButtonMenu()->updateLayout(); + getNameLabel()->setVisible(false); return true; } + void onCommit() override {} + void onResetToDefault() override {} public: void onCreditsBtn(CCObject*) { @@ -782,31 +324,15 @@ class SettingCreditsNode : public SettingNode { CreditsBetaMenu::create()->show(); } - - void commit() override { - // Let the UI know you have committed the value - this->dispatchCommitted(); - } - - // Geode calls this to query if the setting value has been changed, - // and those changes haven't been committed - bool hasUncommittedChanges() override { + bool hasUncommittedChanges() const override { return false; } - - // Geode calls this to query if the setting has a value that is - // different from its default value - bool hasNonDefaultValue() override { - return true; - } - - // Geode calls this to reset the setting's value back to default - void resetToDefault() override { - + bool hasNonDefaultValue() const override { + return false; } - static SettingCreditsNode* create(SettingCreditsValue* value, float width) { - auto ret = new SettingCreditsNode; - if (ret && ret->init(value, width)) { + static SettingCreditsNode* create(std::shared_ptr setting, float width) { + auto ret = new SettingCreditsNode(); + if (ret && ret->init(setting, width)) { ret->autorelease(); return ret; } diff --git a/src/Styles/GauntletStyle.cpp b/src/Styles/GauntletStyle.cpp index 2217817..1f99f3a 100644 --- a/src/Styles/GauntletStyle.cpp +++ b/src/Styles/GauntletStyle.cpp @@ -55,7 +55,7 @@ class $modify(CustomGauntletSelectLayer, GauntletSelectLayer) { void setupGauntlets() { GauntletSelectLayer::setupGauntlets(); - if (!Mod::get()->getSettingValue("gauntletDesign")) return; + if (!Mod::get()->template getSettingValue("gauntletDesign")) return; CCSprite* infoSpr = CCSprite::createWithSpriteFrameName("GJ_infoIcon_001.png"); CCMenuItemSpriteExtra* infoBtn = CCMenuItemSpriteExtra::create( @@ -734,4 +734,4 @@ class $modify(CustomGauntletSelectLayer, GauntletSelectLayer) { } } } -}; \ No newline at end of file +}; diff --git a/src/Styles/IconLockColors.cpp b/src/Styles/IconLockColors.cpp index 465b68b..9000ab1 100644 --- a/src/Styles/IconLockColors.cpp +++ b/src/Styles/IconLockColors.cpp @@ -127,7 +127,7 @@ class $modify(GJGarageLayer) { void onSelect(cocos2d::CCObject* sender) { GJGarageLayer::onSelect(sender); - if (!Mod::get()->getSettingValue("previewIcons")) return; + if (!Mod::get()->template getSettingValue("previewIcons")) return; IconLockColors::createIconColor(); } diff --git a/src/Utils/DemonList.cpp b/src/Utils/DemonList.cpp index 695e098..4672ea5 100644 --- a/src/Utils/DemonList.cpp +++ b/src/Utils/DemonList.cpp @@ -58,7 +58,7 @@ class $modify(LevelInfoLayer) { } bool init(GJGameLevel* level, bool p1) { // inspiration le gdbrowser, what does p1 do? idk if (!LevelInfoLayer::init(level, p1)) return false; - if (!Mod::get()->getSettingValue("demonListPlacement")) return true; + if (!Mod::get()->template getSettingValue("demonListPlacement")) return true; if (level->m_demon.value() == 0 || level->m_stars.value() != 10) return true; if (level->m_demonDifficulty != 6) return true; @@ -104,9 +104,9 @@ class $modify(LevelInfoLayer) { const geode::utils::MiniFunction)> then = [this, level, levelID, loading_circle, positionLabel, demonSpr, winSize](Result const& result_json) { matjson::Value json = result_json.value(); - int listId = Mod::get()->getSettingValue("demonListSelection").m_pos; + std::string listId = Mod::get()->template getSettingValue("demonListSelection"); - if (listId == 2) { + if (listId == "Pointercrate") { if (loading_circle != nullptr) { loading_circle->fadeAndRemove(); } @@ -159,9 +159,9 @@ class $modify(LevelInfoLayer) { this->release(); }; - int listId = Mod::get()->getSettingValue("demonListSelection").m_pos; + std::string listId = Mod::get()->template getSettingValue("demonListSelection"); std::string url = ""; - if (listId == 2) { + if (listId == "Pointercrate") { url = fmt::format("https://pointercrate.com/api/v2/demons/listed/?name={}", url_encode(level->m_levelName).c_str()); } else { url = fmt::format("https://api.aredl.net/api/aredl/levels/{}", levelID); @@ -190,4 +190,4 @@ class $modify(LevelInfoLayer) { return true; } }; -// demon list \ No newline at end of file +// demon list diff --git a/src/Utils/FriendsProfilePage.cpp b/src/Utils/FriendsProfilePage.cpp index 9475884..041f06d 100644 --- a/src/Utils/FriendsProfilePage.cpp +++ b/src/Utils/FriendsProfilePage.cpp @@ -63,7 +63,7 @@ class SearchUserLayer : public BrownAlertDelegate { class $modify(FriendPage, FriendsProfilePage) { bool init(UserListType type) { if (!FriendsProfilePage::init(type)) return false; - if (!Mod::get()->getSettingValue("friendSearch")) return true; + if (!Mod::get()->template getSettingValue("friendSearch")) return true; auto menu = this->m_buttonMenu; auto downSpr = CCSprite::createWithSpriteFrameName("edit_downBtn2_001.png"); diff --git a/src/Utils/InfoNewLayer.cpp b/src/Utils/InfoNewLayer.cpp index 1fb5cd6..ef33337 100644 --- a/src/Utils/InfoNewLayer.cpp +++ b/src/Utils/InfoNewLayer.cpp @@ -18,7 +18,7 @@ class $modify(InfoLayer) { // Check if it's InfoLayer for level if (level == nullptr) return true; - if (!Mod::get()->getSettingValue("levelsProtocolButton")) return true; + if (!Mod::get()->template getSettingValue("levelsProtocolButton")) return true; std::string levelID = std::to_string(level->m_levelID.value()); diff --git a/src/Utils/SpotifyHandler.cpp b/src/Utils/SpotifyHandler.cpp index 627a5be..124448f 100644 --- a/src/Utils/SpotifyHandler.cpp +++ b/src/Utils/SpotifyHandler.cpp @@ -146,13 +146,12 @@ void toggleSpotifyMute(bool automatic = false, bool muted = false) { } else { is_muted = muted; } - if (is_muted) { log::info("Muting Spotify..."); } else { log::info("Unmuting Spotify..."); } - std::wstring targetExeName = StringToWstring(Mod::get()->getSettingValue("spotifyApp").m_application); + std::wstring targetExeName = Mod::get()->template getSettingValue("spotifyApp").filename().wstring(); DWORD processId = GetProcessIdByName(targetExeName); if (processId) { MuteAudioSessionByProcessId(processId, is_muted); @@ -186,7 +185,7 @@ bool isApplicationRunning(const std::string& appName) { return (result.find("true") != std::string::npos); } void MuteApplication() { - std::string targetName = Mod::get()->getSettingValue("spotifyApp").m_application; + std::string targetName = Mod::get()->template getSettingValue("spotifyApp").filename().string(); // Remove the ".app" extension if it exists size_t dotAppPos = targetName.find(".app"); if (dotAppPos != std::string::npos) { diff --git a/src/main.cpp b/src/main.cpp index ec7863d..4b65b6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -174,7 +174,7 @@ class $modify(CCScheduler) { // used to be GameManager if (currentLayer != layerName) { currentLayer = layerName; EventsPush::stopNow(scene); - bool everywhereElse = Mod::get()->getSettingValue("everywhereElse"); + bool everywhereElse = Mod::get()->template getSettingValue("everywhereElse"); if ((layerName != "LevelEditorLayer" && layerName != "PlayLayer") && !everywhereElse) return; if ((layerName != "LevelEditorLayer" && layerName != "PlayLayer") && everywhereElse) { processChestEvent(scene); @@ -184,9 +184,9 @@ class $modify(CCScheduler) { // used to be GameManager if (!event_fired) return; if (event_data == nullptr) return; event_fired = false; - bool everywhereElse = Mod::get()->getSettingValue("everywhereElse"); - bool inLevels = Mod::get()->getSettingValue("inLevels"); - bool inEditor = Mod::get()->getSettingValue("inEditor"); + bool everywhereElse = Mod::get()->template getSettingValue("everywhereElse"); + bool inLevels = Mod::get()->template getSettingValue("inLevels"); + bool inEditor = Mod::get()->template getSettingValue("inEditor"); bool pushEvent = true; if (layerName == "PlayLayer" && !inLevels) { @@ -221,7 +221,7 @@ class $modify(CCScheduler) { // GD Protocol part if (layerName == "PlayLayer") return; if (layerName == "LoadingLayer") return; - bool levelsProtocol = Mod::get()->getSettingValue("levelsProtocol"); + bool levelsProtocol = Mod::get()->template getSettingValue("levelsProtocol"); if (!levelsProtocol) return; auto glm = GameLevelManager::sharedState(); @@ -308,7 +308,7 @@ class $modify(CCSprite) { auto ret = CCSprite::create(name); if (ret == nullptr) return ret; // better code, thanks camila! - if (!strcmp(name, "GJ_gradientBG.png") && Mod::get()->getSettingValue("activate-background")) { + if (!strcmp(name, "GJ_gradientBG.png") && Mod::get()->template getSettingValue("activate-background")) { Loader::get()->queueInMainThread([=] { if (ret != nullptr) { if (ret->getColor() == ccc3(0, 102, 255)) { @@ -316,7 +316,7 @@ class $modify(CCSprite) { if (scene->getChildrenCount() == 0) return; auto layer = scene->getChildren()->objectAtIndex(0); std::string layerName = misc::getNodeName(layer); - ret->setColor(Mod::get()->getSettingValue("background")); + ret->setColor(Mod::get()->template getSettingValue("background")); } } }); @@ -332,72 +332,72 @@ class $modify(CCScale9Sprite) { auto ret = cocos2d::extension::CCScale9Sprite::create(name, rect); if (ret == nullptr) return ret; // better code, thanks camila! - if ((!strcmp(name, "square02b_001.png") || !strcmp(name, "square02b_small.png")) && Mod::get()->getSettingValue("activate-background")) { + if ((!strcmp(name, "square02b_001.png") || !strcmp(name, "square02b_small.png")) && Mod::get()->template getSettingValue("activate-background")) { Loader::get()->queueInMainThread([=] { if (ret != nullptr) { // jouca waht if (ret->getColor() == ccc3(0, 56, 141)) { - ccColor3B new_color = Mod::get()->getSettingValue("child-background"); - if (Mod::get()->getSettingValue("syncBGcolor")) { - new_color = Mod::get()->getSettingValue("background"); + ccColor3B new_color = Mod::get()->template getSettingValue("child-background"); + if (Mod::get()->template getSettingValue("syncBGcolor")) { + new_color = Mod::get()->template getSettingValue("background"); } - if (Mod::get()->getSettingValue("addChildBDGradient")) { + if (Mod::get()->template getSettingValue("addChildBDGradient")) { new_color = ccc3(new_color.r * 0.79, new_color.g * 0.79, new_color.b * 0.79); } - if (Mod::get()->getSettingValue("bgchild-transparency")) { - int opacity = Mod::get()->getSettingValue("bgchild-transparency-scroll"); + if (Mod::get()->template getSettingValue("bgchild-transparency")) { + int opacity = Mod::get()->template getSettingValue("bgchild-transparency-scroll"); ret->setOpacity(opacity); } ret->setColor(new_color); } else if (ret->getColor() == ccc3(0, 39, 98)) { - ccColor3B new_color = Mod::get()->getSettingValue("child-background"); - if (Mod::get()->getSettingValue("syncBGcolor")) { - new_color = Mod::get()->getSettingValue("background"); + ccColor3B new_color = Mod::get()->template getSettingValue("child-background"); + if (Mod::get()->template getSettingValue("syncBGcolor")) { + new_color = Mod::get()->template getSettingValue("background"); } - if (Mod::get()->getSettingValue("addChildBDGradient")) { + if (Mod::get()->template getSettingValue("addChildBDGradient")) { new_color = ccc3(new_color.r * 0.71, new_color.g * 0.71, new_color.b * 0.71); } - if (Mod::get()->getSettingValue("bgchild-transparency")) { - int opacity = Mod::get()->getSettingValue("bgchild-transparency-scroll"); + if (Mod::get()->template getSettingValue("bgchild-transparency")) { + int opacity = Mod::get()->template getSettingValue("bgchild-transparency-scroll"); ret->setOpacity(opacity); } ret->setColor(new_color); } else if (ret->getColor() == ccc3(0, 46, 117)) { - ccColor3B new_color = Mod::get()->getSettingValue("child-background"); - if (Mod::get()->getSettingValue("syncBGcolor")) { - new_color = Mod::get()->getSettingValue("background"); + ccColor3B new_color = Mod::get()->template getSettingValue("child-background"); + if (Mod::get()->template getSettingValue("syncBGcolor")) { + new_color = Mod::get()->template getSettingValue("background"); } - if (Mod::get()->getSettingValue("addChildBDGradient")) { + if (Mod::get()->template getSettingValue("addChildBDGradient")) { new_color = ccc3(new_color.r * 0.74, new_color.g * 0.74, new_color.b * 0.74); } - if (Mod::get()->getSettingValue("bgchild-transparency")) { - int opacity = Mod::get()->getSettingValue("bgchild-transparency-scroll"); + if (Mod::get()->template getSettingValue("bgchild-transparency")) { + int opacity = Mod::get()->template getSettingValue("bgchild-transparency-scroll"); ret->setOpacity(opacity); } ret->setColor(new_color); } else if (ret->getColor() == ccc3(0, 36, 91)) { - ccColor3B new_color = Mod::get()->getSettingValue("child-background"); - if (Mod::get()->getSettingValue("syncBGcolor")) { - new_color = Mod::get()->getSettingValue("background"); + ccColor3B new_color = Mod::get()->template getSettingValue("child-background"); + if (Mod::get()->template getSettingValue("syncBGcolor")) { + new_color = Mod::get()->template getSettingValue("background"); } - if (Mod::get()->getSettingValue("addChildBDGradient")) { + if (Mod::get()->template getSettingValue("addChildBDGradient")) { new_color = ccc3(new_color.r * 0.70, new_color.g * 0.70, new_color.b * 0.70); } - if (Mod::get()->getSettingValue("bgchild-transparency")) { - int opacity = Mod::get()->getSettingValue("bgchild-transparency-scroll"); + if (Mod::get()->template getSettingValue("bgchild-transparency")) { + int opacity = Mod::get()->template getSettingValue("bgchild-transparency-scroll"); ret->setOpacity(opacity); } ret->setColor(new_color); } else if (ret->getColor() == ccc3(0, 31, 79)) { - ccColor3B new_color = Mod::get()->getSettingValue("child-background"); - if (Mod::get()->getSettingValue("syncBGcolor")) { - new_color = Mod::get()->getSettingValue("background"); + ccColor3B new_color = Mod::get()->template getSettingValue("child-background"); + if (Mod::get()->template getSettingValue("syncBGcolor")) { + new_color = Mod::get()->template getSettingValue("background"); } - if (Mod::get()->getSettingValue("addChildBDGradient")) { + if (Mod::get()->template getSettingValue("addChildBDGradient")) { new_color = ccc3(new_color.r * 0.67, new_color.g * 0.67, new_color.b * 0.67); } - if (Mod::get()->getSettingValue("bgchild-transparency")) { - int opacity = Mod::get()->getSettingValue("bgchild-transparency-scroll"); + if (Mod::get()->template getSettingValue("bgchild-transparency")) { + int opacity = Mod::get()->template getSettingValue("bgchild-transparency-scroll"); ret->setOpacity(opacity); } ret->setColor(new_color); @@ -421,7 +421,7 @@ class $modify(MenuLayer) { is_dailychest_ready = true; }*/ if (!is_socketserver_started) { - bool startSocketServer = Mod::get()->getSettingValue("socketServer"); + bool startSocketServer = Mod::get()->template getSettingValue("socketServer"); if (startSocketServer) { current_socket = sio::socket::ptr(); std::thread hThread(start_socket_func); @@ -474,6 +474,16 @@ class $modify(MyMenuLayerGDUTILS, MenuLayer) { }; */ +$execute { + (void)Mod::get()->registerCustomSettingType("test-notification", &SettingTestValue::parse); + (void)Mod::get()->registerCustomSettingType("credit-buttons", &SettingCreditsValue::parse); + //(void)Mod::get()->registerCustomSettingType("notificationPlacement", &SettingPosValue::parse); + auto ret = Mod::get()->registerCustomSettingType("notification-placement", &SettingPosValue::parse); + if (!ret) { + log::error("Unable to register setting type: {}", ret.unwrapErr()); + } +} + // When the socket connection is made $on_mod(Loaded) { log::info("GDUtils Mod Loaded"); @@ -483,24 +493,15 @@ class $modify(MyMenuLayerGDUTILS, MenuLayer) { //Discord::init(); for next update ;) // also for whatever reason, discord rpc doesnt work on vanilla gd, instead it shows absolutes MH icon for some reason even though I dont own MH. can someone explain that - Mod::get()->addCustomSetting("test-notification", "none"); - Mod::get()->addCustomSetting("notificationPlacement", 4); - Mod::get()->addCustomSetting("demonListSelection", 2); - // Sections - Mod::get()->addCustomSetting("notification-section", "none"); - Mod::get()->addCustomSetting("notification-placement-section", "none"); - Mod::get()->addCustomSetting("notification-appearance-section", "none"); - Mod::get()->addCustomSetting("spotify-section", "none"); - Mod::get()->addCustomSetting("misc-section", "none"); - Mod::get()->addCustomSetting("background-section", "none"); - Mod::get()->addCustomSetting("credits-section", "none"); + /*Mod::get()->registerCustomSettingType("notificationPlacement", 4); + Mod::get()->registerCustomSettingType("demonListSelection", 2); // ok listen here, you dont provide a way to JUST get the file name, you provide the full path which isnt what i want, so dont complain geode devs. Okay? we good? ok #ifdef GEODE_IS_WINDOWS - Mod::get()->addCustomSetting("spotifyApp", "Spotify.exe"); + Mod::get()->registerCustomSettingType("spotifyApp", "Spotify.exe"); #else - Mod::get()->addCustomSetting("spotifyApp", "Spotify.app"); + Mod::get()->registerCustomSettingType("spotifyApp", "Spotify.app"); #endif - Mod::get()->addCustomSetting("credit-buttons", "none"); + Mod::get()->registerCustomSettingType("credit-buttons", "none");*/ #ifdef GEODE_IS_WINDOWS #include