@@ -17,6 +17,30 @@ using namespace keybinds;
17
17
static constexpr auto PLATFORM_CONTROL = Modifier::Control;
18
18
#endif
19
19
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
+
20
44
struct $modify(EditorPauseLayer) {
21
45
static void onModify (auto & self) {
22
46
(void )self.setHookPriority (" EditorPauseLayer::keyDown" , 1000 );
@@ -41,8 +65,6 @@ struct $modify(EditorPauseLayer) {
41
65
}
42
66
};
43
67
44
- std::unordered_set<enumKeyCodes> g_allowedKeyCodes;
45
-
46
68
struct $modify(EditorUI) {
47
69
static void onModify (auto & self) {
48
70
(void )self.setHookPriority (" EditorUI::keyDown" , 1000000 );
@@ -82,91 +104,86 @@ struct $modify(EditorUI) {
82
104
};
83
105
});
84
106
this ->defineKeybind (" robtop.geometry-dash/build-mode" , [=] {
85
- this ->toggleMode (m_buildModeBtn );
107
+ this ->passThroughKeyDown (KEY_One );
86
108
});
87
109
this ->defineKeybind (" robtop.geometry-dash/edit-mode" , [=] {
88
- this ->toggleMode (m_editModeBtn );
110
+ this ->passThroughKeyDown (KEY_Two );
89
111
});
90
112
this ->defineKeybind (" robtop.geometry-dash/delete-mode" , [=] {
91
- this ->toggleMode (m_deleteModeBtn );
113
+ this ->passThroughKeyDown (KEY_Three );
92
114
});
93
115
this ->defineKeybind (" robtop.geometry-dash/rotate-ccw" , [=] {
94
- this ->transformObjectCall (EditCommand::RotateCCW );
116
+ this ->passThroughKeyDown (KEY_Q );
95
117
});
96
118
this ->defineKeybind (" robtop.geometry-dash/rotate-cw" , [=] {
97
- this ->transformObjectCall (EditCommand::RotateCW );
119
+ this ->passThroughKeyDown (KEY_E );
98
120
});
99
121
this ->defineKeybind (" robtop.geometry-dash/flip-x" , [=] {
100
- this ->transformObjectCall (EditCommand::FlipX );
122
+ this ->passThroughKeyDown (KEY_Q, Modifier::Alt );
101
123
});
102
124
this ->defineKeybind (" robtop.geometry-dash/flip-y" , [=] {
103
- this ->transformObjectCall (EditCommand::FlipY );
125
+ this ->passThroughKeyDown (KEY_E, Modifier::Alt );
104
126
});
105
127
this ->defineKeybind (" robtop.geometry-dash/delete" , [=] {
106
- this ->onDeleteSelected ( nullptr );
128
+ this ->passThroughKeyDown (KEY_Delete );
107
129
});
108
130
this ->defineKeybind (" robtop.geometry-dash/undo" , [=] {
109
- this ->undoLastAction ( nullptr );
131
+ this ->passThroughKeyDown (KEY_Z, Modifier::Control );
110
132
});
111
133
this ->defineKeybind (" robtop.geometry-dash/redo" , [=] {
112
- this ->redoLastAction ( nullptr );
134
+ this ->passThroughKeyDown (KEY_Z, Modifier::Control | Modifier::Shift );
113
135
});
114
136
this ->defineKeybind (" robtop.geometry-dash/deselect-all" , [=] {
115
- this ->deselectAll ( );
137
+ this ->passThroughKeyDown (KEY_D, Modifier::Alt );
116
138
});
117
139
this ->defineKeybind (" robtop.geometry-dash/copy" , [=] {
118
- this ->onCopy ( nullptr );
140
+ this ->passThroughKeyDown (KEY_C, Modifier::Control );
119
141
});
120
142
this ->defineKeybind (" robtop.geometry-dash/paste" , [=] {
121
- this ->onPaste ( nullptr );
143
+ this ->passThroughKeyDown (KEY_V, Modifier::Control );
122
144
});
123
145
this ->defineKeybind (" robtop.geometry-dash/copy-paste" , [=] {
124
- this ->onDuplicate ( nullptr );
146
+ this ->passThroughKeyDown (KEY_D, Modifier::Control );
125
147
});
126
148
this ->defineKeybind (" robtop.geometry-dash/toggle-rotate" , [=] {
127
- this ->toggleEnableRotate ( nullptr );
149
+ this ->passThroughKeyDown (KEY_R );
128
150
});
129
151
this ->defineKeybind (" robtop.geometry-dash/toggle-free-move" , [=] {
130
- this ->toggleFreeMove ( nullptr );
152
+ this ->passThroughKeyDown (KEY_F );
131
153
});
132
154
this ->defineKeybind (" robtop.geometry-dash/toggle-swipe" , [=] {
133
- this ->toggleSwipe ( nullptr );
155
+ this ->passThroughKeyDown (KEY_T );
134
156
});
135
157
this ->defineKeybind (" robtop.geometry-dash/toggle-snap" , [=] {
136
- this ->toggleSnap ( nullptr );
158
+ this ->passThroughKeyDown (KEY_G );
137
159
});
138
160
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);
145
162
});
146
163
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);
150
165
});
151
166
this ->defineKeybind (" robtop.geometry-dash/prev-build-tab" , [=] {
167
+ // not passthrough because this is different from vanilla
152
168
auto t = m_selectedTab - 1 ;
153
169
if (t < 0 ) {
154
170
t = m_tabsArray->count () - 1 ;
155
171
}
156
172
this ->selectBuildTab (t);
157
173
});
158
174
this ->defineKeybind (" robtop.geometry-dash/next-build-tab" , [=] {
175
+ // not passthrough because this is different from vanilla
159
176
auto t = m_selectedTab + 1 ;
160
177
if (t > static_cast <int >(m_tabsArray->count () - 1 )) {
161
178
t = 0 ;
162
179
}
163
180
this ->selectBuildTab (t);
164
181
});
165
182
this ->defineKeybind (" robtop.geometry-dash/next-layer" , [=] {
166
- this ->onGroupUp ( nullptr );
183
+ this ->passThroughKeyDown (KEY_Right );
167
184
});
168
185
this ->defineKeybind (" robtop.geometry-dash/prev-layer" , [=] {
169
- this ->onGroupDown ( nullptr );
186
+ this ->passThroughKeyDown (KEY_Left );
170
187
});
171
188
this ->defineKeybind (" robtop.geometry-dash/scroll-up" , [=] {
172
189
this ->moveGamelayer ({ .0f , 10 .f });
@@ -181,53 +198,57 @@ struct $modify(EditorUI) {
181
198
this ->zoomOut (nullptr );
182
199
});
183
200
this ->defineKeybind (" robtop.geometry-dash/move-obj-left" , [=] {
184
- this ->moveObjectCall (EditCommand::Left );
201
+ this ->passThroughKeyDown (KEY_A );
185
202
});
186
203
this ->defineKeybind (" robtop.geometry-dash/move-obj-right" , [=] {
187
- this ->moveObjectCall (EditCommand::Right );
204
+ this ->passThroughKeyDown (KEY_D );
188
205
});
189
206
this ->defineKeybind (" robtop.geometry-dash/move-obj-up" , [=] {
190
- this ->moveObjectCall (EditCommand::Up );
207
+ this ->passThroughKeyDown (KEY_W );
191
208
});
192
209
this ->defineKeybind (" robtop.geometry-dash/move-obj-down" , [=] {
193
- this ->moveObjectCall (EditCommand::Down );
210
+ this ->passThroughKeyDown (KEY_S );
194
211
});
195
212
this ->defineKeybind (" robtop.geometry-dash/move-obj-left-small" , [=] {
196
- this ->moveObjectCall (EditCommand::SmallLeft );
213
+ this ->passThroughKeyDown (KEY_A, Modifier::Shift );
197
214
});
198
215
this ->defineKeybind (" robtop.geometry-dash/move-obj-right-small" , [=] {
199
- this ->moveObjectCall (EditCommand::SmallRight );
216
+ this ->passThroughKeyDown (KEY_D, Modifier::Shift );
200
217
});
201
218
this ->defineKeybind (" robtop.geometry-dash/move-obj-up-small" , [=] {
202
- this ->moveObjectCall (EditCommand::SmallUp );
219
+ this ->passThroughKeyDown (KEY_W, Modifier::Shift );
203
220
});
204
221
this ->defineKeybind (" robtop.geometry-dash/move-obj-down-small" , [=] {
205
- this ->moveObjectCall (EditCommand::SmallDown );
222
+ this ->passThroughKeyDown (KEY_S, Modifier::Shift );
206
223
});
207
224
this ->defineKeybind (" robtop.geometry-dash/lock-preview" , [=] {
208
- g_allowedKeyCodes.insert (KEY_F1);
209
- this ->keyDown (KEY_F1);
225
+ this ->passThroughKeyDown (KEY_F1);
210
226
});
211
227
this ->defineKeybind (" robtop.geometry-dash/unlock-preview" , [=] {
212
- g_allowedKeyCodes.insert (KEY_F2);
213
- this ->keyDown (KEY_F2);
228
+ this ->passThroughKeyDown (KEY_F2);
214
229
});
215
230
this ->defineKeybind (" robtop.geometry-dash/toggle-preview-mode" , [=] {
216
- g_allowedKeyCodes.insert (KEY_F3);
217
- this ->keyDown (KEY_F3);
231
+ this ->passThroughKeyDown (KEY_F3);
218
232
});
219
233
this ->defineKeybind (" robtop.geometry-dash/toggle-particle-icons" , [=] {
220
- g_allowedKeyCodes.insert (KEY_F4);
221
- this ->keyDown (KEY_F4);
234
+ this ->passThroughKeyDown (KEY_F4);
222
235
});
223
236
this ->defineKeybind (" robtop.geometry-dash/toggle-editor-hitboxes" , [=] {
224
- g_allowedKeyCodes.insert (KEY_F5);
225
- this ->keyDown (KEY_F5);
237
+ this ->passThroughKeyDown (KEY_F5);
226
238
});
227
239
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
+ }
231
252
});
232
253
233
254
return true ;
@@ -241,14 +262,14 @@ struct $modify(EditorUI) {
241
262
return EditorUI::moveObjectCall (p0);
242
263
}
243
264
244
- void defineKeybind (const char * id, std::function<void (bool )> callback) {
265
+ void defineKeybind (std::string const & id, std::function<void (bool )> callback) {
245
266
this ->template addEventListener <InvokeBindFilter>([=](InvokeBindEvent* event) {
246
267
callback (event->isDown ());
247
268
return ListenerResult::Propagate;
248
269
}, id);
249
270
}
250
271
251
- void defineKeybind (const char * id, std::function<void ()> callback) {
272
+ void defineKeybind (std::string const & id, std::function<void ()> callback) {
252
273
this ->template addEventListener <InvokeBindFilter>([=](InvokeBindEvent* event) {
253
274
if (event->isDown ()) {
254
275
callback ();
@@ -257,13 +278,28 @@ struct $modify(EditorUI) {
257
278
}, id);
258
279
}
259
280
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
+
260
297
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) {
263
299
EditorUI::keyDown (key);
264
300
}
265
- if (g_allowedKeyCodes. contains (key) ) {
266
- g_allowedKeyCodes. erase (key) ;
301
+ else if (s_allowPassThrough ) {
302
+ s_allowPassThrough = false ;
267
303
EditorUI::keyDown (key);
268
304
}
269
305
}
@@ -415,14 +451,14 @@ struct $modify(EditorUI) {
415
451
" robtop.geometry-dash/prev-build-tab" ,
416
452
" Previous Build Tab" ,
417
453
" " ,
418
- { Keybind::create (KEY_F1, Modifier::None) },
454
+ {},
419
455
Category::EDITOR_UI, true
420
456
});
421
457
BindManager::get ()->registerBindable ({
422
458
" robtop.geometry-dash/next-build-tab" ,
423
459
" Next Build Tab" ,
424
460
" " ,
425
- { Keybind::create (KEY_F2, Modifier::None) },
461
+ {},
426
462
Category::EDITOR_UI, true
427
463
});
428
464
BindManager::get ()->registerBindable ({
@@ -571,4 +607,22 @@ struct $modify(EditorUI) {
571
607
{ Keybind::create (KEY_S, Modifier::Shift) },
572
608
Category::EDITOR_MOVE, true
573
609
});
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
+ }
574
628
}
0 commit comments