Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Menu/DASetup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: DASetup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectDASetup *DASetup;
11
12
void DASetup_Update(void) {}
13
14
void DASetup_LateUpdate(void) {}
15
16
void DASetup_StaticUpdate(void)
17
{
18
if (!DASetup->initialized) {
19
DASetup_SetupUI();
20
DASetup->initialized = true;
21
}
22
23
EntityFXFade *fade = DASetup->fxFade;
24
if (DASetup->returnToMenu && fade->timer == 512) {
25
Music_FadeOut(0.02);
26
RSDK.SetScene("Presentation", "Menu");
27
RSDK.LoadScene();
28
}
29
30
EntityUIControl *control = DASetup->control;
31
if (!control->childHasFocus)
32
control->childHasFocus = true;
33
}
34
35
void DASetup_Draw(void) {}
36
37
void DASetup_Create(void *data) {}
38
39
void DASetup_StageLoad(void)
40
{
41
42
foreach_all(UIControl, control)
43
{
44
DASetup->control = control;
45
control->processButtonInputCB = DASetup_State_ManageControl;
46
}
47
48
foreach_all(FXFade, fade) { DASetup->fxFade = fade; }
49
50
foreach_all(UIInfoLabel, label)
51
{
52
if (DASetup->trackTitleLabel) {
53
if (!DASetup->trackSelLabel) {
54
DASetup->trackSelLabel = label;
55
foreach_break;
56
}
57
}
58
else {
59
DASetup->trackTitleLabel = label;
60
}
61
}
62
63
int32 trackCount = 0;
64
foreach_all(Music, track) { DASetup->trackList[trackCount++] = track; }
65
66
DASetup->trackCount = trackCount;
67
DASetup->activeTrack = TRACK_NONE;
68
69
DASetup->sfxEmerald = RSDK.GetSfx("Special/Emerald.wav");
70
DASetup->sfxMedal = RSDK.GetSfx("Special/Medal.wav");
71
DASetup->sfxSSExit = RSDK.GetSfx("Special/SSExit.wav");
72
DASetup->sfxScoreTotal = RSDK.GetSfx("Global/ScoreTotal.wav");
73
}
74
75
void DASetup_DisplayTrack(int32 trackID)
76
{
77
char buffer[0x10];
78
String text;
79
INIT_STRING(text);
80
81
EntityUIInfoLabel *trackTitleLabel = DASetup->trackTitleLabel;
82
EntityMusic *trackCountTrack = DASetup->trackList[trackID];
83
84
memset(buffer, 0, 0x10 * sizeof(char));
85
strcpy(&buffer[2], " - ");
86
buffer[0] = (trackID / 10) + '0';
87
buffer[1] = trackID - 10 * (trackID / 10) + '0';
88
RSDK.SetString(&text, buffer);
89
RSDK.AppendString(&text, &trackCountTrack->soundTestTitle);
90
UIInfoLabel_SetString(trackTitleLabel, &text);
91
}
92
93
bool32 DASetup_HandleMedallionDebug(void)
94
{
95
ProgressRAM *progress = GameProgress_GetProgressRAM();
96
97
if (globals->medallionDebug && progress) {
98
switch (DASetup->trackID) {
99
case 8: // Act Clear/1UP - unlock all zones
100
if (GameProgress_CheckZoneClear()) {
101
RSDK.PlaySfx(DASetup->sfxScoreTotal, false, 255);
102
return true;
103
}
104
break;
105
106
case 44: // Blue Spheres/ERZ Pinch Mode - unlock all medals (silver first if not all unlocked, if all unlocked then gold)
107
if (progress->silverMedalCount < 32) {
108
GameProgress_GiveMedal(globals->blueSpheresID, 1);
109
GameProgress_ShuffleBSSID();
110
RSDK.PlaySfx(DASetup->sfxMedal, false, 255);
111
return true;
112
}
113
else if (progress->goldMedalCount < 32) {
114
GameProgress_GiveMedal(globals->blueSpheresID, 2);
115
GameProgress_ShuffleBSSID();
116
RSDK.PlaySfx(DASetup->sfxMedal, false, 255);
117
return true;
118
}
119
break;
120
121
case 46: // Super/Blue Spheres - unlock all
122
if (!progress->allGoldMedals) {
123
GameProgress_UnlockAll();
124
GameProgress_LockAllSpecialClear();
125
RSDK.PlaySfx(DASetup->sfxEmerald, false, 255);
126
return true;
127
}
128
break;
129
130
case 48: // Game Over/Credits - reset progress
131
if (progress->silverMedalCount > 0 || progress->zoneCleared[0]) {
132
GameProgress_ClearProgress();
133
progress->allSpecialCleared = false;
134
RSDK.PlaySfx(DASetup->sfxSSExit, false, 255);
135
return true;
136
}
137
break;
138
139
default: break;
140
}
141
}
142
143
return false;
144
}
145
146
void DASetup_SetupUI(void)
147
{
148
String buffer;
149
INIT_STRING(buffer);
150
151
TitleBG_SetupFX();
152
DASetup_DisplayTrack(0);
153
EntityUIInfoLabel *trackSelLabel = DASetup->trackSelLabel;
154
Localization_GetString(&buffer, STR_SELECTATRACK);
155
#if MANIA_USE_PLUS
156
LogHelpers_PrintString(&buffer);
157
#endif
158
UIInfoLabel_SetString(trackSelLabel, &buffer);
159
}
160
161
void DASetup_State_ManageControl(void)
162
{
163
int32 prevTrack = DASetup->trackID;
164
if (UIControl->anyRightPress)
165
DASetup->trackID++;
166
else if (UIControl->anyLeftPress)
167
DASetup->trackID--;
168
else if (UIControl->anyUpPress)
169
DASetup->trackID += 10;
170
else if (UIControl->anyDownPress)
171
DASetup->trackID -= 10;
172
173
if (DASetup->trackID < 0)
174
DASetup->trackID += DASetup->trackCount;
175
if (DASetup->trackID >= DASetup->trackCount)
176
DASetup->trackID -= DASetup->trackCount;
177
178
if (prevTrack != DASetup->trackID) {
179
RSDK.PlaySfx(UIWidgets->sfxBleep, false, 255);
180
DASetup_DisplayTrack(DASetup->trackID);
181
}
182
183
if (UIControl->anyConfirmPress) {
184
if (DASetup->activeTrack == DASetup->trackID) {
185
Music_Stop();
186
DASetup->activeTrack = TRACK_NONE;
187
}
188
else {
189
EntityMusic *track = DASetup->trackList[DASetup->trackID];
190
if (!DASetup_HandleMedallionDebug()) {
191
if (track->trackFile.length) {
192
DASetup->activeTrack = DASetup->trackID;
193
Music_PlayTrackPtr(track);
194
}
195
else {
196
DASetup->activeTrack = TRACK_NONE;
197
Music_Stop();
198
}
199
}
200
}
201
}
202
203
if (!DASetup->returnToMenu && UIControl->anyBackPress) {
204
DASetup->returnToMenu = true;
205
206
EntityFXFade *fade = DASetup->fxFade;
207
fade->state = FXFade_State_FadeOut;
208
fade->timer = 0;
209
}
210
}
211
212
#if GAME_INCLUDE_EDITOR
213
void DASetup_EditorDraw(void) {}
214
215
void DASetup_EditorLoad(void) {}
216
#endif
217
218
void DASetup_Serialize(void) {}
219
220