Skip to content

Commit f9a8c4c

Browse files
committed
just use fallthrough for a bunch of keys, fixes holding from respawn
1 parent d40abde commit f9a8c4c

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

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.204"
55
},
6-
"version": "v1.5.0",
6+
"version": "v1.5.1",
77
"id": "geode.custom-keybinds",
88
"name": "Custom Keybinds",
99
"developer": "Geode Team",

src/UILayer.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ struct $modify(UILayer) {
108108
return playLayer != nullptr && playLayer == PlayLayer::get() && getChildOfType<UILayer>(playLayer, 0) == this;
109109
}
110110

111+
void pressKeyFallthrough(enumKeyCodes key, bool down) {
112+
allowKeyDownThrough = true;
113+
if (down) {
114+
this->keyDown(key);
115+
} else {
116+
this->keyUp(key);
117+
}
118+
allowKeyDownThrough = false;
119+
}
120+
111121
bool init(GJBaseGameLayer* layer) {
112122
if (!UILayer::init(layer))
113123
return false;
@@ -118,25 +128,16 @@ struct $modify(UILayer) {
118128
if (!PlayLayer::get()) return;
119129

120130
this->defineKeybind("robtop.geometry-dash/jump-p1", [=](bool down) {
121-
// todo: event priority
122-
if (this->isCurrentPlayLayer() && !this->isPaused()) {
123-
PlayLayer::get()->queueButton(platformButton(), down, false);
124-
}
131+
this->pressKeyFallthrough(KEY_Space, down);
125132
});
126133
this->defineKeybind("robtop.geometry-dash/jump-p2", [=](bool down) {
127-
if (this->isCurrentPlayLayer() && !this->isPaused()) {
128-
PlayLayer::get()->queueButton(platformButton(), down, true);
129-
}
134+
this->pressKeyFallthrough(KEY_Up, down);
130135
});
131136
this->defineKeybind("robtop.geometry-dash/place-checkpoint", [=](bool down) {
132-
if (down && this->isCurrentPlayLayer() && PlayLayer::get()->m_isPracticeMode) {
133-
this->onCheck(nullptr);
134-
}
137+
this->pressKeyFallthrough(KEY_Z, down);
135138
});
136139
this->defineKeybind("robtop.geometry-dash/delete-checkpoint", [=](bool down) {
137-
if (down && this->isCurrentPlayLayer() && PlayLayer::get()->m_isPracticeMode) {
138-
this->onDeleteCheck(nullptr);
139-
}
140+
this->pressKeyFallthrough(KEY_X, down);
140141
});
141142
this->defineKeybind("robtop.geometry-dash/pause-level", [=](bool down) {
142143
if (down && this->isCurrentPlayLayer() && !this->isPaused()) {
@@ -154,31 +155,21 @@ struct $modify(UILayer) {
154155
}
155156
});
156157
this->defineKeybind("robtop.geometry-dash/move-left-p1", [=](bool down) {
157-
if (this->isCurrentPlayLayer() && !this->isPaused()) {
158-
PlayLayer::get()->queueButton(static_cast<int>(PlayerButton::Left), down, false);
159-
}
158+
this->pressKeyFallthrough(KEY_A, down);
160159
});
161160
this->defineKeybind("robtop.geometry-dash/move-right-p1", [=](bool down) {
162-
if (this->isCurrentPlayLayer() && !this->isPaused()) {
163-
PlayLayer::get()->queueButton(static_cast<int>(PlayerButton::Right), down, false);
164-
}
161+
this->pressKeyFallthrough(KEY_D, down);
165162
});
166163
this->defineKeybind("robtop.geometry-dash/move-left-p2", [=](bool down) {
167-
if (this->isCurrentPlayLayer() && !this->isPaused()) {
168-
PlayLayer::get()->queueButton(static_cast<int>(PlayerButton::Left), down, true);
169-
}
164+
this->pressKeyFallthrough(KEY_Left, down);
170165
});
171166
this->defineKeybind("robtop.geometry-dash/move-right-p2", [=](bool down) {
172-
if (this->isCurrentPlayLayer() && !this->isPaused()) {
173-
PlayLayer::get()->queueButton(static_cast<int>(PlayerButton::Right), down, true);
174-
}
167+
this->pressKeyFallthrough(KEY_Right, down);
175168
});
176169
this->defineKeybind("robtop.geometry-dash/toggle-hitboxes", [=](bool down) {
177170
if (down && this->isCurrentPlayLayer() && !this->isPaused()) {
178-
// TODO actually reverse PlayLayer::toggleDebugDraw (its inlined and needs 2 members, a bool and a CCDrawNode*)
179-
allowKeyDownThrough = true;
180-
this->keyDown(enumKeyCodes::KEY_P);
181-
allowKeyDownThrough = false;
171+
// This assumes you have quick keys on
172+
this->pressKeyFallthrough(KEY_P, down);
182173
}
183174
});
184175
// display practice mode button keybinds
@@ -211,12 +202,18 @@ struct $modify(UILayer) {
211202

212203
// silly hack for hitboxes..
213204
static inline bool allowKeyDownThrough = false;
214-
void keyDown(enumKeyCodes key) {
205+
void keyDown(enumKeyCodes key) override {
215206
if (key == enumKeyCodes::KEY_Escape || allowKeyDownThrough) {
216207
UILayer::keyDown(key);
208+
allowKeyDownThrough = false;
209+
}
210+
}
211+
void keyUp(enumKeyCodes key) override {
212+
if (allowKeyDownThrough) {
213+
UILayer::keyUp(key);
214+
allowKeyDownThrough = false;
217215
}
218216
}
219-
void keyUp(enumKeyCodes) {}
220217
};
221218

222219
$execute {

0 commit comments

Comments
 (0)