Skip to content

Commit d68318b

Browse files
committed
Added SelectButtonManager.cpp
Moved definitions there. also how long have i forgot to import the modify for CCMenuItemSpriteExtra and why did this ever compile.
1 parent 64d5e97 commit d68318b

File tree

3 files changed

+147
-109
lines changed

3 files changed

+147
-109
lines changed

src/ButtonActionManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ButtonActionManager : CCObject {
5959

6060
};
6161

62-
62+
#include <Geode/modify/CCMenuItemSpriteExtra.hpp>
6363
class $modify(DifferentThing, CCMenuItemSpriteExtra){
6464
static void onModify(auto& self) {
6565
if (!self.setHookPriorityPre("CCMenuItemSpriteExtra::selected", Priority::First)) {

src/SelectButtonManager.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include <Geode/Geode.hpp>
2+
#include "SelectButtonManager.hpp"
3+
4+
5+
using namespace geode::prelude;
6+
7+
SelectButtonManager* SelectButtonManager::get(){
8+
static SelectButtonManager* instance = nullptr;
9+
if(!instance){
10+
instance = new SelectButtonManager;
11+
}
12+
CCScheduler::get()->scheduleUpdateForTarget(instance, 0, false);
13+
return instance;
14+
}
15+
16+
void SelectButtonManager::setButtons(){
17+
18+
ButtonActions actions;
19+
actions.selected = MenuCallback([this](CCMenuItem* sender){
20+
/*if("change-button-state"_spr == sender->getID()){
21+
sender->selected();
22+
return;
23+
}*/
24+
if(s_popUp && !sender->hasAncestor(s_popUp.data())){
25+
return;
26+
}
27+
28+
m_currBtn = sender;
29+
CCScheduler::get()->scheduleSelector(schedule_selector(SelectButtonManager::over), this, 0, 0, 0.5, false);
30+
sender->selected();
31+
});
32+
actions.unselected = MenuCallback([this](CCMenuItem* sender){
33+
34+
/*if("change-button-state"_spr == sender->getID()){
35+
sender->unselected();
36+
return;
37+
}*/
38+
39+
m_currBtn = nullptr;
40+
CCScheduler::get()->unscheduleSelector(schedule_selector(SelectButtonManager::over), this);
41+
//ButtonActionManager::get()->resetActivate();
42+
sender->unselected();
43+
});
44+
45+
actions.activate = MenuCallback([this](CCMenuItem* sender){
46+
if(s_popUp && !sender->hasAncestor(s_popUp)){
47+
return;
48+
}
49+
s_popUp = nullptr;
50+
sender->activate();
51+
});
52+
ButtonActionManager::get()->setActions(actions);
53+
}
54+
55+
void SelectButtonManager::toggleManager(CCObject*){
56+
static bool state = true;
57+
if(state){
58+
state = false;
59+
//log::debug("haiufhsi");
60+
setButtons();
61+
return;
62+
}
63+
ButtonActionManager::get()->resetSelected();
64+
state = true;
65+
}
66+
67+
CCNode* SelectButtonManager::getTopLayer(CCNode* curr){
68+
while(curr && !typeinfo_cast<CCScene*>(curr->getParent())){ // while parent exists and parent is not CCScene*
69+
curr = curr->getParent();
70+
}
71+
return curr;
72+
}
73+
74+
Result<std::vector<std::string>> SelectButtonManager::getPath(CCNode* curr){
75+
if(curr->getID() == ""){
76+
return Err("The button you tried to select does not have an ID.");
77+
}
78+
79+
std::vector<std::string> path;
80+
path.push_back(curr->getID());
81+
while(curr && !typeinfo_cast<CCScene*>(curr->getParent())){ // while parent exists and parent is not CCScene*
82+
curr = curr->getParent();
83+
if(curr->getID() == ""){
84+
return Err("One of the nodes in the path does not have an ID.");
85+
}
86+
path.push_back(curr->getID());
87+
}
88+
return Ok(path);
89+
}
90+
91+
92+
93+
// int getNumID(CCNode* node) {
94+
// auto parent = node->getParent();
95+
// auto siblings = parent->getChildren();
96+
// return siblings->indexOfObject(node);
97+
// }
98+
99+
// std::vector<NodeID> getPathNum(CCNode* curr){
100+
// std::vector<NodeID> path;
101+
// //struct NodeID test = {curr->getID(),getNumID(curr)};
102+
// path.push_back({curr->getID(),getNumID(curr)});
103+
// while(curr && !typeinfo_cast<CCScene*>(curr->getParent())){ // while parent exists and parent is not CCScene*
104+
// curr = curr->getParent();
105+
// path.push_back({curr->getID(),getNumID(curr)});
106+
// }
107+
// return path;
108+
// }
109+
110+
void SelectButtonManager::over(float df){
111+
112+
//because evil
113+
auto evil = SelectButtonManager::get();
114+
if(evil->m_currBtn){
115+
116+
//log::debug("{}", evil->m_currBtn->getID());
117+
auto top = getTopLayer(evil->m_currBtn);
118+
std::string topName = "";
119+
if(top){
120+
topName = top->getID();
121+
}
122+
auto path = getPath(evil->m_currBtn);
123+
auto pathNum = NodePath::create(evil->m_currBtn);
124+
125+
s_popUp = FLAlertLayer::create("Selector", fmt::format("{} selected", pathNum.to_string()), "OK");
126+
127+
s_popUp->setID("SelectAlert"_spr);
128+
s_popUp->show();
129+
130+
/*if(path.isErr()){
131+
FLAlertLayer::create("Selector", fmt::format("{}", path.err().value()), "OK")->show();
132+
} else {
133+
FLAlertLayer::create("Selector", fmt::format("{} selected", path.ok().value()), "OK")->show();
134+
}*/
135+
136+
SelectButtonManager::get()->m_currBtn->unselected();
137+
}
138+
}

src/SelectButtonManager.hpp

Lines changed: 8 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,23 @@
11
#pragma once
22
#include <Geode/Geode.hpp>
33
#include "NodePath.hpp"
4+
#include "ButtonActionManager.hpp"
45

56
using namespace geode::prelude;
7+
68
class SelectButtonManager : public CCObject {
79
Ref<CCMenuItem> m_currBtn = nullptr;
810
Ref<FLAlertLayer> s_popUp = nullptr;
911
public:
10-
static SelectButtonManager* get(){
11-
static SelectButtonManager* instance = nullptr;
12-
if(!instance){
13-
instance = new SelectButtonManager;
14-
}
15-
CCScheduler::get()->scheduleUpdateForTarget(instance, 0, false);
16-
return instance;
17-
}
18-
19-
void setButtons(){
20-
21-
ButtonActions actions;
22-
actions.selected = MenuCallback([this](CCMenuItem* sender){
23-
/*if("change-button-state"_spr == sender->getID()){
24-
sender->selected();
25-
return;
26-
}*/
27-
if(s_popUp && !sender->hasAncestor(s_popUp.data())){
28-
return;
29-
}
30-
31-
m_currBtn = sender;
32-
CCScheduler::get()->scheduleSelector(schedule_selector(SelectButtonManager::over), this, 0, 0, 0.5, false);
33-
sender->selected();
34-
});
35-
actions.unselected = MenuCallback([this](CCMenuItem* sender){
36-
37-
/*if("change-button-state"_spr == sender->getID()){
38-
sender->unselected();
39-
return;
40-
}*/
41-
42-
m_currBtn = nullptr;
43-
CCScheduler::get()->unscheduleSelector(schedule_selector(SelectButtonManager::over), this);
44-
//ButtonActionManager::get()->resetActivate();
45-
sender->unselected();
46-
});
12+
static SelectButtonManager* get();
4713

48-
actions.activate = MenuCallback([this](CCMenuItem* sender){
49-
if(s_popUp && !sender->hasAncestor(s_popUp)){
50-
return;
51-
}
52-
s_popUp = nullptr;
53-
sender->activate();
54-
});
55-
ButtonActionManager::get()->setActions(actions);
56-
}
14+
void setButtons();
5715

58-
void toggleManager(CCObject*){
59-
static bool state = true;
60-
if(state){
61-
state = false;
62-
//log::debug("haiufhsi");
63-
setButtons();
64-
return;
65-
}
66-
ButtonActionManager::get()->resetSelected();
67-
state = true;
68-
}
16+
void toggleManager(CCObject*);
6917

70-
CCNode* getTopLayer(CCNode* curr){
71-
while(curr && !typeinfo_cast<CCScene*>(curr->getParent())){ // while parent exists and parent is not CCScene*
72-
curr = curr->getParent();
73-
}
74-
return curr;
75-
}
18+
CCNode* getTopLayer(CCNode* curr);
7619

77-
Result<std::vector<std::string>> getPath(CCNode* curr){
78-
if(curr->getID() == ""){
79-
return Err("The button you tried to select does not have an ID.");
80-
}
81-
82-
std::vector<std::string> path;
83-
path.push_back(curr->getID());
84-
while(curr && !typeinfo_cast<CCScene*>(curr->getParent())){ // while parent exists and parent is not CCScene*
85-
curr = curr->getParent();
86-
if(curr->getID() == ""){
87-
return Err("One of the nodes in the path does not have an ID.");
88-
}
89-
path.push_back(curr->getID());
90-
}
91-
return Ok(path);
92-
}
20+
Result<std::vector<std::string>> getPath(CCNode* curr);
9321

9422

9523

@@ -110,33 +38,5 @@ class SelectButtonManager : public CCObject {
11038
// return path;
11139
// }
11240

113-
void over(float df){
114-
115-
//because evil
116-
auto evil = SelectButtonManager::get();
117-
if(evil->m_currBtn){
118-
119-
//log::debug("{}", evil->m_currBtn->getID());
120-
auto top = getTopLayer(evil->m_currBtn);
121-
std::string topName = "";
122-
if(top){
123-
topName = top->getID();
124-
}
125-
auto path = getPath(evil->m_currBtn);
126-
auto pathNum = NodePath::create(evil->m_currBtn);
127-
128-
s_popUp = FLAlertLayer::create("Selector", fmt::format("{} selected", pathNum.to_string()), "OK");
129-
130-
s_popUp->setID("SelectAlert"_spr);
131-
s_popUp->show();
132-
133-
/*if(path.isErr()){
134-
FLAlertLayer::create("Selector", fmt::format("{}", path.err().value()), "OK")->show();
135-
} else {
136-
FLAlertLayer::create("Selector", fmt::format("{} selected", path.ok().value()), "OK")->show();
137-
}*/
138-
139-
SelectButtonManager::get()->m_currBtn->unselected();
140-
}
141-
}
41+
void over(float df);
14242
};

0 commit comments

Comments
 (0)