From 863e6149383f2f806e7f188ce5deb80c1c21216f Mon Sep 17 00:00:00 2001 From: Pseurae Date: Wed, 16 Oct 2024 11:12:01 +0000 Subject: [PATCH] Change to lowercase after first letter in naming screen --- assets/stats_viewer.4bpp.lz | Bin 0 -> 168 bytes assets/stats_viewer.bin.lz | Bin 0 -> 292 bytes assets/stats_viewer.gbapal.lz | Bin 0 -> 24 bytes config.asm | 3 + include/decompress.h | 1 + include/naming_screen.h | 67 +++++++++++++++++++++ include/text.h | 1 + include/types.h | 13 +++- linker/ram.ld | 2 +- linker/rodata.ld | 3 +- linker/text.ld | 8 +++ main.asm | 1 + scripts/autocase.asm | 4 ++ src/naming_screen.c | 24 ++++++++ src/stats_viewer.c | 109 ++++++++++++++++++++++------------ 15 files changed, 196 insertions(+), 40 deletions(-) create mode 100644 assets/stats_viewer.4bpp.lz create mode 100644 assets/stats_viewer.bin.lz create mode 100644 assets/stats_viewer.gbapal.lz create mode 100644 include/naming_screen.h create mode 100644 scripts/autocase.asm create mode 100644 src/naming_screen.c diff --git a/assets/stats_viewer.4bpp.lz b/assets/stats_viewer.4bpp.lz new file mode 100644 index 0000000000000000000000000000000000000000..2eb628cca2c002522946161927852a1f3a903ba1 GIT binary patch literal 168 zcmWe&U|}$HarwZwfKkNQ_yhCv0_G2l8yFcFJ}^#T{1E&{ptykfg8zs4AD9;~yEvT( zQz{>r8<;-?J23xuSpU&bfw5q{Lh=Xsg7X6DcRt7m$cqRne_#$^78JA>6#N)k!1zJ- ZVEu=x4~+jmFrq@j0uMkM9DuH2005PXMGXJ| literal 0 HcmV?d00001 diff --git a/assets/stats_viewer.bin.lz b/assets/stats_viewer.bin.lz new file mode 100644 index 0000000000000000000000000000000000000000..b0bbd07daea36378f61fbc11b1eb927bfab6c265 GIT binary patch literal 292 zcmWe&;9yV|V7S1@$iVc0@dM*V21aHE#t-%^46Gj*zkXl@u>}~}7Vxq=u={f)2y(Cl zaDK1{!T%5nK~h8D2h6wtMotEQ5fyRHa|G)^uKoSV;zk?a}7Z`aJ e#6cqK1sM4rF!Fy;1xqvjhfoNT41oh6-3$PX+J^Q3 literal 0 HcmV?d00001 diff --git a/assets/stats_viewer.gbapal.lz b/assets/stats_viewer.gbapal.lz new file mode 100644 index 0000000000000000000000000000000000000000..62e0b0d6c0f942276a4b30b16e6ef8435303ba01 GIT binary patch literal 24 acmWeoU;u%&rkbi8iX3~(85lk=f&>67Gy}H) literal 0 HcmV?d00001 diff --git a/config.asm b/config.asm index 155a77f..8786a96 100644 --- a/config.asm +++ b/config.asm @@ -87,6 +87,9 @@ ; Gen 6 Exp. Share .definelabel EXP_ALL, 1 +; Auto-change to lowercase after first letter in naming screen. +.definelabel AUTOCASE, 1 + ; Bugfixes ; -------- diff --git a/include/decompress.h b/include/decompress.h index 19a8ffe..16ee9fa 100644 --- a/include/decompress.h +++ b/include/decompress.h @@ -15,3 +15,4 @@ struct CompressedSpriteSheet void LONG_CALL LoadCompressedObjectPic(const struct CompressedSpriteSheet *src); void LONG_CALL DecompressPicFromTable_2(const void *src, u8 coords, u8 y_offset, void *d, void *dest, s32 species); +void LONG_CALL LZDecompressVram(const void *src, void *dest); diff --git a/include/naming_screen.h b/include/naming_screen.h new file mode 100644 index 0000000..659d603 --- /dev/null +++ b/include/naming_screen.h @@ -0,0 +1,67 @@ +#pragma once + +#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 + +enum +{ + PAGE_UPPER, + PAGE_LOWER, + PAGE_OTHERS, +}; + +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, +}; + +struct NamingScreen +{ + /*0x00*/ u8 state; + /*0x01*/ u8 templateNum; + /*0x02*/ u16 nameLeftOffset; + /*0x04*/ u16 bg1vOffset; + /*0x06*/ u16 bg2vOffset; + /*0x08*/ u16 bg1Priority; + /*0x0A*/ u16 bg2Priority; + /*0x0C*/ u8 bgToReveal; + /*0x0D*/ u8 bgToHide; + /*0x0E*/ u8 currentPage; + /*0x0F*/ u8 cursorSpriteId; + /*0x10*/ u8 pageIndicatorSpriteId; + /*0x11*/ u8 textBuffer[0x10]; + /*0x21*/ u8 filler21[0x13]; + /*0x34*/ const struct NamingScreenTemplate *template; + /*0x38*/ u8 *destBuffer; + /*0x3C*/ u16 keyRepeatStartDelayCopy; + /*0x3E*/ u16 speciesOrPlayerGender; + /*0x40*/ u16 monGender; + /*0x42*/ u32 monPersonality; + /*0x46*/ MainCallback returnCallback; +}; + +void LONG_CALL TryStartButtonFlash(u8, u8, u8); +bool8 LONG_CALL AddTextCharacter(void); +void LONG_CALL SquishCursor(void); +void LONG_CALL SetInputState(u8); +void LONG_CALL MainState_StartPageSwap(void); +u8 LONG_CALL GetTextEntryPosition(void); diff --git a/include/text.h b/include/text.h index 2ed5deb..8341232 100644 --- a/include/text.h +++ b/include/text.h @@ -220,5 +220,6 @@ void SetCursorY(struct Window *, u8); void LONG_CALL AddToCursorX(struct Window *, u8); void LONG_CALL AddToCursorY(struct Window *, u8); u16 *GetCursorTilemapPointerWithOffset(struct Window *win, u32, u32); +void LONG_CALL SetWindowBackgroundColor(struct Window *, u8); extern const u8 gFontDefaultPalette[]; diff --git a/include/types.h b/include/types.h index 38e4bdf..9e2213e 100644 --- a/include/types.h +++ b/include/types.h @@ -47,4 +47,15 @@ struct UCoords16 #define ARRAY_COUNT(array) (sizeof(array) / sizeof((array)[0])) -#define _(s) (s) \ No newline at end of file +#define _(s) (s) + +#define INCBIN(...) \ + { \ + 0 \ + } +#define INCBIN_U8 INCBIN +#define INCBIN_U16 INCBIN +#define INCBIN_U32 INCBIN +#define INCBIN_S8 INCBIN +#define INCBIN_S16 INCBIN +#define INCBIN_S32 INCBIN \ No newline at end of file diff --git a/linker/ram.ld b/linker/ram.ld index a2c3d49..1e871b5 100644 --- a/linker/ram.ld +++ b/linker/ram.ld @@ -80,4 +80,4 @@ gBagPocketScrollStates = 0x3005d10; gCurrentBagPocketItemSlots = 0x3005d24; gScriptContext1 = 0x3007440; sMessageBoxMode = 0x30074b8; -gWindowTemplate_Contest_MoveDescription = 0x3004210; \ No newline at end of file +gWindowTemplate_Contest_MoveDescription = 0x3004210; diff --git a/linker/rodata.ld b/linker/rodata.ld index 7393e2a..0fe547d 100644 --- a/linker/rodata.ld +++ b/linker/rodata.ld @@ -1,7 +1,7 @@ Event_NoRegisteredItem = 0x81a14af; BattleScript_SubstituteFade = 0x81d99ab; gFontDefaultPalette = 0x81e66b2; -gWindowTemplate_81E6C3C = 0x81E6C3C; +gWindowTemplate_81E6C3C = 0x81e6c3c; gMenuTextWindowTemplate = 0x81e6ce4; gMonFrontPicCoords = 0x81e7c74; gMonFrontPicTable = 0x81e8354; @@ -58,3 +58,4 @@ BattleStatText_SpAtk = 0x84007ea; BattleStatText_SpDef = 0x84007f2; OtherText_MaleSymbol = 0x8410458; OtherText_FemaleSymbol = 0x841045a; +gNamingScreenPtr = 0x83ce214; diff --git a/linker/text.ld b/linker/text.ld index 1bad019..47f2242 100644 --- a/linker/text.ld +++ b/linker/text.ld @@ -262,3 +262,11 @@ LoadOam = 0x8000f70 | 1; CB2_ReturnToField = 0x80545e4 | 1; Menu_EraseScreen = 0x8071ef4 | 1; GetMonGender = 0x803c4b8 | 1; +LZDecompressVram = 0x800d244 | 1; +SetWindowBackgroundColor = 0x8003f60 | 1; +TryStartButtonFlash = 0x80b6460 | 1; +AddTextCharacter = 0x80b7004 | 1; +SquishCursor = 0x80b6914 | 1; +SetInputState = 0x80b6210 | 1; +MainState_StartPageSwap = 0x80b61c8 | 1; +GetTextEntryPosition = 0x80b6f44 | 1; diff --git a/main.asm b/main.asm index bd3aac7..871476b 100644 --- a/main.asm +++ b/main.asm @@ -52,6 +52,7 @@ .include "scripts/bugfixes/text_colors.asm" .include "scripts/ability_changer.asm" +.include "scripts/autocase.asm" .include "scripts/autorun.asm" .include "scripts/birch_speech.asm" .include "scripts/bag_expansion.asm" diff --git a/scripts/autocase.asm b/scripts/autocase.asm new file mode 100644 index 0000000..7e1b53a --- /dev/null +++ b/scripts/autocase.asm @@ -0,0 +1,4 @@ +.if AUTOCASE +.org 0x83ce240 +.word (KeyboardKeyHandler_Character | 1) +.endif \ No newline at end of file diff --git a/src/naming_screen.c b/src/naming_screen.c new file mode 100644 index 0000000..7adef05 --- /dev/null +++ b/src/naming_screen.c @@ -0,0 +1,24 @@ +#include "types.h" +#include "naming_screen.h" + +extern struct NamingScreen *const gNamingScreenPtr; + +u8 KeyboardKeyHandler_Character(u8 event) +{ + TryStartButtonFlash(3, 0, 0); + if (event == KBEVENT_PRESSED_A) + { + u8 textFull = AddTextCharacter(); + + if (gNamingScreenPtr ->currentPage == PAGE_UPPER && GetTextEntryPosition() == 1) + MainState_StartPageSwap(); + + SquishCursor(); + if (textFull) + { + SetInputState(INPUT_STATE_DISABLED); + gNamingScreenPtr->state = MAIN_STATE_MOVE_TO_OK_BUTTON; + } + } + return FALSE; +} \ No newline at end of file diff --git a/src/stats_viewer.c b/src/stats_viewer.c index a950f7f..4056cd1 100644 --- a/src/stats_viewer.c +++ b/src/stats_viewer.c @@ -17,30 +17,6 @@ #include "constants/songs.h" #include "constants/species.h" -/* -u16 paletteNum = (gMenuWindowPtr->paletteNum << 12); -SetCursorX(gMenuWindowPtr, 8); -SetCursorY(gMenuWindowPtr, 8); - -for (u8 i = 0; i < 3; ++i) -{ - u16 tileNum = GetCursorTileNum(gMenuWindowPtr, 0, 0); - u32 *tileData = (u32 *)(gMenuWindowPtr->tileData + 32 * tileNum); - - for (u8 y = 0; y < 8; ++y) - for (u8 x = 0; x < 8; ++x) - { - tileData[y] |= (gMenuWindowPtr->foregroundColor << (4 * x)); - } - - *GetCursorTilemapPointerWithOffset(gMenuWindowPtr, 0, 0) = tileNum | paletteNum; - *GetCursorTilemapPointerWithOffset(gMenuWindowPtr, 0, 1) = tileNum | paletteNum; - AddToCursorX(gMenuWindowPtr, 8); -} - -AddToCursorY(gMenuWindowPtr, 8); -*/ - const u8 sText_HP[] = _("HP"); const u8 sText_Attack[] = _("Attack"); const u8 sText_Defense[] = _("Defense"); @@ -198,7 +174,7 @@ static void StatViewer_PrintPokemonCount(void) *(ptr++) = CHAR_SLASH; *(ptr++) = CHAR_SPACE; ptr = ConvertIntToDecimalString(ptr, gPlayerPartyCount); - Menu_PrintText(gStringVar4, 1, 17); + MenuPrint_Centered(gStringVar4, 4, 17, StringLength(gStringVar4)); } static void StatViewer_PrintPokemonInfo(void) @@ -223,7 +199,7 @@ static void StatViewer_PrintPokemonInfo(void) ptr = StringCopy(ptr, gSpeciesNames[species]); *(ptr++) = EXT_CTRL_CODE_BEGIN; *(ptr++) = EXT_CTRL_CODE_CLEAR_TO; - *(ptr++) = (POKEMON_NAME_LENGTH + 1) * 6; + *(ptr++) = POKEMON_NAME_LENGTH * 6; *(ptr++) = EOS; Menu_PrintText(gStringVar4, 1, 3); @@ -279,7 +255,7 @@ static void StatViewer_DrawMonSprite(void) { struct Pokemon *mon = &gPlayerParty[sStatViewer.selectedMon]; u16 species = GetMonData(mon, MON_DATA_SPECIES); - sStatViewer.monSpriteId = CreateMonSprite_PicBox(species, 36, 96, 0); + sStatViewer.monSpriteId = CreateMonSprite_PicBox(species, 38, 96, 0); if (sStatViewer.monSpriteId != MAX_SPRITES) { @@ -293,7 +269,7 @@ static void StatViewer_DrawMonSprite(void) static void StatViewer_BlankStats(void) { - Menu_BlankWindowRect(16, 4, 29, 18); + Menu_BlankWindowRect(16, 4, 29, 14); } #define tState data[0] @@ -342,8 +318,30 @@ static void Task_StatViewer_ChangePokemon(u8 taskId) } } -#undef tState -#undef tDelay +static void Task_StatViewer_Close(u8 taskId) +{ + s16 *data = gTasks[taskId].data; + + switch (tState) + { + case 0: + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + tState++; + break; + case 1: + if (!gPaletteFade.active) + tState++; + break; + case 2: + FreeResourcesAndDestroySprite(&gSprites[sStatViewer.monSpriteId]); + tState++; + break; + default: + SetMainCallback2(CB2_ReturnToField); + DestroyTask(taskId); + break; + } +} static void Task_StatViewer_HandleInput(u8 taskId) { @@ -365,12 +363,15 @@ static void Task_StatViewer_HandleInput(u8 taskId) } else if (gMain.newKeys & B_BUTTON) { - SetMainCallback2(CB2_ReturnToField); PlaySE(SE_SELECT); - DestroyTask(taskId); + gTasks[taskId].tState = 0; + gTasks[taskId].func = Task_StatViewer_Close; } } +#undef tState +#undef tDelay + static void StatViewer_PrintStatTypeLabels(void) { MenuPrint_RightAligned(sText_BaseLabel, 20, 2); @@ -417,6 +418,30 @@ static void StatViewer_PrintStatLabels(void) } } +ALIGNED(4) static const u8 sStatViewer_Tiles[] = INCBIN_U8("assets/stats_viewer.4bpp.lz"); +ALIGNED(4) static const u8 sStatViewer_Tilemap[] = INCBIN_U8("assets/stats_viewer.bin.lz"); +ALIGNED(4) static const u8 sStatViewer_Pal[] = INCBIN_U8("assets/stats_viewer.gbapal.lz"); + +const struct WindowTemplate sWindowTemplate_StatsViewer = { + 0, // BG number + 2, // BG character base block + 31, // BG screen base block + 0, // BG priority + 15, // palette number + TEXT_COLOR_DARK_GREY, // foreground color + TEXT_COLOR_TRANSPARENT, // background color + TEXT_COLOR_LIGHT_GREY, // shadow color + 3, // font + 2, // text mode + 0, // spacing + 0, // tilemap left coordinate + 0, // tilemap top coordinate + 30, // width + 20, // height + BG_CHAR_ADDR(2), // tile data + BG_SCREEN_ADDR(31), // tilemap +}; + static bool8 SetupStatViewer(void) { u8 spriteId; @@ -439,27 +464,37 @@ static bool8 SetupStatViewer(void) break; case 3: DmaFill16(3, 0, VRAM, VRAM_SIZE); + DmaFill32(3, 0, OAM, OAM_SIZE); + DmaFill16(3, 0, PLTT, PLTT_SIZE); ClearTilemapBuffers(); gMain.state++; break; case 4: - Text_LoadWindowTemplate(&gWindowTemplate_81E6C3C); - InitMenuWindow(&gMenuTextWindowTemplate); - Menu_BlankWindowRect(0, 0, 29, 19); + Text_LoadWindowTemplate(&sWindowTemplate_StatsViewer); + InitMenuWindow(&sWindowTemplate_StatsViewer); + // Menu_BlankWindowRect(0, 0, 29, 19); + LZDecompressVram(sStatViewer_Tiles, (void *)(BG_CHAR_ADDR(0))); + LZDecompressVram(sStatViewer_Tilemap, (void *)(BG_SCREEN_ADDR(8))); + LoadCompressedPalette(sStatViewer_Pal, 0x0, 32); + REG_BG1CNT = BGCNT_PRIORITY(1) | BGCNT_TXT256x256 | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(8); gMain.state++; break; case 5: + StatViewer_DrawMonSprite(); StatViewer_PrintStatTypeLabels(); StatViewer_PrintStatLabels(); - StatViewer_DrawMonSprite(); - StatViewer_PrintPokemonInfo(); StatViewer_PrintPokemonCount(); + + StatViewer_PrintPokemonInfo(); gMain.state++; break; default: BeginNormalPaletteFade(0xffffffff, 0, 16, 0, RGB_BLACK); gPaletteFade.bufferTransferDisabled = FALSE; + REG_BG1HOFS = 0; + REG_BG1VOFS = 0; + CreateTask(Task_StatViewer_HandleInput, 0x0); SetVBlankCallback(VBlank_StatsViewerRun); SetMainCallback2(CB2_StatsViewerRun);