Skip to content

Commit

Permalink
Formatting fixes, Bug Fixes
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Alphalaneous committed Oct 3, 2024
1 parent e50d2bc commit b6fb87e
Show file tree
Hide file tree
Showing 26 changed files with 694 additions and 746 deletions.
54 changes: 54 additions & 0 deletions src/BackgroundColors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once

#include <Geode/Geode.hpp>
#include <Geode/modify/CCDirector.hpp>
#include <Geode/modify/LeaderboardsLayer.hpp>
#include <Geode/modify/LevelBrowserLayer.hpp>
#include "UIModding.h"

using namespace geode::prelude;

void setBackground(CCNode* node) {
if (UIModding::get()->doModify) {
if (CCSprite* bg = typeinfo_cast<CCSprite*>(node->getChildByIDRecursive("background"))) {
if (bg->getColor() == ccColor3B{0, 102, 255}) {
std::optional<ColorData> 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;
}
};
34 changes: 0 additions & 34 deletions src/CCDirector.h

This file was deleted.

28 changes: 12 additions & 16 deletions src/FileWatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,43 @@ class FileWatcher {

FileWatcher(std::string pathToWatch, std::chrono::duration<int, std::milli> 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<void (std::string, FileStatus)> &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()) {
if (!std::filesystem::exists(it->first)) {
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);
}
}
}
}
Expand Down
43 changes: 22 additions & 21 deletions src/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeName>(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 { \
Expand All @@ -44,7 +44,7 @@ if(type == #typeName){\
}

#define actionForName(name, params) if(type == #name){ \
if(!isNumber){ \
if (!isNumber) { \
actionToDo = CC##name::create params; \
} \
}
Expand All @@ -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;\
Expand All @@ -74,33 +74,33 @@ 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;\
}\
};

#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);\
Expand All @@ -117,24 +117,25 @@ struct My##class : geode::Modify<My##class, class> { \
};\
void method(paramType* p0){\
class::method(p0);\
checkBG(0);\
this->schedule(schedule_selector(My##class::checkBG));\
}\
void checkBG(float dt) {\
CCLayerColor* child = getChildOfType<CCLayerColor>(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<ColorData> 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<ColorData> 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);\
Expand Down
Loading

0 comments on commit b6fb87e

Please sign in to comment.