Path: blob/master/SonicMania/Objects/Menu/UIControl.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: UIControl Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectUIControl *UIControl;1011void UIControl_Update(void)12{13RSDK_THIS(UIControl);1415if (self->buttonID >= 0 && self->buttonID != self->lastButtonID)16self->lastButtonID = self->buttonID;1718if (!UIControl->hasTouchInput && self->buttonID == -1)19self->buttonID = self->lastButtonID;2021StateMachine_Run(self->state);2223if (self->backoutTimer > 0)24self->backoutTimer--;2526StateMachine_Run(self->menuUpdateCB);27}2829void UIControl_LateUpdate(void) {}3031void UIControl_StaticUpdate(void)32{33if (UIControl->lockInput) {34UIControl->lockInput = false;35UIControl->inputLocked = true;36}37else {38UIControl->inputLocked = false;39}4041UIControl->forceBackPress = false;4243++UIControl->timer;44UIControl->timer &= 0x7FFF;45}4647void UIControl_Draw(void)48{49RSDK_THIS(UIControl);5051ScreenInfo->position.x = FROM_FIXED(self->position.x) - ScreenInfo->center.x;52ScreenInfo->position.y = FROM_FIXED(self->position.y) - ScreenInfo->center.y;53}5455void UIControl_Create(void *data)56{57RSDK_THIS(UIControl);5859if (!SceneInfo->inEditor) {60if (data) {61Vector2 *size = (Vector2 *)data;62self->size.x = size->x;63self->size.y = size->y;64}6566self->updateRange.x = self->size.x >> 1;67self->updateRange.y = self->size.y >> 1;68#if MANIA_USE_PLUS69self->promptCount = 0;70#endif7172if (self->rowCount <= 1)73self->rowCount = 1;7475if (self->columnCount <= 1)76self->columnCount = 1;7778if (!self->hasStoredButton)79self->buttonID = self->startingID;80else81self->buttonID = self->storedButtonID;8283self->position.x += self->cameraOffset.x;84self->position.y += self->cameraOffset.y;85self->startPos.x = self->position.x;86self->startPos.y = self->position.y;8788#if MANIA_USE_PLUS89int32 slotID = RSDK.GetEntitySlot(self);90if (UIButtonPrompt && slotID != SLOT_DIALOG_UICONTROL) {91foreach_all(UIButtonPrompt, prompt)92{93if (self->promptCount < UICONTROL_PROMPT_COUNT && UIControl_ContainsPos(self, &prompt->position)) {94prompt->parent = (Entity *)self;95self->prompts[self->promptCount++] = prompt;96}97}98}99#endif100101AnalogStickInfoL[1].deadzone = 0.75f;102AnalogStickInfoL[2].deadzone = 0.75f;103AnalogStickInfoL[3].deadzone = 0.75f;104AnalogStickInfoL[4].deadzone = 0.75f;105106UIControl_SetupButtons();107108if (self->noWidgets) {109self->active = ACTIVE_NORMAL;110self->visible = true;111}112else {113#if MANIA_USE_PLUS114self->menuWasSetup = false;115#endif116117if (self->activeOnLoad)118UIControl_SetActiveMenu(self);119else120self->active = ACTIVE_NEVER;121}122}123}124125void UIControl_StageLoad(void)126{127UIControl->inputLocked = false;128UIControl->lockInput = false;129UIControl->active = ACTIVE_ALWAYS;130UIControl->isProcessingInput = false;131}132133EntityUIControl *UIControl_GetUIControl(void)134{135foreach_all(UIControl, control)136{137if (control->active == ACTIVE_ALWAYS) {138foreach_return control;139}140}141142return NULL;143}144145void UIControl_ClearInputs(uint8 buttonID)146{147for (int32 i = 0; i < PLAYER_COUNT; ++i) {148UIControl->upPress[i] = false;149UIControl->downPress[i] = false;150UIControl->leftPress[i] = false;151UIControl->rightPress[i] = false;152UIControl->yPress[i] = false;153UIControl->xPress[i] = false;154UIControl->backPress[i] = false;155UIControl->confirmPress[i] = false;156#if MANIA_USE_PLUS157UIControl->startPress[i] = false;158#endif159}160161UIControl->anyUpPress = false;162UIControl->anyDownPress = false;163UIControl->anyLeftPress = false;164UIControl->anyRightPress = false;165UIControl->anyYPress = buttonID == UIBUTTONPROMPT_BUTTON_Y;166UIControl->anyXPress = buttonID == UIBUTTONPROMPT_BUTTON_X;167#if MANIA_USE_PLUS168UIControl->anyStartPress = buttonID == UIBUTTONPROMPT_BUTTON_SELECT;169#endif170171if (API_GetConfirmButtonFlip()) {172UIControl->anyConfirmPress = buttonID == UIBUTTONPROMPT_BUTTON_B;173UIControl->anyBackPress = buttonID == UIBUTTONPROMPT_BUTTON_A;174UIControl->forceBackPress = buttonID == UIBUTTONPROMPT_BUTTON_A;175}176else {177UIControl->anyConfirmPress = buttonID == UIBUTTONPROMPT_BUTTON_A;178UIControl->anyBackPress = buttonID == UIBUTTONPROMPT_BUTTON_B;179UIControl->forceBackPress = buttonID == UIBUTTONPROMPT_BUTTON_B;180}181182UIControl->lockInput = true;183UIControl->inputLocked = true;184}185186void UIControl_ProcessInputs(void)187{188RSDK_THIS(UIControl);189190UIControl_HandlePosition();191192if (!UIControl->inputLocked) {193for (int32 i = 0; i < PLAYER_COUNT; ++i) {194UIControl->upPress[i] = ControllerInfo[CONT_P1 + i].keyUp.press || AnalogStickInfoL[CONT_P1 + i].keyUp.press;195UIControl->downPress[i] = ControllerInfo[CONT_P1 + i].keyDown.press || AnalogStickInfoL[CONT_P1 + i].keyDown.press;196UIControl->leftPress[i] = ControllerInfo[CONT_P1 + i].keyLeft.press || AnalogStickInfoL[CONT_P1 + i].keyLeft.press;197UIControl->rightPress[i] = ControllerInfo[CONT_P1 + i].keyRight.press || AnalogStickInfoL[CONT_P1 + i].keyRight.press;198199if (UIControl->upPress[i] && UIControl->downPress[i]) {200UIControl->upPress[i] = false;201UIControl->downPress[i] = false;202}203204if (UIControl->leftPress[i] && UIControl->rightPress[i]) {205UIControl->leftPress[i] = false;206UIControl->rightPress[i] = false;207}208209UIControl->yPress[i] = ControllerInfo[CONT_P1 + i].keyY.press;210UIControl->xPress[i] = ControllerInfo[CONT_P1 + i].keyX.press;211#if MANIA_USE_PLUS212UIControl->startPress[i] = ControllerInfo[CONT_P1 + i].keyStart.press;213#endif214215UIControl->confirmPress[i] = ControllerInfo[CONT_P1 + i].keyStart.press;216if (API_GetConfirmButtonFlip()) {217UIControl->confirmPress[i] |= ControllerInfo[CONT_P1 + i].keyB.press;218UIControl->backPress[i] = ControllerInfo[CONT_P1 + i].keyA.press;219}220else {221UIControl->confirmPress[i] |= ControllerInfo[CONT_P1 + i].keyA.press;222UIControl->backPress[i] = ControllerInfo[CONT_P1 + i].keyB.press;223}224}225226UIControl->anyUpPress = ControllerInfo->keyUp.press || AnalogStickInfoL->keyUp.press;227UIControl->anyDownPress = ControllerInfo->keyDown.press || AnalogStickInfoL->keyDown.press;228UIControl->anyLeftPress = ControllerInfo->keyLeft.press || AnalogStickInfoL->keyLeft.press;229UIControl->anyRightPress = ControllerInfo->keyRight.press || AnalogStickInfoL->keyRight.press;230UIControl->anyYPress = ControllerInfo->keyY.press;231UIControl->anyXPress = ControllerInfo->keyX.press;232#if MANIA_USE_PLUS233UIControl->anyStartPress = ControllerInfo->keyStart.press;234#endif235236UIControl->anyConfirmPress = ControllerInfo->keyStart.press;237if (API_GetConfirmButtonFlip()) {238UIControl->anyConfirmPress |= ControllerInfo->keyB.press;239UIControl->anyBackPress = ControllerInfo->keyA.press;240}241else {242UIControl->anyConfirmPress |= ControllerInfo->keyA.press;243UIControl->anyBackPress = ControllerInfo->keyB.press;244}245246UIControl->anyBackPress |= Unknown_pausePress;247UIControl->anyBackPress |= UIControl->forceBackPress;248249if (UIControl->anyBackPress) {250UIControl->anyConfirmPress = false;251UIControl->anyYPress = false;252}253254if (UIControl->anyConfirmPress) {255UIControl->anyYPress = false;256}257258UIControl->inputLocked = true;259}260261if (!self->selectionDisabled) {262bool32 backPressed = false;263264if (UIControl->anyBackPress) {265if (!self->childHasFocus && !self->dialogHasFocus266#if MANIA_USE_PLUS267&& !self->popoverHasFocus268#endif269&& self->backoutTimer <= 0) {270if (self->backPressCB) {271backPressed = self->backPressCB();272273if (!backPressed) {274UIControl->anyBackPress = false;275}276else {277if (self->buttons[self->buttonID])278self->buttons[self->buttonID]->isSelected = false;279}280}281else {282if (self->parentTag.length <= 0) {283UIControl->anyBackPress = false;284}285else {286self->selectionDisabled = true;287UITransition_StartTransition(UIControl_ReturnToParentMenu, 0);288backPressed = false;289290if (self->buttons[self->buttonID])291self->buttons[self->buttonID]->isSelected = false;292}293}294295if (backPressed)296return;297}298#if MANIA_USE_PLUS299else {300LogHelpers_Print("Backout prevented");301LogHelpers_Print("childHasFocus = %d", self->childHasFocus);302LogHelpers_Print("dialogHasFocus = %d", self->dialogHasFocus);303LogHelpers_Print("popoverHasFocus = %d", self->popoverHasFocus);304LogHelpers_Print("backoutTimer = %d", self->backoutTimer);305}306#endif307}308309if (self->processButtonInputCB) {310StateMachine_Run(self->processButtonInputCB);311}312else313UIControl_ProcessButtonInput();314315if (!self->selectionDisabled) {316if (UIControl->anyYPress) {317if (!self->childHasFocus && !self->dialogHasFocus318#if MANIA_USE_PLUS319&& !self->popoverHasFocus320#endif321&& self->backoutTimer <= 0) {322StateMachine_Run(self->yPressCB);323}324325UIControl->anyYPress = false;326}327328if (UIControl->anyXPress) {329if (!self->childHasFocus && !self->dialogHasFocus330#if MANIA_USE_PLUS331&& !self->popoverHasFocus332#endif333&& self->backoutTimer <= 0) {334StateMachine_Run(self->xPressCB);335}336337UIControl->anyXPress = false;338}339}340}341}342343int32 UIControl_GetButtonID(EntityUIControl *control, EntityUIButton *entity)344{345for (int32 i = 0; i < control->buttonCount; ++i) {346if (entity == control->buttons[i])347return i;348}349350return -1;351}352353void UIControl_MenuChangeButtonInit(EntityUIControl *control)354{355Entity *storeEntity = SceneInfo->entity;356for (int32 i = 0; i < SCENEENTITY_COUNT; ++i) {357EntityUIButton *entity = RSDK_GET_ENTITY(i, UIButton);358359if (entity) {360int32 left = MIN(-ScreenInfo->size.x >> 1, ScreenInfo->size.x >> 1) << 16;361int32 right = MAX(-ScreenInfo->size.x >> 1, ScreenInfo->size.x >> 1) << 16;362int32 top = MIN(-ScreenInfo->size.y >> 1, ScreenInfo->size.y >> 1) << 16;363int32 bottom = MAX(-ScreenInfo->size.y >> 1, ScreenInfo->size.y >> 1) << 16;364365if (entity->position.x >= control->position.x + left && entity->position.x <= control->position.x + right) {366if (entity->position.y >= control->position.y + top && entity->position.y <= control->position.y + bottom) {367int32 slot = RSDK.GetEntitySlot(entity);368369SceneInfo->entity = (Entity *)entity;370if (UIButton && entity->classID == UIButton->classID) {371UIButton_ManageChoices(entity);372UIButton_Update();373}374else if (UIChoice && entity->classID == UIChoice->classID) {375UIChoice_Update();376}377else if (UITAZoneModule && entity->classID == UITAZoneModule->classID) {378UITAZoneModule_Update();379}380#if MANIA_USE_PLUS381else if (UIReplayCarousel && entity->classID == UIReplayCarousel->classID) {382UIReplayCarousel_Update();383}384#endif385else if (UIModeButton && entity->classID == UIModeButton->classID) {386#if MANIA_USE_PLUS387UIModeButton_Update();388#else389EntityUIModeButton *modeButton = (EntityUIModeButton *)SceneInfo->entity;390modeButton->touchPosSizeS.x = 0xB80000;391modeButton->touchPosSizeS.y = 0x3E0000;392modeButton->touchPosOffsetS.x = 0;393modeButton->touchPosOffsetS.y = -0x120000;394if (modeButton->textFrames != UIWidgets->textFrames || modeButton->wasDisabled != modeButton->disabled) {395UIModeButton_SetupSprites();396modeButton->textFrames = UIWidgets->textFrames;397modeButton->wasDisabled = modeButton->disabled;398}399#endif400}401else if (UIVsZoneButton && entity->classID == UIVsZoneButton->classID) {402UIVsZoneButton_Update();403}404else if (UIHeading && entity->classID == UIHeading->classID) {405UIHeading_Update();406}407408if (entity->visible)409RSDK.AddDrawListRef(entity->drawGroup, slot);410411SceneInfo->entity = storeEntity;412}413}414}415}416}417418#if MANIA_USE_PLUS419void UIControl_SetActiveMenuButtonPrompts(EntityUIControl *entity)420{421for (int32 i = 0; i < entity->promptCount; ++i) entity->prompts[i]->active = ACTIVE_NORMAL;422}423#endif424425void UIControl_SetActiveMenu(EntityUIControl *entity)426{427#if MANIA_USE_PLUS428LogHelpers_PrintString(&entity->tag);429#endif430431entity->active = ACTIVE_ALWAYS;432entity->visible = true;433434if (entity->hasStoredButton) {435entity->buttonID = entity->storedButtonID;436entity->storedButtonID = 0;437entity->hasStoredButton = false;438}439else if (entity->resetSelection) {440entity->buttonID = entity->startingID;441}442443RSDK.ClearCameras();444RSDK.AddCamera(&entity->position, ScreenInfo->size.x << 16, ScreenInfo->size.y << 16, true);445446UIControl_MenuChangeButtonInit(entity);447448#if MANIA_USE_PLUS449if (!entity->childHasFocus && (entity->resetSelection || !entity->menuWasSetup)) {450#else451if (!entity->childHasFocus) {452#endif453entity->position.x = entity->startPos.x;454entity->position.y = entity->startPos.y;455entity->targetPos.x = entity->startPos.x;456entity->targetPos.y = entity->startPos.y;457}458459entity->state = UIControl_ProcessInputs;460entity->childHasFocus = false;461462#if MANIA_USE_PLUS463entity->menuWasSetup = true;464465for (int32 p = 0; p < entity->promptCount; ++p) entity->prompts[p]->active = ACTIVE_NORMAL;466#endif467468if (entity->menuSetupCB) {469Entity *storeEntity = SceneInfo->entity;470SceneInfo->entity = (Entity *)entity;471#if RETRO_USE_MOD_LOADER472StateMachine_Run(entity->menuSetupCB);473#else474entity->menuSetupCB();475#endif476SceneInfo->entity = storeEntity;477}478}479480void UIControl_SetMenuLostFocus(EntityUIControl *entity)481{482entity->active = ACTIVE_ALWAYS;483entity->visible = true;484485if (!entity->dialogHasFocus && !entity->childHasFocus486#if MANIA_USE_PLUS487&& !entity->popoverHasFocus488#endif489) {490if (entity->hasStoredButton) {491entity->buttonID = entity->storedButtonID;492entity->storedButtonID = 0;493entity->hasStoredButton = false;494}495else if (entity->resetSelection) {496entity->buttonID = entity->startingID;497#if !MANIA_USE_PLUS498entity->position.x = entity->startPos.x;499entity->position.y = entity->startPos.y;500entity->targetPos.x = entity->startPos.x;501entity->targetPos.y = entity->startPos.y;502entity->state = UIControl_ProcessInputs;503#endif504}505506#if MANIA_USE_PLUS507if (entity->resetSelection || !entity->menuWasSetup) {508entity->position.x = entity->startPos.x;509entity->position.y = entity->startPos.y;510entity->targetPos.x = entity->startPos.x;511entity->targetPos.y = entity->startPos.y;512}513514entity->menuWasSetup = true;515UIControl_SetActiveMenuButtonPrompts(entity);516#endif517entity->state = UIControl_ProcessInputs;518}519}520521void UIControl_SetInactiveMenu(EntityUIControl *control)522{523UIControl->hasTouchInput = false;524control->active = ACTIVE_NEVER;525control->visible = false;526control->state = StateMachine_None;527528#if MANIA_USE_PLUS529RSDK_THIS(UIControl);530531if (self->promptCount) {532for (int32 p = 0; p < control->promptCount; ++p) control->prompts[p]->active = ACTIVE_BOUNDS;533}534#endif535}536537void UIControl_SetupButtons(void)538{539RSDK_THIS(UIControl);540541int32 slotID = RSDK.GetEntitySlot(self);542543if (UIHeading && slotID != SLOT_DIALOG_UICONTROL) {544foreach_all(UIHeading, heading)545{546if (UIControl_ContainsPos(self, &heading->position))547self->heading = heading;548}549}550551#if MANIA_USE_PLUS552if (UIShifter && slotID != SLOT_DIALOG_UICONTROL) {553foreach_all(UIShifter, shifter)554{555if (UIControl_ContainsPos(self, &shifter->position)) {556self->shifter = shifter;557shifter->parent = self;558}559}560}561562if (UICarousel && slotID != SLOT_DIALOG_UICONTROL) {563foreach_all(UICarousel, carousel)564{565if (UIControl_ContainsPos(self, &carousel->position)) {566self->carousel = carousel;567carousel->parent = self;568}569}570}571#endif572573for (int32 i = 0; i < SCENEENTITY_COUNT; ++i) {574EntityUIButton *button = RSDK_GET_ENTITY(i, UIButton);575576if (button) {577int32 classID = button->classID;578if (classID != UIButton->classID && (!UIModeButton || classID != UIModeButton->classID) && (!UISaveSlot || classID != UISaveSlot->classID)579&& (!UICharButton || classID != UICharButton->classID) && (!UITAZoneModule || classID != UITAZoneModule->classID)580#if MANIA_USE_PLUS581&& (!UIRankButton || classID != UIRankButton->classID) && (!UIReplayCarousel || classID != UIReplayCarousel->classID)582#endif583&& (!UILeaderboard || classID != UILeaderboard->classID) && (!UIVsCharSelector || classID != UIVsCharSelector->classID)584&& (!UIVsZoneButton || classID != UIVsZoneButton->classID) && (!UIVsResults || classID != UIVsResults->classID)585&& (!UISlider || classID != UISlider->classID) && (!UIKeyBinder || classID != UIKeyBinder->classID)) {586}587else {588if (self->buttonCount < UICONTROL_BUTTON_COUNT && UIControl_ContainsPos(self, &button->position)) {589if (!button->parent)590button->parent = (Entity *)self;591592self->buttons[self->buttonCount++] = button;593}594}595}596}597}598599bool32 UIControl_isMoving(EntityUIControl *entity)600{601if (entity->scrollSpeed.x && entity->scrollSpeed.y) {602return entity->position.x != entity->targetPos.x || entity->position.y != entity->targetPos.y;603}604else {605if (entity->scrollSpeed.x) {606return entity->position.x != entity->targetPos.x;607}608else if (entity->scrollSpeed.y) {609return entity->position.y != entity->targetPos.y;610}611}612613return false;614}615616void UIControl_MatchMenuTag(const char *text)617{618String string;619INIT_STRING(string);620621RSDK.SetString(&string, text);622foreach_all(UIControl, entity)623{624if (entity->active == ACTIVE_ALWAYS || !RSDK.CompareStrings(&string, &entity->tag, false))625UIControl_SetInactiveMenu(entity);626else627UIControl_SetActiveMenu(entity);628}629}630631void UIControl_HandleMenuChange(String *newMenuTag)632{633if (newMenuTag->length) {634foreach_all(UIControl, entity)635{636if (entity->active == ACTIVE_ALWAYS || !RSDK.CompareStrings(newMenuTag, &entity->tag, false))637UIControl_SetInactiveMenu(entity);638else639UIControl_SetActiveMenu(entity);640}641}642}643644void UIControl_HandleMenuLoseFocus(EntityUIControl *parent)645{646foreach_all(UIControl, entity)647{648if (entity->active == ACTIVE_ALWAYS || entity != parent)649UIControl_SetInactiveMenu(entity);650else651UIControl_SetMenuLostFocus(entity);652}653}654655void UIControl_ReturnToParentMenu(void)656{657EntityUIControl *entity = UIControl_GetUIControl();658entity->selectionDisabled = false;659660UIControl_HandleMenuChange(&entity->parentTag);661}662663#if MANIA_USE_PLUS664void UIControl_SetTargetPos(EntityUIControl *entity, int32 x, int32 y)665{666int32 targetX = x;667if (!x) {668targetX = entity->position.x;669x = entity->position.x;670}671672int32 targetY = y;673if (!y) {674targetY = entity->position.y;675y = entity->position.y;676}677678if (!entity->noClamp) {679int32 startX = entity->startPos.x - entity->cameraOffset.x;680int32 startY = entity->startPos.y - entity->cameraOffset.y;681int32 x1 = startX + (ScreenInfo->size.x << 15) - (entity->size.x >> 1);682int32 x2 = startX + (entity->size.x >> 1) - (ScreenInfo->size.x << 15);683int32 y1 = startY + (ScreenInfo->size.y << 15) - (entity->size.y >> 1);684int32 y2 = startY + (entity->size.y >> 1) - (ScreenInfo->size.y << 15);685686if (x < x2)687x2 = x;688targetX = x2;689690if (x1 > x2)691targetX = x1;692693if (y < y2)694y2 = y;695targetY = y2;696697if (y1 > y2)698targetY = y1;699}700701entity->targetPos.x = targetX;702entity->targetPos.y = targetY;703}704#endif705706void UIControl_HandlePosition(void)707{708RSDK_THIS(UIControl);709710if (self->position.x < self->targetPos.x) {711self->position.x += self->scrollSpeed.x;712if (self->position.x > self->targetPos.x)713self->position.x = self->targetPos.x;714}715else if (self->position.x > self->targetPos.x) {716self->position.x -= self->scrollSpeed.x;717if (self->position.x < self->targetPos.x)718self->position.x = self->targetPos.x;719}720721if (self->position.y < self->targetPos.y) {722self->position.y += self->scrollSpeed.y;723if (self->position.y > self->targetPos.y)724self->position.y = self->targetPos.y;725}726else if (self->position.y > self->targetPos.y) {727self->position.y -= self->scrollSpeed.y;728if (self->position.y < self->targetPos.y)729self->position.y = self->targetPos.y;730}731732if (self->heading)733self->heading->position.x = self->position.x;734}735736void UIControl_ProcessButtonInput(void)737{738RSDK_THIS(UIControl);739740bool32 allowAction = false;741if (TouchInfo->count || UIControl->hasTouchInput) {742EntityUIButton *activeButton = 0;743UIControl->hasTouchInput = TouchInfo->count != 0;744UIControl->isProcessingInput = true;745746for (int32 i = 0; i < self->buttonCount; ++i) {747if (self->buttons[i]) {748EntityUIButton *button = self->buttons[i];749750Entity *storeEntity = SceneInfo->entity;751SceneInfo->entity = (Entity *)button;752if (button->touchCB && !self->dialogHasFocus753#if MANIA_USE_PLUS754&& !self->popoverHasFocus755#endif756) {757if (!button->checkSelectedCB || !button->checkSelectedCB()) {758bool32 wasTouched = button->touchCB();759if (allowAction || wasTouched) {760allowAction = true;761if (button->touchCB && !activeButton)762activeButton = button;763}764else {765allowAction = false;766}767}768}769770SceneInfo->entity = storeEntity;771}772}773774if (TouchInfo->count) {775if (allowAction) {776int32 id = -1;777778for (int32 i = 0; i < self->buttonCount; ++i) {779if (activeButton == self->buttons[i]) {780id = i;781break;782}783}784785self->buttonID = id;786if (activeButton->isSelected) {787Entity *storeEntity = SceneInfo->entity;788SceneInfo->entity = (Entity *)activeButton;789activeButton->isSelected = true;790StateMachine_Run(activeButton->buttonEnterCB);791SceneInfo->entity = storeEntity;792}793}794else {795self->buttonID = -1;796}797}798799UIControl->isProcessingInput = false;800}801802if (self->buttonID >= 0) {803if (self->buttonID < self->buttonCount) {804EntityUIButton *button = self->buttons[self->buttonID];805806if (button) {807Entity *storeEntity = SceneInfo->entity;808SceneInfo->entity = (Entity *)button;809if (button->processButtonCB) {810if (!button->checkSelectedCB || !button->checkSelectedCB()) {811#if RETRO_USE_MOD_LOADER812StateMachine_Run(button->processButtonCB);813#else814button->processButtonCB();815#endif816}817}818SceneInfo->entity = storeEntity;819}820}821}822}823824bool32 UIControl_ContainsPos(EntityUIControl *control, Vector2 *pos) {825int32 x = control->startPos.x - control->cameraOffset.x;826int32 y = control->startPos.y - control->cameraOffset.y;827828Hitbox hitbox;829hitbox.top = -(control->size.y >> 17);830hitbox.left = -(control->size.x >> 17);831hitbox.right = control->size.x >> 17;832hitbox.bottom = control->size.y >> 17;833834if (MathHelpers_PointInHitbox(x, y, pos->x, pos->y, FLIP_NONE, &hitbox))835return true;836837return false;838}839840#if GAME_INCLUDE_EDITOR841void UIControl_EditorDraw(void)842{843RSDK_THIS(UIControl);844845self->updateRange.x = self->size.x >> 1;846self->updateRange.y = self->size.y >> 1;847848DrawHelpers_DrawRectOutline(self->position.x, self->position.y, self->size.x, self->size.y, 0xFFFF00);849850Animator animator;851RSDK.SetSpriteAnimation(UIControl->aniFrames, 0, &animator, false, 7);852RSDK.DrawSprite(&animator, NULL, false);853}854855void UIControl_EditorLoad(void) { UIControl->aniFrames = RSDK.LoadSpriteAnimation("Editor/EditorIcons.bin", SCOPE_STAGE); }856#endif857858void UIControl_Serialize(void)859{860RSDK_EDITABLE_VAR(UIControl, VAR_STRING, tag);861RSDK_EDITABLE_VAR(UIControl, VAR_STRING, parentTag);862RSDK_EDITABLE_VAR(UIControl, VAR_BOOL, activeOnLoad);863RSDK_EDITABLE_VAR(UIControl, VAR_BOOL, noWidgets);864RSDK_EDITABLE_VAR(UIControl, VAR_BOOL, resetSelection);865RSDK_EDITABLE_VAR(UIControl, VAR_UINT8, rowCount);866RSDK_EDITABLE_VAR(UIControl, VAR_UINT8, columnCount);867RSDK_EDITABLE_VAR(UIControl, VAR_UINT8, startingID);868RSDK_EDITABLE_VAR(UIControl, VAR_VECTOR2, size);869RSDK_EDITABLE_VAR(UIControl, VAR_VECTOR2, cameraOffset);870RSDK_EDITABLE_VAR(UIControl, VAR_VECTOR2, scrollSpeed);871#if MANIA_USE_PLUS872RSDK_EDITABLE_VAR(UIControl, VAR_BOOL, noClamp);873RSDK_EDITABLE_VAR(UIControl, VAR_BOOL, noWrap);874#endif875}876877878