Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Menu/MainMenu.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: MainMenu 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
ObjectMainMenu *MainMenu;
12
13
void MainMenu_Update(void) {}
14
15
void MainMenu_LateUpdate(void) {}
16
17
void MainMenu_StaticUpdate(void)
18
{
19
EntityUIControl *control = MainMenu->menuControl;
20
21
if (control && control->active) {
22
EntityUIDiorama *diorama = MainMenu->diorama;
23
MainMenu->confirmPrompt->visible = ((int32)(control->shifter->shiftOffset.y & 0xFFFF0000)) > -0x700000;
24
EntityUIButton *button = control->buttons[control->lastButtonID];
25
26
if (button) {
27
switch (button->frameID) {
28
case 0: diorama->dioramaID = UIDIORAMA_MANIAMODE; break;
29
case 1: diorama->dioramaID = UIDIORAMA_TIMEATTACK; break;
30
case 2: diorama->dioramaID = UIDIORAMA_COMPETITION; break;
31
case 3: diorama->dioramaID = UIDIORAMA_OPTIONS; break;
32
case 4: diorama->dioramaID = UIDIORAMA_EXTRAS; break;
33
case 5: diorama->dioramaID = UIDIORAMA_ENCOREMODE; break;
34
case 6: diorama->dioramaID = UIDIORAMA_PLUSUPSELL; break;
35
case 7: diorama->dioramaID = UIDIORAMA_EXIT; break;
36
default: break;
37
}
38
39
if (button->disabled)
40
diorama->timer = 12;
41
}
42
}
43
}
44
45
void MainMenu_Draw(void) {}
46
47
void MainMenu_Create(void *data) {}
48
49
void MainMenu_StageLoad(void) {}
50
51
void MainMenu_Initialize(void)
52
{
53
String tag;
54
INIT_STRING(tag);
55
RSDK.SetString(&tag, "Main Menu");
56
57
foreach_all(UIControl, control)
58
{
59
if (RSDK.CompareStrings(&tag, &control->tag, false)) {
60
MainMenu->menuControl = control;
61
control->backPressCB = MainMenu_BackPressCB_ReturnToTitle;
62
}
63
}
64
65
EntityUIControl *menuControl = MainMenu->menuControl;
66
67
foreach_all(UIButtonPrompt, prompt)
68
{
69
if (UIControl_ContainsPos(menuControl, &prompt->position) && prompt->buttonID == 0)
70
MainMenu->confirmPrompt = prompt;
71
}
72
73
foreach_all(UIDiorama, diorama)
74
{
75
if (UIControl_ContainsPos(menuControl, &diorama->position)) {
76
MainMenu->diorama = diorama;
77
diorama->parent = menuControl;
78
}
79
}
80
81
#if MANIA_USE_PLUS
82
int32 button1Frame = 1; // Time Attack
83
int32 button2Frame = 2; // Competition
84
int32 button3Frame = 3; // Options
85
int32 button4Frame = 4; // Extras
86
int32 button5Frame = 6; // Buy Plus
87
88
bool32 button3StopMus = false; // Options button does NOT stop music
89
bool32 button5Transition = false; // Buy Plus Does NOT do a transition
90
91
if (API.CheckDLC(DLC_PLUS)) {
92
button1Frame = 5; // Encore Mode
93
button2Frame = 1; // Time Attack
94
button3Frame = 2; // Competition
95
button4Frame = 3; // Options
96
button5Frame = 4; // Extras
97
98
button3StopMus = true; // Competition button stops music
99
button5Transition = true; // Extras Does a transition
100
}
101
102
EntityUIButton *buttonManiaMode = menuControl->buttons[0];
103
buttonManiaMode->frameID = 0;
104
buttonManiaMode->transition = true;
105
buttonManiaMode->stopMusic = true;
106
107
EntityUIButton *buttonEncoreMode = menuControl->buttons[1];
108
buttonEncoreMode->frameID = button1Frame;
109
buttonEncoreMode->transition = true;
110
buttonEncoreMode->stopMusic = true;
111
112
EntityUIButton *buttonTimeAttack = menuControl->buttons[2];
113
buttonTimeAttack->frameID = button2Frame;
114
buttonTimeAttack->transition = true;
115
buttonTimeAttack->stopMusic = true;
116
117
EntityUIButton *buttonCompetition = menuControl->buttons[3];
118
buttonCompetition->frameID = button3Frame;
119
buttonCompetition->transition = true;
120
buttonCompetition->stopMusic = button3StopMus;
121
122
EntityUIButton *buttonOptions = menuControl->buttons[4];
123
buttonOptions->frameID = button4Frame;
124
buttonOptions->transition = true;
125
buttonOptions->stopMusic = false;
126
127
EntityUIButton *buttonExtras = menuControl->buttons[5];
128
buttonExtras->frameID = button5Frame;
129
buttonExtras->transition = button5Transition;
130
buttonExtras->stopMusic = false;
131
132
EntityUIButton *buttonExit = menuControl->buttons[6];
133
buttonExit->frameID = 7;
134
buttonExit->transition = false;
135
buttonExit->stopMusic = false;
136
#endif
137
}
138
139
bool32 MainMenu_BackPressCB_ReturnToTitle(void)
140
{
141
ManiaModeMenu_StartReturnToTitle();
142
143
return true;
144
}
145
146
void MainMenu_ExitGame(void) { API.ExitGame(); }
147
148
void MainMenu_ExitButton_ActionCB(void)
149
{
150
String msg;
151
Localization_GetString(&msg, STR_QUITWARNING);
152
153
UIDialog_CreateDialogYesNo(&msg, MainMenu_StartExitGame, StateMachine_None, true, true);
154
}
155
156
void MainMenu_StartExitGame(void)
157
{
158
if (UIControl_GetUIControl())
159
UIControl_GetUIControl()->state = StateMachine_None;
160
161
Music_FadeOut(0.02);
162
163
MenuSetup_StartTransition(MainMenu_ExitGame, 64);
164
}
165
166
void MainMenu_MenuButton_ActionCB(void)
167
{
168
RSDK_THIS(UIButton);
169
170
switch (self->frameID) {
171
case 0: // Mania Mode
172
if (API_GetNoSave()) {
173
UIControl_MatchMenuTag("No Save Mode");
174
}
175
else {
176
EntityUIControl *saveSelect = ManiaModeMenu->saveSelectMenu;
177
saveSelect->buttonID = 7;
178
#if MANIA_USE_PLUS
179
saveSelect->menuWasSetup = false;
180
ManiaModeMenu->saveSelLastButtonID = -1;
181
182
for (int32 i = 0; i < saveSelect->buttonCount; ++i) {
183
Entity *store = SceneInfo->entity;
184
SceneInfo->entity = (Entity *)saveSelect->buttons[i];
185
UISaveSlot_HandleSaveIconChange();
186
SceneInfo->entity = store;
187
}
188
#endif
189
UIControl_MatchMenuTag("Save Select");
190
}
191
break;
192
193
case 1: // Time Attack
194
if (API.CheckDLC(DLC_PLUS)) {
195
EntityUIControl *control = TimeAttackMenu->timeAttackControl;
196
control->buttonID = 0;
197
control->menuWasSetup = false;
198
UIControl_MatchMenuTag("Time Attack");
199
}
200
else {
201
EntityUIControl *control = TimeAttackMenu->timeAttackControl_Legacy;
202
control->buttonID = 0;
203
control->menuWasSetup = false;
204
UIControl_MatchMenuTag("Time Attack Legacy");
205
}
206
break;
207
208
case 2: // Competition
209
if (API.CheckDLC(DLC_PLUS))
210
UIControl_MatchMenuTag("Competition");
211
else
212
UIControl_MatchMenuTag("Competition Legacy");
213
break;
214
215
case 3: // Options
216
UIControl_MatchMenuTag("Options");
217
break;
218
219
case 4: // Extras
220
UIControl_MatchMenuTag("Extras");
221
break;
222
223
case 5: // Encore
224
if (API_GetNoSave()) {
225
UIControl_MatchMenuTag("No Save Encore");
226
}
227
else {
228
EntityUIControl *encoreSaveSel = ManiaModeMenu->encoreSaveSelect;
229
encoreSaveSel->buttonID = 1;
230
encoreSaveSel->menuWasSetup = false;
231
for (int32 i = 0; i < encoreSaveSel->buttonCount; ++i) {
232
Entity *store = SceneInfo->entity;
233
SceneInfo->entity = (Entity *)encoreSaveSel->buttons[i];
234
UISaveSlot_HandleSaveIconChange();
235
SceneInfo->entity = store;
236
}
237
UIControl_MatchMenuTag("Encore Mode");
238
}
239
break;
240
241
case 6: // Buy Plus DLC
242
#if MANIA_USE_EGS
243
API.SetupExtensionOverlay();
244
245
if (!API.CheckDLC(DLC_PLUS)) {
246
if (!API.CanShowExtensionOverlay(0) || !API.ShowExtensionOverlay(0)) {
247
if (API.CanShowAltExtensionOverlay(0)) {
248
int32 connectingMessage = API.GetConnectingStringID();
249
if (connectingMessage >= 0) {
250
String message;
251
INIT_STRING(message);
252
Localization_GetString(&message, connectingMessage);
253
254
UIDialog_CreateDialogOkCancel(&message, MainMenu_BuyPlusDialogCB, StateMachine_None, true, true);
255
}
256
else {
257
API.ShowAltExtensionOverlay(0);
258
}
259
}
260
}
261
}
262
#else
263
API.ShowExtensionOverlay(0);
264
#endif
265
break;
266
267
default: break;
268
}
269
}
270
271
#if MANIA_USE_EGS
272
void MainMenu_BuyPlusDialogCB(void) { API.ShowAltExtensionOverlay(0); }
273
#endif
274
275
void MainMenu_HandleUnlocks(void)
276
{
277
EntityUIControl *control = MainMenu->menuControl;
278
279
EntityUIButton *taButton = API.CheckDLC(DLC_PLUS) ? control->buttons[2] : control->buttons[1];
280
taButton->disabled = !GameProgress_CheckUnlock(GAMEPROGRESS_UNLOCK_TIMEATTACK);
281
282
EntityUIButton *compButton = API.CheckDLC(DLC_PLUS) ? control->buttons[3] : control->buttons[2];
283
compButton->disabled = !GameProgress_CheckUnlock(GAMEPROGRESS_UNLOCK_COMPETITION);
284
}
285
286
void MainMenu_SetupActions(void)
287
{
288
foreach_all(UIButton, button)
289
{
290
if (button->listID == 1) {
291
if (button->frameID == 7) {
292
if (sku_platform != PLATFORM_PC && sku_platform != PLATFORM_DEV) {
293
EntityUIControl *control = MainMenu->menuControl;
294
295
// Remove "Exit" Button if not on PC or DEV platform
296
destroyEntity(button);
297
--control->buttonCount;
298
--control->rowCount;
299
control->buttons[6] = NULL;
300
}
301
else {
302
button->actionCB = MainMenu_ExitButton_ActionCB;
303
}
304
}
305
else {
306
button->actionCB = MainMenu_MenuButton_ActionCB;
307
}
308
}
309
}
310
311
MainMenu->menuControl->menuSetupCB = MainMenu_MenuSetupCB;
312
}
313
314
void MainMenu_MenuSetupCB(void) { MainMenu->diorama->lastDioramaID = -1; }
315
316
#if GAME_INCLUDE_EDITOR
317
void MainMenu_EditorDraw(void) {}
318
319
void MainMenu_EditorLoad(void) {}
320
#endif
321
322
void MainMenu_Serialize(void) {}
323
#endif
324
325