Path: blob/master/SonicMania/Objects/Menu/UICreditsText.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: UICreditsText Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectUICreditsText *UICreditsText;1011void UICreditsText_Update(void)12{13RSDK_THIS(UICreditsText);1415StateMachine_Run(self->state);16}1718void UICreditsText_LateUpdate(void) {}1920void UICreditsText_StaticUpdate(void) {}2122void UICreditsText_Draw(void)23{24RSDK_THIS(UICreditsText);2526Vector2 drawPos;27int32 width = RSDK.GetStringWidth(UICreditsText->aniFrames, self->listID, &self->text, 0, self->text.length, 0);2829drawPos.x = self->position.x;30drawPos.y = self->position.y + 0x40000;31if (self->hasShape)32UIWidgets_DrawParallelogram(drawPos.x, drawPos.y, (self->scaleTimer * (width + 16)) >> 8, self->scaleTimer >> 4, 16, 0x00, 0x00, 0x00);3334drawPos.x -= width << 15;35drawPos.y = self->position.y;36if (self->animator.animationID >= 7) {37RSDK.DrawSprite(&self->animator, 0, false);38}39else {40RSDK.SetClipBounds(SceneInfo->currentScreenID, 0, 0, ScreenInfo->size.x,41(self->position.y >> 16) + self->clipY2 - ScreenInfo[SceneInfo->currentScreenID].position.y);4243RSDK.DrawText(&self->animator, &drawPos, &self->text, 0, 0, ALIGN_LEFT, 0, NULL, self->charPositions, false);4445RSDK.SetClipBounds(SceneInfo->currentScreenID, 0, 0, ScreenInfo->size.x, ScreenInfo->size.y);46}47}4849void UICreditsText_Create(void *data)50{51RSDK_THIS(UICreditsText);5253RSDK.SetSpriteAnimation(UICreditsText->aniFrames, self->listID, &self->animator, true, 0);5455if (!SceneInfo->inEditor) {56self->active = ACTIVE_BOUNDS;57self->updateRange.x = 0x800000;58self->updateRange.y = 0x800000;59self->drawGroup = 2;60self->state = UICreditsText_State_Init;6162if (!self->text.chars)63RSDK.InitString(&self->text, "UNTITLED", 0);6465bool32 isHeading = self->isHeading;66UICreditsText_SetText(self->animator.animationID, self, &self->text);67self->isHeading = isHeading;68}69}7071void UICreditsText_StageLoad(void) { UICreditsText->aniFrames = RSDK.LoadSpriteAnimation("UI/CreditsText.bin", SCOPE_STAGE); }7273void UICreditsText_SetText(int32 animID, EntityUICreditsText *label, String *text)74{75RSDK.SetSpriteAnimation(UICreditsText->aniFrames, animID, &label->animator, true, 0);7677label->listID = animID;78label->isHeading = animID <= 4;79RSDK.CopyString(&label->text, text);8081RSDK.SetSpriteString(UICreditsText->aniFrames, label->listID, &label->text);8283SpriteFrame *frame = RSDK.GetFrame(UICreditsText->aniFrames, animID, 0);84if (frame)85label->clipY2 = frame->pivotY + frame->height + 2;86}8788void UICreditsText_State_Init(void)89{90RSDK_THIS(UICreditsText);9192if ((self->position.y >> 16) - ScreenInfo->position.y - ScreenInfo->center.y < ScreenInfo->center.y - 16) {93self->active = ACTIVE_NORMAL;94self->visible = true;9596if (self->animator.animationID == 7) {97self->animator.frameID = self->text.chars[1];98self->scaleSpeed = 64;99self->drawFX = FX_SCALE;100self->state = UICreditsText_State_ScaleIn;101}102else if (self->isHeading) {103UICreditsText_State_SetupCharPos();104}105else {106self->inkEffect = INK_ALPHA;107self->state = UICreditsText_State_FadeIn;108}109}110}111112void UICreditsText_State_SetupCharPos(void)113{114RSDK_THIS(UICreditsText);115116self->visible = true;117118int32 yOffset = 0x280000;119for (int32 c = 0; c < self->text.length; ++c) {120self->charPositions[c].y = yOffset;121self->charOffsets[c] = -0x80000;122yOffset += 0x100000;123}124125self->scaleTimer = 0;126self->scaleSpeed = 0x20;127self->state = UICreditsText_State_MoveChars;128}129130void UICreditsText_State_MoveChars(void)131{132RSDK_THIS(UICreditsText);133134for (int32 c = 0; c < self->text.length; ++c) {135if (self->charPositions[c].y < 0)136self->charOffsets[c] += 0x28000;137138self->charPositions[c].y += self->charOffsets[c];139140if (self->charPositions[c].y > 0 && self->charOffsets[c] > 0)141self->charPositions[c].y = 0;142}143144if (self->scaleTimer > 0)145self->scaleSpeed -= 2;146147self->scaleTimer += self->scaleSpeed;148149if (self->scaleTimer < 256 && self->scaleSpeed < 0)150self->scaleTimer = 256;151152if (++self->timer == 120) {153self->timer = 0;154self->state = UICreditsText_SetupIdleDelay;155}156}157158void UICreditsText_State_ScaleIn(void)159{160RSDK_THIS(UICreditsText);161162if (self->scale.y > 0)163self->scaleSpeed -= 4;164165self->scale.y += self->scaleSpeed;166167if (self->scale.y < 0x200 && self->scaleSpeed < 0)168self->scale.y = 0x200;169170self->scale.x = self->scale.y;171172if (++self->timer == 120) {173self->timer = 0;174self->drawFX = FX_NONE;175self->state = UICreditsText_SetupIdleDelay;176}177}178179void UICreditsText_State_FadeIn(void)180{181RSDK_THIS(UICreditsText);182183if (self->alpha >= 0x100)184self->state = UICreditsText_SetupIdleDelay;185else186self->alpha += 8;187}188189void UICreditsText_SetupIdleDelay(void)190{191RSDK_THIS(UICreditsText);192193if ((self->position.y >> 16) - ScreenInfo->position.y < 32) {194if (self->animator.animationID == 7) {195self->drawFX = FX_SCALE;196self->state = UICreditsText_State_ScaleOut;197}198else if (self->isHeading) {199for (int32 c = 0; c < self->text.length; ++c) {200self->charTimers[c] = 2 * (self->text.length - c - 1);201self->charOffsets[c] = -0x80000;202}203204self->state = UICreditsText_State_Idle;205}206else {207self->state = UICreditsText_State_FadeOut;208}209}210}211212void UICreditsText_State_Idle(void)213{214RSDK_THIS(UICreditsText);215216for (int32 c = 0; c < self->text.length; ++c) {217if (self->charTimers[c] <= 0) {218self->charOffsets[c] += 0x28000;219self->charPositions[c].y += self->charOffsets[c];220}221else {222--self->charTimers[c];223}224}225226if (self->timer > 12 && self->scaleTimer > 0)227self->scaleTimer -= 16;228229if (++self->timer == 60)230destroyEntity(self);231}232233void UICreditsText_State_ScaleOut(void)234{235RSDK_THIS(UICreditsText);236237if (self->scale.y > 0)238self->scale.y -= 0x20;239self->scale.x = self->scale.y;240241if (++self->timer == 60)242destroyEntity(self);243}244245void UICreditsText_State_FadeOut(void)246{247RSDK_THIS(UICreditsText);248249if (self->alpha <= 0)250self->state = UICreditsText_SetupIdleDelay;251else252self->alpha -= 8;253}254255#if GAME_INCLUDE_EDITOR256void UICreditsText_EditorDraw(void)257{258RSDK_THIS(UICreditsText);259260RSDK.SetSpriteAnimation(UICreditsText->aniFrames, self->listID, &self->animator, true, 0);261262UICreditsText_Draw();263}264265void UICreditsText_EditorLoad(void) { UICreditsText->aniFrames = RSDK.LoadSpriteAnimation("UI/CreditsText.bin", SCOPE_STAGE); }266#endif267268void UICreditsText_Serialize(void)269{270RSDK_EDITABLE_VAR(UICreditsText, VAR_STRING, text);271RSDK_EDITABLE_VAR(UICreditsText, VAR_STRING, tag);272RSDK_EDITABLE_VAR(UICreditsText, VAR_ENUM, listID);273RSDK_EDITABLE_VAR(UICreditsText, VAR_BOOL, isHeading);274RSDK_EDITABLE_VAR(UICreditsText, VAR_BOOL, hasShape);275}276277278