Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Global/PauseMenu.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PauseMenu Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPauseMenu *PauseMenu;
11
12
void PauseMenu_Update(void)
13
{
14
RSDK_THIS(PauseMenu);
15
16
StateMachine_Run(self->state);
17
18
self->position.x = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;
19
self->position.y = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;
20
21
if (self->manager) {
22
self->manager->position.x = self->position.x;
23
self->manager->position.y = self->position.y;
24
PauseMenu_HandleButtonPositions();
25
}
26
}
27
28
void PauseMenu_LateUpdate(void)
29
{
30
RSDK_THIS(PauseMenu);
31
32
if (self->state) {
33
if (Music_IsPlaying())
34
Music_Pause();
35
}
36
else {
37
StateMachine(state) = RSDK_GET_ENTITY(self->triggerPlayer, Player)->state;
38
39
if (state == Player_State_Death || state == Player_State_Drown) {
40
destroyEntity(self);
41
}
42
else {
43
self->visible = true;
44
self->drawGroup = DRAWGROUP_COUNT - 1;
45
RSDK.SetEngineState(ENGINESTATE_FROZEN);
46
RSDK.SetSpriteAnimation(UIWidgets->textFrames, 10, &self->animator, true, 3);
47
PauseMenu_PauseSound();
48
#if !MANIA_USE_PLUS
49
PauseMenu_SetupTintTable();
50
#endif
51
self->state = PauseMenu_State_SetupButtons;
52
}
53
}
54
}
55
56
void PauseMenu_StaticUpdate(void)
57
{
58
if (SceneInfo->state == ENGINESTATE_REGULAR) {
59
int32 cnt = 0;
60
if (TitleCard)
61
cnt = RSDK.GetEntityCount(TitleCard->classID, true);
62
if (ActClear)
63
cnt += RSDK.GetEntityCount(ActClear->classID, true);
64
65
EntityPauseMenu *pauseMenu = RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
66
67
bool32 allowEvents = true;
68
if (Zone)
69
allowEvents = Zone->timer > 1;
70
71
if (!cnt && pauseMenu->classID == TYPE_BLANK && allowEvents && !PauseMenu->disableEvents) {
72
if (API_GetUserAuthStatus() == STATUS_FORBIDDEN) {
73
PauseMenu->signOutDetected = true;
74
RSDK.ResetEntitySlot(SLOT_PAUSEMENU, PauseMenu->classID, NULL);
75
pauseMenu->triggerPlayer = 0;
76
}
77
#if MANIA_USE_PLUS
78
else if (API.CheckDLC(DLC_PLUS) != (bool32)globals->lastHasPlus) {
79
PauseMenu->plusChanged = true;
80
globals->lastHasPlus = API.CheckDLC(DLC_PLUS);
81
RSDK.ResetEntitySlot(SLOT_PAUSEMENU, PauseMenu->classID, NULL);
82
pauseMenu->triggerPlayer = 0;
83
}
84
#endif
85
else {
86
for (int32 i = 0; i < PauseMenu_GetPlayerCount(); ++i) {
87
#if MANIA_USE_PLUS
88
int32 id = API_GetInputDeviceID(CONT_P1 + i);
89
if (!RSDK.IsInputDeviceAssigned(id) && id != INPUT_AUTOASSIGN) {
90
PauseMenu->controllerDisconnect = true;
91
RSDK.ResetEntitySlot(SLOT_PAUSEMENU, PauseMenu->classID, NULL);
92
pauseMenu->triggerPlayer = i;
93
}
94
#else
95
if (!API_IsInputSlotAssigned(CONT_P1 + i)) {
96
PauseMenu->controllerDisconnect = true;
97
RSDK.ResetEntitySlot(SLOT_PAUSEMENU, PauseMenu->classID, NULL);
98
pauseMenu->triggerPlayer = i;
99
}
100
#endif
101
}
102
}
103
}
104
}
105
}
106
107
void PauseMenu_Draw(void)
108
{
109
RSDK_THIS(PauseMenu);
110
111
if (self->paused)
112
RSDK.FillScreen(0x000000, self->fadeTimer, self->fadeTimer - 128, self->fadeTimer - 256);
113
114
if (RSDK.GetVideoSetting(VIDEOSETTING_SCREENCOUNT) <= 1) {
115
StateMachine_Run(self->stateDraw);
116
}
117
}
118
119
void PauseMenu_Create(void *data)
120
{
121
RSDK_THIS(PauseMenu);
122
123
if (!SceneInfo->inEditor) {
124
self->active = ACTIVE_ALWAYS;
125
126
if (data == INT_TO_VOID(true)) {
127
self->visible = true;
128
self->drawGroup = DRAWGROUP_COUNT - 1;
129
self->state = PauseMenu_State_HandleFadeout;
130
}
131
else {
132
self->state = StateMachine_None;
133
self->stateDraw = StateMachine_None;
134
}
135
}
136
}
137
138
void PauseMenu_StageLoad(void)
139
{
140
PauseMenu->active = ACTIVE_ALWAYS;
141
142
PauseMenu->sfxBleep = RSDK.GetSfx("Global/MenuBleep.wav");
143
PauseMenu->sfxAccept = RSDK.GetSfx("Global/MenuAccept.wav");
144
145
PauseMenu->disableEvents = false;
146
PauseMenu->controllerDisconnect = false;
147
PauseMenu->forcedDisconnect = false;
148
PauseMenu->signOutDetected = false;
149
#if MANIA_USE_PLUS
150
PauseMenu->plusChanged = false;
151
152
if (!globals->hasPlusInitial) {
153
globals->lastHasPlus = API.CheckDLC(DLC_PLUS);
154
globals->hasPlusInitial = true;
155
}
156
#endif
157
158
for (int32 i = 0; i < CHANNEL_COUNT; ++i) {
159
PauseMenu->activeChannels[i] = false;
160
}
161
162
#if MANIA_USE_PLUS
163
PauseMenu_SetupTintTable();
164
#endif
165
}
166
167
void PauseMenu_SetupMenu(void)
168
{
169
RSDK_THIS(PauseMenu);
170
171
Vector2 size;
172
size.x = ScreenInfo->size.x << 16;
173
size.y = ScreenInfo->size.y << 16;
174
RSDK.ResetEntitySlot(SLOT_PAUSEMENU_UICONTROL, UIControl->classID, &size);
175
176
EntityUIControl *control = RSDK_GET_ENTITY(SLOT_PAUSEMENU_UICONTROL, UIControl);
177
178
control->position.x = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;
179
control->position.y = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;
180
181
// Bug Details:
182
// control->rowCount is slightly bugged, if `pauseMenu->disableRestart` is enabled then wrapping by pressing down is broken and wont work
183
// this is due to rowCount being 3, while control->buttonCount is only 2
184
// Fix:
185
// set control->rowCount to control->buttonCount once it's been initialized, instead of using a constant value
186
control->rowCount = PAUSEMENU_BUTTON_COUNT;
187
control->columnCount = 1;
188
control->buttonID = 0;
189
self->manager = control;
190
191
int32 i = 0;
192
for (; i < PAUSEMENU_BUTTON_COUNT; ++i) {
193
if (!self->buttonPtrs[i])
194
break;
195
EntityUIButton *button = self->buttonPtrs[i];
196
button->parent = (Entity *)control;
197
control->buttons[i] = button;
198
}
199
control->buttonCount = i;
200
}
201
202
void PauseMenu_SetupTintTable(void)
203
{
204
#if MANIA_USE_PLUS
205
for (int32 i = 0; i < 0x10000; ++i) {
206
uint32 r = (0x20F * (i >> 11) + 23) >> 6;
207
uint32 g = (0x103 * ((i >> 5) & 0x3F) + 33) >> 6;
208
uint32 b = (0x20F * (i & 0x1F) + 23) >> 6;
209
210
int32 brightness = MIN(((b + g + r) << 8) / 680, 0xFF);
211
212
PauseMenu->tintLookupTable[i] = ColorHelpers_PackRGB(brightness, brightness, brightness);
213
}
214
#else
215
uint16 *tintLookupTable = RSDK.GetTintLookupTable();
216
for (int32 i = 0; i < 0x10000; ++i) {
217
uint32 r = (0x20F * (i >> 11) + 23) >> 6;
218
uint32 g = (0x103 * ((i >> 5) & 0x3F) + 33) >> 6;
219
uint32 b = (0x20F * (i & 0x1F) + 23) >> 7;
220
221
uint32 hue = 0, saturation = 0, luminance = 0;
222
ColorHelpers_RGBToHSL(r, g, b, &hue, &saturation, &luminance);
223
ColorHelpers_HSLToRGB(hue, 0, MIN(13 * luminance / 16, 255), &r, &g, &b);
224
225
tintLookupTable[i] = ColorHelpers_PackRGB(r, g, b);
226
}
227
#endif
228
}
229
230
void PauseMenu_AddButton(uint8 id, void *action)
231
{
232
RSDK_THIS(PauseMenu);
233
234
int32 buttonID = self->buttonCount;
235
if (buttonID < PAUSEMENU_BUTTON_COUNT) {
236
self->buttonIDs[buttonID] = id;
237
self->buttonActions[buttonID] = action;
238
239
int32 buttonSlot = self->buttonCount + 18;
240
RSDK.ResetEntitySlot(buttonSlot, UIButton->classID, NULL);
241
EntityUIButton *button = RSDK_GET_ENTITY(buttonSlot, UIButton);
242
243
button->position.x = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;
244
button->position.y = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;
245
RSDK.SetSpriteAnimation(UIWidgets->textFrames, 10, &button->animator, true, id);
246
button->actionCB = PauseMenu_ActionCB_Button;
247
button->size.x = 60 << 16;
248
button->size.y = 21 << 16;
249
button->bgEdgeSize = 21;
250
button->align = ALIGN_LEFT;
251
button->drawGroup = self->drawGroup;
252
button->active = ACTIVE_ALWAYS;
253
self->buttonPtrs[buttonID] = button;
254
++self->buttonCount;
255
}
256
}
257
258
void PauseMenu_ClearButtons(EntityPauseMenu *entity)
259
{
260
if (entity->manager)
261
destroyEntity(entity->manager);
262
263
for (int32 i = 0; i < PAUSEMENU_BUTTON_COUNT; ++i) {
264
if (entity->buttonPtrs[i])
265
destroyEntity(entity->buttonPtrs[i]);
266
}
267
268
destroyEntity(entity);
269
}
270
271
void PauseMenu_HandleButtonPositions(void)
272
{
273
RSDK_THIS(PauseMenu);
274
275
Vector2 pos;
276
pos.x = TO_FIXED(ScreenInfo->center.x - 69) + self->position.x + self->yellowTrianglePos.x;
277
pos.y = (self->position.y + TO_FIXED(56)) + self->yellowTrianglePos.y - TO_FIXED(36);
278
if (self->buttonCount == (PAUSEMENU_BUTTON_COUNT - 1)) {
279
pos.x -= TO_FIXED(36);
280
pos.y += TO_FIXED(36);
281
}
282
283
for (int32 i = 0; i < self->buttonCount; ++i) {
284
if (!self->buttonPtrs[i])
285
break;
286
287
EntityUIButton *button = self->buttonPtrs[i];
288
button->startPos.x = pos.x;
289
button->startPos.y = pos.y;
290
button->position.x = pos.x;
291
button->position.y = pos.y;
292
pos.x -= TO_FIXED(36);
293
pos.y += TO_FIXED(36);
294
}
295
}
296
297
void PauseMenu_PauseSound(void)
298
{
299
for (int32 i = 0; i < CHANNEL_COUNT; ++i) {
300
if (RSDK.ChannelActive(i)) {
301
RSDK.PauseChannel(i);
302
PauseMenu->activeChannels[i] = true;
303
}
304
}
305
}
306
307
void PauseMenu_ResumeSound(void)
308
{
309
for (int32 i = 0; i < CHANNEL_COUNT; ++i) {
310
if (PauseMenu->activeChannels[i]) {
311
RSDK.ResumeChannel(i);
312
PauseMenu->activeChannels[i] = false;
313
}
314
}
315
}
316
317
void PauseMenu_StopSound(void)
318
{
319
for (int32 i = 0; i < CHANNEL_COUNT; ++i) {
320
if (PauseMenu->activeChannels[i]) {
321
RSDK.StopChannel(i);
322
PauseMenu->activeChannels[i] = false;
323
}
324
}
325
}
326
327
void PauseMenu_FocusCamera(void)
328
{
329
RSDK_THIS(PauseMenu);
330
331
if (!Camera)
332
return;
333
334
LogHelpers_Print("FocusCamera(): triggerPlayer = %d", self->triggerPlayer);
335
foreach_all(Camera, cameraPtr)
336
{
337
int32 id = RSDK.GetEntitySlot(cameraPtr);
338
int32 prevScreen = cameraPtr->screenID;
339
if (id - SLOT_CAMERA1 == self->triggerPlayer) {
340
cameraPtr->screenID = 0;
341
Camera_SetCameraBounds(cameraPtr);
342
}
343
else {
344
cameraPtr->screenID = 1;
345
}
346
LogHelpers_Print("cameraPtr->screenID %d => %d", prevScreen, cameraPtr->screenID);
347
}
348
}
349
350
void PauseMenu_UpdateCameras(void)
351
{
352
if (!Camera)
353
return;
354
355
foreach_all(Camera, camera)
356
{
357
camera->screenID = RSDK.GetEntitySlot(camera) - SLOT_CAMERA1;
358
Camera_SetCameraBounds(camera);
359
}
360
}
361
362
void PauseMenu_CheckAndReassignControllers(void)
363
{
364
EntityPauseMenu *entity = RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
365
366
// prolly a leftover from pre-plus
367
int32 deviceID = API_GetInputDeviceID(CONT_P1 + (entity->triggerPlayer ^ 1));
368
369
#if MANIA_USE_PLUS
370
UNUSED(deviceID); // be quiet compiler I know it aint used!!
371
372
int32 id = API_GetFilteredInputDeviceID(true, true, 5);
373
#else
374
int32 id = API_GetFilteredInputDeviceID(deviceID);
375
#endif
376
377
if (id)
378
API_AssignInputSlotToDevice(CONT_P1 + entity->triggerPlayer, id);
379
else
380
API_AssignInputSlotToDevice(CONT_P1 + entity->triggerPlayer, INPUT_AUTOASSIGN);
381
382
if (globals->gameMode < MODE_TIMEATTACK && !API_GetInputDeviceID(CONT_P2))
383
API_AssignInputSlotToDevice(CONT_P2, INPUT_AUTOASSIGN);
384
385
PauseMenu->forcedDisconnect = true;
386
}
387
388
bool32 PauseMenu_IsDisconnected(void)
389
{
390
RSDK_THIS(PauseMenu);
391
392
int32 id = API_GetInputDeviceID(CONT_P1 + self->triggerPlayer);
393
394
#if MANIA_USE_PLUS
395
return API_IsInputDeviceAssigned(id) || PauseMenu->forcedDisconnect;
396
#else
397
return id != INPUT_NONE || PauseMenu->forcedDisconnect;
398
#endif
399
}
400
401
uint8 PauseMenu_GetPlayerCount(void)
402
{
403
EntityMenuParam *param = MenuParam_GetParam();
404
EntityCompetitionSession *session = CompetitionSession_GetSession();
405
406
if (RSDK.CheckSceneFolder("Puyo")) {
407
if (param->puyoSelection >= PUYO_SELECTION_VS_2P)
408
return 2;
409
}
410
else if (globals->gameMode == MODE_COMPETITION) {
411
return session->playerCount;
412
}
413
return 1;
414
}
415
416
void PauseMenu_ResumeButtonCB(void)
417
{
418
EntityPauseMenu *pauseMenu = RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
419
420
if (globals->gameMode != MODE_COMPETITION || RSDK.CheckSceneFolder("Puyo"))
421
pauseMenu->state = PauseMenu_State_Resume;
422
else
423
pauseMenu->state = PauseMenu_State_ResumeCompetition;
424
}
425
426
void PauseMenu_RestartButtonCB(void)
427
{
428
RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
429
430
String msg;
431
#if MANIA_USE_PLUS
432
int32 strID = STR_AREYOUSURE;
433
if (!ReplayRecorder || !ReplayRecorder->isReplaying)
434
strID = STR_RESTARTWARNING;
435
Localization_GetString(&msg, strID);
436
#else
437
Localization_GetString(&msg, STR_RESTARTWARNING);
438
#endif
439
440
UIDialog_CreateDialogYesNo(&msg, PauseMenu_RestartDialog_YesCB, NULL, false, true);
441
}
442
443
void PauseMenu_ExitButtonCB(void)
444
{
445
RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
446
447
String msg;
448
#if MANIA_USE_PLUS
449
int32 strID = STR_AREYOUSURE;
450
if (!ReplayRecorder || !ReplayRecorder->isReplaying)
451
strID = STR_QUITWARNINGLOSEPROGRESS;
452
Localization_GetString(&msg, strID);
453
#else
454
Localization_GetString(&msg, STR_QUITWARNINGLOSEPROGRESS);
455
#endif
456
457
UIDialog_CreateDialogYesNo(&msg, PauseMenu_ExitDialog_YesCB, NULL, false, true);
458
}
459
460
void PauseMenu_RestartDialog_YesCB(void)
461
{
462
RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
463
464
UIDialog->activeDialog->parent->state = NULL;
465
if (StarPost) {
466
StarPost->postIDs[0] = 0;
467
StarPost->postIDs[1] = 0;
468
StarPost->postIDs[2] = 0;
469
StarPost->postIDs[3] = 0;
470
}
471
Music_Stop();
472
473
int32 x = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;
474
int32 y = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;
475
EntityPauseMenu *fadeout = CREATE_ENTITY(PauseMenu, INT_TO_VOID(true), x, y);
476
fadeout->fadeoutCB = PauseMenu_RestartFadeCB;
477
fadeout->state = PauseMenu_State_HandleFadeout;
478
}
479
480
void PauseMenu_ExitDialog_YesCB(void)
481
{
482
RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
483
484
UIDialog->activeDialog->parent->state = NULL;
485
globals->recallEntities = false;
486
globals->initCoolBonus = false;
487
488
if (StarPost) {
489
StarPost->postIDs[0] = 0;
490
StarPost->postIDs[1] = 0;
491
StarPost->postIDs[2] = 0;
492
StarPost->postIDs[3] = 0;
493
}
494
Music_Stop();
495
496
int32 x = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;
497
int32 y = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;
498
EntityPauseMenu *fadeout = CREATE_ENTITY(PauseMenu, INT_TO_VOID(true), x, y);
499
fadeout->fadeoutCB = PauseMenu_ExitFadeCB;
500
fadeout->state = PauseMenu_State_HandleFadeout;
501
}
502
503
void PauseMenu_RestartFadeCB(void)
504
{
505
globals->specialRingID = 0;
506
PauseMenu_StopSound();
507
RSDK.LoadScene();
508
}
509
510
void PauseMenu_ExitFadeCB(void)
511
{
512
if (StarPost) {
513
StarPost->postIDs[0] = 0;
514
StarPost->postIDs[1] = 0;
515
StarPost->postIDs[2] = 0;
516
StarPost->postIDs[3] = 0;
517
}
518
globals->specialRingID = 0;
519
520
if (globals->gameMode == MODE_COMPETITION) {
521
EntityCompetitionSession *session = CompetitionSession_GetSession();
522
EntityMenuParam *param = MenuParam_GetParam();
523
524
sprintf_s(param->menuTag, (int32)sizeof(param->menuTag), "Competition Zones");
525
param->menuSelection = session->stageIndex;
526
}
527
528
RSDK.SetScene("Presentation", "Menu");
529
PauseMenu_StopSound();
530
RSDK.LoadScene();
531
}
532
533
void PauseMenu_ActionCB_Button(void)
534
{
535
EntityPauseMenu *pauseMenu = RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
536
EntityUIControl *manager = pauseMenu->manager;
537
538
if (manager->buttonID >= 0 && manager->buttonID < manager->buttonCount) {
539
StateMachine_Run(pauseMenu->buttonActions[manager->buttonID]);
540
}
541
}
542
543
void PauseMenu_State_SetupButtons(void)
544
{
545
RSDK_THIS(PauseMenu);
546
547
self->timer = 0;
548
PauseMenu->forcedDisconnect = false;
549
550
#if MANIA_USE_PLUS
551
if (PauseMenu->controllerDisconnect || PauseMenu->signOutDetected || PauseMenu->plusChanged) {
552
#else
553
if (PauseMenu->controllerDisconnect || PauseMenu->signOutDetected) {
554
#endif
555
if (PauseMenu->controllerDisconnect)
556
self->disconnectCheck = PauseMenu_IsDisconnected;
557
558
if (globals->gameMode != MODE_COMPETITION || RSDK.CheckSceneFolder("Puyo"))
559
self->state = PauseMenu_State_ForcedPause;
560
else
561
self->state = PauseMenu_State_ForcedPauseCompetition;
562
563
self->stateDraw = PauseMenu_Draw_ForcePause;
564
}
565
else {
566
RSDK.PlaySfx(PauseMenu->sfxAccept, false, 255);
567
568
PauseMenu_AddButton(0, PauseMenu_ResumeButtonCB);
569
570
if (!self->disableRestart)
571
PauseMenu_AddButton(1, PauseMenu_RestartButtonCB);
572
573
PauseMenu_AddButton(2, PauseMenu_ExitButtonCB);
574
575
PauseMenu_HandleButtonPositions();
576
PauseMenu_SetupMenu();
577
578
if (globals->gameMode != MODE_COMPETITION || RSDK.CheckSceneFolder("Puyo"))
579
self->state = PauseMenu_State_StartPause;
580
else
581
self->state = PauseMenu_State_StartPauseCompetition;
582
self->stateDraw = PauseMenu_Draw_RegularPause;
583
584
#if MANIA_USE_PLUS
585
if (globals->gameMode < MODE_TIMEATTACK && API_GetInputDeviceID(CONT_P2) == (uint32)INPUT_AUTOASSIGN)
586
API_AssignInputSlotToDevice(CONT_P2, INPUT_NONE);
587
#endif
588
}
589
590
StateMachine_Run(self->state);
591
}
592
593
void PauseMenu_State_StartPause(void)
594
{
595
RSDK_THIS(PauseMenu);
596
597
if (self->timer == 1) {
598
UIControl->inputLocked = false;
599
UIControl_SetMenuLostFocus(self->manager);
600
}
601
602
if (self->timer >= 8) {
603
self->headerPos.x = 0;
604
self->headerPos.y = 0;
605
self->yellowTrianglePos.x = 0;
606
self->yellowTrianglePos.y = 0;
607
self->timer = 0;
608
self->state = PauseMenu_State_Paused;
609
}
610
else {
611
Vector2 pos;
612
613
int32 alpha = 32 * self->timer;
614
MathHelpers_Lerp2Sin1024(&pos, MAX(0, alpha), -TO_FIXED(240), 0, 0, 0);
615
616
self->headerPos.x = pos.x;
617
self->headerPos.y = pos.y;
618
MathHelpers_Lerp2Sin1024(&pos, MAX(0, alpha), TO_FIXED(232), 0, 0, 0);
619
620
++self->timer;
621
self->yellowTrianglePos.x = pos.x;
622
self->yellowTrianglePos.y = pos.y;
623
self->tintAlpha = alpha;
624
}
625
}
626
627
void PauseMenu_State_StartPauseCompetition(void)
628
{
629
RSDK_THIS(PauseMenu);
630
631
if (self->timer == 1) {
632
UIControl->inputLocked = false;
633
UIControl_SetMenuLostFocus(self->manager);
634
}
635
636
if (self->timer >= 8) {
637
self->headerPos.x = TO_FIXED(0);
638
self->headerPos.y = TO_FIXED(0);
639
self->yellowTrianglePos.x = TO_FIXED(0);
640
self->yellowTrianglePos.y = TO_FIXED(0);
641
if (self->timer >= 16) {
642
self->paused = false;
643
self->timer = 0;
644
self->state = PauseMenu_State_Paused;
645
}
646
else {
647
int32 t = self->timer - 8;
648
self->paused = true;
649
if (self->timer == 8) {
650
RSDK.SetVideoSetting(VIDEOSETTING_SCREENCOUNT, 1);
651
PauseMenu_FocusCamera();
652
}
653
++self->timer;
654
self->fadeTimer = (8 - t) << 6;
655
}
656
}
657
else {
658
self->headerPos.x = TO_FIXED(0xFFF);
659
self->headerPos.y = TO_FIXED(0xFFF);
660
self->yellowTrianglePos.x = TO_FIXED(0xFFF);
661
self->yellowTrianglePos.y = TO_FIXED(0xFFF);
662
self->paused = true;
663
self->fadeTimer = self->timer << 6;
664
self->timer = self->timer + 1;
665
}
666
}
667
668
void PauseMenu_State_Paused(void)
669
{
670
RSDK_THIS(PauseMenu);
671
672
self->tintAlpha = 0xFF;
673
self->headerPos.x = 0;
674
self->headerPos.y = 0;
675
self->yellowTrianglePos.x = 0;
676
self->yellowTrianglePos.y = 0;
677
678
EntityUIControl *manager = self->manager;
679
if (Unknown_pausePress && !manager->dialogHasFocus) {
680
EntityPauseMenu *pauseMenu = RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
681
if (globals->gameMode != MODE_COMPETITION || RSDK.CheckSceneFolder("Puyo"))
682
pauseMenu->state = PauseMenu_State_Resume;
683
else
684
pauseMenu->state = PauseMenu_State_ResumeCompetition;
685
}
686
}
687
688
void PauseMenu_State_ForcedPause(void)
689
{
690
RSDK_THIS(PauseMenu);
691
String textBuffer;
692
693
if (self->timer == 1) {
694
UIControl->inputLocked = false;
695
if (PauseMenu->controllerDisconnect) {
696
int32 strID = STR_RECONNECTWIRELESSCONTROLLER;
697
if (sku_platform == PLATFORM_SWITCH)
698
strID = STR_RECONNECTCONTROLLER;
699
Localization_GetString(&textBuffer, strID);
700
701
EntityUIDialog *dialog = UIDialog_CreateActiveDialog(&textBuffer);
702
UIDialog_AddButton(DIALOG_CONTINUE, dialog, PauseMenu_CheckAndReassignControllers, 0);
703
UIDialog_Setup(dialog);
704
705
if (globals->gameMode < MODE_TIMEATTACK && API_GetInputDeviceID(2) == (uint32)INPUT_AUTOASSIGN)
706
API_AssignInputSlotToDevice(CONT_P2, INPUT_NONE);
707
}
708
#if MANIA_USE_PLUS
709
else if (PauseMenu->signOutDetected || PauseMenu->plusChanged) {
710
int32 strID = STR_TESTSTR;
711
if (PauseMenu->signOutDetected)
712
strID = STR_SIGNOUTDETECTED;
713
else if (PauseMenu->plusChanged)
714
strID = STR_RETRURNINGTOTITLE;
715
716
Localization_GetString(&textBuffer, strID);
717
718
EntityUIDialog *dialog = UIDialog_CreateActiveDialog(&textBuffer);
719
UIDialog_AddButton(DIALOG_OK, dialog, PauseMenu_State_SetupTitleFade, 1);
720
UIDialog_Setup(dialog);
721
}
722
#else
723
else if (PauseMenu->signOutDetected) {
724
Localization_GetString(&textBuffer, STR_SIGNOUTDETECTED);
725
726
EntityUIDialog *dialog = UIDialog_CreateActiveDialog(&textBuffer);
727
UIDialog_AddButton(DIALOG_OK, dialog, PauseMenu_State_SetupTitleFade, 1);
728
UIDialog_Setup(dialog);
729
}
730
#endif
731
}
732
733
++self->timer;
734
if (!UIDialog->activeDialog) {
735
if (self->forcePaused) {
736
if (globals->gameMode != MODE_COMPETITION || RSDK.CheckSceneFolder("Puyo")) {
737
RSDK.SetEngineState(ENGINESTATE_REGULAR);
738
PauseMenu_ClearButtons(RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu));
739
PauseMenu_ResumeSound();
740
}
741
else {
742
self->timer = 0;
743
self->state = PauseMenu_State_ForcedResumeCompetition;
744
}
745
}
746
}
747
748
if (!self->forcePaused && self->disconnectCheck) {
749
if (self->disconnectCheck()) {
750
if (PauseMenu->controllerDisconnect)
751
PauseMenu->controllerDisconnect = false;
752
753
EntityUIDialog *dialog = UIDialog->activeDialog;
754
if (dialog)
755
UIDialog_CloseOnSel_HandleSelection(dialog, StateMachine_None);
756
757
self->forcePaused = true;
758
}
759
}
760
}
761
762
void PauseMenu_State_ForcedPauseCompetition(void)
763
{
764
RSDK_THIS(PauseMenu);
765
766
if (self->timer == 1)
767
UIControl->inputLocked = 0;
768
769
if (self->timer >= 8) {
770
if (self->timer >= 16) {
771
self->paused = false;
772
self->fadeTimer = 0;
773
self->timer = 0;
774
self->state = PauseMenu_State_ForcedPause;
775
}
776
else {
777
int32 t = self->timer - 8;
778
self->paused = true;
779
780
if (self->timer == 8) {
781
RSDK.SetVideoSetting(VIDEOSETTING_SCREENCOUNT, 1);
782
PauseMenu_FocusCamera();
783
}
784
785
++self->timer;
786
self->fadeTimer = (8 - t) << 6;
787
}
788
}
789
else {
790
self->paused = true;
791
self->fadeTimer = self->timer << 6;
792
self->timer++;
793
}
794
}
795
796
void PauseMenu_State_Resume(void)
797
{
798
RSDK_THIS(PauseMenu);
799
800
if (!self->timer && globals->gameMode < MODE_TIMEATTACK && !API_GetInputDeviceID(CONT_P2))
801
API_AssignInputSlotToDevice(CONT_P2, INPUT_AUTOASSIGN);
802
803
if (self->timer >= 8) {
804
self->headerPos.x = -TO_FIXED(240);
805
self->headerPos.y = 0;
806
self->yellowTrianglePos.x = TO_FIXED(232);
807
self->yellowTrianglePos.y = 0;
808
self->timer = 0;
809
RSDK.SetEngineState(ENGINESTATE_REGULAR);
810
PauseMenu_ClearButtons(RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu));
811
PauseMenu_ResumeSound();
812
}
813
else {
814
Vector2 pos;
815
816
int32 percent = 0x20 * self->timer;
817
MathHelpers_Lerp2Sin1024(&pos, MAX(0, percent), 0, 0, -TO_FIXED(240), 0);
818
819
self->headerPos.x = pos.x;
820
self->headerPos.y = pos.y;
821
MathHelpers_Lerp2Sin1024(&pos, MAX(0, percent), 0, 0, TO_FIXED(232), 0);
822
823
self->yellowTrianglePos.x = pos.x;
824
self->yellowTrianglePos.y = pos.y;
825
self->tintAlpha = ((0x100 - self->timer) << 8) / 8;
826
++self->timer;
827
}
828
}
829
830
void PauseMenu_State_ResumeCompetition(void)
831
{
832
RSDK_THIS(PauseMenu);
833
834
if (self->timer == 1) {
835
UIControl->inputLocked = 0;
836
UIControl_SetMenuLostFocus(self->manager);
837
}
838
839
if (self->timer >= 8) {
840
if (self->timer >= 16) {
841
self->paused = false;
842
self->timer = 0;
843
RSDK.SetEngineState(ENGINESTATE_REGULAR);
844
PauseMenu_ClearButtons(RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu));
845
PauseMenu_ResumeSound();
846
}
847
else {
848
int32 t = self->timer - 8;
849
850
if (self->timer == 8) {
851
EntityCompetitionSession *session = CompetitionSession_GetSession();
852
RSDK.SetVideoSetting(VIDEOSETTING_SCREENCOUNT, session->playerCount);
853
PauseMenu_UpdateCameras();
854
}
855
856
++self->timer;
857
self->fadeTimer = (8 - t) << 6;
858
}
859
}
860
else {
861
self->headerPos.x = 0;
862
self->headerPos.y = 0;
863
self->yellowTrianglePos.x = 0;
864
self->yellowTrianglePos.y = 0;
865
self->paused = true;
866
self->fadeTimer = self->timer << 6;
867
self->timer = self->timer + 1;
868
}
869
}
870
871
void PauseMenu_State_ForcedResumeCompetition(void)
872
{
873
RSDK_THIS(PauseMenu);
874
875
if (self->timer >= 8) {
876
if (self->timer >= 16) {
877
self->paused = false;
878
self->timer = 0;
879
RSDK.SetEngineState(ENGINESTATE_REGULAR);
880
PauseMenu_ClearButtons(RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu));
881
PauseMenu_ResumeSound();
882
}
883
else {
884
int32 t = self->timer - 8;
885
self->paused = true;
886
887
if (self->timer == 8) {
888
EntityCompetitionSession *session = CompetitionSession_GetSession();
889
RSDK.SetVideoSetting(VIDEOSETTING_SCREENCOUNT, session->playerCount);
890
PauseMenu_UpdateCameras();
891
}
892
893
++self->timer;
894
self->fadeTimer = (8 - t) << 6;
895
}
896
}
897
else {
898
self->paused = true;
899
self->fadeTimer = self->timer << 6;
900
self->timer++;
901
}
902
}
903
904
void PauseMenu_State_SetupTitleFade(void)
905
{
906
EntityPauseMenu *pauseMenu = RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
907
pauseMenu->timer = 0;
908
pauseMenu->fadeTimer = 0;
909
pauseMenu->state = PauseMenu_State_FadeToTitle;
910
}
911
912
void PauseMenu_State_FadeToTitle(void)
913
{
914
RSDK_THIS(PauseMenu);
915
916
if (!UIDialog->activeDialog) {
917
if (!self->timer) {
918
self->paused = true;
919
Music_FadeOut(0.2);
920
}
921
922
if (self->timer >= 60) {
923
self->fadeTimer = 512;
924
SaveGame_ClearRestartData();
925
RSDK.SetScene("Presentation", "Title Screen");
926
RSDK.LoadScene();
927
}
928
else {
929
self->fadeTimer = (self->timer << 9) / 60;
930
self->timer++;
931
}
932
}
933
}
934
935
void PauseMenu_State_HandleFadeout(void)
936
{
937
RSDK_THIS(PauseMenu);
938
939
self->fadeTimer += 12;
940
self->paused = true;
941
942
if (self->fadeTimer >= 1024) {
943
StateMachine_Run(self->fadeoutCB);
944
}
945
}
946
947
void PauseMenu_DrawPauseMenu(void)
948
{
949
RSDK_THIS(PauseMenu);
950
951
Vector2 drawPos;
952
drawPos.x = self->position.x + TO_FIXED(100) + self->headerPos.x + -TO_FIXED(1) * ScreenInfo->center.x;
953
drawPos.y = self->position.y - TO_FIXED(96) + self->headerPos.y;
954
UIWidgets_DrawParallelogram(drawPos.x, drawPos.y, 200, 68, 68, 0xE8, 0x28, 0x58);
955
956
drawPos.x += TO_FIXED(10);
957
drawPos.y += TO_FIXED(6);
958
UIWidgets_DrawParallelogram(drawPos.x, drawPos.y, 115, 24, 24, 0x00, 0x00, 0x00);
959
960
// "PAUSED" text
961
RSDK.DrawSprite(&self->animator, &drawPos, false);
962
963
UIWidgets_DrawRightTriangle(self->yellowTrianglePos.x + TO_FIXED(ScreenInfo->center.x) + self->position.x,
964
self->yellowTrianglePos.y + TO_FIXED(ScreenInfo->center.y) + self->position.y, -232, 0xF0, 0xD8, 0x08);
965
}
966
967
void PauseMenu_Draw_RegularPause(void)
968
{
969
RSDK_THIS(PauseMenu);
970
971
if (self->state != PauseMenu_State_HandleFadeout) {
972
#if MANIA_USE_PLUS
973
RSDK.SetTintLookupTable(PauseMenu->tintLookupTable);
974
#endif
975
RSDK.DrawRect(0, 0, ScreenInfo->size.x, ScreenInfo->size.y, 0, self->tintAlpha, INK_TINT, true);
976
977
PauseMenu_DrawPauseMenu();
978
}
979
}
980
981
void PauseMenu_Draw_ForcePause(void)
982
{
983
RSDK_THIS(PauseMenu);
984
985
if (self->state != PauseMenu_State_HandleFadeout) {
986
#if MANIA_USE_PLUS
987
RSDK.SetTintLookupTable(PauseMenu->tintLookupTable);
988
#endif
989
RSDK.DrawRect(0, 0, ScreenInfo->size.x, ScreenInfo->size.y, 0, self->tintAlpha, INK_TINT, true);
990
}
991
}
992
993
#if GAME_INCLUDE_EDITOR
994
void PauseMenu_EditorDraw(void) {}
995
996
void PauseMenu_EditorLoad(void) {}
997
#endif
998
999
void PauseMenu_Serialize(void) {}
1000
1001