Skip to content

Commit 6e56bc5

Browse files
committed
Pause menu!!
1 parent a835aea commit 6e56bc5

File tree

8 files changed

+254
-8
lines changed

8 files changed

+254
-8
lines changed

assets/textures/accessibility.png

178 Bytes
Loading

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"gd": {
44
"win": "2.206"
55
},
6-
"version": "v0.7.2",
6+
"version": "v0.8.0",
77
"id": "zalphalaneous.minecraft",
88
"name": "Minecraftify!",
99
"developer": "Alphalaneous",

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "ui/hooks/CCMenuItemSpriteExtra.h"
77
#include "ui/hooks/CCMenuItemToggler.h"
88
#include "ui/hooks/FLAlertLayer.h"
9+
#include "ui/hooks/PauseLayer.h"
910

1011
$execute{
1112
setlocale( LC_ALL, "en_US.utf8" );

src/ui/hooks/FLAlertLayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class $modify(MyFLAlertLayer, FLAlertLayer){
195195
stopAllActions();
196196
mainLayer->stopAllActions();
197197
mainLayer->setScale(1);
198-
setColor({20, 20, 20});
198+
setColor({15, 15, 15});
199199
setOpacity(200);
200200
}
201201
}

src/ui/hooks/PauseLayer.h

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
#include <Geode/Geode.hpp>
2+
#include <Geode/modify/CCDirector.hpp>
3+
#include <Geode/modify/PauseLayer.hpp>
4+
5+
class $modify(MyPauseLayer, PauseLayer){
6+
7+
void customSetup(){
8+
PauseLayer::customSetup();
9+
10+
if(!Loader::get()->isModLoaded("geode.node-ids")) return;
11+
12+
if(CCNode* node = getChildByID("background")) {
13+
node->setVisible(false);
14+
}
15+
if(CCNode* node = getChildByID("music-slider")) {
16+
node->setVisible(false);
17+
}
18+
if(CCNode* node = getChildByID("sfx-slider")) {
19+
node->setVisible(false);
20+
}
21+
if(CCNode* node = getChildByID("music-label")) {
22+
node->setVisible(false);
23+
}
24+
if(CCNode* node = getChildByID("sfx-label")) {
25+
node->setVisible(false);
26+
}
27+
if(CCNode* node = getChildByID("left-button-menu")) {
28+
node->setVisible(false);
29+
}
30+
if(CCNode* node = getChildByID("right-button-menu")) {
31+
node->setVisible(false);
32+
}
33+
if(CCNode* node = getChildByID("bottom-button-menu")) {
34+
node->setVisible(false);
35+
}
36+
if(CCNode* node = getChildByID("normal-progress-label")) {
37+
node->setVisible(false);
38+
}
39+
if(CCNode* node = getChildByID("normal-progress-bar")) {
40+
node->setVisible(false);
41+
}
42+
if(CCNode* node = getChildByID("normal-mode-label")) {
43+
node->setVisible(false);
44+
}
45+
if(CCNode* node = getChildByID("practice-progress-label")) {
46+
node->setVisible(false);
47+
}
48+
if(CCNode* node = getChildByID("practice-progress-bar")) {
49+
node->setVisible(false);
50+
}
51+
if(CCNode* node = getChildByID("practice-mode-label")) {
52+
node->setVisible(false);
53+
}
54+
55+
PlayLayer* playLayer = PlayLayer::get();
56+
57+
if(CCLabelBMFont* title = typeinfo_cast<CCLabelBMFont*>(getChildByID("level-name"))) {
58+
title->setFntFile("minecraft.fnt"_spr);
59+
title->setScale(0.45f);
60+
title->setPosition({title->getPosition().x, title->getPosition().y - 10});
61+
62+
if(CCLabelBMFont* time = typeinfo_cast<CCLabelBMFont*>(getChildByID("play-time"))) {
63+
time->setFntFile("minecraft.fnt"_spr);
64+
time->setScale(0.45f);
65+
time->setPosition({title->getPosition().x, title->getPosition().y - 15});
66+
}
67+
68+
if(getChildByID("normal-progress-bar")){
69+
70+
CCLabelBMFont* normalProgress = typeinfo_cast<CCLabelBMFont*>(getChildByID("normal-progress-label"));
71+
CCLabelBMFont* practiceProgress = typeinfo_cast<CCLabelBMFont*>(getChildByID("practice-progress-label"));
72+
73+
if(normalProgress && practiceProgress){
74+
std::wstring bestText = L"";
75+
bestText.append(L"Best: \u00A7a");
76+
bestText.append(Utils::strToWstr(normalProgress->getString()));
77+
bestText.append(L" \u00A7f| \u00A7b");
78+
bestText.append(Utils::strToWstr(practiceProgress->getString()));
79+
80+
MCLabel* label = MCLabel::create(bestText, "minecraft.fnt"_spr);
81+
label->setScale(0.45f);
82+
label->setPosition({title->getPosition().x, title->getPosition().y - 15});
83+
addChild(label);
84+
}
85+
}
86+
}
87+
88+
setColor({15, 15, 15});
89+
setOpacity(200);
90+
91+
CCSize winSize = CCDirector::get()->getWinSize();
92+
93+
RowLayout* rowLayout = RowLayout::create();
94+
rowLayout->ignoreInvisibleChildren(true);
95+
rowLayout->setGrowCrossAxis(true);
96+
97+
CCNode* innerButtonMenu = CCNode::create();
98+
99+
innerButtonMenu->setContentSize({200, 200});
100+
innerButtonMenu->setLayout(rowLayout);
101+
innerButtonMenu->setAnchorPoint({0.5, 0.5});
102+
innerButtonMenu->setZOrder(1);
103+
innerButtonMenu->setID("button-menu"_spr);
104+
innerButtonMenu->setPosition({winSize.width/2, winSize.height-140});
105+
106+
CCNode* bottomLeftMenu = CCNode::create();
107+
bottomLeftMenu->setContentSize({20, 20});
108+
bottomLeftMenu->setLayout(rowLayout);
109+
bottomLeftMenu->setAnchorPoint({0.5, 0.5});
110+
bottomLeftMenu->setZOrder(1);
111+
bottomLeftMenu->setID("bottom-left-menu"_spr);
112+
bottomLeftMenu->setPosition({30, 30});
113+
114+
if(MyCCMenuItemSpriteExtra* button = static_cast<MyCCMenuItemSpriteExtra*>(getChildByIDRecursive("play-button"))) {
115+
116+
MCButton* btn2 = MCButton::create("Back to Game", 50.0f, button->m_fields->m_buttonTarget, button->m_fields->m_buttonCallback);
117+
btn2->setID(button->getID());
118+
button->setVisible(false);
119+
innerButtonMenu->addChild(btn2);
120+
121+
}
122+
123+
124+
if(MyCCMenuItemSpriteExtra* button = static_cast<MyCCMenuItemSpriteExtra*>(getChildByIDRecursive("practice-button"))) {
125+
126+
std::string practiceText = "Practice";
127+
128+
if (playLayer->m_isPracticeMode){
129+
practiceText = "Exit Practice";
130+
}
131+
132+
133+
MCButton* btn2 = MCButton::create(practiceText.c_str(), 24.3f, button->m_fields->m_buttonTarget, button->m_fields->m_buttonCallback);
134+
btn2->setID(button->getID());
135+
button->setVisible(false);
136+
innerButtonMenu->addChild(btn2);
137+
138+
}
139+
140+
MCButton* statsButton = MCButton::create("Statistics", 24.3f, this, menu_selector(MyPauseLayer::onStatistics));
141+
innerButtonMenu->addChild(statsButton);
142+
143+
MCButton* optionButton = MCButton::create("Options...", 24.3f, this, menu_selector(MyPauseLayer::onMCOptions));
144+
innerButtonMenu->addChild(optionButton);
145+
146+
if(MyCCMenuItemSpriteExtra* button = static_cast<MyCCMenuItemSpriteExtra*>(getChildByIDRecursive("options-button"))) {
147+
148+
MCButton* btn2 = MCButton::create("", 5.0f, button->m_fields->m_buttonTarget, button->m_fields->m_buttonCallback);
149+
CCSprite* spr = Utils::createPixelSprite("accessibility.png"_spr);
150+
btn2->setID(button->getID());
151+
spr->setPosition({btn2->getContentSize().width/2, btn2->getContentSize().height/2});
152+
btn2->addSprite(spr);
153+
button->setVisible(false);
154+
155+
bottomLeftMenu->addChild(btn2);
156+
}
157+
158+
if(MyCCMenuItemSpriteExtra* button = static_cast<MyCCMenuItemSpriteExtra*>(getChildByIDRecursive("retry-button"))) {
159+
160+
MCButton* btn2 = MCButton::create("Retry", 24.3f, button->m_fields->m_buttonTarget, button->m_fields->m_buttonCallback);
161+
btn2->setID(button->getID());
162+
button->setVisible(false);
163+
innerButtonMenu->addChild(btn2);
164+
}
165+
166+
float buttonSize = 50.0f;
167+
168+
if(MyCCMenuItemSpriteExtra* button = static_cast<MyCCMenuItemSpriteExtra*>(getChildByIDRecursive("edit-button"))) {
169+
170+
if(getChildByIDRecursive("full-restart-button")){
171+
buttonSize = 24.3f;
172+
}
173+
174+
MCButton* btn2 = MCButton::create("Edit Level", buttonSize, button->m_fields->m_buttonTarget, button->m_fields->m_buttonCallback);
175+
btn2->setID(button->getID());
176+
button->setVisible(false);
177+
innerButtonMenu->addChild(btn2);
178+
}
179+
180+
if(MyCCMenuItemSpriteExtra* button = static_cast<MyCCMenuItemSpriteExtra*>(getChildByIDRecursive("full-restart-button"))) {
181+
182+
MCButton* btn2 = MCButton::create("Restart Level", buttonSize, button->m_fields->m_buttonTarget, button->m_fields->m_buttonCallback);
183+
btn2->setID(button->getID());
184+
button->setVisible(false);
185+
innerButtonMenu->addChild(btn2);
186+
}
187+
188+
if(MyCCMenuItemSpriteExtra* button = static_cast<MyCCMenuItemSpriteExtra*>(getChildByIDRecursive("exit-button"))) {
189+
190+
MCButton* btn2 = MCButton::create("Quit to Title", 50.0f, button->m_fields->m_buttonTarget, button->m_fields->m_buttonCallback);
191+
btn2->setID(button->getID());
192+
button->setVisible(false);
193+
innerButtonMenu->addChild(btn2);
194+
195+
}
196+
197+
innerButtonMenu->updateLayout();
198+
bottomLeftMenu->updateLayout();
199+
200+
addChild(innerButtonMenu);
201+
addChild(bottomLeftMenu);
202+
}
203+
204+
void onMCOptions(CCObject* obj){
205+
OptionsLayer* optionsLayer = OptionsLayer::create();
206+
optionsLayer->setZOrder(20);
207+
optionsLayer->showLayer(false);
208+
}
209+
210+
void onStatistics(CCObject* obj){
211+
212+
PlayLayer* playLayer = PlayLayer::get();
213+
214+
LevelInfoLayer* lil = LevelInfoLayer::create(playLayer->m_level, false);
215+
lil->onLevelInfo(nullptr);
216+
}
217+
};

src/ui/nodes/MCButtonChild.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,24 @@ void MCButtonChild::onHoverExit(){
134134

135135
void MCButtonChild::selected(){
136136
if(this->isHovering){
137-
FMODAudioEngine::sharedEngine()->playEffect("click.ogg"_spr);
137+
138+
auto engine = FMODAudioEngine::sharedEngine();
139+
auto system = engine->m_system;
140+
141+
FMOD::Channel* channel;
142+
FMOD::Sound* sound;
143+
144+
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename("click.ogg"_spr, false);;
145+
if(engine->m_sfxVolume > 0) {
146+
system->createSound(fullPath.c_str(), FMOD_DEFAULT, nullptr, &sound);
147+
system->playSound(sound, nullptr, false, &channel);
148+
channel->setVolume(engine->m_sfxVolume);
149+
}
150+
138151
geode::Loader::get()->queueInMainThread([this]() { //delay it by a frame because for some reason it crashes the touch dispatcher otherwise ???
139-
(m_pListener->*m_pfnSelector)(this);
152+
if(m_pListener && m_pfnSelector){
153+
(m_pListener->*m_pfnSelector)(this);
154+
}
140155
});
141156
}
142157
}

src/ui/nodes/MCLabel.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "MCLabel.h"
22
#include "../../utils/Utils.h"
33
#include <cstdlib>
4+
#include <iostream>
45

56
struct ColorPos {
67
unsigned int pos;
@@ -51,16 +52,17 @@ bool MCLabel::init(std::wstring text, std::string font){
5152

5253
for(unsigned int i = 0; i < text.size(); i++) {
5354

54-
if(text.at(i) == L'§'){
55+
if(text.at(i) == L'\u00A7'){
5556

5657
if(i+1 <= text.size() && isValidChar(text.at(i+1))){
57-
ColorPos p = {i - offset - 1, text.at(i+1)};
58+
ColorPos p = {i - offset, text.at(i+1)};
5859

5960
colorPositions.push_back(p);
6061

61-
finalString = finalString.erase(i - offset - 1, 3);
6262

63-
offset += 3;
63+
finalString = finalString.erase(i - offset, 2);
64+
65+
offset += 2;
6466
}
6567
}
6668
}

src/utils/Utils.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ class Utils {
297297
return newToggler;
298298
}
299299

300+
static std::wstring strToWstr(std::string string){
301+
302+
const char* str = string.c_str();
303+
std::wstring wStr = L"";
304+
for(const char* it = str; *it; ++it) {
305+
wStr.push_back(std::btowc(*it));
306+
}
307+
308+
return wStr;
309+
}
310+
300311
static void trim(std::string& str) {
301312
str.erase(str.find_last_not_of(' ')+1);
302313
str.erase(0, str.find_first_not_of(' '));

0 commit comments

Comments
 (0)