-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhooks.cpp
99 lines (90 loc) · 3.09 KB
/
hooks.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <Geode/modify/CCLayer.hpp>
#include <Geode/modify/CCMenu.hpp>
#include <Geode/modify/CCTouchDispatcher.hpp>
#include <Geode/modify/AchievementNotifier.hpp>
#include <Geode/modify/CCTextInputNode.hpp>
#include <Geode/utils/cocos.hpp>
#include "../include/API.hpp"
#include "Pool.hpp"
using namespace geode::prelude;
using namespace mouse;
struct $modify(CCTouchDispatcher) {
void addStandardDelegate(CCTouchDelegate* delegate, int prio) {
CCTouchDispatcher::addStandardDelegate(delegate, prio);
if (auto node = typeinfo_cast<CCNode*>(delegate)) {
if (node->getEventListener("mouse"_spr)) return;
node->template addEventListener<MouseEventFilter>(
"mouse"_spr,
[=](MouseEvent*) {
return MouseResult::Eat;
}
);
Mouse::updateListeners();
}
}
void addTargetedDelegate(CCTouchDelegate* delegate, int prio, bool swallows) {
CCTouchDispatcher::addTargetedDelegate(delegate, prio, swallows);
if (auto node = typeinfo_cast<CCNode*>(delegate)) {
if (node->getEventListener("mouse"_spr)) return;
if (swallows) {
node->template addEventListener<MouseEventFilter>(
"mouse"_spr,
[=](MouseEvent*) {
return MouseResult::Swallow;
}
);
}
else {
node->template addEventListener<MouseEventFilter>(
"mouse"_spr,
[=](MouseEvent*) {
return MouseResult::Eat;
}
);
}
Mouse::updateListeners();
}
}
void removeDelegate(CCTouchDelegate* delegate) {
if (auto node = typeinfo_cast<CCNode*>(delegate)) {
node->removeEventListener("mouse"_spr);
Mouse::updateListeners();
}
CCTouchDispatcher::removeDelegate(delegate);
}
};
struct $modify(CCTextInputNode) {
bool ccTouchBegan(CCTouch* touch, CCEvent* event) {
if (m_delegate && !m_delegate->allowTextInput(this)) {
return false;
}
this->onClickTrackNode(true);
return true;
}
};
struct $modify(CCMenu) {
bool initWithArray(CCArray* items) {
if (!CCMenu::initWithArray(items))
return false;
this->template addEventListener<MouseEventFilter>(
"mouse"_spr,
[=](MouseEvent* ev) {
for (auto& child : CCArrayExt<CCNode>(m_pChildren)) {
if (child->boundingBox().containsPoint(this->convertToNodeSpace(ev->getPosition()))) {
return MouseResult::Swallow;
}
}
return MouseResult::Leave;
},
true
);
Mouse::updateListeners();
return true;
}
};
struct $modify(AchievementNotifier) {
void willSwitchToScene(CCScene* scene) {
AchievementNotifier::willSwitchToScene(scene);
Mouse::updateListeners();
}
};