diff --git a/include/item_menu_icons.h b/include/item_menu_icons.h index 7ff6ace94b..50e11dfd9d 100644 --- a/include/item_menu_icons.h +++ b/include/item_menu_icons.h @@ -14,9 +14,9 @@ void ShakeBagSprite(void); void AddSwitchPocketRotatingBallSprite(s16 rotationDirection); void AddBagItemIconSprite(u16 itemId, u8 id); void RemoveBagItemIconSprite(u8 id); -void sub_80D4FAC(void); -void sub_80D4FC8(u8 arg0); -void sub_80D4FEC(u8 arg0); +void CreateItemMenuSwapLine(void); +void SetItemMenuSwapLineInvisibility(bool8 invisible); +void UpdateItemMenuSwapLinePos(u8 y); u8 CreateBerryTagSprite(u8 id, s16 x, s16 y); void FreeBerryTagSpritePalette(void); u8 CreateSpinningBerrySprite(u8 berryId, u8 x, u8 y, bool8 startAffine); diff --git a/include/menu_helpers.h b/include/menu_helpers.h index 4557ebbb1e..c4401354b7 100644 --- a/include/menu_helpers.h +++ b/include/menu_helpers.h @@ -35,10 +35,10 @@ bool8 MenuHelpers_CallLinkSomething(void); void sub_812220C(struct ItemSlot *slots, u8 count, u8 *arg2, u8 *usedSlotsCount, u8 maxUsedSlotsCount); void sub_812225C(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 numItems); void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4); -void LoadListMenuArrowsGfx(void); -void sub_8122344(u8 *spriteIds, u8 count); -void sub_81223B0(u8 *spriteIds, u8 count); -void sub_81223FC(u8 *spriteIds, u8 count, bool8 invisible); -void sub_8122448(u8 *spriteIds, u8 count, s16 x, u16 y); +void LoadListMenuSwapLineGfx(void); +void CreateSwapLineSprites(u8 *spriteIds, u8 count); +void DestroySwapLineSprites(u8 *spriteIds, u8 count); +void SetSwapLineSpritesInvisibility(u8 *spriteIds, u8 count, bool8 invisible); +void UpdateSwapLineSpritesPos(u8 *spriteIds, u8 count, s16 x, u16 y); #endif //GUARD_MENU_HELPERS_H diff --git a/include/pokeblock.h b/include/pokeblock.h index c82e99d8fb..4c5a404882 100644 --- a/include/pokeblock.h +++ b/include/pokeblock.h @@ -4,8 +4,7 @@ #include "constants/berry.h" #include "constants/pokemon.h" -#define GFX_TAG_POKEBLOCK 14818 -#define GFX_TAG_POKEBLOCK_CASE 14800 +#define TAG_POKEBLOCK 14818 enum { diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index f39bbf5224..23f2f96530 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -63,7 +63,7 @@ static void sub_81C56F8(void); static void sub_81C5A20(void); static void sub_81C6BD8(void); static void sub_81C6EF4(void); -static void sub_81C700C(void); +static void CreateSwapLine(void); static void sub_81C6E98(void); static void sub_81C6F20(void); static void sub_81C6404(void); @@ -84,8 +84,8 @@ static void sub_81C5F08(u8 windowId, u8 horizontalCount, u8 verticalCount); static bool8 IsValidMenuAction(s8 arg0); static void sub_81C6DAC(u8 taskId, const struct YesNoFuncTable *yesNoTable); static void sub_81C6CEC(u8 windowId); -static void sub_81C704C(u8 y); -static void sub_81C7028(bool8 invisible); +static void UpdateSwapLinePos(u8 y); +static void SetSwapLineInvisibility(bool8 invisible); static void sub_81C6F68(struct Sprite *sprite); static void BagAction_UseOnField(u8 taskId); static void BagAction_Toss(u8 taskId); @@ -489,7 +489,7 @@ static bool8 sub_81C5078(void) gMain.state++; break; case 14: - sub_81C700C(); + CreateSwapLine(); gMain.state++; break; case 15: @@ -555,7 +555,7 @@ static bool8 sub_81C5238(void) gPyramidBagResources->state++; break; default: - LoadListMenuArrowsGfx(); + LoadListMenuSwapLineGfx(); gPyramidBagResources->state = 0; return TRUE; } @@ -1268,7 +1268,7 @@ static void Task_BeginItemSwap(u8 taskId) FillWindowPixelBuffer(1, PIXEL_FILL(0)); PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); sub_81C5A98(data[0], 1); - sub_81C704C(data[1]); + UpdateSwapLinePos(data[1]); gTasks[taskId].func = Task_ItemSwapHandleInput; } @@ -1287,8 +1287,8 @@ static void Task_ItemSwapHandleInput(u8 taskId) { s32 id = ListMenu_ProcessInput(data[0]); ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); - sub_81C7028(FALSE); - sub_81C704C(gPyramidBagCursorData.cursorPosition); + SetSwapLineInvisibility(FALSE); + UpdateSwapLinePos(gPyramidBagCursorData.cursorPosition); switch (id) { case LIST_NOTHING_CHOSEN: @@ -1324,7 +1324,7 @@ static void PerformItemSwap(u8 taskId) { MovePyramidBagItemSlotInList(data[1], var); gPyramidBagResources->unk814 = 0xFF; - sub_81C7028(TRUE); + SetSwapLineInvisibility(TRUE); DestroyListMenuTask(data[0], scrollOffset, selectedRow); if (data[1] < var) gPyramidBagCursorData.cursorPosition--; @@ -1341,7 +1341,7 @@ static void sub_81C6A14(u8 taskId) u16 *selectedRow = &gPyramidBagCursorData.cursorPosition; gPyramidBagResources->unk814 = 0xFF; - sub_81C7028(TRUE); + SetSwapLineInvisibility(TRUE); DestroyListMenuTask(data[0], scrollOffset, selectedRow); if (data[1] < *scrollOffset + *selectedRow) gPyramidBagCursorData.cursorPosition--; @@ -1545,17 +1545,17 @@ static void sub_81C6FF8(u8 itemSpriteArrayId) sub_81C6E38(itemSpriteArrayId + 1); } -static void sub_81C700C(void) +static void CreateSwapLine(void) { - sub_8122344(&gPyramidBagResources->itemsSpriteIds[3], 8); + CreateSwapLineSprites(&gPyramidBagResources->itemsSpriteIds[3], 8); } -static void sub_81C7028(bool8 invisible) +static void SetSwapLineInvisibility(bool8 invisible) { - sub_81223FC(&gPyramidBagResources->itemsSpriteIds[3], 8, invisible); + SetSwapLineSpritesInvisibility(&gPyramidBagResources->itemsSpriteIds[3], 8, invisible); } -static void sub_81C704C(u8 y) +static void UpdateSwapLinePos(u8 y) { - sub_8122448(&gPyramidBagResources->itemsSpriteIds[3], 8 | 0x80, 120, (y + 1) * 16); + UpdateSwapLineSpritesPos(&gPyramidBagResources->itemsSpriteIds[3], 8 | 0x80, 120, (y + 1) * 16); } diff --git a/src/item_menu.c b/src/item_menu.c index 8836c0c632..865f8d8d16 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -707,7 +707,7 @@ bool8 SetupBagMenu(void) gMain.state++; break; case 16: - sub_80D4FAC(); + CreateItemMenuSwapLine(); gMain.state++; break; case 17: @@ -787,7 +787,7 @@ bool8 LoadBagMenu_Graphics(void) gBagMenu->graphicsLoadState++; break; default: - LoadListMenuArrowsGfx(); + LoadListMenuSwapLineGfx(); gBagMenu->graphicsLoadState = 0; return TRUE; } @@ -1373,7 +1373,7 @@ void BagMenu_SwapItems(u8 taskId) StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where); FillWindowPixelBuffer(1, PIXEL_FILL(0)); BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); - sub_80D4FEC(data[1]); + UpdateItemMenuSwapLinePos(data[1]); BagDestroyPocketSwitchArrowPair(); BagMenu_PrintCursor_(data[0], 2); gTasks[taskId].func = Task_HandleSwappingItemsInput; @@ -1396,8 +1396,8 @@ static void Task_HandleSwappingItemsInput(u8 taskId) { input = ListMenu_ProcessInput(data[0]); ListMenuGetScrollAndRow(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); - sub_80D4FC8(0); - sub_80D4FEC(gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); + SetItemMenuSwapLineInvisibility(FALSE); + UpdateItemMenuSwapLinePos(gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); switch (input) { case LIST_NOTHING_CHOSEN: @@ -1435,7 +1435,7 @@ void sub_81AC498(u8 taskId) gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]--; LoadBagItemListBuffers(gBagPositionStruct.pocket); data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); - sub_80D4FC8(1); + SetItemMenuSwapLineInvisibility(TRUE); CreatePocketSwitchArrowPair(); gTasks[taskId].func = Task_BagMenu_HandleInput; } @@ -1453,7 +1453,7 @@ void sub_81AC590(u8 taskId) gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]--; LoadBagItemListBuffers(gBagPositionStruct.pocket); data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); - sub_80D4FC8(1); + SetItemMenuSwapLineInvisibility(TRUE); CreatePocketSwitchArrowPair(); gTasks[taskId].func = Task_BagMenu_HandleInput; } diff --git a/src/item_menu_icons.c b/src/item_menu_icons.c index dd00811616..d154092269 100644 --- a/src/item_menu_icons.c +++ b/src/item_menu_icons.c @@ -537,19 +537,19 @@ void RemoveBagItemIconSprite(u8 id) RemoveBagSprite(id + 2); } -void sub_80D4FAC(void) +void CreateItemMenuSwapLine(void) { - sub_8122344(&gBagMenu->spriteId[4], 8); + CreateSwapLineSprites(&gBagMenu->spriteId[4], 8); } -void sub_80D4FC8(u8 arg0) +void SetItemMenuSwapLineInvisibility(bool8 invisible) { - sub_81223FC(&gBagMenu->spriteId[4], 8, arg0); + SetSwapLineSpritesInvisibility(&gBagMenu->spriteId[4], 8, invisible); } -void sub_80D4FEC(u8 arg0) +void UpdateItemMenuSwapLinePos(u8 y) { - sub_8122448(&gBagMenu->spriteId[4], 136, 120, (arg0 + 1) * 16); + UpdateSwapLineSpritesPos(&gBagMenu->spriteId[4], 136, 120, (y + 1) * 16); } static void sub_80D5018(void *mem0, void *mem1) diff --git a/src/lilycove_lady.c b/src/lilycove_lady.c index 22155ffd59..6fa8ba4eb4 100644 --- a/src/lilycove_lady.c +++ b/src/lilycove_lady.c @@ -805,7 +805,7 @@ void Script_BufferContestLadyCategoryAndMonName(void) void OpenPokeblockCaseForContestLady(void) { - OpenPokeblockCase(3, CB2_ReturnToField); + OpenPokeblockCase(PBLOCK_CASE_GIVE, CB2_ReturnToField); } void SetContestLadyGivenPokeblock(void) diff --git a/src/menu_helpers.c b/src/menu_helpers.c index e7385a5edf..5a6ac83947 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -18,19 +18,17 @@ #include "constants/items.h" #include "constants/maps.h" -// this file's functions +#define TAG_SWAP_LINE 109 + static void Task_ContinueTaskAfterMessagePrints(u8 taskId); static void Task_CallYesOrNoCallback(u8 taskId); -// EWRAM vars EWRAM_DATA static struct YesNoFuncTable gUnknown_0203A138 = {0}; EWRAM_DATA static u8 gUnknown_0203A140 = 0; -// IWRAM bss vars static TaskFunc gUnknown_0300117C; -// const rom data -static const struct OamData sOamData_859F4E8 = +static const struct OamData sOamData_SwapLine = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -47,47 +45,47 @@ static const struct OamData sOamData_859F4E8 = .affineParam = 0 }; -static const union AnimCmd sSpriteAnim_859F4F0[] = +static const union AnimCmd sAnim_SwapLine_RightArrow[] = { ANIMCMD_FRAME(0, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_859F4F8[] = +static const union AnimCmd sAnim_SwapLine_Line[] = { ANIMCMD_FRAME(4, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_859F500[] = +static const union AnimCmd sAnim_SwapLine_LeftArrow[] = { - ANIMCMD_FRAME(0, 0, 1, 0), + ANIMCMD_FRAME(0, 0, .hFlip = TRUE), ANIMCMD_END }; -static const union AnimCmd *const sSpriteAnimTable_859F508[] = +static const union AnimCmd *const sAnims_SwapLine[] = { - sSpriteAnim_859F4F0, - sSpriteAnim_859F4F8, - sSpriteAnim_859F500 + sAnim_SwapLine_RightArrow, + sAnim_SwapLine_Line, + sAnim_SwapLine_LeftArrow }; -static const struct CompressedSpriteSheet gUnknown_0859F514 = +static const struct CompressedSpriteSheet sSpriteSheet_SwapLine = { - gBagSwapLineGfx, 0x100, 109 + gBagSwapLineGfx, 0x100, TAG_SWAP_LINE }; -static const struct CompressedSpritePalette gUnknown_0859F51C = +static const struct CompressedSpritePalette sSpritePalette_SwapLine = { - gBagSwapLinePal, 109 + gBagSwapLinePal, TAG_SWAP_LINE }; -static const struct SpriteTemplate gUnknown_0859F524 = +static const struct SpriteTemplate sSpriteTemplate_SwapLine = { - .tileTag = 109, - .paletteTag = 109, - .oam = &sOamData_859F4E8, - .anims = sSpriteAnimTable_859F508, + .tileTag = TAG_SWAP_LINE, + .paletteTag = TAG_SWAP_LINE, + .oam = &sOamData_SwapLine, + .anims = sAnims_SwapLine, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, @@ -390,19 +388,19 @@ void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4) } } -void LoadListMenuArrowsGfx(void) +void LoadListMenuSwapLineGfx(void) { - LoadCompressedSpriteSheet(&gUnknown_0859F514); - LoadCompressedSpritePalette(&gUnknown_0859F51C); + LoadCompressedSpriteSheet(&sSpriteSheet_SwapLine); + LoadCompressedSpritePalette(&sSpritePalette_SwapLine); } -void sub_8122344(u8 *spriteIds, u8 count) +void CreateSwapLineSprites(u8 *spriteIds, u8 count) { u8 i; for (i = 0; i < count; i++) { - spriteIds[i] = CreateSprite(&gUnknown_0859F524, i * 16, 0, 0); + spriteIds[i] = CreateSprite(&sSpriteTemplate_SwapLine, i * 16, 0, 0); if (i != 0) StartSpriteAnim(&gSprites[spriteIds[i]], 1); @@ -410,7 +408,7 @@ void sub_8122344(u8 *spriteIds, u8 count) } } -void sub_81223B0(u8 *spriteIds, u8 count) +void DestroySwapLineSprites(u8 *spriteIds, u8 count) { u8 i; @@ -423,17 +421,15 @@ void sub_81223B0(u8 *spriteIds, u8 count) } } -void sub_81223FC(u8 *spriteIds, u8 count, bool8 invisible) +void SetSwapLineSpritesInvisibility(u8 *spriteIds, u8 count, bool8 invisible) { u8 i; for (i = 0; i < count; i++) - { gSprites[spriteIds[i]].invisible = invisible; - } } -void sub_8122448(u8 *spriteIds, u8 count, s16 x, u16 y) +void UpdateSwapLineSpritesPos(u8 *spriteIds, u8 count, s16 x, u16 y) { u8 i; bool8 unknownBit = count & 0x80; diff --git a/src/player_pc.c b/src/player_pc.c index a06aad60e7..e5c3c5a184 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -112,7 +112,7 @@ static void CopyItemName_PlayerPC(u8 *string, u16 itemId); static void sub_816BC14(void); static void sub_816BFE0(u8 y, u8, u8 speed); static void sub_816BCC4(u8); -static void sub_816C690(u8); +static void UpdateSwapLinePos(u8); static void sub_816C4FC(u8 taskId); static void sub_816C0C8(void); static void sub_816C060(u16 itemId); @@ -558,8 +558,8 @@ static void ItemStorage_WithdrawToss_Helper(u8 taskId, bool8 toss) ItemStorage_SetItemAndMailCount(taskId); sub_816BC14(); FreeAndReserveObjectSpritePalettes(); - LoadListMenuArrowsGfx(); - sub_8122344(gUnknown_0203BCC4->spriteIds, 7); + LoadListMenuSwapLineGfx(); + CreateSwapLineSprites(gUnknown_0203BCC4->spriteIds, 7); ClearDialogWindowAndFrame(0,0); gTasks[taskId].func = ItemStorage_ProcessWithdrawTossInput; } @@ -1186,7 +1186,7 @@ static void ItemStorage_GoBackToPlayerPCMenu(u8 taskId) sub_816C0C8(); ItemStorage_RemoveScrollIndicator(); DestroyListMenuTask(data[5], NULL, NULL); - sub_81223B0(gUnknown_0203BCC4->spriteIds, 7); + DestroySwapLineSprites(gUnknown_0203BCC4->spriteIds, 7); sub_816BC58(); gTasks[taskId].func = ItemStorage_GoBackToPlayerPCMenu_InitStorage; } @@ -1199,7 +1199,7 @@ static void ItemStorage_ItemSwapChoosePrompt(u8 taskId) ListMenuSetUnkIndicatorsStructField(data[5], 16, 1); gUnknown_0203BCC4->unk666 = (playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos); sub_816BFB8(data[5], 0, 0); - sub_816C690(gUnknown_0203BCC4->unk666); + UpdateSwapLinePos(gUnknown_0203BCC4->unk666); CopyItemName(gSaveBlock1Ptr->pcItems[gUnknown_0203BCC4->unk666].itemId, gStringVar1); ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(ITEMPC_SWITCH_WHICH_ITEM)); gTasks[taskId].func = sub_816C4FC; @@ -1219,8 +1219,8 @@ static void sub_816C4FC(u8 taskId) } id = ListMenu_ProcessInput(data[5]); ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); - sub_81223FC(gUnknown_0203BCC4->spriteIds, 7, 0); - sub_816C690(playerPCItemPageInfo.cursorPos); + SetSwapLineSpritesInvisibility(gUnknown_0203BCC4->spriteIds, 7, FALSE); + UpdateSwapLinePos(playerPCItemPageInfo.cursorPos); switch(id) { case LIST_NOTHING_CHOSEN: @@ -1268,16 +1268,16 @@ static void ItemStorage_DoItemSwap(u8 taskId, bool8 a) if (gUnknown_0203BCC4->unk666 < b) playerPCItemPageInfo.cursorPos--; LABEL_SKIP_CURSOR_DECREMENT: - sub_81223FC(gUnknown_0203BCC4->spriteIds, 7, 1); + SetSwapLineSpritesInvisibility(gUnknown_0203BCC4->spriteIds, 7, TRUE); gUnknown_0203BCC4->unk666 = 0xFF; data[5] = ListMenuInit(&gMultiuseListMenuTemplate, playerPCItemPageInfo.itemsAbove, playerPCItemPageInfo.cursorPos); ScheduleBgCopyTilemapToVram(0); gTasks[taskId].func = ItemStorage_ProcessInput; } -static void sub_816C690(u8 a) +static void UpdateSwapLinePos(u8 y) { - sub_8122448(gUnknown_0203BCC4->spriteIds, 7, 128, ((a+1) * 16)); + UpdateSwapLineSpritesPos(gUnknown_0203BCC4->spriteIds, 7, 128, ((y+1) * 16)); } static void sub_816C6BC(u8 windowId, u16 value, u32 mode, u8 x, u8 y, u8 n) diff --git a/src/pokeblock.c b/src/pokeblock.c index 3513e7dd24..7856e70546 100644 --- a/src/pokeblock.c +++ b/src/pokeblock.c @@ -33,23 +33,46 @@ #include "constants/songs.h" #include "constants/rgb.h" +#define MAX_MENU_ITEMS 9 +#define MENU_MIDPOINT (MAX_MENU_ITEMS / 2) + +#define TILE_HIGHLIGHT_NONE 0x0005 // Tile number for the bg of an unselected menu item +#define TILE_HIGHLIGHT_BLUE 0x1005 // Tile number for the bg of a selected menu item +#define TILE_HIGHLIGHT_RED 0x2005 // Tile number for the bg of a menu item to swap + +#define TAG_POKEBLOCK_CASE 14800 +#define TAG_SCROLL_ARROW 1110 + #define POKEBLOCK_MAX_FEEL 99 -#define FIELD_E75_COUNT 7 + +enum { + WIN_TITLE, + WIN_LIST, + WIN_SPICY, + WIN_DRY, + WIN_SWEET, + WIN_BITTER, + WIN_SOUR, + WIN_FEEL, + WIN_ACTIONS_TALL, + WIN_ACTIONS, + WIN_TOSS_MSG, +}; struct PokeblockMenuStruct { - u8 tilemap[0x800]; + u8 tilemap[BG_SCREEN_SIZE]; void (*callbackOnUse)(void); - const u8 *pokeblockOptionsIds; - u8 optionsNo; + const u8 *pokeblockActionIds; + u8 numActions; u8 caseId; u8 itemsNo; u8 maxShowed; struct ListMenuItem items[POKEBLOCKS_COUNT + 1]; - u8 menuItemsStrings[POKEBLOCKS_COUNT + 1][0x20]; // + 1 because of STOW CASE item + u8 menuItemsStrings[POKEBLOCKS_COUNT + 1][32]; // + 1 because of STOW CASE item u8 pokeblockCaseSpriteId; - u8 field_E75[FIELD_E75_COUNT]; - u8 unkTaskId; + u8 swapLineSpriteIds[7]; + u8 arrowTaskId; bool8 isSwapping; s16 gfxState; u8 unused[8]; @@ -58,8 +81,8 @@ struct PokeblockMenuStruct struct PokeblockSavedData { void (*callback)(void); - u16 lastItemPos; - u16 lastItemPage; + u16 selectedRow; + u16 scrollOffset; }; enum @@ -82,43 +105,41 @@ static bool8 LoadPokeblockMenuGfx(void); static void HandleInitBackgrounds(void); static void HandleInitWindows(void); static void SetMenuItemsCountAndMaxShowed(void); -static void sub_81362E0(void); -static void sub_8136344(void); -static void HandlePokeblockListMenuItems(void); -static void sub_81363BC(void); -static void MovePokeblockMenuCursor(s32 pkblId, bool8 arg1, struct ListMenu *arg2); -static void PutPokeblockInfoText(void); -static void HandlePokeblockMenuCursor(u16 cursorPos, u16 arg1); -static void PutPokeblockListMenuString(u8 *dst, u16 pkblId); -static void Task_HandlePokeblockMenuInput(u8 taskId); -static void PokeblockAction_UseOnField(u8 taskId); -static void PokeblockAction_Toss(u8 taskId); -static void PokeblockAction_Cancel(u8 taskId); -static void PokeblockAction_UseInBattle(u8 taskId); -static void PokeblockAction_UseOnPokeblockFeeder(u8 taskId); -static void PokeblockAction_GiveToContestLady(u8 taskId); -static void TossPokeblockChoice_Yes(u8 taskId); -static void TossPokeblockChoice_No(u8 taskId); -static void Task_FreeDataAndExitPokeblockCase(u8 taskId); -static void Task_HandlePokeblockOptionsInput(u8 taskId); -static void PutPokeblockOptionsWindow(u8 taskId); -static void Task_HandlePokeblocksSwapInput(u8 taskId); -static void sub_8136470(struct Sprite *sprite); -static void sub_8135FCC(s32 pkblId); -static void HandlePokeblocksSwap(u8 taskId, bool8 noSwap); +static void LimitMenuScrollAndRow(void); +static void SetInitialScroll(void); +static void UpdatePokeblockList(void); +static void CreateScrollArrows(void); +static void MovePokeblockMenuCursor(s32, bool8, struct ListMenu *); +static void DrawPokeblockMenuTitleText(void); +static void DrawPokeblockMenuHighlight(u16, u16); +static void PutPokeblockListMenuString(u8 *, u16); +static void Task_HandlePokeblockMenuInput(u8); +static void PokeblockAction_UseOnField(u8); +static void PokeblockAction_Toss(u8); +static void PokeblockAction_Cancel(u8); +static void PokeblockAction_UseInBattle(u8); +static void PokeblockAction_UseOnPokeblockFeeder(u8); +static void PokeblockAction_GiveToContestLady(u8); +static void TossedPokeblockMessage(u8); +static void CloseTossPokeblockWindow(u8); +static void Task_FreeDataAndExitPokeblockCase(u8); +static void Task_HandlePokeblockActionsInput(u8); +static void ShowPokeblockActionsWindow(u8); +static void Task_HandlePokeblocksSwapInput(u8); +static void SpriteCB_ShakePokeblockCase(struct Sprite *); +static void DrawPokeblockInfo(s32); +static void UpdatePokeblockSwapMenu(u8, bool8); static void UsePokeblockOnField(void); static void ReturnToPokeblockCaseOnField(void); -static void CreateTossPokeblockYesNoMenu(u8 taskId); -static void HandleErasePokeblock(u8 taskId); +static void CreateTossPokeblockYesNoMenu(u8); +static void TossPokeblock(u8); -// ram variables EWRAM_DATA static struct PokeblockSavedData sSavedPokeblockData = {0}; EWRAM_DATA static struct PokeblockMenuStruct *sPokeblockMenu = NULL; -// const rom data const s8 gPokeblockFlavorCompatibilityTable[NUM_NATURES * FLAVOR_COUNT] = { - // Cool, Beauty, Cute, Smart, Tough + // Spicy, Dry, Sweet, Bitter, Sour 0, 0, 0, 0, 0, // Hardy 1, 0, 0, 0, -1, // Lonely 1, 0, -1, 0, 0, // Brave @@ -198,12 +219,12 @@ const u8 *const gPokeblockNames[] = static const struct MenuAction sPokeblockMenuActions[] = { - {gMenuText_Use, PokeblockAction_UseOnField}, - {gMenuText_Toss, PokeblockAction_Toss}, - {gText_Cancel2, PokeblockAction_Cancel}, - {gMenuText_Use, PokeblockAction_UseInBattle}, - {gMenuText_Use, PokeblockAction_UseOnPokeblockFeeder}, - {gMenuText_Give2, PokeblockAction_GiveToContestLady}, + [PKBL_USE_ON_FIELD] = {gMenuText_Use, PokeblockAction_UseOnField}, + [PKBL_TOSS] = {gMenuText_Toss, PokeblockAction_Toss}, + [PKBL_CANCEL] = {gText_Cancel2, PokeblockAction_Cancel}, + [PKBL_USE_IN_BATTLE] = {gMenuText_Use, PokeblockAction_UseInBattle}, + [PKBL_USE_ON_FEEDER] = {gMenuText_Use, PokeblockAction_UseOnPokeblockFeeder}, + [PKBL_GIVE_TO_LADY] = {gMenuText_Give2, PokeblockAction_GiveToContestLady}, }; static const u8 sActionsOnField[] = {PKBL_USE_ON_FIELD, PKBL_TOSS, PKBL_CANCEL}; @@ -211,7 +232,7 @@ static const u8 sActionsInBattle[] = {PKBL_USE_IN_BATTLE, PKBL_CANCEL}; static const u8 sActionsOnPokeblockFeeder[] = {PKBL_USE_ON_FEEDER, PKBL_CANCEL}; static const u8 sActionsWhenGivingToLady[] = {PKBL_GIVE_TO_LADY, PKBL_CANCEL}; -static const struct YesNoFuncTable sTossYesNoFuncTable = {TossPokeblockChoice_Yes, TossPokeblockChoice_No}; +static const struct YesNoFuncTable sTossYesNoFuncTable = {TossedPokeblockMessage, CloseTossPokeblockWindow}; static const u8 sContestStatsMonData[] = {MON_DATA_COOL, MON_DATA_BEAUTY, MON_DATA_CUTE, MON_DATA_SMART, MON_DATA_TOUGH}; @@ -259,39 +280,39 @@ static const union AffineAnimCmd *const sSpriteAffineAnimTable_85B26F0[] = const struct CompressedSpriteSheet gPokeblockCase_SpriteSheet = { - gMenuPokeblockDevice_Gfx, 0x800, GFX_TAG_POKEBLOCK_CASE + gMenuPokeblockDevice_Gfx, 0x800, TAG_POKEBLOCK_CASE }; const struct CompressedSpritePalette gPokeblockCase_SpritePal = { - gMenuPokeblockDevice_Pal, GFX_TAG_POKEBLOCK_CASE + gMenuPokeblockDevice_Pal, TAG_POKEBLOCK_CASE }; static const struct SpriteTemplate sSpriteTemplate_PokeblockCase = { - GFX_TAG_POKEBLOCK_CASE, - GFX_TAG_POKEBLOCK_CASE, - &sOamData_PokeblockCase, - sSpriteAnimTable_PokeblockCase, - NULL, - gDummySpriteAffineAnimTable, - SpriteCallbackDummy + .tileTag = TAG_POKEBLOCK_CASE, + .paletteTag = TAG_POKEBLOCK_CASE, + .oam = &sOamData_PokeblockCase, + .anims = sSpriteAnimTable_PokeblockCase, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy }; -static const u8 sTextColorInPokeblockMenu[3] = {0, 2, 3}; +static const u8 sTextColor[3] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_LIGHT_GRAY}; -static const struct Pokeblock sFavoritePokeblocksTable[] = +static const struct Pokeblock sFavoritePokeblocksTable[FLAVOR_COUNT] = { - { PBLOCK_CLR_RED, 20, 0, 0, 0, 0, 20}, - { PBLOCK_CLR_BLUE, 0, 20, 0, 0, 0, 20}, - { PBLOCK_CLR_PINK, 0, 0, 20, 0, 0, 20}, - { PBLOCK_CLR_GREEN, 0, 0, 0, 20, 0, 20}, - { PBLOCK_CLR_YELLOW, 0, 0, 0, 0, 20, 20} + [FLAVOR_SPICY] = { PBLOCK_CLR_RED, 20, 0, 0, 0, 0, 20}, + [FLAVOR_DRY] = { PBLOCK_CLR_BLUE, 0, 20, 0, 0, 0, 20}, + [FLAVOR_SWEET] = { PBLOCK_CLR_PINK, 0, 0, 20, 0, 0, 20}, + [FLAVOR_BITTER] = { PBLOCK_CLR_GREEN, 0, 0, 0, 20, 0, 20}, + [FLAVOR_SOUR] = { PBLOCK_CLR_YELLOW, 0, 0, 0, 0, 20, 20} }; -static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = +static const struct WindowTemplate sWindowTemplates[] = { - { + [WIN_TITLE] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 1, @@ -300,7 +321,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x1E }, - { + [WIN_LIST] = { .bg = 0, .tilemapLeft = 15, .tilemapTop = 1, @@ -309,7 +330,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x30 }, - { + [WIN_SPICY] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 13, @@ -318,7 +339,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x12C }, - { + [WIN_DRY] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 15, @@ -327,7 +348,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x136 }, - { + [WIN_SWEET] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 17, @@ -336,7 +357,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x140 }, - { + [WIN_BITTER] = { .bg = 0, .tilemapLeft = 8, .tilemapTop = 13, @@ -345,7 +366,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x14A }, - { + [WIN_SOUR] = { .bg = 0, .tilemapLeft = 8, .tilemapTop = 15, @@ -354,7 +375,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x154 }, - { + [WIN_FEEL] = { .bg = 0, .tilemapLeft = 11, .tilemapTop = 17, @@ -363,7 +384,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x15E }, - { + [WIN_ACTIONS_TALL] = { .bg = 1, .tilemapLeft = 7, .tilemapTop = 5, @@ -372,7 +393,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x162 }, - { + [WIN_ACTIONS] = { .bg = 1, .tilemapLeft = 7, .tilemapTop = 7, @@ -381,7 +402,7 @@ static const struct WindowTemplate sWindowTemplatesForPokeblockMenu[] = .paletteNum = 15, .baseBlock = 0x186 }, - { + [WIN_TOSS_MSG] = { .bg = 1, .tilemapLeft = 2, .tilemapTop = 15, @@ -411,7 +432,7 @@ static const struct ListMenuTemplate sPokeblockListMenuTemplate = .itemPrintFunc = NULL, .totalItems = 0, .maxShowed = 0, - .windowId = 1, + .windowId = WIN_LIST, .header_X = 0, .item_X = 1, .cursor_X = 0, @@ -426,33 +447,32 @@ static const struct ListMenuTemplate sPokeblockListMenuTemplate = .cursorKind = 1 }; -// code void OpenPokeblockCase(u8 caseId, void (*callback)(void)) { sPokeblockMenu = Alloc(sizeof(*sPokeblockMenu)); sPokeblockMenu->caseId = caseId; sPokeblockMenu->callbackOnUse = NULL; - sPokeblockMenu->unkTaskId = TASK_NONE; + sPokeblockMenu->arrowTaskId = TASK_NONE; sPokeblockMenu->isSwapping = FALSE; sSavedPokeblockData.callback = callback; switch (sPokeblockMenu->caseId) { case PBLOCK_CASE_BATTLE: - sPokeblockMenu->pokeblockOptionsIds = sActionsInBattle; - sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsInBattle); + sPokeblockMenu->pokeblockActionIds = sActionsInBattle; + sPokeblockMenu->numActions = ARRAY_COUNT(sActionsInBattle); break; case PBLOCK_CASE_FEEDER: - sPokeblockMenu->pokeblockOptionsIds = sActionsOnPokeblockFeeder; - sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsOnPokeblockFeeder); + sPokeblockMenu->pokeblockActionIds = sActionsOnPokeblockFeeder; + sPokeblockMenu->numActions = ARRAY_COUNT(sActionsOnPokeblockFeeder); break; case PBLOCK_CASE_GIVE: - sPokeblockMenu->pokeblockOptionsIds = sActionsWhenGivingToLady; - sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsWhenGivingToLady); + sPokeblockMenu->pokeblockActionIds = sActionsWhenGivingToLady; + sPokeblockMenu->numActions = ARRAY_COUNT(sActionsWhenGivingToLady); break; default: // PBLOCK_CASE_FIELD - sPokeblockMenu->pokeblockOptionsIds = sActionsOnField; - sPokeblockMenu->optionsNo = ARRAY_COUNT(sActionsOnField); + sPokeblockMenu->pokeblockActionIds = sActionsOnField; + sPokeblockMenu->numActions = ARRAY_COUNT(sActionsOnField); break; } @@ -498,6 +518,10 @@ static void CB2_InitPokeblockMenu(void) } } +#define tListTaskId data[0] +#define tWindowId data[1] +#define tToSwapId data[2] + static bool8 InitPokeblockMenu(void) { u8 taskId; @@ -519,7 +543,7 @@ static bool8 InitPokeblockMenu(void) break; case 3: ResetPaletteFade(); - gPaletteFade.bufferTransferDisabled = 1; + gPaletteFade.bufferTransferDisabled = TRUE; gMain.state++; break; case 4: @@ -543,8 +567,8 @@ static bool8 InitPokeblockMenu(void) break; case 8: SetMenuItemsCountAndMaxShowed(); - sub_81362E0(); - sub_8136344(); + LimitMenuScrollAndRow(); + SetInitialScroll(); gMain.state++; break; case 9: @@ -552,11 +576,11 @@ static bool8 InitPokeblockMenu(void) gMain.state++; break; case 10: - sub_8122344(sPokeblockMenu->field_E75, FIELD_E75_COUNT); + CreateSwapLineSprites(sPokeblockMenu->swapLineSpriteIds, ARRAY_COUNT(sPokeblockMenu->swapLineSpriteIds)); gMain.state++; break; case 11: - HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005); + DrawPokeblockMenuHighlight(sSavedPokeblockData.selectedRow, TILE_HIGHLIGHT_BLUE); gMain.state++; break; case 12: @@ -564,29 +588,29 @@ static bool8 InitPokeblockMenu(void) gMain.state++; break; case 13: - HandlePokeblockListMenuItems(); + UpdatePokeblockList(); gMain.state++; break; case 14: - sub_81363BC(); + CreateScrollArrows(); gMain.state++; break; case 15: taskId = CreateTask(Task_HandlePokeblockMenuInput, 0); - gTasks[taskId].data[0] = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.lastItemPage, sSavedPokeblockData.lastItemPos); + gTasks[taskId].tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.scrollOffset, sSavedPokeblockData.selectedRow); gMain.state++; break; case 16: - PutPokeblockInfoText(); + DrawPokeblockMenuTitleText(); gMain.state++; break; case 17: - BlendPalettes(PALETTES_ALL, 0x10, 0); + BlendPalettes(PALETTES_ALL, 16, 0); gMain.state++; break; case 18: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK); - gPaletteFade.bufferTransferDisabled = 0; + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); + gPaletteFade.bufferTransferDisabled = FALSE; gMain.state++; break; default: @@ -645,7 +669,7 @@ static bool8 LoadPokeblockMenuGfx(void) sPokeblockMenu->gfxState++; break; case 5: - LoadListMenuArrowsGfx(); + LoadListMenuSwapLineGfx(); sPokeblockMenu->gfxState = 0; return TRUE; } @@ -657,16 +681,14 @@ static void HandleInitWindows(void) { u8 i; - InitWindows(sWindowTemplatesForPokeblockMenu); + InitWindows(sWindowTemplates); DeactivateAllTextPrinters(); LoadUserWindowBorderGfx(0, 1, 0xE0); LoadMessageBoxGfx(0, 0xA, 0xD0); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); - for (i = 0; i < ARRAY_COUNT(sWindowTemplatesForPokeblockMenu) - 1; i++) - { + for (i = 0; i < ARRAY_COUNT(sWindowTemplates) - 1; i++) FillWindowPixelBuffer(i, PIXEL_FILL(0)); - } ScheduleBgCopyTilemapToVram(0); ScheduleBgCopyTilemapToVram(1); @@ -674,29 +696,27 @@ static void HandleInitWindows(void) static void PrintOnPokeblockWindow(u8 windowId, const u8 *string, s32 x) { - AddTextPrinterParameterized4(windowId, 1, x, 1, 0, 0, sTextColorInPokeblockMenu, 0, string); + AddTextPrinterParameterized4(windowId, 1, x, 1, 0, 0, sTextColor, 0, string); } -static void PutPokeblockInfoText(void) +static void DrawPokeblockMenuTitleText(void) { u8 i; const u8 *itemName = ItemId_GetName(ITEM_POKEBLOCK_CASE); - PrintOnPokeblockWindow(0, itemName, GetStringCenterAlignXOffset(1, itemName, 0x48)); + PrintOnPokeblockWindow(WIN_TITLE, itemName, GetStringCenterAlignXOffset(1, itemName, 0x48)); - PrintOnPokeblockWindow(2, gText_Spicy, 0); - PrintOnPokeblockWindow(3, gText_Dry, 0); - PrintOnPokeblockWindow(4, gText_Sweet, 0); - PrintOnPokeblockWindow(5, gText_Bitter, 0); - PrintOnPokeblockWindow(6, gText_Sour, 0); + PrintOnPokeblockWindow(WIN_SPICY, gText_Spicy, 0); + PrintOnPokeblockWindow(WIN_DRY, gText_Dry, 0); + PrintOnPokeblockWindow(WIN_SWEET, gText_Sweet, 0); + PrintOnPokeblockWindow(WIN_BITTER, gText_Bitter, 0); + PrintOnPokeblockWindow(WIN_SOUR, gText_Sour, 0); - for (i = 0; i < 8; i++) - { + for (i = 0; i < WIN_ACTIONS_TALL; i++) PutWindowTilemap(i); - } } -static void HandlePokeblockListMenuItems(void) +static void UpdatePokeblockList(void) { u16 i; @@ -731,19 +751,19 @@ static void PutPokeblockListMenuString(u8 *dst, u16 pkblId) StringExpandPlaceholders(txtPtr, gText_LvVar1); } -static void MovePokeblockMenuCursor(s32 pkblId, bool8 arg1, struct ListMenu *arg2) +static void MovePokeblockMenuCursor(s32 pkblId, bool8 onInit, struct ListMenu *list) { - if (arg1 != TRUE) + if (onInit != TRUE) { PlaySE(SE_SELECT); - gSprites[sPokeblockMenu->pokeblockCaseSpriteId].callback = sub_8136470; + gSprites[sPokeblockMenu->pokeblockCaseSpriteId].callback = SpriteCB_ShakePokeblockCase; } if (!sPokeblockMenu->isSwapping) - sub_8135FCC(pkblId); + DrawPokeblockInfo(pkblId); } -static void sub_8135FCC(s32 pkblId) +static void DrawPokeblockInfo(s32 pkblId) { u8 i; struct Pokeblock *pokeblock; @@ -760,28 +780,32 @@ static void sub_8135FCC(s32 pkblId) { if (GetPokeblockData(pokeblock, PBLOCK_SPICY + i) > 0) { + // Pokéblock has this flavor, draw Pokéblock icon next to it rectTilemapSrc[0] = (i << 12) + 0x17; rectTilemapSrc[1] = (i << 12) + 0x18; } else { + // Pokéblock doesn't have this flavor, draw regular tiles rectTilemapSrc[0] = 0xF; rectTilemapSrc[1] = 0xF; } CopyToBgTilemapBufferRect(2, rectTilemapSrc, (i / 3 * 6) + 1, (i % 3 * 2) + 13, 1, 2); } + + // Print the Pokéblock's feel ConvertIntToDecimalStringN(gStringVar1, GetPokeblocksFeel(pokeblock), STR_CONV_MODE_RIGHT_ALIGN, 2); - PrintOnPokeblockWindow(7, gStringVar1, 4); + PrintOnPokeblockWindow(WIN_FEEL, gStringVar1, 4); } else { + // Selected cancel, erase info rectTilemapSrc[0] = 0xF; rectTilemapSrc[1] = 0xF; for (i = 0; i < FLAVOR_COUNT; i++) - { CopyToBgTilemapBufferRect(2, rectTilemapSrc, (i / 3 * 6) + 1, (i % 3 * 2) + 13, 1, 2); - } + CopyWindowToVram(7, 2); } @@ -789,9 +813,9 @@ static void sub_8135FCC(s32 pkblId) ScheduleBgCopyTilemapToVram(2); } -static void HandlePokeblockMenuCursor(u16 cursorPos, u16 arg1) +static void DrawPokeblockMenuHighlight(u16 cursorPos, u16 tileNum) { - FillBgTilemapBufferRect_Palette0(2, arg1, 0xF, (cursorPos * 2) + 1, 0xE, 2); + FillBgTilemapBufferRect_Palette0(2, tileNum, 0xF, (cursorPos * 2) + 1, 0xE, 2); ScheduleBgCopyTilemapToVram(2); } @@ -813,7 +837,7 @@ static void CompactPokeblockSlots(void) } } -static void SwapSortPokeblocksInternalData(u32 id1, u32 id2) +static void SwapPokeblockMenuItems(u32 id1, u32 id2) { s16 i, count; struct Pokeblock *pokeblocks = gSaveBlock1Ptr->pokeblocks; @@ -843,8 +867,8 @@ static void SwapSortPokeblocksInternalData(u32 id1, u32 id2) void ResetPokeblockScrollPositions(void) { - sSavedPokeblockData.lastItemPos = 0; - sSavedPokeblockData.lastItemPage = 0; + sSavedPokeblockData.selectedRow = 0; + sSavedPokeblockData.scrollOffset = 0; } static void SetMenuItemsCountAndMaxShowed(void) @@ -861,56 +885,56 @@ static void SetMenuItemsCountAndMaxShowed(void) sPokeblockMenu->itemsNo++; // STOW CASE menu item - if (sPokeblockMenu->itemsNo > 9) - sPokeblockMenu->maxShowed = 9; + if (sPokeblockMenu->itemsNo > MAX_MENU_ITEMS) + sPokeblockMenu->maxShowed = MAX_MENU_ITEMS; else sPokeblockMenu->maxShowed = sPokeblockMenu->itemsNo; } -static void sub_81362E0(void) +static void LimitMenuScrollAndRow(void) { - if (sSavedPokeblockData.lastItemPage != 0) + if (sSavedPokeblockData.scrollOffset != 0) { - if (sSavedPokeblockData.lastItemPage + sPokeblockMenu->maxShowed > sPokeblockMenu->itemsNo) - sSavedPokeblockData.lastItemPage = sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed; + if (sSavedPokeblockData.scrollOffset + sPokeblockMenu->maxShowed > sPokeblockMenu->itemsNo) + sSavedPokeblockData.scrollOffset = sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed; } - if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos >= sPokeblockMenu->itemsNo) + if (sSavedPokeblockData.scrollOffset + sSavedPokeblockData.selectedRow >= sPokeblockMenu->itemsNo) { if (sPokeblockMenu->itemsNo == 0) - sSavedPokeblockData.lastItemPos = 0; + sSavedPokeblockData.selectedRow = 0; else - sSavedPokeblockData.lastItemPos = sPokeblockMenu->itemsNo - 1; + sSavedPokeblockData.selectedRow = sPokeblockMenu->itemsNo - 1; } } -static void sub_8136344(void) +static void SetInitialScroll(void) { - if (sSavedPokeblockData.lastItemPos > 4) + if (sSavedPokeblockData.selectedRow > MENU_MIDPOINT) { u8 i; for (i = 0; - (i < sSavedPokeblockData.lastItemPos - 4) && (sSavedPokeblockData.lastItemPage + sPokeblockMenu->maxShowed != sPokeblockMenu->itemsNo); - sSavedPokeblockData.lastItemPos--, sSavedPokeblockData.lastItemPage++, i++); + (i < sSavedPokeblockData.selectedRow - MENU_MIDPOINT) && (sSavedPokeblockData.scrollOffset + sPokeblockMenu->maxShowed != sPokeblockMenu->itemsNo); + sSavedPokeblockData.selectedRow--, sSavedPokeblockData.scrollOffset++, i++); } } -static void sub_81363BC(void) +static void CreateScrollArrows(void) { - if (sPokeblockMenu->unkTaskId == TASK_NONE) + if (sPokeblockMenu->arrowTaskId == TASK_NONE) { - sPokeblockMenu->unkTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 0xB0, 8, 0x98, sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed, - 0x456, 0x456, &sSavedPokeblockData.lastItemPage); + sPokeblockMenu->arrowTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 0xB0, 8, 0x98, sPokeblockMenu->itemsNo - sPokeblockMenu->maxShowed, + TAG_SCROLL_ARROW, TAG_SCROLL_ARROW, &sSavedPokeblockData.scrollOffset); } } -static void sub_8136418(void) +static void DestroyScrollArrows(void) { - if (sPokeblockMenu->unkTaskId != TASK_NONE) + if (sPokeblockMenu->arrowTaskId != TASK_NONE) { - RemoveScrollIndicatorArrowPair(sPokeblockMenu->unkTaskId); - sPokeblockMenu->unkTaskId = TASK_NONE; + RemoveScrollIndicatorArrowPair(sPokeblockMenu->arrowTaskId); + sPokeblockMenu->arrowTaskId = TASK_NONE; } } @@ -919,26 +943,29 @@ u8 CreatePokeblockCaseSprite(s16 x, s16 y, u8 subpriority) return CreateSprite(&sSpriteTemplate_PokeblockCase, x, y, subpriority); } -static void sub_8136470(struct Sprite *sprite) -{ - if (sprite->data[0] > 1) - sprite->data[0] = 0; +#define sState data[0] +#define sTimer data[1] - switch (sprite->data[0]) +static void SpriteCB_ShakePokeblockCase(struct Sprite *sprite) +{ + if (sprite->sState > 1) + sprite->sState = 0; + + switch (sprite->sState) { case 0: sprite->oam.affineMode = ST_OAM_AFFINE_NORMAL; sprite->affineAnims = sSpriteAffineAnimTable_85B26F0; InitSpriteAffineAnim(sprite); - sprite->data[0] = 1; - sprite->data[1] = 0; + sprite->sState = 1; + sprite->sTimer = 0; break; case 1: - if (++sprite->data[1] > 11) + if (++sprite->sTimer > 11) { sprite->oam.affineMode = ST_OAM_AFFINE_OFF; - sprite->data[0] = 0; - sprite->data[1] = 0; + sprite->sState = 0; + sprite->sTimer = 0; FreeOamMatrix(sprite->oam.matrixNum); sprite->callback = SpriteCallbackDummy; } @@ -948,7 +975,7 @@ static void sub_8136470(struct Sprite *sprite) static void FadePaletteAndSetTaskToClosePokeblockCase(u8 taskId) { - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); gTasks[taskId].func = Task_FreeDataAndExitPokeblockCase; } @@ -961,8 +988,8 @@ static void Task_FreeDataAndExitPokeblockCase(u8 taskId) if (sPokeblockMenu->caseId == PBLOCK_CASE_FEEDER || sPokeblockMenu->caseId == PBLOCK_CASE_GIVE) gFieldCallback = FieldCB_ContinueScriptHandleMusic; - DestroyListMenuTask(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); - sub_8136418(); + DestroyListMenuTask(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow); + DestroyScrollArrows(); ResetSpriteData(); FreeAllSpritePalettes(); @@ -985,29 +1012,31 @@ static void Task_HandlePokeblockMenuInput(u8 taskId) { if (JOY_NEW(SELECT_BUTTON)) { - ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); - if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos != sPokeblockMenu->itemsNo - 1) + ListMenuGetScrollAndRow(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow); + if (sSavedPokeblockData.scrollOffset + sSavedPokeblockData.selectedRow != sPokeblockMenu->itemsNo - 1) { + // Chose menu item to swap PlaySE(SE_SELECT); - HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x2005); - data[2] = sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos; + DrawPokeblockMenuHighlight(sSavedPokeblockData.selectedRow, TILE_HIGHLIGHT_RED); + tToSwapId = sSavedPokeblockData.scrollOffset + sSavedPokeblockData.selectedRow; sPokeblockMenu->isSwapping = TRUE; gTasks[taskId].func = Task_HandlePokeblocksSwapInput; } } else { - u16 oldPosition = sSavedPokeblockData.lastItemPos; - s32 itemId = ListMenu_ProcessInput(data[0]); + u16 oldPosition = sSavedPokeblockData.selectedRow; + s32 input = ListMenu_ProcessInput(tListTaskId); + ListMenuGetScrollAndRow(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow); - ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); - if (oldPosition != sSavedPokeblockData.lastItemPos) + if (oldPosition != sSavedPokeblockData.selectedRow) { - HandlePokeblockMenuCursor(oldPosition, 5); - HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005); + // Moved cursor + DrawPokeblockMenuHighlight(oldPosition, TILE_HIGHLIGHT_NONE); + DrawPokeblockMenuHighlight(sSavedPokeblockData.selectedRow, TILE_HIGHLIGHT_BLUE); } - switch (itemId) + switch (input) { case LIST_NOTHING_CHOSEN: break; @@ -1018,9 +1047,10 @@ static void Task_HandlePokeblockMenuInput(u8 taskId) FadePaletteAndSetTaskToClosePokeblockCase(taskId); break; default: + // Selected Pokéblock PlaySE(SE_SELECT); - gSpecialVar_ItemId = itemId; - PutPokeblockOptionsWindow(taskId); + gSpecialVar_ItemId = input; + ShowPokeblockActionsWindow(taskId); break; } } @@ -1036,100 +1066,102 @@ static void Task_HandlePokeblocksSwapInput(u8 taskId) if (JOY_NEW(SELECT_BUTTON)) { + // Swap items PlaySE(SE_SELECT); - ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); - HandlePokeblocksSwap(taskId, FALSE); + ListMenuGetScrollAndRow(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow); + UpdatePokeblockSwapMenu(taskId, FALSE); } else { - u16 i = sSavedPokeblockData.lastItemPage; - u16 var = sSavedPokeblockData.lastItemPos; - s32 itemId = ListMenu_ProcessInput(data[0]); + u16 i = sSavedPokeblockData.scrollOffset; + u16 row = sSavedPokeblockData.selectedRow; + s32 input = ListMenu_ProcessInput(tListTaskId); + ListMenuGetScrollAndRow(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow); - ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); - if (i != sSavedPokeblockData.lastItemPage || var != sSavedPokeblockData.lastItemPos) + if (i != sSavedPokeblockData.scrollOffset || row != sSavedPokeblockData.selectedRow) { - for (i = 0; i < 9; i++) + for (i = 0; i < MAX_MENU_ITEMS; i++) { - var = i + sSavedPokeblockData.lastItemPage; - if (var == data[2]) - HandlePokeblockMenuCursor(i, 0x2005); + row = i + sSavedPokeblockData.scrollOffset; + if (row == tToSwapId) + DrawPokeblockMenuHighlight(i, TILE_HIGHLIGHT_RED); else - HandlePokeblockMenuCursor(i, 5); + DrawPokeblockMenuHighlight(i, TILE_HIGHLIGHT_NONE); } } - sub_81223FC(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 0); - sub_8122448(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 0x80, (sSavedPokeblockData.lastItemPos * 16) + 8); + SetSwapLineSpritesInvisibility(sPokeblockMenu->swapLineSpriteIds, ARRAY_COUNT(sPokeblockMenu->swapLineSpriteIds), FALSE); + UpdateSwapLineSpritesPos(sPokeblockMenu->swapLineSpriteIds, ARRAY_COUNT(sPokeblockMenu->swapLineSpriteIds), 128, (sSavedPokeblockData.selectedRow * 16) + 8); - switch (itemId) + switch (input) { case LIST_NOTHING_CHOSEN: break; - case LIST_CANCEL: // same id as STOW CASE field + case LIST_CANCEL: PlaySE(SE_SELECT); - if (JOY_NEW(A_BUTTON)) - HandlePokeblocksSwap(taskId, FALSE); + if (JOY_NEW(A_BUTTON)) // Pointless check, B Button has been pressed here + UpdatePokeblockSwapMenu(taskId, FALSE); else - HandlePokeblocksSwap(taskId, TRUE); + UpdatePokeblockSwapMenu(taskId, TRUE); // Canceled swapping break; default: + // Swap items PlaySE(SE_SELECT); - HandlePokeblocksSwap(taskId, FALSE); + UpdatePokeblockSwapMenu(taskId, FALSE); break; } } } -static void HandlePokeblocksSwap(u8 taskId, bool8 noSwap) +static void UpdatePokeblockSwapMenu(u8 taskId, bool8 noSwap) { u8 i; s16 *data = gTasks[taskId].data; - u16 swappedFromId = sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos; + u16 swappedFromId = sSavedPokeblockData.scrollOffset + sSavedPokeblockData.selectedRow; sPokeblockMenu->isSwapping = FALSE; - DestroyListMenuTask(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); + DestroyListMenuTask(tListTaskId, &sSavedPokeblockData.scrollOffset, &sSavedPokeblockData.selectedRow); - if (!noSwap && data[2] != swappedFromId && data[2] != swappedFromId - 1) + if (!noSwap && tToSwapId != swappedFromId && tToSwapId != swappedFromId - 1) { - SwapSortPokeblocksInternalData(data[2], swappedFromId); - HandlePokeblockListMenuItems(); + SwapPokeblockMenuItems(tToSwapId, swappedFromId); + UpdatePokeblockList(); } - if (data[2] < swappedFromId) - sSavedPokeblockData.lastItemPos--; + if (tToSwapId < swappedFromId) + sSavedPokeblockData.selectedRow--; - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.lastItemPage, sSavedPokeblockData.lastItemPos); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, sSavedPokeblockData.scrollOffset, sSavedPokeblockData.selectedRow); ScheduleBgCopyTilemapToVram(0); - sub_81223FC(sPokeblockMenu->field_E75, FIELD_E75_COUNT, 1); + SetSwapLineSpritesInvisibility(sPokeblockMenu->swapLineSpriteIds, ARRAY_COUNT(sPokeblockMenu->swapLineSpriteIds), TRUE); - for (i = 0; i < 9; i++) - HandlePokeblockMenuCursor(i, 5); + for (i = 0; i < MAX_MENU_ITEMS; i++) + DrawPokeblockMenuHighlight(i, TILE_HIGHLIGHT_NONE); - HandlePokeblockMenuCursor(sSavedPokeblockData.lastItemPos, 0x1005); + DrawPokeblockMenuHighlight(sSavedPokeblockData.selectedRow, TILE_HIGHLIGHT_BLUE); gTasks[taskId].func = Task_HandlePokeblockMenuInput; } -static void PutPokeblockOptionsWindow(u8 taskId) +static void ShowPokeblockActionsWindow(u8 taskId) { s16 *data = gTasks[taskId].data; - if (sPokeblockMenu->optionsNo == 3) - data[1] = 8; + if (sPokeblockMenu->numActions == 3) + tWindowId = WIN_ACTIONS_TALL; else - data[1] = 9; + tWindowId = WIN_ACTIONS; - sub_8136418(); - DrawStdFrameWithCustomTileAndPalette(data[1], 0, 1, 0xE); - sub_81995E4(data[1], sPokeblockMenu->optionsNo, sPokeblockMenuActions, sPokeblockMenu->pokeblockOptionsIds); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[1], sPokeblockMenu->optionsNo, 0); - PutWindowTilemap(data[1]); + DestroyScrollArrows(); + DrawStdFrameWithCustomTileAndPalette(tWindowId, 0, 1, 0xE); + sub_81995E4(tWindowId, sPokeblockMenu->numActions, sPokeblockMenuActions, sPokeblockMenu->pokeblockActionIds); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(tWindowId, sPokeblockMenu->numActions, 0); + PutWindowTilemap(tWindowId); ScheduleBgCopyTilemapToVram(1); - gTasks[taskId].func = Task_HandlePokeblockOptionsInput; + gTasks[taskId].func = Task_HandlePokeblockActionsInput; } -static void Task_HandlePokeblockOptionsInput(u8 taskId) +static void Task_HandlePokeblockActionsInput(u8 taskId) { s8 itemId; @@ -1149,7 +1181,7 @@ static void Task_HandlePokeblockOptionsInput(u8 taskId) else { PlaySE(SE_SELECT); - sPokeblockMenuActions[sPokeblockMenu->pokeblockOptionsIds[itemId]].func.void_u8(taskId); + sPokeblockMenuActions[sPokeblockMenu->pokeblockActionIds[itemId]].func.void_u8(taskId); } } @@ -1173,10 +1205,10 @@ static void PokeblockAction_Toss(u8 taskId) { s16 *data = gTasks[taskId].data; - ClearStdWindowAndFrameToTransparent(data[1], FALSE); + ClearStdWindowAndFrameToTransparent(tWindowId, FALSE); StringCopy(gStringVar1, gPokeblockNames[gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color]); StringExpandPlaceholders(gStringVar4, gText_ThrowAwayVar1); - DisplayMessageAndContinueTask(taskId, 10, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, CreateTossPokeblockYesNoMenu); + DisplayMessageAndContinueTask(taskId, WIN_TOSS_MSG, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, CreateTossPokeblockYesNoMenu); } static void CreateTossPokeblockYesNoMenu(u8 taskId) @@ -1184,44 +1216,44 @@ static void CreateTossPokeblockYesNoMenu(u8 taskId) CreateYesNoMenuWithCallbacks(taskId, &sTossPkblockWindowTemplate, 1, 0, 2, 1, 0xE, &sTossYesNoFuncTable); } -static void TossPokeblockChoice_Yes(u8 taskId) +static void TossedPokeblockMessage(u8 taskId) { StringExpandPlaceholders(gStringVar4, gText_Var1ThrownAway); - DisplayMessageAndContinueTask(taskId, 10, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, HandleErasePokeblock); + DisplayMessageAndContinueTask(taskId, WIN_TOSS_MSG, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, TossPokeblock); } -static void HandleErasePokeblock(u8 taskId) +static void TossPokeblock(u8 taskId) { if (JOY_NEW(A_BUTTON | B_BUTTON)) { s16 *data; - u16 *lastPage, *lastPos; + u16 *scrollOffset, *selectedRow; TryClearPokeblock(gSpecialVar_ItemId); PlaySE(SE_SELECT); - lastPage = &sSavedPokeblockData.lastItemPage; - lastPos = &sSavedPokeblockData.lastItemPos; + scrollOffset = &sSavedPokeblockData.scrollOffset; + selectedRow = &sSavedPokeblockData.selectedRow; data = gTasks[taskId].data; - DestroyListMenuTask(data[0], lastPage, lastPos); - HandlePokeblockMenuCursor(*lastPos, 5); + DestroyListMenuTask(tListTaskId, scrollOffset, selectedRow); + DrawPokeblockMenuHighlight(*selectedRow, TILE_HIGHLIGHT_NONE); SetMenuItemsCountAndMaxShowed(); - sub_81362E0(); - HandlePokeblockListMenuItems(); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *lastPage, *lastPos); - HandlePokeblockMenuCursor(*lastPos, 0x1005); + LimitMenuScrollAndRow(); + UpdatePokeblockList(); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollOffset, *selectedRow); + DrawPokeblockMenuHighlight(*selectedRow, TILE_HIGHLIGHT_BLUE); ScheduleBgCopyTilemapToVram(0); ScheduleBgCopyTilemapToVram(1); - TossPokeblockChoice_No(taskId); + CloseTossPokeblockWindow(taskId); } } -static void TossPokeblockChoice_No(u8 taskId) +static void CloseTossPokeblockWindow(u8 taskId) { - ClearDialogWindowAndFrameToTransparent(10, FALSE); + ClearDialogWindowAndFrameToTransparent(WIN_TOSS_MSG, FALSE); ScheduleBgCopyTilemapToVram(1); - sub_81363BC(); + CreateScrollArrows(); gTasks[taskId].func = Task_HandlePokeblockMenuInput; } @@ -1266,9 +1298,9 @@ static void PokeblockAction_Cancel(u8 taskId) { s16 *data = gTasks[taskId].data; - ClearStdWindowAndFrameToTransparent(data[1], FALSE); + ClearStdWindowAndFrameToTransparent(tWindowId, FALSE); ScheduleBgCopyTilemapToVram(1); - sub_81363BC(); + CreateScrollArrows(); gTasks[taskId].func = Task_HandlePokeblockMenuInput; } diff --git a/src/pokeblock_feed.c b/src/pokeblock_feed.c index e5b13e2f63..1da999fb8e 100644 --- a/src/pokeblock_feed.c +++ b/src/pokeblock_feed.c @@ -498,13 +498,13 @@ static const union AffineAnimCmd *const sThrownPokeblockAffineAnimTable[] = static const struct CompressedSpriteSheet sPokeblock_SpriteSheet = { - gPokeblock_Gfx, 0x20, GFX_TAG_POKEBLOCK + gPokeblock_Gfx, 0x20, TAG_POKEBLOCK }; static const struct SpriteTemplate sThrownPokeblockSpriteTemplate = { - .tileTag = GFX_TAG_POKEBLOCK, - .paletteTag = GFX_TAG_POKEBLOCK, + .tileTag = TAG_POKEBLOCK, + .paletteTag = TAG_POKEBLOCK, .oam = &sThrownPokeblockOamData, .anims = sThrownPokeblockAnimTable, .images = NULL, @@ -711,7 +711,7 @@ static void SetPokeblockSpritePal(u8 pokeblockCaseId) { u8 colorId = GetPokeblockData(&gSaveBlock1Ptr->pokeblocks[pokeblockCaseId], PBLOCK_COLOR); sPokeblockSpritePal.data = sPokeblocksPals[colorId - 1]; - sPokeblockSpritePal.tag = GFX_TAG_POKEBLOCK; + sPokeblockSpritePal.tag = TAG_POKEBLOCK; } // defines for task data fields