From b6fb87ef2c92dee85877d92e06715591fa6a1cbc Mon Sep 17 00:00:00 2001 From: Alphalaneous <38200084+Alphalaneous@users.noreply.github.com> Date: Thu, 3 Oct 2024 00:50:20 -0400 Subject: [PATCH] Formatting fixes, Bug Fixes - Fix CCLabelBMFont color setting - Fix compatibility with Gradient Pages and Custom Profiles - Fix flicker on cells - Fix LeaderboardsLayer and LevelBrowserLayer colors on refresh - Use geode string utils --- src/BackgroundColors.h | 54 ++ src/CCDirector.h | 34 -- src/FileWatcher.h | 28 +- src/Macros.h | 43 +- src/UIModding.cpp | 799 ++++++++++++++---------------- src/UIModding.h | 2 +- src/Utils.h | 48 +- src/fixes/FontFix.cpp | 26 +- src/main.cpp | 3 +- src/nodes/CCLabelBMFont.h | 16 +- src/nodes/CCMenu.h | 38 +- src/nodes/CCMenuItemSpriteExtra.h | 54 +- src/nodes/CCScale9Sprite.h | 35 +- src/nodes/CCScene.h | 16 +- src/nodes/CCTextInputNode.h | 2 +- src/nodes/CommentCell.h | 33 +- src/nodes/EditLevelLayer.h | 16 +- src/nodes/GJChestSprite.h | 14 +- src/nodes/GJCommentListLayer.h | 93 ++-- src/nodes/GJDropDownLayer.h | 18 +- src/nodes/GJListLayer.h | 6 +- src/nodes/InfoLayer.h | 14 +- src/nodes/LevelSearchLayer.h | 8 +- src/nodes/LoadingLayer.h | 4 +- src/nodes/MenuGameLayer.h | 28 +- src/nodes/MenuLayer.h | 8 +- 26 files changed, 694 insertions(+), 746 deletions(-) create mode 100644 src/BackgroundColors.h delete mode 100644 src/CCDirector.h diff --git a/src/BackgroundColors.h b/src/BackgroundColors.h new file mode 100644 index 0000000..3a3591d --- /dev/null +++ b/src/BackgroundColors.h @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include +#include +#include "UIModding.h" + +using namespace geode::prelude; + +void setBackground(CCNode* node) { + if (UIModding::get()->doModify) { + if (CCSprite* bg = typeinfo_cast(node->getChildByIDRecursive("background"))) { + if (bg->getColor() == ccColor3B{0, 102, 255}) { + std::optional dataOpt = UIModding::get()->getColors("background"); + if (dataOpt.has_value()) { + ColorData data = dataOpt.value(); + bg->setColor(data.color); + bg->setOpacity(data.alpha); + } + } + } + } +} + +class $modify(CCDirector) { + + static void onModify(auto& self) { + (void) self.setHookPriority("CCDirector::willSwitchToScene", INT_MIN); + } + + void willSwitchToScene(CCScene* scene) { + setBackground(scene); + CCDirector::willSwitchToScene(scene); + } +}; + +class $modify(LeaderboardsLayer) { + + bool init(LeaderboardState p0) { + if (!LeaderboardsLayer::init(p0)) return false; + setBackground(this); + return true; + } +}; + +class $modify(LevelBrowserLayer) { + + bool init(GJSearchObject* p0) { + if (!LevelBrowserLayer::init(p0)) return false; + setBackground(this); + return true; + } +}; \ No newline at end of file diff --git a/src/CCDirector.h b/src/CCDirector.h deleted file mode 100644 index ea81e31..0000000 --- a/src/CCDirector.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include -#include -#include "UIModding.h" - -using namespace geode::prelude; - -#ifndef GEODE_IS_MACOS - -class $modify(CCDirector){ - - static void onModify(auto& self) { - (void) self.setHookPriority("CCDirector::willSwitchToScene", INT_MIN); - } - - void willSwitchToScene(CCScene* scene){ - if(UIModding::get()->doModify){ - if(CCSprite* bg = typeinfo_cast(scene->getChildByIDRecursive("background"))){ - if(bg->getColor() == ccColor3B{0, 102, 255}){ - std::optional dataOpt = UIModding::get()->getColors("background"); - if(dataOpt.has_value()){ - ColorData data = dataOpt.value(); - bg->setColor(data.color); - bg->setOpacity(data.alpha); - } - } - } - } - CCDirector::willSwitchToScene(scene); - } -}; - -#endif \ No newline at end of file diff --git a/src/FileWatcher.h b/src/FileWatcher.h index 29bcf81..c1d8459 100644 --- a/src/FileWatcher.h +++ b/src/FileWatcher.h @@ -20,23 +20,23 @@ class FileWatcher { FileWatcher(std::string pathToWatch, std::chrono::duration delay) : m_pathToWatch(pathToWatch), m_delay{delay} { - if(std::filesystem::is_directory(pathToWatch)){ - for(auto& file : std::filesystem::recursive_directory_iterator(pathToWatch)) { + if (std::filesystem::is_directory(pathToWatch)) { + for (auto& file : std::filesystem::recursive_directory_iterator(pathToWatch)) { m_paths[file.path().string()] = std::filesystem::last_write_time(file); } } } - void stop(){ + void stop() { m_running = false; } void start(const std::function &action) { - while(m_running) { + while (m_running) { std::this_thread::sleep_for(m_delay); - if(std::filesystem::is_directory(m_pathToWatch)){ + if (std::filesystem::is_directory(m_pathToWatch)) { auto it = m_paths.begin(); while (it != m_paths.end()) { @@ -44,23 +44,19 @@ class FileWatcher { action(it->first, FileStatus::erased); it = m_paths.erase(it); } - else { - it++; - } + else it++; } - for(auto& file : std::filesystem::recursive_directory_iterator(m_pathToWatch)) { + for (auto& file : std::filesystem::recursive_directory_iterator(m_pathToWatch)) { auto currentFileLastWriteTime = std::filesystem::last_write_time(file); - if(!contains(file.path().string())) { + if (!contains(file.path().string())) { m_paths[file.path().string()] = currentFileLastWriteTime; action(file.path().string(), FileStatus::created); - } else { - if(m_paths[file.path().string()] != currentFileLastWriteTime) { - m_paths[file.path().string()] = currentFileLastWriteTime; - action(file.path().string(), FileStatus::modified); - } - } + } else if (m_paths[file.path().string()] != currentFileLastWriteTime) { + m_paths[file.path().string()] = currentFileLastWriteTime; + action(file.path().string(), FileStatus::modified); + } } } } diff --git a/src/Macros.h b/src/Macros.h index 6a75d29..48ecfe0 100644 --- a/src/Macros.h +++ b/src/Macros.h @@ -13,29 +13,29 @@ }(value) #define typeForEaseCC(easingTypeName) \ -if(name == #easingTypeName){\ +if (name == #easingTypeName) {\ easingType = CC##easingTypeName::create(action, rate);\ } #define typeForEaseRate(easingTypeName) \ -if(name == #easingTypeName){\ +if (name == #easingTypeName) {\ easingType = CCEase##easingTypeName::create(action, rate);\ } #define typeForEase(easingTypeName) \ -if(name == #easingTypeName){\ +if (name == #easingTypeName) {\ easingType = CCEase##easingTypeName::create(action);\ } #define handleModifyForType(typeName) \ -if(type == #typeName){\ +if (type == #typeName) {\ UIModding::get()->handleModifications(getChildOfType(node, index), childObject);\ } #define nodesFor(methodName) if(node) UIModding::get()->methodName(node, nodeAttributesObject) #define actionForName2(name, x, y, param2) if(type == #name){ \ - if(!isNumber){ \ + if (!isNumber) { \ actionToDo = CC##name::create(duration, x, y); \ } \ else { \ @@ -44,7 +44,7 @@ if(type == #typeName){\ } #define actionForName(name, params) if(type == #name){ \ - if(!isNumber){ \ + if (!isNumber) { \ actionToDo = CC##name::create params; \ } \ } @@ -57,8 +57,8 @@ class $modify(name){ \ }\ \ bool method params { \ - if(!name::method values) return false;\ - if(UIModding::get()->doModify){\ + if (!name::method values) return false;\ + if (UIModding::get()->doModify) {\ UIModding::get()->doUICheckForType(#name, this);\ }\ return true;\ @@ -74,7 +74,7 @@ class $modify(name){ \ \ static name* method params { \ auto ret = name::method values; \ - if(UIModding::get()->doModify){\ + if (UIModding::get()->doModify) {\ UIModding::get()->doUICheckForType(#name, ret);\ }\ return ret;\ @@ -82,25 +82,25 @@ class $modify(name){ \ }; #define setSpriteVar(varName, jsonName, type)\ -if(infoVal.contains(#jsonName)){\ +if (infoVal.contains(#jsonName)) {\ matjson::Value val = infoVal[#jsonName];\ - if(val.is_##type()){\ + if (val.is_##type()) {\ varName = val.as_##type();\ }\ } #define setSpriteVarNum(varName, jsonName, type)\ -if(infoVal.contains(#jsonName)){\ +if (infoVal.contains(#jsonName)) {\ matjson::Value val = infoVal[#jsonName];\ - if(val.is_number()){\ + if (val.is_number()) {\ varName = val.as_##type();\ }\ } #define forEvent(type, method)\ -if(eventObject.contains(#type)){\ +if (eventObject.contains(#type)) {\ matjson::Value eventVal = eventObject[#type];\ - if(eventVal.is_object()){\ + if (eventVal.is_object()) {\ matjson::Object event = eventVal.as_object();\ event["_pack-name"] = nodeObject["_pack-name"];\ button->set##method(event);\ @@ -117,24 +117,25 @@ struct My##class : geode::Modify { \ };\ void method(paramType* p0){\ class::method(p0);\ + checkBG(0);\ this->schedule(schedule_selector(My##class::checkBG));\ }\ void checkBG(float dt) {\ CCLayerColor* child = getChildOfType(this, 0);\ - if(child){\ - if(m_fields->m_lastBG != child->getColor()){\ + if (child) {\ + if (m_fields->m_lastBG != child->getColor()) {\ m_fields->m_lastBG = child->getColor();\ - if(child->getColor() == ccColor3B{161,88,44}){\ + if (child->getColor() == ccColor3B{161,88,44}) {\ std::optional dataOpt = UIModding::get()->getColors("list-cell-odd");\ - if(dataOpt.has_value()){\ + if (dataOpt.has_value()) {\ ColorData data = dataOpt.value();\ child->setColor(data.color);\ child->setOpacity(data.alpha);\ }\ }\ - else if(child->getColor() == ccColor3B{194,114,62}){\ + else if (child->getColor() == ccColor3B{194,114,62}) {\ std::optional dataOpt = UIModding::get()->getColors("list-cell-even");\ - if(dataOpt.has_value()){\ + if (dataOpt.has_value()) {\ ColorData data = dataOpt.value();\ child->setColor(data.color);\ child->setOpacity(data.alpha);\ diff --git a/src/UIModding.cpp b/src/UIModding.cpp index 0008755..69dc1b9 100644 --- a/src/UIModding.cpp +++ b/src/UIModding.cpp @@ -17,10 +17,10 @@ UIModding* UIModding::instance = nullptr; UIModding::get()->doModify = Mod::get()->getSettingValue("ui-modifications"); } -void UIModding::updateColors(CCNode* node, std::string name){ - if(CCScale9Sprite* bg = typeinfo_cast(node->getChildByIDRecursive(name))){ +void UIModding::updateColors(CCNode* node, std::string name) { + if (CCScale9Sprite* bg = typeinfo_cast(node->getChildByIDRecursive(name))) { std::optional dataOpt = getColors(name); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); bg->setColor(data.color); bg->setOpacity(data.alpha); @@ -28,10 +28,10 @@ void UIModding::updateColors(CCNode* node, std::string name){ } } -std::optional UIModding::getColors(std::string name){ +std::optional UIModding::getColors(std::string name) { - if(colorCache.contains(name)){ - if(colorCache[name].hasColor){ + if (colorCache.contains(name)) { + if (colorCache[name].hasColor) { return colorCache[name]; } else { @@ -50,29 +50,29 @@ std::optional UIModding::getColors(std::string name){ std::string error; std::optional value = matjson::parse(data, error); - if(value.has_value()){ + if (value.has_value()) { matjson::Value expandedValue = value.value(); - if(expandedValue.is_object()){ + if (expandedValue.is_object()) { matjson::Object object = expandedValue.as_object(); - if(object.contains(name)){ + if (object.contains(name)) { matjson::Value colorsVal = object[name]; - if(colorsVal.is_object()){ + if (colorsVal.is_object()) { matjson::Object colors = colorsVal.as_object(); - if(colors.contains("r") && colors.contains("g") && colors.contains("b")){ + if (colors.contains("r") && colors.contains("g") && colors.contains("b")) { matjson::Value rValue = colors["r"]; matjson::Value gValue = colors["g"]; matjson::Value bValue = colors["b"]; unsigned char alpha = 255; - if(colors.contains("a")){ + if (colors.contains("a")) { matjson::Value aValue = colors["a"]; - if(aValue.is_number()) { + if (aValue.is_number()) { alpha = aValue.as_int(); } } - if(rValue.is_number() && gValue.is_number() && bValue.is_number()){ + if (rValue.is_number() && gValue.is_number() && bValue.is_number()) { unsigned char r = rValue.as_int(); unsigned char g = gValue.as_int(); unsigned char b = bValue.as_int(); @@ -95,7 +95,7 @@ std::optional UIModding::getColors(std::string name){ return std::nullopt; } -void UIModding::recursiveModify(CCNode* node, matjson::Object elements){ +void UIModding::recursiveModify(CCNode* node, matjson::Object elements) { CCArray* children = node->getChildren(); if (CCArray* pageChildren = typeinfo_cast(node->getUserObject("alphalaneous.pages_api/page-children"))){ @@ -111,10 +111,10 @@ void UIModding::recursiveModify(CCNode* node, matjson::Object elements){ id = Utils::strReplace(node->getID(), identifier, ""); } - if(elements.contains(id)){ + if (elements.contains(id)) { matjson::Value nodeValue = elements[id]; - if(nodeValue.is_object()){ + if (nodeValue.is_object()) { matjson::Object nodeObject = nodeValue.as_object(); handleModifications(node, nodeObject); } @@ -122,27 +122,27 @@ void UIModding::recursiveModify(CCNode* node, matjson::Object elements){ } } -void UIModding::runAction(CCNode* node, matjson::Object attributes){ +void UIModding::runAction(CCNode* node, matjson::Object attributes) { #ifndef GEODE_IS_MACOS - if(attributes.contains("actions")){ + if (attributes.contains("actions")) { matjson::Value actionsValue = attributes["actions"]; - if(actionsValue.is_array()){ + if (actionsValue.is_array()) { CCArray* actionArray = CCArray::create(); matjson::Array actionValues = actionsValue.as_array(); - for(matjson::Value action : actionValues){ - if(action.is_object()){ + for (matjson::Value action : actionValues) { + if (action.is_object()) { CCActionInterval* actionInterval = createAction(node, action); - if(actionInterval){ + if (actionInterval) { actionArray->addObject(actionInterval); } } } - if(actionArray->count() > 0){ + if (actionArray->count() > 0) { node->runAction(CCSpawn::create(actionArray)); } } @@ -150,12 +150,12 @@ void UIModding::runAction(CCNode* node, matjson::Object attributes){ #endif } -CCActionInterval* UIModding::createAction(CCNode* node, matjson::Value action){ +CCActionInterval* UIModding::createAction(CCNode* node, matjson::Value action) { CCActionInterval* retAction = nullptr; #ifndef GEODE_IS_MACOS - if(action.contains("type")) { + if (action.contains("type")) { bool repeat = false; @@ -171,57 +171,57 @@ CCActionInterval* UIModding::createAction(CCNode* node, matjson::Value action){ CCActionInterval* actionToDo = nullptr; - if(action.contains("easing")){ + if (action.contains("easing")) { matjson::Value easingValue = action["easing"]; - if(easingValue.is_string()){ + if (easingValue.is_string()) { easingType = easingValue.as_string(); } } - if(action.contains("easing-rate")){ + if (action.contains("easing-rate")) { matjson::Value easingRateVal = action["easing-rate"]; - if(easingRateVal.is_number()){ + if (easingRateVal.is_number()) { easingRate = easingRateVal.as_double(); } } - if(action.contains("repeat")){ + if (action.contains("repeat")) { matjson::Value repeatVal = action["repeat"]; - if(repeatVal.is_bool()){ + if (repeatVal.is_bool()) { repeat = repeatVal.as_bool(); } - if(repeatVal.is_number()){ + if (repeatVal.is_number()) { repeatCount = repeatVal.as_int(); } } - if(action.contains("duration")){ + if (action.contains("duration")) { matjson::Value durationValue = action["duration"]; - if(durationValue.is_number()){ + if (durationValue.is_number()) { duration = durationValue.as_double(); } } bool isNumber = false; - if(action.contains("value")){ + if (action.contains("value")) { matjson::Value valueValue = action["value"]; - if(valueValue.is_number()){ + if (valueValue.is_number()) { isNumber = true; value = valueValue.as_double(); } - else if(valueValue.is_object()){ - if(valueValue.contains("x") && valueValue.contains("y")){ + else if (valueValue.is_object()) { + if (valueValue.contains("x") && valueValue.contains("y")) { matjson::Value xValue = valueValue["x"]; matjson::Value yValue = valueValue["y"]; - if(xValue.is_number() && yValue.is_number()){ + if (xValue.is_number() && yValue.is_number()) { x = xValue.as_double(); y = yValue.as_double(); } } - if(valueValue.contains("width") && valueValue.contains("height")){ + if (valueValue.contains("width") && valueValue.contains("height")) { matjson::Value wValue = valueValue["width"]; matjson::Value hValue = valueValue["height"]; - if(wValue.is_number() && hValue.is_number()){ + if (wValue.is_number() && hValue.is_number()) { x = wValue.as_double(); y = hValue.as_double(); } @@ -230,39 +230,37 @@ CCActionInterval* UIModding::createAction(CCNode* node, matjson::Value action){ } matjson::Value typeValue = action["type"]; - if(typeValue.is_string()){ + if (typeValue.is_string()) { std::string type = typeValue.as_string(); - if(type == "Sequence"){ + if (type == "Sequence") { CCArray* sequentialActions = CCArray::create(); - if(action.contains("actions")){ + if (action.contains("actions")) { matjson::Value seqActions = action["actions"]; - if(seqActions.is_array()){ + if (seqActions.is_array()) { matjson::Array seqActionsArr = seqActions.as_array(); - for(matjson::Value seqAction : seqActionsArr){ + for (matjson::Value seqAction : seqActionsArr) { CCActionInterval* seqActionToDo = createAction(node, seqAction); - if(seqActionToDo){ + if (seqActionToDo) { sequentialActions->addObject(seqActionToDo); } } } } - if(sequentialActions->count() > 0){ + if (sequentialActions->count() > 0) { actionToDo = CCSequence::create(sequentialActions); } } - if(type == "Stop"){ + if (type == "Stop") { node->stopAllActions(); } - - actionForName(MoveBy, (duration, {x, y})); actionForName(MoveTo, (duration, {x, y})); actionForName(SkewBy, (duration, x, y)); @@ -276,14 +274,14 @@ CCActionInterval* UIModding::createAction(CCNode* node, matjson::Value action){ actionForName2(RotateTo, x, y, value); } - if(actionToDo){ + if (actionToDo) { CCActionInterval* finalAction = getEasingType(easingType, actionToDo, easingRate); - if(finalAction){ - if(repeat){ + if (finalAction) { + if (repeat) { retAction = CCRepeat::create(finalAction, repeatCount); } - else{ + else { retAction = finalAction; } } @@ -293,11 +291,11 @@ CCActionInterval* UIModding::createAction(CCNode* node, matjson::Value action){ return retAction; } -CCActionInterval* UIModding::getEasingType(std::string name, CCActionInterval* action, float rate){ +CCActionInterval* UIModding::getEasingType(std::string name, CCActionInterval* action, float rate) { CCActionInterval* easingType = nullptr; - if(name == "none"){ + if (name == "none") { easingType = action; } @@ -327,115 +325,112 @@ CCActionInterval* UIModding::getEasingType(std::string name, CCActionInterval* a return easingType; } -void UIModding::setLayout(CCNode* node, matjson::Object attributes){ +void UIModding::setLayout(CCNode* node, matjson::Object attributes) { - if(attributes.contains("layout")){ + if (attributes.contains("layout")) { matjson::Value layoutValue = attributes["layout"]; - if(layoutValue.is_object()){ + if (layoutValue.is_object()) { AxisLayout* layout; - if(node->getLayout()){ + if (node->getLayout()) { layout = typeinfo_cast(node->getLayout()); - if(layoutValue.contains("remove")){ + if (layoutValue.contains("remove")) { matjson::Value removeValue = layoutValue["remove"]; - if(removeValue.is_bool()){ + if (removeValue.is_bool()) { node->setLayout(nullptr); } } } - else{ + else { layout = AxisLayout::create(); node->setLayout(layout); } - if(layout){ + if (layout) { - if(layoutValue.contains("axis")){ + if (layoutValue.contains("axis")) { matjson::Value axisValue = layoutValue["axis"]; - if(axisValue.is_string()){ + if (axisValue.is_string()) { std::string axis = axisValue.as_string(); - if(axis == "row"){ + if (axis == "row") { layout->setAxis(Axis::Row); } - else if(axis == "column"){ + else if (axis == "column") { layout->setAxis(Axis::Column); } } } - if(layoutValue.contains("flip-axis")){ + if (layoutValue.contains("flip-axis")) { matjson::Value flipAxisValue = layoutValue["flip-axis"]; - if(flipAxisValue.is_bool()){ + if (flipAxisValue.is_bool()) { bool flipAxis = flipAxisValue.as_bool(); layout->setAxisReverse(flipAxis); } } - if(layoutValue.contains("ignore-invisible")){ + if (layoutValue.contains("ignore-invisible")) { matjson::Value ignoreInvisibleValue = layoutValue["ignore-invisible"]; - if(ignoreInvisibleValue.is_bool()){ + if (ignoreInvisibleValue.is_bool()) { bool ignoreInvisible = ignoreInvisibleValue.as_bool(); layout->ignoreInvisibleChildren(ignoreInvisible); } } - if(layoutValue.contains("flip-cross-axis")){ + if (layoutValue.contains("flip-cross-axis")) { matjson::Value flipCrossAxisValue = layoutValue["flip-cross-axis"]; - if(flipCrossAxisValue.is_bool()){ + if (flipCrossAxisValue.is_bool()) { bool flipCrossAxis = flipCrossAxisValue.as_bool(); layout->setCrossAxisReverse(flipCrossAxis); } } - if(layoutValue.contains("auto-scale")){ + if (layoutValue.contains("auto-scale")) { matjson::Value autoScaleValue = layoutValue["auto-scale"]; - if(autoScaleValue.is_bool()){ + if (autoScaleValue.is_bool()) { bool autoScale = autoScaleValue.as_bool(); layout->setAutoScale(autoScale); } } - if(layoutValue.contains("grow-cross-axis")){ + if (layoutValue.contains("grow-cross-axis")) { matjson::Value growCrossAxisValue = layoutValue["grow-cross-axis"]; - if(growCrossAxisValue.is_bool()){ + if (growCrossAxisValue.is_bool()) { bool growCrossAxis = growCrossAxisValue.as_bool(); layout->setGrowCrossAxis(growCrossAxis); } } - if(layoutValue.contains("allow-cross-axis-overflow")){ + if (layoutValue.contains("allow-cross-axis-overflow")) { matjson::Value allowCrossAxisOverflowValue = layoutValue["allow-cross-axis-overflow"]; - if(allowCrossAxisOverflowValue.is_bool()){ + if (allowCrossAxisOverflowValue.is_bool()) { bool allowCrossAxisOverflow = allowCrossAxisOverflowValue.as_bool(); layout->setCrossAxisOverflow(allowCrossAxisOverflow); } } - if(layoutValue.contains("gap")){ + if (layoutValue.contains("gap")) { matjson::Value gapValue = layoutValue["gap"]; - if(gapValue.is_number()){ + if (gapValue.is_number()) { float gap = gapValue.as_double(); layout->setGap(gap); } } - if(layoutValue.contains("axis-alignment")){ + if (layoutValue.contains("axis-alignment")) { matjson::Value axisAlignmentValue = layoutValue["axis-alignment"]; - if(axisAlignmentValue.is_string()){ + if (axisAlignmentValue.is_string()) { std::string axisAlignmentStr = axisAlignmentValue.as_string(); AxisAlignment axisAlignment = getAxisAlignment(axisAlignmentStr); layout->setAxisAlignment(axisAlignment); - } } - if(layoutValue.contains("cross-axis-alignment")){ + if (layoutValue.contains("cross-axis-alignment")) { matjson::Value crossAxisAlignmentValue = layoutValue["cross-axis-alignment"]; - if(crossAxisAlignmentValue.is_string()){ + if (crossAxisAlignmentValue.is_string()) { std::string crossAxisAlignmentStr = crossAxisAlignmentValue.as_string(); AxisAlignment axisAlignment = getAxisAlignment(crossAxisAlignmentStr); layout->setCrossAxisAlignment(axisAlignment); - } } - if(layoutValue.contains("cross-axis-line-alignment")){ + if (layoutValue.contains("cross-axis-line-alignment")) { matjson::Value crossAxisLineAlignmentValue = layoutValue["cross-axis-line-alignment"]; - if(crossAxisLineAlignmentValue.is_string()){ + if (crossAxisLineAlignmentValue.is_string()) { std::string crossAxisLineAlignmentStr = crossAxisLineAlignmentValue.as_string(); AxisAlignment axisAlignment = getAxisAlignment(crossAxisLineAlignmentStr); layout->setCrossAxisLineAlignment(axisAlignment); - } } } @@ -444,16 +439,16 @@ void UIModding::setLayout(CCNode* node, matjson::Object attributes){ } } -std::string UIModding::getSound(std::string sound){ +std::string UIModding::getSound(std::string sound) { std::string soundRet = ""; gd::vector paths = CCFileUtils::sharedFileUtils()->getSearchPaths(); - for(std::string path : paths){ + for (std::string path : paths) { std::string soundPathStr = fmt::format("{}{}", path, sound); std::filesystem::path soundPath = std::filesystem::path(soundPathStr); - if(std::filesystem::exists(soundPath)){ + if (std::filesystem::exists(soundPath)) { soundRet = soundPath.string(); break; } @@ -462,53 +457,50 @@ std::string UIModding::getSound(std::string sound){ return soundRet; } -void UIModding::playSound(CCNode* node, matjson::Object attributes){ +void UIModding::playSound(CCNode* node, matjson::Object attributes) { #ifndef GEODE_IS_MACOS - if(attributes.contains("sound")){ + if (attributes.contains("sound")) { matjson::Value soundVal = attributes["sound"]; - if(soundVal.is_string()){ + if (soundVal.is_string()) { std::string sound = soundVal.as_string(); -#ifndef GEODE_IS_ANDROID FMODAudioEngine::sharedEngine()->m_backgroundMusicChannel->setPaused(false); FMODAudioEngine::sharedEngine()->m_globalChannel->setPaused(false); FMODAudioEngine::sharedEngine()->m_channelGroup2->setPaused(false); FMODAudioEngine::sharedEngine()->m_system->update(); -#endif std::string soundPath = getSound(sound); - if(soundPath != ""){ + if (soundPath != "") { FMODAudioEngine::sharedEngine()->playEffectAdvanced(soundPath, 1, 0, 1, 1, true, false, 0, 0, 0, 0, false, 0, false, true, 0, 0, 0, 0); - } } } #endif } -void UIModding::openLink(CCNode* node, matjson::Object attributes){ - if(attributes.contains("link")){ +void UIModding::openLink(CCNode* node, matjson::Object attributes) { + if (attributes.contains("link")) { matjson::Value linkVal = attributes["link"]; - if(linkVal.is_string()){ + if (linkVal.is_string()) { std::string link = linkVal.as_string(); web::openLinkInBrowser(link); } - if(linkVal.is_object()){ + if (linkVal.is_object()) { matjson::Object linkObject = linkVal.as_object(); - if(linkObject.contains("type") && linkObject.contains("id")){ + if (linkObject.contains("type") && linkObject.contains("id")) { matjson::Value typeVal = linkObject["type"]; matjson::Value idVal = linkObject["id"]; - if(typeVal.is_string() && idVal.is_number()){ + if (typeVal.is_string() && idVal.is_number()) { std::string type = typeVal.as_string(); int id = idVal.as_int(); - if(type == "profile"){ + if (type == "profile") { ProfilePage::create(id, false)->show(); } - if(type == "level"){ + if (type == "level") { auto searchObject = GJSearchObject::create(SearchType::Type19, fmt::format("{}&gameVersion=22", id)); auto scene = LevelBrowserLayer::scene(searchObject); CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(0.5f, scene)); @@ -519,45 +511,40 @@ void UIModding::openLink(CCNode* node, matjson::Object attributes){ } } -void UIModding::setShow(CCNode* node, matjson::Object attributes){ - if(attributes.contains("show")){ +void UIModding::setShow(CCNode* node, matjson::Object attributes) { + if (attributes.contains("show")) { matjson::Value showVal = attributes["show"]; - if(showVal.is_bool()){ + if (showVal.is_bool()) { bool show = showVal.as_bool(); - if(FLAlertLayer* alert = typeinfo_cast(node)){ - if(show){ - alert->show(); - } - else{ - alert->keyBackClicked(); - } + if (FLAlertLayer* alert = typeinfo_cast(node)) { + if (show) alert->show(); + else alert->keyBackClicked(); } } } } -void UIModding::setZOrder(CCNode* node, matjson::Object attributes){ - if(attributes.contains("z-order")){ +void UIModding::setZOrder(CCNode* node, matjson::Object attributes) { + if (attributes.contains("z-order")) { matjson::Value zOrderVal = attributes["z-order"]; - if(zOrderVal.is_number()){ + if (zOrderVal.is_number()) { int zOrder = zOrderVal.as_int(); node->setZOrder(zOrder); } } } -void UIModding::setBlending(CCNode* node, matjson::Object attributes){ +void UIModding::setBlending(CCNode* node, matjson::Object attributes) { - if(attributes.contains("blending")){ - + if (attributes.contains("blending")) { matjson::Value blendingVal = attributes["blending"]; - if(blendingVal.is_object()){ + if (blendingVal.is_object()) { matjson::Object blendingObj = blendingVal.as_object(); - if(blendingObj.contains("source") && blendingObj.contains("destination")){ + if (blendingObj.contains("source") && blendingObj.contains("destination")) { matjson::Value sourceVal = blendingObj["source"]; matjson::Value destinationVal = blendingObj["destination"]; - if(sourceVal.is_string() && destinationVal.is_string()){ + if (sourceVal.is_string() && destinationVal.is_string()) { std::string source = sourceVal.as_string(); std::string destination = destinationVal.as_string(); @@ -565,8 +552,8 @@ void UIModding::setBlending(CCNode* node, matjson::Object attributes){ unsigned int src = stringToBlendingMode(source); unsigned int dst = stringToBlendingMode(destination); - if(src != -1 && dst != -1){ - if(CCBlendProtocol* blendable = typeinfo_cast(node)) { + if (src != -1 && dst != -1) { + if (CCBlendProtocol* blendable = typeinfo_cast(node)) { blendable->setBlendFunc({src, dst}); } } @@ -594,38 +581,28 @@ std::map strBlend = { {"GL_ONE_MINUS_CONSTANT_ALPHA", GL_ONE_MINUS_CONSTANT_ALPHA} }; -unsigned int UIModding::stringToBlendingMode(std::string value){ - +unsigned int UIModding::stringToBlendingMode(std::string value) { unsigned int val = -1; - - if(strBlend.contains(value)){ - val = strBlend[value]; - } - + if (strBlend.contains(value)) val = strBlend[value]; return val; } -void UIModding::setFlip(CCNode* node, matjson::Object attributes){ - if(attributes.contains("flip")){ +void UIModding::setFlip(CCNode* node, matjson::Object attributes) { + if (attributes.contains("flip")) { matjson::Value flipVal = attributes["flip"]; - if(flipVal.is_object()){ + if (flipVal.is_object()) { bool flipX = false; bool flipY = false; - if(flipVal.contains("x")){ + if (flipVal.contains("x")) { matjson::Value xVal = flipVal["x"]; - if(xVal.is_bool()){ - flipX = xVal.as_bool(); - } + if (xVal.is_bool()) flipX = xVal.as_bool(); } - if(flipVal.contains("y")){ + if (flipVal.contains("y")) { matjson::Value yVal = flipVal["y"]; - if(yVal.is_bool()){ - flipY = yVal.as_bool(); - } + if (yVal.is_bool()) flipY = yVal.as_bool(); } - - if(CCSprite* sprite = typeinfo_cast(node)){ + if (CCSprite* sprite = typeinfo_cast(node)) { sprite->setFlipX(flipX); sprite->setFlipY(flipY); } @@ -634,38 +611,36 @@ void UIModding::setFlip(CCNode* node, matjson::Object attributes){ } -void UIModding::setFont(CCNode* node, matjson::Object attributes){ - if(attributes.contains("font")){ +void UIModding::setFont(CCNode* node, matjson::Object attributes) { + if (attributes.contains("font")) { matjson::Value fontVal = attributes["font"]; - if(fontVal.is_string()){ - + if (fontVal.is_string()) { CCLabelBMFont* textObject; std::string font = fontVal.as_string(); - if(CCLabelBMFont* textNode = typeinfo_cast(node)) { + if (CCLabelBMFont* textNode = typeinfo_cast(node)) { textObject = textNode; } - else if(CCMenuItemSpriteExtra* buttonNode = typeinfo_cast(node)) { - if(SearchButton* searchButton = getChildOfType(node, 0)){ + else if (CCMenuItemSpriteExtra* buttonNode = typeinfo_cast(node)) { + if (SearchButton* searchButton = getChildOfType(node, 0)) { textObject = getChildOfType(searchButton, 0); } - else if(ButtonSprite* buttonSprite = getChildOfType(node, 0)){ + else if (ButtonSprite* buttonSprite = getChildOfType(node, 0)) { textObject = getChildOfType(buttonSprite, 0); } - else{ + else { textObject = getChildOfType(node, 0); } } - if(textObject){ - - if(Utils::endsWith(font, ".fnt")){ + if (textObject) { + if (utils::string::endsWith(font, ".fnt")) { MyCCLabelBMFont* myTextObject = static_cast(textObject); CCLabelBMFont* dummyTextObject = CCLabelBMFont::create("", font.c_str()); - if(dummyTextObject){ + if (dummyTextObject) { textObject->setFntFile(font.c_str()); - if(myTextObject->m_fields->m_isLimited){ + if (myTextObject->m_fields->m_isLimited) { textObject->limitLabelWidth(myTextObject->m_fields->m_limitWidth, myTextObject->m_fields->m_limitDefaultScale, myTextObject->m_fields->m_limitMinScale); } } @@ -675,90 +650,90 @@ void UIModding::setFont(CCNode* node, matjson::Object attributes){ } } -void UIModding::setPosition(CCNode* node, matjson::Object attributes){ - if(attributes.contains("position")){ +void UIModding::setPosition(CCNode* node, matjson::Object attributes) { + if (attributes.contains("position")) { matjson::Value position = attributes["position"]; - if(position.is_object()){ + if (position.is_object()) { float x = 0; float y = 0; - if(position.contains("x") && position.contains("y")){ + if (position.contains("x") && position.contains("y")) { matjson::Value xVal = position["x"]; matjson::Value yVal = position["y"]; - if(xVal.is_number() && yVal.is_number()){ + if (xVal.is_number() && yVal.is_number()) { x = xVal.as_double(); y = yVal.as_double(); } } - if(position.contains("anchor")){ + if (position.contains("anchor")) { matjson::Value anchorValue = position["anchor"]; - if(anchorValue.is_object() || anchorValue.is_string()){ + if (anchorValue.is_object() || anchorValue.is_string()) { CCNode* parent = node->getParent(); CCSize nodeSize; - if(parent){ + if (parent) { nodeSize = parent->getContentSize(); } - else{ + else { nodeSize = CCDirector::sharedDirector()->getWinSize(); } - if(!anchorValue.is_string()){ - if(anchorValue.contains("relative")){ + if (!anchorValue.is_string()) { + if (anchorValue.contains("relative")) { matjson::Value relativeValue = anchorValue["relative"]; - if(relativeValue.is_string()){ + if (relativeValue.is_string()) { std::string relative = relativeValue.as_string(); - if(relative == "screen"){ + if (relative == "screen") { nodeSize = CCDirector::sharedDirector()->getWinSize(); } - else if(relative == "parent"){ + else if (relative == "parent") { nodeSize = node->getParent()->getContentSize(); } } } } - if(anchorValue.contains("to") || anchorValue.is_string()){ + if (anchorValue.contains("to") || anchorValue.is_string()) { matjson::Value anchorToValue; - if(anchorValue.is_string()){ + if (anchorValue.is_string()) { anchorToValue = anchorValue; } - else if (anchorValue.contains("to")){ + else if (anchorValue.contains("to")) { anchorToValue = anchorValue["to"]; } - if(anchorToValue.is_string()){ + if (anchorToValue.is_string()) { std::string anchorTo = anchorToValue.as_string(); - if(anchorTo == "top-left"){ + if (anchorTo == "top-left") { y += nodeSize.height; } - else if(anchorTo == "top-center"){ + else if (anchorTo == "top-center") { x += nodeSize.width/2; y += nodeSize.height; } - else if(anchorTo == "top-right"){ + else if (anchorTo == "top-right") { x += nodeSize.width; y += nodeSize.height; } - else if(anchorTo == "center-left"){ + else if (anchorTo == "center-left") { y += nodeSize.height/2; } - else if(anchorTo == "center"){ + else if (anchorTo == "center") { x += nodeSize.width/2; y += nodeSize.height/2; } - else if(anchorTo == "center-right"){ + else if (anchorTo == "center-right") { x += nodeSize.width; y += nodeSize.height/2; } - else if(anchorTo == "bottom-center"){ + else if (anchorTo == "bottom-center") { x += nodeSize.width/2; } - else if(anchorTo == "bottom-right"){ + else if (anchorTo == "bottom-right") { x += nodeSize.width; } - else if(anchorTo == "self"){ + else if (anchorTo == "self") { x += node->getPosition().x; y += node->getPosition().y; } @@ -771,43 +746,39 @@ void UIModding::setPosition(CCNode* node, matjson::Object attributes){ } } -void UIModding::setColor(CCNode* node, matjson::Object attributes){ - if(attributes.contains("color")){ +void UIModding::setColor(CCNode* node, matjson::Object attributes) { + if (attributes.contains("color")) { matjson::Value color = attributes["color"]; - if(color.is_object()){ - if(color.contains("r") && color.contains("g") && color.contains("b")){ + if (color.is_object()) { + if (color.contains("r") && color.contains("g") && color.contains("b")) { matjson::Value colorR = color["r"]; matjson::Value colorG = color["g"]; matjson::Value colorB = color["b"]; - if(colorR.is_number() && colorG.is_number() && colorB.is_number()){ + if (colorR.is_number() && colorG.is_number() && colorB.is_number()) { unsigned char r = colorR.as_int(); unsigned char g = colorG.as_int(); unsigned char b = colorB.as_int(); - if(CCMenuItemSpriteExtra* node1 = typeinfo_cast(node)) { + if (CCMenuItemSpriteExtra* node1 = typeinfo_cast(node)) { node1->setColor(ccColor3B{r, g, b}); - if(ButtonSprite* node2 = getChildOfType(node1, 0)) { + if (ButtonSprite* node2 = getChildOfType(node1, 0)) { node2->setColor(ccColor3B{r, g, b}); } } - - if(CCNodeRGBA* node1 = typeinfo_cast(node)) { - node1->setColor(ccColor3B{r, g, b}); - } - if(CCLayerRGBA* node1 = typeinfo_cast(node)) { + if (CCRGBAProtocol* node1 = typeinfo_cast(node)) { node1->setColor(ccColor3B{r, g, b}); } } } } - if(color.is_string()){ + if (color.is_string()) { std::string colorStr = color.as_string(); - if(colorStr == "reset"){ - if(EventCCMenuItemSpriteExtra* node1 = static_cast(node)) { + if (colorStr == "reset") { + if (EventCCMenuItemSpriteExtra* node1 = static_cast(node)) { node1->setColor(node1->m_fields->originalColor); - if(ButtonSprite* node2 = getChildOfType(node1, 0)) { + if (ButtonSprite* node2 = getChildOfType(node1, 0)) { node2->setColor(node1->m_fields->originalColor); } } @@ -816,36 +787,34 @@ void UIModding::setColor(CCNode* node, matjson::Object attributes){ } } -void UIModding::removeChild(CCNode* node, matjson::Object attributes){ - if(attributes.contains("remove")){ +void UIModding::removeChild(CCNode* node, matjson::Object attributes) { + if (attributes.contains("remove")) { matjson::Value removeVal = attributes["remove"]; - if(removeVal.is_bool()){ + if (removeVal.is_bool()) { bool remove = removeVal.as_bool(); - if(remove){ - removalQueue->addObject(node); - } + if (remove) removalQueue->addObject(node); } } } -void UIModding::setScaleMult(CCNode* node, matjson::Object attributes){ - if(attributes.contains("scale-multiplier")){ +void UIModding::setScaleMult(CCNode* node, matjson::Object attributes) { + if (attributes.contains("scale-multiplier")) { matjson::Value mulVal = attributes["scale-multiplier"]; - if(mulVal.is_number()){ + if (mulVal.is_number()) { float multiplier = mulVal.as_double(); - if(CCMenuItemSpriteExtra* button = typeinfo_cast(node)) { + if (CCMenuItemSpriteExtra* button = typeinfo_cast(node)) { button->m_scaleMultiplier = multiplier; } } } } -void UIModding::setScaleBase(CCNode* node, matjson::Object attributes){ - if(attributes.contains("base-scale")){ +void UIModding::setScaleBase(CCNode* node, matjson::Object attributes) { + if (attributes.contains("base-scale")) { matjson::Value baseVal = attributes["base-scale"]; - if(baseVal.is_number()){ + if (baseVal.is_number()) { float base = baseVal.as_double(); - if(CCMenuItemSpriteExtra* button = typeinfo_cast(node)) { + if (CCMenuItemSpriteExtra* button = typeinfo_cast(node)) { button->m_baseScale = base; } } @@ -867,28 +836,28 @@ void UIModding::setDisablePages(CCNode* node, matjson::Object attributes) { } void UIModding::setText(CCNode* node, matjson::Object attributes){ - if(attributes.contains("text")){ + if (attributes.contains("text")) { matjson::Value textVal = attributes["text"]; - if(textVal.is_string()){ + if (textVal.is_string()) { CCLabelBMFont* textObject; std::string text = textVal.as_string(); - if(CCLabelBMFont* textNode = typeinfo_cast(node)) { + if (CCLabelBMFont* textNode = typeinfo_cast(node)) { textObject = textNode; } - else if(CCMenuItemSpriteExtra* buttonNode = typeinfo_cast(node)) { - if(SearchButton* searchButton = getChildOfType(node, 0)){ + else if (CCMenuItemSpriteExtra* buttonNode = typeinfo_cast(node)) { + if (SearchButton* searchButton = getChildOfType(node, 0)){ textObject = getChildOfType(searchButton, 0); } - else if(ButtonSprite* buttonSprite = getChildOfType(node, 0)){ + else if (ButtonSprite* buttonSprite = getChildOfType(node, 0)) { textObject = getChildOfType(buttonSprite, 0); } - else{ + else { textObject = getChildOfType(node, 0); } } - if(textObject){ + if (textObject) { MyCCLabelBMFont* myTextObject = static_cast(textObject); textObject->setString(text.c_str()); @@ -901,29 +870,29 @@ void UIModding::setText(CCNode* node, matjson::Object attributes){ } } -void UIModding::setSprite(CCNode* node, matjson::Object attributes){ - if(attributes.contains("sprite")){ +void UIModding::setSprite(CCNode* node, matjson::Object attributes) { + if (attributes.contains("sprite")) { matjson::Value sprite = attributes["sprite"]; - if(sprite.is_string()){ + if (sprite.is_string()) { std::string spriteName = sprite.as_string(); CCSprite* spr = Utils::getValidSprite(spriteName.c_str()); - if(!spr) return; + if (!spr) return; - if(CCSprite* spriteNode = typeinfo_cast(node)) { + if (CCSprite* spriteNode = typeinfo_cast(node)) { spriteNode->setTexture(spr->getTexture()); spriteNode->setTextureRect(spr->getTextureRect()); } - if(CCMenuItemSpriteExtra* buttonNode = typeinfo_cast(node)) { + if (CCMenuItemSpriteExtra* buttonNode = typeinfo_cast(node)) { - if(attributes.contains("button-info")){ + if (attributes.contains("button-info")) { matjson::Value infoVal = attributes["button-info"]; - if(infoVal.is_object()){ - if(infoVal.contains("type")){ + if (infoVal.is_object()) { + if (infoVal.contains("type")) { matjson::Value typeVal = infoVal["type"]; - if(typeVal.is_string()){ + if (typeVal.is_string()) { std::string type = typeVal.as_string(); - if(type == "labeled"){ + if (type == "labeled") { std::string caption = ""; int width = 30; @@ -942,18 +911,18 @@ void UIModding::setSprite(CCNode* node, matjson::Object attributes){ setSpriteVar(absolute, absolute, bool); CCSprite* spr = Utils::getValidSprite(texture.c_str()); - if(!spr) return; + if (!spr) return; CCLabelBMFont* fnt = CCLabelBMFont::create("", font.c_str()); - if(spr && fnt){ + if (spr && fnt) { auto buttonSprite = ButtonSprite::create(caption.c_str(), width, absolute, font.c_str(), texture.c_str(), height, scale); buttonNode->setNormalImage(buttonSprite); Utils::updateSprite(buttonNode); } } - else if(type == "sprite"){ + else if (type == "sprite") { buttonNode->setNormalImage(spr); Utils::updateSprite(buttonNode); } @@ -961,14 +930,12 @@ void UIModding::setSprite(CCNode* node, matjson::Object attributes){ } } } - if(ButtonSprite* buttonSprite = getChildOfType(node, 0)){ + if (ButtonSprite* buttonSprite = getChildOfType(node, 0)) { buttonSprite->updateBGImage(spriteName.c_str()); } - else if(CCSprite* sprite = getChildOfType(node, 0)){ - + else if (CCSprite* sprite = getChildOfType(node, 0)) { buttonNode->setNormalImage(spr); Utils::updateSprite(buttonNode); - } } } @@ -977,22 +944,22 @@ void UIModding::setSprite(CCNode* node, matjson::Object attributes){ -void UIModding::setSpriteFrame(CCNode* node, matjson::Object attributes){ - if(attributes.contains("sprite-frame")){ +void UIModding::setSpriteFrame(CCNode* node, matjson::Object attributes) { + if (attributes.contains("sprite-frame")) { matjson::Value sprite = attributes["sprite-frame"]; - if(sprite.is_string()){ + if (sprite.is_string()) { std::string spriteName = sprite.as_string(); - if(CCSprite* spriteNode = typeinfo_cast(node)) { + if (CCSprite* spriteNode = typeinfo_cast(node)) { CCSprite* spr = Utils::getValidSpriteFrame(spriteName.c_str()); - if(spr){ + if(spr) { spriteNode->setTextureAtlas(spr->getTextureAtlas()); spriteNode->setTexture(spr->getTexture()); spriteNode->setTextureRect(spr->getTextureRect()); } } - if(CCMenuItemSpriteExtra* buttonNode = typeinfo_cast(node)) { + if (CCMenuItemSpriteExtra* buttonNode = typeinfo_cast(node)) { CCSprite* spr = Utils::getValidSpriteFrame(spriteName.c_str()); - if(spr){ + if (spr) { buttonNode->setNormalImage(spr); Utils::updateSprite(buttonNode); } @@ -1001,30 +968,30 @@ void UIModding::setSpriteFrame(CCNode* node, matjson::Object attributes){ } } -void UIModding::setOpacity(CCNode* node, matjson::Object attributes){ - if(attributes.contains("opacity")){ +void UIModding::setOpacity(CCNode* node, matjson::Object attributes) { + if (attributes.contains("opacity")) { matjson::Value opacity = attributes["opacity"]; - if(opacity.is_number()){ + if (opacity.is_number()) { unsigned char opacityNum = opacity.as_int(); - if(CCMenuItemSpriteExtra* node1 = typeinfo_cast(node)) { + if (CCMenuItemSpriteExtra* node1 = typeinfo_cast(node)) { node1->setOpacity(opacityNum); - if(ButtonSprite* node2 = getChildOfType(node1, 0)) { + if (ButtonSprite* node2 = getChildOfType(node1, 0)) { node2->setOpacity(opacityNum); } } - if(CCNodeRGBA* nodeRGBA = typeinfo_cast(node)) { + if (CCNodeRGBA* nodeRGBA = typeinfo_cast(node)) { nodeRGBA->setOpacity(opacityNum); } - if(CCLayerRGBA* nodeRGBA = typeinfo_cast(node)) { + if (CCLayerRGBA* nodeRGBA = typeinfo_cast(node)) { nodeRGBA->setOpacity(opacityNum); } } - if(opacity.is_string()){ + if (opacity.is_string()) { std::string opacityStr = opacity.as_string(); - if(opacityStr == "reset"){ - if(EventCCMenuItemSpriteExtra* node1 = static_cast(node)) { + if (opacityStr == "reset") { + if (EventCCMenuItemSpriteExtra* node1 = static_cast(node)) { node1->setOpacity(node1->m_fields->originalOpacity); - if(ButtonSprite* node2 = getChildOfType(node1, 0)) { + if (ButtonSprite* node2 = getChildOfType(node1, 0)) { node2->setOpacity(node1->m_fields->originalOpacity); } } @@ -1033,136 +1000,118 @@ void UIModding::setOpacity(CCNode* node, matjson::Object attributes){ } } -void UIModding::setVisible(CCNode* node, matjson::Object attributes){ +void UIModding::setVisible(CCNode* node, matjson::Object attributes) { - if(attributes.contains("visible")){ + if (attributes.contains("visible")) { matjson::Value visible = attributes["visible"]; - if(visible.is_bool()){ - bool isVisible = visible.as_bool(); - node->setVisible(isVisible); + if (visible.is_bool()) { + node->setVisible(visible.as_bool()); } } } -void UIModding::updateLayout(CCNode* node, matjson::Object attributes){ - if(attributes.contains("update-layout")){ +void UIModding::updateLayout(CCNode* node, matjson::Object attributes) { + if (attributes.contains("update-layout")) { matjson::Value update = attributes["update-layout"]; - if(update.is_bool()){ - bool shouldUpdate = update.as_bool(); - if(shouldUpdate){ - CCNode* parent = node->getParent(); - if(parent){ - parent->updateLayout(); - } + if (update.is_bool()) { + if (update.as_bool()) { + if (CCNode* parent = node->getParent()) parent->updateLayout(); } } } } -void UIModding::setIgnoreAnchorPos(CCNode* node, matjson::Object attributes){ - if(attributes.contains("ignore-anchor-pos")){ +void UIModding::setIgnoreAnchorPos(CCNode* node, matjson::Object attributes) { + if (attributes.contains("ignore-anchor-pos")) { matjson::Value ignore = attributes["ignore-anchor-pos"]; - if(ignore.is_bool()){ - bool isIgnoring = ignore.as_bool(); - node->ignoreAnchorPointForPosition(isIgnoring); + if (ignore.is_bool()) { + node->ignoreAnchorPointForPosition(ignore.as_bool()); } } } -void UIModding::setScale(CCNode* node, matjson::Object attributes){ - if(attributes.contains("scale")){ +void UIModding::setScale(CCNode* node, matjson::Object attributes) { + if (attributes.contains("scale")) { matjson::Value scale = attributes["scale"]; - if(scale.is_object()){ + if (scale.is_object()) { matjson::Object scaleAttributes = scale.as_object(); - if(scaleAttributes.contains("x")){ + if (scaleAttributes.contains("x")) { matjson::Value scaleX = scaleAttributes["x"]; - if(!scaleX.is_null() && scaleX.is_number()){ - float scaleValue = scaleX.as_double(); - node->setScaleX(scaleValue); + if (!scaleX.is_null() && scaleX.is_number()) { + node->setScaleX(scaleX.as_double()); } } - if(scaleAttributes.contains("y")){ + if (scaleAttributes.contains("y")) { matjson::Value scaleY = scaleAttributes["y"]; - if(!scaleY.is_null() && scaleY.is_number()){ - float scaleValue = scaleY.as_double(); - node->setScaleY(scaleValue); + if (!scaleY.is_null() && scaleY.is_number()) { + node->setScaleY(scaleY.as_double()); } } } - if(scale.is_number()){ - float scaleValue = scale.as_double(); - node->setScale(scaleValue); + if (scale.is_number()) { + node->setScale(scale.as_double()); } } } -void UIModding::setRotation(CCNode* node, matjson::Object attributes){ - if(attributes.contains("rotation")){ +void UIModding::setRotation(CCNode* node, matjson::Object attributes) { + if (attributes.contains("rotation")) { matjson::Value rotation = attributes["rotation"]; - if(rotation.is_object()){ + if (rotation.is_object()) { matjson::Object rotationAttributes = rotation.as_object(); - if(rotationAttributes.contains("x")){ + if (rotationAttributes.contains("x")) { matjson::Value rotationX = rotationAttributes["x"]; - if(!rotationX.is_null() && rotationX.is_number()){ - float rotationValue = rotationX.as_double(); - node->setRotationX(rotationValue); + if (!rotationX.is_null() && rotationX.is_number()) { + node->setRotationX(rotationX.as_double()); } } - if(rotationAttributes.contains("y")){ + if (rotationAttributes.contains("y")) { matjson::Value rotationY = rotationAttributes["y"]; - if(!rotationY.is_null() && rotationY.is_number()){ - float rotationValue = rotationY.as_double(); - node->setRotationY(rotationValue); + if (!rotationY.is_null() && rotationY.is_number()) { + node->setRotationY(rotationY.as_double()); } } } - if(rotation.is_number()){ - float rotationValue = rotation.as_double(); - node->setRotation(rotationValue); + if (rotation.is_number()) { + node->setRotation(rotation.as_double()); } } } -void UIModding::setSkew(CCNode* node, matjson::Object attributes){ - if(attributes.contains("skew")){ +void UIModding::setSkew(CCNode* node, matjson::Object attributes) { + if (attributes.contains("skew")) { matjson::Value skew = attributes["skew"]; - if(skew.is_object()){ + if (skew.is_object()) { matjson::Object skewAttributes = skew.as_object(); - if(skewAttributes.contains("x")){ + if (skewAttributes.contains("x")) { matjson::Value skewX = skewAttributes["x"]; - if(skewX.is_number()){ - float skewValue = skewX.as_double(); - node->setSkewX(skewValue); - } + if (skewX.is_number()) node->setSkewX(skewX.as_double()); } - if(skewAttributes.contains("y")){ + if (skewAttributes.contains("y")) { matjson::Value skewY = skewAttributes["y"]; - if(skewY.is_number()){ - float skewValue = skewY.as_double(); - node->setSkewY(skewValue); - } + if (skewY.is_number()) node->setSkewY(skewY.as_double()); } } } } -void UIModding::setAnchorPoint(CCNode* node, matjson::Object attributes){ - if(attributes.contains("anchor-point")){ +void UIModding::setAnchorPoint(CCNode* node, matjson::Object attributes) { + if (attributes.contains("anchor-point")) { matjson::Value anchorPoint = attributes["anchor-point"]; - if(anchorPoint.is_object()){ + if (anchorPoint.is_object()) { matjson::Object anchorPointAttributes = anchorPoint.as_object(); - if(anchorPointAttributes.contains("x") && anchorPointAttributes.contains("y")){ + if (anchorPointAttributes.contains("x") && anchorPointAttributes.contains("y")) { matjson::Value anchorPointX = anchorPointAttributes["x"]; matjson::Value anchorPointY = anchorPointAttributes["y"]; - if(anchorPointX.is_number() && anchorPointY.is_number()){ + if (anchorPointX.is_number() && anchorPointY.is_number()) { float anchorPointValueX = anchorPointX.as_double(); float anchorPointValueY = anchorPointY.as_double(); node->setAnchorPoint({anchorPointValueX, anchorPointValueY}); @@ -1172,17 +1121,17 @@ void UIModding::setAnchorPoint(CCNode* node, matjson::Object attributes){ } } -void UIModding::setContentSize(CCNode* node, matjson::Object attributes){ - if(attributes.contains("content-size")){ +void UIModding::setContentSize(CCNode* node, matjson::Object attributes) { + if (attributes.contains("content-size")) { matjson::Value contentSize = attributes["content-size"]; - if(contentSize.is_object()){ + if (contentSize.is_object()) { matjson::Object contentSizeAttributes = contentSize.as_object(); - if(contentSizeAttributes.contains("width") && contentSizeAttributes.contains("height")){ + if (contentSizeAttributes.contains("width") && contentSizeAttributes.contains("height")) { matjson::Value contentSizeWidth = contentSizeAttributes["width"]; matjson::Value contentSizeHeight = contentSizeAttributes["height"]; - if(contentSizeWidth.is_number() && contentSizeHeight.is_number()){ + if (contentSizeWidth.is_number() && contentSizeHeight.is_number()) { float contentSizeValueWidth = contentSizeWidth.as_double(); float contentSizeValueHeight = contentSizeHeight.as_double(); @@ -1193,15 +1142,15 @@ void UIModding::setContentSize(CCNode* node, matjson::Object attributes){ } } -void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ +void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject) { - if(DataNode* data = typeinfo_cast(node)){ + if (DataNode* data = typeinfo_cast(node)){ node = data->m_data; } - if(nodeObject.contains("attributes")){ + if (nodeObject.contains("attributes")) { matjson::Value nodeAttributes = nodeObject["attributes"]; - if(nodeAttributes.is_object()){ + if (nodeAttributes.is_object()) { matjson::Object nodeAttributesObject = nodeAttributes.as_object(); nodeAttributesObject["_pack-name"] = nodeObject["_pack-name"]; @@ -1238,14 +1187,14 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ } } - if(nodeObject.contains("event")){ + if (nodeObject.contains("event")) { matjson::Value eventVal = nodeObject["event"]; - if(eventVal.is_object()){ + if (eventVal.is_object()) { matjson::Object eventObject = eventVal.as_object(); eventObject["_pack-name"] = nodeObject["_pack-name"]; - if(EventCCMenuItemSpriteExtra* button = static_cast(node)){ + if (EventCCMenuItemSpriteExtra* button = static_cast(node)) { forEvent(on-click, OnClick); forEvent(on-release, OnRelease); forEvent(on-activate, OnActivate); @@ -1255,31 +1204,27 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ } } - if(nodeObject.contains("parent")){ + if (nodeObject.contains("parent")) { matjson::Value parentVal = nodeObject["parent"]; - if(parentVal.is_object()){ + if (parentVal.is_object()) { matjson::Object parentObject = parentVal.as_object(); parentObject["_pack-name"] = nodeObject["_pack-name"]; - CCNode* parent = node->getParent(); - if(parent){ - handleModifications(parent, parentObject); - } + if (CCNode* parent = node->getParent()) handleModifications(parent, parentObject); } } - if(nodeObject.contains("children")){ + if (nodeObject.contains("children")) { matjson::Value childrenVal = nodeObject["children"]; - if(childrenVal.is_object()){ + if (childrenVal.is_object()) { matjson::Object childrenObject = childrenVal.as_object(); childrenObject["_pack-name"] = nodeObject["_pack-name"]; - - if(childrenVal.contains("node")){ + if (childrenVal.contains("node")) { matjson::Value nodeChildrenVal = childrenObject["node"]; - if(nodeChildrenVal.is_object()){ + if (nodeChildrenVal.is_object()) { matjson::Object nodeChildrenObject = nodeChildrenVal.as_object(); nodeChildrenObject["_pack-name"] = nodeObject["_pack-name"]; @@ -1287,27 +1232,27 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ recursiveModify(node, nodeChildrenObject); } } - if(childrenVal.contains("index")){ + if (childrenVal.contains("index")) { matjson::Value indexChildrenVal = childrenObject["index"]; - if(indexChildrenVal.is_array()){ + if (indexChildrenVal.is_array()) { matjson::Array nodeChildrenArray = indexChildrenVal.as_array(); - for(matjson::Value value : nodeChildrenArray){ - if(value.is_object()){ + for (matjson::Value value : nodeChildrenArray) { + if (value.is_object()) { matjson::Object childObject = value.as_object(); childObject["_pack-name"] = nodeObject["_pack-name"]; int index = 0; std::string type = "CCNode"; - if(value.contains("index")){ + if (value.contains("index")) { matjson::Value indexVal = value["index"]; - if(indexVal.is_number()){ + if (indexVal.is_number()) { index = indexVal.as_int(); } } - if(value.contains("type")){ + if (value.contains("type")) { matjson::Value typeVal = value["type"]; - if(typeVal.is_string()){ + if (typeVal.is_string()) { type = typeVal.as_string(); } } @@ -1345,14 +1290,13 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ handleModifyForType(CustomSongWidget); handleModifyForType(GJDifficultySprite); handleModifyForType(GJCommentListLayer); - } } } } - if(childrenVal.contains("all")){ + if (childrenVal.contains("all")) { matjson::Value allChildrenVal = childrenObject["all"]; - if(allChildrenVal.is_object()){ + if (allChildrenVal.is_object()) { matjson::Object allChildrenObject = allChildrenVal.as_object(); allChildrenObject["_pack-name"] = nodeObject["_pack-name"]; @@ -1361,43 +1305,43 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ children = pageChildren; } - for(CCNode* node : CCArrayExt(children)){ + for (CCNode* node : CCArrayExt(children)) { handleModifications(node, allChildrenObject); } } } - if(childrenVal.contains("new")){ + if (childrenVal.contains("new")) { matjson::Value newChildrenVal = childrenObject["new"]; - if(newChildrenVal.is_array()){ + if (newChildrenVal.is_array()) { matjson::Array newChildrenArray = newChildrenVal.as_array(); - for(matjson::Value value : newChildrenArray){ - if(value.is_object()){ + for (matjson::Value value : newChildrenArray) { + if (value.is_object()) { matjson::Object childObject = value.as_object(); childObject["_pack-name"] = nodeObject["_pack-name"]; int index = 0; std::string type = "Node"; - if(value.contains("type") && value.contains("id")){ + if (value.contains("type") && value.contains("id")) { matjson::Value typeVal = value["type"]; - if(typeVal.is_string()){ + if (typeVal.is_string()) { type = typeVal.as_string(); CCNode* newNode = nullptr; - if(type == "CCSprite"){ + if (type == "CCSprite") { newNode = CCSprite::create(); } - if(type == "CCLabelBMFont"){ + if (type == "CCLabelBMFont") { newNode = CCLabelBMFont::create("", "chatFont.fnt"); } - if(type == "CCMenu"){ + if (type == "CCMenu") { newNode = CCMenu::create(); } - if(type == "CCLayerColor"){ + if (type == "CCLayerColor") { newNode = CCLayerColor::create(ccColor4B{0,0,0,0}); } - if(type == "CCMenuItemSpriteExtra"){ + if (type == "CCMenuItemSpriteExtra") { newNode = CCMenuItemSpriteExtra::create(CCSprite::create(), nullptr, nullptr, nullptr); } - if(type == "CCScale9Sprite"){ + if (type == "CCScale9Sprite") { if(childObject.contains("attributes")){ matjson::Value attributesVal = childObject["attributes"]; if(attributesVal.contains("sprite")){ @@ -1409,19 +1353,19 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ } } } - if(type == "Alert"){ - if(childObject.contains("attributes")){ + if (type == "Alert") { + if (childObject.contains("attributes")) { matjson::Value attributesVal = childObject["attributes"]; - if(attributesVal.contains("title") && attributesVal.contains("description")){ + if (attributesVal.contains("title") && attributesVal.contains("description")) { matjson::Value titleVal = attributesVal["title"]; matjson::Value descVal = attributesVal["description"]; - if(titleVal.is_string() && descVal.is_string()){ + if (titleVal.is_string() && descVal.is_string()) { std::string title = titleVal.as_string(); std::string description = descVal.as_string(); std::string buttonText = "Okay"; - if(attributesVal.contains("button-text")){ + if (attributesVal.contains("button-text")) { matjson::Value buttonVal = attributesVal["button-text"]; - if(buttonVal.is_string()){ + if (buttonVal.is_string()) { buttonText = buttonVal.as_string(); } } @@ -1432,40 +1376,40 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ } } } - if(type == "Popup"){ + if (type == "Popup") { std::string sprite = "GJ_square01.png"; std::string title = ""; float width = 60; float height = 60; - if(childObject.contains("attributes")){ + if (childObject.contains("attributes")) { matjson::Value attributesVal = childObject["attributes"]; - if(attributesVal.contains("sprite")){ + if (attributesVal.contains("sprite")) { matjson::Value spriteVal = attributesVal["sprite"]; - if(spriteVal.is_string()){ + if (spriteVal.is_string()) { sprite = spriteVal.as_string(); } } - if(attributesVal.contains("popup-size")){ + if (attributesVal.contains("popup-size")) { matjson::Value contentSize = attributesVal["popup-size"]; - if(contentSize.is_object()){ + if (contentSize.is_object()) { matjson::Object contentSizeAttributes = contentSize.as_object(); - if(contentSizeAttributes.contains("width") && contentSizeAttributes.contains("height")){ + if (contentSizeAttributes.contains("width") && contentSizeAttributes.contains("height")) { matjson::Value contentSizeWidth = contentSizeAttributes["width"]; matjson::Value contentSizeHeight = contentSizeAttributes["height"]; - if(contentSizeWidth.is_number() && contentSizeHeight.is_number()){ + if (contentSizeWidth.is_number() && contentSizeHeight.is_number()) { width = contentSizeWidth.as_double(); height = contentSizeHeight.as_double(); } } } } - if(attributesVal.contains("title")){ + if (attributesVal.contains("title")) { matjson::Value titleVal = attributesVal["title"]; - if(titleVal.is_string()){ + if (titleVal.is_string()) { title = titleVal.as_string(); } } @@ -1474,14 +1418,14 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ DataNode* data = DataNode::create(alert); newNode = data; } - if(newNode){ + if (newNode) { matjson::Value idVal = value["id"]; std::string fullID; - if(idVal.is_string()){ + if (idVal.is_string()) { std::string id = idVal.as_string(); std::string packName = "missing"; - if(nodeObject.contains("_pack-name") && nodeObject["_pack-name"].is_string()){ + if (nodeObject.contains("_pack-name") && nodeObject["_pack-name"].is_string()) { packName = nodeObject["_pack-name"].as_string(); } fullID = fmt::format("{}/{}", packName, id); @@ -1489,18 +1433,18 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ newNode->setID(fullID.c_str()); } - if(DataNode* data = typeinfo_cast(newNode)){ - if(FLAlertLayer* alert = typeinfo_cast(data->m_data)){ + if (DataNode* data = typeinfo_cast(newNode)) { + if (FLAlertLayer* alert = typeinfo_cast(data->m_data)) { alert->setID(fullID.c_str()); } data->setID(fullID.c_str()); } - if(FLAlertLayer* alert = typeinfo_cast(node)){ + if (FLAlertLayer* alert = typeinfo_cast(node)) { alert->m_mainLayer->removeChildByID(fullID); alert->m_mainLayer->addChild(newNode); } - else{ + else { node->removeChildByID(fullID); node->addChild(newNode); } @@ -1517,7 +1461,7 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){ } } -void UIModding::doUICheck(CCNode* node){ +void UIModding::doUICheck(CCNode* node) { std::string path = "ui/" + node->getID() + ".json"; @@ -1530,10 +1474,10 @@ void UIModding::doUICheck(CCNode* node){ std::string error; std::optional value = matjson::parse(data, error); - if(value.has_value()){ + if (value.has_value()) { matjson::Value expandedValue = value.value(); - if(expandedValue.is_object()){ + if (expandedValue.is_object()) { matjson::Object object = expandedValue.as_object(); std::string fullPathStr = CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str(), false); @@ -1541,10 +1485,10 @@ void UIModding::doUICheck(CCNode* node){ std::filesystem::path fullPath(fullPathStr); std::string name = fullPath.parent_path().parent_path().filename().string(); - name = Utils::toLower(name); + name = utils::string::toLower(name); if (name == "resources") { name = fullPath.parent_path().parent_path().parent_path().filename().string(); - name = Utils::toLower(name); + name = utils::string::toLower(name); } std::replace( name.begin(), name.end(), ' ', '-'); @@ -1552,7 +1496,7 @@ void UIModding::doUICheck(CCNode* node){ handleModifications(node, object); } - for(CCNode* node : CCArrayExt(removalQueue)) { + for (CCNode* node : CCArrayExt(removalQueue)) { node->removeFromParentAndCleanup(true); } removalQueue->removeAllObjects(); @@ -1562,13 +1506,13 @@ void UIModding::doUICheck(CCNode* node){ delete[] buffer; } -void UIModding::startFileListeners(){ - for(FileWatcher* fw : listeners){ +void UIModding::startFileListeners() { + for (FileWatcher* fw : listeners) { fw->stop(); } listeners.clear(); std::vector packs = Utils::getActivePacks(); - for(std::string path : packs){ + for (std::string path : packs) { std::string uiPath = fmt::format("{}{}", path, "ui\\"); std::replace(uiPath.begin(), uiPath.end(), '$', '/'); @@ -1578,14 +1522,14 @@ void UIModding::startFileListeners(){ std::thread thread([=](FileWatcher* self){ self->start([=] (std::string pathToWatch, FileStatus status) -> void { - if(!std::filesystem::is_regular_file(std::filesystem::path(pathToWatch)) && status != FileStatus::erased) { + if (!std::filesystem::is_regular_file(std::filesystem::path(pathToWatch)) && status != FileStatus::erased) { return; } Loader::get()->queueInMainThread([]{ UIModding::get()->uiCache.clear(); UIModding::get()->colorCache.clear(); CCScene* scene = CCDirector::sharedDirector()->getRunningScene(); - for(CCNode* node : CCArrayExt(scene->getChildren())){ + for (CCNode* node : CCArrayExt(scene->getChildren())) { UIModding::get()->doUICheck(node); } }); @@ -1597,35 +1541,35 @@ void UIModding::startFileListeners(){ -AxisAlignment UIModding::getAxisAlignment(std::string name){ +AxisAlignment UIModding::getAxisAlignment(std::string name) { AxisAlignment axisAlignment = AxisAlignment::Start; - if(name == "start"){ + if (name == "start") { axisAlignment = AxisAlignment::Start; } - if(name == "center"){ + if (name == "center") { axisAlignment = AxisAlignment::Center; } - if(name == "end"){ + if (name == "end") { axisAlignment = AxisAlignment::End; } - if(name == "even"){ + if (name == "even") { axisAlignment = AxisAlignment::Even; } - if(name == "between"){ + if (name == "between") { axisAlignment = AxisAlignment::Between; } return axisAlignment; } -void UIModding::doUICheckForType(std::string type, CCNode* node){ +void UIModding::doUICheckForType(std::string type, CCNode* node) { matjson::Value value; - if(uiCache.contains(type)){ + if (uiCache.contains(type)) { value = uiCache[type]; } - else{ + else { std::string path = "ui/nodes/" + type + ".json"; unsigned long fileSize = 0; @@ -1637,22 +1581,21 @@ void UIModding::doUICheckForType(std::string type, CCNode* node){ std::string error; std::optional valueOpt = matjson::parse(data, error); - if(valueOpt.has_value()){ + if (valueOpt.has_value()) { value = valueOpt.value(); uiCache.insert({type, value}); } - else{ + else { uiCache.insert({type, matjson::Value(nullptr)}); } } - else{ + else { uiCache.insert({type, matjson::Value(nullptr)}); } delete[] buffer; } - if(!value.is_null()){ + if (!value.is_null()) { matjson::Object object = value.as_object(); handleModifications(node, object); } -} - +} \ No newline at end of file diff --git a/src/UIModding.h b/src/UIModding.h index 9189561..a5a9e60 100644 --- a/src/UIModding.h +++ b/src/UIModding.h @@ -62,7 +62,7 @@ class UIModding { std::optional getColors(std::string name); void updateColors(CCNode* node, std::string name); - static UIModding* get(){ + static UIModding* get() { if (!instance) { instance = new UIModding(); diff --git a/src/Utils.h b/src/Utils.h index 15a0913..3618ede 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -5,26 +5,6 @@ using namespace geode::prelude; namespace Utils { - inline std::string toLower(std::string s) { - for(char &c : s){ - c = tolower(c); - } - return s; - } - - inline bool endsWith(std::string value, std::string ending){ - value = toLower(value); - ending = toLower(ending); - - return value.ends_with(ending); - } - - inline bool startsWith(std::string value, std::string start){ - value = toLower(value); - start = toLower(start); - - return value.starts_with(start); - } inline void updateSprite(CCMenuItemSpriteExtra* button) { auto sprite = button->getNormalImage(); @@ -36,9 +16,9 @@ namespace Utils { inline bool hasNode(CCNode* child, CCNode* node) { CCNode* parent = child; - while(true){ - if(parent){ - if(parent == node){ + while (true) { + if (parent) { + if (parent == node) { return true; } parent = parent->getParent(); @@ -59,9 +39,9 @@ namespace Utils { //fix texture loader fallback - inline CCSprite* getValidSprite(const char* sprName){ + inline CCSprite* getValidSprite(const char* sprName) { CCSprite* spr = CCSprite::create(sprName); - if(!spr || spr->getUserObject("geode.texture-loader/fallback")){ + if (!spr || spr->getUserObject("geode.texture-loader/fallback")) { return nullptr; } return spr; @@ -69,38 +49,38 @@ namespace Utils { //fix texture loader fallback - inline CCSprite* getValidSpriteFrame(const char* sprName){ + inline CCSprite* getValidSpriteFrame(const char* sprName) { CCSprite* spr = CCSprite::createWithSpriteFrameName(sprName); - if(!spr || spr->getUserObject("geode.texture-loader/fallback")){ + if (!spr || spr->getUserObject("geode.texture-loader/fallback")) { return nullptr; } return spr; } - static std::vector getActivePacks(){ + static std::vector getActivePacks() { gd::vector paths = CCFileUtils::sharedFileUtils()->getSearchPaths(); std::vector packPaths; Mod* textureLoader = Loader::get()->getLoadedMod("geode.texture-loader"); - if(textureLoader){ + if (textureLoader) { std::filesystem::path textureLoaderPacks = textureLoader->getConfigDir(); std::string packDirStr = fmt::format("{}{}", textureLoaderPacks, "\\packs"); std::filesystem::path packDir = std::filesystem::path(packDirStr); - for(std::string path : paths){ + for (std::string path : paths) { std::filesystem::path fpath = std::filesystem::path(path); std::filesystem::path pathParent = std::filesystem::path(path); - while(pathParent.has_parent_path()){ + while (pathParent.has_parent_path()) { - if(pathParent == packDir){ - if(std::find(packPaths.begin(), packPaths.end(), fpath.string()) == packPaths.end()) { + if (pathParent == packDir) { + if (std::find(packPaths.begin(), packPaths.end(), fpath.string()) == packPaths.end()) { packPaths.push_back(fpath.string()); break; } } - if(pathParent == std::filesystem::current_path().root_path()){ + if (pathParent == std::filesystem::current_path().root_path()) { break; } pathParent = pathParent.parent_path(); diff --git a/src/fixes/FontFix.cpp b/src/fixes/FontFix.cpp index 343410c..04026fd 100644 --- a/src/fixes/FontFix.cpp +++ b/src/fixes/FontFix.cpp @@ -13,22 +13,20 @@ bool s_isInCreateTextLayers = false; class $modify(GJBaseGameLayer) { - void createTextLayers(){ - + void createTextLayers() { s_isInCreateTextLayers = true; GJBaseGameLayer::createTextLayers(); s_isInCreateTextLayers = false; - } }; class $modify(CCSpriteBatchNode) { - bool initWithTexture(CCTexture2D* texture, unsigned int capacity){ + bool initWithTexture(CCTexture2D* texture, unsigned int capacity) { bool doFix = Mod::get()->getSettingValue("pusab-fix"); - if(doFix){ - if(s_isInCreateTextLayers && texture == CCTextureCache::sharedTextureCache()->addImage("bigFont.png", false)){ + if (doFix) { + if (s_isInCreateTextLayers && texture == CCTextureCache::sharedTextureCache()->addImage("bigFont.png", false)) { return CCSpriteBatchNode::initWithTexture(CCTextureCache::sharedTextureCache()->addImage("bigFont.png"_spr, false), capacity); } } @@ -39,12 +37,12 @@ class $modify(CCSpriteBatchNode) { class $modify(CCLabelBMFont) { - static CCLabelBMFont* createBatched(const char* str, const char* fntFile, CCArray* a, int a1){ + static CCLabelBMFont* createBatched(const char* str, const char* fntFile, CCArray* a, int a1) { bool doFix = Mod::get()->getSettingValue("pusab-fix"); - if(doFix){ - if(strcmp(fntFile, "bigFont.fnt") == 0){ + if (doFix) { + if (strcmp(fntFile, "bigFont.fnt") == 0) { fntFile = "bigFont.fnt"_spr; } } @@ -52,19 +50,19 @@ class $modify(CCLabelBMFont) { } }; -class $modify(CCTextureCache){ - CCTexture2D* addImage(const char* fileimage, bool p1){ +class $modify(CCTextureCache) { + CCTexture2D* addImage(const char* fileimage, bool p1) { CCTexture2D* ret = nullptr; bool didChange = false; - if(strcmp(fileimage, "bigFont.png") == 0){ + if (strcmp(fileimage, "bigFont.png") == 0) { bool doFix = Mod::get()->getSettingValue("pusab-fix"); - if(doFix && (PlayLayer::get() || LevelEditorLayer::get())){ + if (doFix && (PlayLayer::get() || LevelEditorLayer::get())) { didChange = true; ret = CCTextureCache::addImage("bigFont.png"_spr, p1); } } - if(!didChange){ + if (!didChange) { ret = CCTextureCache::addImage(fileimage, p1); } return ret; diff --git a/src/main.cpp b/src/main.cpp index 7fb984a..726df60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,6 @@ #include "nodes/GJChestSprite.h" #include "nodes/CCTextInputNode.h" #include "icons/IconHandler.h" -#include "CCDirector.h" -#include +#include "BackgroundColors.h" using namespace geode::prelude; diff --git a/src/nodes/CCLabelBMFont.h b/src/nodes/CCLabelBMFont.h index b6ba5e5..d9063ff 100644 --- a/src/nodes/CCLabelBMFont.h +++ b/src/nodes/CCLabelBMFont.h @@ -6,7 +6,7 @@ using namespace geode::prelude; -class $modify(MyCCLabelBMFont, CCLabelBMFont){ +class $modify(MyCCLabelBMFont, CCLabelBMFont) { struct Fields { float m_limitWidth = 1; @@ -16,7 +16,7 @@ class $modify(MyCCLabelBMFont, CCLabelBMFont){ SEL_SCHEDULE m_schedule; }; - void limitLabelWidth(float width, float defaultScale, float minScale){ + void limitLabelWidth(float width, float defaultScale, float minScale) { m_fields->m_limitWidth = width; m_fields->m_limitDefaultScale = defaultScale; @@ -26,7 +26,7 @@ class $modify(MyCCLabelBMFont, CCLabelBMFont){ CCLabelBMFont::limitLabelWidth(width, defaultScale, minScale); } - static CCLabelBMFont* create(const char *str, const char *fntFile, float width, CCTextAlignment alignment, CCPoint imageOffset){ + static CCLabelBMFont* create(const char *str, const char *fntFile, float width, CCTextAlignment alignment, CCPoint imageOffset) { auto ret = CCLabelBMFont::create(str, fntFile, width, alignment, imageOffset); auto myRet = static_cast(ret); @@ -35,7 +35,7 @@ class $modify(MyCCLabelBMFont, CCLabelBMFont){ bool doFix = Mod::get()->getSettingValue("pusab-fix"); - if(doFix){ + if (doFix) { myRet->m_fields->m_schedule = schedule_selector(MyCCLabelBMFont::checkParent); ret->schedule(myRet->m_fields->m_schedule); } @@ -47,11 +47,11 @@ class $modify(MyCCLabelBMFont, CCLabelBMFont){ #ifndef GEODE_IS_MACOS - void checkParent(float dt){ + void checkParent(float dt) { - if(auto parent = this->getParent()){ - if(typeinfo_cast(parent)){ - if(strcmp(this->getFntFile(), "bigFont.fnt") == 0){ + if (auto parent = this->getParent()) { + if (typeinfo_cast(parent)) { + if (strcmp(this->getFntFile(), "bigFont.fnt") == 0) { ccBlendFunc blendFunc = this->getBlendFunc(); this->setFntFile("bigFont.fnt"_spr); this->setBlendFunc(blendFunc); diff --git a/src/nodes/CCMenu.h b/src/nodes/CCMenu.h index 0cc66fe..79c2bfe 100644 --- a/src/nodes/CCMenu.h +++ b/src/nodes/CCMenu.h @@ -18,7 +18,7 @@ class EventsPush { }; -class $modify(EventCCMenu, CCMenu){ +class $modify(EventCCMenu, CCMenu) { static void onModify(auto& self) { (void) self.setHookPriority("CCMenu::initWithArray", INT_MAX); @@ -31,50 +31,50 @@ class $modify(EventCCMenu, CCMenu){ CCScene* currentScene = nullptr; }; - bool initWithArray(CCArray* array){ - if(!CCMenu::initWithArray(array)) return false; - if(UIModding::get()->doModify){ + bool initWithArray(CCArray* array) { + if (!CCMenu::initWithArray(array)) return false; + if (UIModding::get()->doModify) { schedule(schedule_selector(EventCCMenu::check), 1/15); } return true; } - void checkTouch(CCNode* node, bool hasLayerOnTop){ + void checkTouch(CCNode* node, bool hasLayerOnTop) { - for(CCNode* nodeA : CCArrayExt(node->getChildren())){ - if(nodeA && nodeIsVisible(nodeA)){ - if(EventCCMenuItemSpriteExtra* button = static_cast(nodeA)){ + for (CCNode* nodeA : CCArrayExt(node->getChildren())) { + if (nodeA && nodeIsVisible(nodeA)) { + if (EventCCMenuItemSpriteExtra* button = static_cast(nodeA)) { button->checkTouch(hasLayerOnTop); } - if(CCMenuItemToggler* toggler = typeinfo_cast(nodeA)){ + if (CCMenuItemToggler* toggler = typeinfo_cast(nodeA)) { checkTouch(nodeA, hasLayerOnTop); } } } } - void check(float dt){ + void check(float dt) { - if(!nodeIsVisible(this)) return; + if (!nodeIsVisible(this)) return; CCScene* currentScene = CCDirector::get()->getRunningScene(); int layerCount = currentScene->getChildrenCount(); - if(layerCount != m_fields->lastLayerCount || currentScene != m_fields->currentScene){ + if (layerCount != m_fields->lastLayerCount || currentScene != m_fields->currentScene) { bool hasLayerOnTop = true; bool gotNode = false; - for(CCNode* node : CCArrayExt(currentScene->getChildren())){ - if(!gotNode && Utils::hasNode(this, node)){ - if(typeinfo_cast(node)) return; + for (CCNode* node : CCArrayExt(currentScene->getChildren())) { + if (!gotNode && Utils::hasNode(this, node)) { + if (typeinfo_cast(node)) return; gotNode = true; hasLayerOnTop = false; continue; } - if(gotNode && node->getContentSize() != CCSize{0,0} && node->isVisible()){ - if(!typeinfo_cast(node) && !typeinfo_cast(node) && node->getID() != "itzkiba.better_progression/tier-popup" && node->getID() != "dankmeme.globed2/notification-panel"){ + if (gotNode && node->getContentSize() != CCSize{0,0} && node->isVisible()) { + if (!typeinfo_cast(node) && !typeinfo_cast(node) && node->getID() != "itzkiba.better_progression/tier-popup" && node->getID() != "dankmeme.globed2/notification-panel") { hasLayerOnTop = true; } break; @@ -86,11 +86,11 @@ class $modify(EventCCMenu, CCMenu){ m_fields->currentScene = currentScene; } - if(!m_fields->hasLayerOnTop){ + if (!m_fields->hasLayerOnTop) { checkTouch(this, m_fields->hasLayerOnTop); m_fields->canExit = true; } - else if(m_fields->canExit){ + else if (m_fields->canExit) { checkTouch(this, m_fields->hasLayerOnTop); m_fields->canExit = false; } diff --git a/src/nodes/CCMenuItemSpriteExtra.h b/src/nodes/CCMenuItemSpriteExtra.h index b7be33b..c5cc116 100644 --- a/src/nodes/CCMenuItemSpriteExtra.h +++ b/src/nodes/CCMenuItemSpriteExtra.h @@ -31,83 +31,83 @@ class $modify(EventCCMenuItemSpriteExtra, CCMenuItemSpriteExtra) { ccColor3B originalColor; unsigned char originalOpacity; }; - void setOnClick(matjson::Object onClick){ + void setOnClick(matjson::Object onClick) { m_fields->onClick = onClick; - if(onClick.contains("override")){ + if (onClick.contains("override")) { matjson::Value overrideVal = onClick["override"]; - if(overrideVal.is_bool()){ + if (overrideVal.is_bool()) { m_fields->overrideOnClick = overrideVal.as_bool(); } } } - void setOnRelease(matjson::Object onRelease){ + void setOnRelease(matjson::Object onRelease) { m_fields->onRelease = onRelease; - if(onRelease.contains("override")){ + if (onRelease.contains("override")) { matjson::Value overrideVal = onRelease["override"]; - if(overrideVal.is_bool()){ + if (overrideVal.is_bool()) { m_fields->overrideOnRelease = overrideVal.as_bool(); } } } - void setOnActivate(matjson::Object onActivate){ + void setOnActivate(matjson::Object onActivate) { m_fields->onActivate = onActivate; - if(onActivate.contains("override")){ + if (onActivate.contains("override")) { matjson::Value overrideVal = onActivate["override"]; - if(overrideVal.is_bool()){ + if (overrideVal.is_bool()) { m_fields->overrideOnActivate = overrideVal.as_bool(); } } } - void setOnHover(matjson::Object onHover){ + void setOnHover(matjson::Object onHover) { m_fields->hasHover = true; m_fields->onHover = onHover; } - void setOnExit(matjson::Object onExit){ + void setOnExit(matjson::Object onExit) { m_fields->hasExit = true; m_fields->onExit = onExit; } - void runOnHover(){ + void runOnHover() { UIModding::get()->handleModifications(this, m_fields->onHover); } - void runOnExit(){ + void runOnExit() { UIModding::get()->handleModifications(this, m_fields->onExit); } - void selected(){ + void selected() { SAFE_RUN( - if(!m_fields->overrideOnClick){ + if (!m_fields->overrideOnClick) { CCMenuItemSpriteExtra::selected(); } UIModding::get()->handleModifications(this, m_fields->onClick); ) } - void unselected(){ + void unselected() { SAFE_RUN( - if(!m_fields->overrideOnRelease){ + if (!m_fields->overrideOnRelease) { CCMenuItemSpriteExtra::unselected(); } UIModding::get()->handleModifications(this, m_fields->onRelease); ) } - void activate(){ + void activate() { SAFE_RUN( - if(!m_fields->overrideOnActivate){ + if (!m_fields->overrideOnActivate) { CCMenuItemSpriteExtra::activate(); } UIModding::get()->handleModifications(this, m_fields->onActivate); ) } - void checkTouch(bool hasLayerOnTop){ + void checkTouch(bool hasLayerOnTop) { - if((m_fields->hasHover || m_fields->hasExit) && nodeIsVisible(this)){ + if ((m_fields->hasHover || m_fields->hasExit) && nodeIsVisible(this)) { CCPoint point = getMousePos(); @@ -123,20 +123,20 @@ class $modify(EventCCMenuItemSpriteExtra, CCMenuItemSpriteExtra) { bool containsPoint = r.containsPoint(local); - if(!hasLayerOnTop){ + if (!hasLayerOnTop) { if (containsPoint && !m_fields->isHovering) { m_fields->isHovering = true; m_fields->originalColor = getColor(); m_fields->originalOpacity = getOpacity(); - if(ButtonSprite* node = getChildOfType(this, 0)) { + if (ButtonSprite* node = getChildOfType(this, 0)) { m_fields->originalColor = node->getColor(); m_fields->originalOpacity = node->getOpacity(); - if(node->getColor() == ccColor3B{255,255,255}){ - if(CCSprite* node1 = getChildOfType(node, 0)) { + if (node->getColor() == ccColor3B{255,255,255}) { + if (CCSprite* node1 = getChildOfType(node, 0)) { m_fields->originalColor = node1->getColor(); m_fields->originalOpacity = node1->getOpacity(); } @@ -144,12 +144,12 @@ class $modify(EventCCMenuItemSpriteExtra, CCMenuItemSpriteExtra) { } runOnHover(); } - if (!containsPoint && m_fields->isHovering){ + if (!containsPoint && m_fields->isHovering) { m_fields->isHovering = false; runOnExit(); } } - else if(m_fields->isHovering){ + else if (m_fields->isHovering) { m_fields->isHovering = false; runOnExit(); } diff --git a/src/nodes/CCScale9Sprite.h b/src/nodes/CCScale9Sprite.h index 383917e..98c211c 100644 --- a/src/nodes/CCScale9Sprite.h +++ b/src/nodes/CCScale9Sprite.h @@ -10,7 +10,7 @@ using namespace geode::prelude; #ifndef GEODE_IS_MACOS -class $modify(MyCCScale9Sprite, CCScale9Sprite){ +class $modify(MyCCScale9Sprite, CCScale9Sprite) { struct Fields { std::string textureName; @@ -20,7 +20,7 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ bool setOriginalRects = true; }; - bool initWithFile(const char* file, CCRect rect, CCRect capInsets){ + bool initWithFile(const char* file, CCRect rect, CCRect capInsets) { if(!CCScale9Sprite::initWithFile(file, rect, capInsets)) return false; m_fields->textureName = std::string(file); m_fields->rect = rect; @@ -29,24 +29,23 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ return true; } - void visit(){ + void visit() { bool doFix = Mod::get()->getSettingValue("ccscale9sprite-fix"); - if(doFix && this->getID() != "star-bg"){ - if(this->*(&MyCCScale9Sprite::m_positionsAreDirty)){ + if (doFix) { + if (this->*(&MyCCScale9Sprite::m_positionsAreDirty)) { updateSprites(); this->*(&MyCCScale9Sprite::m_positionsAreDirty) = false; } CCNode::visit(); } - else{ + else { CCScale9Sprite::visit(); } } - void updateSprites(){ + void updateSprites() { - CCSprite* topLeft = public_cast(this, _topLeft); CCSprite* top = public_cast(this, _top); CCSprite* topRight = public_cast(this, _topRight); @@ -69,7 +68,7 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ bottom->setID("bottom"); bottomRight->setID("bottom-right"); - if(m_fields->setOriginalRects){ + if (m_fields->setOriginalRects) { m_fields->originalRects.push_back(topLeft->getTextureRect()); m_fields->originalRects.push_back(top->getTextureRect()); m_fields->originalRects.push_back(topRight->getTextureRect()); @@ -101,11 +100,11 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ bool isSquishedVertically = false; bool isSquishedHorizontally = false; - if(edgeHeight >= size.height){ + if (edgeHeight >= size.height) { isSquishedVertically = true; } - if(edgeWidth >= size.width){ + if (edgeWidth >= size.width) { isSquishedHorizontally = true; } @@ -160,11 +159,11 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ bottom->setVisible(true); center->setVisible(true); - if(isSquishedVertically || isSquishedHorizontally){ + if (isSquishedVertically || isSquishedHorizontally) { center->setVisible(false); } - if(isSquishedVertically){ + if (isSquishedVertically) { left->setVisible(false); right->setVisible(false); @@ -177,7 +176,7 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ fixBottomSprite(bottomLeft); } - if(isSquishedHorizontally){ + if (isSquishedHorizontally) { top->setVisible(false); bottom->setVisible(false); @@ -191,7 +190,7 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ } } - void fixTopSprite(CCSprite* spr){ + void fixTopSprite(CCSprite* spr) { float overlappingHeight = spr->getContentSize().height*2 - this->getContentSize().height; auto rect = spr->getTextureRect(); @@ -200,7 +199,7 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ spr->setTextureRect(rect, spr->isTextureRectRotated(), rect.size); } - void fixBottomSprite(CCSprite* spr){ + void fixBottomSprite(CCSprite* spr) { float overlappingHeight = spr->getContentSize().height*2 - this->getContentSize().height; auto rect = spr->getTextureRect(); @@ -210,7 +209,7 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ spr->setTextureRect(rect, spr->isTextureRectRotated(), rect.size); } - void fixRightSprite(CCSprite* spr){ + void fixRightSprite(CCSprite* spr) { float overlappingWidth = spr->getContentSize().width*2 - this->getContentSize().width; auto rect = spr->getTextureRect(); @@ -219,7 +218,7 @@ class $modify(MyCCScale9Sprite, CCScale9Sprite){ spr->setTextureRect(rect, spr->isTextureRectRotated(), rect.size); } - void fixLeftSprite(CCSprite* spr){ + void fixLeftSprite(CCSprite* spr) { float overlappingWidth = spr->getContentSize().width*2 - this->getContentSize().width; auto rect = spr->getTextureRect(); diff --git a/src/nodes/CCScene.h b/src/nodes/CCScene.h index 8dc8415..0becbfd 100644 --- a/src/nodes/CCScene.h +++ b/src/nodes/CCScene.h @@ -6,7 +6,7 @@ using namespace geode::prelude; -class $modify(MyCCScene, CCScene){ +class $modify(MyCCScene, CCScene) { static void onModify(auto& self) { (void) self.setHookPriority("CCScene::create", INT_MIN); @@ -17,22 +17,22 @@ class $modify(MyCCScene, CCScene){ bool m_isMenuLayer = false; }; - static CCScene* create(){ + static CCScene* create() { auto ret = CCScene::create(); - if(UIModding::get()->doModify){ + if (UIModding::get()->doModify) { ret->schedule(schedule_selector(MyCCScene::checkForUpdates)); } return ret; } - void checkForUpdates(float dt){ - if(this->getChildrenCount() != m_fields->m_currentCount && (this->getChildrenCount() != 1 || m_fields->m_currentCount == 0)){ + void checkForUpdates(float dt) { + if (this->getChildrenCount() != m_fields->m_currentCount && (this->getChildrenCount() != 1 || m_fields->m_currentCount == 0)) { int idx = 0; - for(CCNode* node : CCArrayExt(this->getChildren())){ + for (CCNode* node : CCArrayExt(this->getChildren())) { idx++; - if(node->getID() == "MenuLayer") continue; - if(idx > m_fields->m_currentCount){ + if (node->getID() == "MenuLayer") continue; + if (idx > m_fields->m_currentCount) { UIModding::get()->doUICheck(node); } } diff --git a/src/nodes/CCTextInputNode.h b/src/nodes/CCTextInputNode.h index 24bc98d..00c14c0 100644 --- a/src/nodes/CCTextInputNode.h +++ b/src/nodes/CCTextInputNode.h @@ -4,7 +4,7 @@ #include #include "../Macros.h" -class $modify(MyCCTextInputNode, CCTextInputNode){ +class $modify(MyCCTextInputNode, CCTextInputNode) { /*void refreshLabel() { CCTextInputNode::refreshLabel(); diff --git a/src/nodes/CommentCell.h b/src/nodes/CommentCell.h index bb3035c..d785927 100644 --- a/src/nodes/CommentCell.h +++ b/src/nodes/CommentCell.h @@ -15,63 +15,62 @@ class $modify(MyCommentCell, CommentCell) { (void) self.setHookPriority("CommentCell::loadFromComment", INT_MIN); } - void loadFromComment(GJComment* p0){ + void loadFromComment(GJComment* p0) { CommentCell::loadFromComment(p0); this->schedule(schedule_selector(MyCommentCell::checkBG)); } void checkBG(float dt) { - CCLayerColor* child = getChildOfType(this, 0); - if(child){ - if(m_fields->m_lastBG != child->getColor()){ + if (CCLayerColor* child = getChildOfType(this, 0)) { + if (m_fields->m_lastBG != child->getColor()) { m_fields->m_lastBG = child->getColor(); - if(UIModding::get()->doModify){ + if (UIModding::get()->doModify) { CCLayer* layer = getChildOfType(this, 1); CCScale9Sprite* bg = getChildOfType(layer, 0); - if(child->getColor() == ccColor3B{161,88,44}){ + if (child->getColor() == ccColor3B{161,88,44}) { std::optional dataOpt = UIModding::get()->getColors("comment-cell-odd"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); child->setColor(data.color); child->setOpacity(data.alpha); } - if(bg){ + if (bg) { std::optional dataOpt2 = UIModding::get()->getColors("comment-cell-bg-odd"); - if(dataOpt2.has_value()){ + if (dataOpt2.has_value()) { ColorData data = dataOpt2.value(); bg->setColor(data.color); bg->setOpacity(data.alpha); } } } - else if(child->getColor() == ccColor3B{194,114,62}){ + else if (child->getColor() == ccColor3B{194,114,62}) { std::optional dataOpt = UIModding::get()->getColors("comment-cell-even"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); child->setColor(data.color); child->setOpacity(data.alpha); } - if(bg){ + if (bg) { std::optional dataOpt2 = UIModding::get()->getColors("comment-cell-bg-even"); - if(dataOpt2.has_value()){ + if (dataOpt2.has_value()) { ColorData data = dataOpt2.value(); bg->setColor(data.color); bg->setOpacity(data.alpha); } } } - else if(child->getColor() == ccColor3B{156,85,42}){ + else if (child->getColor() == ccColor3B{156,85,42}) { std::optional dataOpt = UIModding::get()->getColors("comment-cell-small-odd"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); child->setColor(data.color); child->setOpacity(data.alpha); } } - else if(child->getColor() == ccColor3B{144,79,39}){ + else if (child->getColor() == ccColor3B{144,79,39}) { std::optional dataOpt = UIModding::get()->getColors("comment-cell-small-even"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); child->setColor(data.color); child->setOpacity(data.alpha); diff --git a/src/nodes/EditLevelLayer.h b/src/nodes/EditLevelLayer.h index 2252cd2..a791769 100644 --- a/src/nodes/EditLevelLayer.h +++ b/src/nodes/EditLevelLayer.h @@ -5,26 +5,26 @@ using namespace geode::prelude; -class $modify(MyEditLevelLayer, EditLevelLayer){ +class $modify(MyEditLevelLayer, EditLevelLayer) { static void onModify(auto& self) { (void) self.setHookPriority("EditLevelLayer::init", INT_MIN); } - bool init(GJGameLevel* p0){ - if(!EditLevelLayer::init(p0)) return false; - if(UIModding::get()->doModify){ - if(CCScale9Sprite* bg = typeinfo_cast(this->getChildByID("description-background"))){ + bool init(GJGameLevel* p0) { + if (!EditLevelLayer::init(p0)) return false; + if (UIModding::get()->doModify) { + if (CCScale9Sprite* bg = typeinfo_cast(this->getChildByID("description-background"))) { std::optional dataOpt = UIModding::get()->getColors("edit-description-bg"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); bg->setColor(data.color); bg->setOpacity(data.alpha); } } - if(CCScale9Sprite* bg = typeinfo_cast(this->getChildByID("level-name-background"))){ + if (CCScale9Sprite* bg = typeinfo_cast(this->getChildByID("level-name-background"))) { std::optional dataOpt = UIModding::get()->getColors("edit-name-bg"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); bg->setColor(data.color); bg->setOpacity(data.alpha); diff --git a/src/nodes/GJChestSprite.h b/src/nodes/GJChestSprite.h index 0ad786a..a7396e1 100644 --- a/src/nodes/GJChestSprite.h +++ b/src/nodes/GJChestSprite.h @@ -5,7 +5,7 @@ using namespace geode::prelude; -class $modify(MyGJChestSprite, GJChestSprite){ +class $modify(MyGJChestSprite, GJChestSprite) { static void onModify(auto& self) { (void) self.setHookPriority("GJChestSprite::switchToState", INT_MIN); @@ -15,29 +15,29 @@ class $modify(MyGJChestSprite, GJChestSprite){ int idx = 0; for (auto child : CCArrayExt(parent->getChildren())) { if (::isSpriteFrameName(static_cast(child), name)) { - if(idx == index) return child; + if (idx == index) return child; idx++; } } return nullptr; } - void switchToState(ChestSpriteState p0, bool p1){ + void switchToState(ChestSpriteState p0, bool p1) { GJChestSprite::switchToState(p0, p1); - if(UIModding::get()->doModify){ + if (UIModding::get()->doModify) { - if(p0 == ChestSpriteState::Opened){ + if (p0 == ChestSpriteState::Opened) { auto glow0 = static_cast(getChildBySpriteFrameName(this, "chest_glow_bg_001.png")); auto glow1 = static_cast(getChildBySpriteFrameName(this, "chest_glow_bg_001.png", 1)); auto square = static_cast(getChildBySpriteFrameName(this, "block005b_05_001.png")); - if(!glow0 || !glow1 || !square) return; + if (!glow0 || !glow1 || !square) return; std::optional dataOpt = UIModding::get()->getColors("chest-opened-overlay"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); glow0->setColor(data.color); diff --git a/src/nodes/GJCommentListLayer.h b/src/nodes/GJCommentListLayer.h index 50a21c9..c690a2e 100644 --- a/src/nodes/GJCommentListLayer.h +++ b/src/nodes/GJCommentListLayer.h @@ -23,10 +23,10 @@ class $modify(MyGJCommentListLayer, GJCommentListLayer) { static GJCommentListLayer* create(BoomListView* p0, char const* p1, cocos2d::ccColor4B p2, float p3, float p4, bool p5) { auto ret = GJCommentListLayer::create(p0, p1, p2, p3, p4, p5); - if(UIModding::get()->doModify){ - if(ret->getColor() == ccColor3B{191,114,62}){ + if (UIModding::get()->doModify) { + if (ret->getColor() == ccColor3B{191,114,62}) { std::optional dataOpt = UIModding::get()->getColors("comment-list-layer-bg"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); ret->setColor(data.color); ret->setOpacity(data.alpha); @@ -34,21 +34,19 @@ class $modify(MyGJCommentListLayer, GJCommentListLayer) { } } - #ifndef GEODE_IS_MACOS - bool doFix = Mod::get()->getSettingValue("comment-border-fix"); - if(doFix && !Loader::get()->isModLoaded("bitz.customprofiles") && !Loader::get()->isModLoaded("thesillydoggo.gradientpages")){ - if(CCNode* node = ret->getChildByID("left-border")) { + if (doFix) { + if (CCNode* node = ret->getChildByID("left-border")) { node->setVisible(false); } - if(CCNode* node = ret->getChildByID("right-border")) { + if (CCNode* node = ret->getChildByID("right-border")) { node->setVisible(false); } - if(CCNode* node = ret->getChildByID("top-border")) { + if (CCNode* node = ret->getChildByID("top-border")) { node->setVisible(false); } - if(CCNode* node = ret->getChildByID("bottom-border")) { + if (CCNode* node = ret->getChildByID("bottom-border")) { node->setVisible(false); } @@ -68,10 +66,10 @@ class $modify(MyGJCommentListLayer, GJCommentListLayer) { outlineSprite->setZOrder(20); outlineSprite->setID("outline"); - if (!p5){ + if (!p5) { outlineSprite->setColor({130, 64, 32}); std::optional dataOpt = UIModding::get()->getColors("comment-list-outline-brown"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); outlineSprite->setColor(data.color); } @@ -79,7 +77,7 @@ class $modify(MyGJCommentListLayer, GJCommentListLayer) { else { outlineSprite->setColor({32, 49, 130}); std::optional dataOpt = UIModding::get()->getColors("comment-list-outline-blue"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); outlineSprite->setColor(data.color); } @@ -87,34 +85,33 @@ class $modify(MyGJCommentListLayer, GJCommentListLayer) { myRet->addChild(outlineSprite); } - #endif return ret; } - #ifndef GEODE_IS_MACOS - void listenForDisable(float dt) { if (getUserObject("dont-correct-borders")){ revert(); } } - void revert() { + void revert(bool showBorders) { unschedule(m_fields->parentSchedule); unschedule(m_fields->posSchedule); - if(CCNode* node = getChildByID("left-border")) { - node->setVisible(true); - } - if(CCNode* node = getChildByID("right-border")) { - node->setVisible(true); - } - if(CCNode* node = getChildByID("top-border")) { - node->setVisible(true); - } - if(CCNode* node = getChildByID("bottom-border")) { - node->setVisible(true); + if (showBorders) { + if (CCNode* node = getChildByID("left-border")) { + node->setVisible(true); + } + if (CCNode* node = getChildByID("right-border")) { + node->setVisible(true); + } + if (CCNode* node = getChildByID("top-border")) { + node->setVisible(true); + } + if (CCNode* node = getChildByID("bottom-border")) { + node->setVisible(true); + } } removeChildByID("outline"); @@ -123,33 +120,54 @@ class $modify(MyGJCommentListLayer, GJCommentListLayer) { unschedule(m_fields->revertSchedule); } - void listenForPosition(float dt){ - if(m_fields->hasBorder && m_fields->lastPos != getPosition()){ - if(CCNode* parent = getParent()){ + void revert() { + revert(true); + } + + void listenForPosition(float dt) { + if (m_fields->hasBorder && m_fields->lastPos != getPosition()) { + if (CCNode* parent = getParent()) { updateBordersWithParent(parent); } m_fields->lastPos = getPosition(); } } - void checkForParent(float dt){ - if(CCNode* parent = getParent()){ + void checkForParent(float dt) { + if (CCNode* parent = getParent()) { updateBordersWithParent(parent); unschedule(m_fields->parentSchedule); } } - void updateBordersWithParent(CCNode* parent){ + void updateBordersWithParent(CCNode* parent) { + + if (CCNode* bg = parent->getChildByID("background")) { + if (getChildOfType(bg, 0)) { + revert(false); + return; + } + } + + if (parent->getChildByID("bitz.customprofiles/normal-gradient")) { + revert(false); + return; + } + + if (parent->getChildByID("thesillydoggo.gradientpages/gradient-container")) { + revert(false); + return; + } - if(CCScale9Sprite* bg = typeinfo_cast(parent->getChildByID("background"))){ + if (CCScale9Sprite* bg = typeinfo_cast(parent->getChildByID("background"))) { createMask(bg); } - else if(CCScale9Sprite* bg = getChildOfType(parent, 0)){ + else if (CCScale9Sprite* bg = getChildOfType(parent, 0)) { createMask(bg); } } - void createMask(CCScale9Sprite* bg){ + void createMask(CCScale9Sprite* bg) { removeChildByID("special-border"); m_fields->hasBorder = true; @@ -189,5 +207,4 @@ class $modify(MyGJCommentListLayer, GJCommentListLayer) { addChild(parentNode); } - #endif }; \ No newline at end of file diff --git a/src/nodes/GJDropDownLayer.h b/src/nodes/GJDropDownLayer.h index 4988a44..26bc3b0 100644 --- a/src/nodes/GJDropDownLayer.h +++ b/src/nodes/GJDropDownLayer.h @@ -5,27 +5,25 @@ using namespace geode::prelude; -#ifndef GEODE_IS_MACOS - -class $modify(MyGJDropDownLayer, GJDropDownLayer){ +class $modify(MyGJDropDownLayer, GJDropDownLayer) { static void onModify(auto& self) { (void) self.setHookPriority("GJDropDownLayer::showLayer", INT_MIN); } - void showLayer(bool p0){ + void showLayer(bool p0) { - if(UIModding::get()->doModify){ + if (UIModding::get()->doModify) { setVisible(true); removeFromParentAndCleanup(false); CCScene* currentScene = CCDirector::get()->getRunningScene(); currentScene->addChild(this); - if(p0){ + if (p0) { m_mainLayer->setPosition(m_endPosition); setOpacity(125); } - else{ + else { CCMoveTo* moveTo = CCMoveTo::create(0.5, m_endPosition); CCEaseInOut* easeInOut = CCEaseInOut::create(moveTo, 2.0); CCSequence* sequence = CCSequence::create(easeInOut, 0); @@ -37,10 +35,8 @@ class $modify(MyGJDropDownLayer, GJDropDownLayer){ } UIModding::get()->doUICheck(this); } - else{ + else { GJDropDownLayer::showLayer(p0); } } -}; - -#endif \ No newline at end of file +}; \ No newline at end of file diff --git a/src/nodes/GJListLayer.h b/src/nodes/GJListLayer.h index 2ea63d3..b3d8495 100644 --- a/src/nodes/GJListLayer.h +++ b/src/nodes/GJListLayer.h @@ -13,10 +13,10 @@ class $modify(MyGJListLayer, GJListLayer) { static GJListLayer* create(BoomListView* p0, char const* p1, cocos2d::ccColor4B p2, float p3, float p4, int p5) { auto ret = GJListLayer::create(p0, p1, p2, p3, p4, p5); - if(UIModding::get()->doModify){ - if(ret->getColor() == ccColor3B{191,114,62}){ + if (UIModding::get()->doModify) { + if (ret->getColor() == ccColor3B{191,114,62}) { std::optional dataOpt = UIModding::get()->getColors("list-layer-bg"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); ret->setColor(data.color); ret->setOpacity(data.alpha); diff --git a/src/nodes/InfoLayer.h b/src/nodes/InfoLayer.h index b86f80c..eb3fa9c 100644 --- a/src/nodes/InfoLayer.h +++ b/src/nodes/InfoLayer.h @@ -5,26 +5,26 @@ using namespace geode::prelude; -class $modify(MyInfoLayer, InfoLayer){ +class $modify(MyInfoLayer, InfoLayer) { static void onModify(auto& self) { (void) self.setHookPriority("InfoLayer::init", INT_MIN); } bool init(GJGameLevel* p0, GJUserScore* p1, GJLevelList* p2){ - if(!InfoLayer::init(p0, p1, p2)) return false; - if(UIModding::get()->doModify){ + if (!InfoLayer::init(p0, p1, p2)) return false; + if (UIModding::get()->doModify) { CCNode* theNode; - for(CCNode* node : CCArrayExt(this->getChildren())){ - if(node->getChildrenCount() > 1){ + for (CCNode* node : CCArrayExt(this->getChildren())) { + if (node->getChildrenCount() > 1) { theNode = node; break; } } - if(CCScale9Sprite* bg = typeinfo_cast(theNode->getChildByID("desc-background"))){ + if (CCScale9Sprite* bg = typeinfo_cast(theNode->getChildByID("desc-background"))) { std::optional dataOpt = UIModding::get()->getColors("info-description-bg"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); bg->setColor(data.color); bg->setOpacity(data.alpha); diff --git a/src/nodes/LevelSearchLayer.h b/src/nodes/LevelSearchLayer.h index 471a8c7..7fcd760 100644 --- a/src/nodes/LevelSearchLayer.h +++ b/src/nodes/LevelSearchLayer.h @@ -5,15 +5,15 @@ using namespace geode::prelude; -class $modify(MyLevelSearchLayer, LevelSearchLayer){ +class $modify(MyLevelSearchLayer, LevelSearchLayer) { static void onModify(auto& self) { (void) self.setHookPriority("LevelSearchLayer::init", INT_MIN); } - bool init(int p0){ - if(!LevelSearchLayer::init(p0)) return false; - if(UIModding::get()->doModify){ + bool init(int p0) { + if (!LevelSearchLayer::init(p0)) return false; + if (UIModding::get()->doModify) { UIModding::get()->updateColors(this, "level-search-bg"); UIModding::get()->updateColors(this, "level-search-bar-bg"); UIModding::get()->updateColors(this, "quick-search-bg"); diff --git a/src/nodes/LoadingLayer.h b/src/nodes/LoadingLayer.h index d735ddd..6c24f91 100644 --- a/src/nodes/LoadingLayer.h +++ b/src/nodes/LoadingLayer.h @@ -5,9 +5,9 @@ using namespace geode::prelude; -class $modify(MyLoadingLayer, LoadingLayer){ +class $modify(MyLoadingLayer, LoadingLayer) { - bool init(bool p0){ + bool init(bool p0) { UIModding::get()->uiCache.clear(); UIModding::get()->colorCache.clear(); return LoadingLayer::init(p0); diff --git a/src/nodes/MenuGameLayer.h b/src/nodes/MenuGameLayer.h index dea7672..8055961 100644 --- a/src/nodes/MenuGameLayer.h +++ b/src/nodes/MenuGameLayer.h @@ -5,17 +5,17 @@ using namespace geode::prelude; -class $modify(MyMenuGameLayer, MenuGameLayer){ +class $modify(MyMenuGameLayer, MenuGameLayer) { static void onModify(auto& self) { (void) self.setHookPriority("MenuGameLayer::update", INT_MIN); } - void updateGroundSprite(CCSprite* spr){ + void updateGroundSprite(CCSprite* spr) { std::optional dataOpt = UIModding::get()->getColors("main-menu-ground"); - if(dataOpt.has_value()){ - for(CCNode* node : CCArrayExt(spr->getChildren())){ - if(CCSprite* child = typeinfo_cast(node)){ + if (dataOpt.has_value()) { + for (CCNode* node : CCArrayExt(spr->getChildren())) { + if (CCSprite* child = typeinfo_cast(node)) { ColorData data = dataOpt.value(); child->setColor(data.color); child->setOpacity(data.alpha); @@ -27,30 +27,30 @@ class $modify(MyMenuGameLayer, MenuGameLayer){ } } - void update(float p0){ + void update(float p0) { MenuGameLayer::update(p0); - if(UIModding::get()->doModify){ + if (UIModding::get()->doModify) { CCSprite* bg = typeinfo_cast(getChildByID("background")); GJGroundLayer* ground = typeinfo_cast(getChildByID("ground")); - if(bg){ + if (bg) { std::optional dataOpt = UIModding::get()->getColors("main-menu-bg"); - if(dataOpt.has_value()){ + if (dataOpt.has_value()) { ColorData data = dataOpt.value(); bg->setColor(data.color); bg->setOpacity(data.alpha); } } - if(ground){ - if(CCSpriteBatchNode* groundSprites = typeinfo_cast(ground->getChildByID("ground-sprites"))){ - if(CCSprite* groundSprite = getChildOfType(groundSprites, 0)) { + if (ground) { + if (CCSpriteBatchNode* groundSprites = typeinfo_cast(ground->getChildByID("ground-sprites"))) { + if (CCSprite* groundSprite = getChildOfType(groundSprites, 0)) { updateGroundSprite(groundSprite); } } - if(CCSpriteBatchNode* groundSprites2 = typeinfo_cast(ground->getChildByID("ground-sprites-2"))){ - if(CCSprite* groundSprite = getChildOfType(groundSprites2, 0)) { + if(CCSpriteBatchNode* groundSprites2 = typeinfo_cast(ground->getChildByID("ground-sprites-2"))) { + if (CCSprite* groundSprite = getChildOfType(groundSprites2, 0)) { updateGroundSprite(groundSprite); } } diff --git a/src/nodes/MenuLayer.h b/src/nodes/MenuLayer.h index 5712429..451821c 100644 --- a/src/nodes/MenuLayer.h +++ b/src/nodes/MenuLayer.h @@ -5,7 +5,7 @@ using namespace geode::prelude; -class $modify(MyMenuLayer, MenuLayer){ +class $modify(MyMenuLayer, MenuLayer) { static void onModify(auto& self) { (void) self.setHookPriority("MenuLayer::init", INT_MIN/2-1); @@ -13,13 +13,13 @@ class $modify(MyMenuLayer, MenuLayer){ bool init(){ - if(!MenuLayer::init()){ + if (!MenuLayer::init()) { return false; } UIModding::get()->doModify = Mod::get()->getSettingValue("ui-modifications"); - if(UIModding::get()->doModify){ - if(Mod::get()->getSettingValue("hot-reload")){ + if (UIModding::get()->doModify) { + if (Mod::get()->getSettingValue("hot-reload")) { UIModding::get()->startFileListeners(); } UIModding::get()->doUICheck(this);