From 1de27646d2ed57e4746f74928963b10027da5cb1 Mon Sep 17 00:00:00 2001 From: Estellar <137097857+estellarc@users.noreply.github.com> Date: Tue, 28 Oct 2025 06:19:12 -0300 Subject: [PATCH] Remove magic numbers in slot_machine.c (#2195) --- src/slot_machine.c | 59 +++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/slot_machine.c b/src/slot_machine.c index 217767fc9e..da8b3613b3 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -314,6 +314,11 @@ enum { DIG_DISPLAY_BONUS_BIG }; +// IDs for the text windows +enum { + WIN_MSG, + WIN_INFO, +}; // How ReelTime works // ================== @@ -1249,7 +1254,7 @@ static void SlotMachineSetup_LoadGfxAndTilemaps(void) LoadSlotMachineGfx(); LoadMessageBoxGfx(0, 0x200, BG_PLTT_ID(15)); LoadUserWindowBorderGfx(0, 0x214, BG_PLTT_ID(14)); - PutWindowTilemap(0); + PutWindowTilemap(WIN_MSG); } static void CreateSlotMachineSprites(void) @@ -1390,9 +1395,9 @@ static bool8 SlotTask_HandleBetInput(struct Task *task) // SLOTTASK_MSG_NEED_3_COINS static bool8 SlotTask_PrintMsg_Need3Coins(struct Task *task) { - DrawDialogueFrame(0, FALSE); - AddTextPrinterParameterized(0, FONT_NORMAL, gText_YouDontHaveThreeCoins, 0, 1, 0, 0); - CopyWindowToVram(0, COPYWIN_FULL); + DrawDialogueFrame(WIN_MSG, FALSE); + AddTextPrinterParameterized(WIN_MSG, FONT_NORMAL, gText_YouDontHaveThreeCoins, 0, 1, 0, 0); + CopyWindowToVram(WIN_MSG, COPYWIN_FULL); sSlotMachine->state = SLOTTASK_WAIT_MSG_NEED_3_COINS; return FALSE; } @@ -1402,7 +1407,7 @@ static bool8 SlotTask_WaitMsg_Need3Coins(struct Task *task) { if (JOY_NEW(A_BUTTON | B_BUTTON)) { - ClearDialogWindowAndFrame(0, TRUE); + ClearDialogWindowAndFrame(WIN_MSG, TRUE); sSlotMachine->state = SLOTTASK_BET_INPUT; } return FALSE; @@ -1655,9 +1660,9 @@ static bool8 SlotTask_NoMatches(struct Task *task) // SLOTTASK_ASK_QUIT static bool8 SlotTask_AskQuit(struct Task *task) { - DrawDialogueFrame(0, FALSE); - AddTextPrinterParameterized(0, FONT_NORMAL, gText_QuitTheGame, 0, 1, 0, 0); - CopyWindowToVram(0, COPYWIN_FULL); + DrawDialogueFrame(WIN_MSG, FALSE); + AddTextPrinterParameterized(WIN_MSG, FONT_NORMAL, gText_QuitTheGame, 0, 1, 0, 0); + CopyWindowToVram(WIN_MSG, COPYWIN_FULL); CreateYesNoMenuParameterized(0x15, 7, 0x214, 0x180, 0xE, 0xF); sSlotMachine->state = SLOTTASK_HANDLE_QUIT_INPUT; return FALSE; @@ -1669,16 +1674,16 @@ static bool8 SlotTask_HandleQuitInput(struct Task *task) s8 input = Menu_ProcessInputNoWrapClearOnChoose(); if (input == 0) // Chose to quit { - ClearDialogWindowAndFrame(0, TRUE); + ClearDialogWindowAndFrame(WIN_MSG, TRUE); DarkenBetTiles(0); DarkenBetTiles(1); DarkenBetTiles(2); sSlotMachine->coins += sSlotMachine->bet; sSlotMachine->state = SLOTTASK_END; } - else if (input == 1 || input == -1) // Chose not to quit + else if (input == 1 || input == MENU_B_PRESSED) // Chose not to quit { - ClearDialogWindowAndFrame(0, TRUE); + ClearDialogWindowAndFrame(WIN_MSG, TRUE); sSlotMachine->state = SLOTTASK_BET_INPUT; } return FALSE; @@ -1687,9 +1692,9 @@ static bool8 SlotTask_HandleQuitInput(struct Task *task) // SLOTTASK_MSG_MAX_COINS static bool8 SlotTask_PrintMsg_MaxCoins(struct Task *task) { - DrawDialogueFrame(0, FALSE); - AddTextPrinterParameterized(0, FONT_NORMAL, gText_YouveGot9999Coins, 0, 1, 0, 0); - CopyWindowToVram(0, COPYWIN_FULL); + DrawDialogueFrame(WIN_MSG, FALSE); + AddTextPrinterParameterized(WIN_MSG, FONT_NORMAL, gText_YouveGot9999Coins, 0, 1, 0, 0); + CopyWindowToVram(WIN_MSG, COPYWIN_FULL); sSlotMachine->state = SLOTTASK_WAIT_MSG_MAX_COINS; return FALSE; } @@ -1699,7 +1704,7 @@ static bool8 SlotTask_WaitMsg_MaxCoins(struct Task *task) { if (JOY_NEW(A_BUTTON | B_BUTTON)) { - ClearDialogWindowAndFrame(0, TRUE); + ClearDialogWindowAndFrame(WIN_MSG, TRUE); sSlotMachine->state = SLOTTASK_BET_INPUT; } return FALSE; @@ -1708,9 +1713,9 @@ static bool8 SlotTask_WaitMsg_MaxCoins(struct Task *task) // SLOTTASK_MSG_NO_MORE_COINS static bool8 SlotTask_PrintMsg_NoMoreCoins(struct Task *task) { - DrawDialogueFrame(0, FALSE); - AddTextPrinterParameterized(0, FONT_NORMAL, gText_YouveRunOutOfCoins, 0, 1, 0, 0); - CopyWindowToVram(0, COPYWIN_FULL); + DrawDialogueFrame(WIN_MSG, FALSE); + AddTextPrinterParameterized(WIN_MSG, FONT_NORMAL, gText_YouveRunOutOfCoins, 0, 1, 0, 0); + CopyWindowToVram(WIN_MSG, COPYWIN_FULL); sSlotMachine->state = SLOTTASK_WAIT_MSG_NO_MORE_COINS; return FALSE; } @@ -1720,7 +1725,7 @@ static bool8 SlotTask_WaitMsg_NoMoreCoins(struct Task *task) { if (JOY_NEW(A_BUTTON | B_BUTTON)) { - ClearDialogWindowAndFrame(0, TRUE); + ClearDialogWindowAndFrame(WIN_MSG, TRUE); sSlotMachine->state = SLOTTASK_END; } return FALSE; @@ -3922,15 +3927,15 @@ static void InfoBox_DrawWindow(struct Task *task) DestroyDigitalDisplayScene(); LoadInfoBoxTilemap(); AddWindow(&sWindowTemplate_InfoBox); - PutWindowTilemap(1); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); + PutWindowTilemap(WIN_INFO); + FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); task->tState++; } static void InfoBox_AddText(struct Task *task) { - AddTextPrinterParameterized3(1, FONT_NORMAL, 2, 5, sColors_ReeltimeHelp, 0, gText_ReelTimeHelp); - CopyWindowToVram(1, COPYWIN_FULL); + AddTextPrinterParameterized3(WIN_INFO, FONT_NORMAL, 2, 5, sColors_ReeltimeHelp, 0, gText_ReelTimeHelp); + CopyWindowToVram(WIN_INFO, COPYWIN_FULL); BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); task->tState++; } @@ -3939,10 +3944,10 @@ static void InfoBox_WaitInput(struct Task *task) { if (JOY_NEW(B_BUTTON | SELECT_BUTTON)) { - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - ClearWindowTilemap(1); - CopyWindowToVram(1, COPYWIN_MAP); - RemoveWindow(1); + FillWindowPixelBuffer(WIN_INFO, PIXEL_FILL(0)); + ClearWindowTilemap(WIN_INFO); + CopyWindowToVram(WIN_INFO, COPYWIN_MAP); + RemoveWindow(WIN_INFO); BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); task->tState++; }