Skip to content

Commit a1754a5

Browse files
committed
Add some helper methods
1 parent bbf2b1c commit a1754a5

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

loader/include/Geode/cocos/base_nodes/CCNode.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <Geode/utils/casts.hpp>
4242
#include <Geode/utils/function.hpp>
4343
#include <Geode/utils/ZStringView.hpp>
44+
#include <Geode/ui/NodeEvent.hpp>
4445

4546
namespace geode {
4647
class Layout;
@@ -1152,6 +1153,46 @@ class CC_DLL CCNode : public CCObject
11521153
GEODE_DLL geode::comm::ListenerHandle* getEventListener(std::string_view id);
11531154
GEODE_DLL size_t getEventListenerCount();
11541155

1156+
template <class Callback>
1157+
geode::comm::ListenerHandle* addOnEnterCallback(
1158+
Callback&& callback,
1159+
int priority = 0
1160+
) {
1161+
return this->addEventListener("", geode::NodeEvent(this, geode::NodeEventType::OnEnter), std::forward<Callback>(callback), priority);
1162+
}
1163+
1164+
template <class Callback>
1165+
geode::comm::ListenerHandle* addOnEnterTransitionDidFinishCallback(
1166+
Callback&& callback,
1167+
int priority = 0
1168+
) {
1169+
return this->addEventListener("", geode::NodeEvent(this, geode::NodeEventType::OnEnterTransitionDidFinish), std::forward<Callback>(callback), priority);
1170+
}
1171+
1172+
template <class Callback>
1173+
geode::comm::ListenerHandle* addOnExitCallback(
1174+
Callback&& callback,
1175+
int priority = 0
1176+
) {
1177+
return this->addEventListener("", geode::NodeEvent(this, geode::NodeEventType::OnExit), std::forward<Callback>(callback), priority);
1178+
}
1179+
1180+
template <class Callback>
1181+
geode::comm::ListenerHandle* addOnExitTransitionDidStartCallback(
1182+
Callback&& callback,
1183+
int priority = 0
1184+
) {
1185+
return this->addEventListener("", geode::NodeEvent(this, geode::NodeEventType::OnExitTransitionDidStart), std::forward<Callback>(callback), priority);
1186+
}
1187+
1188+
template <class Callback>
1189+
geode::comm::ListenerHandle* addCleanupCallback(
1190+
Callback&& callback,
1191+
int priority = 0
1192+
) {
1193+
return this->addEventListener("", geode::NodeEvent(this, geode::NodeEventType::OnCleanup), std::forward<Callback>(callback), priority);
1194+
}
1195+
11551196
/**
11561197
* Get child at index. Checks bounds. A negative
11571198
* index will get the child starting from the end

loader/include/Geode/cocos/menu_nodes/CCMenuItem.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ THE SOFTWARE.
3030
#include "../base_nodes/CCNode.h"
3131
#include "../include/CCProtocols.h"
3232
#include "../cocoa/CCArray.h"
33+
#include <Geode/ui/NodeEvent.hpp>
3334

3435
NS_CC_BEGIN
3536

@@ -112,6 +113,14 @@ class CC_DLL CCMenuItem : public CCNodeRGBA
112113
/** set the target/selector of the menu item*/
113114
void setTarget(CCObject *rec, SEL_MenuHandler selector);
114115

116+
template <class Callback>
117+
geode::comm::ListenerHandle* addActivateCallback(
118+
Callback&& callback,
119+
int priority = 0
120+
) {
121+
return this->addEventListener("", geode::MenuItemActivatedEvent(this), std::forward<Callback>(callback), priority);
122+
}
123+
115124
public:
116125
CCObject* m_pListener;
117126
SEL_MenuHandler m_pfnSelector;

0 commit comments

Comments
 (0)