Skip to content

Commit bc73a21

Browse files
committed
impl editor load / save position keybinds + passthrough most keybinds
1 parent 453565b commit bc73a21

File tree

2 files changed

+115
-61
lines changed

2 files changed

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

src/EditorUI.cpp

Lines changed: 114 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ using namespace keybinds;
1717
static constexpr auto PLATFORM_CONTROL = Modifier::Control;
1818
#endif
1919

20+
class EvilBypass : public CCKeyboardDispatcher {
21+
public:
22+
bool setControlPressed(bool pressed) {
23+
auto old = m_bControlPressed;
24+
m_bControlPressed = pressed;
25+
return old;
26+
}
27+
bool setCommandPressed(bool pressed) {
28+
auto old = m_bCommandPressed;
29+
m_bCommandPressed = pressed;
30+
return old;
31+
}
32+
bool setShiftPressed(bool pressed) {
33+
auto old = m_bShiftPressed;
34+
m_bShiftPressed = pressed;
35+
return old;
36+
}
37+
bool setAltPressed(bool pressed) {
38+
auto old = m_bAltPressed;
39+
m_bAltPressed = pressed;
40+
return old;
41+
}
42+
};
43+
2044
struct $modify(EditorPauseLayer) {
2145
static void onModify(auto& self) {
2246
(void)self.setHookPriority("EditorPauseLayer::keyDown", 1000);
@@ -41,8 +65,6 @@ struct $modify(EditorPauseLayer) {
4165
}
4266
};
4367

44-
std::unordered_set<enumKeyCodes> g_allowedKeyCodes;
45-
4668
struct $modify(EditorUI) {
4769
static void onModify(auto& self) {
4870
(void)self.setHookPriority("EditorUI::keyDown", 1000000);
@@ -82,91 +104,86 @@ struct $modify(EditorUI) {
82104
};
83105
});
84106
this->defineKeybind("robtop.geometry-dash/build-mode", [=] {
85-
this->toggleMode(m_buildModeBtn);
107+
this->passThroughKeyDown(KEY_One);
86108
});
87109
this->defineKeybind("robtop.geometry-dash/edit-mode", [=] {
88-
this->toggleMode(m_editModeBtn);
110+
this->passThroughKeyDown(KEY_Two);
89111
});
90112
this->defineKeybind("robtop.geometry-dash/delete-mode", [=] {
91-
this->toggleMode(m_deleteModeBtn);
113+
this->passThroughKeyDown(KEY_Three);
92114
});
93115
this->defineKeybind("robtop.geometry-dash/rotate-ccw", [=] {
94-
this->transformObjectCall(EditCommand::RotateCCW);
116+
this->passThroughKeyDown(KEY_Q);
95117
});
96118
this->defineKeybind("robtop.geometry-dash/rotate-cw", [=] {
97-
this->transformObjectCall(EditCommand::RotateCW);
119+
this->passThroughKeyDown(KEY_E);
98120
});
99121
this->defineKeybind("robtop.geometry-dash/flip-x", [=] {
100-
this->transformObjectCall(EditCommand::FlipX);
122+
this->passThroughKeyDown(KEY_Q, Modifier::Alt);
101123
});
102124
this->defineKeybind("robtop.geometry-dash/flip-y", [=] {
103-
this->transformObjectCall(EditCommand::FlipY);
125+
this->passThroughKeyDown(KEY_E, Modifier::Alt);
104126
});
105127
this->defineKeybind("robtop.geometry-dash/delete", [=] {
106-
this->onDeleteSelected(nullptr);
128+
this->passThroughKeyDown(KEY_Delete);
107129
});
108130
this->defineKeybind("robtop.geometry-dash/undo", [=] {
109-
this->undoLastAction(nullptr);
131+
this->passThroughKeyDown(KEY_Z, Modifier::Control);
110132
});
111133
this->defineKeybind("robtop.geometry-dash/redo", [=] {
112-
this->redoLastAction(nullptr);
134+
this->passThroughKeyDown(KEY_Z, Modifier::Control | Modifier::Shift);
113135
});
114136
this->defineKeybind("robtop.geometry-dash/deselect-all", [=] {
115-
this->deselectAll();
137+
this->passThroughKeyDown(KEY_D, Modifier::Alt);
116138
});
117139
this->defineKeybind("robtop.geometry-dash/copy", [=] {
118-
this->onCopy(nullptr);
140+
this->passThroughKeyDown(KEY_C, Modifier::Control);
119141
});
120142
this->defineKeybind("robtop.geometry-dash/paste", [=] {
121-
this->onPaste(nullptr);
143+
this->passThroughKeyDown(KEY_V, Modifier::Control);
122144
});
123145
this->defineKeybind("robtop.geometry-dash/copy-paste", [=] {
124-
this->onDuplicate(nullptr);
146+
this->passThroughKeyDown(KEY_D, Modifier::Control);
125147
});
126148
this->defineKeybind("robtop.geometry-dash/toggle-rotate", [=] {
127-
this->toggleEnableRotate(nullptr);
149+
this->passThroughKeyDown(KEY_R);
128150
});
129151
this->defineKeybind("robtop.geometry-dash/toggle-free-move", [=] {
130-
this->toggleFreeMove(nullptr);
152+
this->passThroughKeyDown(KEY_F);
131153
});
132154
this->defineKeybind("robtop.geometry-dash/toggle-swipe", [=] {
133-
this->toggleSwipe(nullptr);
155+
this->passThroughKeyDown(KEY_T);
134156
});
135157
this->defineKeybind("robtop.geometry-dash/toggle-snap", [=] {
136-
this->toggleSnap(nullptr);
158+
this->passThroughKeyDown(KEY_G);
137159
});
138160
this->defineKeybind("robtop.geometry-dash/playtest", [=] {
139-
if (m_editorLayer->m_playbackMode == PlaybackMode::Playing) {
140-
this->onStopPlaytest(nullptr);
141-
}
142-
else {
143-
this->onPlaytest(nullptr);
144-
}
161+
this->passThroughKeyDown(KEY_Enter);
145162
});
146163
this->defineKeybind("robtop.geometry-dash/playback-music", [=] {
147-
if (m_editorLayer->m_playbackMode != PlaybackMode::Playing) {
148-
this->onPlayback(nullptr);
149-
}
164+
this->passThroughKeyDown(KEY_Enter, Modifier::Control);
150165
});
151166
this->defineKeybind("robtop.geometry-dash/prev-build-tab", [=] {
167+
// not passthrough because this is different from vanilla
152168
auto t = m_selectedTab - 1;
153169
if (t < 0) {
154170
t = m_tabsArray->count() - 1;
155171
}
156172
this->selectBuildTab(t);
157173
});
158174
this->defineKeybind("robtop.geometry-dash/next-build-tab", [=] {
175+
// not passthrough because this is different from vanilla
159176
auto t = m_selectedTab + 1;
160177
if (t > static_cast<int>(m_tabsArray->count() - 1)) {
161178
t = 0;
162179
}
163180
this->selectBuildTab(t);
164181
});
165182
this->defineKeybind("robtop.geometry-dash/next-layer", [=] {
166-
this->onGroupUp(nullptr);
183+
this->passThroughKeyDown(KEY_Right);
167184
});
168185
this->defineKeybind("robtop.geometry-dash/prev-layer", [=] {
169-
this->onGroupDown(nullptr);
186+
this->passThroughKeyDown(KEY_Left);
170187
});
171188
this->defineKeybind("robtop.geometry-dash/scroll-up", [=] {
172189
this->moveGamelayer({ .0f, 10.f });
@@ -181,53 +198,57 @@ struct $modify(EditorUI) {
181198
this->zoomOut(nullptr);
182199
});
183200
this->defineKeybind("robtop.geometry-dash/move-obj-left", [=] {
184-
this->moveObjectCall(EditCommand::Left);
201+
this->passThroughKeyDown(KEY_A);
185202
});
186203
this->defineKeybind("robtop.geometry-dash/move-obj-right", [=] {
187-
this->moveObjectCall(EditCommand::Right);
204+
this->passThroughKeyDown(KEY_D);
188205
});
189206
this->defineKeybind("robtop.geometry-dash/move-obj-up", [=] {
190-
this->moveObjectCall(EditCommand::Up);
207+
this->passThroughKeyDown(KEY_W);
191208
});
192209
this->defineKeybind("robtop.geometry-dash/move-obj-down", [=] {
193-
this->moveObjectCall(EditCommand::Down);
210+
this->passThroughKeyDown(KEY_S);
194211
});
195212
this->defineKeybind("robtop.geometry-dash/move-obj-left-small", [=] {
196-
this->moveObjectCall(EditCommand::SmallLeft);
213+
this->passThroughKeyDown(KEY_A, Modifier::Shift);
197214
});
198215
this->defineKeybind("robtop.geometry-dash/move-obj-right-small", [=] {
199-
this->moveObjectCall(EditCommand::SmallRight);
216+
this->passThroughKeyDown(KEY_D, Modifier::Shift);
200217
});
201218
this->defineKeybind("robtop.geometry-dash/move-obj-up-small", [=] {
202-
this->moveObjectCall(EditCommand::SmallUp);
219+
this->passThroughKeyDown(KEY_W, Modifier::Shift);
203220
});
204221
this->defineKeybind("robtop.geometry-dash/move-obj-down-small", [=] {
205-
this->moveObjectCall(EditCommand::SmallDown);
222+
this->passThroughKeyDown(KEY_S, Modifier::Shift);
206223
});
207224
this->defineKeybind("robtop.geometry-dash/lock-preview", [=] {
208-
g_allowedKeyCodes.insert(KEY_F1);
209-
this->keyDown(KEY_F1);
225+
this->passThroughKeyDown(KEY_F1);
210226
});
211227
this->defineKeybind("robtop.geometry-dash/unlock-preview", [=] {
212-
g_allowedKeyCodes.insert(KEY_F2);
213-
this->keyDown(KEY_F2);
228+
this->passThroughKeyDown(KEY_F2);
214229
});
215230
this->defineKeybind("robtop.geometry-dash/toggle-preview-mode", [=] {
216-
g_allowedKeyCodes.insert(KEY_F3);
217-
this->keyDown(KEY_F3);
231+
this->passThroughKeyDown(KEY_F3);
218232
});
219233
this->defineKeybind("robtop.geometry-dash/toggle-particle-icons", [=] {
220-
g_allowedKeyCodes.insert(KEY_F4);
221-
this->keyDown(KEY_F4);
234+
this->passThroughKeyDown(KEY_F4);
222235
});
223236
this->defineKeybind("robtop.geometry-dash/toggle-editor-hitboxes", [=] {
224-
g_allowedKeyCodes.insert(KEY_F5);
225-
this->keyDown(KEY_F5);
237+
this->passThroughKeyDown(KEY_F5);
226238
});
227239
this->defineKeybind("robtop.geometry-dash/toggle-hide-invisible", [=] {
228-
g_allowedKeyCodes.insert(KEY_F6);
229-
this->keyDown(KEY_F6);
230-
});
240+
this->passThroughKeyDown(KEY_F6);
241+
});
242+
for (size_t i = 0; i < 10; i += 1) {
243+
auto x = std::to_string(i);
244+
auto key = static_cast<enumKeyCodes>(KEY_Zero + i);
245+
this->defineKeybind("robtop.geometry-dash/save-editor-position-" + x, [=] {
246+
this->passThroughKeyDown(key, Modifier::Control);
247+
});
248+
this->defineKeybind("robtop.geometry-dash/load-editor-position-" + x, [=] {
249+
this->passThroughKeyDown(key, Modifier::Alt);
250+
});
251+
}
231252
});
232253

233254
return true;
@@ -241,14 +262,14 @@ struct $modify(EditorUI) {
241262
return EditorUI::moveObjectCall(p0);
242263
}
243264

244-
void defineKeybind(const char* id, std::function<void(bool)> callback) {
265+
void defineKeybind(std::string const& id, std::function<void(bool)> callback) {
245266
this->template addEventListener<InvokeBindFilter>([=](InvokeBindEvent* event) {
246267
callback(event->isDown());
247268
return ListenerResult::Propagate;
248269
}, id);
249270
}
250271

251-
void defineKeybind(const char* id, std::function<void()> callback) {
272+
void defineKeybind(std::string const& id, std::function<void()> callback) {
252273
this->template addEventListener<InvokeBindFilter>([=](InvokeBindEvent* event) {
253274
if (event->isDown()) {
254275
callback();
@@ -257,13 +278,28 @@ struct $modify(EditorUI) {
257278
}, id);
258279
}
259280

281+
static inline bool s_allowPassThrough = false;
282+
283+
void passThroughKeyDown(enumKeyCodes key, Modifier modifiers = Modifier::None) {
284+
s_allowPassThrough = true;
285+
auto d = static_cast<EvilBypass*>(CCKeyboardDispatcher::get());
286+
auto alt = d->setAltPressed(modifiers & Modifier::Alt);
287+
auto shift = d->setShiftPressed(modifiers & Modifier::Shift);
288+
auto ctrl = d->setControlPressed(modifiers & Modifier::Control);
289+
auto cmd = d->setCommandPressed(modifiers & Modifier::Command);
290+
this->keyDown(key);
291+
d->setAltPressed(alt);
292+
d->setShiftPressed(shift);
293+
d->setControlPressed(ctrl);
294+
d->setCommandPressed(cmd);
295+
}
296+
260297
void keyDown(enumKeyCodes key) {
261-
// TODO: I'll let F keys through until we figure out how to toggle them
262-
if (key == enumKeyCodes::KEY_Escape || (key >= enumKeyCodes::KEY_F1 && key <= enumKeyCodes::KEY_F6)) {
298+
if (key == enumKeyCodes::KEY_Escape) {
263299
EditorUI::keyDown(key);
264300
}
265-
if (g_allowedKeyCodes.contains(key)) {
266-
g_allowedKeyCodes.erase(key);
301+
else if (s_allowPassThrough) {
302+
s_allowPassThrough = false;
267303
EditorUI::keyDown(key);
268304
}
269305
}
@@ -415,14 +451,14 @@ struct $modify(EditorUI) {
415451
"robtop.geometry-dash/prev-build-tab",
416452
"Previous Build Tab",
417453
"",
418-
{ Keybind::create(KEY_F1, Modifier::None) },
454+
{},
419455
Category::EDITOR_UI, true
420456
});
421457
BindManager::get()->registerBindable({
422458
"robtop.geometry-dash/next-build-tab",
423459
"Next Build Tab",
424460
"",
425-
{ Keybind::create(KEY_F2, Modifier::None) },
461+
{},
426462
Category::EDITOR_UI, true
427463
});
428464
BindManager::get()->registerBindable({
@@ -571,4 +607,22 @@ struct $modify(EditorUI) {
571607
{ Keybind::create(KEY_S, Modifier::Shift) },
572608
Category::EDITOR_MOVE, true
573609
});
610+
for (size_t i = 0; i < 10; i += 1) {
611+
auto x = std::to_string(i);
612+
BindManager::get()->registerBindable({
613+
"robtop.geometry-dash/save-editor-position-" + x,
614+
"Save Editor Position " + x,
615+
"Save the current editor camera position in the slot " + x + ". "
616+
"You can reload this slot back with Load Editor Position " + x,
617+
{ Keybind::create(static_cast<enumKeyCodes>(KEY_Zero + i), Modifier::Control) },
618+
Category::EDITOR_UI, false
619+
});
620+
BindManager::get()->registerBindable({
621+
"robtop.geometry-dash/load-editor-position-" + x,
622+
"Load Editor Position " + x,
623+
"Load the current editor camera position in the slot " + x,
624+
{ Keybind::create(static_cast<enumKeyCodes>(KEY_Zero + i), Modifier::Alt) },
625+
Category::EDITOR_UI, false
626+
});
627+
}
574628
}

0 commit comments

Comments
 (0)