Skip to content

Commit 2adafc9

Browse files
authored
Themes (#2009)
* initial impl * revert old setting * readd sapphire resources
1 parent 2d28489 commit 2adafc9

14 files changed

Lines changed: 230 additions & 70 deletions

loader/include/Geode/utils/ColorProvider.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ namespace geode {
104104
*/
105105
cocos2d::ccColor3B color3b(std::string_view id) const;
106106
};
107+
108+
class ThemeIDProvidingEvent final : public Event<ThemeIDProvidingEvent, bool(std::string& idOut)> {
109+
public:
110+
// listener params idOut
111+
using Event::Event;
112+
};
113+
114+
/**
115+
* An event that gets posted for someone to request a node for a specific ID. This is
116+
* used in Geode themes to provide custom nodes.
117+
*/
118+
class NodeProvidingEvent final : public GlobalEvent<NodeProvidingEvent, bool(std::string_view id, cocos2d::CCNode*& nodeOut, std::string_view theme), bool(cocos2d::CCNode*& nodeOut, std::string_view theme), std::string> {
119+
public:
120+
// listener params node
121+
// filter params id
122+
using GlobalEvent::GlobalEvent;
123+
124+
bool send(cocos2d::CCNode*& nodeOut);
125+
};
107126
}
108127

109128
inline cocos2d::ccColor4B operator""_cc4b_gd(const char* str, size_t) {
47.9 KB
Loading
10.8 KB
Loading
54.6 KB
Loading

loader/resources/mod.json.in

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,17 @@
9292
"name": "Disable Crash Popup",
9393
"description": "Disables the popup at startup asking if you'd like to send a bug report; intended for developers"
9494
},
95-
"enable-geode-theme": {
96-
"type": "bool",
97-
"default": true,
98-
"name": "Enable Geode-Themed Colors",
99-
"description": "When enabled, the Geode menu has a <ca>Geode-themed color scheme</c>. <cy>This does not affect any other menus!</c>"
95+
"used-theme": {
96+
"type": "string",
97+
"name": "Used Theme",
98+
"description": "The theme used for Geode menu. <cy>This does not affect any other menus!</c>",
99+
"default": "Geode",
100+
"one-of": [
101+
"Geode",
102+
"Geometry Dash",
103+
"Rainbow",
104+
"Sapphire"
105+
]
100106
},
101107
"infinite-local-mods-list": {
102108
"type": "bool",
9.09 KB
Loading
662 Bytes
Loading
13.7 KB
Loading

loader/src/hooks/MenuLayer.cpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <loader/updater.hpp>
1616
#include <Geode/binding/ButtonSprite.hpp>
1717
#include <Geode/modify/LevelSelectLayer.hpp>
18+
#include <Geode/utils/ColorProvider.hpp>
1819

1920
using namespace geode::prelude;
2021

@@ -36,7 +37,7 @@ struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
3637

3738
struct Fields {
3839
bool m_menuDisabled = false;
39-
CCSprite* m_geodeButton = nullptr;
40+
CCNode* m_geodeButton = nullptr;
4041
async::TaskHolder<Result<InstalledModsUpdateCheck, server::ServerError>> m_updateCheckTask;
4142
};
4243

@@ -53,16 +54,45 @@ struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
5354

5455
// add geode button
5556
if (!m_fields->m_menuDisabled) {
56-
m_fields->m_geodeButton = CircleButtonSprite::createWithSpriteFrameName(
57-
"geode-logo-outline-gold.png"_spr,
58-
.95f,
59-
CircleBaseColor::Green,
60-
CircleBaseSize::MediumAlt
61-
);
57+
auto listener = NodeProvidingEvent("geode-button-sprite"_spr).listen([this](cocos2d::CCNode*& nodeOut, std::string_view theme) -> void {
58+
if (nodeOut) return; // someone overrode it already
59+
CCSprite* geodeButton;
60+
if (theme == "sapphire") {
61+
geodeButton = CircleButtonSprite::createWithSpriteFrameName(
62+
"sapphire-logo-outline-gold.png"_spr,
63+
.95f,
64+
CircleBaseColor::Green,
65+
CircleBaseSize::MediumAlt
66+
);
67+
}
68+
else {
69+
geodeButton = CircleButtonSprite::createWithSpriteFrameName(
70+
"geode-logo-outline-gold.png"_spr,
71+
.95f,
72+
CircleBaseColor::Green,
73+
CircleBaseSize::MediumAlt
74+
);
75+
}
76+
77+
if (!geodeButton || geodeButton->isUsingFallback()) {
78+
nodeOut = nullptr;
79+
}
80+
else {
81+
nodeOut = geodeButton;
82+
}
83+
}, Priority::Last);
84+
85+
cocos2d::CCNode* geodeBtn = nullptr;
86+
NodeProvidingEvent("geode-button-sprite"_spr).send(geodeBtn);
87+
6288
auto geodeBtnSelector = &CustomMenuLayer::onGeode;
63-
if (!m_fields->m_geodeButton || m_fields->m_geodeButton->isUsingFallback()) {
64-
geodeBtnSelector = &CustomMenuLayer::onMissingTextures;
89+
if (geodeBtn) {
90+
m_fields->m_geodeButton = static_cast<CCSprite*>(geodeBtn);
91+
}
92+
else {
93+
log::warn("No node provided for geode-button-sprite, using fallback instead");
6594
m_fields->m_geodeButton = ButtonSprite::create("!!");
95+
geodeBtnSelector = &CustomMenuLayer::onMissingTextures;
6696
}
6797

6898
auto bottomMenu = static_cast<CCMenu*>(this->getChildByID("bottom-menu"));

loader/src/ui/GeodeUI.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <Geode/ui/MDPopup.hpp>
66
#include <Geode/ui/LoadingSpinner.hpp>
77
#include <Geode/ui/LazySprite.hpp>
8+
#include <Geode/utils/ColorProvider.hpp>
89
#include <Geode/utils/web.hpp>
910
#include <server/Server.hpp>
1011
#include "mods/GeodeStyle.hpp"
@@ -264,10 +265,26 @@ class ModLogoSprite : public CCNodeRGBA {
264265
if (!mod->isInternal()) {
265266
m_sprite->loadFromFile(dirs::getModRuntimeDir() / mod->getID() / "logo.png");
266267
} else {
267-
if (Mod::get()->getSavedValue("alternate-geode-style", false)) {
268-
m_sprite->initWithSpriteFrameName("geode-logo-alternate.png"_spr);
269-
}
270-
else {
268+
// We only support lazySprite for this because i have no idea how to better integrate this
269+
auto listener = NodeProvidingEvent("geode-mod-logo-sprite"_spr).listen([this](cocos2d::CCNode*& nodeOut, std::string_view theme) -> void {
270+
auto sprite = typeinfo_cast<LazySprite*>(nodeOut);
271+
if (!sprite) return; // someone overrode it, which will probably break maybe
272+
273+
if (theme == "rainbow") {
274+
m_sprite->initWithSpriteFrameName("geode-logo-alternate.png"_spr);
275+
}
276+
else if (theme == "sapphire") {
277+
m_sprite->initWithSpriteFrameName("sapphire-logo.png"_spr);
278+
}
279+
else {
280+
m_sprite->initWithSpriteFrameName("geode-logo.png"_spr);
281+
}
282+
}, Priority::Last);
283+
CCNode* ptr = m_sprite;
284+
NodeProvidingEvent("geode-mod-logo-sprite"_spr).send(ptr);
285+
286+
// fallback
287+
if (ptr != m_sprite) {
271288
m_sprite->initWithSpriteFrameName("geode-logo.png"_spr);
272289
}
273290
}

0 commit comments

Comments
 (0)