diff --git a/graphics/unknown/unknown_DD4544.bin b/graphics/naming_screen/background.bin similarity index 100% rename from graphics/unknown/unknown_DD4544.bin rename to graphics/naming_screen/background.bin diff --git a/graphics/naming_screen/right_pointing_triangle.png b/graphics/naming_screen/input_arrow.png similarity index 100% rename from graphics/naming_screen/right_pointing_triangle.png rename to graphics/naming_screen/input_arrow.png diff --git a/graphics/naming_screen/0.pal b/graphics/naming_screen/keyboard.pal similarity index 100% rename from graphics/naming_screen/0.pal rename to graphics/naming_screen/keyboard.pal diff --git a/graphics/unknown/unknown_DD46E0.bin b/graphics/naming_screen/keyboard_lower.bin similarity index 100% rename from graphics/unknown/unknown_DD46E0.bin rename to graphics/naming_screen/keyboard_lower.bin diff --git a/graphics/unknown/unknown_DD47A0.bin b/graphics/naming_screen/keyboard_symbols.bin similarity index 100% rename from graphics/unknown/unknown_DD47A0.bin rename to graphics/naming_screen/keyboard_symbols.bin diff --git a/graphics/unknown/unknown_DD4620.bin b/graphics/naming_screen/keyboard_upper.bin similarity index 100% rename from graphics/unknown/unknown_DD4620.bin rename to graphics/naming_screen/keyboard_upper.bin diff --git a/graphics/naming_screen/keyboard_button.png b/graphics/naming_screen/page_button.png similarity index 100% rename from graphics/naming_screen/keyboard_button.png rename to graphics/naming_screen/page_button.png diff --git a/graphics/naming_screen/pc_icon/0.png b/graphics/naming_screen/pc_icon/off.png similarity index 100% rename from graphics/naming_screen/pc_icon/0.png rename to graphics/naming_screen/pc_icon/off.png diff --git a/graphics/naming_screen/pc_icon/1.png b/graphics/naming_screen/pc_icon/on.png similarity index 100% rename from graphics/naming_screen/pc_icon/1.png rename to graphics/naming_screen/pc_icon/on.png diff --git a/graphics/naming_screen/1.pal b/graphics/naming_screen/unused.pal similarity index 100% rename from graphics/naming_screen/1.pal rename to graphics/naming_screen/unused.pal diff --git a/include/global.h b/include/global.h index 9612a25f0..478c9f69a 100644 --- a/include/global.h +++ b/include/global.h @@ -102,6 +102,7 @@ #define TEST_BUTTON(field, button) ({(field) & (button);}) #define JOY_NEW(button) TEST_BUTTON(gMain.newKeys, button) #define JOY_HELD(button) TEST_BUTTON(gMain.heldKeys, button) +#define JOY_REPEAT(button) TEST_BUTTON(gMain.newAndRepeatedKeys, button) #define S16TOPOSFLOAT(val) \ ({ \ diff --git a/include/graphics.h b/include/graphics.h index c3281a75e..5dcf464eb 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4069,16 +4069,16 @@ extern const u8 gHealthboxElementsGfxTable[][32]; extern const u16 gNamingScreenMenu_Pal[]; extern const u32 gNamingScreenMenu_Gfx[]; -extern const u32 gUnknown_08DD4544[]; -extern const u8 gUnknown_08DD4620[]; -extern const u8 gUnknown_08DD46E0[]; -extern const u8 gUnknown_08DD47A0[]; +extern const u32 gNamingScreenBackground_Tilemap[]; +extern const u8 gNamingScreenKeyboardUpper_Tilemap[]; +extern const u8 gNamingScreenKeyboardLower_Tilemap[]; +extern const u8 gNamingScreenKeyboardSymbols_Tilemap[]; extern const u8 gNamingScreenRWindow_Gfx[]; -extern const u8 gNamingScreenKeyboardButton_Gfx[]; +extern const u8 gNamingScreenPageButton_Gfx[]; extern const u8 gNamingScreenROptions_Gfx[]; extern const u8 gNamingScreenCursor_Gfx[]; -extern const u8 gNamingScreenRightPointingTriangleTiles[]; -extern const u8 gNamingScreenUnderscoreTiles[]; +extern const u8 gNamingScreenInputArrow_Gfx[]; +extern const u8 gNamingScreenUnderscore_Gfx[]; extern const u32 gUnknown_08D9BA44[]; diff --git a/include/naming_screen.h b/include/naming_screen.h index 7d32abcd3..93527640e 100644 --- a/include/naming_screen.h +++ b/include/naming_screen.h @@ -3,91 +3,14 @@ #include "main.h" -#define KBEVENT_NONE 0 -#define KBEVENT_PRESSED_A 5 -#define KBEVENT_PRESSED_B 6 -#define KBEVENT_PRESSED_SELECT 8 -#define KBEVENT_PRESSED_START 9 - -#define KBROW_COUNT 4 - -enum -{ - KBPAGE_LETTERS_LOWER, - KBPAGE_LETTERS_UPPER, - KBPAGE_SYMBOLS, - KBPAGE_COUNT, -}; - -enum -{ +enum { NAMING_SCREEN_PLAYER, NAMING_SCREEN_BOX, NAMING_SCREEN_CAUGHT_MON, - NAMING_SCREEN_3, + NAMING_SCREEN_NICKNAME, NAMING_SCREEN_WALDA, }; -struct NamingScreenTemplate -{ - u8 copyExistingString; - u8 maxChars; - u8 iconFunction; - u8 addGenderIcon; - u8 initialPage; - u8 unused; - const u8 *title; -}; - -struct NamingScreenData { - /*0x0*/ u8 tilemapBuffer1[0x800]; - /*0x800*/ u8 tilemapBuffer2[0x800]; - /*0x800*/ u8 tilemapBuffer3[0x800]; - /*0x1800*/ u8 textBuffer[0x10]; - /*0x1810*/ u8 tileBuffer[0x600]; - /*0x1E10*/ u8 state; - /*0x1E11*/ u8 windows[5]; - /*0x1E16*/ u16 inputCharBaseXPos; - /*0x1E18*/ u16 bg1vOffset; - /*0x1E1A*/ u16 bg2vOffset; - /*0x1E1C*/ u16 bg1Priority; - /*0x1E1E*/ u16 bg2Priority; - /*0x1E20*/ u8 bgToReveal; - /*0x1E21*/ u8 bgToHide; - /*0x1E22*/ u8 currentPage; - /*0x1E23*/ u8 cursorSpriteId; - /*0x1E24*/ u8 selectBtnFrameSpriteId; - /*0x1E25*/ u8 keyRepeatStartDelayCopy; - /*0x1E28*/ const struct NamingScreenTemplate *template; - /*0x1E2C*/ u8 templateNum; - /*0x1E30*/ u8 *destBuffer; - /*0x1E34*/ u16 monSpecies; - /*0x1E36*/ u16 monGender; - /*0x1E38*/ u32 monPersonality; - /*0x1E3C*/ MainCallback returnCallback; -}; - - -enum -{ - MAIN_STATE_BEGIN_FADE_IN, - MAIN_STATE_WAIT_FADE_IN, - MAIN_STATE_HANDLE_INPUT, - MAIN_STATE_MOVE_TO_OK_BUTTON, - MAIN_STATE_START_PAGE_SWAP, - MAIN_STATE_WAIT_PAGE_SWAP, - MAIN_STATE_6, - MAIN_STATE_UPDATE_SENT_TO_PC_MESSAGE, - MAIN_STATE_BEGIN_FADE_OUT, -}; - -enum -{ - INPUT_STATE_DISABLED, - INPUT_STATE_ENABLED, - INPUT_STATE_2, -}; - void DoNamingScreen(u8 templateNum, u8 *destBuffer, u16 monSpecies, u16 monGender, u32 monPersonality, MainCallback returnCallback); #endif // GUARD_NAMING_SCREEN_H diff --git a/include/text_window.h b/include/text_window.h index 501597aa2..7bdcacd17 100644 --- a/include/text_window.h +++ b/include/text_window.h @@ -20,7 +20,7 @@ void LoadUserWindowBorderGfx_(u8 windowId, u16 destOffset, u8 palOffset); void DrawTextBorderOuter(u8 windowId, u16 tileNum, u8 palNum); void DrawTextBorderInner(u8 windowId, u16 tileNum, u8 palNum); void rbox_fill_rectangle(u8 windowId); -const u16 *stdpal_get(u8 id); +const u16 *GetTextWindowPalette(u8 id); const u16 *GetOverworldTextboxPalettePtr(void); void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset); diff --git a/src/battle_records.c b/src/battle_records.c index ccd16e219..c6363a6ed 100644 --- a/src/battle_records.c +++ b/src/battle_records.c @@ -494,7 +494,7 @@ static void CB2_ShowTrainerHillRecords(void) break; case 3: LoadTrainerHillRecordsWindowGfx(3); - LoadPalette(stdpal_get(0), 0xF0, 0x20); + LoadPalette(GetTextWindowPalette(0), 0xF0, 0x20); gMain.state++; break; case 4: diff --git a/src/dodrio_berry_picking.c b/src/dodrio_berry_picking.c index 5f249abad..f3963ca27 100644 --- a/src/dodrio_berry_picking.c +++ b/src/dodrio_berry_picking.c @@ -4657,7 +4657,7 @@ static bool32 sub_802A8E8(void) return FALSE; break; case 5: - LoadPalette(stdpal_get(3), 0xD0, 0x20); + LoadPalette(GetTextWindowPalette(3), 0xD0, 0x20); break; default: gUnknown_02022CF8->unk3018 = 0; diff --git a/src/egg_hatch.c b/src/egg_hatch.c index db25dbbb8..3ccc7ebf8 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -672,7 +672,7 @@ static void CB2_EggHatch_1(void) species = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_SPECIES); gender = GetMonGender(&gPlayerParty[sEggHatchData->eggPartyID]); personality = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_PERSONALITY, 0); - DoNamingScreen(3, gStringVar3, species, gender, personality, EggHatchSetMonNickname); + DoNamingScreen(NAMING_SCREEN_NICKNAME, gStringVar3, species, gender, personality, EggHatchSetMonNickname); break; case 1: case -1: diff --git a/src/frontier_pass.c b/src/frontier_pass.c index 757205656..024a954d1 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -735,7 +735,7 @@ static bool32 InitFrontierPass(void) case 8: LoadPalette(gUnknown_08DE07C8[0], 0, 0x1A0); LoadPalette(gUnknown_08DE07C8[1 + sPassData->trainerStars], 0x10, 0x20); - LoadPalette(stdpal_get(0), 0xF0, 0x20); + LoadPalette(GetTextWindowPalette(0), 0xF0, 0x20); sub_80C629C(); sub_80C6104(sPassData->cursorArea, sPassData->previousCursorArea); if (sPassData->unkE == 1 || sPassData->unkE == 2) @@ -1378,7 +1378,7 @@ static bool32 InitFrontierMap(void) if (FreeTempTileDataBuffersIfPossible()) return FALSE; LoadPalette(gUnknown_08DE07C8[0], 0, 0x1A0); - LoadPalette(stdpal_get(0), 0xF0, 0x20); + LoadPalette(GetTextWindowPalette(0), 0xF0, 0x20); CopyToBgTilemapBuffer(2, gUnknown_08570E00, 0, 0); CopyBgTilemapBufferToVram(2); break; diff --git a/src/graphics.c b/src/graphics.c index 48323467d..18734c1b2 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1436,15 +1436,13 @@ const u32 gNamingScreenMenu_Gfx[] = INCBIN_U32("graphics/naming_screen/menu.4bpp const u8 gNamingScreenRWindow_Gfx[] = INCBIN_U8("graphics/naming_screen/rwindow.4bpp"); const u8 gNamingScreenROptions_Gfx[] = INCBIN_U8("graphics/naming_screen/roptions.4bpp"); const u8 gNamingScreenCursor_Gfx[] = INCBIN_U8("graphics/naming_screen/cursor.4bpp"); -const u8 gNamingScreenKeyboardButton_Gfx[] = INCBIN_U8("graphics/naming_screen/keyboard_button.4bpp"); - -const u8 gNamingScreenRightPointingTriangleTiles[] = INCBIN_U8("graphics/naming_screen/right_pointing_triangle.4bpp"); -const u8 gNamingScreenUnderscoreTiles[] = INCBIN_U8("graphics/naming_screen/underscore.4bpp"); - -const u32 gUnknown_08DD4544[] = INCBIN_U32("graphics/unknown/unknown_DD4544.bin.lz"); -const u32 gUnknown_08DD4620[] = INCBIN_U32("graphics/unknown/unknown_DD4620.bin.lz"); -const u32 gUnknown_08DD46E0[] = INCBIN_U32("graphics/unknown/unknown_DD46E0.bin.lz"); -const u32 gUnknown_08DD47A0[] = INCBIN_U32("graphics/unknown/unknown_DD47A0.bin.lz"); +const u8 gNamingScreenPageButton_Gfx[] = INCBIN_U8("graphics/naming_screen/page_button.4bpp"); +const u8 gNamingScreenInputArrow_Gfx[] = INCBIN_U8("graphics/naming_screen/input_arrow.4bpp"); +const u8 gNamingScreenUnderscore_Gfx[] = INCBIN_U8("graphics/naming_screen/underscore.4bpp"); +const u32 gNamingScreenBackground_Tilemap[] = INCBIN_U32("graphics/naming_screen/background.bin.lz"); +const u32 gNamingScreenKeyboardUpper_Tilemap[] = INCBIN_U32("graphics/naming_screen/keyboard_upper.bin.lz"); +const u32 gNamingScreenKeyboardLower_Tilemap[] = INCBIN_U32("graphics/naming_screen/keyboard_lower.bin.lz"); +const u32 gNamingScreenKeyboardSymbols_Tilemap[] = INCBIN_U32("graphics/naming_screen/keyboard_symbols.bin.lz"); // union room chat const u16 gUnionRoomChat_Background_Pal[] = INCBIN_U16("graphics/union_room_chat/background.gbapal"); diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index f4c971b0b..19217ae85 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -702,7 +702,7 @@ static void Task_Hof_DisplayPlayer(u8 taskId) gTasks[taskId].tPlayerSpriteID = CreateTrainerPicSprite(PlayerGenderToFrontTrainerPicId_Debug(gSaveBlock2Ptr->playerGender, TRUE), 1, 120, 72, 6, 0xFFFF); AddWindow(&sHof_WindowTemplate); LoadWindowGfx(1, gSaveBlock2Ptr->optionsWindowFrameType, 0x21D, 0xD0); - LoadPalette(stdpal_get(1), 0xE0, 0x20); + LoadPalette(GetTextWindowPalette(1), 0xE0, 0x20); gTasks[taskId].tFrameCount = 120; gTasks[taskId].func = Task_Hof_WaitAndPrintPlayerInfo; } diff --git a/src/main_menu.c b/src/main_menu.c index 781d7f85c..a4de99207 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -1609,7 +1609,7 @@ static void Task_NewGameBirchSpeech_StartNamingScreen(u8 taskId) FreeAndDestroyMonPicSprite(gTasks[taskId].tLotadSpriteId); NewGameBirchSpeech_SetDefaultPlayerName(Random() % 20); DestroyTask(taskId); - DoNamingScreen(0, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_NewGameBirchSpeech_ReturnFromNamingScreen); + DoNamingScreen(NAMING_SCREEN_PLAYER, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_NewGameBirchSpeech_ReturnFromNamingScreen); } } diff --git a/src/mevent_801BAAC.c b/src/mevent_801BAAC.c index 1bfac23d1..847449c45 100644 --- a/src/mevent_801BAAC.c +++ b/src/mevent_801BAAC.c @@ -208,7 +208,7 @@ s32 FadeToWonderCardMenu(void) case 3: if (FreeTempTileDataBuffersIfPossible()) return 0; - LoadPalette(stdpal_get(1), 0x20, 0x20); + LoadPalette(GetTextWindowPalette(1), 0x20, 0x20); gPaletteFade.bufferTransferDisabled = TRUE; LoadPalette(sWonderCardData->unk_0170->pal, 0x10, 0x20); LZ77UnCompWram(sWonderCardData->unk_0170->map, sWonderCardData->buffer_045C); @@ -607,7 +607,7 @@ s32 FadeToWonderNewsMenu(void) case 3: if (FreeTempTileDataBuffersIfPossible()) return 0; - LoadPalette(stdpal_get(1), 0x20, 0x20); + LoadPalette(GetTextWindowPalette(1), 0x20, 0x20); gPaletteFade.bufferTransferDisabled = TRUE; LoadPalette(sWonderNewsData->unk_01BC->pal, 0x10, 0x20); LZ77UnCompWram(sWonderNewsData->unk_01BC->map, sWonderNewsData->buffer_03A4); diff --git a/src/mystery_gift.c b/src/mystery_gift.c index 9672fe0ec..e6b311f0a 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -410,7 +410,7 @@ bool32 HandleMysteryGiftOrEReaderSetup(s32 mg_or_ereader) break; case 1: LoadPalette(gUnkTextboxBorderPal, 0, 0x20); - LoadPalette(stdpal_get(2), 0xd0, 0x20); + LoadPalette(GetTextWindowPalette(2), 0xd0, 0x20); Menu_LoadStdPalAt(0xC0); LoadUserWindowBorderGfx(0, 0xA, 0xE0); LoadUserWindowBorderGfx_(0, 0x1, 0xF0); diff --git a/src/naming_screen.c b/src/naming_screen.c index ab38db745..4ed9d78d0 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -28,7 +28,157 @@ #include "constants/event_objects.h" #include "constants/rgb.h" -EWRAM_DATA static struct NamingScreenData *gNamingScreenData = NULL; +enum { + INPUT_NONE, + INPUT_DPAD_UP, + INPUT_DPAD_DOWN, + INPUT_DPAD_LEFT, + INPUT_DPAD_RIGHT, + INPUT_A_BUTTON, + INPUT_B_BUTTON, + INPUT_LR_BUTTON, + INPUT_SELECT, + INPUT_START, +}; + +#define KBROW_COUNT 4 +#define KBCOL_COUNT 8 + +enum { + GFXTAG_BACK_BUTTON, + GFXTAG_OK_BUTTON, + GFXTAG_PAGE_SWAP_FRAME, + GFXTAG_PAGE_SWAP_BUTTON, + GFXTAG_PAGE_SWAP_UPPER, + GFXTAG_PAGE_SWAP_LOWER, + GFXTAG_PAGE_SWAP_OTHERS, + GFXTAG_CURSOR, + GFXTAG_CURSOR_SQUISHED, + GFXTAG_CURSOR_FILLED, + GFXTAG_INPUT_ARROW, + GFXTAG_UNDERSCORE, +}; + +enum { + PALTAG_PC_ICON, + PALTAG_PAGE_SWAP_UPPER, + PALTAG_PAGE_SWAP_LOWER, + PALTAG_PAGE_SWAP_OTHERS, + PALTAG_PAGE_SWAP, + PALTAG_CURSOR, + PALTAG_BACK_BUTTON, + PALTAG_OK_BUTTON, +}; + +enum { + WIN_KB_PAGE_1, // Which of these two windows is in front is cycled as the player swaps + WIN_KB_PAGE_2, // Initially WIN_KB_PAGE_1 is in front, with WIN_KB_PAGE_2 on deck + WIN_TEXT_ENTRY, + WIN_TEXT_ENTRY_BOX, + WIN_BANNER, + WIN_COUNT, +}; + +// The constants for the pages are needlessly complicated because GF didn't keep the indexing order consistent +// This set is used for sNamingScreen->currentPage. It uses the order that the pages are cycled in +enum { + KBPAGE_SYMBOLS, + KBPAGE_LETTERS_UPPER, + KBPAGE_LETTERS_LOWER, + KBPAGE_COUNT, +}; + +// This set is used for initializing a page's keyboard text and getting its number of columns +enum { + KEYBOARD_LETTERS_LOWER, + KEYBOARD_LETTERS_UPPER, + KEYBOARD_SYMBOLS, +}; + +// This set is used for getting the gfx/pal tags of the page's swap button +enum { + PAGE_SWAP_UPPER, + PAGE_SWAP_OTHERS, + PAGE_SWAP_LOWER, +}; + +enum { + KEY_ROLE_CHAR, + KEY_ROLE_PAGE, + KEY_ROLE_BACKSPACE, + KEY_ROLE_OK, +}; + +enum { + BUTTON_PAGE, + BUTTON_BACK, + BUTTON_OK, + BUTTON_COUNT, +}; + +// states for Task_NamingScreen +enum { + STATE_FADE_IN, + STATE_WAIT_FADE_IN, + STATE_HANDLE_INPUT, + STATE_MOVE_TO_OK_BUTTON, + STATE_START_PAGE_SWAP, + STATE_WAIT_PAGE_SWAP, + STATE_PRESSED_OK, + STATE_WAIT_SENT_TO_PC_MESSAGE, + STATE_FADE_OUT, + STATE_EXIT, +}; + +// sates for Task_HandleInput +enum +{ + INPUT_STATE_DISABLED, + INPUT_STATE_ENABLED, + INPUT_STATE_OVERRIDE, +}; + +struct NamingScreenTemplate +{ + u8 copyExistingString; + u8 maxChars; + u8 iconFunction; + u8 addGenderIcon; + u8 initialPage; + u8 unused; + const u8 *title; +}; + +struct NamingScreenData +{ + u8 tilemapBuffer1[0x800]; + u8 tilemapBuffer2[0x800]; + u8 tilemapBuffer3[0x800]; + u8 textBuffer[16]; + u8 tileBuffer[0x600]; + u8 state; + u8 windows[WIN_COUNT]; + u16 inputCharBaseXPos; + u16 bg1vOffset; + u16 bg2vOffset; + u16 bg1Priority; + u16 bg2Priority; + u8 bgToReveal; + u8 bgToHide; + u8 currentPage; + u8 cursorSpriteId; + u8 swapBtnFrameSpriteId; + u8 keyRepeatStartDelayCopy; + const struct NamingScreenTemplate *template; + u8 templateNum; + u8 *destBuffer; + u16 monSpecies; + u16 monGender; + u32 monPersonality; + MainCallback returnCallback; +}; + +EWRAM_DATA static struct NamingScreenData *sNamingScreen = NULL; extern u16 gKeyRepeatStartDelay; // extern text @@ -40,10 +190,10 @@ extern const u8 gText_TellHimTheWords[]; // start of .rodata -static const u8 gSpriteImage_858BBF8[] = INCBIN_U8("graphics/naming_screen/pc_icon/0.4bpp"); -static const u8 gSpriteImage_858BCB8[] = INCBIN_U8("graphics/naming_screen/pc_icon/1.4bpp"); -static const u16 gUnknown_0858BD78[] = INCBIN_U16("graphics/naming_screen/0.gbapal"); -static const u16 gUnknown_0858BD98[] = INCBIN_U16("graphics/naming_screen/1.gbapal"); +static const u8 sPCIconOff_Gfx[] = INCBIN_U8("graphics/naming_screen/pc_icon/off.4bpp"); +static const u8 sPCIconOn_Gfx[] = INCBIN_U8("graphics/naming_screen/pc_icon/on.4bpp"); +static const u16 sKeyboard_Pal[] = INCBIN_U16("graphics/naming_screen/keyboard.gbapal"); +static const u16 sUnused_Pal[] = INCBIN_U16("graphics/naming_screen/unused.gbapal"); static const u8 *const sTransferredToPCMessages[] = { @@ -55,7 +205,7 @@ static const u8 *const sTransferredToPCMessages[] = static const u8 sText_AlphabetUpperLower[] = _("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!"); -static const struct BgTemplate gUnknown_0858BE00[] = +static const struct BgTemplate sBgTemplates[] = { { .bg = 0, @@ -83,9 +233,9 @@ static const struct BgTemplate gUnknown_0858BE00[] = } }; -static const struct WindowTemplate gUnknown_0858BE10[] = +static const struct WindowTemplate sWindowTemplates[WIN_COUNT + 1] = { - { + [WIN_KB_PAGE_1] = { .bg = 1, .tilemapLeft = 3, .tilemapTop = 10, @@ -94,7 +244,7 @@ static const struct WindowTemplate gUnknown_0858BE10[] = .paletteNum = 10, .baseBlock = 0x030 }, - { + [WIN_KB_PAGE_2] = { .bg = 2, .tilemapLeft = 3, .tilemapTop = 10, @@ -103,7 +253,7 @@ static const struct WindowTemplate gUnknown_0858BE10[] = .paletteNum = 10, .baseBlock = 0x0C8 }, - { + [WIN_TEXT_ENTRY] = { .bg = 3, .tilemapLeft = 8, .tilemapTop = 6, @@ -112,7 +262,7 @@ static const struct WindowTemplate gUnknown_0858BE10[] = .paletteNum = 10, .baseBlock = 0x030 }, - { + [WIN_TEXT_ENTRY_BOX] = { .bg = 3, .tilemapLeft = 8, .tilemapTop = 4, @@ -121,7 +271,7 @@ static const struct WindowTemplate gUnknown_0858BE10[] = .paletteNum = 10, .baseBlock = 0x052 }, - { + [WIN_BANNER] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 0, @@ -133,124 +283,146 @@ static const struct WindowTemplate gUnknown_0858BE10[] = DUMMY_WIN_TEMPLATE }; -static const u8 gUnknown_0858BE40[] = __("abcdef .ghijkl ,mnopqrs tuvwxyz ABCDEF .GHIJKL ,MNOPQRS TUVWXYZ 01234 56789 !?♂♀/- …“”‘' "); +// This handles what characters get inserted when a key is pressed +// The keys shown on the keyboard are handled separately by sNamingScreenKeyboardText +static const u8 sKeyboardChars[KBPAGE_COUNT * KBROW_COUNT * KBCOL_COUNT] = __( + "abcdef ." + "ghijkl ," + "mnopqrs " + "tuvwxyz " + "ABCDEF ." + "GHIJKL ," + "MNOPQRS " + "TUVWXYZ " + "01234 " + "56789 " + "!?♂♀/- " + "…“”‘' "); -static const u8 gUnknown_0858BEA0[] = { 8, 8, 6 }; -static const u8 gUnknown_0858BEA3[] = { 0, 12, 24, 56, 68, 80, 92, 123, 0, 12, 24, 56, 68, 80, 92, 123, 0, 22, 44, 66, 88, 110, 0, 0 }; +static const u8 sPageColumnCounts[KBPAGE_COUNT] = { + [KEYBOARD_LETTERS_LOWER] = KBCOL_COUNT, + [KEYBOARD_LETTERS_UPPER] = KBCOL_COUNT, + [KEYBOARD_SYMBOLS] = 6 +}; +static const u8 sPageColumnXPos[KBPAGE_COUNT * KBCOL_COUNT] = { + 0, 12, 24, 56, 68, 80, 92, 123, // KEYBOARD_LETTERS_LOWER + 0, 12, 24, 56, 68, 80, 92, 123, // KEYBOARD_LETTERS_UPPER + 0, 22, 44, 66, 88, 110 // KEYBOARD_SYMBOLS +}; // forward declarations static const struct NamingScreenTemplate *const sNamingScreenTemplates[]; -static const struct SubspriteTable gUnknown_0858C050[]; -static const struct SubspriteTable gUnknown_0858C058[]; -static const struct SubspriteTable gUnknown_0858C070[]; -static const struct SubspriteTable gUnknown_0858C078[]; -static const struct SpriteTemplate gUnknown_0858C0C0; -static const struct SpriteTemplate gUnknown_0858C0D8; -static const struct SpriteTemplate gUnknown_0858C0F0; -static const struct SpriteTemplate gUnknown_0858C108; -static const struct SpriteTemplate gUnknown_0858C120; -static const struct SpriteTemplate gUnknown_0858C138; +static const struct SubspriteTable sSubspriteTable_PageSwapFrame[]; +static const struct SubspriteTable sSubspriteTable_PageSwapText[]; +static const struct SubspriteTable sSubspriteTable_Button[]; +static const struct SubspriteTable sSubspriteTable_PCIcon[]; +static const struct SpriteTemplate sSpriteTemplate_PageSwapFrame; +static const struct SpriteTemplate sSpriteTemplate_PageSwapButton; +static const struct SpriteTemplate sSpriteTemplate_PageSwapText; +static const struct SpriteTemplate sSpriteTemplate_BackButton; +static const struct SpriteTemplate sSpriteTemplate_OkButton; +static const struct SpriteTemplate sSpriteTemplate_Cursor; static const struct SpriteTemplate sSpriteTemplate_InputArrow; static const struct SpriteTemplate sSpriteTemplate_Underscore; -static const struct SpriteTemplate gUnknown_0858C180; +static const struct SpriteTemplate sSpriteTemplate_PCIcon; static const u8* const sNamingScreenKeyboardText[KBPAGE_COUNT][KBROW_COUNT]; -static const struct SpriteSheet gUnknown_0858C1C8[]; -static const struct SpritePalette gUnknown_0858C230[]; +static const struct SpriteSheet sSpriteSheets[]; +static const struct SpritePalette sSpritePalettes[]; -static void C2_NamingScreen(void); +static void CB2_LoadNamingScreen(void); static void NamingScreen_Init(void); static void NamingScreen_InitBGs(void); -static void sub_80E3194(void); -static void sub_80E31B0(u8 taskId); -static bool8 MainState_BeginFadeIn(void); +static void CreateNamingScreenTask(void); +static void Task_NamingScreen(u8 taskId); +static bool8 MainState_FadeIn(void); static bool8 MainState_WaitFadeIn(void); static bool8 MainState_HandleInput(void); static bool8 MainState_MoveToOKButton(void); -static bool8 MainState_6(void); -static bool8 MainState_BeginFadeInOut(void); -static bool8 MainState_WaitFadeOutAndExit(void); +static bool8 MainState_PressedOKButton(void); +static bool8 MainState_FadeOut(void); +static bool8 MainState_Exit(void); static void DisplaySentToPCMessage(void); -static bool8 sub_80E3604(void); +static bool8 MainState_WaitSentToPCMessage(void); static bool8 MainState_StartPageSwap(void); static bool8 MainState_WaitPageSwap(void); static void StartPageSwapAnim(void); static void Task_HandlePageSwapAnim(u8); static bool8 IsPageSwapAnimNotInProgress(void); -static void sub_80E3948(u8, u8, u8); -static void Task_80E39BC(u8); -static u16 sub_80E3A74(u8); -static void sub_80E3AE8(u8); -static void sub_80E3B10(struct Task *, u8, u8); -static void sub_80E3CC8(void); -static void CursorInit(void); +static void TryStartButtonFlash(u8, bool8, bool8); +static void Task_UpdateButtonFlash(u8); +static u16 GetButtonPalOffset(u8); +static void RestoreButtonColor(u8); +static void StartButtonFlash(struct Task *, u8, bool8); +static void CreateSprites(void); +static void CreateCursorSprite(void); static void SetCursorPos(s16, s16); static void GetCursorPos(s16 *x, s16 *y); static void MoveCursorToOKButton(void); -static void sub_80E3E3C(u8); -static void sub_80E3E94(u8); +static void SetCursorInvisibility(u8); +static void SetCursorFlashing(bool8); static u8 IsCursorAnimFinished(void); static u8 GetCurrentPageColumnCount(void); -static void CreatePageSwitcherSprites(void); -static void sub_80E4050(void); -static void sub_80E41B8(u8, struct Sprite *, struct Sprite *); +static void CreatePageSwapButtonSprites(void); +static void StartPageSwapButtonAnim(void); +static void SetPageSwapButtonGfx(u8, struct Sprite *, struct Sprite *); static void CreateBackOkSprites(void); -static void CreateUnderscoreSprites(void); +static void CreateTextEntrySprites(void); static void CreateInputTargetIcon(void); static u8 HandleKeyboardEvent(void); -static u8 sub_80E45E0(void); +static u8 SwapKeyboardPage(void); static u8 GetInputEvent(void); static void SetInputState(u8); -static void sub_80E4964(void); -static u8 GetTextCaretPosition(void); +static void DrawTextEntryBox(void); +static u8 GetTextEntryPosition(void); static void DeleteTextCharacter(void); -static bool8 sub_80E4B54(void); -static void AddTextCharacter(u8); -static void sub_80E4BE4(void); -static void choose_name_or_words_screen_load_bg_tile_patterns(void); -static void sub_80E4CB8(void); -static void choose_name_or_words_screen_apply_bg_pals(void); -static void sub_80E4CF8(u8, const void *); -static void nullsub_10(u8, u8); -static void sub_80E4D10(void); -static void sub_80E4DE4(u8, u8); -static void sub_80E4E5C(void); -static void sub_80E4EF0(void); -static void sub_80E4F58(void); -static void NamingScreen_TurnOffScreen(void); -static void NamingScreen_InitDisplayMode(void); +static bool8 AddTextCharacter(void); +static void BufferCharacter(u8); +static void SaveInputText(void); +static void LoadGfx(void); +static void CreateHelperTasks(void); +static void LoadPalettes(void); +static void DrawBgTilemap(u8, const void *); +static void NamingScreen_Dummy(u8, u8); +static void DrawTextEntry(void); +static void PrintKeyboardKeys(u8, u8); +static void DrawKeyboardPageOnDeck(void); +static void PrintControls(void); +static void CB2_NamingScreen(void); +static void ResetVHBlank(void); +static void SetVBlank(void); static void VBlankCB_NamingScreen(void); -static void sub_80E501C(void); -static bool8 IsLetter(u8); +static void NamingScreen_ShowBgs(void); +static bool8 IsWideLetter(u8); void DoNamingScreen(u8 templateNum, u8 *destBuffer, u16 monSpecies, u16 monGender, u32 monPersonality, MainCallback returnCallback) { - gNamingScreenData = Alloc(sizeof(struct NamingScreenData)); - if (!gNamingScreenData) + sNamingScreen = Alloc(sizeof(struct NamingScreenData)); + if (!sNamingScreen) { SetMainCallback2(returnCallback); } else { - gNamingScreenData->templateNum = templateNum; - gNamingScreenData->monSpecies = monSpecies; - gNamingScreenData->monGender = monGender; - gNamingScreenData->monPersonality = monPersonality; - gNamingScreenData->destBuffer = destBuffer; - gNamingScreenData->returnCallback = returnCallback; + sNamingScreen->templateNum = templateNum; + sNamingScreen->monSpecies = monSpecies; + sNamingScreen->monGender = monGender; + sNamingScreen->monPersonality = monPersonality; + sNamingScreen->destBuffer = destBuffer; + sNamingScreen->returnCallback = returnCallback; - if (templateNum == 0) + if (templateNum == NAMING_SCREEN_PLAYER) StartTimer1(); - SetMainCallback2(C2_NamingScreen); + SetMainCallback2(CB2_LoadNamingScreen); } } -static void C2_NamingScreen(void) +static void CB2_LoadNamingScreen(void) { switch (gMain.state) { case 0: - NamingScreen_TurnOffScreen(); + ResetVHBlank(); NamingScreen_Init(); gMain.state++; break; @@ -272,48 +444,48 @@ static void C2_NamingScreen(void) gMain.state++; break; case 5: - choose_name_or_words_screen_apply_bg_pals(); + LoadPalettes(); gMain.state++; break; case 6: - choose_name_or_words_screen_load_bg_tile_patterns(); + LoadGfx(); gMain.state++; break; case 7: - sub_80E3CC8(); + CreateSprites(); UpdatePaletteFade(); - sub_80E501C(); + NamingScreen_ShowBgs(); gMain.state++; break; default: - sub_80E4CB8(); - sub_80E3194(); + CreateHelperTasks(); + CreateNamingScreenTask(); break; } } static void NamingScreen_Init(void) { - gNamingScreenData->state = 0; - gNamingScreenData->bg1vOffset = 0; - gNamingScreenData->bg2vOffset = 0; - gNamingScreenData->bg1Priority = BGCNT_PRIORITY(1); - gNamingScreenData->bg2Priority = BGCNT_PRIORITY(2); - gNamingScreenData->bgToReveal = 0; - gNamingScreenData->bgToHide = 1; - gNamingScreenData->template = sNamingScreenTemplates[gNamingScreenData->templateNum]; - gNamingScreenData->currentPage = gNamingScreenData->template->initialPage; - gNamingScreenData->inputCharBaseXPos = (240 - gNamingScreenData->template->maxChars * 8) / 2 + 6; - if (gNamingScreenData->templateNum == 4) - gNamingScreenData->inputCharBaseXPos += 11; - gNamingScreenData->keyRepeatStartDelayCopy = gKeyRepeatStartDelay; - memset(gNamingScreenData->textBuffer, 0xFF, sizeof(gNamingScreenData->textBuffer)); - if (gNamingScreenData->template->copyExistingString != 0) - StringCopy(gNamingScreenData->textBuffer, gNamingScreenData->destBuffer); + sNamingScreen->state = STATE_FADE_IN; + sNamingScreen->bg1vOffset = 0; + sNamingScreen->bg2vOffset = 0; + sNamingScreen->bg1Priority = BGCNT_PRIORITY(1); + sNamingScreen->bg2Priority = BGCNT_PRIORITY(2); + sNamingScreen->bgToReveal = 0; + sNamingScreen->bgToHide = 1; + sNamingScreen->template = sNamingScreenTemplates[sNamingScreen->templateNum]; + sNamingScreen->currentPage = sNamingScreen->template->initialPage; + sNamingScreen->inputCharBaseXPos = (240 - sNamingScreen->template->maxChars * 8) / 2 + 6; + if (sNamingScreen->templateNum == NAMING_SCREEN_WALDA) + sNamingScreen->inputCharBaseXPos += 11; + sNamingScreen->keyRepeatStartDelayCopy = gKeyRepeatStartDelay; + memset(sNamingScreen->textBuffer, EOS, sizeof(sNamingScreen->textBuffer)); + if (sNamingScreen->template->copyExistingString) + StringCopy(sNamingScreen->textBuffer, sNamingScreen->destBuffer); gKeyRepeatStartDelay = 16; } -static void sub_80E2FA4(void) +static void SetSpritesVisible(void) { u8 i; for (i = 0; i < MAX_SPRITES; i++) @@ -321,7 +493,7 @@ static void sub_80E2FA4(void) if (gSprites[i].inUse) gSprites[i].invisible = FALSE; } - sub_80E3E3C(0); + SetCursorInvisibility(FALSE); } static void NamingScreen_InitBGs(void) @@ -334,7 +506,7 @@ static void NamingScreen_InitBGs(void) SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, gUnknown_0858BE00, 4); + InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); @@ -348,123 +520,124 @@ static void NamingScreen_InitBGs(void) InitStandardTextBoxWindows(); InitTextBoxGfxAndPrinters(); - for (i = 0; i < 5; i++) - gNamingScreenData->windows[i] = AddWindow(&gUnknown_0858BE10[i]); + for (i = 0; i < WIN_COUNT; i++) + sNamingScreen->windows[i] = AddWindow(&sWindowTemplates[i]); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2); - SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0xC, 0x8)); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(12, 8)); - SetBgTilemapBuffer(1, gNamingScreenData->tilemapBuffer1); - SetBgTilemapBuffer(2, gNamingScreenData->tilemapBuffer2); - SetBgTilemapBuffer(3, gNamingScreenData->tilemapBuffer3); + SetBgTilemapBuffer(1, sNamingScreen->tilemapBuffer1); + SetBgTilemapBuffer(2, sNamingScreen->tilemapBuffer2); + SetBgTilemapBuffer(3, sNamingScreen->tilemapBuffer3); FillBgTilemapBufferRect_Palette0(1, 0, 0, 0, 0x20, 0x20); FillBgTilemapBufferRect_Palette0(2, 0, 0, 0, 0x20, 0x20); FillBgTilemapBufferRect_Palette0(3, 0, 0, 0, 0x20, 0x20); } -static void sub_80E3194(void) +static void CreateNamingScreenTask(void) { - CreateTask(sub_80E31B0, 2); - SetMainCallback2(sub_80E4F58); + CreateTask(Task_NamingScreen, 2); + SetMainCallback2(CB2_NamingScreen); } -static void sub_80E31B0(u8 taskId) +static void Task_NamingScreen(u8 taskId) { - switch (gNamingScreenData->state) + switch (sNamingScreen->state) { - case 0: - MainState_BeginFadeIn(); - sub_80E2FA4(); - NamingScreen_InitDisplayMode(); + case STATE_FADE_IN: + MainState_FadeIn(); + SetSpritesVisible(); + SetVBlank(); break; - case 1: + case STATE_WAIT_FADE_IN: MainState_WaitFadeIn(); break; - case 2: + case STATE_HANDLE_INPUT: MainState_HandleInput(); break; - case 3: + case STATE_MOVE_TO_OK_BUTTON: MainState_MoveToOKButton(); MainState_HandleInput(); break; - case 4: + case STATE_START_PAGE_SWAP: MainState_StartPageSwap(); break; - case 5: + case STATE_WAIT_PAGE_SWAP: MainState_WaitPageSwap(); break; - case 6: - MainState_6(); + case STATE_PRESSED_OK: + MainState_PressedOKButton(); break; - case 7: - sub_80E3604(); + case STATE_WAIT_SENT_TO_PC_MESSAGE: + MainState_WaitSentToPCMessage(); break; - case 8: - MainState_BeginFadeInOut(); + case STATE_FADE_OUT: + MainState_FadeOut(); break; - case 9: - MainState_WaitFadeOutAndExit(); + case STATE_EXIT: + MainState_Exit(); break; } } -static const u8 sPageOrderLowerFirst[] = +// Which gfx/pal to load for the swap page button +static const u8 sPageToNextGfxId[KBPAGE_COUNT] = { - KBPAGE_LETTERS_LOWER, - KBPAGE_SYMBOLS, - KBPAGE_LETTERS_UPPER + [KBPAGE_SYMBOLS] = PAGE_SWAP_UPPER, + [KBPAGE_LETTERS_UPPER] = PAGE_SWAP_LOWER, + [KBPAGE_LETTERS_LOWER] = PAGE_SWAP_OTHERS }; -static const u8 sPageOrderUpperFirst[] = +static const u8 sPageToNextKeyboardId[KBPAGE_COUNT] = { - KBPAGE_LETTERS_UPPER, - KBPAGE_LETTERS_LOWER, - KBPAGE_SYMBOLS + [KBPAGE_SYMBOLS] = KEYBOARD_LETTERS_UPPER, + [KBPAGE_LETTERS_UPPER] = KEYBOARD_LETTERS_LOWER, + [KBPAGE_LETTERS_LOWER] = KEYBOARD_SYMBOLS }; -static const u8 sPageOrderSymbolsFirst[] = +static const u8 sPageToKeyboardId[KBPAGE_COUNT] = { - KBPAGE_SYMBOLS, - KBPAGE_LETTERS_UPPER, - KBPAGE_LETTERS_LOWER + [KBPAGE_SYMBOLS] = KEYBOARD_SYMBOLS, + [KBPAGE_LETTERS_UPPER] = KEYBOARD_LETTERS_UPPER, + [KBPAGE_LETTERS_LOWER] = KEYBOARD_LETTERS_LOWER }; -static u8 sub_80E3244(u8 a1) +static u8 PageToNextGfxId(u8 page) { - return sPageOrderLowerFirst[a1]; + return sPageToNextGfxId[page]; } -static u8 sub_80E3254(void) +static u8 CurrentPageToNextKeyboardId(void) { - return sPageOrderUpperFirst[gNamingScreenData->currentPage]; + return sPageToNextKeyboardId[sNamingScreen->currentPage]; } -static u8 sub_80E3274(void) +static u8 CurrentPageToKeyboardId(void) { - return sPageOrderSymbolsFirst[gNamingScreenData->currentPage]; + return sPageToKeyboardId[sNamingScreen->currentPage]; } -static bool8 MainState_BeginFadeIn(void) +static bool8 MainState_FadeIn(void) { - sub_80E4CF8(3, gUnknown_08DD4544); - gNamingScreenData->currentPage = KBPAGE_LETTERS_UPPER; - sub_80E4CF8(2, gUnknown_08DD46E0); - sub_80E4CF8(1, gUnknown_08DD4620); - sub_80E4DE4(gNamingScreenData->windows[1], KBPAGE_LETTERS_LOWER); - sub_80E4DE4(gNamingScreenData->windows[0], KBPAGE_LETTERS_UPPER); - nullsub_10(2, KBPAGE_LETTERS_LOWER); - nullsub_10(1, KBPAGE_LETTERS_UPPER); - sub_80E4D10(); - sub_80E4964(); - sub_80E4EF0(); + DrawBgTilemap(3, gNamingScreenBackground_Tilemap); + sNamingScreen->currentPage = KBPAGE_LETTERS_UPPER; + DrawBgTilemap(2, gNamingScreenKeyboardLower_Tilemap); + DrawBgTilemap(1, gNamingScreenKeyboardUpper_Tilemap); + PrintKeyboardKeys(sNamingScreen->windows[WIN_KB_PAGE_2], KEYBOARD_LETTERS_LOWER); + PrintKeyboardKeys(sNamingScreen->windows[WIN_KB_PAGE_1], KEYBOARD_LETTERS_UPPER); + NamingScreen_Dummy(2, KEYBOARD_LETTERS_LOWER); + NamingScreen_Dummy(1, KEYBOARD_LETTERS_UPPER); + DrawTextEntry(); + DrawTextEntryBox(); + PrintControls(); CopyBgTilemapBufferToVram(1); CopyBgTilemapBufferToVram(2); CopyBgTilemapBufferToVram(3); BlendPalettes(-1, 16, 0); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK); - gNamingScreenData->state++; + sNamingScreen->state++; return FALSE; } @@ -473,8 +646,8 @@ static bool8 MainState_WaitFadeIn(void) if (!gPaletteFade.active) { SetInputState(INPUT_STATE_ENABLED); - sub_80E3E94(1); - gNamingScreenData->state++; + SetCursorFlashing(TRUE); + sNamingScreen->state++; } return FALSE; } @@ -490,48 +663,48 @@ static bool8 MainState_MoveToOKButton(void) { SetInputState(INPUT_STATE_ENABLED); MoveCursorToOKButton(); - gNamingScreenData->state = MAIN_STATE_HANDLE_INPUT; + sNamingScreen->state = STATE_HANDLE_INPUT; } return FALSE; } -static bool8 MainState_6(void) +static bool8 MainState_PressedOKButton(void) { - sub_80E4BE4(); + SaveInputText(); SetInputState(INPUT_STATE_DISABLED); - sub_80E3E94(0); - sub_80E3948(3, 0, 1); - if (gNamingScreenData->templateNum == NAMING_SCREEN_CAUGHT_MON && - CalculatePlayerPartyCount() >= 6) + SetCursorFlashing(FALSE); + TryStartButtonFlash(BUTTON_COUNT, FALSE, TRUE); + if (sNamingScreen->templateNum == NAMING_SCREEN_CAUGHT_MON + && CalculatePlayerPartyCount() >= PARTY_SIZE) { DisplaySentToPCMessage(); - gNamingScreenData->state = MAIN_STATE_UPDATE_SENT_TO_PC_MESSAGE; + sNamingScreen->state = STATE_WAIT_SENT_TO_PC_MESSAGE; return FALSE; } else { - gNamingScreenData->state = MAIN_STATE_BEGIN_FADE_OUT; - return TRUE; //Exit the naming screen + sNamingScreen->state = STATE_FADE_OUT; + return TRUE; } } -static bool8 MainState_BeginFadeInOut(void) +static bool8 MainState_FadeOut(void) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); - gNamingScreenData->state++; + sNamingScreen->state++; return FALSE; } -static bool8 MainState_WaitFadeOutAndExit(void) +static bool8 MainState_Exit(void) { if (!gPaletteFade.active) { - if (gNamingScreenData->templateNum == NAMING_SCREEN_PLAYER) + if (sNamingScreen->templateNum == NAMING_SCREEN_PLAYER) SeedRngAndSetTrainerId(); - SetMainCallback2(gNamingScreenData->returnCallback); - DestroyTask(FindTaskIdByFunc(sub_80E31B0)); + SetMainCallback2(sNamingScreen->returnCallback); + DestroyTask(FindTaskIdByFunc(Task_NamingScreen)); FreeAllWindowBuffers(); - FREE_AND_SET_NULL(gNamingScreenData); + FREE_AND_SET_NULL(sNamingScreen); } return FALSE; } @@ -543,12 +716,12 @@ static void DisplaySentToPCMessage(void) if (!IsDestinationBoxFull()) { StringCopy(gStringVar1, GetBoxNamePtr(VarGet(VAR_PC_BOX_TO_SEND_MON))); - StringCopy(gStringVar2, gNamingScreenData->destBuffer); + StringCopy(gStringVar2, sNamingScreen->destBuffer); } else { StringCopy(gStringVar1, GetBoxNamePtr(VarGet(VAR_PC_BOX_TO_SEND_MON))); - StringCopy(gStringVar2, gNamingScreenData->destBuffer); + StringCopy(gStringVar2, sNamingScreen->destBuffer); StringCopy(gStringVar3, GetBoxNamePtr(GetPCBoxToSendMon())); stringToDisplay = 2; } @@ -563,12 +736,11 @@ static void DisplaySentToPCMessage(void) CopyWindowToVram(0, 3); } -static bool8 sub_80E3604(void) +static bool8 MainState_WaitSentToPCMessage(void) { RunTextPrinters(); - - if (!IsTextPrinterActive(0) && (gMain.newKeys & A_BUTTON)) - gNamingScreenData->state = MAIN_STATE_BEGIN_FADE_OUT; + if (!IsTextPrinterActive(0) && JOY_NEW(A_BUTTON)) + sNamingScreen->state = STATE_FADE_OUT; return FALSE; } @@ -576,12 +748,12 @@ static bool8 sub_80E3604(void) static bool8 MainState_StartPageSwap(void) { SetInputState(INPUT_STATE_DISABLED); - sub_80E4050(); + StartPageSwapButtonAnim(); StartPageSwapAnim(); - sub_80E3E3C(1); - sub_80E3948(0, 0, 1); + SetCursorInvisibility(TRUE); + TryStartButtonFlash(BUTTON_PAGE, FALSE, TRUE); PlaySE(SE_WIN_OPEN); - gNamingScreenData->state = MAIN_STATE_WAIT_PAGE_SWAP; + sNamingScreen->state = STATE_WAIT_PAGE_SWAP; return FALSE; } @@ -589,19 +761,19 @@ static bool8 MainState_WaitPageSwap(void) { s16 cursorX; s16 cursorY; - bool32 var3; + bool32 onLastColumn; if (IsPageSwapAnimNotInProgress()) { GetCursorPos(&cursorX, &cursorY); - var3 = (cursorX == GetCurrentPageColumnCount()); + onLastColumn = (cursorX == GetCurrentPageColumnCount()); - gNamingScreenData->state = MAIN_STATE_HANDLE_INPUT; - gNamingScreenData->currentPage++; - gNamingScreenData->currentPage %= 3; + sNamingScreen->state = STATE_HANDLE_INPUT; + sNamingScreen->currentPage++; + sNamingScreen->currentPage %= KBPAGE_COUNT; - if (var3) + if (onLastColumn) { cursorX = GetCurrentPageColumnCount(); } @@ -612,9 +784,9 @@ static bool8 MainState_WaitPageSwap(void) } SetCursorPos(cursorX, cursorY); - sub_80E4E5C(); + DrawKeyboardPageOnDeck(); SetInputState(INPUT_STATE_ENABLED); - sub_80E3E3C(0); + SetCursorInvisibility(FALSE); } return FALSE; } @@ -662,29 +834,29 @@ static bool8 IsPageSwapAnimNotInProgress(void) static bool8 PageSwapAnimState_Init(struct Task *task) { - gNamingScreenData->bg1vOffset = 0; - gNamingScreenData->bg2vOffset = 0; + sNamingScreen->bg1vOffset = 0; + sNamingScreen->bg2vOffset = 0; task->tState++; return 0; } static bool8 PageSwapAnimState_1(struct Task *task) { - u16 *const arr[] = + u16 *const vOffsets[] = { - &gNamingScreenData->bg2vOffset, - &gNamingScreenData->bg1vOffset + &sNamingScreen->bg2vOffset, + &sNamingScreen->bg1vOffset }; task->tFrameCount += 4; - *arr[gNamingScreenData->bgToReveal] = Sin(task->tFrameCount, 40); - *arr[gNamingScreenData->bgToHide] = Sin((task->tFrameCount + 128) & 0xFF, 40); + *vOffsets[sNamingScreen->bgToReveal] = Sin(task->tFrameCount, 40); + *vOffsets[sNamingScreen->bgToHide] = Sin((task->tFrameCount + 128) & 0xFF, 40); if (task->tFrameCount >= 64) { - u8 temp = gNamingScreenData->bg1Priority; //Why u8 and not u16? + u8 temp = sNamingScreen->bg1Priority; //Why u8 and not u16? - gNamingScreenData->bg1Priority = gNamingScreenData->bg2Priority; - gNamingScreenData->bg2Priority = temp; + sNamingScreen->bg1Priority = sNamingScreen->bg2Priority; + sNamingScreen->bg2Priority = temp; task->tState++; } return 0; @@ -692,21 +864,21 @@ static bool8 PageSwapAnimState_1(struct Task *task) static bool8 PageSwapAnimState_2(struct Task *task) { - u16 *const arr[] = + u16 *const vOffsets[] = { - &gNamingScreenData->bg2vOffset, - &gNamingScreenData->bg1vOffset + &sNamingScreen->bg2vOffset, + &sNamingScreen->bg1vOffset }; task->tFrameCount += 4; - *arr[gNamingScreenData->bgToReveal] = Sin(task->tFrameCount, 40); - *arr[gNamingScreenData->bgToHide] = Sin((task->tFrameCount + 128) & 0xFF, 40); + *vOffsets[sNamingScreen->bgToReveal] = Sin(task->tFrameCount, 40); + *vOffsets[sNamingScreen->bgToHide] = Sin((task->tFrameCount + 128) & 0xFF, 40); if (task->tFrameCount >= 128) { - u8 temp = gNamingScreenData->bgToReveal; + u8 temp = sNamingScreen->bgToReveal; - gNamingScreenData->bgToReveal = gNamingScreenData->bgToHide; - gNamingScreenData->bgToHide = temp; + sNamingScreen->bgToReveal = sNamingScreen->bgToHide; + sNamingScreen->bgToHide = temp; task->tState++; } return 0; @@ -725,221 +897,260 @@ static bool8 PageSwapAnimState_Done(struct Task *task) // //-------------------------------------------------- -static void sub_80E3920(void) +#define tButtonId data[0] +#define tKeepFlashing data[1] +#define tAllowFlash data[2] +#define tColor data[3] +#define tColorIncr data[4] +#define tColorDelay data[5] +#define tColorDelta data[6] + +static void CreateButtonFlashTask(void) { u8 taskId; - taskId = CreateTask(Task_80E39BC, 3); - gTasks[taskId].data[0] = 3; + taskId = CreateTask(Task_UpdateButtonFlash, 3); + gTasks[taskId].tButtonId = BUTTON_COUNT; } -static void sub_80E3948(u8 a, u8 b, u8 c) +static void TryStartButtonFlash(u8 button, bool8 keepFlashing, bool8 interruptCurFlash) { - struct Task *task = &gTasks[FindTaskIdByFunc(Task_80E39BC)]; + struct Task *task = &gTasks[FindTaskIdByFunc(Task_UpdateButtonFlash)]; - if (a == task->data[0] && c == 0) + if (button == task->tButtonId && !interruptCurFlash) { - task->data[1] = b; - task->data[2] = 1; + task->tKeepFlashing = keepFlashing; + task->tAllowFlash = TRUE; return; } - if (a == 3 && task->data[1] == 0 && c == 0) + if (button == BUTTON_COUNT && !task->tKeepFlashing && !interruptCurFlash) return; - if (task->data[0] != 3) - sub_80E3AE8(task->data[0]); - sub_80E3B10(task, a, b); + + if (task->tButtonId != BUTTON_COUNT) + RestoreButtonColor(task->tButtonId); + + StartButtonFlash(task, button, keepFlashing); } -static void Task_80E39BC(u8 taskId) +static void Task_UpdateButtonFlash(u8 taskId) { struct Task *task = &gTasks[taskId]; - if (task->data[0] == 3 || task->data[2] == 0) + if (task->tButtonId == BUTTON_COUNT || !task->tAllowFlash) return; - MultiplyInvertedPaletteRGBComponents(sub_80E3A74(task->data[0]), task->data[3], task->data[3], task->data[3]); - if (task->data[5] != 0) + + MultiplyInvertedPaletteRGBComponents(GetButtonPalOffset(task->tButtonId), task->tColor, task->tColor, task->tColor); + + if (task->tColorDelay && --task->tColorDelay) + return; + + task->tColorDelay = 2; + if (task->tColorIncr >= 0) { - task->data[5]--; - if (task->data[5] != 0) - return; - } - task->data[5] = 2; - if (task->data[4] >= 0) - { - if (task->data[3] < 14) + if (task->tColor < 14) { - task->data[3] += task->data[4]; - task->data[6] += task->data[4]; + task->tColor += task->tColorIncr; + task->tColorDelta += task->tColorIncr; } else { - task->data[3] = 16; - task->data[6]++; + task->tColor = 16; + task->tColorDelta++; } } else { - task->data[3] += task->data[4]; - task->data[6] += task->data[4]; + task->tColor += task->tColorIncr; + task->tColorDelta += task->tColorIncr; } - if (task->data[3] == 16 && task->data[6] == 22) + if (task->tColor == 16 && task->tColorDelta == 22) { - task->data[4] = -4; + task->tColorIncr = -4; } - else if (task->data[3] == 0) + else if (task->tColor == 0) { - task->data[2] = task->data[1]; - task->data[4] = 2; - task->data[6] = 0; + task->tAllowFlash = task->tKeepFlashing; + task->tColorIncr = 2; + task->tColorDelta = 0; } } -static u16 sub_80E3A74(u8 a) +static u16 GetButtonPalOffset(u8 button) { - const u16 arr[] = + const u16 palOffsets[BUTTON_COUNT + 1] = { - IndexOfSpritePaletteTag(4) * 16 + 0x10E, - IndexOfSpritePaletteTag(6) * 16 + 0x10E, - IndexOfSpritePaletteTag(7) * 16 + 0x10E, - IndexOfSpritePaletteTag(7) * 16 + 0x101, + [BUTTON_PAGE] = IndexOfSpritePaletteTag(PALTAG_PAGE_SWAP) * 16 + 0x10E, + [BUTTON_BACK] = IndexOfSpritePaletteTag(PALTAG_BACK_BUTTON) * 16 + 0x10E, + [BUTTON_OK] = IndexOfSpritePaletteTag(PALTAG_OK_BUTTON) * 16 + 0x10E, + [BUTTON_COUNT] = IndexOfSpritePaletteTag(PALTAG_OK_BUTTON) * 16 + 0x101, }; - return arr[a]; + return palOffsets[button]; } -static void sub_80E3AE8(u8 a) +static void RestoreButtonColor(u8 button) { - u16 index = sub_80E3A74(a); - + u16 index = GetButtonPalOffset(button); gPlttBufferFaded[index] = gPlttBufferUnfaded[index]; } -static void sub_80E3B10(struct Task *task, u8 b, u8 c) +static void StartButtonFlash(struct Task *task, u8 button, bool8 keepFlashing) { - task->data[0] = b; - task->data[1] = c; - task->data[2] = 1; - task->data[3] = 4; - task->data[4] = 2; - task->data[5] = 0; - task->data[6] = 4; + task->tButtonId = button; + task->tKeepFlashing = keepFlashing; + task->tAllowFlash = TRUE; + task->tColor = 4; + task->tColorIncr = 2; + task->tColorDelay = 0; + task->tColorDelta = 4; } -static void sub_80E3B30(struct Sprite *sprite) +#undef tButtonId +#undef tColor + +// Sprite data for the the cursor +#define sX data[0] +#define sY data[1] +#define sPrevX data[2] +#define sPrevY data[3] +#define sInvisible data[4] & 0x00FF +#define sFlashing data[4] & 0xFF00 +#define sColor data[5] +#define sColorIncr data[6] +#define sColorDelay data[7] + +static void SpriteCB_Cursor(struct Sprite *sprite) { if (sprite->animEnded) StartSpriteAnim(sprite, 0); - sprite->invisible = (sprite->data[4] & 0xFF); - if (sprite->data[0] == GetCurrentPageColumnCount()) + + // Hide cursor when on button column + sprite->invisible = sprite->sInvisible; + if (sprite->sX == GetCurrentPageColumnCount()) sprite->invisible = TRUE; - if (sprite->invisible || (sprite->data[4] & 0xFF00) == 0 - || sprite->data[0] != sprite->data[2] || sprite->data[1] != sprite->data[3]) + + if (sprite->invisible + || !(sprite->sFlashing) + || sprite->sX != sprite->sPrevX + || sprite->sY != sprite->sPrevY) { - sprite->data[5] = 0; - sprite->data[6] = 2; - sprite->data[7] = 2; + sprite->sColor = 0; + sprite->sColorIncr = 2; + sprite->sColorDelay = 2; } - sprite->data[7]--; - if (sprite->data[7] == 0) + + sprite->sColorDelay--; + if (sprite->sColorDelay == 0) { - sprite->data[5] += sprite->data[6]; - if (sprite->data[5] == 16 || sprite->data[5] == 0) - sprite->data[6] = -sprite->data[6]; - sprite->data[7] = 2; + sprite->sColor += sprite->sColorIncr; + if (sprite->sColor == 16 || sprite->sColor == 0) + sprite->sColorIncr = -sprite->sColorIncr; + sprite->sColorDelay = 2; } - if ((sprite->data[4] & 0xFF00) != 0) + + if (sprite->sFlashing) { - s8 gb = sprite->data[5]; - s8 r = sprite->data[5] >> 1; - u16 index = IndexOfSpritePaletteTag(5) * 16 + 0x0101; + s8 gb = sprite->sColor; + s8 r = sprite->sColor >> 1; + u16 index = IndexOfSpritePaletteTag(PALTAG_CURSOR) * 16 + 0x0101; MultiplyInvertedPaletteRGBComponents(index, r, gb, gb); } } -static void sub_80E3C20(struct Sprite *sprite) -{ - const s16 arr[] = {0, -4, -2, -1}; +#define sDelay data[0] +#define sXPosId data[1] - if (sprite->data[0] == 0 || --sprite->data[0] == 0) +static void SpriteCB_InputArrow(struct Sprite *sprite) +{ + const s16 x[] = {0, -4, -2, -1}; + + if (sprite->sDelay == 0 || --sprite->sDelay == 0) { - sprite->data[0] = 8; - sprite->data[1] = (sprite->data[1] + 1) & 3; + sprite->sDelay = 8; + sprite->sXPosId = (sprite->sXPosId + 1) & (ARRAY_COUNT(x) - 1); } - sprite->pos2.x = arr[sprite->data[1]]; + sprite->pos2.x = x[sprite->sXPosId]; } -static void sub_80E3C6C(struct Sprite *sprite) -{ - const s16 arr[] = {2, 3, 2, 1}; - u8 var; +#undef sDelay +#undef sXPosId - var = GetTextCaretPosition(); - if (var != (u8)sprite->data[0]) +#define sId data[0] // set in CreateTextEntrySprites +#define sYPosId data[1] +#define sDelay data[2] + +static void SpriteCB_Underscore(struct Sprite *sprite) +{ + const s16 y[] = {2, 3, 2, 1}; + u8 pos; + + pos = GetTextEntryPosition(); + if (pos != (u8)sprite->sId) { sprite->pos2.y = 0; - sprite->data[1] = 0; - sprite->data[2] = 0; + sprite->sYPosId = 0; + sprite->sDelay = 0; } else { - sprite->pos2.y = arr[sprite->data[1]]; - sprite->data[2]++; - if (sprite->data[2] > 8) + sprite->pos2.y = y[sprite->sYPosId]; + sprite->sDelay++; + if (sprite->sDelay > 8) { - sprite->data[1] = (sprite->data[1] + 1) & 3; - sprite->data[2] = 0; + sprite->sYPosId = (sprite->sYPosId + 1) & (ARRAY_COUNT(y) - 1); + sprite->sDelay = 0; } } } -//-------------------------------------------------- -// Cursor -//-------------------------------------------------- +#undef sId +#undef sYPosId +#undef sDelay -static void sub_80E3CC8(void) +static void CreateSprites(void) { - CursorInit(); - CreatePageSwitcherSprites(); + CreateCursorSprite(); + CreatePageSwapButtonSprites(); CreateBackOkSprites(); - CreateUnderscoreSprites(); + CreateTextEntrySprites(); CreateInputTargetIcon(); } -static void CursorInit(void) +static void CreateCursorSprite(void) { - gNamingScreenData->cursorSpriteId = CreateSprite(&gUnknown_0858C138, 38, 88, 1); - sub_80E3E3C(1); - gSprites[gNamingScreenData->cursorSpriteId].oam.priority = 1; - gSprites[gNamingScreenData->cursorSpriteId].oam.objMode = ST_OAM_OBJ_BLEND; - gSprites[gNamingScreenData->cursorSpriteId].data[6] = 1; - gSprites[gNamingScreenData->cursorSpriteId].data[6] = 2; + sNamingScreen->cursorSpriteId = CreateSprite(&sSpriteTemplate_Cursor, 38, 88, 1); + SetCursorInvisibility(TRUE); + gSprites[sNamingScreen->cursorSpriteId].oam.priority = 1; + gSprites[sNamingScreen->cursorSpriteId].oam.objMode = ST_OAM_OBJ_BLEND; + gSprites[sNamingScreen->cursorSpriteId].sColorIncr = 1; // ? immediately overwritten + gSprites[sNamingScreen->cursorSpriteId].sColorIncr = 2; SetCursorPos(0, 0); } static void SetCursorPos(s16 x, s16 y) { - struct Sprite *cursorSprite = &gSprites[gNamingScreenData->cursorSpriteId]; + struct Sprite *cursorSprite = &gSprites[sNamingScreen->cursorSpriteId]; - if (x < gUnknown_0858BEA0[sub_80E3274()]) - cursorSprite->pos1.x = gUnknown_0858BEA3[x + sub_80E3274() * 8] + 38; + if (x < sPageColumnCounts[CurrentPageToKeyboardId()]) + cursorSprite->pos1.x = sPageColumnXPos[x + CurrentPageToKeyboardId() * KBCOL_COUNT] + 38; else cursorSprite->pos1.x = 0; cursorSprite->pos1.y = y * 16 + 88; - cursorSprite->data[2] = cursorSprite->data[0]; - cursorSprite->data[3] = cursorSprite->data[1]; - cursorSprite->data[0] = x; - cursorSprite->data[1] = y; + cursorSprite->sPrevX = cursorSprite->sX; + cursorSprite->sPrevY = cursorSprite->sY; + cursorSprite->sX = x; + cursorSprite->sY = y; } static void GetCursorPos(s16 *x, s16 *y) { - struct Sprite *cursorSprite = &gSprites[gNamingScreenData->cursorSpriteId]; + struct Sprite *cursorSprite = &gSprites[sNamingScreen->cursorSpriteId]; - *x = cursorSprite->data[0]; - *y = cursorSprite->data[1]; + *x = cursorSprite->sX; + *y = cursorSprite->sY; } static void MoveCursorToOKButton(void) @@ -947,38 +1158,30 @@ static void MoveCursorToOKButton(void) SetCursorPos(GetCurrentPageColumnCount(), 2); } -static void sub_80E3E3C(u8 a) +static void SetCursorInvisibility(bool8 invisible) { - gSprites[gNamingScreenData->cursorSpriteId].data[4] &= -256; - gSprites[gNamingScreenData->cursorSpriteId].data[4] |= a; - StartSpriteAnim(&gSprites[gNamingScreenData->cursorSpriteId], 0); + gSprites[sNamingScreen->cursorSpriteId].data[4] &= 0xFF00; + gSprites[sNamingScreen->cursorSpriteId].data[4] |= invisible; // sInvisible + StartSpriteAnim(&gSprites[sNamingScreen->cursorSpriteId], 0); } -static void sub_80E3E94(u8 a) +static void SetCursorFlashing(bool8 flashing) { - gSprites[gNamingScreenData->cursorSpriteId].data[4] &= 0xFF; - gSprites[gNamingScreenData->cursorSpriteId].data[4] |= a << 8; + gSprites[sNamingScreen->cursorSpriteId].data[4] &= 0xFF; + gSprites[sNamingScreen->cursorSpriteId].data[4] |= flashing << 8; // sFlashing } -static void sub_80E3ED8(void) +static void SquishCursor(void) { - StartSpriteAnim(&gSprites[gNamingScreenData->cursorSpriteId], 1); + StartSpriteAnim(&gSprites[sNamingScreen->cursorSpriteId], 1); } static bool8 IsCursorAnimFinished(void) { - return gSprites[gNamingScreenData->cursorSpriteId].animEnded; + return gSprites[sNamingScreen->cursorSpriteId].animEnded; } -enum -{ - KEY_ROLE_CHAR, - KEY_ROLE_PAGE, - KEY_ROLE_BACKSPACE, - KEY_ROLE_OK, -}; - -static const u8 sKeyRoles[] = {KEY_ROLE_PAGE, KEY_ROLE_BACKSPACE, KEY_ROLE_OK}; +static const u8 sButtonKeyRoles[] = {KEY_ROLE_PAGE, KEY_ROLE_BACKSPACE, KEY_ROLE_OK}; static u8 GetKeyRoleAtCursorPos(void) { @@ -989,146 +1192,174 @@ static u8 GetKeyRoleAtCursorPos(void) if (cursorX < GetCurrentPageColumnCount()) return KEY_ROLE_CHAR; else - return sKeyRoles[cursorY]; + return sButtonKeyRoles[cursorY]; } +// If the cursor's x is equal to the column count, cursor is in the button column static u8 GetCurrentPageColumnCount(void) { - return gUnknown_0858BEA0[sub_80E3274()]; + return sPageColumnCounts[CurrentPageToKeyboardId()]; } -static void CreatePageSwitcherSprites(void) +#undef sX +#undef sY +#undef sPrevX +#undef sPrevY +#undef sInvisible +#undef sFlashing +#undef sColor +#undef sColorIncr +#undef sColorDelay + +static bool8 PageSwapSprite_Init(struct Sprite *); +static bool8 PageSwapSprite_Idle(struct Sprite *); +static bool8 PageSwapSprite_SlideOff(struct Sprite *); +static bool8 PageSwapSprite_SlideOn(struct Sprite *); + +#define sState data[0] +#define sPage data[1] +#define sTextSpriteId data[6] +#define sButtonSpriteId data[7] + +static void CreatePageSwapButtonSprites(void) { - u8 spriteId1; - u8 spriteId2; - u8 spriteId3; + u8 frameSpriteId; + u8 textSpriteId; + u8 buttonSpriteId; - spriteId1 = CreateSprite(&gUnknown_0858C0C0, 0xCC, 0x58, 0); - gNamingScreenData->selectBtnFrameSpriteId = spriteId1; - SetSubspriteTables(&gSprites[spriteId1], gUnknown_0858C050); - gSprites[spriteId1].invisible = TRUE; + frameSpriteId = CreateSprite(&sSpriteTemplate_PageSwapFrame, 204, 88, 0); + sNamingScreen->swapBtnFrameSpriteId = frameSpriteId; + SetSubspriteTables(&gSprites[frameSpriteId], sSubspriteTable_PageSwapFrame); + gSprites[frameSpriteId].invisible = TRUE; - spriteId2 = CreateSprite(&gUnknown_0858C0F0, 0xCC, 0x54, 1); - gSprites[spriteId1].data[6] = spriteId2; - SetSubspriteTables(&gSprites[spriteId2], gUnknown_0858C058); - gSprites[spriteId2].invisible = TRUE; + textSpriteId = CreateSprite(&sSpriteTemplate_PageSwapText, 204, 84, 1); + gSprites[frameSpriteId].sTextSpriteId = textSpriteId; + SetSubspriteTables(&gSprites[textSpriteId], sSubspriteTable_PageSwapText); + gSprites[textSpriteId].invisible = TRUE; - spriteId3 = CreateSprite(&gUnknown_0858C0D8, 0xCC, 0x53, 2); - gSprites[spriteId3].oam.priority = 1; - gSprites[spriteId1].data[7] = spriteId3; - gSprites[spriteId3].invisible = TRUE; + buttonSpriteId = CreateSprite(&sSpriteTemplate_PageSwapButton, 204, 83, 2); + gSprites[buttonSpriteId].oam.priority = 1; + gSprites[frameSpriteId].sButtonSpriteId = buttonSpriteId; + gSprites[buttonSpriteId].invisible = TRUE; } -static void sub_80E4050(void) +static void StartPageSwapButtonAnim(void) { - struct Sprite *sprite = &gSprites[gNamingScreenData->selectBtnFrameSpriteId]; + struct Sprite *sprite = &gSprites[sNamingScreen->swapBtnFrameSpriteId]; - sprite->data[0] = 2; - sprite->data[1] = gNamingScreenData->currentPage; + sprite->sState = 2; // go to PageSwapSprite_SlideOff + sprite->sPage = sNamingScreen->currentPage; } -static u8 sub_80E40AC(struct Sprite *); -static u8 sub_80E4100(struct Sprite *); -static u8 sub_80E4104(struct Sprite *); -static u8 sub_80E4178(struct Sprite *); - -static u8 (*const gUnknown_0858BEE8[])(struct Sprite *) = +static u8 (*const sPageSwapSpriteFuncs[])(struct Sprite *) = { - sub_80E40AC, - sub_80E4100, - sub_80E4104, - sub_80E4178, + PageSwapSprite_Init, + PageSwapSprite_Idle, + PageSwapSprite_SlideOff, + PageSwapSprite_SlideOn, }; -static void sub_80E4084(struct Sprite *sprite) +static void SpriteCB_PageSwap(struct Sprite *sprite) { - while (gUnknown_0858BEE8[sprite->data[0]](sprite) != 0); + while (sPageSwapSpriteFuncs[sprite->sState](sprite)); } -static u8 sub_80E40AC(struct Sprite *sprite) +static bool8 PageSwapSprite_Init(struct Sprite *sprite) { - struct Sprite *sprite1 = &gSprites[sprite->data[6]]; - struct Sprite *sprite2 = &gSprites[sprite->data[7]]; + struct Sprite *text = &gSprites[sprite->sTextSpriteId]; + struct Sprite *button = &gSprites[sprite->sButtonSpriteId]; - sub_80E41B8(sub_80E3244(gNamingScreenData->currentPage), sprite1, sprite2); - sprite->data[0]++; - return 0; + SetPageSwapButtonGfx(PageToNextGfxId(sNamingScreen->currentPage), text, button); + sprite->sState++; + return FALSE; } -static u8 sub_80E4100(struct Sprite *sprite) +static bool8 PageSwapSprite_Idle(struct Sprite *sprite) { - return 0; + return FALSE; } -static u8 sub_80E4104(struct Sprite *sprite) +static bool8 PageSwapSprite_SlideOff(struct Sprite *sprite) { - struct Sprite *r4 = &gSprites[sprite->data[6]]; - struct Sprite *r5 = &gSprites[sprite->data[7]]; + struct Sprite *text = &gSprites[sprite->sTextSpriteId]; + struct Sprite *button = &gSprites[sprite->sButtonSpriteId]; - r4->pos2.y++; - if (r4->pos2.y > 7) + text->pos2.y++; + if (text->pos2.y > 7) { - sprite->data[0]++; - r4->pos2.y = -4; - r4->invisible = TRUE; - sub_80E41B8(sub_80E3244(((u8)sprite->data[1] + 1) % 3), r4, r5); + sprite->sState++; + text->pos2.y = -4; + text->invisible = TRUE; + SetPageSwapButtonGfx(PageToNextGfxId(((u8)sprite->sPage + 1) % KBPAGE_COUNT), text, button); } - return 0; + return FALSE; } -static u8 sub_80E4178(struct Sprite *sprite) +static bool8 PageSwapSprite_SlideOn(struct Sprite *sprite) { - struct Sprite *r2 = &gSprites[sprite->data[6]]; + struct Sprite *text = &gSprites[sprite->sTextSpriteId]; - r2->invisible = FALSE; - r2->pos2.y++; - if (r2->pos2.y >= 0) + text->invisible = FALSE; + text->pos2.y++; + if (text->pos2.y >= 0) { - r2->pos2.y = 0; - sprite->data[0] = 1; + text->pos2.y = 0; + sprite->sState = 1; // go to PageSwapSprite_Idle } - return 0; + return FALSE; } -static const u16 gUnknown_0858BEF8[] = {1, 3, 2}; -static const u16 gUnknown_0858BEFE[] = {4, 6, 5}; +static const u16 sPageSwapPalTags[] = { + [PAGE_SWAP_UPPER] = PALTAG_PAGE_SWAP_UPPER, + [PAGE_SWAP_OTHERS] = PALTAG_PAGE_SWAP_OTHERS, + [PAGE_SWAP_LOWER] = PALTAG_PAGE_SWAP_LOWER +}; -static void sub_80E41B8(u8 a, struct Sprite *b, struct Sprite *c) +static const u16 sPageSwapGfxTags[] = { + [PAGE_SWAP_UPPER] = GFXTAG_PAGE_SWAP_UPPER, + [PAGE_SWAP_OTHERS] = GFXTAG_PAGE_SWAP_OTHERS, + [PAGE_SWAP_LOWER] = GFXTAG_PAGE_SWAP_LOWER +}; + +static void SetPageSwapButtonGfx(u8 page, struct Sprite *text, struct Sprite *button) { - c->oam.paletteNum = IndexOfSpritePaletteTag(gUnknown_0858BEF8[a]); - b->sheetTileStart = GetSpriteTileStartByTag(gUnknown_0858BEFE[a]); - b->subspriteTableNum = a; + button->oam.paletteNum = IndexOfSpritePaletteTag(sPageSwapPalTags[page]); + text->sheetTileStart = GetSpriteTileStartByTag(sPageSwapGfxTags[page]); + text->subspriteTableNum = page; } -// +#undef sState +#undef sPage +#undef sTextSpriteId +#undef sButtonSpriteId static void CreateBackOkSprites(void) { u8 spriteId; - spriteId = CreateSprite(&gUnknown_0858C108, 0xCC, 0x74, 0); - SetSubspriteTables(&gSprites[spriteId], gUnknown_0858C070); + spriteId = CreateSprite(&sSpriteTemplate_BackButton, 204, 116, 0); + SetSubspriteTables(&gSprites[spriteId], sSubspriteTable_Button); gSprites[spriteId].invisible = TRUE; - spriteId = CreateSprite(&gUnknown_0858C120, 0xCC, 0x8C, 0); - SetSubspriteTables(&gSprites[spriteId], gUnknown_0858C070); + spriteId = CreateSprite(&sSpriteTemplate_OkButton, 204, 140, 0); + SetSubspriteTables(&gSprites[spriteId], sSubspriteTable_Button); gSprites[spriteId].invisible = TRUE; } -static void CreateUnderscoreSprites(void) +static void CreateTextEntrySprites(void) { u8 spriteId; s16 xPos; u8 i; - xPos = gNamingScreenData->inputCharBaseXPos - 5; - spriteId = CreateSprite(&sSpriteTemplate_InputArrow, xPos, 0x38, 0); + xPos = sNamingScreen->inputCharBaseXPos - 5; + spriteId = CreateSprite(&sSpriteTemplate_InputArrow, xPos, 56, 0); gSprites[spriteId].oam.priority = 3; gSprites[spriteId].invisible = TRUE; - xPos = gNamingScreenData->inputCharBaseXPos; - for (i = 0; i < gNamingScreenData->template->maxChars; i++, xPos += 8) + xPos = sNamingScreen->inputCharBaseXPos; + for (i = 0; i < sNamingScreen->template->maxChars; i++, xPos += 8) { - spriteId = CreateSprite(&sSpriteTemplate_Underscore, xPos + 3, 0x3C, 0); + spriteId = CreateSprite(&sSpriteTemplate_Underscore, xPos + 3, 60, 0); gSprites[spriteId].oam.priority = 3; gSprites[spriteId].data[0] = i; gSprites[spriteId].invisible = TRUE; @@ -1139,27 +1370,27 @@ static void CreateUnderscoreSprites(void) // Icon creation (the thing you're naming or giving input to) //-------------------------------------------------- -static void TaskDummy2(void); +static void NamingScreen_NoIcon(void); static void NamingScreen_CreatePlayerIcon(void); static void NamingScreen_CreatePCIcon(void); static void NamingScreen_CreateMonIcon(void); -static void NamingScreen_CreateWandaDadIcon(void); +static void NamingScreen_CreateWaldaDadIcon(void); static void (*const sIconFunctions[])(void) = { - TaskDummy2, + NamingScreen_NoIcon, NamingScreen_CreatePlayerIcon, NamingScreen_CreatePCIcon, NamingScreen_CreateMonIcon, - NamingScreen_CreateWandaDadIcon, + NamingScreen_CreateWaldaDadIcon, }; static void CreateInputTargetIcon(void) { - sIconFunctions[gNamingScreenData->template->iconFunction](); + sIconFunctions[sNamingScreen->template->iconFunction](); } -static void TaskDummy2(void) +static void NamingScreen_NoIcon(void) { } @@ -1169,8 +1400,8 @@ static void NamingScreen_CreatePlayerIcon(void) u8 rivalGfxId; u8 spriteId; - rivalGfxId = GetRivalAvatarGraphicsIdByStateIdAndGender(0, gNamingScreenData->monSpecies); - spriteId = AddPseudoObjectEvent(rivalGfxId, SpriteCallbackDummy, 0x38, 0x25, 0); + rivalGfxId = GetRivalAvatarGraphicsIdByStateIdAndGender(0, sNamingScreen->monSpecies); + spriteId = AddPseudoObjectEvent(rivalGfxId, SpriteCallbackDummy, 56, 37, 0); gSprites[spriteId].oam.priority = 3; StartSpriteAnim(&gSprites[spriteId], 4); } @@ -1179,8 +1410,8 @@ static void NamingScreen_CreatePCIcon(void) { u8 spriteId; - spriteId = CreateSprite(&gUnknown_0858C180, 0x38, 0x29, 0); - SetSubspriteTables(&gSprites[spriteId], gUnknown_0858C078); + spriteId = CreateSprite(&sSpriteTemplate_PCIcon, 56, 41, 0); + SetSubspriteTables(&gSprites[spriteId], sSubspriteTable_PCIcon); gSprites[spriteId].oam.priority = 3; } @@ -1189,15 +1420,15 @@ static void NamingScreen_CreateMonIcon(void) u8 spriteId; LoadMonIconPalettes(); - spriteId = CreateMonIcon(gNamingScreenData->monSpecies, SpriteCallbackDummy, 0x38, 0x28, 0, gNamingScreenData->monPersonality, 1); + spriteId = CreateMonIcon(sNamingScreen->monSpecies, SpriteCallbackDummy, 56, 40, 0, sNamingScreen->monPersonality, 1); gSprites[spriteId].oam.priority = 3; } -static void NamingScreen_CreateWandaDadIcon(void) +static void NamingScreen_CreateWaldaDadIcon(void) { u8 spriteId; - spriteId = AddPseudoObjectEvent(OBJ_EVENT_GFX_MAN_1, SpriteCallbackDummy, 0x38, 0x25, 0); + spriteId = AddPseudoObjectEvent(OBJ_EVENT_GFX_MAN_1, SpriteCallbackDummy, 56, 37, 0); gSprites[spriteId].oam.priority = 3; StartSpriteAnim(&gSprites[spriteId], 4); } @@ -1213,87 +1444,87 @@ static bool8 KeyboardKeyHandler_OK(u8); static bool8 (*const sKeyboardKeyHandlers[])(u8) = { - KeyboardKeyHandler_Character, - KeyboardKeyHandler_Page, - KeyboardKeyHandler_Backspace, - KeyboardKeyHandler_OK, + [KEY_ROLE_CHAR] = KeyboardKeyHandler_Character, + [KEY_ROLE_PAGE] = KeyboardKeyHandler_Page, + [KEY_ROLE_BACKSPACE] = KeyboardKeyHandler_Backspace, + [KEY_ROLE_OK] = KeyboardKeyHandler_OK, }; static bool8 HandleKeyboardEvent(void) { - u8 event = GetInputEvent(); + u8 input = GetInputEvent(); u8 keyRole = GetKeyRoleAtCursorPos(); - if (event == KBEVENT_PRESSED_SELECT) + if (input == INPUT_SELECT) { - return sub_80E45E0(); + return SwapKeyboardPage(); } - else if (event == KBEVENT_PRESSED_B) + else if (input == INPUT_B_BUTTON) { DeleteTextCharacter(); return FALSE; } - else if (event == KBEVENT_PRESSED_START) + else if (input == INPUT_START) { MoveCursorToOKButton(); return FALSE; } else { - return sKeyboardKeyHandlers[keyRole](event); + return sKeyboardKeyHandlers[keyRole](input); } } -static bool8 KeyboardKeyHandler_Character(u8 event) +static bool8 KeyboardKeyHandler_Character(u8 input) { - sub_80E3948(3, 0, 0); - if (event == KBEVENT_PRESSED_A) + TryStartButtonFlash(BUTTON_COUNT, FALSE, FALSE); + if (input == INPUT_A_BUTTON) { - bool8 var = sub_80E4B54(); + bool8 textFull = AddTextCharacter(); - sub_80E3ED8(); - if (var) + SquishCursor(); + if (textFull) { - SetInputState(INPUT_STATE_2); - gNamingScreenData->state = MAIN_STATE_MOVE_TO_OK_BUTTON; + SetInputState(INPUT_STATE_OVERRIDE); + sNamingScreen->state = STATE_MOVE_TO_OK_BUTTON; } } return FALSE; } -static bool8 KeyboardKeyHandler_Page(u8 event) +static bool8 KeyboardKeyHandler_Page(u8 input) { - sub_80E3948(0, 1, 0); - if (event == KBEVENT_PRESSED_A) - return sub_80E45E0(); + TryStartButtonFlash(BUTTON_PAGE, TRUE, FALSE); + if (input == INPUT_A_BUTTON) + return SwapKeyboardPage(); else return FALSE; } -static bool8 KeyboardKeyHandler_Backspace(u8 event) +static bool8 KeyboardKeyHandler_Backspace(u8 input) { - sub_80E3948(1, 1, 0); - if (event == KBEVENT_PRESSED_A) + TryStartButtonFlash(BUTTON_BACK, TRUE, FALSE); + if (input == INPUT_A_BUTTON) DeleteTextCharacter(); return FALSE; } -static bool8 KeyboardKeyHandler_OK(u8 event) +static bool8 KeyboardKeyHandler_OK(u8 input) { - sub_80E3948(2, 1, 0); - if (event == KBEVENT_PRESSED_A) + TryStartButtonFlash(BUTTON_OK, TRUE, FALSE); + if (input == INPUT_A_BUTTON) { PlaySE(SE_SELECT); - gNamingScreenData->state = MAIN_STATE_6; + sNamingScreen->state = STATE_PRESSED_OK; return TRUE; } else return FALSE; } -static bool8 sub_80E45E0(void) +static bool8 SwapKeyboardPage(void) { - gNamingScreenData->state = MAIN_STATE_START_PAGE_SWAP; + sNamingScreen->state = STATE_START_PAGE_SWAP; return TRUE; } @@ -1301,33 +1532,26 @@ static bool8 sub_80E45E0(void) // Input handling //-------------------------------------------------- -enum -{ - FNKEY_CASE, - FNKEY_BACK, - FNKEY_OK, -}; - #define tState data[0] #define tKeyboardEvent data[1] -#define tKbFunctionKey data[2] +#define tButtonId data[2] -static void InputState_Disabled(struct Task *); -static void InputState_Enabled(struct Task *); -static void InputState_2(struct Task *); +static void Input_Disabled(struct Task *); +static void Input_Enabled(struct Task *); +static void Input_Override(struct Task *); -static void (*const sInputStateFuncs[])(struct Task *) = +static void (*const sInputFuncs[])(struct Task *) = { - InputState_Disabled, - InputState_Enabled, - InputState_2, + [INPUT_STATE_DISABLED] = Input_Disabled, + [INPUT_STATE_ENABLED] = Input_Enabled, + [INPUT_STATE_OVERRIDE] = Input_Override, }; static void Task_HandleInput(u8); static void HandleDpadMovement(struct Task *); -static void InputInit(void) +static void CreateInputHandlerTask(void) { CreateTask(Task_HandleInput, 1); } @@ -1348,121 +1572,128 @@ static void SetInputState(u8 state) static void Task_HandleInput(u8 taskId) { - sInputStateFuncs[gTasks[taskId].tState](&gTasks[taskId]); + sInputFuncs[gTasks[taskId].tState](&gTasks[taskId]); } -static void InputState_Disabled(struct Task *task) +static void Input_Disabled(struct Task *task) { - task->tKeyboardEvent = 0; + task->tKeyboardEvent = INPUT_NONE; } -static void InputState_Enabled(struct Task *task) +static void Input_Enabled(struct Task *task) { - task->tKeyboardEvent = 0; + task->tKeyboardEvent = INPUT_NONE; - if (gMain.newKeys & A_BUTTON) - task->tKeyboardEvent = KBEVENT_PRESSED_A; - else if (gMain.newKeys & B_BUTTON) - task->tKeyboardEvent = KBEVENT_PRESSED_B; - else if (gMain.newKeys & SELECT_BUTTON) - task->tKeyboardEvent = KBEVENT_PRESSED_SELECT; - else if (gMain.newKeys & START_BUTTON) - task->tKeyboardEvent = KBEVENT_PRESSED_START; + if (JOY_NEW(A_BUTTON)) + task->tKeyboardEvent = INPUT_A_BUTTON; + else if (JOY_NEW(B_BUTTON)) + task->tKeyboardEvent = INPUT_B_BUTTON; + else if (JOY_NEW(SELECT_BUTTON)) + task->tKeyboardEvent = INPUT_SELECT; + else if (JOY_NEW(START_BUTTON)) + task->tKeyboardEvent = INPUT_START; else HandleDpadMovement(task); } -static void InputState_2(struct Task *task) +static void Input_Override(struct Task *task) { - task->tKeyboardEvent = 0; + task->tKeyboardEvent = INPUT_NONE; } static void HandleDpadMovement(struct Task *task) { const s16 sDpadDeltaX[] = { - 0, //none - 0, //up - 0, //down - -1, //left - 1 //right + [INPUT_NONE] = 0, + [INPUT_DPAD_UP] = 0, + [INPUT_DPAD_DOWN] = 0, + [INPUT_DPAD_LEFT] = -1, + [INPUT_DPAD_RIGHT] = 1 }; const s16 sDpadDeltaY[] = { - 0, //none - -1, //up - 1, //down - 0, //left - 0 //right + [INPUT_NONE] = 0, + [INPUT_DPAD_UP] = -1, + [INPUT_DPAD_DOWN] = 1, + [INPUT_DPAD_LEFT] = 0, + [INPUT_DPAD_RIGHT] = 0 }; - const s16 s4RowTo3RowTableY[] = {0, 1, 1, 2}; - const s16 gUnknown_0858BF50[] = {0, 0, 3}; + const s16 sKeyRowToButtonRow[KBROW_COUNT] = {0, 1, 1, 2}; + const s16 sButtonRowToKeyRow[BUTTON_COUNT] = {0, 0, 3}; s16 cursorX; s16 cursorY; - u16 dpadDir; + u16 input; s16 prevCursorX; GetCursorPos(&cursorX, &cursorY); - dpadDir = 0; - if (gMain.newAndRepeatedKeys & DPAD_UP) - dpadDir = 1; - if (gMain.newAndRepeatedKeys & DPAD_DOWN) - dpadDir = 2; - if (gMain.newAndRepeatedKeys & DPAD_LEFT) - dpadDir = 3; - if (gMain.newAndRepeatedKeys & DPAD_RIGHT) - dpadDir = 4; + input = INPUT_NONE; + if (JOY_REPEAT(DPAD_UP)) + input = INPUT_DPAD_UP; + if (JOY_REPEAT(DPAD_DOWN)) + input = INPUT_DPAD_DOWN; + if (JOY_REPEAT(DPAD_LEFT)) + input = INPUT_DPAD_LEFT; + if (JOY_REPEAT(DPAD_RIGHT)) + input = INPUT_DPAD_RIGHT; - //Get new cursor position + // Get new cursor position prevCursorX = cursorX; - cursorX += sDpadDeltaX[dpadDir]; - cursorY += sDpadDeltaY[dpadDir]; + cursorX += sDpadDeltaX[input]; + cursorY += sDpadDeltaY[input]; - //Wrap cursor position in the X direction + // Wrap cursor position in the X direction if (cursorX < 0) cursorX = GetCurrentPageColumnCount(); if (cursorX > GetCurrentPageColumnCount()) cursorX = 0; - //Handle cursor movement in X direction - if (sDpadDeltaX[dpadDir] != 0) + + // Handle moving on/off the button column + if (sDpadDeltaX[input] != 0) { if (cursorX == GetCurrentPageColumnCount()) { - //We are now on the last column - task->tKbFunctionKey = cursorY; - cursorY = s4RowTo3RowTableY[cursorY]; + // Moved onto button column + // Save cursor pos in tButtonId for moving back onto keys + task->tButtonId = cursorY; + cursorY = sKeyRowToButtonRow[cursorY]; } else if (prevCursorX == GetCurrentPageColumnCount()) { - if (cursorY == 1) - cursorY = task->tKbFunctionKey; + // Moved off button column + // If you're on the middle button, go to the row that + // the cursor was on previously (saved in tButtonId above) + if (cursorY == BUTTON_COUNT / 2) + cursorY = task->tButtonId; else - cursorY = gUnknown_0858BF50[cursorY]; + cursorY = sButtonRowToKeyRow[cursorY]; } } + // Wrap cursor position in the y direction if (cursorX == GetCurrentPageColumnCount()) { - //There are only 3 keys on the last column, unlike the others, - //so wrap Y accordingly + // There are only 3 keys in the button column + // so wrap Y accordingly if (cursorY < 0) - cursorY = 2; - if (cursorY > 2) + cursorY = BUTTON_COUNT - 1; + if (cursorY >= BUTTON_COUNT) cursorY = 0; + if (cursorY == 0) - task->tKbFunctionKey = FNKEY_BACK; - else if (cursorY == 2) - task->tKbFunctionKey = FNKEY_OK; + task->tButtonId = BUTTON_BACK; + else if (cursorY == BUTTON_COUNT - 1) + task->tButtonId = BUTTON_OK; } else { if (cursorY < 0) - cursorY = 3; - if (cursorY > 3) + cursorY = KBROW_COUNT - 1; + if (cursorY > KBROW_COUNT - 1) cursorY = 0; } SetCursorPos(cursorX, cursorY); @@ -1470,55 +1701,55 @@ static void HandleDpadMovement(struct Task *task) #undef tState #undef tKeyboardEvent -#undef tKbFunctionKey +#undef tButtonId -static void sub_80E4894(void) +static void DrawNormalTextEntryBox(void) { - FillWindowPixelBuffer(gNamingScreenData->windows[3], PIXEL_FILL(1)); - AddTextPrinterParameterized(gNamingScreenData->windows[3], 1, gNamingScreenData->template->title, 8, 1, 0, 0); - PutWindowTilemap(gNamingScreenData->windows[3]); + FillWindowPixelBuffer(sNamingScreen->windows[WIN_TEXT_ENTRY_BOX], PIXEL_FILL(1)); + AddTextPrinterParameterized(sNamingScreen->windows[WIN_TEXT_ENTRY_BOX], 1, sNamingScreen->template->title, 8, 1, 0, 0); + PutWindowTilemap(sNamingScreen->windows[WIN_TEXT_ENTRY_BOX]); } -static void sub_80E48E8(void) +static void DrawMonTextEntryBox(void) { - u8 buffer[0x20]; + u8 buffer[32]; - StringCopy(buffer, gSpeciesNames[gNamingScreenData->monSpecies]); - StringAppendN(buffer, gNamingScreenData->template->title, 15); - FillWindowPixelBuffer(gNamingScreenData->windows[3], PIXEL_FILL(1)); - AddTextPrinterParameterized(gNamingScreenData->windows[3], 1, buffer, 8, 1, 0, 0); - PutWindowTilemap(gNamingScreenData->windows[3]); + StringCopy(buffer, gSpeciesNames[sNamingScreen->monSpecies]); + StringAppendN(buffer, sNamingScreen->template->title, 15); + FillWindowPixelBuffer(sNamingScreen->windows[WIN_TEXT_ENTRY_BOX], PIXEL_FILL(1)); + AddTextPrinterParameterized(sNamingScreen->windows[WIN_TEXT_ENTRY_BOX], 1, buffer, 8, 1, 0, 0); + PutWindowTilemap(sNamingScreen->windows[WIN_TEXT_ENTRY_BOX]); } -static void (*const gUnknown_0858BF58[])(void) = +static void (*const sDrawTextEntryBoxFuncs[])(void) = { - sub_80E4894, - sub_80E4894, - sub_80E48E8, - sub_80E48E8, - sub_80E4894, + [NAMING_SCREEN_PLAYER] = DrawNormalTextEntryBox, + [NAMING_SCREEN_BOX] = DrawNormalTextEntryBox, + [NAMING_SCREEN_CAUGHT_MON] = DrawMonTextEntryBox, + [NAMING_SCREEN_NICKNAME] = DrawMonTextEntryBox, + [NAMING_SCREEN_WALDA] = DrawNormalTextEntryBox, }; -static void sub_80E4964(void) +static void DrawTextEntryBox(void) { - gUnknown_0858BF58[gNamingScreenData->templateNum](); + sDrawTextEntryBoxFuncs[sNamingScreen->templateNum](); } -static void TaskDummy3(void); -static void sub_80E49BC(void); +static void DummyGenderIcon(void); +static void DrawGenderIcon(void); -static void (*const gUnknown_0858BF6C[])(void) = +static void (*const sDrawGenderIconFuncs[])(void) = { - TaskDummy3, - sub_80E49BC, + [FALSE] = DummyGenderIcon, + [TRUE] = DrawGenderIcon, }; -static void sub_80E498C(void) +static void TryDrawGenderIcon(void) { - gUnknown_0858BF6C[gNamingScreenData->template->addGenderIcon](); + sDrawGenderIconFuncs[sNamingScreen->template->addGenderIcon](); } -static void TaskDummy3(void) +static void DummyGenderIcon(void) { } @@ -1529,49 +1760,48 @@ static const u8 sGenderColors[2][3] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_LIGHT_RED, TEXT_COLOR_RED} }; -static void sub_80E49BC(void) +static void DrawGenderIcon(void) { - u8 genderSymbol[2]; + u8 text[2]; bool8 isFemale = FALSE; - StringCopy(genderSymbol, gText_MaleSymbol); - - if (gNamingScreenData->monGender != MON_GENDERLESS) + StringCopy(text, gText_MaleSymbol); + if (sNamingScreen->monGender != MON_GENDERLESS) { - if (gNamingScreenData->monGender == MON_FEMALE) + if (sNamingScreen->monGender == MON_FEMALE) { - StringCopy(genderSymbol, gText_FemaleSymbol); + StringCopy(text, gText_FemaleSymbol); isFemale = TRUE; } - AddTextPrinterParameterized3(gNamingScreenData->windows[2], 1, 0x68, 1, sGenderColors[isFemale], -1, genderSymbol); + AddTextPrinterParameterized3(sNamingScreen->windows[WIN_TEXT_ENTRY], 1, 0x68, 1, sGenderColors[isFemale], -1, text); } } -static u8 GetCharAtKeyboardPos(s16 a, s16 b) +static u8 GetCharAtKeyboardPos(s16 x, s16 y) { - return gUnknown_0858BE40[a + b * 8 + sub_80E3274() * 32]; + return sKeyboardChars[x + y * KBCOL_COUNT + CurrentPageToKeyboardId() * KBCOL_COUNT * KBROW_COUNT]; } -static u8 GetTextCaretPosition(void) +static u8 GetTextEntryPosition(void) { u8 i; - for (i = 0; i < gNamingScreenData->template->maxChars; i++) + for (i = 0; i < sNamingScreen->template->maxChars; i++) { - if (gNamingScreenData->textBuffer[i] == EOS) + if (sNamingScreen->textBuffer[i] == EOS) return i; } - return gNamingScreenData->template->maxChars - 1; + return sNamingScreen->template->maxChars - 1; } static u8 GetPreviousTextCaretPosition(void) { s8 i; - for (i = gNamingScreenData->template->maxChars - 1; i > 0; i--) + for (i = sNamingScreen->template->maxChars - 1; i > 0; i--) { - if (gNamingScreenData->textBuffer[i] != EOS) + if (sNamingScreen->textBuffer[i] != EOS) return i; } return 0; @@ -1580,112 +1810,115 @@ static u8 GetPreviousTextCaretPosition(void) static void DeleteTextCharacter(void) { u8 index; - u8 var2; + u8 keyRole; index = GetPreviousTextCaretPosition(); - gNamingScreenData->textBuffer[index] = 0; - sub_80E4D10(); + sNamingScreen->textBuffer[index] = 0; + DrawTextEntry(); CopyBgTilemapBufferToVram(3); - gNamingScreenData->textBuffer[index] = EOS; - var2 = GetKeyRoleAtCursorPos(); - if (var2 == 0 || var2 == 2) - sub_80E3948(1, 0, 1); + sNamingScreen->textBuffer[index] = EOS; + keyRole = GetKeyRoleAtCursorPos(); + + // The below flashes the Back key once on delete + // It incorrectly leaves the Back key 1 shade lighter than its default + if (keyRole == KEY_ROLE_CHAR || keyRole == KEY_ROLE_BACKSPACE) + TryStartButtonFlash(BUTTON_BACK, FALSE, TRUE); PlaySE(SE_BOWA); } -static bool8 sub_80E4B54(void) +// Returns TRUE if the text entry is now full +static bool8 AddTextCharacter(void) { s16 x; s16 y; GetCursorPos(&x, &y); - AddTextCharacter(GetCharAtKeyboardPos(x, y)); - sub_80E4D10(); + BufferCharacter(GetCharAtKeyboardPos(x, y)); + DrawTextEntry(); CopyBgTilemapBufferToVram(3); PlaySE(SE_SELECT); - if (GetPreviousTextCaretPosition() != gNamingScreenData->template->maxChars - 1) + if (GetPreviousTextCaretPosition() != sNamingScreen->template->maxChars - 1) return FALSE; else return TRUE; } -static void AddTextCharacter(u8 ch) +static void BufferCharacter(u8 ch) { - u8 index = GetTextCaretPosition(); - - gNamingScreenData->textBuffer[index] = ch; + u8 index = GetTextEntryPosition(); + sNamingScreen->textBuffer[index] = ch; } -static void sub_80E4BE4(void) +static void SaveInputText(void) { u8 i; - for (i = 0; i < gNamingScreenData->template->maxChars; i++) + for (i = 0; i < sNamingScreen->template->maxChars; i++) { - if (gNamingScreenData->textBuffer[i] != CHAR_SPACE && gNamingScreenData->textBuffer[i] != EOS) + if (sNamingScreen->textBuffer[i] != CHAR_SPACE && sNamingScreen->textBuffer[i] != EOS) { - StringCopyN(gNamingScreenData->destBuffer, gNamingScreenData->textBuffer, gNamingScreenData->template->maxChars + 1); + StringCopyN(sNamingScreen->destBuffer, sNamingScreen->textBuffer, sNamingScreen->template->maxChars + 1); break; } } } -static void choose_name_or_words_screen_load_bg_tile_patterns(void) +static void LoadGfx(void) { - LZ77UnCompWram(gNamingScreenMenu_Gfx, gNamingScreenData->tileBuffer); - LoadBgTiles(1, gNamingScreenData->tileBuffer, 0x600, 0); - LoadBgTiles(2, gNamingScreenData->tileBuffer, 0x600, 0); - LoadBgTiles(3, gNamingScreenData->tileBuffer, 0x600, 0); - LoadSpriteSheets(gUnknown_0858C1C8); - LoadSpritePalettes(gUnknown_0858C230); + LZ77UnCompWram(gNamingScreenMenu_Gfx, sNamingScreen->tileBuffer); + LoadBgTiles(1, sNamingScreen->tileBuffer, sizeof(sNamingScreen->tileBuffer), 0); + LoadBgTiles(2, sNamingScreen->tileBuffer, sizeof(sNamingScreen->tileBuffer), 0); + LoadBgTiles(3, sNamingScreen->tileBuffer, sizeof(sNamingScreen->tileBuffer), 0); + LoadSpriteSheets(sSpriteSheets); + LoadSpritePalettes(sSpritePalettes); } -static void sub_80E4CB8(void) +static void CreateHelperTasks(void) { - InputInit(); - sub_80E3920(); + CreateInputHandlerTask(); + CreateButtonFlashTask(); } -static void choose_name_or_words_screen_apply_bg_pals(void) +static void LoadPalettes(void) { LoadPalette(gNamingScreenMenu_Pal, 0, 0xC0); - LoadPalette(gUnknown_0858BD78, 0xA0, sizeof(gUnknown_0858BD78)); - LoadPalette(stdpal_get(2), 0xB0, 0x20); + LoadPalette(sKeyboard_Pal, 0xA0, sizeof(sKeyboard_Pal)); + LoadPalette(GetTextWindowPalette(2), 0xB0, 0x20); } -static void sub_80E4CF8(u8 bg, const void *src) +static void DrawBgTilemap(u8 bg, const void *src) { CopyToBgTilemapBuffer(bg, src, 0, 0); } -static void nullsub_10(u8 a1, u8 page) +static void NamingScreen_Dummy(u8 bg, u8 page) { } -static void sub_80E4D10(void) +static void DrawTextEntry(void) { u8 i; u8 temp[2]; - u16 unk2; - u8 maxChars = gNamingScreenData->template->maxChars; - u16 unk = gNamingScreenData->inputCharBaseXPos - 0x40; + u16 extraWidth; + u8 maxChars = sNamingScreen->template->maxChars; + u16 x = sNamingScreen->inputCharBaseXPos - 0x40; - FillWindowPixelBuffer(gNamingScreenData->windows[2], PIXEL_FILL(1)); + FillWindowPixelBuffer(sNamingScreen->windows[WIN_TEXT_ENTRY], PIXEL_FILL(1)); for (i = 0; i < maxChars; i++) { - temp[0] = gNamingScreenData->textBuffer[i]; + temp[0] = sNamingScreen->textBuffer[i]; temp[1] = gText_ExpandedPlaceholder_Empty[0]; - unk2 = (IsLetter(temp[0]) == TRUE) ? 2 : 0; + extraWidth = (IsWideLetter(temp[0]) == TRUE) ? 2 : 0; - AddTextPrinterParameterized(gNamingScreenData->windows[2], 1, temp, i * 8 + unk + unk2, 1, 0xFF, NULL); + AddTextPrinterParameterized(sNamingScreen->windows[WIN_TEXT_ENTRY], 1, temp, i * 8 + x + extraWidth, 1, 0xFF, NULL); } - sub_80E498C(); - CopyWindowToVram(gNamingScreenData->windows[2], 2); - PutWindowTilemap(gNamingScreenData->windows[2]); + TryDrawGenderIcon(); + CopyWindowToVram(sNamingScreen->windows[WIN_TEXT_ENTRY], 2); + PutWindowTilemap(sNamingScreen->windows[WIN_TEXT_ENTRY]); } struct TextColor // Needed because of alignment @@ -1704,77 +1937,77 @@ static const struct TextColor sTextColorStruct = static const u8 sFillValues[KBPAGE_COUNT] = { - [KBPAGE_LETTERS_LOWER] = PIXEL_FILL(0xE), - [KBPAGE_LETTERS_UPPER] = PIXEL_FILL(0xD), - [KBPAGE_SYMBOLS] = PIXEL_FILL(0xF) + [KEYBOARD_LETTERS_LOWER] = PIXEL_FILL(14), + [KEYBOARD_LETTERS_UPPER] = PIXEL_FILL(13), + [KEYBOARD_SYMBOLS] = PIXEL_FILL(15) }; static const u8 *const sKeyboardTextColors[KBPAGE_COUNT] = { - [KBPAGE_LETTERS_LOWER] = sTextColorStruct.colors[1], - [KBPAGE_LETTERS_UPPER] = sTextColorStruct.colors[0], - [KBPAGE_SYMBOLS] = sTextColorStruct.colors[2] + [KEYBOARD_LETTERS_LOWER] = sTextColorStruct.colors[1], + [KEYBOARD_LETTERS_UPPER] = sTextColorStruct.colors[0], + [KEYBOARD_SYMBOLS] = sTextColorStruct.colors[2] }; -static void sub_80E4DE4(u8 window, u8 page) +static void PrintKeyboardKeys(u8 window, u8 page) { u8 i; FillWindowPixelBuffer(window, sFillValues[page]); for (i = 0; i < KBROW_COUNT; i++) - { AddTextPrinterParameterized3(window, 1, 0, i * 16 + 1, sKeyboardTextColors[page], 0, sNamingScreenKeyboardText[page][i]); - } PutWindowTilemap(window); } -static const u8 *const gUnknown_0858BF98[] = +static const u8 *const sNextKeyboardPageTilemaps[] = { - gUnknown_08DD4620, - gUnknown_08DD46E0, - gUnknown_08DD47A0 + [KBPAGE_SYMBOLS] = gNamingScreenKeyboardUpper_Tilemap, + [KBPAGE_LETTERS_UPPER] = gNamingScreenKeyboardLower_Tilemap, // lower + [KBPAGE_LETTERS_LOWER] = gNamingScreenKeyboardSymbols_Tilemap // symbols }; -static void sub_80E4E5C(void) +// There are always 2 keyboard pages drawn, the current page and the one that will shown next if the player swaps +// When the page swap is complete this function invisibly replaces the old page with the new next one +static void DrawKeyboardPageOnDeck(void) { - u8 unk1; - u8 unk2; - u8 unk3; + u8 bg; + u8 bg_; + u8 windowId; u8 bg1Priority = GetGpuReg(REG_OFFSET_BG1CNT) & 3; u8 bg2Priority = GetGpuReg(REG_OFFSET_BG2CNT) & 3; if (bg1Priority > bg2Priority) { - unk1 = 1; - unk2 = 1; - unk3 = gNamingScreenData->windows[0]; + bg = 1; + bg_ = 1; + windowId = sNamingScreen->windows[WIN_KB_PAGE_1]; } else { - unk1 = 2; - unk2 = 2; - unk3 = gNamingScreenData->windows[1]; + bg = 2; + bg_ = 2; + windowId = sNamingScreen->windows[WIN_KB_PAGE_2]; } - sub_80E4CF8(unk1, gUnknown_0858BF98[gNamingScreenData->currentPage]); - sub_80E4DE4(unk3, sub_80E3254()); - nullsub_10(unk1, sub_80E3254()); - CopyBgTilemapBufferToVram(unk2); + DrawBgTilemap(bg, sNextKeyboardPageTilemaps[sNamingScreen->currentPage]); + PrintKeyboardKeys(windowId, CurrentPageToNextKeyboardId()); + NamingScreen_Dummy(bg, CurrentPageToNextKeyboardId()); + CopyBgTilemapBufferToVram(bg_); } -static void sub_80E4EF0(void) +static void PrintControls(void) { const u8 color[3] = { TEXT_DYNAMIC_COLOR_6, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY }; - FillWindowPixelBuffer(gNamingScreenData->windows[4], PIXEL_FILL(15)); - AddTextPrinterParameterized3(gNamingScreenData->windows[4], 0, 2, 1, color, 0, gText_MoveOkBack); - PutWindowTilemap(gNamingScreenData->windows[4]); - CopyWindowToVram(gNamingScreenData->windows[4], 3); + FillWindowPixelBuffer(sNamingScreen->windows[WIN_BANNER], PIXEL_FILL(15)); + AddTextPrinterParameterized3(sNamingScreen->windows[WIN_BANNER], 0, 2, 1, color, 0, gText_MoveOkBack); + PutWindowTilemap(sNamingScreen->windows[WIN_BANNER]); + CopyWindowToVram(sNamingScreen->windows[WIN_BANNER], 3); } -static void sub_80E4F58(void) +static void CB2_NamingScreen(void) { RunTasks(); AnimateSprites(); @@ -1782,13 +2015,13 @@ static void sub_80E4F58(void) UpdatePaletteFade(); } -static void NamingScreen_TurnOffScreen(void) +static void ResetVHBlank(void) { SetVBlankCallback(NULL); SetHBlankCallback(NULL); } -static void NamingScreen_InitDisplayMode(void) +static void SetVBlank(void) { SetVBlankCallback(VBlankCB_NamingScreen); } @@ -1798,15 +2031,15 @@ static void VBlankCB_NamingScreen(void) LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); - SetGpuReg(REG_OFFSET_BG1VOFS, gNamingScreenData->bg1vOffset); - SetGpuReg(REG_OFFSET_BG2VOFS, gNamingScreenData->bg2vOffset); + SetGpuReg(REG_OFFSET_BG1VOFS, sNamingScreen->bg1vOffset); + SetGpuReg(REG_OFFSET_BG2VOFS, sNamingScreen->bg2vOffset); SetGpuReg(REG_OFFSET_BG1CNT, GetGpuReg(REG_OFFSET_BG1CNT) & 0xFFFC); - SetGpuRegBits(REG_OFFSET_BG1CNT, gNamingScreenData->bg1Priority); + SetGpuRegBits(REG_OFFSET_BG1CNT, sNamingScreen->bg1Priority); SetGpuReg(REG_OFFSET_BG2CNT, GetGpuReg(REG_OFFSET_BG2CNT) & 0xFFFC); - SetGpuRegBits(REG_OFFSET_BG2CNT, gNamingScreenData->bg2Priority); + SetGpuRegBits(REG_OFFSET_BG2CNT, sNamingScreen->bg2Priority); } -static void sub_80E501C(void) +static void NamingScreen_ShowBgs(void) { ShowBg(0); ShowBg(1); @@ -1814,7 +2047,8 @@ static void sub_80E501C(void) ShowBg(3); } -static bool8 IsLetter(u8 character) +// Always false (presumably for non-latin languages) +static bool8 IsWideLetter(u8 character) { u8 i; @@ -1826,69 +2060,71 @@ static bool8 IsLetter(u8 character) return FALSE; } -static void sub_80E5074(void) +// Debug? Unused, and arguments aren't sensible for non-player screens. +static void Debug_NamingScreenPlayer(void) { - DoNamingScreen(0, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_ReturnToFieldWithOpenMenu); + DoNamingScreen(NAMING_SCREEN_PLAYER, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_ReturnToFieldWithOpenMenu); } -static void sub_80E509C(void) +static void Debug_NamingScreenBox(void) { - DoNamingScreen(1, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_ReturnToFieldWithOpenMenu); + DoNamingScreen(NAMING_SCREEN_BOX, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_ReturnToFieldWithOpenMenu); } -static void sub_80E50C4(void) +static void Debug_NamingScreenCaughtMon(void) { - DoNamingScreen(2, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_ReturnToFieldWithOpenMenu); + DoNamingScreen(NAMING_SCREEN_CAUGHT_MON, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_ReturnToFieldWithOpenMenu); } -static void sub_80E50EC(void) +static void Debug_NamingScreenNickname(void) { - DoNamingScreen(3, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_ReturnToFieldWithOpenMenu); + DoNamingScreen(NAMING_SCREEN_NICKNAME, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_ReturnToFieldWithOpenMenu); } //-------------------------------------------------- // Forward-declared variables //-------------------------------------------------- -static const struct NamingScreenTemplate playerNamingScreenTemplate = +// Initial pages below are pointless, they're overwritten with KBPAGE_LETTERS_UPPER in MainState_FadeIn() +static const struct NamingScreenTemplate sPlayerNamingScreenTemplate = { - .copyExistingString = 0, + .copyExistingString = FALSE, .maxChars = 7, .iconFunction = 1, - .addGenderIcon = 0, + .addGenderIcon = FALSE, .initialPage = KBPAGE_LETTERS_UPPER, .unused = 35, .title = gText_YourName, }; -static const struct NamingScreenTemplate pcBoxNamingTemplate = +static const struct NamingScreenTemplate sPCBoxNamingTemplate = { - .copyExistingString = 0, + .copyExistingString = FALSE, .maxChars = 8, .iconFunction = 2, - .addGenderIcon = 0, + .addGenderIcon = FALSE, .initialPage = KBPAGE_LETTERS_UPPER, .unused = 19, .title = gText_BoxName, }; -static const struct NamingScreenTemplate monNamingScreenTemplate = +static const struct NamingScreenTemplate sMonNamingScreenTemplate = { - .copyExistingString = 0, + .copyExistingString = FALSE, .maxChars = 10, .iconFunction = 3, - .addGenderIcon = 1, + .addGenderIcon = TRUE, .initialPage = KBPAGE_LETTERS_UPPER, .unused = 35, .title = gText_PkmnsNickname, }; -static const struct NamingScreenTemplate wandaWordsScreenTemplate = +static const struct NamingScreenTemplate sWaldaWordsScreenTemplate = { - .copyExistingString = 1, + .copyExistingString = TRUE, .maxChars = 15, .iconFunction = 4, - .addGenderIcon = 0, + .addGenderIcon = FALSE, .initialPage = KBPAGE_LETTERS_UPPER, .unused = 11, .title = gText_TellHimTheWords, @@ -1896,14 +2132,14 @@ static const struct NamingScreenTemplate wandaWordsScreenTemplate = static const struct NamingScreenTemplate *const sNamingScreenTemplates[] = { - &playerNamingScreenTemplate, - &pcBoxNamingTemplate, - &monNamingScreenTemplate, - &monNamingScreenTemplate, - &wandaWordsScreenTemplate, + [NAMING_SCREEN_PLAYER] = &sPlayerNamingScreenTemplate, + [NAMING_SCREEN_BOX] = &sPCBoxNamingTemplate, + [NAMING_SCREEN_CAUGHT_MON] = &sMonNamingScreenTemplate, + [NAMING_SCREEN_NICKNAME] = &sMonNamingScreenTemplate, + [NAMING_SCREEN_WALDA] = &sWaldaWordsScreenTemplate, }; -const struct OamData gOamData_858BFEC = +static const struct OamData sOam_8x8 = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1917,7 +2153,7 @@ const struct OamData gOamData_858BFEC = .paletteNum = 0, }; -const struct OamData gOamData_858BFF4 = +static const struct OamData sOam_16x16 = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1931,7 +2167,7 @@ const struct OamData gOamData_858BFF4 = .paletteNum = 0, }; -const struct OamData gOamData_858BFFC = +static const struct OamData sOam_32x16 = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -1945,7 +2181,7 @@ const struct OamData gOamData_858BFFC = .paletteNum = 0, }; -static const struct Subsprite gUnknown_0858C004[] = +static const struct Subsprite sSubsprites_PageSwapFrame[] = { { .x = -20, @@ -2013,7 +2249,7 @@ static const struct Subsprite gUnknown_0858C004[] = } }; -static const struct Subsprite gUnknown_0858C024[] = +static const struct Subsprite sSubsprites_PageSwapText[] = { { .x = -12, @@ -2033,7 +2269,7 @@ static const struct Subsprite gUnknown_0858C024[] = } }; -static const struct Subsprite gUnknown_0858C02C[] = +static const struct Subsprite sSubsprites_Button[] = { { .x = -20, @@ -2085,7 +2321,7 @@ static const struct Subsprite gUnknown_0858C02C[] = } }; -static const struct Subsprite gUnknown_0858C044[] = +static const struct Subsprite sSubsprites_PCIcon[] = { { .x = -8, @@ -2113,186 +2349,186 @@ static const struct Subsprite gUnknown_0858C044[] = } }; -static const struct SubspriteTable gUnknown_0858C050[] = +static const struct SubspriteTable sSubspriteTable_PageSwapFrame[] = { - {ARRAY_COUNT(gUnknown_0858C004), gUnknown_0858C004} + {ARRAY_COUNT(sSubsprites_PageSwapFrame), sSubsprites_PageSwapFrame} }; -static const struct SubspriteTable gUnknown_0858C058[] = +static const struct SubspriteTable sSubspriteTable_PageSwapText[] = { - {ARRAY_COUNT(gUnknown_0858C024), gUnknown_0858C024}, - {ARRAY_COUNT(gUnknown_0858C024), gUnknown_0858C024}, - {ARRAY_COUNT(gUnknown_0858C024), gUnknown_0858C024} + {ARRAY_COUNT(sSubsprites_PageSwapText), sSubsprites_PageSwapText}, + {ARRAY_COUNT(sSubsprites_PageSwapText), sSubsprites_PageSwapText}, + {ARRAY_COUNT(sSubsprites_PageSwapText), sSubsprites_PageSwapText} }; -static const struct SubspriteTable gUnknown_0858C070[] = +static const struct SubspriteTable sSubspriteTable_Button[] = { - {ARRAY_COUNT(gUnknown_0858C02C), gUnknown_0858C02C} + {ARRAY_COUNT(sSubsprites_Button), sSubsprites_Button} }; -static const struct SubspriteTable gUnknown_0858C078[] = +static const struct SubspriteTable sSubspriteTable_PCIcon[] = { - {ARRAY_COUNT(gUnknown_0858C044), gUnknown_0858C044} + {ARRAY_COUNT(sSubsprites_PCIcon), sSubsprites_PCIcon} }; -static const struct SpriteFrameImage gUnknown_0858C080[] = +static const struct SpriteFrameImage sImageTable_PCIcon[] = { - {gSpriteImage_858BBF8, sizeof(gSpriteImage_858BBF8)}, - {gSpriteImage_858BCB8, sizeof(gSpriteImage_858BCB8)}, + {sPCIconOff_Gfx, sizeof(sPCIconOff_Gfx)}, + {sPCIconOn_Gfx, sizeof(sPCIconOn_Gfx)}, }; -static const union AnimCmd gSpriteAnim_858C090[] = +static const union AnimCmd sAnim_Loop[] = { ANIMCMD_FRAME(0, 1), ANIMCMD_JUMP(0) }; -static const union AnimCmd gSpriteAnim_858C098[] = +static const union AnimCmd sAnim_CursorSquish[] = { ANIMCMD_FRAME(4, 8), ANIMCMD_FRAME(8, 8), ANIMCMD_END }; -static const union AnimCmd gSpriteAnim_858C0A4[] = +static const union AnimCmd sAnim_PCIcon[] = { ANIMCMD_FRAME(0, 2), ANIMCMD_FRAME(1, 2), ANIMCMD_JUMP(0) }; -static const union AnimCmd *const gSpriteAnimTable_858C0B0[] = +static const union AnimCmd *const sAnims_Loop[] = { - gSpriteAnim_858C090 + sAnim_Loop }; -static const union AnimCmd *const gSpriteAnimTable_858C0B4[] = +static const union AnimCmd *const sAnims_Cursor[] = { - gSpriteAnim_858C090, - gSpriteAnim_858C098 + sAnim_Loop, + sAnim_CursorSquish }; -static const union AnimCmd *const gSpriteAnimTable_858C0BC[] = +static const union AnimCmd *const sAnims_PCIcon[] = { - gSpriteAnim_858C0A4 + sAnim_PCIcon }; -static const struct SpriteTemplate gUnknown_0858C0C0 = +static const struct SpriteTemplate sSpriteTemplate_PageSwapFrame = { - .tileTag = 0x0002, - .paletteTag = 0x0004, - .oam = &gOamData_858BFEC, - .anims = gSpriteAnimTable_858C0B0, + .tileTag = GFXTAG_PAGE_SWAP_FRAME, + .paletteTag = PALTAG_PAGE_SWAP, + .oam = &sOam_8x8, + .anims = sAnims_Loop, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80E4084 + .callback = SpriteCB_PageSwap }; -static const struct SpriteTemplate gUnknown_0858C0D8 = +static const struct SpriteTemplate sSpriteTemplate_PageSwapButton = { - .tileTag = 0x0003, - .paletteTag = 0x0001, - .oam = &gOamData_858BFFC, - .anims = gSpriteAnimTable_858C0B0, + .tileTag = GFXTAG_PAGE_SWAP_BUTTON, + .paletteTag = PALTAG_PAGE_SWAP_UPPER, + .oam = &sOam_32x16, + .anims = sAnims_Loop, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_0858C0F0 = +static const struct SpriteTemplate sSpriteTemplate_PageSwapText = { - .tileTag = 0x0004, - .paletteTag = 0x0004, - .oam = &gOamData_858BFEC, - .anims = gSpriteAnimTable_858C0B0, + .tileTag = GFXTAG_PAGE_SWAP_UPPER, + .paletteTag = PALTAG_PAGE_SWAP, + .oam = &sOam_8x8, + .anims = sAnims_Loop, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_0858C108 = +static const struct SpriteTemplate sSpriteTemplate_BackButton = { - .tileTag = 0x0000, - .paletteTag = 0x0006, - .oam = &gOamData_858BFEC, - .anims = gSpriteAnimTable_858C0B0, + .tileTag = GFXTAG_BACK_BUTTON, + .paletteTag = PALTAG_BACK_BUTTON, + .oam = &sOam_8x8, + .anims = sAnims_Loop, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_0858C120 = +static const struct SpriteTemplate sSpriteTemplate_OkButton = { - .tileTag = 0x0001, - .paletteTag = 0x0007, - .oam = &gOamData_858BFEC, - .anims = gSpriteAnimTable_858C0B0, + .tileTag = GFXTAG_OK_BUTTON, + .paletteTag = PALTAG_OK_BUTTON, + .oam = &sOam_8x8, + .anims = sAnims_Loop, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; -static const struct SpriteTemplate gUnknown_0858C138 = +static const struct SpriteTemplate sSpriteTemplate_Cursor = { - .tileTag = 0x0007, - .paletteTag = 0x0005, - .oam = &gOamData_858BFF4, - .anims = gSpriteAnimTable_858C0B4, + .tileTag = GFXTAG_CURSOR, + .paletteTag = PALTAG_CURSOR, + .oam = &sOam_16x16, + .anims = sAnims_Cursor, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80E3B30 + .callback = SpriteCB_Cursor }; static const struct SpriteTemplate sSpriteTemplate_InputArrow = { - .tileTag = 0x000A, - .paletteTag = 0x0003, - .oam = &gOamData_858BFEC, - .anims = gSpriteAnimTable_858C0B0, + .tileTag = GFXTAG_INPUT_ARROW, + .paletteTag = PALTAG_PAGE_SWAP_OTHERS, + .oam = &sOam_8x8, + .anims = sAnims_Loop, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80E3C20 + .callback = SpriteCB_InputArrow }; static const struct SpriteTemplate sSpriteTemplate_Underscore = { - .tileTag = 0x000B, - .paletteTag = 0x0003, - .oam = &gOamData_858BFEC, - .anims = gSpriteAnimTable_858C0B0, + .tileTag = GFXTAG_UNDERSCORE, + .paletteTag = PALTAG_PAGE_SWAP_OTHERS, + .oam = &sOam_8x8, + .anims = sAnims_Loop, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80E3C6C + .callback = SpriteCB_Underscore }; -static const struct SpriteTemplate gUnknown_0858C180 = +static const struct SpriteTemplate sSpriteTemplate_PCIcon = { .tileTag = 0xFFFF, - .paletteTag = 0x0000, - .oam = &gOamData_858BFEC, - .anims = gSpriteAnimTable_858C0BC, - .images = gUnknown_0858C080, + .paletteTag = PALTAG_PC_ICON, + .oam = &sOam_8x8, + .anims = sAnims_PCIcon, + .images = sImageTable_PCIcon, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; static const u8* const sNamingScreenKeyboardText[KBPAGE_COUNT][KBROW_COUNT] = { - [KBPAGE_LETTERS_LOWER] = + [KEYBOARD_LETTERS_LOWER] = { gText_NamingScreenKeyboard_abcdef, gText_NamingScreenKeyboard_ghijkl, gText_NamingScreenKeyboard_mnopqrs, gText_NamingScreenKeyboard_tuvwxyz }, - [KBPAGE_LETTERS_UPPER] = + [KEYBOARD_LETTERS_UPPER] = { gText_NamingScreenKeyboard_ABCDEF, gText_NamingScreenKeyboard_GHIJKL, gText_NamingScreenKeyboard_MNOPQRS, gText_NamingScreenKeyboard_TUVWXYZ }, - [KBPAGE_SYMBOLS] = + [KEYBOARD_SYMBOLS] = { gText_NamingScreenKeyboard_01234, gText_NamingScreenKeyboard_56789, @@ -2301,34 +2537,34 @@ static const u8* const sNamingScreenKeyboardText[KBPAGE_COUNT][KBROW_COUNT] = }, }; -static const struct SpriteSheet gUnknown_0858C1C8[] = +static const struct SpriteSheet sSpriteSheets[] = { - {gNamingScreenRWindow_Gfx + 0x280, 0x1E0, 0x0000}, - {gNamingScreenRWindow_Gfx + 0x460, 0x1E0, 0x0001}, - {gNamingScreenRWindow_Gfx, 0x280, 0x0002}, - {gNamingScreenKeyboardButton_Gfx + 0x20, 0x100, 0x0003}, - {gNamingScreenROptions_Gfx, 0x060, 0x0004}, - {gNamingScreenROptions_Gfx + 0xA0, 0x060, 0x0005}, - {gNamingScreenROptions_Gfx + 0x140, 0x060, 0x0006}, - {gNamingScreenCursor_Gfx, 0x080, 0x0007}, - {gNamingScreenCursor_Gfx + 0xA0, 0x080, 0x0008}, - {gNamingScreenCursor_Gfx + 0x140, 0x080, 0x0009}, - {gNamingScreenRightPointingTriangleTiles, 0x020, 0x000A}, - {gNamingScreenUnderscoreTiles, 0x020, 0x000B}, - {NULL} + {gNamingScreenRWindow_Gfx + 0x280, 0x1E0, GFXTAG_BACK_BUTTON}, + {gNamingScreenRWindow_Gfx + 0x460, 0x1E0, GFXTAG_OK_BUTTON}, + {gNamingScreenRWindow_Gfx, 0x280, GFXTAG_PAGE_SWAP_FRAME}, + {gNamingScreenPageButton_Gfx + 0x20, 0x100, GFXTAG_PAGE_SWAP_BUTTON}, + {gNamingScreenROptions_Gfx, 0x060, GFXTAG_PAGE_SWAP_UPPER}, + {gNamingScreenROptions_Gfx + 0xA0, 0x060, GFXTAG_PAGE_SWAP_LOWER}, + {gNamingScreenROptions_Gfx + 0x140, 0x060, GFXTAG_PAGE_SWAP_OTHERS}, + {gNamingScreenCursor_Gfx, 0x080, GFXTAG_CURSOR}, + {gNamingScreenCursor_Gfx + 0xA0, 0x080, GFXTAG_CURSOR_SQUISHED}, + {gNamingScreenCursor_Gfx + 0x140, 0x080, GFXTAG_CURSOR_FILLED}, + {gNamingScreenInputArrow_Gfx, 0x020, GFXTAG_INPUT_ARROW}, + {gNamingScreenUnderscore_Gfx, 0x020, GFXTAG_UNDERSCORE}, + {} }; -static const struct SpritePalette gUnknown_0858C230[] = +static const struct SpritePalette sSpritePalettes[] = { - {gNamingScreenMenu_Pal, 0x0000}, - {gNamingScreenMenu_Pal + 0x10, 0x0001}, - {gNamingScreenMenu_Pal + 0x20, 0x0002}, - {gNamingScreenMenu_Pal + 0x30, 0x0003}, - {gNamingScreenMenu_Pal + 0x40, 0x0004}, - {gNamingScreenMenu_Pal + 0x50, 0x0005}, - {gNamingScreenMenu_Pal + 0x40, 0x0006}, - {gNamingScreenMenu_Pal + 0x40, 0x0007}, - {NULL} + {gNamingScreenMenu_Pal, PALTAG_PC_ICON}, + {gNamingScreenMenu_Pal + 0x10, PALTAG_PAGE_SWAP_UPPER}, + {gNamingScreenMenu_Pal + 0x20, PALTAG_PAGE_SWAP_LOWER}, + {gNamingScreenMenu_Pal + 0x30, PALTAG_PAGE_SWAP_OTHERS}, + {gNamingScreenMenu_Pal + 0x40, PALTAG_PAGE_SWAP}, + {gNamingScreenMenu_Pal + 0x50, PALTAG_CURSOR}, + {gNamingScreenMenu_Pal + 0x40, PALTAG_BACK_BUTTON}, + {gNamingScreenMenu_Pal + 0x40, PALTAG_OK_BUTTON}, + {} }; diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 115c369af..5f2f5516b 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -8097,7 +8097,7 @@ static bool8 sub_80D0344(void) if (!IsDma3ManagerBusyWithBgCopy()) { sub_80CFE84(); - LoadPalette(stdpal_get(3), 0xD0, 0x20); + LoadPalette(GetTextWindowPalette(3), 0xD0, 0x20); ShowBg(0); return FALSE; } @@ -8203,7 +8203,7 @@ static bool8 sub_80D04C8(void) case 3: if (!IsDma3ManagerBusyWithBgCopy()) { - LoadPalette(stdpal_get(3), 0xD0, 0x20); + LoadPalette(GetTextWindowPalette(3), 0xD0, 0x20); sub_80CFE84(); ShowBg(0); return FALSE; diff --git a/src/text_window.c b/src/text_window.c index 98fc09e87..864bd0831 100644 --- a/src/text_window.c +++ b/src/text_window.c @@ -49,7 +49,7 @@ static const u16 sTextWindowFrame18_Pal[] = INCBIN_U16("graphics/text_window/18. static const u16 sTextWindowFrame19_Pal[] = INCBIN_U16("graphics/text_window/19.gbapal"); static const u16 sTextWindowFrame20_Pal[] = INCBIN_U16("graphics/text_window/20.gbapal"); -static const u16 sUnknown_0851017C[][16] = +static const u16 sTextWindowPalettes[][16] = { INCBIN_U16("graphics/text_window/message_box.gbapal"), INCBIN_U16("graphics/text_window/text_pal1.gbapal"), @@ -160,7 +160,7 @@ void rbox_fill_rectangle(u8 windowId) FillBgTilemapBufferRect(bgLayer, 0, tilemapLeft - 1, tilemapTop - 1, width + 2, height + 2, 0x11); } -const u16 *stdpal_get(u8 id) +const u16 *GetTextWindowPalette(u8 id) { switch (id) { @@ -182,7 +182,7 @@ const u16 *stdpal_get(u8 id) break; } - return (const u16 *)(sUnknown_0851017C) + id; + return (const u16 *)(sTextWindowPalettes) + id; } const u16 *GetOverworldTextboxPalettePtr(void) diff --git a/src/tv.c b/src/tv.c index 0e419a99f..0444912f0 100644 --- a/src/tv.c +++ b/src/tv.c @@ -3442,7 +3442,7 @@ void ChangePokemonNickname(void) GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_NICKNAME, gStringVar3); GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_NICKNAME, gStringVar2); - DoNamingScreen(3, gStringVar2, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES, NULL), GetMonGender(&gPlayerParty[gSpecialVar_0x8004]), GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_PERSONALITY, NULL), ChangePokemonNickname_CB); + DoNamingScreen(NAMING_SCREEN_NICKNAME, gStringVar2, GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES, NULL), GetMonGender(&gPlayerParty[gSpecialVar_0x8004]), GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_PERSONALITY, NULL), ChangePokemonNickname_CB); } void ChangePokemonNickname_CB(void) @@ -3458,7 +3458,7 @@ void ChangeBoxPokemonNickname(void) boxMon = GetBoxedMonPtr(gSpecialVar_MonBoxId, gSpecialVar_MonBoxPos); GetBoxMonData(boxMon, MON_DATA_NICKNAME, gStringVar3); GetBoxMonData(boxMon, MON_DATA_NICKNAME, gStringVar2); - DoNamingScreen(3, gStringVar2, GetBoxMonData(boxMon, MON_DATA_SPECIES, NULL), GetBoxMonGender(boxMon), GetBoxMonData(boxMon, MON_DATA_PERSONALITY, NULL), ChangeBoxPokemonNickname_CB); + DoNamingScreen(NAMING_SCREEN_NICKNAME, gStringVar2, GetBoxMonData(boxMon, MON_DATA_SPECIES, NULL), GetBoxMonGender(boxMon), GetBoxMonData(boxMon, MON_DATA_PERSONALITY, NULL), ChangeBoxPokemonNickname_CB); } void ChangeBoxPokemonNickname_CB(void)