Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Menu/UICreditsText.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: UICreditsText Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectUICreditsText *UICreditsText;
11
12
void UICreditsText_Update(void)
13
{
14
RSDK_THIS(UICreditsText);
15
16
StateMachine_Run(self->state);
17
}
18
19
void UICreditsText_LateUpdate(void) {}
20
21
void UICreditsText_StaticUpdate(void) {}
22
23
void UICreditsText_Draw(void)
24
{
25
RSDK_THIS(UICreditsText);
26
27
Vector2 drawPos;
28
int32 width = RSDK.GetStringWidth(UICreditsText->aniFrames, self->listID, &self->text, 0, self->text.length, 0);
29
30
drawPos.x = self->position.x;
31
drawPos.y = self->position.y + 0x40000;
32
if (self->hasShape)
33
UIWidgets_DrawParallelogram(drawPos.x, drawPos.y, (self->scaleTimer * (width + 16)) >> 8, self->scaleTimer >> 4, 16, 0x00, 0x00, 0x00);
34
35
drawPos.x -= width << 15;
36
drawPos.y = self->position.y;
37
if (self->animator.animationID >= 7) {
38
RSDK.DrawSprite(&self->animator, 0, false);
39
}
40
else {
41
RSDK.SetClipBounds(SceneInfo->currentScreenID, 0, 0, ScreenInfo->size.x,
42
(self->position.y >> 16) + self->clipY2 - ScreenInfo[SceneInfo->currentScreenID].position.y);
43
44
RSDK.DrawText(&self->animator, &drawPos, &self->text, 0, 0, ALIGN_LEFT, 0, NULL, self->charPositions, false);
45
46
RSDK.SetClipBounds(SceneInfo->currentScreenID, 0, 0, ScreenInfo->size.x, ScreenInfo->size.y);
47
}
48
}
49
50
void UICreditsText_Create(void *data)
51
{
52
RSDK_THIS(UICreditsText);
53
54
RSDK.SetSpriteAnimation(UICreditsText->aniFrames, self->listID, &self->animator, true, 0);
55
56
if (!SceneInfo->inEditor) {
57
self->active = ACTIVE_BOUNDS;
58
self->updateRange.x = 0x800000;
59
self->updateRange.y = 0x800000;
60
self->drawGroup = 2;
61
self->state = UICreditsText_State_Init;
62
63
if (!self->text.chars)
64
RSDK.InitString(&self->text, "UNTITLED", 0);
65
66
bool32 isHeading = self->isHeading;
67
UICreditsText_SetText(self->animator.animationID, self, &self->text);
68
self->isHeading = isHeading;
69
}
70
}
71
72
void UICreditsText_StageLoad(void) { UICreditsText->aniFrames = RSDK.LoadSpriteAnimation("UI/CreditsText.bin", SCOPE_STAGE); }
73
74
void UICreditsText_SetText(int32 animID, EntityUICreditsText *label, String *text)
75
{
76
RSDK.SetSpriteAnimation(UICreditsText->aniFrames, animID, &label->animator, true, 0);
77
78
label->listID = animID;
79
label->isHeading = animID <= 4;
80
RSDK.CopyString(&label->text, text);
81
82
RSDK.SetSpriteString(UICreditsText->aniFrames, label->listID, &label->text);
83
84
SpriteFrame *frame = RSDK.GetFrame(UICreditsText->aniFrames, animID, 0);
85
if (frame)
86
label->clipY2 = frame->pivotY + frame->height + 2;
87
}
88
89
void UICreditsText_State_Init(void)
90
{
91
RSDK_THIS(UICreditsText);
92
93
if ((self->position.y >> 16) - ScreenInfo->position.y - ScreenInfo->center.y < ScreenInfo->center.y - 16) {
94
self->active = ACTIVE_NORMAL;
95
self->visible = true;
96
97
if (self->animator.animationID == 7) {
98
self->animator.frameID = self->text.chars[1];
99
self->scaleSpeed = 64;
100
self->drawFX = FX_SCALE;
101
self->state = UICreditsText_State_ScaleIn;
102
}
103
else if (self->isHeading) {
104
UICreditsText_State_SetupCharPos();
105
}
106
else {
107
self->inkEffect = INK_ALPHA;
108
self->state = UICreditsText_State_FadeIn;
109
}
110
}
111
}
112
113
void UICreditsText_State_SetupCharPos(void)
114
{
115
RSDK_THIS(UICreditsText);
116
117
self->visible = true;
118
119
int32 yOffset = 0x280000;
120
for (int32 c = 0; c < self->text.length; ++c) {
121
self->charPositions[c].y = yOffset;
122
self->charOffsets[c] = -0x80000;
123
yOffset += 0x100000;
124
}
125
126
self->scaleTimer = 0;
127
self->scaleSpeed = 0x20;
128
self->state = UICreditsText_State_MoveChars;
129
}
130
131
void UICreditsText_State_MoveChars(void)
132
{
133
RSDK_THIS(UICreditsText);
134
135
for (int32 c = 0; c < self->text.length; ++c) {
136
if (self->charPositions[c].y < 0)
137
self->charOffsets[c] += 0x28000;
138
139
self->charPositions[c].y += self->charOffsets[c];
140
141
if (self->charPositions[c].y > 0 && self->charOffsets[c] > 0)
142
self->charPositions[c].y = 0;
143
}
144
145
if (self->scaleTimer > 0)
146
self->scaleSpeed -= 2;
147
148
self->scaleTimer += self->scaleSpeed;
149
150
if (self->scaleTimer < 256 && self->scaleSpeed < 0)
151
self->scaleTimer = 256;
152
153
if (++self->timer == 120) {
154
self->timer = 0;
155
self->state = UICreditsText_SetupIdleDelay;
156
}
157
}
158
159
void UICreditsText_State_ScaleIn(void)
160
{
161
RSDK_THIS(UICreditsText);
162
163
if (self->scale.y > 0)
164
self->scaleSpeed -= 4;
165
166
self->scale.y += self->scaleSpeed;
167
168
if (self->scale.y < 0x200 && self->scaleSpeed < 0)
169
self->scale.y = 0x200;
170
171
self->scale.x = self->scale.y;
172
173
if (++self->timer == 120) {
174
self->timer = 0;
175
self->drawFX = FX_NONE;
176
self->state = UICreditsText_SetupIdleDelay;
177
}
178
}
179
180
void UICreditsText_State_FadeIn(void)
181
{
182
RSDK_THIS(UICreditsText);
183
184
if (self->alpha >= 0x100)
185
self->state = UICreditsText_SetupIdleDelay;
186
else
187
self->alpha += 8;
188
}
189
190
void UICreditsText_SetupIdleDelay(void)
191
{
192
RSDK_THIS(UICreditsText);
193
194
if ((self->position.y >> 16) - ScreenInfo->position.y < 32) {
195
if (self->animator.animationID == 7) {
196
self->drawFX = FX_SCALE;
197
self->state = UICreditsText_State_ScaleOut;
198
}
199
else if (self->isHeading) {
200
for (int32 c = 0; c < self->text.length; ++c) {
201
self->charTimers[c] = 2 * (self->text.length - c - 1);
202
self->charOffsets[c] = -0x80000;
203
}
204
205
self->state = UICreditsText_State_Idle;
206
}
207
else {
208
self->state = UICreditsText_State_FadeOut;
209
}
210
}
211
}
212
213
void UICreditsText_State_Idle(void)
214
{
215
RSDK_THIS(UICreditsText);
216
217
for (int32 c = 0; c < self->text.length; ++c) {
218
if (self->charTimers[c] <= 0) {
219
self->charOffsets[c] += 0x28000;
220
self->charPositions[c].y += self->charOffsets[c];
221
}
222
else {
223
--self->charTimers[c];
224
}
225
}
226
227
if (self->timer > 12 && self->scaleTimer > 0)
228
self->scaleTimer -= 16;
229
230
if (++self->timer == 60)
231
destroyEntity(self);
232
}
233
234
void UICreditsText_State_ScaleOut(void)
235
{
236
RSDK_THIS(UICreditsText);
237
238
if (self->scale.y > 0)
239
self->scale.y -= 0x20;
240
self->scale.x = self->scale.y;
241
242
if (++self->timer == 60)
243
destroyEntity(self);
244
}
245
246
void UICreditsText_State_FadeOut(void)
247
{
248
RSDK_THIS(UICreditsText);
249
250
if (self->alpha <= 0)
251
self->state = UICreditsText_SetupIdleDelay;
252
else
253
self->alpha -= 8;
254
}
255
256
#if GAME_INCLUDE_EDITOR
257
void UICreditsText_EditorDraw(void)
258
{
259
RSDK_THIS(UICreditsText);
260
261
RSDK.SetSpriteAnimation(UICreditsText->aniFrames, self->listID, &self->animator, true, 0);
262
263
UICreditsText_Draw();
264
}
265
266
void UICreditsText_EditorLoad(void) { UICreditsText->aniFrames = RSDK.LoadSpriteAnimation("UI/CreditsText.bin", SCOPE_STAGE); }
267
#endif
268
269
void UICreditsText_Serialize(void)
270
{
271
RSDK_EDITABLE_VAR(UICreditsText, VAR_STRING, text);
272
RSDK_EDITABLE_VAR(UICreditsText, VAR_STRING, tag);
273
RSDK_EDITABLE_VAR(UICreditsText, VAR_ENUM, listID);
274
RSDK_EDITABLE_VAR(UICreditsText, VAR_BOOL, isHeading);
275
RSDK_EDITABLE_VAR(UICreditsText, VAR_BOOL, hasShape);
276
}
277
278