Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Menu/ManiaModeMenu.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: ManiaModeMenu Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
#if MANIA_USE_PLUS
11
ObjectManiaModeMenu *ManiaModeMenu;
12
13
void ManiaModeMenu_Update(void) {}
14
15
void ManiaModeMenu_LateUpdate(void) {}
16
17
void ManiaModeMenu_StaticUpdate(void) {}
18
19
void ManiaModeMenu_Draw(void) {}
20
21
void ManiaModeMenu_Create(void *data) {}
22
23
void ManiaModeMenu_StageLoad(void) {}
24
25
void ManiaModeMenu_Initialize(void)
26
{
27
LogHelpers_Print("ManiaModeMenu_Initialize()");
28
29
MainMenu_Initialize();
30
UISubHeading_Initialize();
31
TimeAttackMenu_Initialize();
32
CompetitionMenu_Initialize();
33
OptionsMenu_Initialize();
34
ExtrasMenu_Initialize();
35
36
ManiaModeMenu_HandleUnlocks();
37
ManiaModeMenu_SetupActions();
38
}
39
40
bool32 ManiaModeMenu_InitAPI(void)
41
{
42
if (!MenuSetup->initializedAPI)
43
MenuSetup->fxFade->timer = 512;
44
45
int32 authStatus = API.GetUserAuthStatus();
46
if (!authStatus) {
47
API.TryAuth();
48
}
49
else if (authStatus != STATUS_CONTINUE) {
50
int32 storageStatus = API.GetStorageStatus();
51
if (!storageStatus) {
52
API.TryInitStorage();
53
}
54
else if (storageStatus != STATUS_CONTINUE) {
55
int32 saveStatus = API.GetSaveStatus();
56
57
if (!API_GetNoSave() && (authStatus != STATUS_OK || storageStatus != STATUS_OK)) {
58
if (saveStatus != STATUS_CONTINUE) {
59
if (saveStatus != STATUS_FORBIDDEN) {
60
DialogRunner_PromptSavePreference(storageStatus);
61
}
62
else {
63
RSDK.SetScene("Presentation", "Title Screen");
64
RSDK.LoadScene();
65
}
66
}
67
68
return false;
69
}
70
71
if (!MenuSetup->initializedSaves) {
72
UIWaitSpinner_StartWait();
73
Options_LoadFile(Options_LoadCallback);
74
SaveGame_LoadFile(SaveGame_SaveLoadedCB);
75
ReplayDB_LoadDB(ReplayDB_LoadCallback);
76
77
MenuSetup->initializedSaves = true;
78
}
79
80
if (MenuSetup->initializedAPI)
81
return true;
82
83
if (globals->optionsLoaded == STATUS_OK && globals->saveLoaded == STATUS_OK && globals->replayTableLoaded == STATUS_OK
84
&& globals->taTableLoaded == STATUS_OK) {
85
86
if (!API_GetNoSave() && DialogRunner_NotifyAutosave())
87
return false;
88
89
UIWaitSpinner_FinishWait();
90
if (DialogRunner_CheckUnreadNotifs())
91
return false;
92
93
MenuSetup->initializedAPI = true;
94
return true;
95
}
96
97
if (API_GetNoSave()) {
98
UIWaitSpinner_FinishWait();
99
return true;
100
}
101
else {
102
if (globals->optionsLoaded == STATUS_ERROR || globals->saveLoaded == STATUS_ERROR || globals->replayTableLoaded == STATUS_ERROR
103
|| globals->taTableLoaded == STATUS_ERROR) {
104
int32 status = API.GetSaveStatus();
105
106
if (status != STATUS_CONTINUE) {
107
if (status == STATUS_FORBIDDEN) {
108
RSDK.SetScene("Presentation", "Title Screen");
109
RSDK.LoadScene();
110
}
111
else {
112
DialogRunner_PromptSavePreference(STATUS_CORRUPT);
113
}
114
}
115
}
116
}
117
}
118
}
119
120
return false;
121
}
122
123
void ManiaModeMenu_InitLocalization(bool32 success)
124
{
125
if (success) {
126
Localization->loaded = false;
127
128
Localization_LoadStrings();
129
UIWidgets_ApplyLanguage();
130
UIHeading_LoadSprites();
131
}
132
}
133
134
int32 ManiaModeMenu_GetActiveMenu(void)
135
{
136
EntityUIControl *control = UIControl_GetUIControl();
137
138
if (control == MainMenu->menuControl || control == ExtrasMenu->extrasControl || control == OptionsMenu->optionsControl
139
|| control == OptionsMenu->videoControl || control == OptionsMenu->soundControl || control == OptionsMenu->dataOptionsControl
140
|| control == OptionsMenu->controlsControl_Windows || control == OptionsMenu->controlsControl_KB
141
|| control == OptionsMenu->controlsControl_PS4 || control == OptionsMenu->controlsControl_XB1 || control == OptionsMenu->controlsControl_NX
142
|| control == OptionsMenu->controlsControl_NXGrip || control == OptionsMenu->controlsControl_NXJoycon
143
|| control == OptionsMenu->controlsControl_NXPro) {
144
return MAINMENU_MAIN;
145
}
146
147
if (control == TimeAttackMenu->timeAttackControl || control == TimeAttackMenu->timeAttackControl_Legacy
148
|| control == TimeAttackMenu->taZoneSelControl || control == TimeAttackMenu->taDetailsControl
149
|| control == TimeAttackMenu->leaderboardsControl || control == TimeAttackMenu->replaysControl
150
|| control == CompetitionMenu->competitionControl || control == CompetitionMenu->competitionControl_Legacy
151
|| control == CompetitionMenu->compRulesControl || control == CompetitionMenu->compZoneControl) {
152
return MAINMENU_TIMEATTACK;
153
}
154
155
if (control == CompetitionMenu->compRoundControl || control == CompetitionMenu->compTotalControl)
156
return MAINMENU_COMPETITION;
157
158
if (control == ManiaModeMenu->saveSelectMenu || control == ManiaModeMenu->noSaveMenu || control == ManiaModeMenu->secretsMenu)
159
return MAINMENU_SAVESELECT;
160
161
if (control == ManiaModeMenu->encoreSaveSelect || control == ManiaModeMenu->noSaveMenuEncore)
162
return MAINMENU_SAVESELECT_ENCORE;
163
164
return MAINMENU_MAIN;
165
}
166
167
void ManiaModeMenu_ChangeMenuTrack(void)
168
{
169
int32 trackID = 0;
170
171
switch (ManiaModeMenu_GetActiveMenu()) {
172
default:
173
case MAINMENU_MAIN: trackID = 0; break;
174
case MAINMENU_TIMEATTACK: trackID = 1; break;
175
case MAINMENU_COMPETITION: trackID = 2; break;
176
case MAINMENU_SAVESELECT: trackID = 3; break;
177
case MAINMENU_SAVESELECT_ENCORE: trackID = 4; break;
178
}
179
180
if (!Music_IsPlaying())
181
Music_PlayTrack(trackID);
182
else if (Music->activeTrack != trackID)
183
Music_TransitionTrack(trackID, 0.12);
184
}
185
186
void ManiaModeMenu_StartReturnToTitle(void)
187
{
188
EntityUIControl *control = UIControl_GetUIControl();
189
if (control)
190
control->state = StateMachine_None;
191
192
Music_FadeOut(0.05);
193
MenuSetup_StartTransition(ManiaModeMenu_ReturnToTitle, 32);
194
}
195
196
void ManiaModeMenu_SetBGColors(void)
197
{
198
switch (ManiaModeMenu_GetActiveMenu()) {
199
case MAINMENU_MAIN: UIBackground->activeColors = UIBackground->bgColors; break;
200
201
case MAINMENU_TIMEATTACK:
202
case MAINMENU_COMPETITION: UIBackground->activeColors = &UIBackground->bgColors[3]; break;
203
204
case MAINMENU_SAVESELECT: UIBackground->activeColors = &UIBackground->bgColors[6]; break;
205
206
case MAINMENU_SAVESELECT_ENCORE: UIBackground->activeColors = &UIBackground->bgColors[15]; break;
207
208
default: break;
209
}
210
}
211
212
void ManiaModeMenu_ReturnToTitle(void)
213
{
214
TimeAttackData_Clear();
215
216
RSDK.SetScene("Presentation", "Title Screen");
217
RSDK.LoadScene();
218
}
219
220
void ManiaModeMenu_State_HandleTransition(void)
221
{
222
RSDK_THIS(MenuSetup);
223
224
self->fadeTimer = CLAMP(self->timer << ((self->fadeShift & 0xFF) - 1), 0, 0x200);
225
}
226
227
void ManiaModeMenu_HandleUnlocks(void)
228
{
229
MainMenu_HandleUnlocks();
230
UISubHeading_HandleUnlocks();
231
TimeAttackMenu_HandleUnlocks();
232
233
int32 maxRounds = CompetitionMenu_HandleUnlocks();
234
EntityUIControl *compRules = CompetitionMenu->compRulesControl;
235
236
EntityUIVsRoundPicker *vsRoundPicker = (EntityUIVsRoundPicker *)UIButton_GetChoicePtr(compRules->buttons[1], compRules->buttons[1]->selection);
237
if (vsRoundPicker) {
238
vsRoundPicker->maxVal = maxRounds;
239
vsRoundPicker->val = MIN(vsRoundPicker->val, maxRounds);
240
}
241
242
OptionsMenu_HandleUnlocks();
243
ExtrasMenu_HandleUnlocks();
244
}
245
246
void ManiaModeMenu_SetupActions(void)
247
{
248
MainMenu_SetupActions();
249
UISubHeading_SetupActions();
250
TimeAttackMenu_SetupActions();
251
CompetitionMenu_SetupActions();
252
OptionsMenu_SetupActions();
253
ExtrasMenu_SetupActions();
254
}
255
256
void ManiaModeMenu_HandleMenuReturn(void)
257
{
258
EntityMenuParam *param = MenuParam_GetParam();
259
260
char buffer[0x100];
261
memset(buffer, 0, 0x100);
262
if (strcmp(param->menuTag, "") == 0)
263
UIUsernamePopup_ShowPopup();
264
265
foreach_all(UIControl, control)
266
{
267
if (strcmp(param->menuTag, "") != 0) {
268
RSDK.GetCString(buffer, &control->tag);
269
270
if (strcmp((const char *)buffer, param->menuTag) != 0) {
271
UIControl_SetInactiveMenu(control);
272
}
273
else {
274
control->storedButtonID = param->menuSelection;
275
control->hasStoredButton = true;
276
UIControl_SetActiveMenu(control);
277
control->buttonID = param->menuSelection;
278
}
279
}
280
}
281
282
UISubHeading_HandleMenuReturn(0);
283
TimeAttackMenu_HandleMenuReturn();
284
CompetitionMenu_HandleMenuReturn();
285
OptionsMenu_HandleMenuReturn();
286
287
if (param->puyoSelection == PUYO_SELECTION_VS_2P) {
288
EntityUIControl *extras = ExtrasMenu->extrasControl;
289
UIButton_SetChoiceSelection(extras->buttons[1], 1);
290
}
291
292
int32 zoneID = 0, actID = 0, characterID = 0, isEncoreMode = false;
293
bool32 inTimeAttack = param->inTimeAttack;
294
if (inTimeAttack) {
295
characterID = param->characterID;
296
zoneID = param->zoneID;
297
actID = param->actID;
298
isEncoreMode = param->isEncoreMode;
299
}
300
301
TimeAttackData_Clear();
302
303
if (inTimeAttack) {
304
param->characterID = characterID;
305
param->zoneID = zoneID;
306
param->actID = actID;
307
param->isEncoreMode = isEncoreMode;
308
}
309
}
310
311
#if GAME_INCLUDE_EDITOR
312
void ManiaModeMenu_EditorDraw(void) {}
313
314
void ManiaModeMenu_EditorLoad(void) {}
315
#endif
316
317
void ManiaModeMenu_Serialize(void) {}
318
#endif
319
320