Path: blob/master/SonicMania/Objects/Menu/UICharButton.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: UICharButton Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectUICharButton *UICharButton;1011void UICharButton_Update(void)12{13RSDK_THIS(UICharButton);1415self->touchPosSizeS.x = 0x600000;16self->touchPosSizeS.y = 0x600000;17self->touchPosOffsetS.x = 0;18self->touchPosOffsetS.y = 0;1920StateMachine_Run(self->state);2122if (self->isSelected) {23self->triBounceVelocity -= 0x600;24self->triBounceOffset += self->triBounceVelocity;2526if (self->triBounceOffset <= 0x10000 && self->triBounceVelocity < 0) {27self->triBounceOffset = 0x10000;28self->triBounceVelocity = 0;29}3031self->playerBounceVelocity -= 0x1800;32self->playerBounceOffset += self->playerBounceVelocity;3334if (self->playerBounceOffset <= 0x8000 && self->playerBounceVelocity < 0) {35self->playerBounceOffset = 0x8000;36self->playerBounceVelocity = 0;37}38}39else if (self->state != UICharButton_State_Selected) {40if (self->triBounceOffset > 0) {41self->triBounceOffset -= 0x2000;4243if (self->triBounceOffset < 0)44self->triBounceOffset = 0;45}4647if (self->playerBounceOffset > 0) {48self->playerBounceOffset -= 0x2000;4950if (self->playerBounceOffset < 0)51self->playerBounceOffset = 0;52}53}5455EntityUIControl *parent = (EntityUIControl *)self->parent;56int32 id = -1;57for (int32 i = 0; i < parent->buttonCount; ++i) {58if (self == (EntityUICharButton *)parent->buttons[i]) {59id = i;60break;61}62}6364if (self->isSelected && (parent->state != UIControl_ProcessInputs || parent->buttonID != id)) {65self->isSelected = false;66self->state = UICharButton_State_HandleButtonLeave;67}68}6970void UICharButton_LateUpdate(void) {}7172void UICharButton_StaticUpdate(void) {}7374void UICharButton_Draw(void)75{76RSDK_THIS(UICharButton);7778RSDK.DrawRect(self->position.x - 0x2D0000, self->position.y - 0x2D0000, 0x600000, 0x600000, 0xFFFFFF, 0x7F, INK_BLEND, false);7980UICharButton_DrawBG();81UICharButton_DrawOutlines();82UICharButton_DrawPlayers();83}8485void UICharButton_Create(void *data)86{87RSDK_THIS(UICharButton);8889self->active = ACTIVE_BOUNDS;90self->drawGroup = 2;91self->visible = true;92self->drawFX = FX_FLIP;93self->updateRange.x = 0x800000;94self->updateRange.y = 0x300000;9596self->processButtonCB = UIButton_ProcessButtonCB_Scroll;97self->touchCB = UIButton_ProcessTouchCB_Single;98self->selectedCB = UICharButton_SelectedCB;99self->failCB = StateMachine_None;100self->buttonEnterCB = UICharButton_ButtonEnterCB;101self->buttonLeaveCB = UICharButton_ButtonLeaveCB;102self->checkButtonEnterCB = UICharButton_CheckButtonEnterCB;103self->checkSelectedCB = UICharButton_CheckSelectedCB;104self->state = UICharButton_State_HandleButtonLeave;105}106107void UICharButton_StageLoad(void) { UICharButton->aniFrames = RSDK.LoadSpriteAnimation("UI/SaveSelect.bin", SCOPE_STAGE); }108109void UICharButton_DrawOutlines(void)110{111RSDK_THIS(UICharButton);112113if (!SceneInfo->inEditor)114UIWidgets_DrawRectOutline_Blended(self->position.x + 0x30000, self->position.y + 0x30000, 96, 96);115116if (self->isSelected)117UIWidgets_DrawRectOutline_Flash(self->position.x, self->position.y, 96, 96);118else119UIWidgets_DrawRectOutline_Black(self->position.x, self->position.y, 96, 96);120}121122void UICharButton_DrawBG(void)123{124RSDK_THIS(UICharButton);125126UIWidgets_DrawRightTriangle(self->position.x - 0x2D0000, self->position.y - 0x2D0000, (self->triBounceOffset >> 11), 232, 40, 88);127UIWidgets_DrawRightTriangle(self->position.x + 0x2D0000, self->position.y + 0x2C0000, (-64 * self->triBounceOffset) >> 16, 96, 160, 176);128UIWidgets_DrawRightTriangle(self->position.x + 0x2D0000, self->position.y + 0x2C0000, (-44 * self->triBounceOffset) >> 16, 88, 112, 224);129}130131void UICharButton_DrawPlayers(void)132{133RSDK_THIS(UICharButton);134135Vector2 drawPos;136drawPos = self->position;137drawPos.x -= 0x2D0000;138drawPos.y += 0x180000;139RSDK.DrawRect(drawPos.x, drawPos.y, 0x5A0000, 0x100000, 0, 255, INK_NONE, false);140141if (self->state != UICharButton_State_Selected || !(self->timer & 2)) {142int32 frame = self->characterID;143#if MANIA_USE_PLUS144if (self->characterID >= UICHARBUTTON_MIGHTY)145frame = self->characterID + 1;146#endif147RSDK.SetSpriteAnimation(UICharButton->aniFrames, 1, &self->playerAnimator, true, frame);148RSDK.SetSpriteAnimation(UICharButton->aniFrames, 2, &self->shadowAnimator, true, frame);149drawPos.x = self->position.x;150drawPos.y = self->position.y - 0x80000;151drawPos.x += 4 * self->playerBounceOffset;152drawPos.y += 4 * self->playerBounceOffset;153RSDK.DrawSprite(&self->shadowAnimator, &drawPos, false);154155drawPos.x -= 8 * self->playerBounceOffset;156drawPos.y -= 8 * self->playerBounceOffset;157RSDK.DrawSprite(&self->playerAnimator, &drawPos, false);158159RSDK.SetSpriteAnimation(UIWidgets->textFrames, 8, &self->nameAnimator, true, self->characterID);160drawPos.x = self->position.x;161drawPos.y = self->position.y + 0x200000;162RSDK.DrawSprite(&self->nameAnimator, &drawPos, false);163}164}165166void UICharButton_SelectedCB(void)167{168RSDK_THIS(UICharButton);169170self->timer = 0;171self->state = UICharButton_State_Selected;172self->processButtonCB = StateMachine_None;173174UITransition_StartTransition(self->actionCB, 30);175176if (UIControl_GetUIControl())177UIControl_GetUIControl()->selectionDisabled = true;178179((EntityUIControl *)self->parent)->backoutTimer = 30;180181RSDK.PlaySfx(UIWidgets->sfxAccept, false, 255);182}183184bool32 UICharButton_CheckButtonEnterCB(void)185{186RSDK_THIS(UICharButton);187188return self->state == UICharButton_State_HandleButtonEnter;189}190191bool32 UICharButton_CheckSelectedCB(void)192{193RSDK_THIS(UICharButton);194195return self->state == UICharButton_State_Selected;196}197198void UICharButton_ButtonEnterCB(void)199{200RSDK_THIS(UICharButton);201202if (!self->isSelected) {203self->triBounceOffset = 0;204self->triBounceVelocity = 0x4000;205self->playerBounceOffset = 0;206self->playerBounceVelocity = 0x8000;207208self->isSelected = true;209self->state = UICharButton_State_HandleButtonEnter;210}211}212213void UICharButton_ButtonLeaveCB(void)214{215RSDK_THIS(UICharButton);216217self->isSelected = false;218self->state = UICharButton_State_HandleButtonLeave;219}220221void UICharButton_State_HandleButtonLeave(void) {}222223void UICharButton_State_HandleButtonEnter(void) {}224225void UICharButton_State_Selected(void)226{227RSDK_THIS(UICharButton);228229if (self->timer >= 30) {230self->isSelected = false;231self->timer = 0;232self->state = UICharButton_State_HandleButtonLeave;233self->processButtonCB = UIButton_ProcessButtonCB_Scroll;234}235else {236if (self->timer == 2) {237switch (self->characterID) {238case UICHARBUTTON_SONIC: RSDK.PlaySfx(Announcer->sfxSonic, false, 255); break;239case UICHARBUTTON_TAILS: RSDK.PlaySfx(Announcer->sfxTails, false, 255); break;240case UICHARBUTTON_KNUX: RSDK.PlaySfx(Announcer->sfxKnuckles, false, 255); break;241#if MANIA_USE_PLUS242case UICHARBUTTON_MIGHTY: RSDK.PlaySfx(Announcer->sfxMighty, false, 255); break;243case UICHARBUTTON_RAY: RSDK.PlaySfx(Announcer->sfxRay, false, 255); break;244#endif245default: break;246}247}248249++self->timer;250}251}252253#if GAME_INCLUDE_EDITOR254void UICharButton_EditorDraw(void)255{256RSDK_THIS(UICharButton);257258self->inkEffect = self->disabled ? INK_BLEND : INK_NONE;259260UICharButton_Draw();261}262263void UICharButton_EditorLoad(void)264{265UICharButton->aniFrames = RSDK.LoadSpriteAnimation("UI/SaveSelect.bin", SCOPE_STAGE);266267RSDK_ACTIVE_VAR(UICharButton, characterID);268RSDK_ENUM_VAR("Sonic", UICHARBUTTON_SONIC);269RSDK_ENUM_VAR("Tails", UICHARBUTTON_TAILS);270RSDK_ENUM_VAR("Knuckles", UICHARBUTTON_KNUX);271#if MANIA_USE_PLUS272RSDK_ENUM_VAR("Mighty", UICHARBUTTON_MIGHTY);273RSDK_ENUM_VAR("Ray", UICHARBUTTON_RAY);274#endif275}276#endif277278void UICharButton_Serialize(void)279{280RSDK_EDITABLE_VAR(UICharButton, VAR_BOOL, disabled);281RSDK_EDITABLE_VAR(UICharButton, VAR_UINT8, characterID);282}283284285