Skip to content

Commit 536dd1f

Browse files
committed
Made it so only certain action types can be "freezable".
1 parent f26283b commit 536dd1f

File tree

8 files changed

+111
-52
lines changed

8 files changed

+111
-52
lines changed

source/source/content/other/gui.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,7 @@ GuiItem* GuiManager::getFocusedItem() const {
11921192
* @return Whether it got handled.
11931193
*/
11941194
bool GuiManager::handleAllegroEvent(const ALLEGRO_EVENT& ev) {
1195-
if(!responsive) return false;
1196-
if(animTimer.getRatioLeft() > 0.0f && ignoreInputOnAnimation) return false;
1195+
if(!shouldHandleEvents()) return false;
11971196

11981197
bool handled = false;
11991198
bool mouseMoved = false;
@@ -1257,15 +1256,7 @@ bool GuiManager::handleAllegroEvent(const ALLEGRO_EVENT& ev) {
12571256
* @return Whether the action was consumed.
12581257
*/
12591258
bool GuiManager::handlePlayerAction(const Inpution::Action& action) {
1260-
if(!responsive) {
1261-
return false;
1262-
}
1263-
if(
1264-
animTimer.getRatioLeft() > 0.0f &&
1265-
ignoreInputOnAnimation
1266-
) {
1267-
return false;
1268-
}
1259+
if(!shouldHandleEvents()) return false;
12691260

12701261
bool isDown = (action.value >= 0.5);
12711262
bool buttonRecognized = true;
@@ -1522,6 +1513,18 @@ bool GuiManager::setFocusedItem(GuiItem* item, bool silent) {
15221513
}
15231514

15241515

1516+
/**
1517+
* @brief Whether it should be handling events right now.
1518+
*
1519+
* @return Whether it should.
1520+
*/
1521+
bool GuiManager::shouldHandleEvents() {
1522+
if(!responsive) return false;
1523+
if(animTimer.getRatioLeft() > 0.0f && ignoreInputOnAnimation) return false;
1524+
return true;
1525+
}
1526+
1527+
15251528
/**
15261529
* @brief Shows all items, if they were hidden.
15271530
*

source/source/content/other/gui.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ struct GuiItemDef {
160160

161161
//Width and height.
162162
Point size;
163-
163+
164164
//Optional description. Shows up in the GUI editor.
165165
string description;
166166

@@ -173,7 +173,7 @@ struct GuiItemDef {
173173
* since the engine expects it.
174174
*/
175175
struct HardcodedGuiItemDef : public GuiItemDef {
176-
176+
177177
};
178178

179179

@@ -742,6 +742,7 @@ class GuiManager {
742742
);
743743
bool removeItem(GuiItem* item);
744744
bool setFocusedItem(GuiItem* item, bool silent = false);
745+
bool shouldHandleEvents();
745746
bool showItems();
746747
bool startAnimation(
747748
const GUI_MANAGER_ANIM type, float duration

source/source/core/controls_mediator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ void ControlsMediator::addModifier(
7474
* @param valueType Type of value an action can have.
7575
* @param autoRepeat Auto-repeat threshold.
7676
* @param reinsertionTTL Time to live when reinserted into the queue.
77+
* @param freezable If true, its value can be frozen between game states.
7778
*/
7879
void ControlsMediator::addPlayerActionType(
7980
PLAYER_ACTION_TYPE id, PLAYER_ACTION_CAT category,
8081
const string& name, const string& description, const string& internalName,
8182
const string& defaultBindStr, Inpution::ACTION_VALUE_TYPE valueType,
82-
float autoRepeat, float reinsertionTTL
83+
float autoRepeat, float reinsertionTTL, bool freezable
8384
) {
8485
PlayerActionType a;
8586
a.id = id;
@@ -91,6 +92,7 @@ void ControlsMediator::addPlayerActionType(
9192
a.valueType = valueType;
9293
a.autoRepeat = autoRepeat;
9394
a.reinsertionTTL = reinsertionTTL;
95+
a.freezable = freezable;
9496

9597
playerActionTypes.push_back(a);
9698
mgr.actionTypes[id] = a;

source/source/core/controls_mediator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ struct ControlsMediator {
353353
const string& defaultBindStr,
354354
Inpution::ACTION_VALUE_TYPE valueType,
355355
float autoRepeat = 0.0f,
356-
float reinsertionTTL = 0.0f
356+
float reinsertionTTL = 0.0f,
357+
bool freezable = false
357358
);
358359
const vector<PlayerActionType>& getAllPlayerActionTypes() const;
359360
vector<Inpution::Bind>& binds();

source/source/core/init.cpp

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -178,106 +178,120 @@ void initControls() {
178178
PLAYER_ACTION_CAT_MAIN,
179179
"Move right",
180180
"Move the leader right.",
181-
"move_right", "k_4", Inpution::ACTION_VALUE_TYPE_ANALOG
181+
"move_right", "k_4", Inpution::ACTION_VALUE_TYPE_ANALOG,
182+
0.0f, 0.0f, true
182183
);
183184
game.controls.addPlayerActionType(
184185
PLAYER_ACTION_TYPE_DOWN,
185186
PLAYER_ACTION_CAT_MAIN,
186187
"Move down",
187188
"Move the leader down.",
188-
"move_down", "k_19", Inpution::ACTION_VALUE_TYPE_ANALOG
189+
"move_down", "k_19", Inpution::ACTION_VALUE_TYPE_ANALOG,
190+
0.0f, 0.0f, true
189191
);
190192
game.controls.addPlayerActionType(
191193
PLAYER_ACTION_TYPE_LEFT,
192194
PLAYER_ACTION_CAT_MAIN,
193195
"Move left",
194196
"Move the leader left.",
195-
"move_left", "k_1", Inpution::ACTION_VALUE_TYPE_ANALOG
197+
"move_left", "k_1", Inpution::ACTION_VALUE_TYPE_ANALOG,
198+
0.0f, 0.0f, true
196199
);
197200
game.controls.addPlayerActionType(
198201
PLAYER_ACTION_TYPE_UP,
199202
PLAYER_ACTION_CAT_MAIN,
200203
"Move up",
201204
"Move the leader up.",
202-
"move_up", "k_23", Inpution::ACTION_VALUE_TYPE_ANALOG
205+
"move_up", "k_23", Inpution::ACTION_VALUE_TYPE_ANALOG,
206+
0.0f, 0.0f, true
203207
);
204208
game.controls.addPlayerActionType(
205209
PLAYER_ACTION_TYPE_LEADER_CURSOR_RIGHT,
206210
PLAYER_ACTION_CAT_MAIN,
207211
"Leader cursor right",
208212
"Move the leader's cursor right.",
209-
"cursor_right", "", Inpution::ACTION_VALUE_TYPE_ANALOG
213+
"cursor_right", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
214+
0.0f, 0.0f, true
210215
);
211216
game.controls.addPlayerActionType(
212217
PLAYER_ACTION_TYPE_LEADER_CURSOR_DOWN,
213218
PLAYER_ACTION_CAT_MAIN,
214219
"Leader cursor down",
215220
"Move the leader's cursor down.",
216-
"cursor_down", "", Inpution::ACTION_VALUE_TYPE_ANALOG
221+
"cursor_down", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
222+
0.0f, 0.0f, true
217223
);
218224
game.controls.addPlayerActionType(
219225
PLAYER_ACTION_TYPE_LEADER_CURSOR_LEFT,
220226
PLAYER_ACTION_CAT_MAIN,
221227
"Leader cursor left",
222228
"Move the leader's cursor left.",
223-
"cursor_left", "", Inpution::ACTION_VALUE_TYPE_ANALOG
229+
"cursor_left", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
230+
0.0f, 0.0f, true
224231
);
225232
game.controls.addPlayerActionType(
226233
PLAYER_ACTION_TYPE_LEADER_CURSOR_UP,
227234
PLAYER_ACTION_CAT_MAIN,
228235
"Leader cursor up",
229236
"Move the leader's cursor up.",
230-
"cursor_up", "", Inpution::ACTION_VALUE_TYPE_ANALOG
237+
"cursor_up", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
238+
0.0f, 0.0f, true
231239
);
232240
game.controls.addPlayerActionType(
233241
PLAYER_ACTION_TYPE_THROW,
234242
PLAYER_ACTION_CAT_MAIN,
235243
"Throw",
236244
"Throw a Pikmin at the leader's cursor.",
237245
"throw", "mb_1", Inpution::ACTION_VALUE_TYPE_DIGITAL,
238-
0.0f, 0.2f
246+
0.0f, 0.2f, true
239247
);
240248
game.controls.addPlayerActionType(
241249
PLAYER_ACTION_TYPE_WHISTLE,
242250
PLAYER_ACTION_CAT_MAIN,
243251
"Whistle",
244252
"Whistle around the leader's cursor.",
245-
"whistle", "mb_2", Inpution::ACTION_VALUE_TYPE_DIGITAL
253+
"whistle", "mb_2", Inpution::ACTION_VALUE_TYPE_DIGITAL,
254+
0.0f, 0.0f, true
246255
);
247256
game.controls.addPlayerActionType(
248257
PLAYER_ACTION_TYPE_NEXT_TYPE,
249258
PLAYER_ACTION_CAT_MAIN,
250259
"Next Pikmin",
251260
"Change to the next Pikmin type in the group.",
252-
"next_type", "mwd", Inpution::ACTION_VALUE_TYPE_DIGITAL
261+
"next_type", "mwd", Inpution::ACTION_VALUE_TYPE_DIGITAL,
262+
0.0f, 0.0f, true
253263
);
254264
game.controls.addPlayerActionType(
255265
PLAYER_ACTION_TYPE_PREV_TYPE,
256266
PLAYER_ACTION_CAT_MAIN,
257267
"Prev. Pikmin",
258268
"Change to the previous Pikmin type in the group.",
259-
"prev_type", "mwu", Inpution::ACTION_VALUE_TYPE_DIGITAL
269+
"prev_type", "mwu", Inpution::ACTION_VALUE_TYPE_DIGITAL,
270+
0.0f, 0.0f, true
260271
);
261272
game.controls.addPlayerActionType(
262273
PLAYER_ACTION_TYPE_NEXT_LEADER,
263274
PLAYER_ACTION_CAT_MAIN,
264275
"Next leader",
265276
"Change to the next leader.",
266-
"next_leader", "k_215", Inpution::ACTION_VALUE_TYPE_DIGITAL
277+
"next_leader", "k_215", Inpution::ACTION_VALUE_TYPE_DIGITAL,
278+
0.0f, 0.0f, true
267279
);
268280
game.controls.addPlayerActionType(
269281
PLAYER_ACTION_TYPE_GROUP_CURSOR,
270282
PLAYER_ACTION_CAT_MAIN,
271283
"Swarm to cursor",
272284
"Swarm all Pikmin towards the leader's cursor.",
273-
"swarm_cursor", "k_75", Inpution::ACTION_VALUE_TYPE_DIGITAL
285+
"swarm_cursor", "k_75", Inpution::ACTION_VALUE_TYPE_DIGITAL,
286+
0.0f, 0.0f, true
274287
);
275288
game.controls.addPlayerActionType(
276289
PLAYER_ACTION_TYPE_DISMISS,
277290
PLAYER_ACTION_CAT_MAIN,
278291
"Dismiss",
279292
"Dismiss all Pikmin.",
280-
"dismiss", "k_217", Inpution::ACTION_VALUE_TYPE_DIGITAL
293+
"dismiss", "k_217", Inpution::ACTION_VALUE_TYPE_DIGITAL,
294+
0.0f, 0.0f, true
281295
);
282296
game.controls.addPlayerActionType(
283297
PLAYER_ACTION_TYPE_INVENTORY,
@@ -393,119 +407,136 @@ void initControls() {
393407
PLAYER_ACTION_CAT_ADVANCED,
394408
"Swarm right",
395409
"Swarm all Pikmin right.",
396-
"swarm_right", "", Inpution::ACTION_VALUE_TYPE_ANALOG
410+
"swarm_right", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
411+
0.0f, 0.0f, true
397412
);
398413
game.controls.addPlayerActionType(
399414
PLAYER_ACTION_TYPE_GROUP_DOWN,
400415
PLAYER_ACTION_CAT_ADVANCED,
401416
"Swarm down",
402417
"Swarm all Pikmin down.",
403-
"swarm_down", "", Inpution::ACTION_VALUE_TYPE_ANALOG
418+
"swarm_down", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
419+
0.0f, 0.0f, true
404420
);
405421
game.controls.addPlayerActionType(
406422
PLAYER_ACTION_TYPE_GROUP_LEFT,
407423
PLAYER_ACTION_CAT_ADVANCED,
408424
"Swarm left",
409425
"Swarm all Pikmin left.",
410-
"swarm_left", "", Inpution::ACTION_VALUE_TYPE_ANALOG
426+
"swarm_left", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
427+
0.0f, 0.0f, true
411428
);
412429
game.controls.addPlayerActionType(
413430
PLAYER_ACTION_TYPE_GROUP_UP,
414431
PLAYER_ACTION_CAT_ADVANCED,
415432
"Swarm up",
416433
"Swarm all Pikmin up.",
417-
"swarm_up", "", Inpution::ACTION_VALUE_TYPE_ANALOG
434+
"swarm_up", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
435+
0.0f, 0.0f, true
418436
);
419437
game.controls.addPlayerActionType(
420438
PLAYER_ACTION_TYPE_PREV_LEADER,
421439
PLAYER_ACTION_CAT_ADVANCED,
422440
"Prev. leader",
423441
"Change to the previous leader.",
424-
"prev_leader", "", Inpution::ACTION_VALUE_TYPE_DIGITAL
442+
"prev_leader", "", Inpution::ACTION_VALUE_TYPE_DIGITAL,
443+
0.0f, 0.0f, true
425444
);
426445
game.controls.addPlayerActionType(
427446
PLAYER_ACTION_TYPE_CHANGE_ZOOM,
428447
PLAYER_ACTION_CAT_ADVANCED,
429448
"Change zoom",
430449
"Change the current zoom level.",
431-
"change_zoom", "k_3", Inpution::ACTION_VALUE_TYPE_DIGITAL
450+
"change_zoom", "k_3", Inpution::ACTION_VALUE_TYPE_DIGITAL,
451+
0.0f, 0.0f, true
432452
);
433453
game.controls.addPlayerActionType(
434454
PLAYER_ACTION_TYPE_ZOOM_IN,
435455
PLAYER_ACTION_CAT_ADVANCED,
436456
"Zoom in",
437457
"Change to a closer zoom level.",
438-
"zoom_in", "", Inpution::ACTION_VALUE_TYPE_DIGITAL
458+
"zoom_in", "", Inpution::ACTION_VALUE_TYPE_DIGITAL,
459+
0.0f, 0.0f, true
439460
);
440461
game.controls.addPlayerActionType(
441462
PLAYER_ACTION_TYPE_ZOOM_OUT,
442463
PLAYER_ACTION_CAT_ADVANCED,
443464
"Zoom out",
444465
"Change to a farther zoom level.",
445-
"zoom_out", "", Inpution::ACTION_VALUE_TYPE_DIGITAL
466+
"zoom_out", "", Inpution::ACTION_VALUE_TYPE_DIGITAL,
467+
0.0f, 0.0f, true
446468
);
447469
game.controls.addPlayerActionType(
448470
PLAYER_ACTION_TYPE_NEXT_MATURITY,
449471
PLAYER_ACTION_CAT_ADVANCED,
450472
"Next maturity",
451473
"Change to a Pikmin of the next maturity.",
452-
"next_maturity", "", Inpution::ACTION_VALUE_TYPE_DIGITAL
474+
"next_maturity", "", Inpution::ACTION_VALUE_TYPE_DIGITAL,
475+
0.0f, 0.0f, true
453476
);
454477
game.controls.addPlayerActionType(
455478
PLAYER_ACTION_TYPE_PREV_MATURITY,
456479
PLAYER_ACTION_CAT_ADVANCED,
457480
"Prev. maturity",
458481
"Change to a Pikmin of the previous maturity.",
459-
"prev_maturity", "", Inpution::ACTION_VALUE_TYPE_DIGITAL
482+
"prev_maturity", "", Inpution::ACTION_VALUE_TYPE_DIGITAL,
483+
0.0f, 0.0f, true
460484
);
461485
game.controls.addPlayerActionType(
462486
PLAYER_ACTION_TYPE_INVENTORY_SHORTCUT_A,
463487
PLAYER_ACTION_CAT_ADVANCED,
464488
"Inventory shortcut A",
465489
"Use the inventory item set to shortcut A.",
466-
"inventory_shortcut_a", "", Inpution::ACTION_VALUE_TYPE_DIGITAL
490+
"inventory_shortcut_a", "", Inpution::ACTION_VALUE_TYPE_DIGITAL,
491+
0.0f, 0.0f, true
467492
);
468493
game.controls.addPlayerActionType(
469494
PLAYER_ACTION_TYPE_INVENTORY_SHORTCUT_B,
470495
PLAYER_ACTION_CAT_ADVANCED,
471496
"Inventory shortcut B",
472497
"Use the inventory item set to shortcut B.",
473-
"inventory_shortcut_b", "", Inpution::ACTION_VALUE_TYPE_DIGITAL
498+
"inventory_shortcut_b", "", Inpution::ACTION_VALUE_TYPE_DIGITAL,
499+
0.0f, 0.0f, true
474500
);
475501
game.controls.addPlayerActionType(
476502
PLAYER_ACTION_TYPE_INVENTORY_SHORTCUT_C,
477503
PLAYER_ACTION_CAT_ADVANCED,
478504
"Inventory shortcut C",
479505
"Use the inventory item set to shortcut C.",
480-
"inventory_shortcut_c", "", Inpution::ACTION_VALUE_TYPE_DIGITAL
506+
"inventory_shortcut_c", "", Inpution::ACTION_VALUE_TYPE_DIGITAL,
507+
0.0f, 0.0f, true
481508
);
482509
game.controls.addPlayerActionType(
483510
PLAYER_ACTION_TYPE_INVENTORY_SHORTCUT_D,
484511
PLAYER_ACTION_CAT_ADVANCED,
485512
"Inventory shortcut D",
486513
"Use the inventory item set to shortcut D.",
487-
"inventory_shortcut_d", "", Inpution::ACTION_VALUE_TYPE_DIGITAL
514+
"inventory_shortcut_d", "", Inpution::ACTION_VALUE_TYPE_DIGITAL,
515+
0.0f, 0.0f, true
488516
);
489517
game.controls.addPlayerActionType(
490518
PLAYER_ACTION_TYPE_CUSTOM_A,
491519
PLAYER_ACTION_CAT_ADVANCED,
492520
"Custom A",
493521
"Custom action A, if the current leader supports it.",
494-
"custom_a", "", Inpution::ACTION_VALUE_TYPE_ANALOG
522+
"custom_a", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
523+
0.0f, 0.0f, true
495524
);
496525
game.controls.addPlayerActionType(
497526
PLAYER_ACTION_TYPE_CUSTOM_B,
498527
PLAYER_ACTION_CAT_ADVANCED,
499528
"Custom B",
500529
"Custom action B, if the current leader supports it.",
501-
"custom_b", "", Inpution::ACTION_VALUE_TYPE_ANALOG
530+
"custom_b", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
531+
0.0f, 0.0f, true
502532
);
503533
game.controls.addPlayerActionType(
504534
PLAYER_ACTION_TYPE_CUSTOM_C,
505535
PLAYER_ACTION_CAT_ADVANCED,
506536
"Custom C",
507537
"Custom action C, if the current leader supports it.",
508-
"custom_c", "", Inpution::ACTION_VALUE_TYPE_ANALOG
538+
"custom_c", "", Inpution::ACTION_VALUE_TYPE_ANALOG,
539+
0.0f, 0.0f, true
509540
);
510541
game.controls.addPlayerActionType(
511542
PLAYER_ACTION_TYPE_RADAR,

0 commit comments

Comments
 (0)