diff --git a/gflib/malloc.h b/gflib/malloc.h index f2dcf6d46..8d49e0be7 100644 --- a/gflib/malloc.h +++ b/gflib/malloc.h @@ -12,6 +12,8 @@ ptr = NULL; \ } +#define TRY_FREE_AND_SET_NULL(ptr) if (ptr != NULL) FREE_AND_SET_NULL(ptr) + extern u8 gHeap[]; void *Alloc(u32 size); diff --git a/graphics/frontier_pass/tiles.bin b/graphics/frontier_pass/bg.bin similarity index 100% rename from graphics/frontier_pass/tiles.bin rename to graphics/frontier_pass/bg.bin diff --git a/graphics/frontier_pass/tiles.pal b/graphics/frontier_pass/bg.pal similarity index 100% rename from graphics/frontier_pass/tiles.pal rename to graphics/frontier_pass/bg.pal diff --git a/graphics/frontier_pass/tiles.png b/graphics/frontier_pass/bg.png similarity index 100% rename from graphics/frontier_pass/tiles.png rename to graphics/frontier_pass/bg.png diff --git a/graphics/frontier_pass/tilemap1.bin b/graphics/frontier_pass/cancel.bin similarity index 100% rename from graphics/frontier_pass/tilemap1.bin rename to graphics/frontier_pass/cancel.bin diff --git a/graphics/frontier_pass/tilemap2.bin b/graphics/frontier_pass/cancel_highlighted.bin similarity index 100% rename from graphics/frontier_pass/tilemap2.bin rename to graphics/frontier_pass/cancel_highlighted.bin diff --git a/graphics/frontier_pass/tiles2.png b/graphics/frontier_pass/map_and_card.png similarity index 100% rename from graphics/frontier_pass/tiles2.png rename to graphics/frontier_pass/map_and_card.png diff --git a/graphics/frontier_pass/unknown_571298.bin b/graphics/frontier_pass/unused.bin similarity index 100% rename from graphics/frontier_pass/unknown_571298.bin rename to graphics/frontier_pass/unused.bin diff --git a/include/battle_pyramid_bag.h b/include/battle_pyramid_bag.h index de571714c..b8b3eb20f 100644 --- a/include/battle_pyramid_bag.h +++ b/include/battle_pyramid_bag.h @@ -29,7 +29,7 @@ enum { struct PyramidBagMenu { - void (*exitCallback)(void); + void (*newScreenCallback)(void); u8 tilemapBuffer[BG_SCREEN_SIZE]; u8 spriteIds[PBAG_SPRITE_COUNT]; u8 windowIds[5]; @@ -49,7 +49,7 @@ struct PyramidBagMenu struct PyramidBagMenuState { - void (*callback)(void); + void (*exitCallback)(void); u8 location; u16 cursorPosition; u16 scrollPosition; @@ -64,7 +64,7 @@ void CB2_ReturnToPyramidBagMenu(void); void UpdatePyramidBagList(void); void UpdatePyramidBagCursorPos(void); void sub_81C4EFC(void); -void GoToBattlePyramidBagMenu(u8 a0, void (*callback)(void)); +void GoToBattlePyramidBagMenu(u8 location, void (*exitCallback)(void)); void Task_CloseBattlePyramidBagMessage(u8 taskId); void TryStoreHeldItemsInPyramidBag(void); void ChooseItemsToTossFromPyramidBag(void); diff --git a/include/constants/item.h b/include/constants/item.h index 3277f2379..a224291fa 100644 --- a/include/constants/item.h +++ b/include/constants/item.h @@ -16,9 +16,4 @@ #define KEYITEMS_POCKET 4 #define POCKETS_COUNT 5 -// The TM/HM pocket is the largest pocket, so the maximum amount of items -// in a pocket is its count + 1 for the cancel option -#define MAX_POCKET_ITEMS (BAG_TMHM_COUNT + 1) - - #endif // GUARD_ITEM_CONSTANTS_H diff --git a/include/constants/items.h b/include/constants/items.h index 8f77e80de..c596dd3b8 100644 --- a/include/constants/items.h +++ b/include/constants/items.h @@ -199,9 +199,11 @@ #define FIRST_BERRY_INDEX ITEM_CHERI_BERRY #define LAST_BERRY_INDEX ITEM_ENIGMA_BERRY -#define ITEM_0B0 176 -#define ITEM_0B1 177 -#define ITEM_0B2 178 +#define ITEM_UNUSED_BERRY_1 176 +#define ITEM_UNUSED_BERRY_2 177 +#define ITEM_UNUSED_BERRY_3 178 + +#define MAX_BERRY_INDEX ITEM_UNUSED_BERRY_3 // Battle Held items #define ITEM_BRIGHT_POWDER 179 @@ -531,6 +533,6 @@ #define ITEM_B_USE_OTHER 2 // Check if the item is one that can be used on a Pokemon. -#define ITEM_HAS_EFFECT(item) ((item) >= ITEM_POTION && (item) <= ITEM_0B2) +#define ITEM_HAS_EFFECT(item) ((item) >= ITEM_POTION && (item) <= MAX_BERRY_INDEX) #endif // GUARD_CONSTANTS_ITEMS_H diff --git a/include/event_scripts.h b/include/event_scripts.h index 3340da6f5..c478f41f8 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -584,9 +584,11 @@ extern const u8 SecretBase_EventScript_ShrubUseSecretPower[]; extern const u8 TrainerHill_EventScript_TrainerBattle[]; // Item Use -extern u8 BerryTree_EventScript_ItemUsePlantBerry[]; -extern u8 BerryTree_EventScript_ItemUseWailmerPail[]; -extern u8 BattleFrontier_OutsideEast_EventScript_WaterSudowoodo[]; +extern const u8 BerryTree_EventScript_ItemUsePlantBerry[]; +extern const u8 BerryTree_EventScript_ItemUseWailmerPail[]; +extern const u8 BattleFrontier_OutsideEast_EventScript_WaterSudowoodo[]; + +extern const u8 EventScript_SelectWithoutRegisteredItem[]; // overworld extern const u8 EventScript_WhiteOut[]; diff --git a/include/graphics.h b/include/graphics.h index 903338c49..dc020c401 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -5284,13 +5284,13 @@ extern const u32 gKantoTrainerCardFrontLink_Tilemap[]; extern const u32 gHoennTrainerCardBg_Tilemap[]; // Frontier Pass -extern const u32 gUnknown_08DE08C8[]; -extern const u32 gUnknown_08DE2084[]; -extern const u32 gUnknown_08DE3350[]; -extern const u32 gUnknown_08DE3374[]; -extern const u32 gUnknown_08DE3060[]; +extern const u32 gFrontierPassBg_Gfx[]; +extern const u32 gFrontierPassBg_Tilemap[]; +extern const u16 gFrontierPassBg_Pal[][16]; +extern const u32 gFrontierPassMapAndCard_Gfx[]; +extern const u32 gFrontierPassCancelButton_Tilemap[]; +extern const u32 gFrontierPassCancelButtonHighlighted_Tilemap[]; extern const u32 gFrontierPassMedals_Gfx[]; -extern const u16 gUnknown_08DE07C8[][16]; extern const u16 gFrontierPassCursor_Pal[]; extern const u16 gFrontierPassMedalsGold_Pal[]; extern const u16 gFrontierPassMedalsSilver_Pal[]; diff --git a/include/item_menu.h b/include/item_menu.h index a99272b0c..fd576c3b5 100644 --- a/include/item_menu.h +++ b/include/item_menu.h @@ -1,107 +1,111 @@ -#ifndef GUARD_item_menu_H -#define GUARD_item_menu_H +#ifndef GUARD_ITEM_MENU_H +#define GUARD_ITEM_MENU_H #include "item.h" #include "menu_helpers.h" -#define ITEMMENULOCATION_FIELD 0 -#define ITEMMENULOCATION_BATTLE 1 -#define ITEMMENULOCATION_PARTY 2 -#define ITEMMENULOCATION_SHOP 3 -#define ITEMMENULOCATION_BERRY_TREE 4 -#define ITEMMENULOCATION_BERRY_BLENDER_CRUSH 5 -#define ITEMMENULOCATION_ITEMPC 6 -#define ITEMMENULOCATION_FAVOR_LADY 7 -#define ITEMMENULOCATION_QUIZ_LADY 8 -#define ITEMMENULOCATION_APPRENTICE 9 -#define ITEMMENULOCATION_WALLY 10 -#define ITEMMENULOCATION_PCBOX 11 -#define ITEMMENULOCATION_LAST 12 +enum { + ITEMMENULOCATION_FIELD, + ITEMMENULOCATION_BATTLE, + ITEMMENULOCATION_PARTY, + ITEMMENULOCATION_SHOP, + ITEMMENULOCATION_BERRY_TREE, + ITEMMENULOCATION_BERRY_BLENDER_CRUSH, + ITEMMENULOCATION_ITEMPC, + ITEMMENULOCATION_FAVOR_LADY, + ITEMMENULOCATION_QUIZ_LADY, + ITEMMENULOCATION_APPRENTICE, + ITEMMENULOCATION_WALLY, + ITEMMENULOCATION_PCBOX, + ITEMMENULOCATION_LAST, +}; -#define ITEMMENUACTION_USE 0 -#define ITEMMENUACTION_TOSS 1 -#define ITEMMENUACTION_REGISTER 2 -#define ITEMMENUACTION_GIVE 3 -#define ITEMMENUACTION_CANCEL 4 -#define ITEMMENUACTION_BATTLE_USE 5 -#define ITEMMENUACTION_CHECK 6 -#define ITEMMENUACTION_WALK 7 -#define ITEMMENUACTION_DESELECT 8 -#define ITEMMENUACTION_CHECK_TAG 9 -#define ITEMMENUACTION_CONFIRM 10 -#define ITEMMENUACTION_SHOW 11 -#define ITEMMENUACTION_GIVE_2 12 -#define ITEMMENUACTION_CONFIRM_2 13 -#define ITEMMENUACTION_DUMMY 14 +// Window IDs for the item menu +enum { + ITEMWIN_1x1, + ITEMWIN_1x2, + ITEMWIN_2x2, + ITEMWIN_2x3, + ITEMWIN_MESSAGE, + ITEMWIN_YESNO_LOW, + ITEMWIN_YESNO_HIGH, + ITEMWIN_QUANTITY, + ITEMWIN_QUANTITY_WIDE, + ITEMWIN_MONEY, + ITEMWIN_COUNT +}; -// Exported type declarations -struct BagStruct +#define ITEMMENU_SWAP_LINE_LENGTH 8 // Swap line is 8 sprites long +enum { + ITEMMENUSPRITE_BAG, + ITEMMENUSPRITE_BALL, + ITEMMENUSPRITE_ITEM, + ITEMMENUSPRITE_ITEM_ALT, // Need two when selecting new item + ITEMMENUSPRITE_SWAP_LINE, + ITEMMENUSPRITE_COUNT = ITEMMENUSPRITE_SWAP_LINE + ITEMMENU_SWAP_LINE_LENGTH, +}; + +struct BagPosition { - void (*bagCallback)(void); + void (*exitCallback)(void); u8 location; u8 pocket; - u16 unk6; + u16 pocketSwitchArrowPos; u16 cursorPosition[POCKETS_COUNT]; u16 scrollPosition[POCKETS_COUNT]; }; -extern struct BagStruct gBagPositionStruct; +extern struct BagPosition gBagPosition; -struct BagMenuStruct +struct BagMenu { - void (*exitCallback)(void); - u8 tilemapBuffer[0x800]; - u8 spriteId[12]; - u8 windowPointers[10]; - u8 itemOriginalLocation; + void (*newScreenCallback)(void); + u8 tilemapBuffer[BG_SCREEN_SIZE]; + u8 spriteIds[ITEMMENUSPRITE_COUNT]; + u8 windowIds[ITEMWIN_COUNT]; + u8 toSwapPos; u8 pocketSwitchDisabled:4; u8 itemIconSlot:2; u8 inhibitItemDescriptionPrint:1; u8 hideCloseBagText:1; - u8 filler3[2]; + u8 unused1[2]; u8 pocketScrollArrowsTask; u8 pocketSwitchArrowsTask; const u8* contextMenuItemsPtr; u8 contextMenuItemsBuffer[4]; u8 contextMenuNumItems; u8 numItemStacks[POCKETS_COUNT]; - u8 numShownItems[6]; + u8 numShownItems[POCKETS_COUNT]; s16 graphicsLoadState; - u8 filler4[0xE]; + u8 unused2[14]; u8 pocketNameBuffer[32][32]; - u8 filler2[4]; + u8 unused3[4]; }; -extern struct BagMenuStruct *gBagMenu; - -// Exported RAM declarations - +extern struct BagMenu *gBagMenu; extern u16 gSpecialVar_ItemId; -// Exported ROM declarations void CB2_GoToItemDepositMenu(void); void FavorLadyOpenBagMenu(void); void QuizLadyOpenBagMenu(void); void ApprenticeOpenBagMenu(void); void CB2_BagMenuFromBattle(void); -void SetInitialScrollAndCursorPositions(u8 pocketId); +void UpdatePocketListPosition(u8 pocketId); void CB2_ReturnToBagMenuPocket(void); void CB2_BagMenuFromStartMenu(void); u8 GetItemListPosition(u8 pocketId); bool8 UseRegisteredKeyItemOnField(void); void CB2_GoToSellMenu(void); -void GoToBagMenu(u8 bagMenuType, u8 pocketId, void ( *postExitMenuMainCallback2)()); +void GoToBagMenu(u8 bagMenuType, u8 pocketId, void ( *exitCallback)()); void DoWallyTutorialBagMenu(void); void ResetBagScrollPositions(void); void ChooseBerryForMachine(void (*exitCallback)(void)); void CB2_ChooseBerry(void); void Task_FadeAndCloseBagMenu(u8 taskId); -void BagMenu_YesNo(u8, u8, const struct YesNoFuncTable*); -void BagMenu_InitListsMenu(u8 taskId); +void BagMenu_YesNo(u8 taskId, u8 windowType, const struct YesNoFuncTable* funcTable); void UpdatePocketItemList(u8 pocketId); void DisplayItemMessage(u8 taskId, u8 fontId, const u8 *str, void ( *callback)(u8 taskId)); void DisplayItemMessageOnField(u8 taskId, const u8 *src, TaskFunc callback); +void CloseItemMessage(u8 taskId); - - -#endif //GUARD_item_menu_H +#endif //GUARD_ITEM_MENU_H diff --git a/include/item_menu_icons.h b/include/item_menu_icons.h index 50e11dfd9..d01dcccf5 100644 --- a/include/item_menu_icons.h +++ b/include/item_menu_icons.h @@ -22,10 +22,4 @@ void FreeBerryTagSpritePalette(void); u8 CreateSpinningBerrySprite(u8 berryId, u8 x, u8 y, bool8 startAffine); u8 CreateBerryFlavorCircleSprite(s16 x); -#define TAG_BAG_GFX 100 -#define TAG_ROTATING_BALL_GFX 101 -#define TAG_BERRY_CHECK_CIRCLE_GFX 10000 -#define TAG_BERRY_PIC_TILE 0xFFFF -#define TAG_BERRY_PIC_PAL 0x7544 - #endif // GUARD_ITEM_MENU_ICONS_H diff --git a/include/menu_helpers.h b/include/menu_helpers.h index 9909437a2..1434efcf3 100644 --- a/include/menu_helpers.h +++ b/include/menu_helpers.h @@ -28,13 +28,13 @@ void CreateYesNoMenuWithCallbacks(u8 taskId, const struct WindowTemplate *templa bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1); u8 GetLRKeysPressed(void); u8 GetLRKeysPressedAndHeld(void); -bool8 sub_8122148(u16 itemId); +bool8 IsHoldingItemAllowed(u16 itemId); bool8 IsWritingMailAllowed(u16 itemId); bool8 MenuHelpers_LinkSomething(void); 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 SetItemListPerPageCount(struct ItemSlot *slots, u8 slotsCount, u8 *pageItems, u8 *totalItems, u8 maxPerPage); +void SetCursorWithinListBounds(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 totalItems); +void SetCursorScrollWithinListBounds(u16 *scrollOffset, u16 *cursorPos, u8 shownItems, u8 totalItems, u8 maxShownItems); void LoadListMenuSwapLineGfx(void); void CreateSwapLineSprites(u8 *spriteIds, u8 count); void DestroySwapLineSprites(u8 *spriteIds, u8 count); diff --git a/include/menu_specialized.h b/include/menu_specialized.h index 987fca9fc..c29110662 100644 --- a/include/menu_specialized.h +++ b/include/menu_specialized.h @@ -15,6 +15,14 @@ #define MAX_CONDITION_SPARKLES 10 +// Window IDs for the Player PC Mailbox +enum { + MAILBOXWIN_TITLE, + MAILBOXWIN_LIST, + MAILBOXWIN_OPTIONS, + MAILBOXWIN_COUNT +}; + struct UnknownSubStruct_81D1ED4 { u16 unk0; @@ -35,12 +43,12 @@ struct ConditionGraph /*0x355*/ u8 state; }; -bool8 sub_81D1C44(u8 count); -u8 sub_81D1C84(u8 a0); -u8 sub_81D1DC0(struct PlayerPCItemPageStruct *page); -void sub_81D1E90(struct PlayerPCItemPageStruct *page); -void sub_81D1EC0(void); -void sub_81D1D04(u8 a0); +bool8 MailboxMenu_Alloc(u8 count); +u8 MailboxMenu_AddWindow(u8 windowIdx); +u8 MailboxMenu_CreateList(struct PlayerPCItemPageStruct *page); +void MailboxMenu_AddScrollArrows(struct PlayerPCItemPageStruct *page); +void MailboxMenu_Free(void); +void MailboxMenu_RemoveWindow(u8 windowIdx); void InitConditionGraphData(struct ConditionGraph *graph); void sub_81D2108(struct ConditionGraph *graph); void SetConditionGraphIOWindows(u8 bg); diff --git a/include/player_pc.h b/include/player_pc.h index bdf4a4e0e..2521eac13 100644 --- a/include/player_pc.h +++ b/include/player_pc.h @@ -3,69 +3,6 @@ #include "menu.h" -// local task defines -#define PAGE_INDEX data[0] -#define ITEMS_ABOVE_TOP data[1] -#define NUM_ITEMS data[1] -#define NUM_QUANTITY_ROLLER data[3] -#define NUM_PAGE_ITEMS data[4] -// not used -#define CURRENT_ITEM_STORAGE_MENU data[3] -// not used -#define SWAP_ITEM_INDEX data[8] -#define SWITCH_MODE_ACTIVE data[9] - -// this is potentially an ewram access occuring in high ewram. TODO: investigate this further. -#define NEW_GAME_PC_ITEMS(i, type) ((u16)((u16 *)gNewGamePCItems + type)[i * 2]) - -// defined and used in the above macro -enum -{ - PC_ITEM_ID, - PC_QUANTITY -}; - -// player PC menu options -enum -{ - PLAYERPC_MENU_ITEMSTORAGE, - PLAYERPC_MENU_MAILBOX, - PLAYERPC_MENU_DECORATION, - PLAYERPC_MENU_TURNOFF -}; - -// item storage menus -enum -{ - ITEMPC_MENU_WITHDRAW, - ITEMPC_MENU_DEPOSIT, - ITEMPC_MENU_TOSS, - ITEMPC_MENU_EXIT -}; - -// mailbox mail options -enum -{ - MAILBOX_READ, - MAILBOX_MOVE_TO_BAG, - MAILBOX_GIVE, - MAILBOX_CANCEL, -}; - -// special item description handlers -enum -{ - ITEMPC_SWITCH_WHICH_ITEM = 0xFFF7, - ITEMPC_OKAY_TO_THROW_AWAY, - ITEMPC_TOO_IMPORTANT, - ITEMPC_NO_MORE_ROOM, - ITEMPC_THREW_AWAY_ITEM, - ITEMPC_HOW_MANY_TO_TOSS, - ITEMPC_WITHDREW_THING, - ITEMPC_HOW_MANY_TO_WITHDRAW, - ITEMPC_GO_BACK_TO_PREV -}; - struct PlayerPCItemPageStruct { u16 cursorPos; @@ -76,16 +13,12 @@ struct PlayerPCItemPageStruct u8 scrollIndicatorTaskId; }; -// Exported type declarations +extern struct PlayerPCItemPageStruct gPlayerPCItemPageInfo; -// Exported RAM declarations -extern struct PlayerPCItemPageStruct playerPCItemPageInfo; - -// Exported ROM declarations extern const struct MenuAction gMailboxMailOptions[]; void ReshowPlayerPC(u8 taskId); -void sub_816B31C(void); +void CB2_PlayerPCExitBagMenu(void); void Mailbox_ReturnToMailListAfterDeposit(void); void NewGameInitPCItems(void); diff --git a/include/strings.h b/include/strings.h index 9b3be0538..2357e3777 100644 --- a/include/strings.h +++ b/include/strings.h @@ -419,8 +419,8 @@ extern const u8 gText_FirmSlash[]; // item menu screen text extern const u8 gText_CloseBag[]; -extern const u8 gText_ClearTo11Var1Clear5Var2[]; -extern const u8 gText_NumberVar1Clear7Var2[]; +extern const u8 gText_NumberItem_HM[]; +extern const u8 gText_NumberItem_TMBerry[]; extern const u8 gText_xVar1[]; extern const u8 gText_ReturnToVar1[]; extern const u8 gText_SelectorArrow2[]; @@ -442,6 +442,7 @@ extern const u8 gText_CantStoreImportantItems[]; extern const u8 gText_DepositedVar2Var1s[]; extern const u8 gText_NoRoomForItems[]; extern const u8 gText_ThreeDashes[]; +extern const u8 *const gPocketNamesStringsTable[]; // party menu text extern const u8 gText_PkmnHPRestoredByVar2[]; diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index 266b85415..83bf35090 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -411,20 +411,20 @@ static void Task_ChooseItemsToTossFromPyramidBag(u8 taskId) void CB2_ReturnToPyramidBagMenu(void) { - GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_PREV, gPyramidBagMenuState.callback); + GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_PREV, gPyramidBagMenuState.exitCallback); } -void GoToBattlePyramidBagMenu(u8 location, void (*callback)(void)) +void GoToBattlePyramidBagMenu(u8 location, void (*exitCallback)(void)) { gPyramidBagMenu = AllocZeroed(sizeof(*gPyramidBagMenu)); if (location != PYRAMIDBAG_LOC_PREV) gPyramidBagMenuState.location = location; - if (callback != NULL) - gPyramidBagMenuState.callback = callback; + if (exitCallback != NULL) + gPyramidBagMenuState.exitCallback = exitCallback; - gPyramidBagMenu->exitCallback = NULL; + gPyramidBagMenu->newScreenCallback = NULL; gPyramidBagMenu->toSwapPos = POS_NONE; gPyramidBagMenu->scrollIndicatorsTaskId = TASK_NONE; @@ -624,7 +624,7 @@ static void CopyBagItemName(u8 *dst, u16 itemId) { ConvertIntToDecimalStringN(gStringVar1, ITEM_TO_BERRY(itemId), STR_CONV_MODE_LEADING_ZEROS, 2); CopyItemName(itemId, gStringVar2); - StringExpandPlaceholders(dst, gText_NumberVar1Clear7Var2); + StringExpandPlaceholders(dst, gText_NumberItem_TMBerry); } else { @@ -866,10 +866,13 @@ static void Task_ClosePyramidBag(u8 taskId) if (!gPaletteFade.active) { DestroyListMenuTask(tListTaskId, &gPyramidBagMenuState.scrollPosition, &gPyramidBagMenuState.cursorPosition); - if (gPyramidBagMenu->exitCallback != NULL) - SetMainCallback2(gPyramidBagMenu->exitCallback); + + // If ready for a new screen (e.g. party menu for giving an item) go to that screen + // Otherwise exit the bag and use callback set up when the bag was first opened + if (gPyramidBagMenu->newScreenCallback != NULL) + SetMainCallback2(gPyramidBagMenu->newScreenCallback); else - SetMainCallback2(gPyramidBagMenuState.callback); + SetMainCallback2(gPyramidBagMenuState.exitCallback); RemoveScrollArrow(); ResetSpriteData(); FreeAllSpritePalettes(); @@ -1249,7 +1252,7 @@ static void BagAction_Give(u8 taskId) } else if (!ItemId_GetImportance(gSpecialVar_ItemId)) { - gPyramidBagMenu->exitCallback = CB2_ChooseMonToGiveItem; + gPyramidBagMenu->newScreenCallback = CB2_ChooseMonToGiveItem; CloseBattlePyramidBag(taskId); } else diff --git a/src/berry_tag_screen.c b/src/berry_tag_screen.c index 4632f6dc0..babbbb3eb 100644 --- a/src/berry_tag_screen.c +++ b/src/berry_tag_screen.c @@ -548,9 +548,9 @@ static void Task_HandleInput(u8 taskId) static void TryChangeDisplayedBerry(u8 taskId, s8 toMove) { s16 *data = gTasks[taskId].data; - s16 currPocketPosition = gBagPositionStruct.scrollPosition[3] + gBagPositionStruct.cursorPosition[3]; + s16 currPocketPosition = gBagPosition.scrollPosition[BERRIES_POCKET] + gBagPosition.cursorPosition[BERRIES_POCKET]; u32 newPocketPosition = currPocketPosition + toMove; - if (newPocketPosition < 46 && BagGetItemIdByPocketPosition(POCKET_BERRIES, newPocketPosition) != 0) + if (newPocketPosition < ITEM_TO_BERRY(MAX_BERRY_INDEX) && BagGetItemIdByPocketPosition(POCKET_BERRIES, newPocketPosition) != ITEM_NONE) { if (toMove < 0) data[1] = 2; @@ -566,8 +566,8 @@ static void TryChangeDisplayedBerry(u8 taskId, s8 toMove) static void HandleBagCursorPositionChange(s8 toMove) { - u16 *scrollPos = &gBagPositionStruct.scrollPosition[3]; - u16 *cursorPos = &gBagPositionStruct.cursorPosition[3]; + u16 *scrollPos = &gBagPosition.scrollPosition[BERRIES_POCKET]; + u16 *cursorPos = &gBagPosition.cursorPosition[BERRIES_POCKET]; if (toMove > 0) { if (*cursorPos < 4 || BagGetItemIdByPocketPosition(POCKET_BERRIES, *scrollPos + 8) == 0) diff --git a/src/data/item_icon_table.h b/src/data/item_icon_table.h index c36969ab5..ea8315e76 100644 --- a/src/data/item_icon_table.h +++ b/src/data/item_icon_table.h @@ -192,10 +192,9 @@ const u32 *const gItemIconTable[][2] = [ITEM_LANSAT_BERRY] = {gItemIcon_LansatBerry, gItemIconPalette_LansatBerry}, [ITEM_STARF_BERRY] = {gItemIcon_StarfBerry, gItemIconPalette_StarfBerry}, [ITEM_ENIGMA_BERRY] = {gItemIcon_EnigmaBerry, gItemIconPalette_EnigmaBerry}, - // ???????? - [ITEM_0B0] = {gItemIcon_QuestionMark, gItemIconPalette_QuestionMark}, - [ITEM_0B1] = {gItemIcon_QuestionMark, gItemIconPalette_QuestionMark}, - [ITEM_0B2] = {gItemIcon_QuestionMark, gItemIconPalette_QuestionMark}, + [ITEM_UNUSED_BERRY_1] = {gItemIcon_QuestionMark, gItemIconPalette_QuestionMark}, + [ITEM_UNUSED_BERRY_2] = {gItemIcon_QuestionMark, gItemIconPalette_QuestionMark}, + [ITEM_UNUSED_BERRY_3] = {gItemIcon_QuestionMark, gItemIconPalette_QuestionMark}, // Hold items [ITEM_BRIGHT_POWDER] = {gItemIcon_BrightPowder, gItemIconPalette_BrightPowder}, [ITEM_WHITE_HERB] = {gItemIcon_InBattleHerb, gItemIconPalette_WhiteHerb}, diff --git a/src/data/items.h b/src/data/items.h index fc7792186..370cd2022 100644 --- a/src/data/items.h +++ b/src/data/items.h @@ -2148,7 +2148,7 @@ const struct Item gItems[] = .battleUseFunc = ItemUseInBattle_EnigmaBerry, }, - [ITEM_0B0] = + [ITEM_UNUSED_BERRY_1] = { .name = _("????????"), .itemId = ITEM_NONE, @@ -2159,7 +2159,7 @@ const struct Item gItems[] = .fieldUseFunc = ItemUseOutOfBattle_CannotUse, }, - [ITEM_0B1] = + [ITEM_UNUSED_BERRY_2] = { .name = _("????????"), .itemId = ITEM_NONE, @@ -2170,7 +2170,7 @@ const struct Item gItems[] = .fieldUseFunc = ItemUseOutOfBattle_CannotUse, }, - [ITEM_0B2] = + [ITEM_UNUSED_BERRY_3] = { .name = _("????????"), .itemId = ITEM_NONE, diff --git a/src/data/object_events/berry_tree_graphics_tables.h b/src/data/object_events/berry_tree_graphics_tables.h index 390c82f95..fe41bda3b 100755 --- a/src/data/object_events/berry_tree_graphics_tables.h +++ b/src/data/object_events/berry_tree_graphics_tables.h @@ -559,7 +559,7 @@ const u8 *const gBerryTreeObjectEventGraphicsIdTablePointers[] = { [ITEM_STARF_BERRY - FIRST_BERRY_INDEX] = gBerryTreeObjectEventGraphicsIdTable, [ITEM_ENIGMA_BERRY - FIRST_BERRY_INDEX] = gBerryTreeObjectEventGraphicsIdTable, // 3 unused berries. - [ITEM_0B0 - FIRST_BERRY_INDEX] = gBerryTreeObjectEventGraphicsIdTable, - [ITEM_0B1 - FIRST_BERRY_INDEX] = gBerryTreeObjectEventGraphicsIdTable, - [ITEM_0B2 - FIRST_BERRY_INDEX] = gBerryTreeObjectEventGraphicsIdTable, + [ITEM_UNUSED_BERRY_1 - FIRST_BERRY_INDEX] = gBerryTreeObjectEventGraphicsIdTable, + [ITEM_UNUSED_BERRY_2 - FIRST_BERRY_INDEX] = gBerryTreeObjectEventGraphicsIdTable, + [ITEM_UNUSED_BERRY_3 - FIRST_BERRY_INDEX] = gBerryTreeObjectEventGraphicsIdTable, }; diff --git a/src/decoration.c b/src/decoration.c index 62d1966bf..39858e957 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -862,12 +862,12 @@ static void InitDecorationItemsMenuLimits(void) static void InitDecorationItemsMenuScrollAndCursor(void) { - sub_812225C(&sDecorationsScrollOffset, &sDecorationsCursorPos, sDecorationItemsMenu->maxShownItems, sDecorationItemsMenu->numMenuItems); + SetCursorWithinListBounds(&sDecorationsScrollOffset, &sDecorationsCursorPos, sDecorationItemsMenu->maxShownItems, sDecorationItemsMenu->numMenuItems); } static void InitDecorationItemsMenuScrollAndCursor2(void) { - sub_8122298(&sDecorationsScrollOffset, &sDecorationsCursorPos, sDecorationItemsMenu->maxShownItems, sDecorationItemsMenu->numMenuItems, 8); + SetCursorScrollWithinListBounds(&sDecorationsScrollOffset, &sDecorationsCursorPos, sDecorationItemsMenu->maxShownItems, sDecorationItemsMenu->numMenuItems, 8); } static void PrintDecorationItemMenuItems(u8 taskId) diff --git a/src/frontier_pass.c b/src/frontier_pass.c index 22a7695f2..e3e5ee1f2 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -38,14 +38,14 @@ enum WINDOW_BATTLE_RECORD, WINDOW_BATTLE_POINTS, WINDOW_DESCRIPTION, - WINDOW_4, + WINDOW_DUMMY, WINDOW_COUNT }; // Windows displayed in the facilities map view. enum { - MAP_WINDOW_0, + MAP_WINDOW_UNUSED, // Overlaps the "Battle Frontier" title area of the map MAP_WINDOW_NAME, MAP_WINDOW_DESCRIPTION, MAP_WINDOW_COUNT @@ -59,9 +59,39 @@ enum CURSOR_AREA_RECORD, CURSOR_AREA_CANCEL, CURSOR_AREA_POINTS, - CURSOR_AREA_EARNED_SYMBOLS, // The window. - CURSOR_AREA_SYMBOL, // All 7 symbols. - CURSOR_AREA_COUNT = CURSOR_AREA_SYMBOL + NUM_FRONTIER_FACILITIES, + CURSOR_AREA_EARNED_SYMBOLS, // The window containing the symbols + CURSOR_AREA_SYMBOL_TOWER, + CURSOR_AREA_SYMBOL_DOME, + CURSOR_AREA_SYMBOL_PALACE, + CURSOR_AREA_SYMBOL_ARENA, + CURSOR_AREA_SYMBOL_FACTORY, + CURSOR_AREA_SYMBOL_PIKE, + CURSOR_AREA_SYMBOL_PYRAMID, + CURSOR_AREA_COUNT +}; + +// Start of symbol cursor areas +#define CURSOR_AREA_SYMBOL CURSOR_AREA_SYMBOL_TOWER + +enum { + MAP_INDICATOR_RECTANGLE, + MAP_INDICATOR_SQUARE, +}; + +enum { + TAG_CURSOR, + TAG_MAP_INDICATOR, + TAG_MEDAL_SILVER, + TAG_MEDAL_GOLD, + TAG_HEAD_MALE, + TAG_HEAD_FEMALE, +}; + +// Error return codes. Never read +enum { + SUCCESS, + ERR_ALREADY_DONE, + ERR_ALLOC_FAILED, }; struct FrontierPassData @@ -73,25 +103,26 @@ struct FrontierPassData s16 cursorY; u8 cursorArea; u8 previousCursorArea; - u8 hasBattleRecord:1; - u8 unkE:3; + bool8 hasBattleRecord:1; + u8 areaToShow:3; u8 trainerStars:4; - u8 facilitySymbols[NUM_FRONTIER_FACILITIES]; + u8 facilitySymbols[NUM_FRONTIER_FACILITIES]; // 0: no symbol, 1: silver, 2: gold }; struct FrontierPassGfx { struct Sprite *cursorSprite; struct Sprite *symbolSprites[NUM_FRONTIER_FACILITIES]; - u8 *unk20; - u8 *unk24; - u8 *unk28; - bool8 setAffine; - s16 unk2E; - s16 unk30; - u8 tilemapBuff1[0x1000]; - u8 tilemapBuff2[0x1000]; - u8 tilemapBuff3[0x400]; + // These 3 tilemaps are used to overwrite the respective area when highlighted + u8 *mapAndCardZoomTilemap; + u8 *mapAndCardTilemap; + u8 *battleRecordTilemap; + bool8 zooming; + s16 scaleX; + s16 scaleY; + u8 tilemapBuff1[BG_SCREEN_SIZE * 2]; + u8 tilemapBuff2[BG_SCREEN_SIZE * 2]; + u8 tilemapBuff3[BG_SCREEN_SIZE / 2]; }; struct FrontierPassSaved @@ -109,9 +140,9 @@ struct FrontierMapData struct Sprite *mapIndicatorSprite; u8 cursorPos; u8 unused; - u8 tilemapBuff0[0x1000]; - u8 tilemapBuff1[0x1000]; - u8 tilemapBuff2[0x1000]; + u8 tilemapBuff0[BG_SCREEN_SIZE * 2]; + u8 tilemapBuff1[BG_SCREEN_SIZE * 2]; + u8 tilemapBuff2[BG_SCREEN_SIZE * 2]; }; static EWRAM_DATA struct FrontierPassData *sPassData = NULL; @@ -119,37 +150,39 @@ static EWRAM_DATA struct FrontierPassGfx *sPassGfx = NULL; static EWRAM_DATA struct FrontierMapData *sMapData = NULL; static EWRAM_DATA struct FrontierPassSaved sSavedPassData = {0}; -// This file's functions. static u32 AllocateFrontierPassData(void (*callback)(void)); static void ShowFrontierMap(void (*callback)(void)); static void CB2_InitFrontierPass(void); -static void sub_80C629C(void); +static void DrawFrontierPassBg(void); static void FreeCursorAndSymbolSprites(void); static void LoadCursorAndSymbolSprites(void); static u32 FreeFrontierPassData(void); static bool32 InitFrontierPass(void); static bool32 HideFrontierPass(void); -static void Task_HandleFrontierPassInput(u8 taskId); -static void Task_DoFadeEffect(u8 taskId); -static void sub_80C6104(u8 cursorArea, u8 previousCursorArea); -static void PrintAreaDescription(u8 cursorArea); -static void sub_80C5F58(bool8 arg0, bool8 arg1); -static void SpriteCb_Dummy(struct Sprite *sprite); +static void Task_HandleFrontierPassInput(u8); +static void Task_PassAreaZoom(u8); +static void UpdateAreaHighlight(u8, u8); +static void PrintAreaDescription(u8); +static void ShowHideZoomingArea(bool8, bool8); +static void SpriteCB_PlayerHead(struct Sprite *); -// Const rom data. -static const u16 sMaleHeadPalette[] = INCBIN_U16("graphics/frontier_pass/map_heads.gbapal"); -static const u16 sFemaleHeadPalette[] = INCBIN_U16("graphics/frontier_pass/map_heads_female.gbapal"); -static const u32 gUnknown_0856FBBC[] = INCBIN_U32("graphics/frontier_pass/map_screen.4bpp.lz"); -static const u32 sCursorGfx[] = INCBIN_U32("graphics/frontier_pass/cursor.4bpp.lz"); -static const u32 sHeadsGfx[] = INCBIN_U32("graphics/frontier_pass/map_heads.4bpp.lz"); -static const u32 sMapCursorGfx[] = INCBIN_U32("graphics/frontier_pass/map_cursor.4bpp.lz"); -static const u32 gUnknown_08570E00[] = INCBIN_U32("graphics/frontier_pass/map_screen.bin.lz"); -static const u32 gUnknown_08571060[] = INCBIN_U32("graphics/frontier_pass/small_map_and_card.bin.lz"); -static const u32 gUnknown_08571298[] = INCBIN_U32("graphics/frontier_pass/unknown_571298.bin"); -static const u32 gUnknown_085712C0[] = INCBIN_U32("graphics/frontier_pass/record_frame.bin.lz"); -static const u32 gUnknown_085712F8[] = INCBIN_U32("graphics/frontier_pass/small_map_and_card_affine.bin.lz"); +static const u16 sMaleHead_Pal[] = INCBIN_U16("graphics/frontier_pass/map_heads.gbapal"); +static const u16 sFemaleHead_Pal[] = INCBIN_U16("graphics/frontier_pass/map_heads_female.gbapal"); +static const u32 sMapScreen_Gfx[] = INCBIN_U32("graphics/frontier_pass/map_screen.4bpp.lz"); +static const u32 sCursor_Gfx[] = INCBIN_U32("graphics/frontier_pass/cursor.4bpp.lz"); +static const u32 sHeads_Gfx[] = INCBIN_U32("graphics/frontier_pass/map_heads.4bpp.lz"); +static const u32 sMapCursor_Gfx[] = INCBIN_U32("graphics/frontier_pass/map_cursor.4bpp.lz"); +static const u32 sMapScreen_Tilemap[] = INCBIN_U32("graphics/frontier_pass/map_screen.bin.lz"); +static const u32 sMapAndCard_ZoomedOut_Tilemap[] = INCBIN_U32("graphics/frontier_pass/small_map_and_card.bin.lz"); +static const u32 sUnusedData[] = INCBIN_U32("graphics/frontier_pass/unused.bin"); +static const u32 sBattleRecord_Tilemap[] = INCBIN_U32("graphics/frontier_pass/record_frame.bin.lz"); +static const u32 sMapAndCard_Zooming_Tilemap[] = INCBIN_U32("graphics/frontier_pass/small_map_and_card_affine.bin.lz"); -static const s16 gUnknown_085713E0[][2] = {{216, 32}, {216, 128}}; +static const s16 sBgAffineCoords[][2] = +{ + [CURSOR_AREA_MAP - 1] = {216, 32}, + [CURSOR_AREA_CARD - 1] = {216, 128} +}; static const struct BgTemplate sPassBgTemplates[] = { @@ -213,9 +246,9 @@ static const struct BgTemplate sMapBgTemplates[] = }, }; -static const struct WindowTemplate sPassWindowTemplates[] = +static const struct WindowTemplate sPassWindowTemplates[WINDOW_COUNT] = { - { + [WINDOW_EARNED_SYMBOLS] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 3, @@ -224,7 +257,7 @@ static const struct WindowTemplate sPassWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x1, }, - { + [WINDOW_BATTLE_RECORD] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 10, @@ -233,7 +266,7 @@ static const struct WindowTemplate sPassWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x26, }, - { + [WINDOW_BATTLE_POINTS] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 13, @@ -242,7 +275,7 @@ static const struct WindowTemplate sPassWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x4B, }, - { + [WINDOW_DESCRIPTION] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 18, @@ -256,7 +289,7 @@ static const struct WindowTemplate sPassWindowTemplates[] = static const struct WindowTemplate sMapWindowTemplates[] = { - { + [MAP_WINDOW_UNUSED] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 1, @@ -265,7 +298,7 @@ static const struct WindowTemplate sMapWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x1, }, - { + [MAP_WINDOW_NAME] = { .bg = 0, .tilemapLeft = 20, .tilemapTop = 1, @@ -274,7 +307,7 @@ static const struct WindowTemplate sMapWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x4D, }, - { + [MAP_WINDOW_DESCRIPTION] = { .bg = 0, .tilemapLeft = 2, .tilemapTop = 16, @@ -300,159 +333,162 @@ struct s16 xStart; s16 xEnd; } -static const sPassAreasLayout[] = +static const sPassAreasLayout[CURSOR_AREA_COUNT - 1] = { - {28, 76, 132, 220}, - {84, 132, 132, 220}, - {80, 102, 20, 108}, - {0, 16, 152, 240}, - {108, 134, 20, 108}, - {24, 48, 20, 108}, - {50, 66, 20, 36}, - {66, 82, 32, 48}, - {50, 66, 44, 60}, - {66, 82, 56, 72}, - {50, 66, 68, 84}, - {66, 82, 80, 96}, - {50, 66, 92, 108}, + [CURSOR_AREA_MAP - 1] = { 28, 76, 132, 220}, + [CURSOR_AREA_CARD - 1] = { 84, 132, 132, 220}, + [CURSOR_AREA_RECORD - 1] = { 80, 102, 20, 108}, + [CURSOR_AREA_CANCEL - 1] = { 0, 16, 152, 240}, + [CURSOR_AREA_POINTS - 1] = {108, 134, 20, 108}, + [CURSOR_AREA_EARNED_SYMBOLS - 1] = { 24, 48, 20, 108}, + [CURSOR_AREA_SYMBOL_TOWER - 1] = { 50, 66, 20, 36}, + [CURSOR_AREA_SYMBOL_DOME - 1] = { 66, 82, 32, 48}, + [CURSOR_AREA_SYMBOL_PALACE - 1] = { 50, 66, 44, 60}, + [CURSOR_AREA_SYMBOL_ARENA - 1] = { 66, 82, 56, 72}, + [CURSOR_AREA_SYMBOL_FACTORY - 1] = { 50, 66, 68, 84}, + [CURSOR_AREA_SYMBOL_PIKE - 1] = { 66, 82, 80, 96}, + [CURSOR_AREA_SYMBOL_PYRAMID - 1] = { 50, 66, 92, 108}, }; static const struct CompressedSpriteSheet sCursorSpriteSheets[] = { - {sCursorGfx, 0x100, 0}, - {sMapCursorGfx, 0x400, 1}, - {gFrontierPassMedals_Gfx, 0x380, 2}, + {sCursor_Gfx, 0x100, TAG_CURSOR}, + {sMapCursor_Gfx, 0x400, TAG_MAP_INDICATOR}, + {gFrontierPassMedals_Gfx, 0x380, TAG_MEDAL_SILVER}, }; static const struct CompressedSpriteSheet sHeadsSpriteSheet[] = { - {sHeadsGfx, 0x100, 4}, + {sHeads_Gfx, 0x100, TAG_HEAD_MALE}, {} }; static const struct SpritePalette sSpritePalettes[] = { - {gFrontierPassCursor_Pal, 0}, - {gFrontierPassMapCursor_Pal, 1}, - {gFrontierPassMedalsSilver_Pal, 2}, - {gFrontierPassMedalsGold_Pal, 3}, - {sMaleHeadPalette, 4}, - {sFemaleHeadPalette, 5}, + {gFrontierPassCursor_Pal, TAG_CURSOR}, + {gFrontierPassMapCursor_Pal, TAG_MAP_INDICATOR}, + {gFrontierPassMedalsSilver_Pal, TAG_MEDAL_SILVER}, + {gFrontierPassMedalsGold_Pal, TAG_MEDAL_GOLD}, + {sMaleHead_Pal, TAG_HEAD_MALE}, + {sFemaleHead_Pal, TAG_HEAD_FEMALE}, {} }; -static const union AnimCmd sSpriteAnim_857151C[] = +static const union AnimCmd sAnim_Frame1_Unused[] = { ANIMCMD_FRAME(0, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571524[] = +static const union AnimCmd sAnim_Frame1[] = { ANIMCMD_FRAME(0, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_857152C[] = +static const union AnimCmd sAnim_Frame2[] = { ANIMCMD_FRAME(4, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571534[] = +static const union AnimCmd sAnim_Frame3[] = { ANIMCMD_FRAME(8, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_857153C[] = +static const union AnimCmd sAnim_Frame4[] = { ANIMCMD_FRAME(12, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571544[] = +static const union AnimCmd sAnim_Frame5[] = { ANIMCMD_FRAME(16, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_857154C[] = +static const union AnimCmd sAnim_Frame6[] = { ANIMCMD_FRAME(20, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_8571554[] = +static const union AnimCmd sAnim_Frame7[] = { ANIMCMD_FRAME(24, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_857155C[] = +static const union AnimCmd sAnim_MapIndicatorCursor_Rectangle[] = { ANIMCMD_FRAME(0, 45), ANIMCMD_FRAME(8, 45), ANIMCMD_JUMP(0) }; -static const union AnimCmd sSpriteAnim_8571568[] = +static const union AnimCmd sAnim_MapIndicatorCursor_Square[] = { ANIMCMD_FRAME(16, 45), ANIMCMD_FRAME(24, 45), ANIMCMD_JUMP(0) }; -static const union AnimCmd *const sSpriteAnimTable_8571574[] = +// Used both by the cursor and the map head icons +static const union AnimCmd *const sAnims_TwoFrame[] = { - sSpriteAnim_8571524, - sSpriteAnim_857152C + sAnim_Frame1, + sAnim_Frame2 }; -static const union AnimCmd *const sSpriteAnimTable_857157C[] = +static const union AnimCmd *const sAnims_Medal[] = { - sSpriteAnim_8571524, - sSpriteAnim_857152C, - sSpriteAnim_8571534, - sSpriteAnim_857153C, - sSpriteAnim_8571544, - sSpriteAnim_857154C, - sSpriteAnim_8571554 + [CURSOR_AREA_SYMBOL_TOWER - CURSOR_AREA_SYMBOL] = sAnim_Frame1, + [CURSOR_AREA_SYMBOL_DOME - CURSOR_AREA_SYMBOL] = sAnim_Frame2, + [CURSOR_AREA_SYMBOL_PALACE - CURSOR_AREA_SYMBOL] = sAnim_Frame3, + [CURSOR_AREA_SYMBOL_ARENA - CURSOR_AREA_SYMBOL] = sAnim_Frame4, + [CURSOR_AREA_SYMBOL_FACTORY - CURSOR_AREA_SYMBOL] = sAnim_Frame5, + [CURSOR_AREA_SYMBOL_PIKE - CURSOR_AREA_SYMBOL] = sAnim_Frame6, + [CURSOR_AREA_SYMBOL_PYRAMID - CURSOR_AREA_SYMBOL] = sAnim_Frame7 }; -static const union AnimCmd *const sSpriteAnimTable_8571598[] = +static const union AnimCmd *const sAnims_MapIndicatorCursor[] = { - sSpriteAnim_857155C, - sSpriteAnim_8571568 + [MAP_INDICATOR_RECTANGLE] = sAnim_MapIndicatorCursor_Rectangle, + [MAP_INDICATOR_SQUARE] = sAnim_MapIndicatorCursor_Square }; -static const union AffineAnimCmd sSpriteAffineAnim_85715A0[] = +static const union AffineAnimCmd sAffineAnim_Unused[] = { AFFINEANIMCMD_FRAME(256, 256, 0, 0), AFFINEANIMCMD_END }; -static const union AffineAnimCmd *const sSpriteAffineAnimTable_85715B0[] = +static const union AffineAnimCmd *const sAffineAnims_Unused[] = { - sSpriteAffineAnim_85715A0 + sAffineAnim_Unused }; static const struct SpriteTemplate sSpriteTemplates_Cursors[] = { + // Triangular cursor { - .tileTag = 0, - .paletteTag = 0, + .tileTag = TAG_CURSOR, + .paletteTag = TAG_CURSOR, .oam = &gOamData_AffineOff_ObjNormal_16x16, - .anims = sSpriteAnimTable_8571574, + .anims = sAnims_TwoFrame, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }, + // Map indicator cursor { - .tileTag = 1, - .paletteTag = 1, + .tileTag = TAG_MAP_INDICATOR, + .paletteTag = TAG_MAP_INDICATOR, .oam = &gOamData_AffineOff_ObjNormal_32x16, - .anims = sSpriteAnimTable_8571598, + .anims = sAnims_MapIndicatorCursor, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, @@ -461,43 +497,43 @@ static const struct SpriteTemplate sSpriteTemplates_Cursors[] = static const struct SpriteTemplate sSpriteTemplate_Medal = { - .tileTag = 2, - .paletteTag = 2, + .tileTag = TAG_MEDAL_SILVER, + .paletteTag = TAG_MEDAL_SILVER, .oam = &gOamData_AffineOff_ObjNormal_16x16, - .anims = sSpriteAnimTable_857157C, + .anims = sAnims_Medal, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, }; -static const struct SpriteTemplate sSpriteTemplate_Head = +static const struct SpriteTemplate sSpriteTemplate_PlayerHead = { - .tileTag = 4, - .paletteTag = 4, + .tileTag = TAG_HEAD_MALE, + .paletteTag = TAG_HEAD_MALE, .oam = &gOamData_AffineOff_ObjNormal_16x16, - .anims = sSpriteAnimTable_8571574, + .anims = sAnims_TwoFrame, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCb_Dummy, + .callback = SpriteCB_PlayerHead, }; -static const u8 *const sPassAreaDescriptions[] = +static const u8 *const sPassAreaDescriptions[CURSOR_AREA_COUNT + 1] = { - gText_ThereIsNoBattleRecord, - gText_CheckFrontierMap, - gText_CheckTrainerCard, - gText_ViewRecordedBattle, - gText_PutAwayFrontierPass, - gText_CurrentBattlePoints, - gText_CollectedSymbols, - gText_BattleTowerAbilitySymbol, - gText_BattleDomeTacticsSymbol, - gText_BattlePalaceSpiritsSymbol, - gText_BattleArenaGutsSymbol, - gText_BattleFactoryKnowledgeSymbol, - gText_BattlePikeLuckSymbol, - gText_BattlePyramidBraveSymbol, - gText_EmptyString7, + [CURSOR_AREA_NOTHING] = gText_ThereIsNoBattleRecord, // NOTHING is re-used for CURSOR_AREA_RECORD when no Record is present + [CURSOR_AREA_MAP] = gText_CheckFrontierMap, + [CURSOR_AREA_CARD] = gText_CheckTrainerCard, + [CURSOR_AREA_RECORD] = gText_ViewRecordedBattle, + [CURSOR_AREA_CANCEL] = gText_PutAwayFrontierPass, + [CURSOR_AREA_POINTS] = gText_CurrentBattlePoints, + [CURSOR_AREA_EARNED_SYMBOLS] = gText_CollectedSymbols, + [CURSOR_AREA_SYMBOL_TOWER] = gText_BattleTowerAbilitySymbol, + [CURSOR_AREA_SYMBOL_DOME] = gText_BattleDomeTacticsSymbol, + [CURSOR_AREA_SYMBOL_PALACE] = gText_BattlePalaceSpiritsSymbol, + [CURSOR_AREA_SYMBOL_ARENA] = gText_BattleArenaGutsSymbol, + [CURSOR_AREA_SYMBOL_FACTORY] = gText_BattleFactoryKnowledgeSymbol, + [CURSOR_AREA_SYMBOL_PIKE] = gText_BattlePikeLuckSymbol, + [CURSOR_AREA_SYMBOL_PYRAMID] = gText_BattlePyramidBraveSymbol, + [CURSOR_AREA_COUNT] = gText_EmptyString7, }; struct @@ -507,18 +543,17 @@ struct s16 x; s16 y; u8 animNum; -} static const sMapLandmarks[] = +} static const sMapLandmarks[NUM_FRONTIER_FACILITIES] = { - {gText_BattleTower3, gText_BattleTowerDesc, 0x59, 0x28, 1}, - {gText_BattleDome2, gText_BattleDomeDesc, 0x21, 0x2A, 1}, - {gText_BattlePalace2, gText_BattlePalaceDesc, 0x78, 0x56, 0}, - {gText_BattleArena2, gText_BattleArenaDesc, 0x72, 0x3B, 0}, - {gText_BattleFactory2, gText_BattleFactoryDesc, 0x19, 0x43, 0}, - {gText_BattlePike2, gText_BattlePikeDesc, 0x39, 0x39, 1}, - {gText_BattlePyramid2, gText_BattlePyramidDesc, 0x86, 0x29, 1}, + [FRONTIER_FACILITY_TOWER] = {gText_BattleTower3, gText_BattleTowerDesc, 89, 40, MAP_INDICATOR_SQUARE}, + [FRONTIER_FACILITY_DOME] = {gText_BattleDome2, gText_BattleDomeDesc, 33, 42, MAP_INDICATOR_SQUARE}, + [FRONTIER_FACILITY_PALACE] = {gText_BattlePalace2, gText_BattlePalaceDesc, 120, 86, MAP_INDICATOR_RECTANGLE}, + [FRONTIER_FACILITY_ARENA] = {gText_BattleArena2, gText_BattleArenaDesc, 114, 59, MAP_INDICATOR_RECTANGLE}, + [FRONTIER_FACILITY_FACTORY] = {gText_BattleFactory2, gText_BattleFactoryDesc, 25, 67, MAP_INDICATOR_RECTANGLE}, + [FRONTIER_FACILITY_PIKE] = {gText_BattlePike2, gText_BattlePikeDesc, 57, 57, MAP_INDICATOR_SQUARE}, + [FRONTIER_FACILITY_PYRAMID] = {gText_BattlePyramid2, gText_BattlePyramidDesc, 134, 41, MAP_INDICATOR_SQUARE}, }; -// code static void ResetGpuRegsAndBgs(void) { SetGpuReg(REG_OFFSET_DISPCNT, 0); @@ -564,30 +599,34 @@ static u32 AllocateFrontierPassData(void (*callback)(void)) u8 i; if (sPassData != NULL) - return 1; + return ERR_ALREADY_DONE; sPassData = AllocZeroed(sizeof(*sPassData)); if (sPassData == NULL) - return 2; + return ERR_ALLOC_FAILED; sPassData->callback = callback; i = GetCurrentRegionMapSectionId(); if (i != MAPSEC_BATTLE_FRONTIER && i != MAPSEC_ARTISAN_CAVE) { + // Player is not in the frontier, set + // cursor position to the Trainer Card sPassData->cursorX = 176; sPassData->cursorY = 104; } else { + // Player is in the frontier, set + // cursor position to the frontier map sPassData->cursorX = 176; sPassData->cursorY = 48; } sPassData->battlePoints = gSaveBlock2Ptr->frontier.battlePoints; sPassData->hasBattleRecord = CanCopyRecordedBattleSaveData(); - sPassData->unkE = 0; + sPassData->areaToShow = CURSOR_AREA_NOTHING; sPassData->trainerStars = CountPlayerTrainerStars(); - for (i = 0; i < 7; i++) + for (i = 0; i < NUM_FRONTIER_FACILITIES; i++) { if (FlagGet(FLAG_SYS_TOWER_SILVER + i * 2)) sPassData->facilitySymbols[i]++; @@ -595,60 +634,57 @@ static u32 AllocateFrontierPassData(void (*callback)(void)) sPassData->facilitySymbols[i]++; } - return 0; + return SUCCESS; } static u32 FreeFrontierPassData(void) { if (sPassData == NULL) - return 1; + return ERR_ALREADY_DONE; memset(sPassData, 0, sizeof(*sPassData)); // Why clear data, if it's going to be freed anyway? FREE_AND_SET_NULL(sPassData); - return 0; + return SUCCESS; } static u32 AllocateFrontierPassGfx(void) { if (sPassGfx != NULL) - return 1; + return ERR_ALREADY_DONE; sPassGfx = AllocZeroed(sizeof(*sPassGfx)); if (sPassGfx == NULL) - return 2; + return ERR_ALLOC_FAILED; - return 0; + return SUCCESS; } static u32 FreeFrontierPassGfx(void) { FreeAllWindowBuffers(); if (sPassGfx == NULL) - return 1; + return ERR_ALREADY_DONE; - if (sPassGfx->unk28 != NULL) - FREE_AND_SET_NULL(sPassGfx->unk28); - if (sPassGfx->unk24 != NULL) - FREE_AND_SET_NULL(sPassGfx->unk24); - if (sPassGfx->unk20 != NULL) - FREE_AND_SET_NULL(sPassGfx->unk20); + TRY_FREE_AND_SET_NULL(sPassGfx->battleRecordTilemap); + TRY_FREE_AND_SET_NULL(sPassGfx->mapAndCardTilemap); + TRY_FREE_AND_SET_NULL(sPassGfx->mapAndCardZoomTilemap); memset(sPassGfx, 0, sizeof(*sPassGfx)); // Why clear data, if it's going to be freed anyway? FREE_AND_SET_NULL(sPassGfx); - return 0; + return SUCCESS; } -static void VblankCb_FrontierPass(void) +static void VBlankCB_FrontierPass(void) { - if (sPassGfx->setAffine) + if (sPassGfx->zooming) { SetBgAffine(2, - gUnknown_085713E0[sPassData->unkE - 1][0] << 8, - gUnknown_085713E0[sPassData->unkE - 1][1] << 8, - gUnknown_085713E0[sPassData->unkE - 1][0], - gUnknown_085713E0[sPassData->unkE - 1][1], - sPassGfx->unk2E, - sPassGfx->unk30, + sBgAffineCoords[sPassData->areaToShow - 1][0] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][1] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][0], + sBgAffineCoords[sPassData->areaToShow - 1][1], + sPassGfx->scaleX, + sPassGfx->scaleY, 0); } LoadOam(); @@ -716,11 +752,11 @@ static bool32 InitFrontierPass(void) DeactivateAllTextPrinters(); break; case 6: - sPassGfx->unk20 = malloc_and_decompress(gUnknown_085712F8, &sizeOut); - sPassGfx->unk24 = malloc_and_decompress(gUnknown_08571060, &sizeOut); - sPassGfx->unk28 = malloc_and_decompress(gUnknown_085712C0, &sizeOut); - DecompressAndCopyTileDataToVram(1, gUnknown_08DE08C8, 0, 0, 0); - DecompressAndCopyTileDataToVram(2, gUnknown_08DE2084, 0, 0, 0); + sPassGfx->mapAndCardZoomTilemap = malloc_and_decompress(sMapAndCard_Zooming_Tilemap, &sizeOut); + sPassGfx->mapAndCardTilemap = malloc_and_decompress(sMapAndCard_ZoomedOut_Tilemap, &sizeOut); + sPassGfx->battleRecordTilemap = malloc_and_decompress(sBattleRecord_Tilemap, &sizeOut); + DecompressAndCopyTileDataToVram(1, gFrontierPassBg_Gfx, 0, 0, 0); + DecompressAndCopyTileDataToVram(2, gFrontierPassMapAndCard_Gfx, 0, 0, 0); break; case 7: if (FreeTempTileDataBuffersIfPossible()) @@ -733,12 +769,12 @@ static bool32 InitFrontierPass(void) CopyBgTilemapBufferToVram(2); break; case 8: - LoadPalette(gUnknown_08DE07C8[0], 0, 0x1A0); - LoadPalette(gUnknown_08DE07C8[1 + sPassData->trainerStars], 0x10, 0x20); + LoadPalette(gFrontierPassBg_Pal[0], 0, 0x1A0); + LoadPalette(gFrontierPassBg_Pal[1 + sPassData->trainerStars], 0x10, 0x20); LoadPalette(GetTextWindowPalette(0), 0xF0, 0x20); - sub_80C629C(); - sub_80C6104(sPassData->cursorArea, sPassData->previousCursorArea); - if (sPassData->unkE == 1 || sPassData->unkE == 2) + DrawFrontierPassBg(); + UpdateAreaHighlight(sPassData->cursorArea, sPassData->previousCursorArea); + if (sPassData->areaToShow == CURSOR_AREA_MAP || sPassData->areaToShow == CURSOR_AREA_CARD) { sPassData->state = 0; return TRUE; @@ -750,9 +786,9 @@ static bool32 InitFrontierPass(void) ShowBg(1); ShowBg(2); LoadCursorAndSymbolSprites(); - SetVBlankCallback(VblankCb_FrontierPass); - BlendPalettes(PALETTES_ALL, 0x10, RGB_BLACK); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK); + SetVBlankCallback(VBlankCB_FrontierPass); + BlendPalettes(PALETTES_ALL, 16, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); break; case 10: AnimateSprites(); @@ -773,9 +809,9 @@ static bool32 HideFrontierPass(void) switch (sPassData->state) { case 0: - if (sPassData->unkE != 1 && sPassData->unkE != 2) + if (sPassData->areaToShow != CURSOR_AREA_MAP && sPassData->areaToShow != CURSOR_AREA_CARD) { - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); } else { @@ -822,11 +858,11 @@ static u8 GetCursorAreaFromCoords(s16 x, s16 y) { u8 i; - // Minus/Plus 1, because the table doesn't take into account the nothing field. + // Minus/Plus 1, because the table doesn't take CURSOR_AREA_NOTHING into account. for (i = 0; i < CURSOR_AREA_COUNT - 1; i++) { if (sPassAreasLayout[i].yStart <= y && sPassAreasLayout[i].yEnd >= y - && sPassAreasLayout[i].xStart <= x && sPassAreasLayout[i].xEnd >= x) + && sPassAreasLayout[i].xStart <= x && sPassAreasLayout[i].xEnd >= x) { if (i >= CURSOR_AREA_SYMBOL - 1 && sPassData->facilitySymbols[i - CURSOR_AREA_SYMBOL + 1] == 0) break; @@ -835,9 +871,12 @@ static u8 GetCursorAreaFromCoords(s16 x, s16 y) } } - return 0; + return CURSOR_AREA_NOTHING; } +// For Task_PassAreaZoom +#define tZoomOut data[0] + void CB2_ReshowFrontierPass(void) { u8 taskId; @@ -845,16 +884,16 @@ void CB2_ReshowFrontierPass(void) if (!InitFrontierPass()) return; - switch (sPassData->unkE) + switch (sPassData->areaToShow) { - case 1: - case 2: - taskId = CreateTask(Task_DoFadeEffect, 0); - gTasks[taskId].data[0] = TRUE; + case CURSOR_AREA_MAP: + case CURSOR_AREA_CARD: + taskId = CreateTask(Task_PassAreaZoom, 0); + gTasks[taskId].tZoomOut = TRUE; break; - case 3: + case CURSOR_AREA_RECORD: default: - sPassData->unkE = 0; + sPassData->areaToShow = CURSOR_AREA_NOTHING; taskId = CreateTask(Task_HandleFrontierPassInput, 0); break; } @@ -889,19 +928,19 @@ static void CB2_ShowFrontierPassFeature(void) if (!HideFrontierPass()) return; - switch (sPassData->unkE) + switch (sPassData->areaToShow) { - case 1: + case CURSOR_AREA_MAP: ShowFrontierMap(CB2_ReshowFrontierPass); break; - case 3: + case CURSOR_AREA_RECORD: sSavedPassData.callback = sPassData->callback; sSavedPassData.cursorX = sPassData->cursorX; sSavedPassData.cursorY = sPassData->cursorY; FreeFrontierPassData(); PlayRecordedBattle(CB2_ReturnFromRecord); break; - case 2: + case CURSOR_AREA_CARD: ShowPlayerTrainerCard(CB2_ReshowFrontierPass); break; } @@ -914,15 +953,15 @@ static bool32 TryCallPassAreaFunction(u8 taskId, u8 cursorArea) case CURSOR_AREA_RECORD: if (!sPassData->hasBattleRecord) return FALSE; - sPassData->unkE = 3; + sPassData->areaToShow = CURSOR_AREA_RECORD; DestroyTask(taskId); SetMainCallback2(CB2_ShowFrontierPassFeature); break; case CURSOR_AREA_MAP: case CURSOR_AREA_CARD: - sPassData->unkE = cursorArea; - gTasks[taskId].func = Task_DoFadeEffect; - gTasks[taskId].data[0] = FALSE; + sPassData->areaToShow = cursorArea; + gTasks[taskId].func = Task_PassAreaZoom; + gTasks[taskId].tZoomOut = FALSE; break; default: return FALSE; @@ -1004,77 +1043,92 @@ static void Task_HandleFrontierPassInput(u8 taskId) PrintAreaDescription(var); sPassData->previousCursorArea = sPassData->cursorArea; sPassData->cursorArea = var; - sub_80C6104(sPassData->cursorArea, sPassData->previousCursorArea); + UpdateAreaHighlight(sPassData->cursorArea, sPassData->previousCursorArea); } } } -static void Task_DoFadeEffect(u8 taskId) +#define tScaleX data[1] +#define tScaleY data[2] +#define tScaleSpeedX data[3] +#define tScaleSpeedY data[4] + +// Zoom in/out for the Frontier map or the trainer card +static void Task_PassAreaZoom(u8 taskId) { s16 *data = gTasks[taskId].data; switch (sPassData->state) { case 0: - if (!data[0]) + // Initialize the zoom, start fading in/out + if (!tZoomOut) { - sub_80C5F58(TRUE, FALSE); - data[1] = Q_8_8(1); - data[2] = Q_8_8(1); - data[3] = 0x15; - data[4] = 0x15; - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_WHITE); + // Zooming in to map/card screen + ShowHideZoomingArea(TRUE, FALSE); + tScaleX = Q_8_8(1); + tScaleY = Q_8_8(1); + tScaleSpeedX = 0x15; + tScaleSpeedY = 0x15; + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_WHITE); } else { - data[1] = Q_8_8(1.984375); // 1 and 63/64 - data[2] = Q_8_8(1.984375); - data[3] = -0x15; - data[4] = -0x15; + // Zooming out of map/card screen back to frontier pass + tScaleX = Q_8_8(1.984375); // 1 and 63/64 + tScaleY = Q_8_8(1.984375); + tScaleSpeedX = -0x15; + tScaleSpeedY = -0x15; SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); ShowBg(0); ShowBg(1); ShowBg(2); LoadCursorAndSymbolSprites(); - SetVBlankCallback(VblankCb_FrontierPass); - BlendPalettes(PALETTES_ALL, 0x10, RGB_WHITE); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_WHITE); + SetVBlankCallback(VBlankCB_FrontierPass); + BlendPalettes(PALETTES_ALL, 16, RGB_WHITE); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_WHITE); } - sPassGfx->setAffine = TRUE; - sPassGfx->unk2E = MathUtil_Inv16(data[1]); - sPassGfx->unk30 = MathUtil_Inv16(data[2]); + sPassGfx->zooming = TRUE; + sPassGfx->scaleX = MathUtil_Inv16(tScaleX); + sPassGfx->scaleY = MathUtil_Inv16(tScaleY); break; case 1: + // Update the fade and zoom UpdatePaletteFade(); - data[1] += data[3]; - data[2] += data[4]; - sPassGfx->unk2E = MathUtil_Inv16(data[1]); - sPassGfx->unk30 = MathUtil_Inv16(data[2]); - if (!data[0]) + tScaleX += tScaleSpeedX; + tScaleY += tScaleSpeedY; + sPassGfx->scaleX = MathUtil_Inv16(tScaleX); + sPassGfx->scaleY = MathUtil_Inv16(tScaleY); + + // Check if zoom hasn't reached target + if (!tZoomOut) { - if (data[1] <= Q_8_8(1.984375)) + if (tScaleX <= Q_8_8(1.984375)) return; } else { - if (data[1] != Q_8_8(1)) + if (tScaleX != Q_8_8(1)) return; } break; case 2: - if (sPassGfx->setAffine) // Nonsensical check. - sPassGfx->setAffine = FALSE; + if (sPassGfx->zooming) + sPassGfx->zooming = FALSE; if (UpdatePaletteFade()) return; - if (!data[0]) + + if (!tZoomOut) { + // Zoomed in and faded out, switch to map or trainer card DestroyTask(taskId); SetMainCallback2(CB2_ShowFrontierPassFeature); } else { - sub_80C5F58(FALSE, FALSE); - sPassData->unkE = 0; + // Zoomed out and faded in, return to frontier pass + ShowHideZoomingArea(FALSE, FALSE); + sPassData->areaToShow = CURSOR_AREA_NOTHING; gTasks[taskId].func = Task_HandleFrontierPassInput; } SetBgAttribute(2, BG_ATTR_WRAPAROUND, 0); @@ -1120,8 +1174,9 @@ static void ShowAndPrintWindows(void) static void PrintAreaDescription(u8 cursorArea) { FillWindowPixelBuffer(WINDOW_DESCRIPTION, PIXEL_FILL(0)); + if (cursorArea == CURSOR_AREA_RECORD && !sPassData->hasBattleRecord) - AddTextPrinterParameterized3(WINDOW_DESCRIPTION, 1, 2, 0, sTextColors[1], 0, sPassAreaDescriptions[0]); + AddTextPrinterParameterized3(WINDOW_DESCRIPTION, 1, 2, 0, sTextColors[1], 0, sPassAreaDescriptions[CURSOR_AREA_NOTHING]); else if (cursorArea != CURSOR_AREA_NOTHING) AddTextPrinterParameterized3(WINDOW_DESCRIPTION, 1, 2, 0, sTextColors[1], 0, sPassAreaDescriptions[cursorArea]); @@ -1129,19 +1184,19 @@ static void PrintAreaDescription(u8 cursorArea) CopyBgTilemapBufferToVram(0); } -static void sub_80C5F58(bool8 arg0, bool8 arg1) +static void ShowHideZoomingArea(bool8 show, bool8 zoomedIn) { - switch (sPassData->unkE) + switch (sPassData->areaToShow) { - case 1: - if (arg0) - CopyToBgTilemapBufferRect_ChangePalette(2, sPassGfx->unk20, 16, 3, 12, 7, 16); + case CURSOR_AREA_MAP: + if (show) + CopyToBgTilemapBufferRect_ChangePalette(2, sPassGfx->mapAndCardZoomTilemap, 16, 3, 12, 7, 16); else FillBgTilemapBufferRect(2, 0, 16, 3, 12, 7, 16); break; - case 2: - if (arg0) - CopyToBgTilemapBufferRect_ChangePalette(2, sPassGfx->unk20 + 84, 16, 10, 12, 7, 16); + case CURSOR_AREA_CARD: + if (show) + CopyToBgTilemapBufferRect_ChangePalette(2, sPassGfx->mapAndCardZoomTilemap + 84, 16, 10, 12, 7, 16); else FillBgTilemapBufferRect(2, 0, 16, 10, 12, 7, 16); break; @@ -1150,13 +1205,13 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) } CopyBgTilemapBufferToVram(2); - if (arg1) + if (zoomedIn) { SetBgAffine(2, - gUnknown_085713E0[sPassData->unkE - 1][0] << 8, - gUnknown_085713E0[sPassData->unkE - 1][1] << 8, - gUnknown_085713E0[sPassData->unkE - 1][0], - gUnknown_085713E0[sPassData->unkE - 1][1], + sBgAffineCoords[sPassData->areaToShow - 1][0] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][1] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][0], + sBgAffineCoords[sPassData->areaToShow - 1][1], MathUtil_Inv16(Q_8_8(1.984375)), // 1 and 63/64 MathUtil_Inv16(Q_8_8(1.984375)), 0); @@ -1164,71 +1219,75 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) else { SetBgAffine(2, - gUnknown_085713E0[sPassData->unkE - 1][0] << 8, - gUnknown_085713E0[sPassData->unkE - 1][1] << 8, - gUnknown_085713E0[sPassData->unkE - 1][0], - gUnknown_085713E0[sPassData->unkE - 1][1], + sBgAffineCoords[sPassData->areaToShow - 1][0] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][1] << 8, + sBgAffineCoords[sPassData->areaToShow - 1][0], + sBgAffineCoords[sPassData->areaToShow - 1][1], MathUtil_Inv16(Q_8_8(1)), MathUtil_Inv16(Q_8_8(1)), 0); } } -static void sub_80C6104(u8 cursorArea, u8 previousCursorArea) +static void UpdateAreaHighlight(u8 cursorArea, u8 previousCursorArea) { + #define NON_HIGHLIGHT_AREA(area)((area) == CURSOR_AREA_NOTHING || (area) > CURSOR_AREA_CANCEL) + + // If moving off highlightable area, unhighlight it switch (previousCursorArea) { case CURSOR_AREA_MAP: - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24, 16, 3, 12, 7, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->mapAndCardTilemap, 16, 3, 12, 7, 17); break; case CURSOR_AREA_CARD: - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24 + 336, 16, 10, 12, 7, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->mapAndCardTilemap + 336, 16, 10, 12, 7, 17); break; case CURSOR_AREA_RECORD: if (sPassData->hasBattleRecord) - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk28, 2, 10, 12, 3, 17); - else if (cursorArea == CURSOR_AREA_NOTHING || cursorArea > CURSOR_AREA_CANCEL) + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->battleRecordTilemap, 2, 10, 12, 3, 17); + else if (NON_HIGHLIGHT_AREA(cursorArea)) return; break; case CURSOR_AREA_CANCEL: - CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3350, 21, 0, 9, 2, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, gFrontierPassCancelButton_Tilemap, 21, 0, 9, 2, 17); break; default: - if (cursorArea == CURSOR_AREA_NOTHING || cursorArea > CURSOR_AREA_CANCEL) + if (NON_HIGHLIGHT_AREA(cursorArea)) return; break; } + // If moving on to highlightable area, highlight it switch (cursorArea) { case CURSOR_AREA_MAP: - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24 + 168, 16, 3, 12, 7, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->mapAndCardTilemap + 168, 16, 3, 12, 7, 17); break; case CURSOR_AREA_CARD: - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24 + 504, 16, 10, 12, 7, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->mapAndCardTilemap + 504, 16, 10, 12, 7, 17); break; case CURSOR_AREA_RECORD: if (sPassData->hasBattleRecord) - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk28 + 72, 2, 10, 12, 3, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->battleRecordTilemap + 72, 2, 10, 12, 3, 17); else return; - break; //needed to match + break; case CURSOR_AREA_CANCEL: - CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3374, 21, 0, 9, 2, 17); + CopyToBgTilemapBufferRect_ChangePalette(1, gFrontierPassCancelButtonHighlighted_Tilemap, 21, 0, 9, 2, 17); break; default: - if (previousCursorArea == CURSOR_AREA_NOTHING || previousCursorArea > CURSOR_AREA_CANCEL) + if (NON_HIGHLIGHT_AREA(previousCursorArea)) return; } CopyBgTilemapBufferToVram(1); } -static void sub_80C629C(void) +static void DrawFrontierPassBg(void) { - CopyToBgTilemapBuffer(1, gUnknown_08DE3060, 0, 0); - sub_80C6104(sPassData->cursorArea, sPassData->previousCursorArea); - sub_80C5F58(TRUE, sPassData->unkE); + CopyToBgTilemapBuffer(1, gFrontierPassBg_Tilemap, 0, 0); + UpdateAreaHighlight(sPassData->cursorArea, sPassData->previousCursorArea); + ShowHideZoomingArea(TRUE, sPassData->areaToShow); // If returning to frontier pass from map/card (areaToShow will be != 0) ShowAndPrintWindows(); CopyBgTilemapBufferToVram(1); } @@ -1253,7 +1312,7 @@ static void LoadCursorAndSymbolSprites(void) { struct SpriteTemplate sprite = sSpriteTemplate_Medal; - sprite.paletteTag += sPassData->facilitySymbols[i] - 1; + sprite.paletteTag += sPassData->facilitySymbols[i] - 1; // Adds 1 if gold for TAG_MEDAL_GOLD spriteId = CreateSprite(&sprite, sPassAreasLayout[i + CURSOR_AREA_SYMBOL - 1].xStart + 8, sPassAreasLayout[i + CURSOR_AREA_SYMBOL - 1].yStart + 6, i + 1); sPassGfx->symbolSprites[i] = &gSprites[spriteId]; sPassGfx->symbolSprites[i]->oam.priority = 2; @@ -1277,11 +1336,11 @@ static void FreeCursorAndSymbolSprites(void) } } FreeAllSpritePalettes(); - FreeSpriteTilesByTag(2); - FreeSpriteTilesByTag(0); + FreeSpriteTilesByTag(TAG_MEDAL_SILVER); + FreeSpriteTilesByTag(TAG_CURSOR); } -static void SpriteCb_Dummy(struct Sprite *sprite) +static void SpriteCB_PlayerHead(struct Sprite *sprite) { } @@ -1349,14 +1408,14 @@ static bool32 InitFrontierMap(void) InitWindows(sMapWindowTemplates); DeactivateAllTextPrinters(); PrintOnFrontierMap(); - DecompressAndCopyTileDataToVram(1, gUnknown_0856FBBC, 0, 0, 0); + DecompressAndCopyTileDataToVram(1, sMapScreen_Gfx, 0, 0, 0); break; case 5: if (FreeTempTileDataBuffersIfPossible()) return FALSE; - LoadPalette(gUnknown_08DE07C8[0], 0, 0x1A0); + LoadPalette(gFrontierPassBg_Pal[0], 0, 0x1A0); LoadPalette(GetTextWindowPalette(0), 0xF0, 0x20); - CopyToBgTilemapBuffer(2, gUnknown_08570E00, 0, 0); + CopyToBgTilemapBuffer(2, sMapScreen_Tilemap, 0, 0); CopyBgTilemapBufferToVram(2); break; case 6: @@ -1365,9 +1424,9 @@ static bool32 InitFrontierMap(void) ShowBg(1); ShowBg(2); InitFrontierMapSprites(); - SetVBlankCallback(VblankCb_FrontierPass); - BlendPalettes(PALETTES_ALL, 0x10, RGB_WHITE); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_WHITE); + SetVBlankCallback(VBlankCB_FrontierPass); + BlendPalettes(PALETTES_ALL, 16, RGB_WHITE); + BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_WHITE); break; case 7: if (UpdatePaletteFade()) @@ -1385,7 +1444,7 @@ static bool32 ExitFrontierMap(void) switch (sPassData->state) { case 0: - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_WHITE); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_WHITE); break; case 1: if (UpdatePaletteFade()) @@ -1404,17 +1463,17 @@ static bool32 ExitFrontierMap(void) if (sMapData->cursorSprite != NULL) { DestroySprite(sMapData->cursorSprite); - FreeSpriteTilesByTag(0); + FreeSpriteTilesByTag(TAG_CURSOR); } if (sMapData->mapIndicatorSprite != NULL) { DestroySprite(sMapData->mapIndicatorSprite); - FreeSpriteTilesByTag(1); + FreeSpriteTilesByTag(TAG_MAP_INDICATOR); } if (sMapData->playerHeadSprite != NULL) { DestroySprite(sMapData->playerHeadSprite); - FreeSpriteTilesByTag(4); + FreeSpriteTilesByTag(TAG_HEAD_MALE); } FreeAllWindowBuffers(); break; @@ -1435,11 +1494,14 @@ static bool32 ExitFrontierMap(void) return FALSE; } +#define tState data[0] +#define tMoveSteps data[1] + static void Task_HandleFrontierMap(u8 taskId) { s16 *data = gTasks[taskId].data; - switch (data[0]) + switch (tState) { case 0: if (InitFrontierMap()) @@ -1449,47 +1511,47 @@ static void Task_HandleFrontierMap(u8 taskId) if (JOY_NEW(B_BUTTON)) { PlaySE(SE_PC_OFF); - data[0] = 4; + tState = 4; } else if (JOY_NEW(DPAD_DOWN)) { if (sMapData->cursorPos >= NUM_FRONTIER_FACILITIES - 1) HandleFrontierMapCursorMove(0); else - data[0] = 2; + tState = 2; } else if (JOY_NEW(DPAD_UP)) { if (sMapData->cursorPos == 0) HandleFrontierMapCursorMove(1); else - data[0] = 3; + tState = 3; } return; case 2: - if (data[1] > 3) + if (tMoveSteps > 3) { HandleFrontierMapCursorMove(0); - data[1] = 0; - data[0] = 1; + tMoveSteps = 0; + tState = 1; } else { sMapData->cursorSprite->y += 4; - data[1]++; + tMoveSteps++; } return; case 3: - if (data[1] > 3) + if (tMoveSteps > 3) { HandleFrontierMapCursorMove(1); - data[1] = 0; - data[0] = 1; + tMoveSteps = 0; + tState = 1; } else { sMapData->cursorSprite->y -= 4; - data[1]++; + tMoveSteps++; } return; case 4: @@ -1502,31 +1564,42 @@ static void Task_HandleFrontierMap(u8 taskId) return; } - data[0]++; + tState++; } static u8 MapNumToFrontierFacilityId(u16 mapNum) // id + 1, zero means not a frontier map number { + // In Battle Tower if ((mapNum >= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_LOBBY) && mapNum <= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_BATTLE_ROOM)) - || (mapNum >= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_MULTI_PARTNER_ROOM) && mapNum <= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_MULTI_BATTLE_ROOM))) + || (mapNum >= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_MULTI_PARTNER_ROOM) && mapNum <= MAP_NUM(BATTLE_FRONTIER_BATTLE_TOWER_MULTI_BATTLE_ROOM))) return FRONTIER_FACILITY_TOWER + 1; + + // In Battle Dome else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_DOME_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_DOME_CORRIDOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_DOME_PRE_BATTLE_ROOM) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_DOME_BATTLE_ROOM)) return FRONTIER_FACILITY_DOME + 1; + + // In Battle Palace else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PALACE_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PALACE_CORRIDOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PALACE_BATTLE_ROOM)) return FRONTIER_FACILITY_PALACE + 1; + + // In Battle Arena else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_ARENA_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_ARENA_CORRIDOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_ARENA_BATTLE_ROOM)) return FRONTIER_FACILITY_ARENA + 1; + + // In Battle Factory else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_FACTORY_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_FACTORY_PRE_BATTLE_ROOM) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_FACTORY_BATTLE_ROOM)) return FRONTIER_FACILITY_FACTORY + 1; + + // In Battle Pike else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_CORRIDOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_THREE_PATH_ROOM) @@ -1534,10 +1607,13 @@ static u8 MapNumToFrontierFacilityId(u16 mapNum) // id + 1, zero means not a fro || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_ROOM_FINAL) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PIKE_ROOM_WILD_MONS)) return FRONTIER_FACILITY_PIKE + 1; + + // In Battle Pyramid else if (mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PYRAMID_LOBBY) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PYRAMID_FLOOR) || mapNum == MAP_NUM(BATTLE_FRONTIER_BATTLE_PYRAMID_TOP)) return FRONTIER_FACILITY_PYRAMID + 1; + else return 0; } @@ -1606,8 +1682,8 @@ static void InitFrontierMapSprites(void) } LoadCompressedSpriteSheet(sHeadsSpriteSheet); - sprite = sSpriteTemplate_Head; - sprite.paletteTag = gSaveBlock2Ptr->playerGender + 4; + sprite = sSpriteTemplate_PlayerHead; + sprite.paletteTag = gSaveBlock2Ptr->playerGender + TAG_HEAD_MALE; // TAG_HEAD_FEMALE if gender is FEMALE if (id != 0) { spriteId = CreateSprite(&sprite, x, y, 0); @@ -1678,7 +1754,7 @@ static void HandleFrontierMapCursorMove(u8 direction) FillWindowPixelBuffer(MAP_WINDOW_DESCRIPTION, PIXEL_FILL(0)); AddTextPrinterParameterized3(MAP_WINDOW_DESCRIPTION, 1, 4, 0, sTextColors[0], 0, sMapLandmarks[sMapData->cursorPos].description); - for (i = 0; i < 3; i++) + for (i = 0; i < MAP_WINDOW_COUNT; i++) CopyWindowToVram(i, 3); CopyBgTilemapBufferToVram(0); diff --git a/src/graphics.c b/src/graphics.c index e1381a284..4c648a479 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -2049,14 +2049,12 @@ const u32 gTitleScreenPressStartGfx[] = INCBIN_U32("graphics/title_screen/press_ const u32 gUnknown_08DE0644[] = INCBIN_U32("graphics/title_screen/title_screen2.bin.lz"); -// more trainer card stuff - -const u16 gUnknown_08DE07C8[][16] = INCBIN_U16("graphics/frontier_pass/tiles.gbapal");// size in LoadPalette calls is reported as 0xD0 << 1, which is 0x1A0, but palette is only 0x100 bytes long so it loads garbage as well -const u32 gUnknown_08DE08C8[] = INCBIN_U32("graphics/frontier_pass/tiles.4bpp.lz"); -const u32 gUnknown_08DE2084[] = INCBIN_U32("graphics/frontier_pass/tiles2.8bpp.lz"); -const u32 gUnknown_08DE3060[] = INCBIN_U32("graphics/frontier_pass/tiles.bin.lz"); -const u16 gUnknown_08DE3350[] = INCBIN_U16("graphics/frontier_pass/tilemap1.bin"); -const u16 gUnknown_08DE3374[] = INCBIN_U16("graphics/frontier_pass/tilemap2.bin"); +const u16 gFrontierPassBg_Pal[][16] = INCBIN_U16("graphics/frontier_pass/bg.gbapal");// size in LoadPalette calls is reported as 0xD0 << 1, which is 0x1A0, but palette is only 0x100 bytes long so it loads garbage as well +const u32 gFrontierPassBg_Gfx[] = INCBIN_U32("graphics/frontier_pass/bg.4bpp.lz"); +const u32 gFrontierPassMapAndCard_Gfx[] = INCBIN_U32("graphics/frontier_pass/map_and_card.8bpp.lz"); +const u32 gFrontierPassBg_Tilemap[] = INCBIN_U32("graphics/frontier_pass/bg.bin.lz"); +const u16 gFrontierPassCancelButton_Tilemap[] = INCBIN_U16("graphics/frontier_pass/cancel.bin"); +const u16 gFrontierPassCancelButtonHighlighted_Tilemap[] = INCBIN_U16("graphics/frontier_pass/cancel_highlighted.bin"); // Berry Crush const u16 gBerryCrush_Crusher_Pal[] = INCBIN_U16("graphics/berry_crush/crusher.gbapal"); diff --git a/src/international_string_util.c b/src/international_string_util.c index ab812de89..eb2ec16e7 100644 --- a/src/international_string_util.c +++ b/src/international_string_util.c @@ -34,11 +34,11 @@ int GetStringWidthDifference(int fontId, const u8 *str, int totalWidth, int lett return 0; } -int GetMaxWidthInMenuTable(const struct MenuAction *str, int arg1) +int GetMaxWidthInMenuTable(const struct MenuAction *str, int numActions) { int i, var; - for (var = 0, i = 0; i < arg1; i++) + for (var = 0, i = 0; i < numActions; i++) { int stringWidth = GetStringWidth(1, str[i].text, 0); if (stringWidth > var) diff --git a/src/item_menu.c b/src/item_menu.c index 39abf883a..9cc02e8cc 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -7,12 +7,11 @@ #include "battle_pyramid_bag.h" #include "berry_tag_screen.h" #include "bg.h" -#include "constants/items.h" -#include "constants/songs.h" #include "data.h" #include "decompress.h" #include "event_data.h" #include "event_object_movement.h" +#include "event_scripts.h" #include "field_player_avatar.h" #include "field_specials.h" #include "graphics.h" @@ -49,113 +48,168 @@ #include "window.h" #include "apprentice.h" #include "battle_pike.h" +#include "constants/items.h" #include "constants/rgb.h" +#include "constants/songs.h" -enum -{ +#define TAG_POCKET_SCROLL_ARROW 110 +#define TAG_BAG_SCROLL_ARROW 111 + +// The buffer for the bag item list needs to be large enough to hold the maximum +// number of item slots that could fit in a single pocket, + 1 for Cancel. +// This constant picks the max of the existing pocket sizes. +// By default, the largest pocket is BAG_TMHM_COUNT at 64. +#define MAX_POCKET_ITEMS ((max(BAG_TMHM_COUNT, \ + max(BAG_BERRIES_COUNT, \ + max(BAG_ITEMS_COUNT, \ + max(BAG_KEYITEMS_COUNT, \ + BAG_POKEBALLS_COUNT))))) + 1) + +// Up to 8 item slots can be visible at a time +#define MAX_ITEMS_SHOWN 8 + +enum { SWITCH_POCKET_NONE, SWITCH_POCKET_LEFT, SWITCH_POCKET_RIGHT }; -void GoToBagMenu(u8 bagMenuType, u8 pocketId, void (*postExitMenuMainCallback2)()); -void CB2_Bag(void); -bool8 SetupBagMenu(void); -void BagMenu_InitBGs(void); -bool8 LoadBagMenu_Graphics(void); -void SetupBagMenu_Textboxes(void); -void AllocateBagItemListBuffers(void); -void LoadBagItemListBuffers(u8); -void BagMenu_PrintPocketNames(const u8*, const u8*); -void BagMenu_CopyPocketNameToWindow(u32); -static void DrawPocketIndicatorSquare(u8 x, bool8 isCurrentPocket); -void CreatePocketScrollArrowPair(void); -void CreatePocketSwitchArrowPair(void); -void BagMenu_PrepareTMHMMoveWindow(void); -bool8 IsWallysBag(void); -void Task_WallyTutorialBagMenu(u8); -void Task_BagMenu_HandleInput(u8); -void GetItemName(s8*, u16); -u16 ItemIdToBattleMoveId(u16); -u16 BagGetItemIdByPocketPosition(u8, u16); -void BagMenu_PrintDescription(int); -void BagMenu_PrintCursor(u8, u8); -void BagMenu_Print(u8, u8, const u8*, u8, u8, u8, u8, u8, u8); -bool8 ItemId_GetImportance(u16); -u16 BagGetQuantityByPocketPosition(u8, u16); -void BagDestroyPocketSwitchArrowPair(void); -void TaskCloseBagMenu_2(u8); -u8 AddItemMessageWindow(u8); -void BagMenu_RemoveBagItemMessageWindow(u8); -void set_callback3_to_bag(u8); -void PrintItemDepositAmount(u8, s16); +enum { + ACTION_USE, + ACTION_TOSS, + ACTION_REGISTER, + ACTION_GIVE, + ACTION_CANCEL, + ACTION_BATTLE_USE, + ACTION_CHECK, + ACTION_WALK, + ACTION_DESELECT, + ACTION_CHECK_TAG, + ACTION_CONFIRM, + ACTION_SHOW, + ACTION_GIVE_FAVOR_LADY, + ACTION_CONFIRM_QUIZ_LADY, + ACTION_DUMMY, +}; + +enum { + WIN_ITEM_LIST, + WIN_DESCRIPTION, + WIN_POCKET_NAME, + WIN_TMHM_INFO_ICONS, + WIN_TMHM_INFO, + WIN_MESSAGE, // Identical to ITEMWIN_MESSAGE. Unused? +}; + +// Item list ID for toSwapPos to indicate an item is not currently being swapped +#define NOT_SWAPPING 0xFF + +struct ListBuffer1 { + struct ListMenuItem subBuffers[MAX_POCKET_ITEMS]; +}; + +struct ListBuffer2 { + s8 name[MAX_POCKET_ITEMS][ITEM_NAME_LENGTH + 10]; +}; + +struct TempWallyBag { + struct ItemSlot bagPocket_Items[BAG_ITEMS_COUNT]; + struct ItemSlot bagPocket_PokeBalls[BAG_POKEBALLS_COUNT]; + u16 cursorPosition[POCKETS_COUNT]; + u16 scrollPosition[POCKETS_COUNT]; + u16 unused; + u16 pocket; +}; + +static void CB2_Bag(void); +static bool8 SetupBagMenu(void); +static void BagMenu_InitBGs(void); +static bool8 LoadBagMenu_Graphics(void); +static void LoadBagMenuTextWindows(void); +static void AllocateBagItemListBuffers(void); +static void LoadBagItemListBuffers(u8); +static void PrintPocketNames(const u8*, const u8*); +static void CopyPocketNameToWindow(u32); +static void DrawPocketIndicatorSquare(u8, bool8); +static void CreatePocketScrollArrowPair(void); +static void CreatePocketSwitchArrowPair(void); +static void DestroyPocketSwitchArrowPair(void); +static void PrepareTMHMMoveWindow(void); +static bool8 IsWallysBag(void); +static void Task_WallyTutorialBagMenu(u8); +static void Task_BagMenu_HandleInput(u8); +static void GetItemName(s8*, u16); +static void PrintItemDescription(int); +static void BagMenu_PrintCursorAtPos(u8, u8); +static void BagMenu_Print(u8, u8, const u8*, u8, u8, u8, u8, u8, u8); +static void Task_CloseBagMenu(u8); +static u8 AddItemMessageWindow(u8); +static void RemoveItemMessageWindow(u8); +static void ReturnToItemList(u8); +static void PrintItemQuantity(u8, s16); static u8 BagMenu_AddWindow(u8); static u8 GetSwitchBagPocketDirection(void); -static void SwitchBagPocket(u8, s16, u16); +static void SwitchBagPocket(u8, s16, bool16); static bool8 CanSwapItems(void); -static void BagMenu_SwapItems(u8 taskId); -static void sub_81AC10C(u8); +static void StartItemSwap(u8 taskId); +static void Task_SwitchBagPocket(u8); static void Task_HandleSwappingItemsInput(u8); -void sub_81AC498(u8); -void sub_81AC590(u8); -void PrintTMHMMoveData(u16); -void sub_81ACAF8(u8); -void sub_81ACB54(u8, u8, u8); -void Task_HandleInBattleItemMenuInput(u8); -void Task_HandleOutOfBattleItemMenuInput(u8); -bool8 sub_81ACDFC(s8); -void BagMenu_RemoveWindow(u8); -void BagMenu_PrintThereIsNoPokemon(u8); -void Task_ChooseHowManyToToss(u8); -void BagMenu_TossItems(u8); -void BagMenu_YesNo(u8, u8, const struct YesNoFuncTable*); -void Task_ActuallyToss(u8); -void ItemMenu_Cancel(u8); -void sub_81AD350(u8); -static void BagMenu_PrintItemCantBeHeld(u8); +static void DoItemSwap(u8); +static void CancelItemSwap(u8); +static void PrintTMHMMoveData(u16); +static void PrintContextMenuItems(u8); +static void PrintContextMenuItemGrid(u8, u8, u8); +static void Task_ItemContext_SingleRow(u8); +static void Task_ItemContext_MultipleRows(u8); +static bool8 IsValidContextMenuPos(s8); +static void BagMenu_RemoveWindow(u8); +static void PrintThereIsNoPokemon(u8); +static void Task_ChooseHowManyToToss(u8); +static void AskTossItems(u8); +static void Task_RemoveItemFromBag(u8); +static void ItemMenu_Cancel(u8); +static void HandleErrorMessage(u8); +static void PrintItemCantBeHeld(u8); static void DisplayCurrentMoneyWindow(void); static void DisplaySellItemPriceAndConfirm(u8); -void sub_81AD730(u8); -void sub_81AD6E4(u8); +static void InitSellHowManyInput(u8); +static void AskSellItems(u8); static void RemoveMoneyWindow(void); -static void Task_SellHowManyDialogueHandleInput(u8); -static void BagMenu_Sell_UpdateItemListAndMoney(u8); -static void BagMenu_Sell_WaitForABPress(u8); -static void BagMenu_TryDepositItem(u8); +static void Task_ChooseHowManyToSell(u8); +static void SellItem(u8); +static void WaitAfterItemSell(u8); +static void TryDepositItem(u8); static void Task_ChooseHowManyToDeposit(u8 taskId); -static void BagMenu_Deposit_WaitForABPress(u8); -void CB2_ApprenticeExitBagMenu(void); -void CB2_FavorLadyExitBagMenu(void); -void CB2_QuizLadyExitBagMenu(void); -void All_CalculateNItemsAndMaxShowed(void); -static void SetPocketListPositions(void); -void UpdatePocketScrollPositions(void); -u8 CreateBagInputHandlerTask(u8); -void sub_81AC23C(u8); -void BagMenu_MoveCursorCallback(s32 a, bool8 b, struct ListMenu*); -void BagMenu_ItemPrintCallback(u8 windowId, u32 itemIndex, u8 a); -void ItemMenu_UseOutOfBattle(u8 taskId); -void ItemMenu_Toss(u8 taskId); -void ItemMenu_Register(u8 taskId); -void ItemMenu_Give(u8 taskId); -void ItemMenu_Cancel(u8 taskId); -void ItemMenu_UseInBattle(u8 taskId); -void ItemMenu_CheckTag(u8 taskId); -void Task_FadeAndCloseBagMenu(u8 taskId); -void unknown_ItemMenu_Show(u8 taskId); -void unknown_ItemMenu_Give2(u8 taskId); -void unknown_ItemMenu_Confirm2(u8 taskId); -void Task_ItemContext_FieldOrBattle(u8 taskId); -void Task_ItemContext_FieldGive(u8 taskId); -void Task_ItemContext_Sell(u8 taskId); -void Task_ItemContext_Deposit(u8 taskId); -void Task_ItemContext_ItemPC_2(u8 taskId); -void BagMenu_ConfirmToss(u8 taskId); -void BagMenu_CancelToss(u8 taskId); -void BagMenu_ConfirmSell(u8 taskId); -void BagMenu_CancelSell(u8 taskId); - -// .rodata +static void WaitDepositErrorMessage(u8); +static void CB2_ApprenticeExitBagMenu(void); +static void CB2_FavorLadyExitBagMenu(void); +static void CB2_QuizLadyExitBagMenu(void); +static void UpdatePocketItemLists(void); +static void InitPocketListPositions(void); +static void InitPocketScrollPositions(void); +static u8 CreateBagInputHandlerTask(u8); +static void DrawItemListBgRow(u8); +static void BagMenu_MoveCursorCallback(s32, bool8, struct ListMenu*); +static void BagMenu_ItemPrintCallback(u8, u32, u8); +static void ItemMenu_UseOutOfBattle(u8); +static void ItemMenu_Toss(u8); +static void ItemMenu_Register(u8); +static void ItemMenu_Give(u8); +static void ItemMenu_Cancel(u8); +static void ItemMenu_UseInBattle(u8); +static void ItemMenu_CheckTag(u8); +static void ItemMenu_Show(u8); +static void ItemMenu_GiveFavorLady(u8); +static void ItemMenu_ConfirmQuizLady(u8); +static void Task_ItemContext_Normal(u8); +static void Task_ItemContext_GiveToParty(u8); +static void Task_ItemContext_Sell(u8); +static void Task_ItemContext_Deposit(u8); +static void Task_ItemContext_GiveToPC(u8); +static void ConfirmToss(u8); +static void CancelToss(u8); +static void ConfirmSell(u8); +static void CancelSell(u8); static const struct BgTemplate sBgTemplates_ItemMenu[] = { @@ -211,98 +265,98 @@ static const struct ListMenuTemplate sItemListMenu = }; static const struct MenuAction sItemMenuActions[] = { - [ITEMMENUACTION_USE] = {gMenuText_Use, ItemMenu_UseOutOfBattle}, - [ITEMMENUACTION_TOSS] = {gMenuText_Toss, ItemMenu_Toss}, - [ITEMMENUACTION_REGISTER] = {gMenuText_Register, ItemMenu_Register}, - [ITEMMENUACTION_GIVE] = {gMenuText_Give, ItemMenu_Give}, - [ITEMMENUACTION_CANCEL] = {gText_Cancel2, ItemMenu_Cancel}, - [ITEMMENUACTION_BATTLE_USE] = {gMenuText_Use, ItemMenu_UseInBattle}, - [ITEMMENUACTION_CHECK] = {gMenuText_Check, ItemMenu_UseOutOfBattle}, - [ITEMMENUACTION_WALK] = {gMenuText_Walk, ItemMenu_UseOutOfBattle}, - [ITEMMENUACTION_DESELECT] = {gMenuText_Deselect, ItemMenu_Register}, - [ITEMMENUACTION_CHECK_TAG] = {gMenuText_CheckTag, ItemMenu_CheckTag}, - [ITEMMENUACTION_CONFIRM] = {gMenuText_Confirm, Task_FadeAndCloseBagMenu}, - [ITEMMENUACTION_SHOW] = {gMenuText_Show, unknown_ItemMenu_Show}, - [ITEMMENUACTION_GIVE_2] = {gMenuText_Give2, unknown_ItemMenu_Give2}, - [ITEMMENUACTION_CONFIRM_2] = {gMenuText_Confirm, unknown_ItemMenu_Confirm2}, - [ITEMMENUACTION_DUMMY] = {gText_EmptyString2, NULL} + [ACTION_USE] = {gMenuText_Use, ItemMenu_UseOutOfBattle}, + [ACTION_TOSS] = {gMenuText_Toss, ItemMenu_Toss}, + [ACTION_REGISTER] = {gMenuText_Register, ItemMenu_Register}, + [ACTION_GIVE] = {gMenuText_Give, ItemMenu_Give}, + [ACTION_CANCEL] = {gText_Cancel2, ItemMenu_Cancel}, + [ACTION_BATTLE_USE] = {gMenuText_Use, ItemMenu_UseInBattle}, + [ACTION_CHECK] = {gMenuText_Check, ItemMenu_UseOutOfBattle}, + [ACTION_WALK] = {gMenuText_Walk, ItemMenu_UseOutOfBattle}, + [ACTION_DESELECT] = {gMenuText_Deselect, ItemMenu_Register}, + [ACTION_CHECK_TAG] = {gMenuText_CheckTag, ItemMenu_CheckTag}, + [ACTION_CONFIRM] = {gMenuText_Confirm, Task_FadeAndCloseBagMenu}, + [ACTION_SHOW] = {gMenuText_Show, ItemMenu_Show}, + [ACTION_GIVE_FAVOR_LADY] = {gMenuText_Give2, ItemMenu_GiveFavorLady}, + [ACTION_CONFIRM_QUIZ_LADY] = {gMenuText_Confirm, ItemMenu_ConfirmQuizLady}, + [ACTION_DUMMY] = {gText_EmptyString2, NULL} }; // these are all 2D arrays with a width of 2 but are represented as 1D arrays -// ITEMMENUACTION_DUMMY is used to represent blank spaces +// ACTION_DUMMY is used to represent blank spaces static const u8 sContextMenuItems_ItemsPocket[] = { - ITEMMENUACTION_USE, ITEMMENUACTION_GIVE, - ITEMMENUACTION_TOSS, ITEMMENUACTION_CANCEL + ACTION_USE, ACTION_GIVE, + ACTION_TOSS, ACTION_CANCEL }; static const u8 sContextMenuItems_KeyItemsPocket[] = { - ITEMMENUACTION_USE, ITEMMENUACTION_REGISTER, - ITEMMENUACTION_DUMMY, ITEMMENUACTION_CANCEL + ACTION_USE, ACTION_REGISTER, + ACTION_DUMMY, ACTION_CANCEL }; static const u8 sContextMenuItems_BallsPocket[] = { - ITEMMENUACTION_GIVE, ITEMMENUACTION_DUMMY, - ITEMMENUACTION_TOSS, ITEMMENUACTION_CANCEL + ACTION_GIVE, ACTION_DUMMY, + ACTION_TOSS, ACTION_CANCEL }; static const u8 sContextMenuItems_TmHmPocket[] = { - ITEMMENUACTION_USE, ITEMMENUACTION_GIVE, - ITEMMENUACTION_DUMMY, ITEMMENUACTION_CANCEL + ACTION_USE, ACTION_GIVE, + ACTION_DUMMY, ACTION_CANCEL }; static const u8 sContextMenuItems_BerriesPocket[] = { - ITEMMENUACTION_CHECK_TAG, ITEMMENUACTION_DUMMY, - ITEMMENUACTION_USE, ITEMMENUACTION_GIVE, - ITEMMENUACTION_TOSS, ITEMMENUACTION_CANCEL + ACTION_CHECK_TAG, ACTION_DUMMY, + ACTION_USE, ACTION_GIVE, + ACTION_TOSS, ACTION_CANCEL }; static const u8 sContextMenuItems_BattleUse[] = { - ITEMMENUACTION_BATTLE_USE, ITEMMENUACTION_CANCEL + ACTION_BATTLE_USE, ACTION_CANCEL }; static const u8 sContextMenuItems_Give[] = { - ITEMMENUACTION_GIVE, ITEMMENUACTION_CANCEL + ACTION_GIVE, ACTION_CANCEL }; static const u8 sContextMenuItems_Cancel[] = { - ITEMMENUACTION_CANCEL + ACTION_CANCEL }; static const u8 sContextMenuItems_BerryBlenderCrush[] = { - ITEMMENUACTION_CONFIRM, ITEMMENUACTION_CHECK_TAG, - ITEMMENUACTION_DUMMY, ITEMMENUACTION_CANCEL + ACTION_CONFIRM, ACTION_CHECK_TAG, + ACTION_DUMMY, ACTION_CANCEL }; static const u8 sContextMenuItems_Apprentice[] = { - ITEMMENUACTION_SHOW, ITEMMENUACTION_CANCEL + ACTION_SHOW, ACTION_CANCEL }; static const u8 sContextMenuItems_FavorLady[] = { - ITEMMENUACTION_GIVE_2, ITEMMENUACTION_CANCEL + ACTION_GIVE_FAVOR_LADY, ACTION_CANCEL }; static const u8 sContextMenuItems_QuizLady[] = { - ITEMMENUACTION_CONFIRM_2, ITEMMENUACTION_CANCEL + ACTION_CONFIRM_QUIZ_LADY, ACTION_CANCEL }; -static const TaskFunc gUnknown_08614054[] = { - [ITEMMENULOCATION_FIELD] = Task_ItemContext_FieldOrBattle, - [ITEMMENULOCATION_BATTLE] = Task_ItemContext_FieldOrBattle, - [ITEMMENULOCATION_PARTY] = Task_ItemContext_FieldGive, +static const TaskFunc sContextMenuFuncs[] = { + [ITEMMENULOCATION_FIELD] = Task_ItemContext_Normal, + [ITEMMENULOCATION_BATTLE] = Task_ItemContext_Normal, + [ITEMMENULOCATION_PARTY] = Task_ItemContext_GiveToParty, [ITEMMENULOCATION_SHOP] = Task_ItemContext_Sell, [ITEMMENULOCATION_BERRY_TREE] = Task_FadeAndCloseBagMenu, - [ITEMMENULOCATION_BERRY_BLENDER_CRUSH] = Task_ItemContext_FieldOrBattle, + [ITEMMENULOCATION_BERRY_BLENDER_CRUSH] = Task_ItemContext_Normal, [ITEMMENULOCATION_ITEMPC] = Task_ItemContext_Deposit, - [ITEMMENULOCATION_FAVOR_LADY] = Task_ItemContext_FieldOrBattle, - [ITEMMENULOCATION_QUIZ_LADY] = Task_ItemContext_FieldOrBattle, - [ITEMMENULOCATION_APPRENTICE] = Task_ItemContext_FieldOrBattle, + [ITEMMENULOCATION_FAVOR_LADY] = Task_ItemContext_Normal, + [ITEMMENULOCATION_QUIZ_LADY] = Task_ItemContext_Normal, + [ITEMMENULOCATION_APPRENTICE] = Task_ItemContext_Normal, [ITEMMENULOCATION_WALLY] = NULL, - [ITEMMENULOCATION_PCBOX] = Task_ItemContext_ItemPC_2 + [ITEMMENULOCATION_PCBOX] = Task_ItemContext_GiveToPC }; -static const struct YesNoFuncTable sYesNoTossFunctions = {BagMenu_ConfirmToss, BagMenu_CancelToss}; +static const struct YesNoFuncTable sYesNoTossFunctions = {ConfirmToss, CancelToss}; -static const struct YesNoFuncTable sYesNoSellItemFunctions = {BagMenu_ConfirmSell, BagMenu_CancelSell}; +static const struct YesNoFuncTable sYesNoSellItemFunctions = {ConfirmSell, CancelSell}; static const struct ScrollArrowsTemplate sBagScrollArrowsTemplate = { .firstArrowType = SCROLL_ARROW_LEFT, @@ -313,25 +367,33 @@ static const struct ScrollArrowsTemplate sBagScrollArrowsTemplate = { .secondY = 16, .fullyUpThreshold = -1, .fullyDownThreshold = -1, - .tileTag = 111, - .palTag = 111, + .tileTag = TAG_BAG_SCROLL_ARROW, + .palTag = TAG_BAG_SCROLL_ARROW, .palNum = 0, }; static const u8 sRegisteredSelect_Gfx[] = INCBIN_U8("graphics/interface/select_button.4bpp"); +enum { + COLORID_NORMAL, + COLORID_POCKET_NAME, + COLORID_GRAY_CURSOR, + COLORID_UNUSED, + COLORID_TMHM_INFO, + COLORID_NONE = 0xFF +}; static const u8 sFontColorTable[][3] = { -// bgColor, textColor, shadowColor - {0, 1, 3}, - {0, 1, 4}, - {0, 3, 6}, - {2, 1, 3}, - {0, 14, 10} + // bgColor, textColor, shadowColor + [COLORID_NORMAL] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY}, + [COLORID_POCKET_NAME] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_RED}, + [COLORID_GRAY_CURSOR] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_LIGHT_GRAY, TEXT_COLOR_GREEN}, + [COLORID_UNUSED] = {TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY}, + [COLORID_TMHM_INFO] = {TEXT_COLOR_TRANSPARENT, TEXT_DYNAMIC_COLOR_5, TEXT_DYNAMIC_COLOR_1} }; -const struct WindowTemplate sDefaultBagWindows[] = +static const struct WindowTemplate sDefaultBagWindows[] = { - { // Item names + [WIN_ITEM_LIST] = { .bg = 0, .tilemapLeft = 14, .tilemapTop = 2, @@ -340,7 +402,7 @@ const struct WindowTemplate sDefaultBagWindows[] = .paletteNum = 1, .baseBlock = 0x27, }, - { // Description + [WIN_DESCRIPTION] = { .bg = 0, .tilemapLeft = 0, .tilemapTop = 13, @@ -349,7 +411,7 @@ const struct WindowTemplate sDefaultBagWindows[] = .paletteNum = 1, .baseBlock = 0x117, }, - { // Pocket name + [WIN_POCKET_NAME] = { .bg = 0, .tilemapLeft = 4, .tilemapTop = 1, @@ -358,7 +420,7 @@ const struct WindowTemplate sDefaultBagWindows[] = .paletteNum = 1, .baseBlock = 0x1A1, }, - { // TM/HM info icons + [WIN_TMHM_INFO_ICONS] = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 13, @@ -367,7 +429,7 @@ const struct WindowTemplate sDefaultBagWindows[] = .paletteNum = 12, .baseBlock = 0x16B, }, - {// TM/HM info + [WIN_TMHM_INFO] = { .bg = 0, .tilemapLeft = 7, .tilemapTop = 13, @@ -376,7 +438,7 @@ const struct WindowTemplate sDefaultBagWindows[] = .paletteNum = 12, .baseBlock = 0x189, }, - { // Field message box + [WIN_MESSAGE] = { .bg = 1, .tilemapLeft = 2, .tilemapTop = 15, @@ -388,9 +450,9 @@ const struct WindowTemplate sDefaultBagWindows[] = DUMMY_WIN_TEMPLATE, }; -const struct WindowTemplate sContextMenuWindowTemplates[] = +static const struct WindowTemplate sContextMenuWindowTemplates[] = { - { + [ITEMWIN_1x1] = { .bg = 1, .tilemapLeft = 22, .tilemapTop = 17, @@ -399,7 +461,7 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x21D, }, - { + [ITEMWIN_1x2] = { .bg = 1, .tilemapLeft = 22, .tilemapTop = 15, @@ -408,7 +470,7 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x21D, }, - { + [ITEMWIN_2x2] = { .bg = 1, .tilemapLeft = 15, .tilemapTop = 15, @@ -417,7 +479,7 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x21D, }, - { + [ITEMWIN_2x3] = { .bg = 1, .tilemapLeft = 15, .tilemapTop = 13, @@ -426,7 +488,7 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x21D, }, - { + [ITEMWIN_MESSAGE] = { .bg = 1, .tilemapLeft = 2, .tilemapTop = 15, @@ -435,7 +497,7 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x1B1, }, - { + [ITEMWIN_YESNO_LOW] = { // Yes/No tucked in corner, for toss confirm .bg = 1, .tilemapLeft = 24, .tilemapTop = 15, @@ -444,7 +506,7 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x21D, }, - { + [ITEMWIN_YESNO_HIGH] = { // Yes/No higher up, positioned above a lower message box .bg = 1, .tilemapLeft = 21, .tilemapTop = 9, @@ -453,7 +515,7 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x21D, }, - { + [ITEMWIN_QUANTITY] = { // Used for quantity of items to Toss/Deposit .bg = 1, .tilemapLeft = 24, .tilemapTop = 17, @@ -462,7 +524,7 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x21D, }, - { + [ITEMWIN_QUANTITY_WIDE] = { // Used for quantity and price of items to Sell .bg = 1, .tilemapLeft = 18, .tilemapTop = 11, @@ -471,7 +533,7 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = .paletteNum = 15, .baseBlock = 0x245, }, - { + [ITEMWIN_MONEY] = { .bg = 1, .tilemapLeft = 1, .tilemapTop = 1, @@ -482,41 +544,18 @@ const struct WindowTemplate sContextMenuWindowTemplates[] = }, }; -// .text - -struct ListBuffer1 { - struct ListMenuItem subBuffers[MAX_POCKET_ITEMS]; -}; - -struct ListBuffer2 { - s8 name[MAX_POCKET_ITEMS][24]; -}; - -struct TempWallyStruct { - struct ItemSlot bagPocket_Items[BAG_ITEMS_COUNT]; - struct ItemSlot bagPocket_PokeBalls[BAG_POKEBALLS_COUNT]; - u16 cursorPosition[POCKETS_COUNT]; - u16 scrollPosition[POCKETS_COUNT]; - u8 filler[2]; - u16 pocket; -}; - -EWRAM_DATA struct BagMenuStruct *gBagMenu = 0; -EWRAM_DATA struct BagStruct gBagPositionStruct = {0}; +EWRAM_DATA struct BagMenu *gBagMenu = 0; +EWRAM_DATA struct BagPosition gBagPosition = {0}; static EWRAM_DATA struct ListBuffer1 *sListBuffer1 = 0; static EWRAM_DATA struct ListBuffer2 *sListBuffer2 = 0; EWRAM_DATA u16 gSpecialVar_ItemId = 0; -static EWRAM_DATA struct TempWallyStruct *sTempWallyBag = 0; - -extern u8 *const gPocketNamesStringsTable[]; -extern const u8 EventScript_SelectWithoutRegisteredItem[]; -extern const u16 gUnknown_0860F074[]; +static EWRAM_DATA struct TempWallyBag *sTempWallyBag = 0; void ResetBagScrollPositions(void) { - gBagPositionStruct.pocket = ITEMS_POCKET; - memset(gBagPositionStruct.cursorPosition, 0, 10); - memset(gBagPositionStruct.scrollPosition, 0, 10); + gBagPosition.pocket = ITEMS_POCKET; + memset(gBagPosition.cursorPosition, 0, sizeof(gBagPosition.cursorPosition)); + memset(gBagPosition.scrollPosition, 0, sizeof(gBagPosition.scrollPosition)); } void CB2_BagMenuFromStartMenu(void) @@ -551,7 +590,7 @@ void CB2_GoToSellMenu(void) void CB2_GoToItemDepositMenu(void) { - GoToBagMenu(ITEMMENULOCATION_ITEMPC, POCKETS_COUNT, sub_816B31C); + GoToBagMenu(ITEMMENULOCATION_ITEMPC, POCKETS_COUNT, CB2_PlayerPCExitBagMenu); } void ApprenticeOpenBagMenu(void) @@ -573,30 +612,31 @@ void QuizLadyOpenBagMenu(void) gSpecialVar_Result = FALSE; } -void GoToBagMenu(u8 location, u8 pocket, void ( *postExitMenuMainCallback2)()) +void GoToBagMenu(u8 location, u8 pocket, void ( *exitCallback)()) { - gBagMenu = AllocZeroed(sizeof(struct BagMenuStruct)); + gBagMenu = AllocZeroed(sizeof(*gBagMenu)); if (gBagMenu == NULL) { - SetMainCallback2(postExitMenuMainCallback2); + // Alloc failed, exit + SetMainCallback2(exitCallback); } else { if (location != ITEMMENULOCATION_LAST) - gBagPositionStruct.location = location; - if (postExitMenuMainCallback2) - gBagPositionStruct.bagCallback = postExitMenuMainCallback2; + gBagPosition.location = location; + if (exitCallback) + gBagPosition.exitCallback = exitCallback; if (pocket < POCKETS_COUNT) - gBagPositionStruct.pocket = pocket; - if (gBagPositionStruct.location == ITEMMENULOCATION_BERRY_TREE || - gBagPositionStruct.location == ITEMMENULOCATION_BERRY_BLENDER_CRUSH) + gBagPosition.pocket = pocket; + if (gBagPosition.location == ITEMMENULOCATION_BERRY_TREE || + gBagPosition.location == ITEMMENULOCATION_BERRY_BLENDER_CRUSH) gBagMenu->pocketSwitchDisabled = TRUE; - gBagMenu->exitCallback = NULL; - gBagMenu->itemOriginalLocation = 0xFF; + gBagMenu->newScreenCallback = NULL; + gBagMenu->toSwapPos = NOT_SWAPPING; gBagMenu->pocketScrollArrowsTask = TASK_NONE; gBagMenu->pocketSwitchArrowsTask = TASK_NONE; - memset(gBagMenu->spriteId, 0xFF, sizeof(gBagMenu->spriteId)); - memset(gBagMenu->windowPointers, 0xFF, 10); + memset(gBagMenu->spriteIds, SPRITE_NONE, sizeof(gBagMenu->spriteIds)); + memset(gBagMenu->windowIds, WINDOW_NONE, sizeof(gBagMenu->windowIds)); SetMainCallback2(CB2_Bag); } } @@ -617,14 +657,23 @@ void VBlankCB_BagMenuRun(void) TransferPlttBuffer(); } -#define tItemCount data[8] +#define tListTaskId data[0] +#define tListPosition data[1] +#define tQuantity data[2] +#define tNeverRead data[3] +#define tItemCount data[8] +#define tMsgWindowId data[10] +#define tPocketSwitchDir data[11] +#define tPocketSwitchTimer data[12] +#define tPocketSwitchState data[13] -void CB2_Bag(void) +static void CB2_Bag(void) { - while(MenuHelpers_CallLinkSomething() != TRUE && SetupBagMenu() != TRUE && MenuHelpers_LinkSomething() != TRUE) {}; + while(MenuHelpers_CallLinkSomething() != TRUE && SetupBagMenu() != TRUE && MenuHelpers_LinkSomething() != TRUE) + {}; } -bool8 SetupBagMenu(void) +static bool8 SetupBagMenu(void) { u8 taskId; @@ -671,13 +720,13 @@ bool8 SetupBagMenu(void) gMain.state++; break; case 9: - SetupBagMenu_Textboxes(); + LoadBagMenuTextWindows(); gMain.state++; break; case 10: - All_CalculateNItemsAndMaxShowed(); - SetPocketListPositions(); - UpdatePocketScrollPositions(); + UpdatePocketItemLists(); + InitPocketListPositions(); + InitPocketScrollPositions(); gMain.state++; break; case 11: @@ -685,24 +734,24 @@ bool8 SetupBagMenu(void) gMain.state++; break; case 12: - LoadBagItemListBuffers(gBagPositionStruct.pocket); + LoadBagItemListBuffers(gBagPosition.pocket); gMain.state++; break; case 13: - BagMenu_PrintPocketNames(gPocketNamesStringsTable[gBagPositionStruct.pocket], 0); - BagMenu_CopyPocketNameToWindow(0); - DrawPocketIndicatorSquare(gBagPositionStruct.pocket, TRUE); + PrintPocketNames(gPocketNamesStringsTable[gBagPosition.pocket], 0); + CopyPocketNameToWindow(0); + DrawPocketIndicatorSquare(gBagPosition.pocket, TRUE); gMain.state++; break; case 14: - taskId = CreateBagInputHandlerTask(gBagPositionStruct.location); - gTasks[taskId].data[0] = ListMenuInit(&gMultiuseListMenuTemplate, gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); - gTasks[taskId].data[3] = 0; + taskId = CreateBagInputHandlerTask(gBagPosition.location); + gTasks[taskId].tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gBagPosition.scrollPosition[gBagPosition.pocket], gBagPosition.cursorPosition[gBagPosition.pocket]); + gTasks[taskId].tNeverRead = 0; gTasks[taskId].tItemCount = 0; gMain.state++; break; case 15: - AddBagVisualSprite(gBagPositionStruct.pocket); + AddBagVisualSprite(gBagPosition.pocket); gMain.state++; break; case 16: @@ -715,7 +764,7 @@ bool8 SetupBagMenu(void) gMain.state++; break; case 18: - BagMenu_PrepareTMHMMoveWindow(); + PrepareTMHMMoveWindow(); gMain.state++; break; case 19: @@ -735,10 +784,10 @@ bool8 SetupBagMenu(void) return FALSE; } -void BagMenu_InitBGs(void) +static void BagMenu_InitBGs(void) { ResetVramOamAndBgCntRegs(); - memset(gBagMenu->tilemapBuffer, 0, 0x800); + memset(gBagMenu->tilemapBuffer, 0, sizeof(gBagMenu->tilemapBuffer)); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sBgTemplates_ItemMenu, ARRAY_COUNT(sBgTemplates_ItemMenu)); SetBgTilemapBuffer(2, gBagMenu->tilemapBuffer); @@ -751,49 +800,49 @@ void BagMenu_InitBGs(void) SetGpuReg(REG_OFFSET_BLDCNT, 0); } -bool8 LoadBagMenu_Graphics(void) +static bool8 LoadBagMenu_Graphics(void) { switch (gBagMenu->graphicsLoadState) { - case 0: - ResetTempTileDataBuffers(); - DecompressAndCopyTileDataToVram(2, gBagScreen_Gfx, 0, 0, 0); + case 0: + ResetTempTileDataBuffers(); + DecompressAndCopyTileDataToVram(2, gBagScreen_Gfx, 0, 0, 0); + gBagMenu->graphicsLoadState++; + break; + case 1: + if (FreeTempTileDataBuffersIfPossible() != TRUE) + { + LZDecompressWram(gBagScreen_GfxTileMap, gBagMenu->tilemapBuffer); gBagMenu->graphicsLoadState++; - break; - case 1: - if (FreeTempTileDataBuffersIfPossible() != TRUE) - { - LZDecompressWram(gBagScreen_GfxTileMap, gBagMenu->tilemapBuffer); - gBagMenu->graphicsLoadState++; - } - break; - case 2: - if (!IsWallysBag() && gSaveBlock2Ptr->playerGender != MALE) - LoadCompressedPalette(gBagScreenFemale_Pal, 0, 0x40); - else - LoadCompressedPalette(gBagScreenMale_Pal, 0, 0x40); - gBagMenu->graphicsLoadState++; - break; - case 3: - if (IsWallysBag() == TRUE || gSaveBlock2Ptr->playerGender == MALE) - LoadCompressedSpriteSheet(&gBagMaleSpriteSheet); - else - LoadCompressedSpriteSheet(&gBagFemaleSpriteSheet); - gBagMenu->graphicsLoadState++; - break; - case 4: - LoadCompressedSpritePalette(&gBagPaletteTable); - gBagMenu->graphicsLoadState++; - break; - default: - LoadListMenuSwapLineGfx(); - gBagMenu->graphicsLoadState = 0; - return TRUE; + } + break; + case 2: + if (!IsWallysBag() && gSaveBlock2Ptr->playerGender != MALE) + LoadCompressedPalette(gBagScreenFemale_Pal, 0, 0x40); + else + LoadCompressedPalette(gBagScreenMale_Pal, 0, 0x40); + gBagMenu->graphicsLoadState++; + break; + case 3: + if (IsWallysBag() == TRUE || gSaveBlock2Ptr->playerGender == MALE) + LoadCompressedSpriteSheet(&gBagMaleSpriteSheet); + else + LoadCompressedSpriteSheet(&gBagFemaleSpriteSheet); + gBagMenu->graphicsLoadState++; + break; + case 4: + LoadCompressedSpritePalette(&gBagPaletteTable); + gBagMenu->graphicsLoadState++; + break; + default: + LoadListMenuSwapLineGfx(); + gBagMenu->graphicsLoadState = 0; + return TRUE; } return FALSE; } -u8 CreateBagInputHandlerTask(u8 location) +static u8 CreateBagInputHandlerTask(u8 location) { u8 taskId; if (location == ITEMMENULOCATION_WALLY) @@ -803,13 +852,13 @@ u8 CreateBagInputHandlerTask(u8 location) return taskId; } -void AllocateBagItemListBuffers(void) +static void AllocateBagItemListBuffers(void) { - sListBuffer1 = Alloc(sizeof(struct ListBuffer1)); - sListBuffer2 = Alloc(sizeof(struct ListBuffer2)); + sListBuffer1 = Alloc(sizeof(*sListBuffer1)); + sListBuffer2 = Alloc(sizeof(*sListBuffer2)); } -void LoadBagItemListBuffers(u8 pocketId) +static void LoadBagItemListBuffers(u8 pocketId) { u16 i; struct BagPocket *pocket = &gBagPockets[pocketId]; @@ -845,55 +894,57 @@ void LoadBagItemListBuffers(u8 pocketId) gMultiuseListMenuTemplate.maxShowed = gBagMenu->numShownItems[pocketId]; } -void GetItemName(s8 *dest, u16 itemId) +static void GetItemName(s8 *dest, u16 itemId) { - switch (gBagPositionStruct.pocket) + switch (gBagPosition.pocket) { - case TMHM_POCKET: - StringCopy(gStringVar2, gMoveNames[ItemIdToBattleMoveId(itemId)]); - if (itemId >= ITEM_HM01) - { - ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_HM01 + 1, STR_CONV_MODE_LEADING_ZEROS, 1); - StringExpandPlaceholders(dest, gText_ClearTo11Var1Clear5Var2); - } - else - { - ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_TM01 + 1, STR_CONV_MODE_LEADING_ZEROS, 2); - StringExpandPlaceholders(dest, gText_NumberVar1Clear7Var2); - } - break; - case BERRIES_POCKET: - ConvertIntToDecimalStringN(gStringVar1, itemId - FIRST_BERRY_INDEX + 1, STR_CONV_MODE_LEADING_ZEROS, 2); - CopyItemName(itemId, gStringVar2); - StringExpandPlaceholders(dest, gText_NumberVar1Clear7Var2); - break; - default: - CopyItemName(itemId, dest); - break; + case TMHM_POCKET: + StringCopy(gStringVar2, gMoveNames[ItemIdToBattleMoveId(itemId)]); + if (itemId >= ITEM_HM01) + { + // Get HM number + ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_HM01 + 1, STR_CONV_MODE_LEADING_ZEROS, 1); + StringExpandPlaceholders(dest, gText_NumberItem_HM); + } + else + { + // Get TM number + ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_TM01 + 1, STR_CONV_MODE_LEADING_ZEROS, 2); + StringExpandPlaceholders(dest, gText_NumberItem_TMBerry); + } + break; + case BERRIES_POCKET: + ConvertIntToDecimalStringN(gStringVar1, itemId - FIRST_BERRY_INDEX + 1, STR_CONV_MODE_LEADING_ZEROS, 2); + CopyItemName(itemId, gStringVar2); + StringExpandPlaceholders(dest, gText_NumberItem_TMBerry); + break; + default: + CopyItemName(itemId, dest); + break; } } -void BagMenu_MoveCursorCallback(s32 itemIndex, bool8 onInit, struct ListMenu *list) +static void BagMenu_MoveCursorCallback(s32 itemIndex, bool8 onInit, struct ListMenu *list) { if (onInit != TRUE) { PlaySE(SE_SELECT); ShakeBagSprite(); } - if (gBagMenu->itemOriginalLocation == 0xFF) + if (gBagMenu->toSwapPos == NOT_SWAPPING) { RemoveBagItemIconSprite(gBagMenu->itemIconSlot ^ 1); if (itemIndex != LIST_CANCEL) - AddBagItemIconSprite(BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, itemIndex), gBagMenu->itemIconSlot); + AddBagItemIconSprite(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex), gBagMenu->itemIconSlot); else AddBagItemIconSprite(-1, gBagMenu->itemIconSlot); gBagMenu->itemIconSlot ^= 1; if (!gBagMenu->inhibitItemDescriptionPrint) - BagMenu_PrintDescription(itemIndex); + PrintItemDescription(itemIndex); } } -void BagMenu_ItemPrintCallback(u8 windowId, u32 itemIndex, u8 y) +static void BagMenu_ItemPrintCallback(u8 windowId, u32 itemIndex, u8 y) { u16 itemId; u16 itemQuantity; @@ -901,74 +952,80 @@ void BagMenu_ItemPrintCallback(u8 windowId, u32 itemIndex, u8 y) if (itemIndex != LIST_CANCEL) { - if (gBagMenu->itemOriginalLocation != 0xFF) + if (gBagMenu->toSwapPos != NOT_SWAPPING) { - if (gBagMenu->itemOriginalLocation == (u8)itemIndex) - BagMenu_PrintCursor(y, 2); + // Swapping items, draw cursor at original item's location + if (gBagMenu->toSwapPos == (u8)itemIndex) + BagMenu_PrintCursorAtPos(y, COLORID_GRAY_CURSOR); else - BagMenu_PrintCursor(y, 0xFF); + BagMenu_PrintCursorAtPos(y, COLORID_NONE); } - itemId = BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, itemIndex); - itemQuantity = BagGetQuantityByPocketPosition(gBagPositionStruct.pocket + 1, itemIndex); + itemId = BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex); + itemQuantity = BagGetQuantityByPocketPosition(gBagPosition.pocket + 1, itemIndex); + // Draw HM icon if (itemId >= ITEM_HM01 && itemId <= ITEM_HM08) BlitBitmapToWindow(windowId, gBagMenuHMIcon_Gfx, 8, y - 1, 16, 16); - if (gBagPositionStruct.pocket == BERRIES_POCKET) + if (gBagPosition.pocket == BERRIES_POCKET) { + // Print berry quantity ConvertIntToDecimalStringN(gStringVar1, itemQuantity, STR_CONV_MODE_RIGHT_ALIGN, BERRY_CAPACITY_DIGITS); StringExpandPlaceholders(gStringVar4, gText_xVar1); offset = GetStringRightAlignXOffset(7, gStringVar4, 119); - BagMenu_Print(windowId, 7, gStringVar4, offset, y, 0, 0, -1, 0); + BagMenu_Print(windowId, 7, gStringVar4, offset, y, 0, 0, TEXT_SPEED_FF, COLORID_NORMAL); } - else if (gBagPositionStruct.pocket != KEYITEMS_POCKET && ItemId_GetImportance(itemId) == FALSE) + else if (gBagPosition.pocket != KEYITEMS_POCKET && ItemId_GetImportance(itemId) == FALSE) { + // Print item quantity ConvertIntToDecimalStringN(gStringVar1, itemQuantity, STR_CONV_MODE_RIGHT_ALIGN, BAG_ITEM_CAPACITY_DIGITS); StringExpandPlaceholders(gStringVar4, gText_xVar1); offset = GetStringRightAlignXOffset(7, gStringVar4, 119); - BagMenu_Print(windowId, 7, gStringVar4, offset, y, 0, 0, -1, 0); + BagMenu_Print(windowId, 7, gStringVar4, offset, y, 0, 0, TEXT_SPEED_FF, COLORID_NORMAL); } else { + // Print registered icon if (gSaveBlock1Ptr->registeredItem && gSaveBlock1Ptr->registeredItem == itemId) BlitBitmapToWindow(windowId, sRegisteredSelect_Gfx, 96, y - 1, 24, 16); } } } -void BagMenu_PrintDescription(int itemIndex) +static void PrintItemDescription(int itemIndex) { const u8 *str; if (itemIndex != LIST_CANCEL) { - str = ItemId_GetDescription(BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, itemIndex)); + str = ItemId_GetDescription(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex)); } else { - StringCopy(gStringVar1, gBagMenu_ReturnToStrings[gBagPositionStruct.location]); + // Print 'Cancel' description + StringCopy(gStringVar1, gBagMenu_ReturnToStrings[gBagPosition.location]); StringExpandPlaceholders(gStringVar4, gText_ReturnToVar1); str = gStringVar4; } - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - BagMenu_Print(1, 1, str, 3, 1, 0, 0, 0, 0); + FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0)); + BagMenu_Print(WIN_DESCRIPTION, 1, str, 3, 1, 0, 0, 0, COLORID_NORMAL); } -void BagMenu_PrintCursor_(u8 listTaskId, u8 colorIndex) +static void BagMenu_PrintCursor(u8 listTaskId, u8 colorIndex) { - BagMenu_PrintCursor(ListMenuGetYCoordForPrintingArrowCursor(listTaskId), colorIndex); + BagMenu_PrintCursorAtPos(ListMenuGetYCoordForPrintingArrowCursor(listTaskId), colorIndex); } -void BagMenu_PrintCursor(u8 y, u8 colorIndex) +static void BagMenu_PrintCursorAtPos(u8 y, u8 colorIndex) { - if (colorIndex == 0xFF) - FillWindowPixelRect(0, PIXEL_FILL(0), 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); + if (colorIndex == COLORID_NONE) + FillWindowPixelRect(WIN_ITEM_LIST, PIXEL_FILL(0), 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); else - BagMenu_Print(0, 1, gText_SelectorArrow2, 0, y, 0, 0, 0, colorIndex); + BagMenu_Print(WIN_ITEM_LIST, 1, gText_SelectorArrow2, 0, y, 0, 0, 0, colorIndex); } -void CreatePocketScrollArrowPair(void) +static void CreatePocketScrollArrowPair(void) { if (gBagMenu->pocketScrollArrowsTask == TASK_NONE) gBagMenu->pocketScrollArrowsTask = AddScrollIndicatorArrowPairParameterized( @@ -976,10 +1033,10 @@ void CreatePocketScrollArrowPair(void) 172, 12, 148, - gBagMenu->numItemStacks[gBagPositionStruct.pocket] - gBagMenu->numShownItems[gBagPositionStruct.pocket], - 110, - 110, - &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]); + gBagMenu->numItemStacks[gBagPosition.pocket] - gBagMenu->numShownItems[gBagPosition.pocket], + TAG_POCKET_SCROLL_ARROW, + TAG_POCKET_SCROLL_ARROW, + &gBagPosition.scrollPosition[gBagPosition.pocket]); } void BagDestroyPocketScrollArrowPair(void) @@ -989,16 +1046,16 @@ void BagDestroyPocketScrollArrowPair(void) RemoveScrollIndicatorArrowPair(gBagMenu->pocketScrollArrowsTask); gBagMenu->pocketScrollArrowsTask = TASK_NONE; } - BagDestroyPocketSwitchArrowPair(); + DestroyPocketSwitchArrowPair(); } -void CreatePocketSwitchArrowPair(void) +static void CreatePocketSwitchArrowPair(void) { if (gBagMenu->pocketSwitchDisabled != TRUE && gBagMenu->pocketSwitchArrowsTask == TASK_NONE) - gBagMenu->pocketSwitchArrowsTask = AddScrollIndicatorArrowPair(&sBagScrollArrowsTemplate, &gBagPositionStruct.unk6); + gBagMenu->pocketSwitchArrowsTask = AddScrollIndicatorArrowPair(&sBagScrollArrowsTemplate, &gBagPosition.pocketSwitchArrowPos); } -void BagDestroyPocketSwitchArrowPair(void) +static void DestroyPocketSwitchArrowPair(void) { if (gBagMenu->pocketSwitchArrowsTask != TASK_NONE) { @@ -1007,7 +1064,7 @@ void BagDestroyPocketSwitchArrowPair(void) } } -void FreeBagItemListBuffers(void) +static void FreeBagMenu(void) { Free(sListBuffer2); Free(sListBuffer1); @@ -1018,23 +1075,27 @@ void FreeBagItemListBuffers(void) void Task_FadeAndCloseBagMenu(u8 taskId) { BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); - gTasks[taskId].func = TaskCloseBagMenu_2; + gTasks[taskId].func = Task_CloseBagMenu; } -void TaskCloseBagMenu_2(u8 taskId) +static void Task_CloseBagMenu(u8 taskId) { s16* data = gTasks[taskId].data; if (!gPaletteFade.active) { - DestroyListMenuTask(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); - if (gBagMenu->exitCallback != NULL) - SetMainCallback2(gBagMenu->exitCallback); + DestroyListMenuTask(tListTaskId, &gBagPosition.scrollPosition[gBagPosition.pocket], &gBagPosition.cursorPosition[gBagPosition.pocket]); + + // If ready for a new screen (e.g. party menu for giving an item) go to that screen + // Otherwise exit the bag and use callback set up when the bag was first opened + if (gBagMenu->newScreenCallback != NULL) + SetMainCallback2(gBagMenu->newScreenCallback); else - SetMainCallback2(gBagPositionStruct.bagCallback); + SetMainCallback2(gBagPosition.exitCallback); + BagDestroyPocketScrollArrowPair(); ResetSpriteData(); FreeAllSpritePalettes(); - FreeBagItemListBuffers(); + FreeBagMenu(); DestroyTask(taskId); } } @@ -1045,13 +1106,13 @@ void UpdatePocketItemList(u8 pocketId) struct BagPocket *pocket = &gBagPockets[pocketId]; switch (pocketId) { - case TMHM_POCKET: - case BERRIES_POCKET: - SortBerriesOrTMHMs(pocket); - break; - default: - CompactItemsInBagPocket(pocket); - break; + case TMHM_POCKET: + case BERRIES_POCKET: + SortBerriesOrTMHMs(pocket); + break; + default: + CompactItemsInBagPocket(pocket); + break; } gBagMenu->numItemStacks[pocketId] = 0; @@ -1062,160 +1123,161 @@ void UpdatePocketItemList(u8 pocketId) if (!gBagMenu->hideCloseBagText) gBagMenu->numItemStacks[pocketId]++; - if (gBagMenu->numItemStacks[pocketId] > 8) - gBagMenu->numShownItems[pocketId] = 8; + if (gBagMenu->numItemStacks[pocketId] > MAX_ITEMS_SHOWN) + gBagMenu->numShownItems[pocketId] = MAX_ITEMS_SHOWN; else gBagMenu->numShownItems[pocketId] = gBagMenu->numItemStacks[pocketId]; } -void All_CalculateNItemsAndMaxShowed(void) +static void UpdatePocketItemLists(void) { u8 i; for (i = 0; i < POCKETS_COUNT; i++) UpdatePocketItemList(i); } -void SetInitialScrollAndCursorPositions(u8 pocketId) +void UpdatePocketListPosition(u8 pocketId) { - sub_812225C(&gBagPositionStruct.scrollPosition[pocketId], &gBagPositionStruct.cursorPosition[pocketId], gBagMenu->numShownItems[pocketId], gBagMenu->numItemStacks[pocketId]); + SetCursorWithinListBounds(&gBagPosition.scrollPosition[pocketId], &gBagPosition.cursorPosition[pocketId], gBagMenu->numShownItems[pocketId], gBagMenu->numItemStacks[pocketId]); } -static void SetPocketListPositions(void) +static void InitPocketListPositions(void) { u8 i; for (i = 0; i < POCKETS_COUNT; i++) - SetInitialScrollAndCursorPositions(i); + UpdatePocketListPosition(i); } -void UpdatePocketScrollPositions(void) +static void InitPocketScrollPositions(void) { u8 i; for (i = 0; i < POCKETS_COUNT; i++) - sub_8122298(&gBagPositionStruct.scrollPosition[i], &gBagPositionStruct.cursorPosition[i], gBagMenu->numShownItems[i], gBagMenu->numItemStacks[i], 8); + SetCursorScrollWithinListBounds(&gBagPosition.scrollPosition[i], &gBagPosition.cursorPosition[i], gBagMenu->numShownItems[i], gBagMenu->numItemStacks[i], MAX_ITEMS_SHOWN); } u8 GetItemListPosition(u8 pocketId) { - return gBagPositionStruct.scrollPosition[pocketId] + gBagPositionStruct.cursorPosition[pocketId]; + return gBagPosition.scrollPosition[pocketId] + gBagPosition.cursorPosition[pocketId]; } void DisplayItemMessage(u8 taskId, u8 fontId, const u8 *str, void (*callback)(u8 taskId)) { s16* data = gTasks[taskId].data; - data[10] = AddItemMessageWindow(4); - FillWindowPixelBuffer(data[10], PIXEL_FILL(1)); - DisplayMessageAndContinueTask(taskId, data[10], 10, 13, fontId, GetPlayerTextSpeedDelay(), str, callback); + tMsgWindowId = AddItemMessageWindow(ITEMWIN_MESSAGE); + FillWindowPixelBuffer(tMsgWindowId, PIXEL_FILL(1)); + DisplayMessageAndContinueTask(taskId, tMsgWindowId, 10, 13, fontId, GetPlayerTextSpeedDelay(), str, callback); ScheduleBgCopyTilemapToVram(1); } -void BagMenu_InitListsMenu(u8 taskId) +void CloseItemMessage(u8 taskId) { s16* data = gTasks[taskId].data; - u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]; - u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; - BagMenu_RemoveBagItemMessageWindow(4); - DestroyListMenuTask(data[0], scrollPos, cursorPos); - UpdatePocketItemList(gBagPositionStruct.pocket); - SetInitialScrollAndCursorPositions(gBagPositionStruct.pocket); - LoadBagItemListBuffers(gBagPositionStruct.pocket); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); + u16* scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket]; + u16* cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket]; + RemoveItemMessageWindow(ITEMWIN_MESSAGE); + DestroyListMenuTask(tListTaskId, scrollPos, cursorPos); + UpdatePocketItemList(gBagPosition.pocket); + UpdatePocketListPosition(gBagPosition.pocket); + LoadBagItemListBuffers(gBagPosition.pocket); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); ScheduleBgCopyTilemapToVram(0); - set_callback3_to_bag(taskId); + ReturnToItemList(taskId); } -void sub_81ABC3C(u8 a) +static void AddItemQuantityWindow(u8 windowType) { - PrintItemDepositAmount(BagMenu_AddWindow(a), 1); + PrintItemQuantity(BagMenu_AddWindow(windowType), 1); } -void PrintItemDepositAmount(u8 windowId, s16 numDeposited) +static void PrintItemQuantity(u8 windowId, s16 quantity) { - u8 numDigits = (gBagPositionStruct.pocket == BERRIES_POCKET) ? BERRY_CAPACITY_DIGITS : BAG_ITEM_CAPACITY_DIGITS; - ConvertIntToDecimalStringN(gStringVar1, numDeposited, STR_CONV_MODE_LEADING_ZEROS, numDigits); + u8 numDigits = (gBagPosition.pocket == BERRIES_POCKET) ? BERRY_CAPACITY_DIGITS : BAG_ITEM_CAPACITY_DIGITS; + ConvertIntToDecimalStringN(gStringVar1, quantity, STR_CONV_MODE_LEADING_ZEROS, numDigits); StringExpandPlaceholders(gStringVar4, gText_xVar1); AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringCenterAlignXOffset(1, gStringVar4, 0x28), 2, 0, 0); } -void PrintItemSoldAmount(int windowId, int numSold, int moneyEarned) +// Prints the quantity of items to be sold and the amount that would be earned +static void PrintItemSoldAmount(int windowId, int numSold, int moneyEarned) { - u8 numDigits = (gBagPositionStruct.pocket == BERRIES_POCKET) ? BERRY_CAPACITY_DIGITS : BAG_ITEM_CAPACITY_DIGITS; + u8 numDigits = (gBagPosition.pocket == BERRIES_POCKET) ? BERRY_CAPACITY_DIGITS : BAG_ITEM_CAPACITY_DIGITS; ConvertIntToDecimalStringN(gStringVar1, numSold, STR_CONV_MODE_LEADING_ZEROS, numDigits); StringExpandPlaceholders(gStringVar4, gText_xVar1); - AddTextPrinterParameterized(windowId, 1, gStringVar4, 0, 1, -1, 0); + AddTextPrinterParameterized(windowId, 1, gStringVar4, 0, 1, TEXT_SPEED_FF, 0); PrintMoneyAmount(windowId, 38, 1, moneyEarned, 0); } -void Task_BagMenu_HandleInput(u8 taskId) +static void Task_BagMenu_HandleInput(u8 taskId) { s16* data = gTasks[taskId].data; - u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]; - u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; + u16* scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket]; + u16* cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket]; s32 listPosition; if (MenuHelpers_CallLinkSomething() != TRUE && !gPaletteFade.active) { switch (GetSwitchBagPocketDirection()) { - case SWITCH_POCKET_LEFT: - SwitchBagPocket(taskId, MENU_CURSOR_DELTA_LEFT, 0); - return; - case SWITCH_POCKET_RIGHT: - SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, 0); - return; - default: - if (JOY_NEW(SELECT_BUTTON)) + case SWITCH_POCKET_LEFT: + SwitchBagPocket(taskId, MENU_CURSOR_DELTA_LEFT, FALSE); + return; + case SWITCH_POCKET_RIGHT: + SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, FALSE); + return; + default: + if (JOY_NEW(SELECT_BUTTON)) + { + if (CanSwapItems() == TRUE) { - if (CanSwapItems() == TRUE) + ListMenuGetScrollAndRow(tListTaskId, scrollPos, cursorPos); + if ((*scrollPos + *cursorPos) != gBagMenu->numItemStacks[gBagPosition.pocket] - 1) { - ListMenuGetScrollAndRow(data[0], scrollPos, cursorPos); - if ((*scrollPos + *cursorPos) != gBagMenu->numItemStacks[gBagPositionStruct.pocket] - 1) - { - PlaySE(SE_SELECT); - BagMenu_SwapItems(taskId); - } + PlaySE(SE_SELECT); + StartItemSwap(taskId); } - return; } - break; + return; + } + break; } - listPosition = ListMenu_ProcessInput(data[0]); - ListMenuGetScrollAndRow(data[0], scrollPos, cursorPos); + listPosition = ListMenu_ProcessInput(tListTaskId); + ListMenuGetScrollAndRow(tListTaskId, scrollPos, cursorPos); switch (listPosition) { - case LIST_NOTHING_CHOSEN: - break; - case LIST_CANCEL: - if (gBagPositionStruct.location == ITEMMENULOCATION_BERRY_BLENDER_CRUSH) - { - PlaySE(SE_FAILURE); - break; - } - PlaySE(SE_SELECT); - gSpecialVar_ItemId = ITEM_NONE; - gTasks[taskId].func = Task_FadeAndCloseBagMenu; - break; - default: // A_BUTTON - PlaySE(SE_SELECT); - BagDestroyPocketScrollArrowPair(); - BagMenu_PrintCursor_(data[0], 2); - data[1] = listPosition; - data[2] = BagGetQuantityByPocketPosition(gBagPositionStruct.pocket + 1, listPosition); - gSpecialVar_ItemId = BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, listPosition); - gUnknown_08614054[gBagPositionStruct.location](taskId); + case LIST_NOTHING_CHOSEN: + break; + case LIST_CANCEL: + if (gBagPosition.location == ITEMMENULOCATION_BERRY_BLENDER_CRUSH) + { + PlaySE(SE_FAILURE); break; + } + PlaySE(SE_SELECT); + gSpecialVar_ItemId = ITEM_NONE; + gTasks[taskId].func = Task_FadeAndCloseBagMenu; + break; + default: // A_BUTTON + PlaySE(SE_SELECT); + BagDestroyPocketScrollArrowPair(); + BagMenu_PrintCursor(tListTaskId, COLORID_GRAY_CURSOR); + tListPosition = listPosition; + tQuantity = BagGetQuantityByPocketPosition(gBagPosition.pocket + 1, listPosition); + gSpecialVar_ItemId = BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, listPosition); + sContextMenuFuncs[gBagPosition.location](taskId); + break; } } } -void set_callback3_to_bag(u8 taskId) +static void ReturnToItemList(u8 taskId) { CreatePocketScrollArrowPair(); CreatePocketSwitchArrowPair(); - ClearWindowTilemap(3); - ClearWindowTilemap(4); - PutWindowTilemap(1); + ClearWindowTilemap(WIN_TMHM_INFO_ICONS); + ClearWindowTilemap(WIN_TMHM_INFO); + PutWindowTilemap(WIN_DESCRIPTION); ScheduleBgCopyTilemapToVram(0); gTasks[taskId].func = Task_BagMenu_HandleInput; } @@ -1226,12 +1288,12 @@ static u8 GetSwitchBagPocketDirection(void) if (gBagMenu->pocketSwitchDisabled) return SWITCH_POCKET_NONE; LRKeys = GetLRKeysPressed(); - if ((JOY_NEW(DPAD_LEFT)) || LRKeys == MENU_L_PRESSED) + if (JOY_NEW(DPAD_LEFT) || LRKeys == MENU_L_PRESSED) { PlaySE(SE_SELECT); return SWITCH_POCKET_LEFT; } - if ((JOY_NEW(DPAD_RIGHT)) || LRKeys == MENU_R_PRESSED) + if (JOY_NEW(DPAD_RIGHT) || LRKeys == MENU_R_PRESSED) { PlaySE(SE_SELECT); return SWITCH_POCKET_RIGHT; @@ -1241,54 +1303,54 @@ static u8 GetSwitchBagPocketDirection(void) static void ChangeBagPocketId(u8 *bagPocketId, s8 deltaBagPocketId) { - if (deltaBagPocketId == 1 && *bagPocketId == POCKETS_COUNT - 1) + if (deltaBagPocketId == MENU_CURSOR_DELTA_RIGHT && *bagPocketId == POCKETS_COUNT - 1) *bagPocketId = 0; - else if (deltaBagPocketId == -1 && *bagPocketId == 0) + else if (deltaBagPocketId == MENU_CURSOR_DELTA_LEFT && *bagPocketId == 0) *bagPocketId = POCKETS_COUNT - 1; else *bagPocketId += deltaBagPocketId; } -static void SwitchBagPocket(u8 taskId, s16 deltaBagPocketId, u16 a3) +static void SwitchBagPocket(u8 taskId, s16 deltaBagPocketId, bool16 skipEraseList) { s16* data = gTasks[taskId].data; - u8 pocketId; + u8 newPocket; - data[13] = 0; - data[12] = 0; - data[11] = deltaBagPocketId; - if (a3 == 0) + tPocketSwitchState = 0; + tPocketSwitchTimer = 0; + tPocketSwitchDir = deltaBagPocketId; + if (!skipEraseList) { - ClearWindowTilemap(0); - ClearWindowTilemap(1); - DestroyListMenuTask(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); + ClearWindowTilemap(WIN_ITEM_LIST); + ClearWindowTilemap(WIN_DESCRIPTION); + DestroyListMenuTask(tListTaskId, &gBagPosition.scrollPosition[gBagPosition.pocket], &gBagPosition.cursorPosition[gBagPosition.pocket]); ScheduleBgCopyTilemapToVram(0); - gSprites[gBagMenu->spriteId[2 + (gBagMenu->itemIconSlot ^ 1)]].invisible = TRUE; + gSprites[gBagMenu->spriteIds[ITEMMENUSPRITE_ITEM + (gBagMenu->itemIconSlot ^ 1)]].invisible = TRUE; BagDestroyPocketScrollArrowPair(); } - pocketId = gBagPositionStruct.pocket; - ChangeBagPocketId(&pocketId, deltaBagPocketId); + newPocket = gBagPosition.pocket; + ChangeBagPocketId(&newPocket, deltaBagPocketId); if (deltaBagPocketId == MENU_CURSOR_DELTA_RIGHT) { - BagMenu_PrintPocketNames(gPocketNamesStringsTable[gBagPositionStruct.pocket], gPocketNamesStringsTable[pocketId]); - BagMenu_CopyPocketNameToWindow(0); + PrintPocketNames(gPocketNamesStringsTable[gBagPosition.pocket], gPocketNamesStringsTable[newPocket]); + CopyPocketNameToWindow(0); } else { - BagMenu_PrintPocketNames(gPocketNamesStringsTable[pocketId], gPocketNamesStringsTable[gBagPositionStruct.pocket]); - BagMenu_CopyPocketNameToWindow(8); + PrintPocketNames(gPocketNamesStringsTable[newPocket], gPocketNamesStringsTable[gBagPosition.pocket]); + CopyPocketNameToWindow(8); } - DrawPocketIndicatorSquare(gBagPositionStruct.pocket, FALSE); - DrawPocketIndicatorSquare(pocketId, TRUE); + DrawPocketIndicatorSquare(gBagPosition.pocket, FALSE); + DrawPocketIndicatorSquare(newPocket, TRUE); FillBgTilemapBufferRect_Palette0(2, 11, 14, 2, 15, 16); ScheduleBgCopyTilemapToVram(2); - SetBagVisualPocketId(pocketId, 1); - RemoveBagSprite(1); + SetBagVisualPocketId(newPocket, 1); + RemoveBagSprite(ITEMMENUSPRITE_BALL); AddSwitchPocketRotatingBallSprite(deltaBagPocketId); - SetTaskFuncWithFollowupFunc(taskId, sub_81AC10C, gTasks[taskId].func); + SetTaskFuncWithFollowupFunc(taskId, Task_SwitchBagPocket, gTasks[taskId].func); } -void sub_81AC10C(u8 taskId) +static void Task_SwitchBagPocket(u8 taskId) { s16* data = gTasks[taskId].data; @@ -1296,48 +1358,50 @@ void sub_81AC10C(u8 taskId) { switch (GetSwitchBagPocketDirection()) { - case SWITCH_POCKET_LEFT: - ChangeBagPocketId(&gBagPositionStruct.pocket, data[11]); - SwitchTaskToFollowupFunc(taskId); - SwitchBagPocket(taskId, MENU_CURSOR_DELTA_LEFT, 1); - return; - case SWITCH_POCKET_RIGHT: - ChangeBagPocketId(&gBagPositionStruct.pocket, data[11]); - SwitchTaskToFollowupFunc(taskId); - SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, 1); - return; + case SWITCH_POCKET_LEFT: + ChangeBagPocketId(&gBagPosition.pocket, tPocketSwitchDir); + SwitchTaskToFollowupFunc(taskId); + SwitchBagPocket(taskId, MENU_CURSOR_DELTA_LEFT, TRUE); + return; + case SWITCH_POCKET_RIGHT: + ChangeBagPocketId(&gBagPosition.pocket, tPocketSwitchDir); + SwitchTaskToFollowupFunc(taskId); + SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, TRUE); + return; } } - switch (data[13]) + switch (tPocketSwitchState) { - case 0: - sub_81AC23C(data[12]); - if (!(++data[12] & 1)) - { - if (data[11] == 1) - BagMenu_CopyPocketNameToWindow((u8)(data[12] >> 1)); - else - BagMenu_CopyPocketNameToWindow((u8)(8 - (data[12] >> 1))); - } - if (data[12] == 16) - data[13]++; - break; - case 1: - ChangeBagPocketId(&gBagPositionStruct.pocket, data[11]); - LoadBagItemListBuffers(gBagPositionStruct.pocket); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); - PutWindowTilemap(1); - PutWindowTilemap(2); - ScheduleBgCopyTilemapToVram(0); - CreatePocketScrollArrowPair(); - CreatePocketSwitchArrowPair(); - SwitchTaskToFollowupFunc(taskId); + case 0: + DrawItemListBgRow(tPocketSwitchTimer); + if (!(++tPocketSwitchTimer & 1)) + { + if (tPocketSwitchDir == MENU_CURSOR_DELTA_RIGHT) + CopyPocketNameToWindow((u8)(tPocketSwitchTimer >> 1)); + else + CopyPocketNameToWindow((u8)(8 - (tPocketSwitchTimer >> 1))); + } + if (tPocketSwitchTimer == 16) + tPocketSwitchState++; + break; + case 1: + ChangeBagPocketId(&gBagPosition.pocket, tPocketSwitchDir); + LoadBagItemListBuffers(gBagPosition.pocket); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gBagPosition.scrollPosition[gBagPosition.pocket], gBagPosition.cursorPosition[gBagPosition.pocket]); + PutWindowTilemap(WIN_DESCRIPTION); + PutWindowTilemap(WIN_POCKET_NAME); + ScheduleBgCopyTilemapToVram(0); + CreatePocketScrollArrowPair(); + CreatePocketSwitchArrowPair(); + SwitchTaskToFollowupFunc(taskId); } } -void sub_81AC23C(u8 a) +// The background of the item list is a lighter color than the surrounding menu +// When the pocket is switched this lighter background is redrawn row by row +static void DrawItemListBgRow(u8 y) { - FillBgTilemapBufferRect_Palette0(2, 17, 14, a + 2, 15, 1); + FillBgTilemapBufferRect_Palette0(2, 17, 14, y + 2, 15, 1); ScheduleBgCopyTilemapToVram(2); } @@ -1352,299 +1416,308 @@ static void DrawPocketIndicatorSquare(u8 x, bool8 isCurrentPocket) static bool8 CanSwapItems(void) { - if (gBagPositionStruct.location <= ITEMMENULOCATION_BATTLE) + // Swaps can only be done from the field or in battle (as opposed to while selling items, for example) + if (gBagPosition.location == ITEMMENULOCATION_FIELD + || gBagPosition.location == ITEMMENULOCATION_BATTLE) { - u8 temp = gBagPositionStruct.pocket - 2; - if (temp > 1) + // TMHMs and berries are numbered, and so may not be swapped + if (gBagPosition.pocket != TMHM_POCKET + && gBagPosition.pocket != BERRIES_POCKET) return TRUE; } return FALSE; } -void BagMenu_SwapItems(u8 taskId) +static void StartItemSwap(u8 taskId) { s16* data = gTasks[taskId].data; - ListMenuSetUnkIndicatorsStructField(data[0], 16, 1); - data[1] = gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket] + gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; - gBagMenu->itemOriginalLocation = data[1]; - CopyItemName(BagGetItemIdByPocketPosition(gBagPositionStruct.pocket + 1, data[1]), gStringVar1); + ListMenuSetUnkIndicatorsStructField(tListTaskId, 16, 1); + tListPosition = gBagPosition.scrollPosition[gBagPosition.pocket] + gBagPosition.cursorPosition[gBagPosition.pocket]; + gBagMenu->toSwapPos = tListPosition; + CopyItemName(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, tListPosition), gStringVar1); StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); - UpdateItemMenuSwapLinePos(data[1]); - BagDestroyPocketSwitchArrowPair(); - BagMenu_PrintCursor_(data[0], 2); + FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0)); + BagMenu_Print(WIN_DESCRIPTION, 1, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL); + UpdateItemMenuSwapLinePos(tListPosition); + DestroyPocketSwitchArrowPair(); + BagMenu_PrintCursor(tListTaskId, COLORID_GRAY_CURSOR); gTasks[taskId].func = Task_HandleSwappingItemsInput; } static void Task_HandleSwappingItemsInput(u8 taskId) { s16* data = gTasks[taskId].data; - int input; if (MenuHelpers_CallLinkSomething() != TRUE) { if (JOY_NEW(SELECT_BUTTON)) { PlaySE(SE_SELECT); - ListMenuGetScrollAndRow(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); - sub_81AC498(taskId); + ListMenuGetScrollAndRow(tListTaskId, &gBagPosition.scrollPosition[gBagPosition.pocket], &gBagPosition.cursorPosition[gBagPosition.pocket]); + DoItemSwap(taskId); } else { - input = ListMenu_ProcessInput(data[0]); - ListMenuGetScrollAndRow(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); + s32 input = ListMenu_ProcessInput(tListTaskId); + ListMenuGetScrollAndRow(tListTaskId, &gBagPosition.scrollPosition[gBagPosition.pocket], &gBagPosition.cursorPosition[gBagPosition.pocket]); SetItemMenuSwapLineInvisibility(FALSE); - UpdateItemMenuSwapLinePos(gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); + UpdateItemMenuSwapLinePos(gBagPosition.cursorPosition[gBagPosition.pocket]); switch (input) { - case LIST_NOTHING_CHOSEN: - break; - case LIST_CANCEL: - PlaySE(SE_SELECT); - if (JOY_NEW(A_BUTTON)) - sub_81AC498(taskId); - else - sub_81AC590(taskId); - break; - default: - PlaySE(SE_SELECT); - sub_81AC498(taskId); + case LIST_NOTHING_CHOSEN: + break; + case LIST_CANCEL: + PlaySE(SE_SELECT); + if (JOY_NEW(A_BUTTON)) + DoItemSwap(taskId); + else + CancelItemSwap(taskId); + break; + default: + PlaySE(SE_SELECT); + DoItemSwap(taskId); + break; } } } } -void sub_81AC498(u8 taskId) +static void DoItemSwap(u8 taskId) { s16* data = gTasks[taskId].data; - u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]; - u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; + u16* scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket]; + u16* cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket]; u16 realPos = (*scrollPos + *cursorPos); - if (data[1] == realPos || data[1] == (realPos - 1)) - sub_81AC590(taskId); + if (tListPosition == realPos || tListPosition == realPos - 1) + { + // Position is the same as the original, cancel + CancelItemSwap(taskId); + } else { - MoveItemSlotInList(gBagPockets[gBagPositionStruct.pocket].itemSlots, data[1], realPos); - gBagMenu->itemOriginalLocation = -1; - DestroyListMenuTask(data[0], scrollPos, cursorPos); - if (data[1] < realPos) - gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]--; - LoadBagItemListBuffers(gBagPositionStruct.pocket); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); + MoveItemSlotInList(gBagPockets[gBagPosition.pocket].itemSlots, tListPosition, realPos); + gBagMenu->toSwapPos = NOT_SWAPPING; + DestroyListMenuTask(tListTaskId, scrollPos, cursorPos); + if (tListPosition < realPos) + gBagPosition.cursorPosition[gBagPosition.pocket]--; + LoadBagItemListBuffers(gBagPosition.pocket); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); SetItemMenuSwapLineInvisibility(TRUE); CreatePocketSwitchArrowPair(); gTasks[taskId].func = Task_BagMenu_HandleInput; } } -void sub_81AC590(u8 taskId) +static void CancelItemSwap(u8 taskId) { s16* data = gTasks[taskId].data; - u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]; - u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; + u16* scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket]; + u16* cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket]; - gBagMenu->itemOriginalLocation = -1; - DestroyListMenuTask(data[0], scrollPos, cursorPos); - if (data[1] < (*scrollPos + *cursorPos)) - gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]--; - LoadBagItemListBuffers(gBagPositionStruct.pocket); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); + gBagMenu->toSwapPos = NOT_SWAPPING; + DestroyListMenuTask(tListTaskId, scrollPos, cursorPos); + if (tListPosition < *scrollPos + *cursorPos) + gBagPosition.cursorPosition[gBagPosition.pocket]--; + LoadBagItemListBuffers(gBagPosition.pocket); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); SetItemMenuSwapLineInvisibility(TRUE); CreatePocketSwitchArrowPair(); gTasks[taskId].func = Task_BagMenu_HandleInput; } -static void OpenContextMenu(u8 unused) +static void OpenContextMenu(u8 taskId) { - switch (gBagPositionStruct.location) + switch (gBagPosition.location) { - case ITEMMENULOCATION_BATTLE: - case ITEMMENULOCATION_WALLY: - if (ItemId_GetBattleUsage(gSpecialVar_ItemId)) - { - gBagMenu->contextMenuItemsPtr = sContextMenuItems_BattleUse; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BattleUse); - } - else + case ITEMMENULOCATION_BATTLE: + case ITEMMENULOCATION_WALLY: + if (ItemId_GetBattleUsage(gSpecialVar_ItemId)) + { + gBagMenu->contextMenuItemsPtr = sContextMenuItems_BattleUse; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BattleUse); + } + else + { + gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel); + } + break; + case ITEMMENULOCATION_BERRY_BLENDER_CRUSH: + gBagMenu->contextMenuItemsPtr = sContextMenuItems_BerryBlenderCrush; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BerryBlenderCrush); + break; + case ITEMMENULOCATION_APPRENTICE: + if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) + { + gBagMenu->contextMenuItemsPtr = sContextMenuItems_Apprentice; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Apprentice); + } + else + { + gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel); + } + break; + case ITEMMENULOCATION_FAVOR_LADY: + if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) + { + gBagMenu->contextMenuItemsPtr = sContextMenuItems_FavorLady; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_FavorLady); + } + else + { + gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel); + } + break; + case ITEMMENULOCATION_QUIZ_LADY: + if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) + { + gBagMenu->contextMenuItemsPtr = sContextMenuItems_QuizLady; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_QuizLady); + } + else + { + gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel); + } + break; + case ITEMMENULOCATION_PARTY: + case ITEMMENULOCATION_SHOP: + case ITEMMENULOCATION_BERRY_TREE: + case ITEMMENULOCATION_ITEMPC: + default: + if (MenuHelpers_LinkSomething() == TRUE || InUnionRoom() == TRUE) + { + if (gBagPosition.pocket == KEYITEMS_POCKET || !IsHoldingItemAllowed(gSpecialVar_ItemId)) { gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel; gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel); } - break; - case ITEMMENULOCATION_BERRY_BLENDER_CRUSH: - gBagMenu->contextMenuItemsPtr = sContextMenuItems_BerryBlenderCrush; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BerryBlenderCrush); - break; - case ITEMMENULOCATION_APPRENTICE: - if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) - { - gBagMenu->contextMenuItemsPtr = sContextMenuItems_Apprentice; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Apprentice); - } else { - gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel); + gBagMenu->contextMenuItemsPtr = sContextMenuItems_Give; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Give); } - break; - case ITEMMENULOCATION_FAVOR_LADY: - if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) + } + else + { + switch (gBagPosition.pocket) { - gBagMenu->contextMenuItemsPtr = sContextMenuItems_FavorLady; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_FavorLady); - } - else - { - gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel); - } - break; - case ITEMMENULOCATION_QUIZ_LADY: - if (!ItemId_GetImportance(gSpecialVar_ItemId) && gSpecialVar_ItemId != ITEM_ENIGMA_BERRY) - { - gBagMenu->contextMenuItemsPtr = sContextMenuItems_QuizLady; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_QuizLady); - } - else - { - gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel); - } - break; - case ITEMMENULOCATION_PARTY: - case ITEMMENULOCATION_SHOP: - case ITEMMENULOCATION_BERRY_TREE: - case ITEMMENULOCATION_ITEMPC: - default: - if (MenuHelpers_LinkSomething() == TRUE || InUnionRoom() == TRUE) - { - if (gBagPositionStruct.pocket == KEYITEMS_POCKET || !sub_8122148(gSpecialVar_ItemId)) + case ITEMS_POCKET: + gBagMenu->contextMenuItemsPtr = gBagMenu->contextMenuItemsBuffer; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_ItemsPocket); + memcpy(&gBagMenu->contextMenuItemsBuffer, &sContextMenuItems_ItemsPocket, sizeof(sContextMenuItems_ItemsPocket)); + if (ItemIsMail(gSpecialVar_ItemId) == TRUE) + gBagMenu->contextMenuItemsBuffer[0] = ACTION_CHECK; + break; + case KEYITEMS_POCKET: + gBagMenu->contextMenuItemsPtr = gBagMenu->contextMenuItemsBuffer; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_KeyItemsPocket); + memcpy(&gBagMenu->contextMenuItemsBuffer, &sContextMenuItems_KeyItemsPocket, sizeof(sContextMenuItems_KeyItemsPocket)); + if (gSaveBlock1Ptr->registeredItem == gSpecialVar_ItemId) + gBagMenu->contextMenuItemsBuffer[1] = ACTION_DESELECT; + if (gSpecialVar_ItemId == ITEM_MACH_BIKE || gSpecialVar_ItemId == ITEM_ACRO_BIKE) { - gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel); - } - else - { - gBagMenu->contextMenuItemsPtr = sContextMenuItems_Give; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Give); - } - } - else - { - switch (gBagPositionStruct.pocket) - { - case ITEMS_POCKET: - gBagMenu->contextMenuItemsPtr = gBagMenu->contextMenuItemsBuffer; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_ItemsPocket); - memcpy(&gBagMenu->contextMenuItemsBuffer, &sContextMenuItems_ItemsPocket, sizeof(sContextMenuItems_ItemsPocket)); - if (ItemIsMail(gSpecialVar_ItemId) == TRUE) - gBagMenu->contextMenuItemsBuffer[0] = ITEMMENUACTION_CHECK; - break; - case KEYITEMS_POCKET: - gBagMenu->contextMenuItemsPtr = gBagMenu->contextMenuItemsBuffer; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_KeyItemsPocket); - memcpy(&gBagMenu->contextMenuItemsBuffer, &sContextMenuItems_KeyItemsPocket, sizeof(sContextMenuItems_KeyItemsPocket)); - if (gSaveBlock1Ptr->registeredItem == gSpecialVar_ItemId) - gBagMenu->contextMenuItemsBuffer[1] = ITEMMENUACTION_DESELECT; - if (gSpecialVar_ItemId == ITEM_MACH_BIKE || gSpecialVar_ItemId == ITEM_ACRO_BIKE) - { - if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE)) - gBagMenu->contextMenuItemsBuffer[0] = ITEMMENUACTION_WALK; - } - break; - case BALLS_POCKET: - gBagMenu->contextMenuItemsPtr = sContextMenuItems_BallsPocket; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BallsPocket); - break; - case TMHM_POCKET: - gBagMenu->contextMenuItemsPtr = sContextMenuItems_TmHmPocket; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_TmHmPocket); - break; - case BERRIES_POCKET: - gBagMenu->contextMenuItemsPtr = sContextMenuItems_BerriesPocket; - gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BerriesPocket); - break; + if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE)) + gBagMenu->contextMenuItemsBuffer[0] = ACTION_WALK; } + break; + case BALLS_POCKET: + gBagMenu->contextMenuItemsPtr = sContextMenuItems_BallsPocket; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BallsPocket); + break; + case TMHM_POCKET: + gBagMenu->contextMenuItemsPtr = sContextMenuItems_TmHmPocket; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_TmHmPocket); + break; + case BERRIES_POCKET: + gBagMenu->contextMenuItemsPtr = sContextMenuItems_BerriesPocket; + gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BerriesPocket); + break; } + } } - if (gBagPositionStruct.pocket == TMHM_POCKET) + if (gBagPosition.pocket == TMHM_POCKET) { - ClearWindowTilemap(1); + ClearWindowTilemap(WIN_DESCRIPTION); PrintTMHMMoveData(gSpecialVar_ItemId); - PutWindowTilemap(3); - PutWindowTilemap(4); + PutWindowTilemap(WIN_TMHM_INFO_ICONS); + PutWindowTilemap(WIN_TMHM_INFO); ScheduleBgCopyTilemapToVram(0); } else { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_Var1IsSelected); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); + FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0)); + BagMenu_Print(WIN_DESCRIPTION, 1, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL); } if (gBagMenu->contextMenuNumItems == 1) - sub_81ACAF8(BagMenu_AddWindow(0)); + PrintContextMenuItems(BagMenu_AddWindow(ITEMWIN_1x1)); else if (gBagMenu->contextMenuNumItems == 2) - sub_81ACAF8(BagMenu_AddWindow(1)); + PrintContextMenuItems(BagMenu_AddWindow(ITEMWIN_1x2)); else if (gBagMenu->contextMenuNumItems == 4) - sub_81ACB54(BagMenu_AddWindow(2), 2, 2); + PrintContextMenuItemGrid(BagMenu_AddWindow(ITEMWIN_2x2), 2, 2); else - sub_81ACB54(BagMenu_AddWindow(3), 2, 3); + PrintContextMenuItemGrid(BagMenu_AddWindow(ITEMWIN_2x3), 2, 3); } -void sub_81ACAF8(u8 a) +static void PrintContextMenuItems(u8 windowId) { - AddItemMenuActionTextPrinters(a, 7, 8, 1, 0, 16, gBagMenu->contextMenuNumItems, sItemMenuActions, gBagMenu->contextMenuItemsPtr); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(a, gBagMenu->contextMenuNumItems, 0); + AddItemMenuActionTextPrinters(windowId, 7, 8, 1, 0, 16, gBagMenu->contextMenuNumItems, sItemMenuActions, gBagMenu->contextMenuItemsPtr); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, gBagMenu->contextMenuNumItems, 0); } -void sub_81ACB54(u8 a, u8 b, u8 c) +static void PrintContextMenuItemGrid(u8 windowId, u8 columns, u8 rows) { - PrintMenuActionGrid(a, 7, 8, 1, 0x38, b, c, sItemMenuActions, gBagMenu->contextMenuItemsPtr); - InitMenuActionGrid(a, 0x38, b, c, 0); + PrintMenuActionGrid(windowId, 7, 8, 1, 56, columns, rows, sItemMenuActions, gBagMenu->contextMenuItemsPtr); + InitMenuActionGrid(windowId, 56, columns, rows, 0); } -void Task_ItemContext_FieldOrBattle(u8 taskId) +static void Task_ItemContext_Normal(u8 taskId) { OpenContextMenu(taskId); + + // Context menu width is never greater than 2 columns, so if + // there are more than 2 items then there are multiple rows if (gBagMenu->contextMenuNumItems <= 2) - gTasks[taskId].func = Task_HandleInBattleItemMenuInput; + gTasks[taskId].func = Task_ItemContext_SingleRow; else - gTasks[taskId].func = Task_HandleOutOfBattleItemMenuInput; + gTasks[taskId].func = Task_ItemContext_MultipleRows; } -void Task_HandleInBattleItemMenuInput(u8 taskId) +static void Task_ItemContext_SingleRow(u8 taskId) { if (MenuHelpers_CallLinkSomething() != TRUE) { s8 selection = Menu_ProcessInputNoWrap(); switch (selection) { - case MENU_NOTHING_CHOSEN: - break; - case MENU_B_PRESSED: - PlaySE(SE_SELECT); - sItemMenuActions[ITEMMENUACTION_CANCEL].func.void_u8(taskId); - break; - default: - PlaySE(SE_SELECT); - sItemMenuActions[gBagMenu->contextMenuItemsPtr[selection]].func.void_u8(taskId); - break; + case MENU_NOTHING_CHOSEN: + break; + case MENU_B_PRESSED: + PlaySE(SE_SELECT); + sItemMenuActions[ACTION_CANCEL].func.void_u8(taskId); + break; + default: + PlaySE(SE_SELECT); + sItemMenuActions[gBagMenu->contextMenuItemsPtr[selection]].func.void_u8(taskId); + break; } } } -void Task_HandleOutOfBattleItemMenuInput(u8 taskId) +static void Task_ItemContext_MultipleRows(u8 taskId) { if (MenuHelpers_CallLinkSomething() != TRUE) { s8 cursorPos = Menu_GetCursorPos(); if (JOY_NEW(DPAD_UP)) { - if (cursorPos > 0 && sub_81ACDFC(cursorPos - 2)) + if (cursorPos > 0 && IsValidContextMenuPos(cursorPos - 2)) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP); @@ -1652,23 +1725,23 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) } else if (JOY_NEW(DPAD_DOWN)) { - if (cursorPos < (gBagMenu->contextMenuNumItems - 2) && sub_81ACDFC(cursorPos + 2)) + if (cursorPos < (gBagMenu->contextMenuNumItems - 2) && IsValidContextMenuPos(cursorPos + 2)) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); } } - else if ((JOY_NEW(DPAD_LEFT)) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) { - if ((cursorPos & 1) && sub_81ACDFC(cursorPos - 1)) + if ((cursorPos & 1) && IsValidContextMenuPos(cursorPos - 1)) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE); } } - else if ((JOY_NEW(DPAD_RIGHT)) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) { - if (!(cursorPos & 1) && sub_81ACDFC(cursorPos + 1)) + if (!(cursorPos & 1) && IsValidContextMenuPos(cursorPos + 1)) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); @@ -1682,50 +1755,48 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - sItemMenuActions[ITEMMENUACTION_CANCEL].func.void_u8(taskId); + sItemMenuActions[ACTION_CANCEL].func.void_u8(taskId); } } } -bool8 sub_81ACDFC(s8 a) +static bool8 IsValidContextMenuPos(s8 cursorPos) { - if (a < 0) + if (cursorPos < 0) return FALSE; - if (a > gBagMenu->contextMenuNumItems) + if (cursorPos > gBagMenu->contextMenuNumItems) return FALSE; - if (gBagMenu->contextMenuItemsPtr[a] == 14) + if (gBagMenu->contextMenuItemsPtr[cursorPos] == ACTION_DUMMY) return FALSE; return TRUE; } -void BagMenu_RemoveSomeWindow(void) +static void RemoveContextWindow(void) { if (gBagMenu->contextMenuNumItems == 1) - BagMenu_RemoveWindow(0); + BagMenu_RemoveWindow(ITEMWIN_1x1); else if (gBagMenu->contextMenuNumItems == 2) - { - BagMenu_RemoveWindow(1); - } + BagMenu_RemoveWindow(ITEMWIN_1x2); else if (gBagMenu->contextMenuNumItems == 4) - { - BagMenu_RemoveWindow(2); - } + BagMenu_RemoveWindow(ITEMWIN_2x2); else - BagMenu_RemoveWindow(3); + BagMenu_RemoveWindow(ITEMWIN_2x3); } -void ItemMenu_UseOutOfBattle(u8 taskId) +static void ItemMenu_UseOutOfBattle(u8 taskId) { if (ItemId_GetFieldFunc(gSpecialVar_ItemId)) { - BagMenu_RemoveSomeWindow(); + RemoveContextWindow(); if (CalculatePlayerPartyCount() == 0 && ItemId_GetType(gSpecialVar_ItemId) == ITEM_USE_PARTY_MENU) - BagMenu_PrintThereIsNoPokemon(taskId); + { + PrintThereIsNoPokemon(taskId); + } else { - FillWindowPixelBuffer(1, PIXEL_FILL(0)); + FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0)); ScheduleBgCopyTilemapToVram(0); - if (gBagPositionStruct.pocket != BERRIES_POCKET) + if (gBagPosition.pocket != BERRIES_POCKET) ItemId_GetFieldFunc(gSpecialVar_ItemId)(taskId); else ItemUseOutOfBattle_Berry(taskId); @@ -1733,186 +1804,190 @@ void ItemMenu_UseOutOfBattle(u8 taskId) } } -void ItemMenu_Toss(u8 taskId) +static void ItemMenu_Toss(u8 taskId) { s16* data = gTasks[taskId].data; - BagMenu_RemoveSomeWindow(); + RemoveContextWindow(); tItemCount = 1; - if (data[2] == 1) + if (tQuantity == 1) { - BagMenu_TossItems(taskId); + AskTossItems(taskId); } else { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_TossHowManyVar1s); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); - sub_81ABC3C(7); + FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0)); + BagMenu_Print(WIN_DESCRIPTION, 1, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL); + AddItemQuantityWindow(ITEMWIN_QUANTITY); gTasks[taskId].func = Task_ChooseHowManyToToss; } } -void BagMenu_TossItems(u8 taskId) +static void AskTossItems(u8 taskId) { s16* data = gTasks[taskId].data; CopyItemName(gSpecialVar_ItemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_ITEM_DIGITS); StringExpandPlaceholders(gStringVar4, gText_ConfirmTossItems); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); - BagMenu_YesNo(taskId, 5, &sYesNoTossFunctions); + FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0)); + BagMenu_Print(WIN_DESCRIPTION, 1, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL); + BagMenu_YesNo(taskId, ITEMWIN_YESNO_LOW, &sYesNoTossFunctions); } -void BagMenu_CancelToss(u8 taskId) +static void CancelToss(u8 taskId) { s16* data = gTasks[taskId].data; - BagMenu_PrintDescription(data[1]); - BagMenu_PrintCursor_(data[0], 0); - set_callback3_to_bag(taskId); + PrintItemDescription(tListPosition); + BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL); + ReturnToItemList(taskId); } -void Task_ChooseHowManyToToss(u8 taskId) +static void Task_ChooseHowManyToToss(u8 taskId) { s16* data = gTasks[taskId].data; - if (AdjustQuantityAccordingToDPadInput(&tItemCount, data[2]) == TRUE) + if (AdjustQuantityAccordingToDPadInput(&tItemCount, tQuantity) == TRUE) { - PrintItemDepositAmount(gBagMenu->windowPointers[7], tItemCount); + PrintItemQuantity(gBagMenu->windowIds[ITEMWIN_QUANTITY], tItemCount); } else if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); - BagMenu_RemoveWindow(7); - BagMenu_TossItems(taskId); + BagMenu_RemoveWindow(ITEMWIN_QUANTITY); + AskTossItems(taskId); } else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - BagMenu_RemoveWindow(7); - BagMenu_CancelToss(taskId); + BagMenu_RemoveWindow(ITEMWIN_QUANTITY); + CancelToss(taskId); } } -void BagMenu_ConfirmToss(u8 taskId) +static void ConfirmToss(u8 taskId) { s16* data = gTasks[taskId].data; CopyItemName(gSpecialVar_ItemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_ITEM_DIGITS); StringExpandPlaceholders(gStringVar4, gText_ThrewAwayVar2Var1s); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); - gTasks[taskId].func = Task_ActuallyToss; + FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0)); + BagMenu_Print(WIN_DESCRIPTION, 1, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL); + gTasks[taskId].func = Task_RemoveItemFromBag; } -void Task_ActuallyToss(u8 taskId) +// Remove selected item(s) from the bag and update list +// For when items are tossed or deposited +static void Task_RemoveItemFromBag(u8 taskId) { s16* data = gTasks[taskId].data; - u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]; - u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; + u16* scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket]; + u16* cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket]; if (JOY_NEW(A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); RemoveBagItem(gSpecialVar_ItemId, tItemCount); - DestroyListMenuTask(data[0], scrollPos, cursorPos); - UpdatePocketItemList(gBagPositionStruct.pocket); - SetInitialScrollAndCursorPositions(gBagPositionStruct.pocket); - LoadBagItemListBuffers(gBagPositionStruct.pocket); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); + DestroyListMenuTask(tListTaskId, scrollPos, cursorPos); + UpdatePocketItemList(gBagPosition.pocket); + UpdatePocketListPosition(gBagPosition.pocket); + LoadBagItemListBuffers(gBagPosition.pocket); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); ScheduleBgCopyTilemapToVram(0); - set_callback3_to_bag(taskId); + ReturnToItemList(taskId); } } -void ItemMenu_Register(u8 taskId) +static void ItemMenu_Register(u8 taskId) { s16* data = gTasks[taskId].data; - u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]; - u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; + u16* scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket]; + u16* cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket]; if (gSaveBlock1Ptr->registeredItem == gSpecialVar_ItemId) gSaveBlock1Ptr->registeredItem = 0; else gSaveBlock1Ptr->registeredItem = gSpecialVar_ItemId; - DestroyListMenuTask(data[0], scrollPos, cursorPos); - LoadBagItemListBuffers(gBagPositionStruct.pocket); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); + DestroyListMenuTask(tListTaskId, scrollPos, cursorPos); + LoadBagItemListBuffers(gBagPosition.pocket); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); ScheduleBgCopyTilemapToVram(0); ItemMenu_Cancel(taskId); } -void ItemMenu_Give(u8 taskId) +static void ItemMenu_Give(u8 taskId) { - BagMenu_RemoveSomeWindow(); + RemoveContextWindow(); if (!IsWritingMailAllowed(gSpecialVar_ItemId)) { - DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350); + DisplayItemMessage(taskId, 1, gText_CantWriteMail, HandleErrorMessage); } else if (!ItemId_GetImportance(gSpecialVar_ItemId)) { if (CalculatePlayerPartyCount() == 0) - BagMenu_PrintThereIsNoPokemon(taskId); + { + PrintThereIsNoPokemon(taskId); + } else { - gBagMenu->exitCallback = CB2_ChooseMonToGiveItem; + gBagMenu->newScreenCallback = CB2_ChooseMonToGiveItem; Task_FadeAndCloseBagMenu(taskId); } } else { - BagMenu_PrintItemCantBeHeld(taskId); + PrintItemCantBeHeld(taskId); } } -void BagMenu_PrintThereIsNoPokemon(u8 taskId) +static void PrintThereIsNoPokemon(u8 taskId) { - DisplayItemMessage(taskId, 1, gText_NoPokemon, sub_81AD350); + DisplayItemMessage(taskId, 1, gText_NoPokemon, HandleErrorMessage); } -static void BagMenu_PrintItemCantBeHeld(u8 taskId) +static void PrintItemCantBeHeld(u8 taskId) { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeld); - DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD350); + DisplayItemMessage(taskId, 1, gStringVar4, HandleErrorMessage); } -void sub_81AD350(u8 taskId) +static void HandleErrorMessage(u8 taskId) { if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); - BagMenu_InitListsMenu(taskId); + CloseItemMessage(taskId); } } -void ItemMenu_CheckTag(u8 taskId) +static void ItemMenu_CheckTag(u8 taskId) { - gBagMenu->exitCallback = DoBerryTagScreen; + gBagMenu->newScreenCallback = DoBerryTagScreen; Task_FadeAndCloseBagMenu(taskId); } -void ItemMenu_Cancel(u8 taskId) +static void ItemMenu_Cancel(u8 taskId) { s16* data = gTasks[taskId].data; - BagMenu_RemoveSomeWindow(); - BagMenu_PrintDescription(data[1]); + RemoveContextWindow(); + PrintItemDescription(tListPosition); ScheduleBgCopyTilemapToVram(0); ScheduleBgCopyTilemapToVram(1); - BagMenu_PrintCursor_(data[0], 0); - set_callback3_to_bag(taskId); + BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL); + ReturnToItemList(taskId); } -void ItemMenu_UseInBattle(u8 taskId) +static void ItemMenu_UseInBattle(u8 taskId) { if (ItemId_GetBattleFunc(gSpecialVar_ItemId)) { - BagMenu_RemoveSomeWindow(); + RemoveContextWindow(); ItemId_GetBattleFunc(gSpecialVar_ItemId)(taskId); } } @@ -1922,39 +1997,40 @@ void CB2_ReturnToBagMenuPocket(void) GoToBagMenu(ITEMMENULOCATION_LAST, POCKETS_COUNT, NULL); } -void Task_ItemContext_FieldGive(u8 taskId) +static void Task_ItemContext_GiveToParty(u8 taskId) { if (!IsWritingMailAllowed(gSpecialVar_ItemId)) { - DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350); + DisplayItemMessage(taskId, 1, gText_CantWriteMail, HandleErrorMessage); } - else if (!sub_8122148(gSpecialVar_ItemId)) + else if (!IsHoldingItemAllowed(gSpecialVar_ItemId)) { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeldHere); - DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD350); + DisplayItemMessage(taskId, 1, gStringVar4, HandleErrorMessage); } - else if (gBagPositionStruct.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId)) + else if (gBagPosition.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId)) { Task_FadeAndCloseBagMenu(taskId); } else { - BagMenu_PrintItemCantBeHeld(taskId); + PrintItemCantBeHeld(taskId); } } -void Task_ItemContext_ItemPC_2(u8 taskId) +// Selected item to give to a Pokémon in PC storage +static void Task_ItemContext_GiveToPC(u8 taskId) { if (ItemIsMail(gSpecialVar_ItemId) == TRUE) - DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350); - else if (gBagPositionStruct.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId)) + DisplayItemMessage(taskId, 1, gText_CantWriteMail, HandleErrorMessage); + else if (gBagPosition.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId)) gTasks[taskId].func = Task_FadeAndCloseBagMenu; else - BagMenu_PrintItemCantBeHeld(taskId); + PrintItemCantBeHeld(taskId); } -#define tUsingRegisteredKeyItem data[3] +#define tUsingRegisteredKeyItem data[3] // See usage in item_use.c bool8 UseRegisteredKeyItemOnField(void) { @@ -1988,7 +2064,7 @@ bool8 UseRegisteredKeyItemOnField(void) #undef tUsingRegisteredKeyItem -void Task_ItemContext_Sell(u8 taskId) +static void Task_ItemContext_Sell(u8 taskId) { s16* data = gTasks[taskId].data; @@ -1996,12 +2072,12 @@ void Task_ItemContext_Sell(u8 taskId) { CopyItemName(gSpecialVar_ItemId, gStringVar2); StringExpandPlaceholders(gStringVar4, gText_CantBuyKeyItem); - DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage); } else { tItemCount = 1; - if (data[2] == 1) + if (tQuantity == 1) { DisplayCurrentMoneyWindow(); DisplaySellItemPriceAndConfirm(taskId); @@ -2010,7 +2086,7 @@ void Task_ItemContext_Sell(u8 taskId) { CopyItemName(gSpecialVar_ItemId, gStringVar2); StringExpandPlaceholders(gStringVar4, gText_HowManyToSell); - DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD730); + DisplayItemMessage(taskId, 1, gStringVar4, InitSellHowManyInput); } } } @@ -2021,114 +2097,114 @@ static void DisplaySellItemPriceAndConfirm(u8 taskId) ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, 6); StringExpandPlaceholders(gStringVar4, gText_ICanPayVar1); - DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD6E4); + DisplayItemMessage(taskId, 1, gStringVar4, AskSellItems); } -void sub_81AD6E4(u8 taskId) +static void AskSellItems(u8 taskId) { - BagMenu_YesNo(taskId, 6, &sYesNoSellItemFunctions); + BagMenu_YesNo(taskId, ITEMWIN_YESNO_HIGH, &sYesNoSellItemFunctions); } -void BagMenu_CancelSell(u8 taskId) +static void CancelSell(u8 taskId) { s16* data = gTasks[taskId].data; RemoveMoneyWindow(); - BagMenu_RemoveBagItemMessageWindow(4); - BagMenu_PrintCursor_(data[0], 0); - set_callback3_to_bag(taskId); + RemoveItemMessageWindow(ITEMWIN_MESSAGE); + BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL); + ReturnToItemList(taskId); } -void sub_81AD730(u8 taskId) +static void InitSellHowManyInput(u8 taskId) { s16* data = gTasks[taskId].data; - u8 windowId = BagMenu_AddWindow(8); + u8 windowId = BagMenu_AddWindow(ITEMWIN_QUANTITY_WIDE); PrintItemSoldAmount(windowId, 1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount); DisplayCurrentMoneyWindow(); - gTasks[taskId].func = Task_SellHowManyDialogueHandleInput; + gTasks[taskId].func = Task_ChooseHowManyToSell; } -static void Task_SellHowManyDialogueHandleInput(u8 taskId) +static void Task_ChooseHowManyToSell(u8 taskId) { s16* data = gTasks[taskId].data; - if (AdjustQuantityAccordingToDPadInput(&tItemCount, data[2]) == TRUE) + if (AdjustQuantityAccordingToDPadInput(&tItemCount, tQuantity) == TRUE) { - PrintItemSoldAmount(gBagMenu->windowPointers[8], tItemCount, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount); + PrintItemSoldAmount(gBagMenu->windowIds[ITEMWIN_QUANTITY_WIDE], tItemCount, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount); } else if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); - BagMenu_RemoveWindow(8); + BagMenu_RemoveWindow(ITEMWIN_QUANTITY_WIDE); DisplaySellItemPriceAndConfirm(taskId); } else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - BagMenu_PrintCursor_(data[0], 0); + BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL); RemoveMoneyWindow(); - BagMenu_RemoveWindow(8); - BagMenu_RemoveBagItemMessageWindow(4); - set_callback3_to_bag(taskId); + BagMenu_RemoveWindow(ITEMWIN_QUANTITY_WIDE); + RemoveItemMessageWindow(ITEMWIN_MESSAGE); + ReturnToItemList(taskId); } } -void BagMenu_ConfirmSell(u8 taskId) +static void ConfirmSell(u8 taskId) { s16* data = gTasks[taskId].data; CopyItemName(gSpecialVar_ItemId, gStringVar2); ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, 6); StringExpandPlaceholders(gStringVar4, gText_TurnedOverVar1ForVar2); - DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_Sell_UpdateItemListAndMoney); + DisplayItemMessage(taskId, 1, gStringVar4, SellItem); } -static void BagMenu_Sell_UpdateItemListAndMoney(u8 taskId) +static void SellItem(u8 taskId) { s16* data = gTasks[taskId].data; - u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]; - u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; + u16* scrollPos = &gBagPosition.scrollPosition[gBagPosition.pocket]; + u16* cursorPos = &gBagPosition.cursorPosition[gBagPosition.pocket]; PlaySE(SE_SHOP); RemoveBagItem(gSpecialVar_ItemId, tItemCount); AddMoney(&gSaveBlock1Ptr->money, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount); - DestroyListMenuTask(data[0], scrollPos, cursorPos); - UpdatePocketItemList(gBagPositionStruct.pocket); - SetInitialScrollAndCursorPositions(gBagPositionStruct.pocket); - LoadBagItemListBuffers(gBagPositionStruct.pocket); - data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); - BagMenu_PrintCursor_(data[0], 2); - PrintMoneyAmountInMoneyBox(gBagMenu->windowPointers[9], GetMoney(&gSaveBlock1Ptr->money), 0); - gTasks[taskId].func = BagMenu_Sell_WaitForABPress; + DestroyListMenuTask(tListTaskId, scrollPos, cursorPos); + UpdatePocketItemList(gBagPosition.pocket); + UpdatePocketListPosition(gBagPosition.pocket); + LoadBagItemListBuffers(gBagPosition.pocket); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); + BagMenu_PrintCursor(tListTaskId, COLORID_GRAY_CURSOR); + PrintMoneyAmountInMoneyBox(gBagMenu->windowIds[ITEMWIN_MONEY], GetMoney(&gSaveBlock1Ptr->money), 0); + gTasks[taskId].func = WaitAfterItemSell; } -static void BagMenu_Sell_WaitForABPress(u8 taskId) +static void WaitAfterItemSell(u8 taskId) { if (JOY_NEW(A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); RemoveMoneyWindow(); - BagMenu_InitListsMenu(taskId); + CloseItemMessage(taskId); } } -void Task_ItemContext_Deposit(u8 taskId) +static void Task_ItemContext_Deposit(u8 taskId) { s16* data = gTasks[taskId].data; tItemCount = 1; - if (data[2] == 1) + if (tQuantity == 1) { - BagMenu_TryDepositItem(taskId); + TryDepositItem(taskId); } else { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_DepositHowManyVar1); - FillWindowPixelBuffer(1, PIXEL_FILL(0)); - BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); - sub_81ABC3C(7); + FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0)); + BagMenu_Print(WIN_DESCRIPTION, 1, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL); + AddItemQuantityWindow(ITEMWIN_QUANTITY); gTasks[taskId].func = Task_ChooseHowManyToDeposit; } } @@ -2137,100 +2213,103 @@ static void Task_ChooseHowManyToDeposit(u8 taskId) { s16* data = gTasks[taskId].data; - if (AdjustQuantityAccordingToDPadInput(&tItemCount, data[2]) == TRUE) + if (AdjustQuantityAccordingToDPadInput(&tItemCount, tQuantity) == TRUE) { - PrintItemDepositAmount(gBagMenu->windowPointers[7], tItemCount); + PrintItemQuantity(gBagMenu->windowIds[ITEMWIN_QUANTITY], tItemCount); } else if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); - BagMenu_RemoveWindow(7); - BagMenu_TryDepositItem(taskId); + BagMenu_RemoveWindow(ITEMWIN_QUANTITY); + TryDepositItem(taskId); } else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); - BagMenu_PrintDescription(data[1]); - BagMenu_PrintCursor_(data[0], 0); - BagMenu_RemoveWindow(7); - set_callback3_to_bag(taskId); + PrintItemDescription(tListPosition); + BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL); + BagMenu_RemoveWindow(ITEMWIN_QUANTITY); + ReturnToItemList(taskId); } } -static void BagMenu_TryDepositItem(u8 taskId) +static void TryDepositItem(u8 taskId) { s16* data = gTasks[taskId].data; - FillWindowPixelBuffer(1, PIXEL_FILL(0)); + FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0)); if (ItemId_GetImportance(gSpecialVar_ItemId)) { - BagMenu_Print(1, 1, gText_CantStoreImportantItems, 3, 1, 0, 0, 0, 0); - gTasks[taskId].func = BagMenu_Deposit_WaitForABPress; + // Can't deposit important items + BagMenu_Print(WIN_DESCRIPTION, 1, gText_CantStoreImportantItems, 3, 1, 0, 0, 0, COLORID_NORMAL); + gTasks[taskId].func = WaitDepositErrorMessage; } else if (AddPCItem(gSpecialVar_ItemId, tItemCount) == TRUE) { + // Successfully deposited CopyItemName(gSpecialVar_ItemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_ITEM_DIGITS); StringExpandPlaceholders(gStringVar4, gText_DepositedVar2Var1s); - BagMenu_Print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); - gTasks[taskId].func = Task_ActuallyToss; + BagMenu_Print(WIN_DESCRIPTION, 1, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL); + gTasks[taskId].func = Task_RemoveItemFromBag; } else { - BagMenu_Print(1, 1, gText_NoRoomForItems, 3, 1, 0, 0, 0, 0); - gTasks[taskId].func = BagMenu_Deposit_WaitForABPress; + // No room to deposit + BagMenu_Print(WIN_DESCRIPTION, 1, gText_NoRoomForItems, 3, 1, 0, 0, 0, COLORID_NORMAL); + gTasks[taskId].func = WaitDepositErrorMessage; } } -static void BagMenu_Deposit_WaitForABPress(u8 taskId) +static void WaitDepositErrorMessage(u8 taskId) { s16* data = gTasks[taskId].data; if (JOY_NEW(A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); - BagMenu_PrintDescription(data[1]); - BagMenu_PrintCursor_(data[0], 0); - set_callback3_to_bag(taskId); + PrintItemDescription(tListPosition); + BagMenu_PrintCursor(tListTaskId, COLORID_NORMAL); + ReturnToItemList(taskId); } } -bool8 IsWallysBag(void) +static bool8 IsWallysBag(void) { - if (gBagPositionStruct.location == 10) + if (gBagPosition.location == ITEMMENULOCATION_WALLY) return TRUE; return FALSE; } -void PrepareBagForWallyTutorial(void) +static void PrepareBagForWallyTutorial(void) { u32 i; - sTempWallyBag = AllocZeroed(sizeof(struct TempWallyStruct)); + sTempWallyBag = AllocZeroed(sizeof(*sTempWallyBag)); memcpy(sTempWallyBag->bagPocket_Items, gSaveBlock1Ptr->bagPocket_Items, sizeof(gSaveBlock1Ptr->bagPocket_Items)); memcpy(sTempWallyBag->bagPocket_PokeBalls, gSaveBlock1Ptr->bagPocket_PokeBalls, sizeof(gSaveBlock1Ptr->bagPocket_PokeBalls)); - sTempWallyBag->pocket = gBagPositionStruct.pocket; - for (i = 0; i <= 4; i++) + sTempWallyBag->pocket = gBagPosition.pocket; + for (i = 0; i < POCKETS_COUNT; i++) { - sTempWallyBag->cursorPosition[i] = gBagPositionStruct.cursorPosition[i]; - sTempWallyBag->scrollPosition[i] = gBagPositionStruct.scrollPosition[i]; + sTempWallyBag->cursorPosition[i] = gBagPosition.cursorPosition[i]; + sTempWallyBag->scrollPosition[i] = gBagPosition.scrollPosition[i]; } ClearItemSlots(gSaveBlock1Ptr->bagPocket_Items, BAG_ITEMS_COUNT); ClearItemSlots(gSaveBlock1Ptr->bagPocket_PokeBalls, BAG_POKEBALLS_COUNT); ResetBagScrollPositions(); } -void RestoreBagAfterWallyTutorial(void) +static void RestoreBagAfterWallyTutorial(void) { u32 i; memcpy(gSaveBlock1Ptr->bagPocket_Items, sTempWallyBag->bagPocket_Items, sizeof(sTempWallyBag->bagPocket_Items)); memcpy(gSaveBlock1Ptr->bagPocket_PokeBalls, sTempWallyBag->bagPocket_PokeBalls, sizeof(sTempWallyBag->bagPocket_PokeBalls)); - gBagPositionStruct.pocket = sTempWallyBag->pocket; - for (i = 0; i <= 4; i++) + gBagPosition.pocket = sTempWallyBag->pocket; + for (i = 0; i < POCKETS_COUNT; i++) { - gBagPositionStruct.cursorPosition[i] = sTempWallyBag->cursorPosition[i]; - gBagPositionStruct.scrollPosition[i] = sTempWallyBag->scrollPosition[i]; + gBagPosition.cursorPosition[i] = sTempWallyBag->cursorPosition[i]; + gBagPosition.scrollPosition[i] = sTempWallyBag->scrollPosition[i]; } Free(sTempWallyBag); } @@ -2243,86 +2322,93 @@ void DoWallyTutorialBagMenu(void) GoToBagMenu(ITEMMENULOCATION_WALLY, ITEMS_POCKET, CB2_SetUpReshowBattleScreenAfterMenu2); } -void Task_WallyTutorialBagMenu(u8 taskId) +#define tTimer data[8] +#define WALLY_BAG_DELAY 102 // The number of frames between each action Wally takes in the bag + +static void Task_WallyTutorialBagMenu(u8 taskId) { s16* data = gTasks[taskId].data; if (!gPaletteFade.active) { - switch (data[8]) + switch (tTimer) { - case 0x66: - PlaySE(SE_SELECT); - SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, 0); - data[8]++; - break; - case 0xCC: - PlaySE(SE_SELECT); - BagMenu_PrintCursor_(data[0], 2); - gSpecialVar_ItemId = ITEM_POKE_BALL; - OpenContextMenu(taskId); - data[8]++; - break; - case 0x132: - PlaySE(SE_SELECT); - BagMenu_RemoveSomeWindow(); - DestroyListMenuTask(data[0], 0, 0); - RestoreBagAfterWallyTutorial(); - Task_FadeAndCloseBagMenu(taskId); - break; - default: - data[8]++; - break; + case WALLY_BAG_DELAY * 1: + PlaySE(SE_SELECT); + SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, FALSE); + tTimer++; + break; + case WALLY_BAG_DELAY * 2: + PlaySE(SE_SELECT); + BagMenu_PrintCursor(tListTaskId, COLORID_GRAY_CURSOR); + gSpecialVar_ItemId = ITEM_POKE_BALL; + OpenContextMenu(taskId); + tTimer++; + break; + case WALLY_BAG_DELAY * 3: + PlaySE(SE_SELECT); + RemoveContextWindow(); + DestroyListMenuTask(tListTaskId, 0, 0); + RestoreBagAfterWallyTutorial(); + Task_FadeAndCloseBagMenu(taskId); + break; + default: + tTimer++; + break; } } } -#undef tItemCount +#undef tTimer -void unknown_ItemMenu_Show(u8 taskId) +// This action is used to show the Apprentice an item when +// they ask what item they should make their Pokémon hold +static void ItemMenu_Show(u8 taskId) { gSpecialVar_0x8005 = gSpecialVar_ItemId; - gSpecialVar_Result = 1; - BagMenu_RemoveSomeWindow(); + gSpecialVar_Result = TRUE; + RemoveContextWindow(); Task_FadeAndCloseBagMenu(taskId); } -void CB2_ApprenticeExitBagMenu(void) +static void CB2_ApprenticeExitBagMenu(void) { gFieldCallback = Apprentice_EnableBothScriptContexts; SetMainCallback2(CB2_ReturnToField); } -void unknown_ItemMenu_Give2(u8 taskId) +static void ItemMenu_GiveFavorLady(u8 taskId) { RemoveBagItem(gSpecialVar_ItemId, 1); - gSpecialVar_Result = 1; - BagMenu_RemoveSomeWindow(); + gSpecialVar_Result = TRUE; + RemoveContextWindow(); Task_FadeAndCloseBagMenu(taskId); } -void CB2_FavorLadyExitBagMenu(void) +static void CB2_FavorLadyExitBagMenu(void) { gFieldCallback = FieldCallback_FavorLadyEnableScriptContexts; SetMainCallback2(CB2_ReturnToField); } -void unknown_ItemMenu_Confirm2(u8 taskId) +// This action is used to confirm which item to use as +// a prize for a custom quiz with the Lilycove Quiz Lady +static void ItemMenu_ConfirmQuizLady(u8 taskId) { - gSpecialVar_Result = 1; - BagMenu_RemoveSomeWindow(); + gSpecialVar_Result = TRUE; + RemoveContextWindow(); Task_FadeAndCloseBagMenu(taskId); } -void CB2_QuizLadyExitBagMenu(void) +static void CB2_QuizLadyExitBagMenu(void) { gFieldCallback = FieldCallback_QuizLadyEnableScriptContexts; SetMainCallback2(CB2_ReturnToField); } -void BagMenu_PrintPocketNames(const u8 *pocketName1, const u8 *pocketName2) +static void PrintPocketNames(const u8 *pocketName1, const u8 *pocketName2) { - struct WindowTemplate window = {0, 0, 0, 0, 0, 0, 0}; + struct WindowTemplate window = {0}; u16 windowId; int offset; @@ -2331,32 +2417,32 @@ void BagMenu_PrintPocketNames(const u8 *pocketName1, const u8 *pocketName2) windowId = AddWindow(&window); FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); offset = GetStringCenterAlignXOffset(1, pocketName1, 0x40); - BagMenu_Print(windowId, 1, pocketName1, offset, 1, 0, 0, -1, 1); + BagMenu_Print(windowId, 1, pocketName1, offset, 1, 0, 0, TEXT_SPEED_FF, COLORID_POCKET_NAME); if (pocketName2) { offset = GetStringCenterAlignXOffset(1, pocketName2, 0x40); - BagMenu_Print(windowId, 1, pocketName2, offset + 0x40, 1, 0, 0, -1, 1); + BagMenu_Print(windowId, 1, pocketName2, offset + 0x40, 1, 0, 0, TEXT_SPEED_FF, COLORID_POCKET_NAME); } - CpuCopy32((u8*)GetWindowAttribute(windowId, WINDOW_TILE_DATA), gBagMenu->pocketNameBuffer, 0x400); + CpuCopy32((u8*)GetWindowAttribute(windowId, WINDOW_TILE_DATA), gBagMenu->pocketNameBuffer, sizeof(gBagMenu->pocketNameBuffer)); RemoveWindow(windowId); } -void BagMenu_CopyPocketNameToWindow(u32 a) +static void CopyPocketNameToWindow(u32 a) { - u8 (* r4)[32][32]; - u8* windowAttribute; + u8 (* tileDataBuffer)[32][32]; + u8* windowTileData; int b; if (a > 8) a = 8; - r4 = &gBagMenu->pocketNameBuffer; - windowAttribute = (u8*)GetWindowAttribute(2, WINDOW_TILE_DATA); - CpuCopy32(r4[0][a], windowAttribute, 0x100); + tileDataBuffer = &gBagMenu->pocketNameBuffer; + windowTileData = (u8*)GetWindowAttribute(2, WINDOW_TILE_DATA); + CpuCopy32(tileDataBuffer[0][a], windowTileData, 0x100); // Top half of pocket name b = a + 16; - CpuCopy32(r4[0][b], windowAttribute + 0x100, 0x100); - CopyWindowToVram(2, 2); + CpuCopy32(tileDataBuffer[0][b], windowTileData + 0x100, 0x100); // Bottom half of pocket name + CopyWindowToVram(WIN_POCKET_NAME, 2); } -void SetupBagMenu_Textboxes(void) +static void LoadBagMenuTextWindows(void) { u8 i; @@ -2366,7 +2452,7 @@ void SetupBagMenu_Textboxes(void) LoadMessageBoxGfx(0, 10, 0xD0); ListMenuLoadStdPalAt(0xC0, 1); LoadPalette(&gUnknown_0860F074, 0xF0, 0x20); - for (i = 0; i < 3; i++) + for (i = 0; i <= WIN_POCKET_NAME; i++) { FillWindowPixelBuffer(i, PIXEL_FILL(0)); PutWindowTilemap(i); @@ -2375,109 +2461,111 @@ void SetupBagMenu_Textboxes(void) ScheduleBgCopyTilemapToVram(1); } -void BagMenu_Print(u8 windowId, u8 fontId, const u8 *str, u8 left, u8 top, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 colorIndex) +static void BagMenu_Print(u8 windowId, u8 fontId, const u8 *str, u8 left, u8 top, u8 letterSpacing, u8 lineSpacing, u8 speed, u8 colorIndex) { AddTextPrinterParameterized4(windowId, fontId, left, top, letterSpacing, lineSpacing, sFontColorTable[colorIndex], speed, str); } -//Unused -u8 sub_81AE124(u8 which) +// Unused +static u8 BagMenu_GetWindowId(u8 windowType) { - return gBagMenu->windowPointers[which]; + return gBagMenu->windowIds[windowType]; } -u8 BagMenu_AddWindow(u8 which) +static u8 BagMenu_AddWindow(u8 windowType) { - u8 *ptr = &gBagMenu->windowPointers[which]; - if (*ptr == WINDOW_NONE) + u8 *windowId = &gBagMenu->windowIds[windowType]; + if (*windowId == WINDOW_NONE) { - *ptr = AddWindow(&sContextMenuWindowTemplates[which]); - DrawStdFrameWithCustomTileAndPalette(*ptr, 0, 1, 14); + *windowId = AddWindow(&sContextMenuWindowTemplates[windowType]); + DrawStdFrameWithCustomTileAndPalette(*windowId, 0, 1, 14); ScheduleBgCopyTilemapToVram(1); } - return *ptr; + return *windowId; } -void BagMenu_RemoveWindow(u8 which) +static void BagMenu_RemoveWindow(u8 windowType) { - u8 *ptr = &gBagMenu->windowPointers[which]; - if (*ptr != WINDOW_NONE) + u8 *windowId = &gBagMenu->windowIds[windowType]; + if (*windowId != WINDOW_NONE) { - ClearStdWindowAndFrameToTransparent(*ptr, FALSE); - ClearWindowTilemap(*ptr); - RemoveWindow(*ptr); + ClearStdWindowAndFrameToTransparent(*windowId, FALSE); + ClearWindowTilemap(*windowId); + RemoveWindow(*windowId); ScheduleBgCopyTilemapToVram(1); - *ptr = WINDOW_NONE; + *windowId = WINDOW_NONE; } } -u8 AddItemMessageWindow(u8 which) +static u8 AddItemMessageWindow(u8 windowType) { - u8 *ptr = &gBagMenu->windowPointers[which]; - if (*ptr == WINDOW_NONE) - *ptr = AddWindow(&sContextMenuWindowTemplates[which]); - return *ptr; + u8 *windowId = &gBagMenu->windowIds[windowType]; + if (*windowId == WINDOW_NONE) + *windowId = AddWindow(&sContextMenuWindowTemplates[windowType]); + return *windowId; } -void BagMenu_RemoveBagItemMessageWindow(u8 which) +static void RemoveItemMessageWindow(u8 windowType) { - u8 *ptr = &gBagMenu->windowPointers[which]; - if (*ptr != WINDOW_NONE) + u8 *windowId = &gBagMenu->windowIds[windowType]; + if (*windowId != WINDOW_NONE) { - ClearDialogWindowAndFrameToTransparent(*ptr, FALSE); + ClearDialogWindowAndFrameToTransparent(*windowId, FALSE); // This ClearWindowTilemap call is redundant, since ClearDialogWindowAndFrameToTransparent already calls it. - ClearWindowTilemap(*ptr); - RemoveWindow(*ptr); + ClearWindowTilemap(*windowId); + RemoveWindow(*windowId); ScheduleBgCopyTilemapToVram(1); - *ptr = WINDOW_NONE; + *windowId = WINDOW_NONE; } } -void BagMenu_YesNo(u8 a, u8 b, const struct YesNoFuncTable *funcTable) +void BagMenu_YesNo(u8 taskId, u8 windowType, const struct YesNoFuncTable *funcTable) { - CreateYesNoMenuWithCallbacks(a, &sContextMenuWindowTemplates[b], 1, 0, 2, 1, 14, funcTable); + CreateYesNoMenuWithCallbacks(taskId, &sContextMenuWindowTemplates[windowType], 1, 0, 2, 1, 14, funcTable); } static void DisplayCurrentMoneyWindow(void) { - u8 windowId = BagMenu_AddWindow(9); + u8 windowId = BagMenu_AddWindow(ITEMWIN_MONEY); PrintMoneyAmountInMoneyBoxWithBorder(windowId, 1, 14, GetMoney(&gSaveBlock1Ptr->money)); AddMoneyLabelObject(19, 11); } static void RemoveMoneyWindow(void) { - BagMenu_RemoveWindow(9); + BagMenu_RemoveWindow(ITEMWIN_MONEY); RemoveMoneyLabelObject(); } -void BagMenu_PrepareTMHMMoveWindow(void) +static void PrepareTMHMMoveWindow(void) { - FillWindowPixelBuffer(3, PIXEL_FILL(0)); - BlitMenuInfoIcon(3, MENU_INFO_ICON_TYPE, 0, 0); - BlitMenuInfoIcon(3, MENU_INFO_ICON_POWER, 0, 12); - BlitMenuInfoIcon(3, MENU_INFO_ICON_ACCURACY, 0, 24); - BlitMenuInfoIcon(3, MENU_INFO_ICON_PP, 0, 36); - CopyWindowToVram(3, 2); + FillWindowPixelBuffer(WIN_TMHM_INFO_ICONS, PIXEL_FILL(0)); + BlitMenuInfoIcon(WIN_TMHM_INFO_ICONS, MENU_INFO_ICON_TYPE, 0, 0); + BlitMenuInfoIcon(WIN_TMHM_INFO_ICONS, MENU_INFO_ICON_POWER, 0, 12); + BlitMenuInfoIcon(WIN_TMHM_INFO_ICONS, MENU_INFO_ICON_ACCURACY, 0, 24); + BlitMenuInfoIcon(WIN_TMHM_INFO_ICONS, MENU_INFO_ICON_PP, 0, 36); + CopyWindowToVram(WIN_TMHM_INFO_ICONS, 2); } -void PrintTMHMMoveData(u16 itemId) +static void PrintTMHMMoveData(u16 itemId) { u8 i; u16 moveId; const u8* text; - FillWindowPixelBuffer(4, PIXEL_FILL(0)); + FillWindowPixelBuffer(WIN_TMHM_INFO, PIXEL_FILL(0)); if (itemId == ITEM_NONE) { for (i = 0; i < 4; i++) - BagMenu_Print(4, 1, gText_ThreeDashes, 7, i * 12, 0, 0, -1, 4); - CopyWindowToVram(4, 2); + BagMenu_Print(WIN_TMHM_INFO, 1, gText_ThreeDashes, 7, i * 12, 0, 0, TEXT_SPEED_FF, COLORID_TMHM_INFO); + CopyWindowToVram(WIN_TMHM_INFO, 2); } else { moveId = ItemIdToBattleMoveId(itemId); - BlitMenuInfoIcon(4, gBattleMoves[moveId].type + 1, 0, 0); + BlitMenuInfoIcon(WIN_TMHM_INFO, gBattleMoves[moveId].type + 1, 0, 0); + + // Print TMHM power if (gBattleMoves[moveId].power <= 1) { text = gText_ThreeDashes; @@ -2487,7 +2575,9 @@ void PrintTMHMMoveData(u16 itemId) ConvertIntToDecimalStringN(gStringVar1, gBattleMoves[moveId].power, STR_CONV_MODE_RIGHT_ALIGN, 3); text = gStringVar1; } - BagMenu_Print(4, 1, text, 7, 12, 0, 0, -1, 4); + BagMenu_Print(WIN_TMHM_INFO, 1, text, 7, 12, 0, 0, TEXT_SPEED_FF, COLORID_TMHM_INFO); + + // Print TMHM accuracy if (gBattleMoves[moveId].accuracy == 0) { text = gText_ThreeDashes; @@ -2497,9 +2587,12 @@ void PrintTMHMMoveData(u16 itemId) ConvertIntToDecimalStringN(gStringVar1, gBattleMoves[moveId].accuracy, STR_CONV_MODE_RIGHT_ALIGN, 3); text = gStringVar1; } - BagMenu_Print(4, 1, text, 7, 24, 0, 0, -1, 4); + BagMenu_Print(WIN_TMHM_INFO, 1, text, 7, 24, 0, 0, TEXT_SPEED_FF, COLORID_TMHM_INFO); + + // Print TMHM pp ConvertIntToDecimalStringN(gStringVar1, gBattleMoves[moveId].pp, STR_CONV_MODE_RIGHT_ALIGN, 3); - BagMenu_Print(4, 1, gStringVar1, 7, 36, 0, 0, -1, 4); - CopyWindowToVram(4, 2); + BagMenu_Print(WIN_TMHM_INFO, 1, gStringVar1, 7, 36, 0, 0, TEXT_SPEED_FF, COLORID_TMHM_INFO); + + CopyWindowToVram(WIN_TMHM_INFO, 2); } } diff --git a/src/item_menu_icons.c b/src/item_menu_icons.c index 5c0849eef..c8d1cd8d0 100644 --- a/src/item_menu_icons.c +++ b/src/item_menu_icons.c @@ -11,6 +11,15 @@ #include "window.h" #include "constants/items.h" +enum { + TAG_BAG_GFX = 100, + TAG_ROTATING_BALL_GFX, + TAG_ITEM_ICON, + TAG_ITEM_ICON_ALT, +}; +#define TAG_BERRY_CHECK_CIRCLE_GFX 10000 +#define TAG_BERRY_PIC_PAL 30020 + struct CompressedTilesPal { const u32 *tiles; @@ -128,7 +137,7 @@ const struct CompressedSpritePalette gBagPaletteTable = gBagPalette, TAG_BAG_GFX }; -static const struct SpriteTemplate gBagSpriteTemplate = +static const struct SpriteTemplate sBagSpriteTemplate = { .tileTag = TAG_BAG_GFX, .paletteTag = TAG_BAG_GFX, @@ -189,17 +198,17 @@ static const union AffineAnimCmd *const sRotatingBallAnimCmds_FullRotation[] = sSpriteAffineAnim_RotatingBallRotation2, }; -static const struct SpriteSheet gRotatingBallTable = +static const struct SpriteSheet sRotatingBallTable = { gRotatingBall, 0x80, TAG_ROTATING_BALL_GFX }; -static const struct SpritePalette gRotatingBallPaletteTable = +static const struct SpritePalette sRotatingBallPaletteTable = { gRotatingBall_Pal, TAG_ROTATING_BALL_GFX }; -static const struct SpriteTemplate gRotatingBallSpriteTemplate = +static const struct SpriteTemplate sRotatingBallSpriteTemplate = { .tileTag = TAG_ROTATING_BALL_GFX, .paletteTag = TAG_ROTATING_BALL_GFX, @@ -262,7 +271,7 @@ static const struct SpriteFrameImage sBerryPicSpriteImageTable[] = static const struct SpriteTemplate gBerryPicSpriteTemplate = { - .tileTag = TAG_BERRY_PIC_TILE, + .tileTag = 0xFFFF, .paletteTag = TAG_BERRY_PIC_PAL, .oam = &sBerryPicOamData, .anims = sBerryPicSpriteAnimTable, @@ -301,7 +310,7 @@ static const union AffineAnimCmd *const sBerryPicRotatingAnimCmds[] = static const struct SpriteTemplate gBerryPicRotatingSpriteTemplate = { - .tileTag = TAG_BERRY_PIC_TILE, + .tileTag = 0xFFFF, .paletteTag = TAG_BERRY_PIC_PAL, .oam = &sBerryPicRotatingOamData, .anims = sBerryPicSpriteAnimTable, @@ -409,11 +418,11 @@ static const struct SpriteTemplate gBerryCheckCircleSpriteTemplate = // code void RemoveBagSprite(u8 id) { - u8 *spriteId = &gBagMenu->spriteId[id]; + u8 *spriteId = &gBagMenu->spriteIds[id]; if (*spriteId != SPRITE_NONE) { - FreeSpriteTilesByTag(id + 100); - FreeSpritePaletteByTag(id + 100); + FreeSpriteTilesByTag(id + TAG_BAG_GFX); + FreeSpritePaletteByTag(id + TAG_BAG_GFX); FreeSpriteOamMatrix(&gSprites[*spriteId]); DestroySprite(&gSprites[*spriteId]); *spriteId = SPRITE_NONE; @@ -422,14 +431,14 @@ void RemoveBagSprite(u8 id) void AddBagVisualSprite(u8 bagPocketId) { - u8 *spriteId = &gBagMenu->spriteId[0]; - *spriteId = CreateSprite(&gBagSpriteTemplate, 68, 66, 0); + u8 *spriteId = &gBagMenu->spriteIds[ITEMMENUSPRITE_BAG]; + *spriteId = CreateSprite(&sBagSpriteTemplate, 68, 66, 0); SetBagVisualPocketId(bagPocketId, FALSE); } void SetBagVisualPocketId(u8 bagPocketId, bool8 isSwitchingPockets) { - struct Sprite *sprite = &gSprites[gBagMenu->spriteId[0]]; + struct Sprite *sprite = &gSprites[gBagMenu->spriteIds[ITEMMENUSPRITE_BAG]]; if (isSwitchingPockets) { sprite->y2 = -5; @@ -458,7 +467,7 @@ static void SpriteCB_BagVisualSwitchingPockets(struct Sprite *sprite) void ShakeBagSprite(void) { - struct Sprite *sprite = &gSprites[gBagMenu->spriteId[0]]; + struct Sprite *sprite = &gSprites[gBagMenu->spriteIds[ITEMMENUSPRITE_BAG]]; if (sprite->affineAnimEnded) { StartSpriteAffineAnim(sprite, 1); @@ -477,10 +486,10 @@ static void SpriteCB_ShakeBagSprite(struct Sprite *sprite) void AddSwitchPocketRotatingBallSprite(s16 rotationDirection) { - u8 *spriteId = &gBagMenu->spriteId[1]; - LoadSpriteSheet(&gRotatingBallTable); - LoadSpritePalette(&gRotatingBallPaletteTable); - *spriteId = CreateSprite(&gRotatingBallSpriteTemplate, 16, 16, 0); + u8 *spriteId = &gBagMenu->spriteIds[ITEMMENUSPRITE_BALL]; + LoadSpriteSheet(&sRotatingBallTable); + LoadSpritePalette(&sRotatingBallPaletteTable); + *spriteId = CreateSprite(&sRotatingBallSpriteTemplate, 16, 16, 0); gSprites[*spriteId].data[0] = rotationDirection; } @@ -510,19 +519,20 @@ static void SpriteCB_SwitchPocketRotatingBallContinue(struct Sprite *sprite) sprite->data[3]++; UpdateSwitchPocketRotatingBallCoords(sprite); if (sprite->data[3] == 16) - RemoveBagSprite(1); + RemoveBagSprite(ITEMMENUSPRITE_BALL); } void AddBagItemIconSprite(u16 itemId, u8 id) { - u8 *spriteId = &gBagMenu->spriteId[id + 2]; + u8 *spriteId = &gBagMenu->spriteIds[id + ITEMMENUSPRITE_ITEM]; if (*spriteId == SPRITE_NONE) { u8 iconSpriteId; - FreeSpriteTilesByTag(id + 102); - FreeSpritePaletteByTag(id + 102); - iconSpriteId = AddItemIconSprite(id + 102, id + 102, itemId); + // Either TAG_ITEM_ICON or TAG_ITEM_ICON_ALT + FreeSpriteTilesByTag(id + TAG_ITEM_ICON); + FreeSpritePaletteByTag(id + TAG_ITEM_ICON); + iconSpriteId = AddItemIconSprite(id + TAG_ITEM_ICON, id + TAG_ITEM_ICON, itemId); if (iconSpriteId != MAX_SPRITES) { *spriteId = iconSpriteId; @@ -534,22 +544,22 @@ void AddBagItemIconSprite(u16 itemId, u8 id) void RemoveBagItemIconSprite(u8 id) { - RemoveBagSprite(id + 2); + RemoveBagSprite(id + ITEMMENUSPRITE_ITEM); } void CreateItemMenuSwapLine(void) { - CreateSwapLineSprites(&gBagMenu->spriteId[4], 8); + CreateSwapLineSprites(&gBagMenu->spriteIds[ITEMMENUSPRITE_SWAP_LINE], ITEMMENU_SWAP_LINE_LENGTH); } void SetItemMenuSwapLineInvisibility(bool8 invisible) { - SetSwapLineSpritesInvisibility(&gBagMenu->spriteId[4], 8, invisible); + SetSwapLineSpritesInvisibility(&gBagMenu->spriteIds[ITEMMENUSPRITE_SWAP_LINE], ITEMMENU_SWAP_LINE_LENGTH, invisible); } void UpdateItemMenuSwapLinePos(u8 y) { - UpdateSwapLineSpritesPos(&gBagMenu->spriteId[4], 136, 120, (y + 1) * 16); + UpdateSwapLineSpritesPos(&gBagMenu->spriteIds[ITEMMENUSPRITE_SWAP_LINE], ITEMMENU_SWAP_LINE_LENGTH | 0x80, 120, (y + 1) * 16); } static void sub_80D5018(void *mem0, void *mem1) diff --git a/src/item_use.c b/src/item_use.c index 0c4e1a5ab..d5d52b07a 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -92,7 +92,7 @@ static const u8 sClockwiseDirections[] = {DIR_NORTH, DIR_EAST, DIR_SOUTH, DIR_WE static const struct YesNoFuncTable sUseTMHMYesNoFuncTable = { .yesFunc = UseTMHM, - .noFunc = BagMenu_InitListsMenu, + .noFunc = CloseItemMessage, }; #define tEnigmaBerryType data[4] @@ -105,12 +105,12 @@ static void SetUpItemUseCallback(u8 taskId) type = ItemId_GetType(gSpecialVar_ItemId) - 1; if (!InBattlePyramid()) { - gBagMenu->exitCallback = sItemUseCallbacks[type]; + gBagMenu->newScreenCallback = sItemUseCallbacks[type]; Task_FadeAndCloseBagMenu(taskId); } else { - gPyramidBagMenu->exitCallback = sItemUseCallbacks[type]; + gPyramidBagMenu->newScreenCallback = sItemUseCallbacks[type]; CloseBattlePyramidBag(taskId); } } @@ -144,7 +144,7 @@ static void DisplayCannotUseItemMessage(u8 taskId, bool8 isUsingRegisteredKeyIte if (!isUsingRegisteredKeyItemOnField) { if (!InBattlePyramid()) - DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage); else DisplayItemMessageInBattlePyramid(taskId, gText_DadsAdvice, Task_CloseBattlePyramidBagMessage); } @@ -190,7 +190,7 @@ static void CB2_CheckMail(void) void ItemUseOutOfBattle_Mail(u8 taskId) { - gBagMenu->exitCallback = CB2_CheckMail; + gBagMenu->newScreenCallback = CB2_CheckMail; Task_FadeAndCloseBagMenu(taskId); } @@ -615,7 +615,7 @@ void ItemUseOutOfBattle_PokeblockCase(u8 taskId) } else if (gTasks[taskId].tUsingRegisteredKeyItem != TRUE) { - gBagMenu->exitCallback = CB2_OpenPokeblockFromBag; + gBagMenu->newScreenCallback = CB2_OpenPokeblockFromBag; Task_FadeAndCloseBagMenu(taskId); } else @@ -648,7 +648,7 @@ void ItemUseOutOfBattle_CoinCase(u8 taskId) if (!gTasks[taskId].tUsingRegisteredKeyItem) { - DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage); } else { @@ -663,7 +663,7 @@ void ItemUseOutOfBattle_PowderJar(u8 taskId) if (!gTasks[taskId].tUsingRegisteredKeyItem) { - DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage); } else { @@ -677,7 +677,7 @@ void ItemUseOutOfBattle_Berry(u8 taskId) { sItemUseOnFieldCB = ItemUseOnFieldCB_Berry; gFieldCallback = FieldCB_UseItemOnField; - gBagMenu->exitCallback = CB2_ReturnToField; + gBagMenu->newScreenCallback = CB2_ReturnToField; Task_FadeAndCloseBagMenu(taskId); } else @@ -802,7 +802,7 @@ static void Task_ShowTMHMContainedMessage(u8 taskId) static void UseTMHMYesNo(u8 taskId) { - BagMenu_YesNo(taskId, 6, &sUseTMHMYesNoFuncTable); + BagMenu_YesNo(taskId, ITEMWIN_YESNO_HIGH, &sUseTMHMYesNoFuncTable); } static void UseTMHM(u8 taskId) @@ -819,7 +819,7 @@ static void RemoveUsedItem(void) if (!InBattlePyramid()) { UpdatePocketItemList(ItemId_GetPocket(gSpecialVar_ItemId)); - SetInitialScrollAndCursorPositions(ItemId_GetPocket(gSpecialVar_ItemId)); + UpdatePocketListPosition(ItemId_GetPocket(gSpecialVar_ItemId)); } else { @@ -833,7 +833,7 @@ void ItemUseOutOfBattle_Repel(u8 taskId) if (VarGet(VAR_REPEL_STEP_COUNT) == 0) gTasks[taskId].func = Task_StartUseRepel; else if (!InBattlePyramid()) - DisplayItemMessage(taskId, 1, gText_RepelEffectsLingered, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, gText_RepelEffectsLingered, CloseItemMessage); else DisplayItemMessageInBattlePyramid(taskId, gText_RepelEffectsLingered, Task_CloseBattlePyramidBagMessage); } @@ -857,7 +857,7 @@ static void Task_UseRepel(u8 taskId) VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_ItemId)); RemoveUsedItem(); if (!InBattlePyramid()) - DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage); else DisplayItemMessageInBattlePyramid(taskId, gStringVar4, Task_CloseBattlePyramidBagMessage); } @@ -869,7 +869,7 @@ static void Task_UsedBlackWhiteFlute(u8 taskId) { PlaySE(SE_GLASS_FLUTE); if (!InBattlePyramid()) - DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, gStringVar4, CloseItemMessage); else DisplayItemMessageInBattlePyramid(taskId, gStringVar4, Task_CloseBattlePyramidBagMessage); } @@ -944,7 +944,7 @@ void ItemUseInBattle_PokeBall(u8 taskId) static const u8 textCantThrowPokeBall[] = _("Cannot throw a ball!\nThere are two pokemon out there!\p"); if (!InBattlePyramid()) - DisplayItemMessage(taskId, 1, textCantThrowPokeBall, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, textCantThrowPokeBall, CloseItemMessage); else DisplayItemMessageInBattlePyramid(taskId, textCantThrowPokeBall, Task_CloseBattlePyramidBagMessage); } @@ -954,7 +954,7 @@ void ItemUseInBattle_PokeBall(u8 taskId) static const u8 textCantThrowPokeBall[] = _("Cannot throw a ball!\p"); if (!InBattlePyramid()) - DisplayItemMessage(taskId, 1, textCantThrowPokeBall, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, textCantThrowPokeBall, CloseItemMessage); else DisplayItemMessageInBattlePyramid(taskId, textCantThrowPokeBall, Task_CloseBattlePyramidBagMessage); } @@ -969,7 +969,7 @@ void ItemUseInBattle_PokeBall(u8 taskId) else { if (!InBattlePyramid()) - DisplayItemMessage(taskId, 1, gText_BoxFull, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, gText_BoxFull, CloseItemMessage); else DisplayItemMessageInBattlePyramid(taskId, gText_BoxFull, Task_CloseBattlePyramidBagMessage); } @@ -1007,7 +1007,7 @@ void ItemUseInBattle_StatIncrease(u8 taskId) if (ExecuteTableBasedItemEffect(&gPlayerParty[partyId], gSpecialVar_ItemId, partyId, 0) != FALSE) { if (!InBattlePyramid()) - DisplayItemMessage(taskId, 1, gText_WontHaveEffect, BagMenu_InitListsMenu); + DisplayItemMessage(taskId, 1, gText_WontHaveEffect, CloseItemMessage); else DisplayItemMessageInBattlePyramid(taskId, gText_WontHaveEffect, Task_CloseBattlePyramidBagMessage); } @@ -1022,12 +1022,12 @@ static void ItemUseInBattle_ShowPartyMenu(u8 taskId) { if (!InBattlePyramid()) { - gBagMenu->exitCallback = ChooseMonForInBattleItem; + gBagMenu->newScreenCallback = ChooseMonForInBattleItem; Task_FadeAndCloseBagMenu(taskId); } else { - gPyramidBagMenu->exitCallback = ChooseMonForInBattleItem; + gPyramidBagMenu->newScreenCallback = ChooseMonForInBattleItem; CloseBattlePyramidBag(taskId); } } diff --git a/src/m4a.c b/src/m4a.c index 105312a40..b159e3873 100644 --- a/src/m4a.c +++ b/src/m4a.c @@ -906,7 +906,6 @@ void CgbSound(void) { s32 ch; struct CgbChannel *channels; - s32 envelopeStepTimeAndDir; s32 prevC15; struct SoundInfo *soundInfo = SOUND_INFO_PTR; vu8 *nrx0ptr; @@ -914,6 +913,7 @@ void CgbSound(void) vu8 *nrx2ptr; vu8 *nrx3ptr; vu8 *nrx4ptr; + s32 envelopeStepTimeAndDir; // Most comparision operations that cast to s8 perform 'and' by 0xFF. int mask = 0xff; @@ -1198,8 +1198,8 @@ void CgbSound(void) } else { - envelopeStepTimeAndDir &= 0xf; - *nrx2ptr = (channels->envelopeVolume << 4) + envelopeStepTimeAndDir; + u32 envMask = 0xF; + *nrx2ptr = (envelopeStepTimeAndDir & envMask) + (channels->envelopeVolume << 4); *nrx4ptr = channels->n4 | 0x80; if (ch == 1 && !(*nrx0ptr & 0x08)) *nrx4ptr = channels->n4 | 0x80; diff --git a/src/menu.c b/src/menu.c index 789707960..156a4c332 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1098,32 +1098,32 @@ s8 Menu_ProcessInputNoWrapAround_other(void) return MENU_NOTHING_CHOSEN; } -void PrintTextArray(u8 windowId, u8 fontId, u8 left, u8 top, u8 lineHeight, u8 itemCount, const struct MenuAction *strs) +void PrintTextArray(u8 windowId, u8 fontId, u8 left, u8 top, u8 lineHeight, u8 itemCount, const struct MenuAction *menuActions) { u8 i; for (i = 0; i < itemCount; i++) { - AddTextPrinterParameterized(windowId, fontId, strs[i].text, left, (lineHeight * i) + top, 0xFF, NULL); + AddTextPrinterParameterized(windowId, fontId, menuActions[i].text, left, (lineHeight * i) + top, 0xFF, NULL); } CopyWindowToVram(windowId, 2); } -void sub_81987BC(u8 windowId, u8 fontId, u8 left, u8 top, u8 lineHeight, u8 itemCount, const struct MenuAction *strs, u8 a6, u8 a7) +void sub_81987BC(u8 windowId, u8 fontId, u8 left, u8 top, u8 lineHeight, u8 itemCount, const struct MenuAction *menuActions, u8 a6, u8 a7) { u8 i; for (i = 0; i < itemCount; i++) { - AddTextPrinterParameterized5(windowId, fontId, strs[i].text, left, (lineHeight * i) + top, 0xFF, NULL, a6, a7); + AddTextPrinterParameterized5(windowId, fontId, menuActions[i].text, left, (lineHeight * i) + top, 0xFF, NULL, a6, a7); } CopyWindowToVram(windowId, 2); } -void sub_8198854(u8 windowId, u8 fontId, u8 lineHeight, u8 itemCount, const struct MenuAction *strs) +void sub_8198854(u8 windowId, u8 fontId, u8 lineHeight, u8 itemCount, const struct MenuAction *menuActions) { - PrintTextArray(windowId, fontId, GetFontAttribute(fontId, 0), 1, lineHeight, itemCount, strs); + PrintTextArray(windowId, fontId, GetFontAttribute(fontId, 0), 1, lineHeight, itemCount, menuActions); } -void AddItemMenuActionTextPrinters(u8 windowId, u8 fontId, u8 left, u8 top, u8 letterSpacing, u8 lineHeight, u8 itemCount, const struct MenuAction *strs, const u8 *a8) +void AddItemMenuActionTextPrinters(u8 windowId, u8 fontId, u8 left, u8 top, u8 letterSpacing, u8 lineHeight, u8 itemCount, const struct MenuAction *menuActions, const u8 *actionIds) { u8 i; struct TextPrinterTemplate printer; @@ -1141,7 +1141,7 @@ void AddItemMenuActionTextPrinters(u8 windowId, u8 fontId, u8 left, u8 top, u8 l for (i = 0; i < itemCount; i++) { - printer.currentChar = strs[a8[i]].text; + printer.currentChar = menuActions[actionIds[i]].text; printer.y = (lineHeight * i) + top; printer.currentY = printer.y; AddTextPrinter(&printer, 0xFF, NULL); @@ -1150,9 +1150,9 @@ void AddItemMenuActionTextPrinters(u8 windowId, u8 fontId, u8 left, u8 top, u8 l CopyWindowToVram(windowId, 2); } -void sub_81989B8(u8 windowId, u8 fontId, u8 lineHeight, u8 itemCount, const struct MenuAction *strs, const u8 *a5) +void sub_81989B8(u8 windowId, u8 fontId, u8 lineHeight, u8 itemCount, const struct MenuAction *menuActions, const u8 *actionIds) { - AddItemMenuActionTextPrinters(windowId, fontId, GetFontAttribute(fontId, FONTATTR_MAX_LETTER_WIDTH), 1, GetFontAttribute(fontId, FONTATTR_LETTER_SPACING), lineHeight, itemCount, strs, a5); + AddItemMenuActionTextPrinters(windowId, fontId, GetFontAttribute(fontId, FONTATTR_MAX_LETTER_WIDTH), 1, GetFontAttribute(fontId, FONTATTR_LETTER_SPACING), lineHeight, itemCount, menuActions, actionIds); } void SetWindowTemplateFields(struct WindowTemplate *template, u8 bg, u8 left, u8 top, u8 width, u8 height, u8 paletteNum, u16 baseBlock) @@ -1225,7 +1225,7 @@ void sub_8198C78(void) RemoveWindow(sYesNoWindowId); } -void sub_8198C94(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 a5, u8 a6, u8 a7, const struct MenuAction *strs) +void sub_8198C94(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 a5, u8 a6, u8 a7, const struct MenuAction *menuActions) { u8 i; u8 j; @@ -1233,18 +1233,18 @@ void sub_8198C94(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 a5, u8 a6, u { for (j = 0; j < a6; j++) { - AddTextPrinterParameterized(windowId, fontId, strs[(i * a6) + j].text, (a4 * j) + left, (a5 * i) + top, 0xFF, NULL); + AddTextPrinterParameterized(windowId, fontId, menuActions[(i * a6) + j].text, (a4 * j) + left, (a5 * i) + top, 0xFF, NULL); } } CopyWindowToVram(windowId, 2); } -void sub_8198D54(u8 windowId, u8 fontId, u8 a2, u8 a3, u8 a4, u8 a5, const struct MenuAction *strs) +void sub_8198D54(u8 windowId, u8 fontId, u8 a2, u8 a3, u8 a4, u8 a5, const struct MenuAction *menuActions) { - sub_8198C94(windowId, fontId, GetFontAttribute(fontId, 0), 0, a2, a3, a4, a5, strs); + sub_8198C94(windowId, fontId, GetFontAttribute(fontId, 0), 0, a2, a3, a4, a5, menuActions); } -void PrintMenuActionGrid(u8 windowId, u8 fontId, u8 left, u8 top, u8 optionWidth, u8 horizontalCount, u8 verticalCount, const struct MenuAction *strs, const u8 *strIds) +void PrintMenuActionGrid(u8 windowId, u8 fontId, u8 left, u8 top, u8 optionWidth, u8 horizontalCount, u8 verticalCount, const struct MenuAction *menuActions, const u8 *actionIds) { u8 i; u8 j; @@ -1263,7 +1263,7 @@ void PrintMenuActionGrid(u8 windowId, u8 fontId, u8 left, u8 top, u8 optionWidth { for (j = 0; j < horizontalCount; j++) { - printer.currentChar = strs[strIds[(horizontalCount * i) + j]].text; + printer.currentChar = menuActions[actionIds[(horizontalCount * i) + j]].text; printer.x = (optionWidth * j) + left; printer.y = (GetFontAttribute(fontId, FONTATTR_MAX_LETTER_HEIGHT) * i) + top; printer.currentX = printer.x; @@ -1276,9 +1276,9 @@ void PrintMenuActionGrid(u8 windowId, u8 fontId, u8 left, u8 top, u8 optionWidth } // Unused -static void PrintMenuActionGrid_TopLeft(u8 windowId, u8 fontId, u8 optionWidth, u8 unused, u8 horizontalCount, u8 verticalCount, const struct MenuAction *strs, const u8 *strIds) +static void PrintMenuActionGrid_TopLeft(u8 windowId, u8 fontId, u8 optionWidth, u8 unused, u8 horizontalCount, u8 verticalCount, const struct MenuAction *menuActions, const u8 *actionIds) { - PrintMenuActionGrid(windowId, fontId, GetFontAttribute(fontId, FONTATTR_MAX_LETTER_WIDTH), 0, optionWidth, horizontalCount, verticalCount, strs, strIds); + PrintMenuActionGrid(windowId, fontId, GetFontAttribute(fontId, FONTATTR_MAX_LETTER_WIDTH), 0, optionWidth, horizontalCount, verticalCount, menuActions, actionIds); } u8 sub_8198F58(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 cursorHeight, u8 a6, u8 a7, u8 numChoices, u8 a9) @@ -1598,19 +1598,19 @@ u8 InitMenuInUpperLeftCornerPlaySoundWhenAPressed(u8 windowId, u8 itemCount, u8 return InitMenuInUpperLeftCorner(windowId, itemCount, initialCursorPos, FALSE); } -void PrintMenuTable(u8 windowId, u8 itemCount, const struct MenuAction *strs) +void PrintMenuTable(u8 windowId, u8 itemCount, const struct MenuAction *menuActions) { u32 i; for (i = 0; i < itemCount; i++) { - AddTextPrinterParameterized(windowId, 1, strs[i].text, 8, (i * 16) + 1, 0xFF, NULL); + AddTextPrinterParameterized(windowId, 1, menuActions[i].text, 8, (i * 16) + 1, 0xFF, NULL); } CopyWindowToVram(windowId, 2); } -void sub_81995E4(u8 windowId, u8 itemCount, const struct MenuAction *strs, const u8 *a8) +void sub_81995E4(u8 windowId, u8 itemCount, const struct MenuAction *menuActions, const u8 *actionIds) { u8 i; struct TextPrinterTemplate printer; @@ -1628,7 +1628,7 @@ void sub_81995E4(u8 windowId, u8 itemCount, const struct MenuAction *strs, const for (i = 0; i < itemCount; i++) { - printer.currentChar = strs[a8[i]].text; + printer.currentChar = menuActions[actionIds[i]].text; printer.y = (i * 16) + 1; printer.currentY = (i * 16) + 1; AddTextPrinter(&printer, 0xFF, NULL); @@ -1662,19 +1662,19 @@ void CreateYesNoMenu(const struct WindowTemplate *window, u16 baseTileNum, u8 pa InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sYesNoWindowId, 2, initialCursorPos); } -void PrintMenuGridTable(u8 windowId, u8 optionWidth, u8 columns, u8 rows, const struct MenuAction *strs) +void PrintMenuGridTable(u8 windowId, u8 optionWidth, u8 columns, u8 rows, const struct MenuAction *menuActions) { u32 i, j; for (i = 0; i < rows; i++) { for (j = 0; j < columns; j++) - AddTextPrinterParameterized(windowId, 1, strs[(i * columns) + j].text, (optionWidth * j) + 8, (i * 16) + 1, 0xFF, NULL); + AddTextPrinterParameterized(windowId, 1, menuActions[(i * columns) + j].text, (optionWidth * j) + 8, (i * 16) + 1, 0xFF, NULL); } CopyWindowToVram(windowId, 2); } -void sub_819983C(u8 windowId, u8 a4, u8 itemCount, u8 itemCount2, const struct MenuAction *strs, const u8 *a8) +void sub_819983C(u8 windowId, u8 a4, u8 itemCount, u8 itemCount2, const struct MenuAction *menuActions, const u8 *actionIds) { u8 i; u8 j; @@ -1693,7 +1693,7 @@ void sub_819983C(u8 windowId, u8 a4, u8 itemCount, u8 itemCount2, const struct M { for (j = 0; j < itemCount; j++) { - printer.currentChar = strs[a8[(itemCount * i) + j]].text; + printer.currentChar = menuActions[actionIds[(itemCount * i) + j]].text; printer.x = (a4 * j) + 8; printer.y = (16 * i) + 1; printer.currentX = printer.x; diff --git a/src/menu_helpers.c b/src/menu_helpers.c index dce00e51e..3e8148a42 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -23,10 +23,10 @@ static void Task_ContinueTaskAfterMessagePrints(u8 taskId); static void Task_CallYesOrNoCallback(u8 taskId); -EWRAM_DATA static struct YesNoFuncTable gUnknown_0203A138 = {0}; -EWRAM_DATA static u8 gUnknown_0203A140 = 0; +EWRAM_DATA static struct YesNoFuncTable sYesNo = {0}; +EWRAM_DATA static u8 sMessageWindowId = 0; -static TaskFunc gUnknown_0300117C; +static TaskFunc sMessageNextTask; static const struct OamData sOamData_SwapLine = { @@ -122,17 +122,17 @@ void SetVBlankHBlankCallbacksToNull(void) SetHBlankCallback(NULL); } -void DisplayMessageAndContinueTask(u8 taskId, u8 windowId, u16 arg2, u8 arg3, u8 fontId, u8 textSpeed, const u8 *string, void *taskFunc) +void DisplayMessageAndContinueTask(u8 taskId, u8 windowId, u16 tileNum, u8 paletteNum, u8 fontId, u8 textSpeed, const u8 *string, void *taskFunc) { - gUnknown_0203A140 = windowId; - DrawDialogFrameWithCustomTileAndPalette(windowId, TRUE, arg2, arg3); + sMessageWindowId = windowId; + DrawDialogFrameWithCustomTileAndPalette(windowId, TRUE, tileNum, paletteNum); if (string != gStringVar4) StringExpandPlaceholders(gStringVar4, string); gTextFlags.canABSpeedUpPrint = 1; AddTextPrinterParameterized2(windowId, fontId, gStringVar4, textSpeed, NULL, 2, 1, 3); - gUnknown_0300117C = taskFunc; + sMessageNextTask = taskFunc; gTasks[taskId].func = Task_ContinueTaskAfterMessagePrints; } @@ -144,20 +144,20 @@ bool16 RunTextPrintersRetIsActive(u8 textPrinterId) static void Task_ContinueTaskAfterMessagePrints(u8 taskId) { - if (!RunTextPrintersRetIsActive(gUnknown_0203A140)) - gUnknown_0300117C(taskId); + if (!RunTextPrintersRetIsActive(sMessageWindowId)) + sMessageNextTask(taskId); } void DoYesNoFuncWithChoice(u8 taskId, const struct YesNoFuncTable *data) { - gUnknown_0203A138 = *data; + sYesNo = *data; gTasks[taskId].func = Task_CallYesOrNoCallback; } void CreateYesNoMenuWithCallbacks(u8 taskId, const struct WindowTemplate *template, u8 arg2, u8 arg3, u8 arg4, u16 tileStart, u8 palette, const struct YesNoFuncTable *yesNo) { CreateYesNoMenu(template, tileStart, palette, 0); - gUnknown_0203A138 = *yesNo; + sYesNo = *yesNo; gTasks[taskId].func = Task_CallYesOrNoCallback; } @@ -167,12 +167,12 @@ static void Task_CallYesOrNoCallback(u8 taskId) { case 0: PlaySE(SE_SELECT); - gUnknown_0203A138.yesFunc(taskId); + sYesNo.yesFunc(taskId); break; case 1: case MENU_B_PRESSED: PlaySE(SE_SELECT); - gUnknown_0203A138.noFunc(taskId); + sYesNo.noFunc(taskId); break; } } @@ -275,11 +275,13 @@ u8 GetLRKeysPressedAndHeld(void) return 0; } -bool8 sub_8122148(u16 itemId) +bool8 IsHoldingItemAllowed(u16 itemId) { + // Enigma Berry can't be held in link areas if (itemId != ITEM_ENIGMA_BERRY) return TRUE; - else if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(TRADE_CENTER) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRADE_CENTER)) + else if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(TRADE_CENTER) + && gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRADE_CENTER)) return FALSE; else if (InUnionRoom() != TRUE) return TRUE; @@ -323,66 +325,72 @@ bool8 MenuHelpers_CallLinkSomething(void) return TRUE; } -void sub_812220C(struct ItemSlot *slots, u8 count, u8 *arg2, u8 *usedSlotsCount, u8 maxUsedSlotsCount) +void SetItemListPerPageCount(struct ItemSlot *slots, u8 slotsCount, u8 *pageItems, u8 *totalItems, u8 maxPerPage) { u16 i; struct ItemSlot *slots_ = slots; - (*usedSlotsCount) = 0; - for (i = 0; i < count; i++) + // Count the number of non-empty item slots + *totalItems = 0; + for (i = 0; i < slotsCount; i++) { if (slots_[i].itemId != ITEM_NONE) - (*usedSlotsCount)++; + (*totalItems)++; } + (*totalItems)++; // + 1 for 'Cancel' - (*usedSlotsCount)++; - if ((*usedSlotsCount) > maxUsedSlotsCount) - *arg2 = maxUsedSlotsCount; + // Set number of items per page + if (*totalItems > maxPerPage) + *pageItems = maxPerPage; else - *arg2 = (*usedSlotsCount); + *pageItems = *totalItems; } -void sub_812225C(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 numItems) +void SetCursorWithinListBounds(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 totalItems) { - if (*scrollOffset != 0 && *scrollOffset + maxShownItems > numItems) - *scrollOffset = numItems - maxShownItems; + if (*scrollOffset != 0 && *scrollOffset + maxShownItems > totalItems) + *scrollOffset = totalItems - maxShownItems; - if (*scrollOffset + *cursorPos >= numItems) + if (*scrollOffset + *cursorPos >= totalItems) { - if (numItems == 0) + if (totalItems == 0) *cursorPos = 0; else - *cursorPos = numItems - 1; + *cursorPos = totalItems - 1; } } -void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4) +void SetCursorScrollWithinListBounds(u16 *scrollOffset, u16 *cursorPos, u8 shownItems, u8 totalItems, u8 maxShownItems) { u8 i; - if (arg4 % 2 != 0) + if (maxShownItems % 2 != 0) { - if ((*arg1) >= arg4 / 2) + // Is cursor at least halfway down visible list + if (*cursorPos >= maxShownItems / 2) { - for (i = 0; i < (*arg1) - (arg4 / 2); i++) + for (i = 0; i < *cursorPos - (maxShownItems / 2); i++) { - if ((*arg0) + arg2 == arg3) + // Stop if reached end of list + if (*scrollOffset + shownItems == totalItems) break; - (*arg1)--; - (*arg0)++; + (*cursorPos)--; + (*scrollOffset)++; } } } else { - if ((*arg1) >= (arg4 / 2) + 1) + // Is cursor at least halfway down visible list + if (*cursorPos >= (maxShownItems / 2) + 1) { - for (i = 0; i <= (*arg1) - (arg4 / 2); i++) + for (i = 0; i <= *cursorPos - (maxShownItems / 2); i++) { - if ((*arg0) + arg2 == arg3) + // Stop if reached end of list + if (*scrollOffset + shownItems == totalItems) break; - (*arg1)--; - (*arg0)++; + (*cursorPos)--; + (*scrollOffset)++; } } } diff --git a/src/menu_specialized.c b/src/menu_specialized.c index eb8cae72f..2fd12f2fd 100644 --- a/src/menu_specialized.c +++ b/src/menu_specialized.c @@ -28,10 +28,10 @@ extern const struct CompressedSpriteSheet gMonFrontPicTable[]; -EWRAM_DATA static u8 sUnknown_0203CF48[3] = {0}; -EWRAM_DATA static struct ListMenuItem *sUnknown_0203CF4C = NULL; +EWRAM_DATA static u8 sMailboxWindowIds[MAILBOXWIN_COUNT] = {0}; +EWRAM_DATA static struct ListMenuItem *sMailboxList = NULL; -static void sub_81D1E7C(s32 itemIndex, bool8 onInit, struct ListMenu *list); +static void MailboxMenu_MoveCursorFunc(s32 itemIndex, bool8 onInit, struct ListMenu *list); static void sub_81D24A4(struct ConditionGraph *a0); static void sub_81D2634(struct ConditionGraph *a0); static void MoveRelearnerCursorCallback(s32 itemIndex, bool8 onInit, struct ListMenu *list); @@ -40,33 +40,33 @@ static void SetNextConditionSparkle(struct Sprite *sprite); static void SpriteCB_ConditionSparkle(struct Sprite *sprite); static void ShowAllConditionSparkles(struct Sprite *sprite); -static const struct WindowTemplate sUnknown_086253E8[] = +static const struct WindowTemplate sWindowTemplates_MailboxMenu[MAILBOXWIN_COUNT] = { - { + [MAILBOXWIN_TITLE] = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 1, .width = 8, .height = 2, - .paletteNum = 0xF, + .paletteNum = 15, .baseBlock = 0x8 }, - { + [MAILBOXWIN_LIST] = { .bg = 0, .tilemapLeft = 21, .tilemapTop = 1, .width = 8, .height = 18, - .paletteNum = 0xF, + .paletteNum = 15, .baseBlock = 0x18 }, - { + [MAILBOXWIN_OPTIONS] = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 1, .width = 11, .height = 8, - .paletteNum = 0xF, + .paletteNum = 15, .baseBlock = 0x18 } }; @@ -207,53 +207,55 @@ static const struct ListMenuTemplate sMoveRelearnerMovesListTemplate = .cursorKind = 0 }; -bool8 sub_81D1C44(u8 count) +bool8 MailboxMenu_Alloc(u8 count) { u8 i; - sUnknown_0203CF4C = Alloc(count * sizeof(*sUnknown_0203CF4C) + sizeof(*sUnknown_0203CF4C)); - if (sUnknown_0203CF4C == NULL) + // + 1 to count for 'Cancel' + sMailboxList = Alloc((count + 1) * sizeof(*sMailboxList)); + if (sMailboxList == NULL) return FALSE; - for (i = 0; i < ARRAY_COUNT(sUnknown_0203CF48); i++) - sUnknown_0203CF48[i] = WINDOW_NONE; + for (i = 0; i < ARRAY_COUNT(sMailboxWindowIds); i++) + sMailboxWindowIds[i] = WINDOW_NONE; return TRUE; } -u8 sub_81D1C84(u8 a0) +u8 MailboxMenu_AddWindow(u8 windowIdx) { - if (sUnknown_0203CF48[a0] == WINDOW_NONE) + if (sMailboxWindowIds[windowIdx] == WINDOW_NONE) { - if (a0 == 2) + if (windowIdx == MAILBOXWIN_OPTIONS) { - struct WindowTemplate template = sUnknown_086253E8[2]; + struct WindowTemplate template = sWindowTemplates_MailboxMenu[windowIdx]; template.width = GetMaxWidthInMenuTable(&gMailboxMailOptions[0], 4); - sUnknown_0203CF48[2] = AddWindow(&template); + sMailboxWindowIds[windowIdx] = AddWindow(&template); } - else + else // MAILBOXWIN_TITLE or MAILBOXWIN_LIST { - sUnknown_0203CF48[a0] = AddWindow(&sUnknown_086253E8[a0]); + sMailboxWindowIds[windowIdx] = AddWindow(&sWindowTemplates_MailboxMenu[windowIdx]); } - SetStandardWindowBorderStyle(sUnknown_0203CF48[a0], 0); + SetStandardWindowBorderStyle(sMailboxWindowIds[windowIdx], 0); } - return sUnknown_0203CF48[a0]; + return sMailboxWindowIds[windowIdx]; } -void sub_81D1D04(u8 a0) +void MailboxMenu_RemoveWindow(u8 windowIdx) { - ClearStdWindowAndFrameToTransparent(sUnknown_0203CF48[a0], 0); - ClearWindowTilemap(sUnknown_0203CF48[a0]); - RemoveWindow(sUnknown_0203CF48[a0]); - sUnknown_0203CF48[a0] = WINDOW_NONE; + ClearStdWindowAndFrameToTransparent(sMailboxWindowIds[windowIdx], 0); + ClearWindowTilemap(sMailboxWindowIds[windowIdx]); + RemoveWindow(sMailboxWindowIds[windowIdx]); + sMailboxWindowIds[windowIdx] = WINDOW_NONE; } -static u8 sub_81D1D34(u8 a0) +// Unused +static u8 MailboxMenu_GetWindowId(u8 windowIdx) { - return sUnknown_0203CF48[a0]; + return sMailboxWindowIds[windowIdx]; } -static void sub_81D1D44(u8 windowId, u32 itemId, u8 y) +static void MailboxMenu_ItemPrintFunc(u8 windowId, u32 itemId, u8 y) { u8 buffer[30]; u16 length; @@ -269,21 +271,21 @@ static void sub_81D1D44(u8 windowId, u32 itemId, u8 y) AddTextPrinterParameterized4(windowId, 1, 8, y, 0, 0, sPlayerNameTextColors, -1, buffer); } -u8 sub_81D1DC0(struct PlayerPCItemPageStruct *page) +u8 MailboxMenu_CreateList(struct PlayerPCItemPageStruct *page) { u16 i; for (i = 0; i < page->count; i++) { - sUnknown_0203CF4C[i].name = sEmptyItemName; - sUnknown_0203CF4C[i].id = i; + sMailboxList[i].name = sEmptyItemName; + sMailboxList[i].id = i; } - sUnknown_0203CF4C[i].name = gText_Cancel2; - sUnknown_0203CF4C[i].id = LIST_CANCEL; + sMailboxList[i].name = gText_Cancel2; + sMailboxList[i].id = LIST_CANCEL; - gMultiuseListMenuTemplate.items = sUnknown_0203CF4C; + gMultiuseListMenuTemplate.items = sMailboxList; gMultiuseListMenuTemplate.totalItems = page->count + 1; - gMultiuseListMenuTemplate.windowId = sUnknown_0203CF48[1]; + gMultiuseListMenuTemplate.windowId = sMailboxWindowIds[MAILBOXWIN_LIST]; gMultiuseListMenuTemplate.header_X = 0; gMultiuseListMenuTemplate.item_X = 8; gMultiuseListMenuTemplate.cursor_X = 0; @@ -292,8 +294,8 @@ u8 sub_81D1DC0(struct PlayerPCItemPageStruct *page) gMultiuseListMenuTemplate.cursorPal = 2; gMultiuseListMenuTemplate.fillValue = 1; gMultiuseListMenuTemplate.cursorShadowPal = 3; - gMultiuseListMenuTemplate.moveCursorFunc = sub_81D1E7C; - gMultiuseListMenuTemplate.itemPrintFunc = sub_81D1D44; + gMultiuseListMenuTemplate.moveCursorFunc = MailboxMenu_MoveCursorFunc; + gMultiuseListMenuTemplate.itemPrintFunc = MailboxMenu_ItemPrintFunc; gMultiuseListMenuTemplate.fontId = 1; gMultiuseListMenuTemplate.cursorKind = 0; gMultiuseListMenuTemplate.lettersSpacing = 0; @@ -302,20 +304,20 @@ u8 sub_81D1DC0(struct PlayerPCItemPageStruct *page) return ListMenuInit(&gMultiuseListMenuTemplate, page->itemsAbove, page->cursorPos); } -static void sub_81D1E7C(s32 itemIndex, bool8 onInit, struct ListMenu *list) +static void MailboxMenu_MoveCursorFunc(s32 itemIndex, bool8 onInit, struct ListMenu *list) { if (onInit != TRUE) PlaySE(SE_SELECT); } -void sub_81D1E90(struct PlayerPCItemPageStruct *page) +void MailboxMenu_AddScrollArrows(struct PlayerPCItemPageStruct *page) { page->scrollIndicatorTaskId = AddScrollIndicatorArrowPairParameterized(2, 0xC8, 12, 0x94, page->count - page->pageItems + 1, 0x6E, 0x6E, &page->itemsAbove); } -void sub_81D1EC0(void) +void MailboxMenu_Free(void) { - Free(sUnknown_0203CF4C); + Free(sMailboxList); } void InitConditionGraphData(struct ConditionGraph *graph) diff --git a/src/party_menu.c b/src/party_menu.c index bfd7d5220..34b038861 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -4203,7 +4203,7 @@ static void CB2_ReturnToBagMenu(void) if (InBattlePyramid() == FALSE) GoToBagMenu(ITEMMENULOCATION_LAST, POCKETS_COUNT, NULL); else - GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_PREV, gPyramidBagMenuState.callback); + GoToBattlePyramidBagMenu(PYRAMIDBAG_LOC_PREV, gPyramidBagMenuState.exitCallback); } static void Task_SetSacredAshCB(u8 taskId) @@ -5475,7 +5475,7 @@ static void TryGiveMailToSelectedMon(u8 taskId) struct MailStruct *mail; gPartyMenuUseExitCallback = FALSE; - mail = &gSaveBlock1Ptr->mail[playerPCItemPageInfo.itemsAbove + 6 + playerPCItemPageInfo.cursorPos]; + mail = &gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos]; if (GetMonData(mon, MON_DATA_HELD_ITEM) != ITEM_NONE) { DisplayPartyMenuMessage(gText_PkmnHoldingItemCantHoldMail, TRUE); diff --git a/src/player_pc.c b/src/player_pc.c index f44a111b3..301b8c362 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -30,24 +30,79 @@ #include "window.h" #include "menu_specialized.h" -// structures -struct Struct203BCC4 -{ - struct ListMenuItem unk0[51]; - u8 unk198[51][0x18]; - u8 windowIds[6]; - u8 unk666; - u8 spriteId; - u8 spriteIds[7]; +// Top level PC menu options +enum { + MENU_ITEMSTORAGE, + MENU_MAILBOX, + MENU_DECORATION, + MENU_TURNOFF +}; + +// Item storage menu options +enum { + MENU_WITHDRAW, + MENU_DEPOSIT, + MENU_TOSS, + MENU_EXIT +}; + +// Windows for the main menus (top level menu, and item storage menu) +enum { + WIN_MAIN_MENU, + WIN_MAIN_MENU_BEDROOM, + WIN_ITEM_STORAGE_MENU, +}; + +// Windows for item storage (while viewing the PC's item inventory) +enum { + ITEMPC_WIN_LIST, + ITEMPC_WIN_MESSAGE, + ITEMPC_WIN_ICON, + ITEMPC_WIN_TITLE, + ITEMPC_WIN_QUANTITY, + ITEMPC_WIN_YESNO, + ITEMPC_WIN_COUNT +}; + // When showing the main list, the first window to this window are drawn +#define ITEMPC_WIN_LIST_END ITEMPC_WIN_TITLE + +// Message IDs for Item Storage +enum { + MSG_SWITCH_WHICH_ITEM = 0xFFF7, + MSG_OKAY_TO_THROW_AWAY, + MSG_TOO_IMPORTANT, + MSG_NO_MORE_ROOM, + MSG_THREW_AWAY_ITEM, + MSG_HOW_MANY_TO_TOSS, + MSG_WITHDREW_ITEM, + MSG_HOW_MANY_TO_WITHDRAW, + MSG_GO_BACK_TO_PREV +}; + +#define TAG_ITEM_ICON 5110 +#define TAG_SCROLL_ARROW 5112 + +// Item list ID for toSwapPos to indicate an item is not currently being swapped +#define NOT_SWAPPING 0xFF + +#define SWAP_LINE_LENGTH 7 + +struct ItemStorageMenu +{ + struct ListMenuItem listItems[PC_ITEMS_COUNT + 1]; + u8 itemNames[PC_ITEMS_COUNT + 1][ITEM_NAME_LENGTH + 10]; + u8 windowIds[ITEMPC_WIN_COUNT]; + u8 toSwapPos; + u8 spriteId; + u8 swapLineSpriteIds[SWAP_LINE_LENGTH]; }; -// static functions static void InitPlayerPCMenu(u8 taskId); static void PlayerPCProcessMenuInput(u8 taskId); static void InitItemStorageMenu(u8 taskId, u8 var); static u8 GetMailboxMailCount(void); -static void Mailbox_UpdateMailList(void); +static void Mailbox_CompactMailList(void); static void Mailbox_DrawMailboxMenu(u8 taskId); static void Mailbox_ProcessInput(u8 taskId); static void Mailbox_PrintWhatToDoWithPlayerMailText(u8 taskId); @@ -67,15 +122,14 @@ static void Mailbox_Give(u8 taskId); static void Mailbox_Cancel(u8 taskId); static void Mailbox_CancelMoveToBag(u8 taskId); -static void Mailbox_MoveToBagYesNoPrompt(u8 taskId); -static void Mailbox_DrawYesNoBeforeMove(u8 taskId); +static void Mailbox_HandleConfirmMoveToBag(u8 taskId); +static void Mailbox_AskConfirmMoveToBag(u8 taskId); static void Mailbox_DoGiveMailPokeMenu(u8 taskId); static void Mailbox_NoPokemonForMail(u8 taskId); static void Mailbox_FadeAndReadMail(u8 taskId); static void Mailbox_ReturnToFieldFromReadMail(void); -static void Mailbox_DoRedrawMailboxMenuAfterReturn(void); -static void pal_fill_for_maplights_or_black(void); +static void Mailbox_ReshowAfterMail(void); static void Mailbox_HandleReturnToProcessInput(u8 taskId); static void Mailbox_UpdateMailListAfterDeposit(void); @@ -83,91 +137,92 @@ static void ItemStorage_Withdraw(u8 taskId); static void ItemStorage_Deposit(u8 taskId); static void ItemStorage_Toss(u8 taskId); static void ItemStorage_Exit(u8 taskId); -static void ItemStorage_ResumeInputFromYesToss(u8 taskId); -static void ItemStorage_ResumeInputFromNoToss(u8 taskId); +static void ItemStorage_TossItemYes(u8 taskId); +static void ItemStorage_TossItemNo(u8 taskId); static void ItemStorageMenuPrint(const u8 *); static void ItemStorageMenuProcessInput(u8 taskId); -static void ItemStorage_ProcessWithdrawTossInput(u8 taskId); -static void ItemStorage_SetItemAndMailCount(u8); +static void SetPlayerPCListCount(u8); static void ItemStorage_HandleReturnToProcessInput(u8 taskId); -static void ItemStorage_WithdrawToss_Helper(u8 taskId, bool8 toss); +static void ItemStorage_Enter(u8 taskId, bool8 toss); +static void ItemStorage_CreateListMenu(u8 taskId); +static void ItemStorage_ProcessInput(u8 taskId); static void Task_ItemStorage_Deposit(u8 taskId); +static void ItemStorage_ReshowAfterBagMenu(void); static void ItemStorage_DoItemWithdraw(u8 taskId); static void ItemStorage_DoItemToss(u8 taskid); static void ItemStorage_HandleQuantityRolling(u8 taskid); -static void ItemStorage_GoBackToPlayerPCMenu(u8 taskId); -static void ItemStorage_ItemSwapChoosePrompt(u8 taskId); +static void ItemStorage_ExitItemList(u8 taskId); +static void ItemStorage_StartItemSwap(u8 taskId); static void ItemStorage_DoItemAction(u8 taskId); -static void ItemStorage_ProcessInput(u8 taskId); -static void ItemStorage_DoItemSwap(u8 taskId, bool8 a); +static void ItemStorage_FinishItemSwap(u8 taskId, bool8 a); static void ItemStorage_HandleRemoveItem(u8 taskId); -static void ItemStorage_WaitPressHandleResumeProcessInput(u8 taskId); -static void ItemStorage_StartScrollIndicatorAndProcessInput(u8 taskId); +static void ItemStorage_HandleErrorMessageInput(u8 taskId); +static void ItemStorage_ReturnToListInput(u8 taskId); -static const u8* ItemStorage_GetItemPcResponse(u16); +static const u8* ItemStorage_GetMessage(u16); 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 UpdateSwapLinePos(u8); -static void sub_816C4FC(u8 taskId); -static void sub_816C0C8(void); -static void sub_816C060(u16 itemId); -static void sub_816BEF0(s32 id); -static void sub_816B4DC(u8 taskId); +static void ItemStorage_Init(void); +static void ItemStorage_DrawSwapArrow(u8 y, u8, u8 speed); +static void ItemStorage_RemoveWindow(u8); +static void ItemStorage_UpdateSwapLinePos(u8); +static void ItemStorage_ProcessItemSwapInput(u8 taskId); +static void ItemStorage_EraseItemIcon(void); +static void ItemStorage_DrawItemIcon(u16 itemId); +static void ItemStorage_PrintDescription(s32 id); +static void ItemStorage_EraseMainMenu(u8 taskId); static void ItemStorage_MoveCursor(s32 id, bool8 b, struct ListMenu * thisMenu); -static void fish4_goto_x5_or_x6(u8 windowId, u32 id, u8 yOffset); +static void ItemStorage_PrintMenuItem(u8 windowId, u32 id, u8 yOffset); -// EWRAM -static EWRAM_DATA const u8 *gPcItemMenuOptionOrder = NULL; -static EWRAM_DATA u8 gPcItemMenuOptionsNum = 0; -EWRAM_DATA struct PlayerPCItemPageStruct playerPCItemPageInfo = {0, 0, 0, 0, {0, 0, 0}, 0}; -static EWRAM_DATA struct Struct203BCC4 *gUnknown_0203BCC4 = NULL; +static EWRAM_DATA const u8 *sTopMenuOptionOrder = NULL; +static EWRAM_DATA u8 sTopMenuNumOptions = 0; +EWRAM_DATA struct PlayerPCItemPageStruct gPlayerPCItemPageInfo = {}; +static EWRAM_DATA struct ItemStorageMenu *sItemStorageMenu = NULL; -// .rodata -static const u8 *const gPCText_OptionDescList[] = +static const u8 *const sItemStorage_OptionDescriptions[] = { - gText_TakeOutItemsFromPC, - gText_StoreItemsInPC, - gText_ThrowAwayItemsInPC, - gText_GoBackPrevMenu, + [MENU_WITHDRAW] = gText_TakeOutItemsFromPC, + [MENU_DEPOSIT] = gText_StoreItemsInPC, + [MENU_TOSS] = gText_ThrowAwayItemsInPC, + [MENU_EXIT] = gText_GoBackPrevMenu, }; static const struct MenuAction sPlayerPCMenuActions[] = { - { gText_ItemStorage, PlayerPC_ItemStorage }, - { gText_Mailbox, PlayerPC_Mailbox }, - { gText_Decoration, PlayerPC_Decoration }, - { gText_TurnOff, PlayerPC_TurnOff } + [MENU_ITEMSTORAGE] = { gText_ItemStorage, PlayerPC_ItemStorage }, + [MENU_MAILBOX] = { gText_Mailbox, PlayerPC_Mailbox }, + [MENU_DECORATION] = { gText_Decoration, PlayerPC_Decoration }, + [MENU_TURNOFF] = { gText_TurnOff, PlayerPC_TurnOff } }; -static const u8 gBedroomPC_OptionOrder[] = +static const u8 sBedroomPC_OptionOrder[] = { - PLAYERPC_MENU_ITEMSTORAGE, - PLAYERPC_MENU_MAILBOX, - PLAYERPC_MENU_DECORATION, - PLAYERPC_MENU_TURNOFF + MENU_ITEMSTORAGE, + MENU_MAILBOX, + MENU_DECORATION, + MENU_TURNOFF }; +#define NUM_BEDROOM_PC_OPTIONS ARRAY_COUNT(sBedroomPC_OptionOrder) -static const u8 gPlayerPC_OptionOrder[] = +static const u8 sPlayerPC_OptionOrder[] = { - PLAYERPC_MENU_ITEMSTORAGE, - PLAYERPC_MENU_MAILBOX, - PLAYERPC_MENU_TURNOFF + MENU_ITEMSTORAGE, + MENU_MAILBOX, + MENU_TURNOFF }; +#define NUM_PLAYER_PC_OPTIONS ARRAY_COUNT(sPlayerPC_OptionOrder) -static const struct MenuAction gPCText_ItemPCOptionsText[] = +static const struct MenuAction sItemStorage_MenuActions[] = { - { gText_WithdrawItem, ItemStorage_Withdraw }, - { gText_DepositItem, ItemStorage_Deposit }, - { gText_TossItem, ItemStorage_Toss }, - { gText_Cancel, ItemStorage_Exit } + [MENU_WITHDRAW] = { gText_WithdrawItem, ItemStorage_Withdraw }, + [MENU_DEPOSIT] = { gText_DepositItem, ItemStorage_Deposit }, + [MENU_TOSS] = { gText_TossItem, ItemStorage_Toss }, + [MENU_EXIT] = { gText_Cancel, ItemStorage_Exit } }; -static const struct ItemSlot gNewGamePCItems[] = +static const struct ItemSlot sNewGamePCItems[] = { { ITEM_POTION, 1 }, { ITEM_NONE, 0 } @@ -175,15 +230,15 @@ static const struct ItemSlot gNewGamePCItems[] = const struct MenuAction gMailboxMailOptions[] = { - { gText_Read, Mailbox_DoMailRead }, + { gText_Read, Mailbox_DoMailRead }, { gText_MoveToBag, Mailbox_MoveToBag }, - { gText_Give2, Mailbox_Give }, - { gText_Cancel2, Mailbox_Cancel } + { gText_Give2, Mailbox_Give }, + { gText_Cancel2, Mailbox_Cancel } }; -static const struct WindowTemplate gUnknown_085DFF24[3] = +static const struct WindowTemplate sWindowTemplates_MainMenus[] = { - { + [WIN_MAIN_MENU] = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 1, @@ -192,7 +247,7 @@ static const struct WindowTemplate gUnknown_085DFF24[3] = .paletteNum = 15, .baseBlock = 1 }, - { + [WIN_MAIN_MENU_BEDROOM] = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 1, @@ -201,7 +256,7 @@ static const struct WindowTemplate gUnknown_085DFF24[3] = .paletteNum = 15, .baseBlock = 1 }, - { + [WIN_ITEM_STORAGE_MENU] = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 1, @@ -212,17 +267,17 @@ static const struct WindowTemplate gUnknown_085DFF24[3] = } }; -static const struct YesNoFuncTable ResumeFromWithdrawYesNoFuncList = // ResumeFromWithdrawYesNoFuncList +static const struct YesNoFuncTable ItemTossYesNoFuncs = { - ItemStorage_ResumeInputFromYesToss, - ItemStorage_ResumeInputFromNoToss + ItemStorage_TossItemYes, + ItemStorage_TossItemNo }; -static const struct ListMenuTemplate gUnknown_085DFF44 = +static const struct ListMenuTemplate sListMenuTemplate_ItemStorage = { .items = NULL, .moveCursorFunc = ItemStorage_MoveCursor, - .itemPrintFunc = fish4_goto_x5_or_x6, + .itemPrintFunc = ItemStorage_PrintMenuItem, .totalItems = 0, .maxShowed = 0, .windowId = 0, @@ -239,9 +294,9 @@ static const struct ListMenuTemplate gUnknown_085DFF44 = .fontId = 7 }; -static const struct WindowTemplate gUnknown_085DFF5C[5] = +static const struct WindowTemplate sWindowTemplates_ItemStorage[ITEMPC_WIN_COUNT] = { - { + [ITEMPC_WIN_LIST] = { .bg = 0, .tilemapLeft = 16, .tilemapTop = 1, @@ -250,7 +305,7 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] = .paletteNum = 15, .baseBlock = 0x0001 }, - { + [ITEMPC_WIN_MESSAGE] = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 13, @@ -259,7 +314,7 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] = .paletteNum = 15, .baseBlock = 0x00EB }, - { + [ITEMPC_WIN_ICON] = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 8, @@ -268,7 +323,7 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] = .paletteNum = 15, .baseBlock = 0x0153 }, - { + [ITEMPC_WIN_TITLE] = { .bg = 0, .tilemapLeft = 1, .tilemapTop = 1, @@ -277,7 +332,7 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] = .paletteNum = 15, .baseBlock = 0x0139 }, - { + [ITEMPC_WIN_QUANTITY] = { .bg = 0, .tilemapLeft = 8, .tilemapTop = 9, @@ -285,61 +340,67 @@ static const struct WindowTemplate gUnknown_085DFF5C[5] = .height = 2, .paletteNum = 15, .baseBlock = 0x015C + }, + [ITEMPC_WIN_YESNO] = { + .bg = 0, + .tilemapLeft = 9, + .tilemapTop = 7, + .width = 5, + .height = 4, + .paletteNum = 15, + .baseBlock = 0x0168 } }; -static const struct WindowTemplate gUnknown_085DFF84 = -{ - .bg = 0, - .tilemapLeft = 9, - .tilemapTop = 7, - .width = 5, - .height = 4, - .paletteNum = 15, - .baseBlock = 0x0168 -}; +static const u8 sSwapArrowTextColors[] = {TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY, TEXT_COLOR_DARK_GRAY}; -static const u8 gUnknown_085DFF8C[] = {0x01, 0x03, 0x02, 0x00}; - -// text +// Macro below is likely a fakematch, equivalent to sNewGamePCItems[i].quantity +#define GET_QUANTITY(i) ((u16)((u16 *)sNewGamePCItems + 1)[i * 2]) void NewGameInitPCItems(void) { - u8 i; - - // because Game Freak don't know how to use a struct or a 2d array - for(i = 0, ClearItemSlots(gSaveBlock1Ptr->pcItems, ARRAY_COUNT(gSaveBlock1Ptr->pcItems)); NEW_GAME_PC_ITEMS(i, PC_ITEM_ID) && NEW_GAME_PC_ITEMS(i, PC_QUANTITY) && - AddPCItem(NEW_GAME_PC_ITEMS(i, PC_ITEM_ID), NEW_GAME_PC_ITEMS(i, PC_QUANTITY)) == TRUE; i++); + u8 i = 0; + ClearItemSlots(gSaveBlock1Ptr->pcItems, PC_ITEMS_COUNT); + for(; sNewGamePCItems[i].itemId != ITEM_NONE && GET_QUANTITY(i) && + AddPCItem(sNewGamePCItems[i].itemId, GET_QUANTITY(i)) == TRUE; i++); } +#undef GET_QUANTITY void BedroomPC(void) { - gPcItemMenuOptionOrder = gBedroomPC_OptionOrder; - gPcItemMenuOptionsNum = 4; + sTopMenuOptionOrder = sBedroomPC_OptionOrder; + sTopMenuNumOptions = NUM_BEDROOM_PC_OPTIONS; DisplayItemMessageOnField(CreateTask(TaskDummy, 0), gText_WhatWouldYouLike, InitPlayerPCMenu); } void PlayerPC(void) { - gPcItemMenuOptionOrder = gPlayerPC_OptionOrder; - gPcItemMenuOptionsNum = 3; + sTopMenuOptionOrder = sPlayerPC_OptionOrder; + sTopMenuNumOptions = NUM_PLAYER_PC_OPTIONS; DisplayItemMessageOnField(CreateTask(TaskDummy, 0), gText_WhatWouldYouLike, InitPlayerPCMenu); } +#define tUsedSlots data[1] +#define tQuantity data[2] +#define tInTossMenu data[3] +#define tWindowId data[4] +#define tListTaskId data[5] + static void InitPlayerPCMenu(u8 taskId) { u16 *data; struct WindowTemplate windowTemplate; - data = gTasks[taskId].data; - if (gPcItemMenuOptionsNum == 3) - windowTemplate = gUnknown_085DFF24[0]; - else - windowTemplate = gUnknown_085DFF24[1]; - windowTemplate.width = sub_81DB3D8(sPlayerPCMenuActions, gPcItemMenuOptionOrder, gPcItemMenuOptionsNum); - data[4] = AddWindow(&windowTemplate); - SetStandardWindowBorderStyle(data[4], 0); - sub_81995E4(data[4], gPcItemMenuOptionsNum, sPlayerPCMenuActions, gPcItemMenuOptionOrder); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[4], gPcItemMenuOptionsNum, 0); + + if (sTopMenuNumOptions == NUM_PLAYER_PC_OPTIONS) + windowTemplate = sWindowTemplates_MainMenus[WIN_MAIN_MENU]; + else // Bedroom PC + windowTemplate = sWindowTemplates_MainMenus[WIN_MAIN_MENU_BEDROOM]; + + windowTemplate.width = sub_81DB3D8(sPlayerPCMenuActions, sTopMenuOptionOrder, sTopMenuNumOptions); + tWindowId = AddWindow(&windowTemplate); + SetStandardWindowBorderStyle(tWindowId, 0); + sub_81995E4(tWindowId, sTopMenuNumOptions, sPlayerPCMenuActions, sTopMenuOptionOrder); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(tWindowId, sTopMenuNumOptions, 0); ScheduleBgCopyTilemapToVram(0); gTasks[taskId].func = PlayerPCProcessMenuInput; } @@ -350,30 +411,30 @@ static void PlayerPCProcessMenuInput(u8 taskId) s8 inputOptionId; data = gTasks[taskId].data; - if (gPcItemMenuOptionsNum > 3) + if (sTopMenuNumOptions > 3) inputOptionId = Menu_ProcessInput(); else inputOptionId = Menu_ProcessInputNoWrap(); switch (inputOptionId) { - case MENU_NOTHING_CHOSEN: - break; - case MENU_B_PRESSED: - PlaySE(SE_SELECT); - ClearStdWindowAndFrameToTransparent(data[4], FALSE); - ClearWindowTilemap(data[4]); - RemoveWindow(data[4]); - ScheduleBgCopyTilemapToVram(0); - gTasks[taskId].func = PlayerPC_TurnOff; - break; - default: - ClearStdWindowAndFrameToTransparent(data[4], FALSE); - ClearWindowTilemap(data[4]); - RemoveWindow(data[4]); - ScheduleBgCopyTilemapToVram(0); - gTasks[taskId].func = sPlayerPCMenuActions[gPcItemMenuOptionOrder[inputOptionId]].func.void_u8; - break; + case MENU_NOTHING_CHOSEN: + break; + case MENU_B_PRESSED: + PlaySE(SE_SELECT); + ClearStdWindowAndFrameToTransparent(tWindowId, FALSE); + ClearWindowTilemap(tWindowId); + RemoveWindow(tWindowId); + ScheduleBgCopyTilemapToVram(0); + gTasks[taskId].func = PlayerPC_TurnOff; + break; + default: + ClearStdWindowAndFrameToTransparent(tWindowId, FALSE); + ClearWindowTilemap(tWindowId); + RemoveWindow(tWindowId); + ScheduleBgCopyTilemapToVram(0); + gTasks[taskId].func = sPlayerPCMenuActions[sTopMenuOptionOrder[inputOptionId]].func.void_u8; + break; } } @@ -384,31 +445,37 @@ void ReshowPlayerPC(u8 var) static void PlayerPC_ItemStorage(u8 taskId) { - InitItemStorageMenu(taskId, ITEMPC_MENU_WITHDRAW); + InitItemStorageMenu(taskId, MENU_WITHDRAW); gTasks[taskId].func = ItemStorageMenuProcessInput; } static void PlayerPC_Mailbox(u8 taskId) { - playerPCItemPageInfo.count = GetMailboxMailCount(); + gPlayerPCItemPageInfo.count = GetMailboxMailCount(); - if (playerPCItemPageInfo.count == 0) + if (gPlayerPCItemPageInfo.count == 0) + { + // Mailbox cannot be opened if no mail is in PC DisplayItemMessageOnField(taskId, gText_NoMailHere, ReshowPlayerPC); + } else { - playerPCItemPageInfo.cursorPos = 0; - playerPCItemPageInfo.itemsAbove = 0; - playerPCItemPageInfo.scrollIndicatorTaskId = TASK_NONE; - Mailbox_UpdateMailList(); - ItemStorage_SetItemAndMailCount(taskId); - if (sub_81D1C44(playerPCItemPageInfo.count) == TRUE) + gPlayerPCItemPageInfo.cursorPos = 0; + gPlayerPCItemPageInfo.itemsAbove = 0; + gPlayerPCItemPageInfo.scrollIndicatorTaskId = TASK_NONE; + Mailbox_CompactMailList(); + SetPlayerPCListCount(taskId); + if (MailboxMenu_Alloc(gPlayerPCItemPageInfo.count) == TRUE) { ClearDialogWindowAndFrame(0, 0); Mailbox_DrawMailboxMenu(taskId); gTasks[taskId].func = Mailbox_ProcessInput; } - else + else + { + // Alloc failed, exit Mailbox DisplayItemMessageOnField(taskId, gText_NoMailHere, ReshowPlayerPC); + } } } @@ -419,7 +486,7 @@ static void PlayerPC_Decoration(u8 taskId) static void PlayerPC_TurnOff(u8 taskId) { - if (gPcItemMenuOptionsNum == 4) // if the option count is 4, we are at the bedroom PC, so do gender specific handling. + if (sTopMenuNumOptions == NUM_BEDROOM_PC_OPTIONS) // Flimsy way to determine if Bedroom PC is in use { if (gSaveBlock2Ptr->playerGender == MALE) ScriptContext1_SetupScript(LittlerootTown_BrendansHouse_2F_EventScript_TurnOffPlayerPC); @@ -439,14 +506,14 @@ static void InitItemStorageMenu(u8 taskId, u8 var) struct WindowTemplate windowTemplate; data = gTasks[taskId].data; - windowTemplate = gUnknown_085DFF24[2]; - windowTemplate.width = GetMaxWidthInMenuTable(gPCText_ItemPCOptionsText, 4); - data[4] = AddWindow(&windowTemplate); - SetStandardWindowBorderStyle(data[4], 0); - PrintMenuTable(data[4], ARRAY_COUNT(gPCText_ItemPCOptionsText), gPCText_ItemPCOptionsText); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[4], 4, var); + windowTemplate = sWindowTemplates_MainMenus[WIN_ITEM_STORAGE_MENU]; + windowTemplate.width = GetMaxWidthInMenuTable(sItemStorage_MenuActions, ARRAY_COUNT(sItemStorage_MenuActions)); + tWindowId = AddWindow(&windowTemplate); + SetStandardWindowBorderStyle(tWindowId, 0); + PrintMenuTable(tWindowId, ARRAY_COUNT(sItemStorage_MenuActions), sItemStorage_MenuActions); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(tWindowId, 4, var); ScheduleBgCopyTilemapToVram(0); - ItemStorageMenuPrint(gPCText_OptionDescList[var]); + ItemStorageMenuPrint(sItemStorage_OptionDescriptions[var]); } static void ItemStorageMenuPrint(const u8 *textPtr) @@ -457,27 +524,26 @@ static void ItemStorageMenuPrint(const u8 *textPtr) static void ItemStorageMenuProcessInput(u8 taskId) { - s8 r5; - s8 r2; + s8 oldPos, newPos; s8 inputOptionId; - r5 = Menu_GetCursorPos(); + oldPos = Menu_GetCursorPos(); inputOptionId = Menu_ProcessInput(); - r2 = Menu_GetCursorPos(); + newPos = Menu_GetCursorPos(); switch (inputOptionId) { - case MENU_NOTHING_CHOSEN: - if (r5 != r2) - ItemStorageMenuPrint(gPCText_OptionDescList[r2]); - break; - case MENU_B_PRESSED: - PlaySE(SE_SELECT); - ItemStorage_Exit(taskId); - break; - default: - PlaySE(SE_SELECT); - gPCText_ItemPCOptionsText[inputOptionId].func.void_u8(taskId); - break; + case MENU_NOTHING_CHOSEN: + if (oldPos != newPos) + ItemStorageMenuPrint(sItemStorage_OptionDescriptions[newPos]); + break; + case MENU_B_PRESSED: + PlaySE(SE_SELECT); + ItemStorage_Exit(taskId); + break; + default: + PlaySE(SE_SELECT); + sItemStorage_MenuActions[inputOptionId].func.void_u8(taskId); + break; } } @@ -497,13 +563,13 @@ static void Task_ItemStorage_Deposit(u8 taskId) } } -void sub_816B31C(void) +void CB2_PlayerPCExitBagMenu(void) { - gFieldCallback = Mailbox_DoRedrawMailboxMenuAfterReturn; + gFieldCallback = ItemStorage_ReshowAfterBagMenu; SetMainCallback2(CB2_ReturnToField); } -void Mailbox_DoRedrawMailboxMenuAfterReturn(void) +static void ItemStorage_ReshowAfterBagMenu(void) { LoadMessageBoxAndBorderGfx(); DrawDialogueFrame(0, 1); @@ -521,12 +587,15 @@ static void ItemStorage_Withdraw(u8 taskId) { s16 *data = gTasks[taskId].data; - NUM_ITEMS = CountUsedPCItemSlots(); - if (NUM_ITEMS != 0) - ItemStorage_WithdrawToss_Helper(taskId, FALSE); + tUsedSlots = CountUsedPCItemSlots(); + if (tUsedSlots != 0) + { + ItemStorage_Enter(taskId, FALSE); + } else { - sub_816B4DC(taskId); + // Can't withdraw, no items in PC + ItemStorage_EraseMainMenu(taskId); DisplayItemMessageOnField(taskId, gText_NoItems, PlayerPC_ItemStorage); } @@ -536,136 +605,133 @@ static void ItemStorage_Toss(u8 taskId) { s16 *data = gTasks[taskId].data; - NUM_ITEMS = CountUsedPCItemSlots(); - if (NUM_ITEMS != 0) - ItemStorage_WithdrawToss_Helper(taskId, TRUE); + tUsedSlots = CountUsedPCItemSlots(); + if (tUsedSlots != 0) + { + ItemStorage_Enter(taskId, TRUE); + } else { - sub_816B4DC(taskId); + // Can't toss, no items in PC + ItemStorage_EraseMainMenu(taskId); DisplayItemMessageOnField(taskId, gText_NoItems, PlayerPC_ItemStorage); } } -static void ItemStorage_WithdrawToss_Helper(u8 taskId, bool8 toss) +static void ItemStorage_Enter(u8 taskId, bool8 toss) { u16 *data = gTasks[taskId].data; - data[3] = toss; - sub_816B4DC(taskId); - playerPCItemPageInfo.cursorPos = 0; - playerPCItemPageInfo.itemsAbove = 0; - playerPCItemPageInfo.scrollIndicatorTaskId = TASK_NONE; - ItemStorage_SetItemAndMailCount(taskId); - sub_816BC14(); + tInTossMenu = toss; + ItemStorage_EraseMainMenu(taskId); + gPlayerPCItemPageInfo.cursorPos = 0; + gPlayerPCItemPageInfo.itemsAbove = 0; + gPlayerPCItemPageInfo.scrollIndicatorTaskId = TASK_NONE; + SetPlayerPCListCount(taskId); + ItemStorage_Init(); FreeAndReserveObjectSpritePalettes(); LoadListMenuSwapLineGfx(); - CreateSwapLineSprites(gUnknown_0203BCC4->spriteIds, 7); + CreateSwapLineSprites(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH); ClearDialogWindowAndFrame(0,0); - gTasks[taskId].func = ItemStorage_ProcessWithdrawTossInput; + gTasks[taskId].func = ItemStorage_CreateListMenu; } static void ItemStorage_Exit(u8 taskId) { - sub_816B4DC(taskId); + ItemStorage_EraseMainMenu(taskId); ReshowPlayerPC(taskId); } - -static void ItemStorage_SetItemAndMailCount(u8 taskId) +// Used by Item Storage and the Mailbox +static void SetPlayerPCListCount(u8 taskId) { - if (playerPCItemPageInfo.count > 7) - playerPCItemPageInfo.pageItems = 8; + if (gPlayerPCItemPageInfo.count > 7) + gPlayerPCItemPageInfo.pageItems = 8; else - playerPCItemPageInfo.pageItems = playerPCItemPageInfo.count + 1; + gPlayerPCItemPageInfo.pageItems = gPlayerPCItemPageInfo.count + 1; } -static void sub_816B4DC(u8 taskId) +static void ItemStorage_EraseMainMenu(u8 taskId) { u16 *data = gTasks[taskId].data; - - ClearStdWindowAndFrameToTransparent(data[4], FALSE); - ClearWindowTilemap(data[4]); - RemoveWindow(data[4]); + ClearStdWindowAndFrameToTransparent(tWindowId, FALSE); + ClearWindowTilemap(tWindowId); + RemoveWindow(tWindowId); ScheduleBgCopyTilemapToVram(0); } static u8 GetMailboxMailCount(void) { - u8 i, j; + u8 mailInPC, i; - for(i = 0, j = PARTY_SIZE; j < MAIL_COUNT; j++) - if (gSaveBlock1Ptr->mail[j].itemId != ITEM_NONE) - i++; + // Count mail in PC (by first skipping over mail in party) + for (mailInPC = 0, i = PARTY_SIZE; i < MAIL_COUNT; i++) + if (gSaveBlock1Ptr->mail[i].itemId != ITEM_NONE) + mailInPC++; - return i; + return mailInPC; } -static void Mailbox_UpdateMailList(void) +static void Mailbox_CompactMailList(void) { - struct MailStruct mailBuffer; + struct MailStruct temp; u8 i, j; for (i = PARTY_SIZE; i < MAIL_COUNT - 1; i++) { for (j = i + 1; j < MAIL_COUNT; j++) { - if (gSaveBlock1Ptr->mail[i].itemId == 0) - { - mailBuffer = gSaveBlock1Ptr->mail[i]; - gSaveBlock1Ptr->mail[i] = gSaveBlock1Ptr->mail[j]; - gSaveBlock1Ptr->mail[j] = mailBuffer; - } + if (gSaveBlock1Ptr->mail[i].itemId == ITEM_NONE) + SWAP(gSaveBlock1Ptr->mail[i], gSaveBlock1Ptr->mail[j], temp); } } } static void Mailbox_DrawMailboxMenu(u8 taskId) { - u8 windowId; - - windowId = sub_81D1C84(0); - sub_81D1C84(1); + u8 windowId = MailboxMenu_AddWindow(MAILBOXWIN_TITLE); + MailboxMenu_AddWindow(MAILBOXWIN_LIST); AddTextPrinterParameterized(windowId, 1, gText_Mailbox, GetStringCenterAlignXOffset(1, gText_Mailbox, 0x40), 1, 0, NULL); ScheduleBgCopyTilemapToVram(0); - gTasks[taskId].data[5] = sub_81D1DC0(&playerPCItemPageInfo); - sub_81D1E90(&playerPCItemPageInfo); + gTasks[taskId].tListTaskId = MailboxMenu_CreateList(&gPlayerPCItemPageInfo); + MailboxMenu_AddScrollArrows(&gPlayerPCItemPageInfo); } static void Mailbox_ProcessInput(u8 taskId) { u16 *data = gTasks[taskId].data; - s32 inputOptionId; if (!gPaletteFade.active) { - inputOptionId = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); + s32 inputOptionId = ListMenu_ProcessInput(tListTaskId); + ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos); switch (inputOptionId) { - case LIST_NOTHING_CHOSEN: - break; - case LIST_CANCEL: - PlaySE(SE_SELECT); - RemoveScrollIndicatorArrowPair(playerPCItemPageInfo.scrollIndicatorTaskId); - Mailbox_ReturnToPlayerPC(taskId); - break; - default: - PlaySE(SE_SELECT); - sub_81D1D04(0); - sub_81D1D04(1); - DestroyListMenuTask(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); - ScheduleBgCopyTilemapToVram(0); - RemoveScrollIndicatorArrowPair(playerPCItemPageInfo.scrollIndicatorTaskId); - gTasks[taskId].func = Mailbox_PrintWhatToDoWithPlayerMailText; - break; + case LIST_NOTHING_CHOSEN: + break; + case LIST_CANCEL: + PlaySE(SE_SELECT); + RemoveScrollIndicatorArrowPair(gPlayerPCItemPageInfo.scrollIndicatorTaskId); + Mailbox_ReturnToPlayerPC(taskId); + break; + default: + // Selected mail, ask what to do with it + PlaySE(SE_SELECT); + MailboxMenu_RemoveWindow(MAILBOXWIN_TITLE); + MailboxMenu_RemoveWindow(MAILBOXWIN_LIST); + DestroyListMenuTask(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos); + ScheduleBgCopyTilemapToVram(0); + RemoveScrollIndicatorArrowPair(gPlayerPCItemPageInfo.scrollIndicatorTaskId); + gTasks[taskId].func = Mailbox_PrintWhatToDoWithPlayerMailText; + break; } } } static void Mailbox_PrintWhatToDoWithPlayerMailText(u8 taskId) { - StringCopy(gStringVar1, gSaveBlock1Ptr->mail[playerPCItemPageInfo.itemsAbove + PARTY_SIZE + playerPCItemPageInfo.cursorPos].playerName); + StringCopy(gStringVar1, gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos].playerName); ConvertInternationalPlayerNameStripChar(gStringVar1, CHAR_SPACE); StringExpandPlaceholders(gStringVar4, gText_WhatToDoWithVar1sMail); DisplayItemMessageOnField(taskId, gStringVar4, Mailbox_PrintMailOptions); @@ -675,19 +741,19 @@ static void Mailbox_ReturnToPlayerPC(u8 taskId) { s16 *data = gTasks[taskId].data; - sub_81D1D04(0); - sub_81D1D04(1); - DestroyListMenuTask(data[5], NULL, NULL); + MailboxMenu_RemoveWindow(MAILBOXWIN_TITLE); + MailboxMenu_RemoveWindow(MAILBOXWIN_LIST); + DestroyListMenuTask(tListTaskId, NULL, NULL); ScheduleBgCopyTilemapToVram(0); - sub_81D1EC0(); + MailboxMenu_Free(); ReshowPlayerPC(taskId); } static void Mailbox_PrintMailOptions(u8 taskId) { - u8 r4 = sub_81D1C84(2); - PrintMenuTable(r4, ARRAY_COUNT(gMailboxMailOptions), gMailboxMailOptions); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(r4, 4, 0); + u8 windowId = MailboxMenu_AddWindow(MAILBOXWIN_OPTIONS); + PrintMenuTable(windowId, ARRAY_COUNT(gMailboxMailOptions), gMailboxMailOptions); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, 4, 0); ScheduleBgCopyTilemapToVram(0); gTasks[taskId].func = Mailbox_MailOptionsProcessInput; } @@ -696,19 +762,18 @@ static void Mailbox_MailOptionsProcessInput(u8 taskId) { s8 inputOptionId = ProcessMenuInput_other(); - switch(inputOptionId) + switch (inputOptionId) { - case -2: - break; - case -1: - PlaySE(SE_SELECT); - Mailbox_Cancel(taskId); - break; - - default: - PlaySE(SE_SELECT); - gMailboxMailOptions[inputOptionId].func.void_u8(taskId); - break; + case MENU_NOTHING_CHOSEN: + break; + case MENU_B_PRESSED: + PlaySE(SE_SELECT); + Mailbox_Cancel(taskId); + break; + default: + PlaySE(SE_SELECT); + gMailboxMailOptions[inputOptionId].func.void_u8(taskId); + break; } } @@ -722,26 +787,26 @@ static void Mailbox_FadeAndReadMail(u8 taskId) { if (!gPaletteFade.active) { - sub_81D1EC0(); + MailboxMenu_Free(); CleanupOverworldWindowsAndTilemaps(); - ReadMail(&(gSaveBlock1Ptr->mail[playerPCItemPageInfo.itemsAbove + PARTY_SIZE + playerPCItemPageInfo.cursorPos]), Mailbox_ReturnToFieldFromReadMail, TRUE); + ReadMail(&gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos], Mailbox_ReturnToFieldFromReadMail, TRUE); DestroyTask(taskId); } } static void Mailbox_ReturnToFieldFromReadMail(void) { - gFieldCallback = pal_fill_for_maplights_or_black; + gFieldCallback = Mailbox_ReshowAfterMail; SetMainCallback2(CB2_ReturnToField); } -static void pal_fill_for_maplights_or_black(void) +static void Mailbox_ReshowAfterMail(void) { u8 taskId; LoadMessageBoxAndBorderGfx(); taskId = CreateTask(Mailbox_HandleReturnToProcessInput, 0); - if (sub_81D1C44(playerPCItemPageInfo.count) == TRUE) + if (MailboxMenu_Alloc(gPlayerPCItemPageInfo.count) == TRUE) Mailbox_DrawMailboxMenu(taskId); else DestroyTask(taskId); @@ -756,49 +821,49 @@ static void Mailbox_HandleReturnToProcessInput(u8 taskId) static void Mailbox_MoveToBag(u8 taskId) { - DisplayItemMessageOnField(taskId, gText_MessageWillBeLost, Mailbox_DrawYesNoBeforeMove); + DisplayItemMessageOnField(taskId, gText_MessageWillBeLost, Mailbox_AskConfirmMoveToBag); } -static void Mailbox_DrawYesNoBeforeMove(u8 taskId) +static void Mailbox_AskConfirmMoveToBag(u8 taskId) { DisplayYesNoMenuDefaultYes(); - gTasks[taskId].func = Mailbox_MoveToBagYesNoPrompt; + gTasks[taskId].func = Mailbox_HandleConfirmMoveToBag; } -static void Mailbox_MoveToBagYesNoPrompt(u8 taskId) +static void Mailbox_HandleConfirmMoveToBag(u8 taskId) { - switch(Menu_ProcessInputNoWrapClearOnChoose()) + switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: - Mailbox_DoMailMoveToBag(taskId); - break; - case -1: - PlaySE(SE_SELECT); - case 1: - Mailbox_CancelMoveToBag(taskId); - break; - case -2: - default: - break; + case 0: // Yes + Mailbox_DoMailMoveToBag(taskId); + break; + case MENU_B_PRESSED: + PlaySE(SE_SELECT); + case 1: // No + Mailbox_CancelMoveToBag(taskId); + break; + case MENU_NOTHING_CHOSEN: + default: + break; } } static void Mailbox_DoMailMoveToBag(u8 taskId) { - struct MailStruct *mailStruct = &(gSaveBlock1Ptr->mail[playerPCItemPageInfo.itemsAbove + PARTY_SIZE + playerPCItemPageInfo.cursorPos]); - if (!AddBagItem(mailStruct->itemId, 1)) + struct MailStruct *mail = &gSaveBlock1Ptr->mail[gPlayerPCItemPageInfo.itemsAbove + PARTY_SIZE + gPlayerPCItemPageInfo.cursorPos]; + if (!AddBagItem(mail->itemId, 1)) { DisplayItemMessageOnField(taskId, gText_BagIsFull, Mailbox_Cancel); } else { DisplayItemMessageOnField(taskId, gText_MailToBagMessageErased, Mailbox_Cancel); - ClearMailStruct(mailStruct); - Mailbox_UpdateMailList(); - playerPCItemPageInfo.count--; - if (playerPCItemPageInfo.count < (playerPCItemPageInfo.pageItems + playerPCItemPageInfo.itemsAbove) && playerPCItemPageInfo.itemsAbove != 0) - playerPCItemPageInfo.itemsAbove--; - ItemStorage_SetItemAndMailCount(taskId); + ClearMailStruct(mail); + Mailbox_CompactMailList(); + gPlayerPCItemPageInfo.count--; + if (gPlayerPCItemPageInfo.count < (gPlayerPCItemPageInfo.pageItems + gPlayerPCItemPageInfo.itemsAbove) && gPlayerPCItemPageInfo.itemsAbove != 0) + gPlayerPCItemPageInfo.itemsAbove--; + SetPlayerPCListCount(taskId); } } @@ -822,7 +887,7 @@ static void Mailbox_DoGiveMailPokeMenu(u8 taskId) { if (!gPaletteFade.active) { - sub_81D1EC0(); + MailboxMenu_Free(); CleanupOverworldWindowsAndTilemaps(); ChooseMonToGiveMailFromMailbox(); DestroyTask(taskId); @@ -840,15 +905,15 @@ static void Mailbox_UpdateMailListAfterDeposit(void) u8 taskId; u8 prevCount; taskId = CreateTask(Mailbox_HandleReturnToProcessInput, 0); - prevCount = playerPCItemPageInfo.count; - playerPCItemPageInfo.count = GetMailboxMailCount(); - Mailbox_UpdateMailList(); - if (prevCount != playerPCItemPageInfo.count && (playerPCItemPageInfo.count < (playerPCItemPageInfo.pageItems + playerPCItemPageInfo.itemsAbove)) - && playerPCItemPageInfo.itemsAbove != 0) - playerPCItemPageInfo.itemsAbove--; - ItemStorage_SetItemAndMailCount(taskId); + prevCount = gPlayerPCItemPageInfo.count; + gPlayerPCItemPageInfo.count = GetMailboxMailCount(); + Mailbox_CompactMailList(); + if (prevCount != gPlayerPCItemPageInfo.count && (gPlayerPCItemPageInfo.count < (gPlayerPCItemPageInfo.pageItems + gPlayerPCItemPageInfo.itemsAbove)) + && gPlayerPCItemPageInfo.itemsAbove != 0) + gPlayerPCItemPageInfo.itemsAbove--; + SetPlayerPCListCount(taskId); LoadMessageBoxAndBorderGfx(); - if (sub_81D1C44(playerPCItemPageInfo.count) == TRUE) + if (MailboxMenu_Alloc(gPlayerPCItemPageInfo.count) == TRUE) Mailbox_DrawMailboxMenu(taskId); else DestroyTask(taskId); @@ -862,45 +927,44 @@ static void Mailbox_NoPokemonForMail(u8 taskId) static void Mailbox_Cancel(u8 taskId) { - sub_81D1D04(2); + MailboxMenu_RemoveWindow(MAILBOXWIN_OPTIONS); ClearDialogWindowAndFrame(0, 0); Mailbox_DrawMailboxMenu(taskId); ScheduleBgCopyTilemapToVram(0); gTasks[taskId].func = Mailbox_ProcessInput; } -static void sub_816BC14(void) +static void ItemStorage_Init(void) { - gUnknown_0203BCC4 = AllocZeroed(sizeof(struct Struct203BCC4)); - memset(gUnknown_0203BCC4->windowIds, 0xFF, 0x6); - gUnknown_0203BCC4->unk666 = 0xFF; - gUnknown_0203BCC4->spriteId = SPRITE_NONE; + sItemStorageMenu = AllocZeroed(sizeof(*sItemStorageMenu)); + memset(sItemStorageMenu->windowIds, WINDOW_NONE, ITEMPC_WIN_COUNT); + sItemStorageMenu->toSwapPos = NOT_SWAPPING; + sItemStorageMenu->spriteId = SPRITE_NONE; } -static void sub_816BC58(void) +static void ItemStorage_Free(void) { u32 i; - - for(i = 0; i < 6; i++) - sub_816BCC4(i); - Free(gUnknown_0203BCC4); + for (i = 0; i < ITEMPC_WIN_COUNT; i++) + ItemStorage_RemoveWindow(i); + Free(sItemStorageMenu); } -static u8 sub_816BC7C(u8 a) +static u8 ItemStorage_AddWindow(u8 i) { - u8 *windowIdLoc = &(gUnknown_0203BCC4->windowIds[a]); + u8 *windowIdLoc = &sItemStorageMenu->windowIds[i]; if (*windowIdLoc == WINDOW_NONE) { - *windowIdLoc = AddWindow(&gUnknown_085DFF5C[a]); + *windowIdLoc = AddWindow(&sWindowTemplates_ItemStorage[i]); DrawStdFrameWithCustomTileAndPalette(*windowIdLoc, FALSE, 0x214, 0xE); ScheduleBgCopyTilemapToVram(0); } return *windowIdLoc; } -static void sub_816BCC4(u8 a) +static void ItemStorage_RemoveWindow(u8 i) { - u8 *windowIdLoc = &(gUnknown_0203BCC4->windowIds[a]); + u8 *windowIdLoc = &sItemStorageMenu->windowIds[i]; if (*windowIdLoc != WINDOW_NONE) { ClearStdWindowAndFrameToTransparent(*windowIdLoc, FALSE); @@ -915,20 +979,25 @@ void ItemStorage_RefreshListMenu(void) { u16 i; - for(i = 0; i < playerPCItemPageInfo.count - 1; i++) + // Copy item names for all entries but the last (which is Cancel) + for(i = 0; i < gPlayerPCItemPageInfo.count - 1; i++) { - CopyItemName_PlayerPC(&(gUnknown_0203BCC4->unk198[i][0]), gSaveBlock1Ptr->pcItems[i].itemId); - gUnknown_0203BCC4->unk0[i].name = &(gUnknown_0203BCC4->unk198[i][0]); - gUnknown_0203BCC4->unk0[i].id = i; + CopyItemName_PlayerPC(&sItemStorageMenu->itemNames[i][0], gSaveBlock1Ptr->pcItems[i].itemId); + sItemStorageMenu->listItems[i].name = &sItemStorageMenu->itemNames[i][0]; + sItemStorageMenu->listItems[i].id = i; } - StringCopy(&(gUnknown_0203BCC4->unk198[i][0]) ,gText_Cancel2); - gUnknown_0203BCC4->unk0[i].name = &(gUnknown_0203BCC4->unk198[i][0]); - gUnknown_0203BCC4->unk0[i].id = -2; - gMultiuseListMenuTemplate = gUnknown_085DFF44; - gMultiuseListMenuTemplate.windowId = sub_816BC7C(0); - gMultiuseListMenuTemplate.totalItems = playerPCItemPageInfo.count; - gMultiuseListMenuTemplate.items = gUnknown_0203BCC4->unk0; - gMultiuseListMenuTemplate.maxShowed = playerPCItemPageInfo.pageItems; + + // Set up Cancel entry + StringCopy(&sItemStorageMenu->itemNames[i][0], gText_Cancel2); + sItemStorageMenu->listItems[i].name = &sItemStorageMenu->itemNames[i][0]; + sItemStorageMenu->listItems[i].id = LIST_CANCEL; + + // Set list menu data + gMultiuseListMenuTemplate = sListMenuTemplate_ItemStorage; + gMultiuseListMenuTemplate.windowId = ItemStorage_AddWindow(ITEMPC_WIN_LIST); + gMultiuseListMenuTemplate.totalItems = gPlayerPCItemPageInfo.count; + gMultiuseListMenuTemplate.items = sItemStorageMenu->listItems; + gMultiuseListMenuTemplate.maxShowed = gPlayerPCItemPageInfo.pageItems; } void CopyItemName_PlayerPC(u8 *string, u16 itemId) @@ -936,31 +1005,31 @@ void CopyItemName_PlayerPC(u8 *string, u16 itemId) CopyItemName(itemId, string); } -static void ItemStorage_MoveCursor(s32 id, bool8 b, struct ListMenu *thisMenu) +static void ItemStorage_MoveCursor(s32 id, bool8 onInit, struct ListMenu *list) { - if (b != TRUE) + if (onInit != TRUE) PlaySE(SE_SELECT); - if (gUnknown_0203BCC4->unk666 == 0xFF) + if (sItemStorageMenu->toSwapPos == NOT_SWAPPING) { - sub_816C0C8(); + ItemStorage_EraseItemIcon(); if (id != LIST_CANCEL) - sub_816C060(gSaveBlock1Ptr->pcItems[id].itemId); + ItemStorage_DrawItemIcon(gSaveBlock1Ptr->pcItems[id].itemId); else - sub_816C060(ITEMPC_GO_BACK_TO_PREV); - sub_816BEF0(id); + ItemStorage_DrawItemIcon(MSG_GO_BACK_TO_PREV); + ItemStorage_PrintDescription(id); } } -static void fish4_goto_x5_or_x6(u8 windowId, u32 id, u8 yOffset) +static void ItemStorage_PrintMenuItem(u8 windowId, u32 id, u8 yOffset) { if (id != LIST_CANCEL) { - if (gUnknown_0203BCC4->unk666 != 0xFF) + if (sItemStorageMenu->toSwapPos != NOT_SWAPPING) { - if (gUnknown_0203BCC4->unk666 == (u8)id) - sub_816BFE0(yOffset, 0, 0xFF); + if (sItemStorageMenu->toSwapPos == (u8)id) + ItemStorage_DrawSwapArrow(yOffset, 0, TEXT_SPEED_FF); else - sub_816BFE0(yOffset, 0xFF, 0xFF); + ItemStorage_DrawSwapArrow(yOffset, 0xFF, TEXT_SPEED_FF); } ConvertIntToDecimalStringN(gStringVar1, gSaveBlock1Ptr->pcItems[id].quantity, STR_CONV_MODE_RIGHT_ALIGN, 3); StringExpandPlaceholders(gStringVar4, gText_xVar1); @@ -968,58 +1037,64 @@ static void fish4_goto_x5_or_x6(u8 windowId, u32 id, u8 yOffset) } } -static void sub_816BEF0(s32 id) +static void ItemStorage_PrintDescription(s32 id) { const u8* description; - u8 windowId = gUnknown_0203BCC4->windowIds[1]; + u8 windowId = sItemStorageMenu->windowIds[ITEMPC_WIN_MESSAGE]; - if (id != -2) + // Get item description (or Cancel text) + if (id != LIST_CANCEL) description = (u8 *)ItemId_GetDescription(gSaveBlock1Ptr->pcItems[id].itemId); else - description = ItemStorage_GetItemPcResponse(ITEMPC_GO_BACK_TO_PREV); + description = ItemStorage_GetMessage(MSG_GO_BACK_TO_PREV); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); AddTextPrinterParameterized(windowId, 1, description, 0, 1, 0, NULL); } -static void ItemStorage_StartScrollIndicator(void) +static void ItemStorage_AddScrollIndicator(void) { - if (playerPCItemPageInfo.scrollIndicatorTaskId == TASK_NONE) - playerPCItemPageInfo.scrollIndicatorTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 0xB0, 0xC, 0x94, playerPCItemPageInfo.count - playerPCItemPageInfo.pageItems, 0x13F8, 0x13F8, &(playerPCItemPageInfo.itemsAbove)); + if (gPlayerPCItemPageInfo.scrollIndicatorTaskId == TASK_NONE) + gPlayerPCItemPageInfo.scrollIndicatorTaskId = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 176, 12, 148, + gPlayerPCItemPageInfo.count - gPlayerPCItemPageInfo.pageItems, + TAG_SCROLL_ARROW, + TAG_SCROLL_ARROW, + &gPlayerPCItemPageInfo.itemsAbove); } static void ItemStorage_RemoveScrollIndicator(void) { - if (playerPCItemPageInfo.scrollIndicatorTaskId != TASK_NONE) + if (gPlayerPCItemPageInfo.scrollIndicatorTaskId != TASK_NONE) { - RemoveScrollIndicatorArrowPair(playerPCItemPageInfo.scrollIndicatorTaskId); - playerPCItemPageInfo.scrollIndicatorTaskId = TASK_NONE; + RemoveScrollIndicatorArrowPair(gPlayerPCItemPageInfo.scrollIndicatorTaskId); + gPlayerPCItemPageInfo.scrollIndicatorTaskId = TASK_NONE; } } -static void sub_816BFB8(u8 a, u8 b, u8 speed) +static void ItemStorage_SetSwapArrow(u8 listTaskId, u8 b, u8 speed) { - sub_816BFE0(ListMenuGetYCoordForPrintingArrowCursor(a), b, speed); + ItemStorage_DrawSwapArrow(ListMenuGetYCoordForPrintingArrowCursor(listTaskId), b, speed); } -static void sub_816BFE0(u8 y, u8 b, u8 speed) +static void ItemStorage_DrawSwapArrow(u8 y, u8 b, u8 speed) { - u8 windowId = gUnknown_0203BCC4->windowIds[0]; + u8 windowId = sItemStorageMenu->windowIds[ITEMPC_WIN_LIST]; if (b == 0xFF) FillWindowPixelRect(windowId, PIXEL_FILL(1), 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); else - AddTextPrinterParameterized4(windowId, 1, 0, y, 0, 0, gUnknown_085DFF8C, speed, gText_SelectorArrow2); + AddTextPrinterParameterized4(windowId, 1, 0, y, 0, 0, sSwapArrowTextColors, speed, gText_SelectorArrow2); } -static void sub_816C060(u16 itemId) +static void ItemStorage_DrawItemIcon(u16 itemId) { u8 spriteId; - u8* spriteIdLoc = &(gUnknown_0203BCC4->spriteId); + u8* spriteIdLoc = &sItemStorageMenu->spriteId; if (*spriteIdLoc == SPRITE_NONE) { - FreeSpriteTilesByTag(0x13F6); - FreeSpritePaletteByTag(0x13F6); - spriteId = AddItemIconSprite(0x13F6, 0x13F6, itemId); + FreeSpriteTilesByTag(TAG_ITEM_ICON); + FreeSpritePaletteByTag(TAG_ITEM_ICON); + spriteId = AddItemIconSprite(TAG_ITEM_ICON, TAG_ITEM_ICON, itemId); if (spriteId != MAX_SPRITES) { *spriteIdLoc = spriteId; @@ -1030,30 +1105,30 @@ static void sub_816C060(u16 itemId) } } -static void sub_816C0C8(void) +static void ItemStorage_EraseItemIcon(void) { - u8* spriteIdLoc = &(gUnknown_0203BCC4->spriteId); + u8* spriteIdLoc = &sItemStorageMenu->spriteId; if (*spriteIdLoc != SPRITE_NONE) { - FreeSpriteTilesByTag(0x13F6); - FreeSpritePaletteByTag(0x13F6); - DestroySprite(&(gSprites[*spriteIdLoc])); + FreeSpriteTilesByTag(TAG_ITEM_ICON); + FreeSpritePaletteByTag(TAG_ITEM_ICON); + DestroySprite(&gSprites[*spriteIdLoc]); *spriteIdLoc = SPRITE_NONE; } } -static void sub_816C110(void) +static void ItemStorage_CompactList(void) { CompactPCItems(); - sub_812220C(gSaveBlock1Ptr->pcItems, 50, &(playerPCItemPageInfo.pageItems), &(playerPCItemPageInfo.count), 0x8); + SetItemListPerPageCount(gSaveBlock1Ptr->pcItems, PC_ITEMS_COUNT, &gPlayerPCItemPageInfo.pageItems, &gPlayerPCItemPageInfo.count, 8); } -static void sub_816C140(void) +static void ItemStorage_CompactCursor(void) { - sub_812225C(&(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos), playerPCItemPageInfo.pageItems, playerPCItemPageInfo.count); + SetCursorWithinListBounds(&gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos, gPlayerPCItemPageInfo.pageItems, gPlayerPCItemPageInfo.count); } -static void ItemStorage_ProcessWithdrawTossInput(u8 taskId) +static void ItemStorage_CreateListMenu(u8 taskId) { s16 *data; bool32 toss; @@ -1061,98 +1136,97 @@ static void ItemStorage_ProcessWithdrawTossInput(u8 taskId) const u8* text; data = gTasks[taskId].data; - for(i = 0; i <=3; i++) - sub_816BC7C(i); - toss = data[3]; + for (i = 0; i <= ITEMPC_WIN_LIST_END; i++) + ItemStorage_AddWindow(i); + toss = tInTossMenu; text = gText_TossItem; if (!toss) text = gText_WithdrawItem; x = GetStringCenterAlignXOffset(1, text, 104); - AddTextPrinterParameterized(gUnknown_0203BCC4->windowIds[3], 1, text, x, 1, 0, NULL); - CopyWindowToVram(gUnknown_0203BCC4->windowIds[2], 2); - sub_816C110(); - sub_816C140(); + AddTextPrinterParameterized(sItemStorageMenu->windowIds[ITEMPC_WIN_TITLE], 1, text, x, 1, 0, NULL); + CopyWindowToVram(sItemStorageMenu->windowIds[ITEMPC_WIN_ICON], 2); + ItemStorage_CompactList(); + ItemStorage_CompactCursor(); ItemStorage_RefreshListMenu(); - data[5] = ListMenuInit(&gMultiuseListMenuTemplate, playerPCItemPageInfo.itemsAbove, playerPCItemPageInfo.cursorPos); - ItemStorage_StartScrollIndicator(); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gPlayerPCItemPageInfo.itemsAbove, gPlayerPCItemPageInfo.cursorPos); + ItemStorage_AddScrollIndicator(); ScheduleBgCopyTilemapToVram(0); gTasks[taskId].func = ItemStorage_ProcessInput; } -static const u8* ItemStorage_GetItemPcResponse(u16 itemId) +static const u8* ItemStorage_GetMessage(u16 itemId) { const u8 *string; switch(itemId) { - case ITEMPC_GO_BACK_TO_PREV: - string = gText_GoBackPrevMenu; - break; - case ITEMPC_HOW_MANY_TO_WITHDRAW: - string = gText_WithdrawHowManyItems; - break; - case ITEMPC_WITHDREW_THING: - string = gText_WithdrawXItems; - break; - case ITEMPC_HOW_MANY_TO_TOSS: - string = gText_TossHowManyVar1s; - break; - case ITEMPC_THREW_AWAY_ITEM: - string = gText_ThrewAwayVar2Var1s; - break; - case ITEMPC_NO_MORE_ROOM: - string = gText_NoRoomInBag; - break; - case ITEMPC_TOO_IMPORTANT: - string = gText_TooImportantToToss; - break; - case ITEMPC_OKAY_TO_THROW_AWAY: - string = gText_ConfirmTossItems; - break; - case ITEMPC_SWITCH_WHICH_ITEM: - string = gText_MoveVar1Where; - break; - default: - string = ItemId_GetDescription(itemId); - break; + case MSG_GO_BACK_TO_PREV: + string = gText_GoBackPrevMenu; + break; + case MSG_HOW_MANY_TO_WITHDRAW: + string = gText_WithdrawHowManyItems; + break; + case MSG_WITHDREW_ITEM: + string = gText_WithdrawXItems; + break; + case MSG_HOW_MANY_TO_TOSS: + string = gText_TossHowManyVar1s; + break; + case MSG_THREW_AWAY_ITEM: + string = gText_ThrewAwayVar2Var1s; + break; + case MSG_NO_MORE_ROOM: + string = gText_NoRoomInBag; + break; + case MSG_TOO_IMPORTANT: + string = gText_TooImportantToToss; + break; + case MSG_OKAY_TO_THROW_AWAY: + string = gText_ConfirmTossItems; + break; + case MSG_SWITCH_WHICH_ITEM: + string = gText_MoveVar1Where; + break; + default: + string = ItemId_GetDescription(itemId); + break; } return string; } -static void ItemStorage_PrintItemPcResponse(const u8 *string) +static void ItemStorage_PrintMessage(const u8 *string) { - u8 windowId = gUnknown_0203BCC4->windowIds[1]; + u8 windowId = sItemStorageMenu->windowIds[ITEMPC_WIN_MESSAGE]; FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); StringExpandPlaceholders(gStringVar4, string); AddTextPrinterParameterized(windowId, 1, gStringVar4, 0, 1, 0, NULL); } +// Process input while on the item storage's item list static void ItemStorage_ProcessInput(u8 taskId) { - s16 *data; - s32 id; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; if (JOY_NEW(SELECT_BUTTON)) { - ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); - if ((playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos) != (playerPCItemPageInfo.count - 1)) + // 'Select' starts input for swapping items if not on Cancel + ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos); + if (gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos != gPlayerPCItemPageInfo.count - 1) { PlaySE(SE_SELECT); - ItemStorage_ItemSwapChoosePrompt(taskId); + ItemStorage_StartItemSwap(taskId); } } else { - id = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); - switch(id) + s32 id = ListMenu_ProcessInput(tListTaskId); + ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos); + switch (id) { case LIST_NOTHING_CHOSEN: break; case LIST_CANCEL: PlaySE(SE_SELECT); - ItemStorage_GoBackToPlayerPCMenu(taskId); + ItemStorage_ExitItemList(taskId); break; default: PlaySE(SE_SELECT); @@ -1162,50 +1236,46 @@ static void ItemStorage_ProcessInput(u8 taskId) } } -static void ItemStorage_GoBackToPlayerPCMenu_InitStorage(u8 taskId) +static void ItemStorage_ReturnToMenuSelect(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; if (!IsDma3ManagerBusyWithBgCopy()) { DrawDialogueFrame(0, 0); - if (!data[3]) - InitItemStorageMenu(taskId, ITEMPC_MENU_WITHDRAW); + + // Select Withdraw/Toss by default depending on which was just exited + if (!tInTossMenu) + InitItemStorageMenu(taskId, MENU_WITHDRAW); else - InitItemStorageMenu(taskId, ITEMPC_MENU_TOSS); + InitItemStorageMenu(taskId, MENU_TOSS); gTasks[taskId].func = ItemStorageMenuProcessInput; } } -static void ItemStorage_GoBackToPlayerPCMenu(u8 taskId) +static void ItemStorage_ExitItemList(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; - sub_816C0C8(); + s16 *data = gTasks[taskId].data; + ItemStorage_EraseItemIcon(); ItemStorage_RemoveScrollIndicator(); - DestroyListMenuTask(data[5], NULL, NULL); - DestroySwapLineSprites(gUnknown_0203BCC4->spriteIds, 7); - sub_816BC58(); - gTasks[taskId].func = ItemStorage_GoBackToPlayerPCMenu_InitStorage; + DestroyListMenuTask(tListTaskId, NULL, NULL); + DestroySwapLineSprites(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH); + ItemStorage_Free(); + gTasks[taskId].func = ItemStorage_ReturnToMenuSelect; } -static void ItemStorage_ItemSwapChoosePrompt(u8 taskId) +static void ItemStorage_StartItemSwap(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; - ListMenuSetUnkIndicatorsStructField(data[5], 16, 1); - gUnknown_0203BCC4->unk666 = (playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos); - sub_816BFB8(data[5], 0, 0); - 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; + s16 *data = gTasks[taskId].data; + ListMenuSetUnkIndicatorsStructField(tListTaskId, 16, 1); + sItemStorageMenu->toSwapPos = gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos; + ItemStorage_SetSwapArrow(tListTaskId, 0, 0); + ItemStorage_UpdateSwapLinePos(sItemStorageMenu->toSwapPos); + CopyItemName(gSaveBlock1Ptr->pcItems[sItemStorageMenu->toSwapPos].itemId, gStringVar1); + ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_SWITCH_WHICH_ITEM)); + gTasks[taskId].func = ItemStorage_ProcessItemSwapInput; } -static void sub_816C4FC(u8 taskId) +static void ItemStorage_ProcessItemSwapInput(u8 taskId) { s16 *data; s32 id; @@ -1213,225 +1283,220 @@ static void sub_816C4FC(u8 taskId) data = gTasks[taskId].data; if (JOY_NEW(SELECT_BUTTON)) { - ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); - ItemStorage_DoItemSwap(taskId, FALSE); + ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos); + ItemStorage_FinishItemSwap(taskId, FALSE); return; } - id = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); - SetSwapLineSpritesInvisibility(gUnknown_0203BCC4->spriteIds, 7, FALSE); - UpdateSwapLinePos(playerPCItemPageInfo.cursorPos); - switch(id) + id = ListMenu_ProcessInput(tListTaskId); + ListMenuGetScrollAndRow(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos); + SetSwapLineSpritesInvisibility(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH, FALSE); + ItemStorage_UpdateSwapLinePos(gPlayerPCItemPageInfo.cursorPos); + switch (id) { case LIST_NOTHING_CHOSEN: break; case LIST_CANCEL: if (JOY_NEW(A_BUTTON)) - { - ItemStorage_DoItemSwap(taskId, FALSE); - } + ItemStorage_FinishItemSwap(taskId, FALSE); else - { - ItemStorage_DoItemSwap(taskId, TRUE); - } + ItemStorage_FinishItemSwap(taskId, TRUE); break; default: - ItemStorage_DoItemSwap(taskId, FALSE); + ItemStorage_FinishItemSwap(taskId, FALSE); break; } } -static void ItemStorage_DoItemSwap(u8 taskId, bool8 a) +static void ItemStorage_FinishItemSwap(u8 taskId, bool8 canceled) { - s16 *data; - u16 b; - - data = gTasks[taskId].data; - b = (playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos); + s16 *data = gTasks[taskId].data; + u16 newPos = gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos; PlaySE(SE_SELECT); - DestroyListMenuTask(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); - if (!a) + DestroyListMenuTask(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos); + + if (!canceled && sItemStorageMenu->toSwapPos != newPos && sItemStorageMenu->toSwapPos != newPos - 1) { - if (gUnknown_0203BCC4->unk666 != b) - { - if (gUnknown_0203BCC4->unk666 != b - 1) - { - MoveItemSlotInList(gSaveBlock1Ptr->pcItems, gUnknown_0203BCC4->unk666, b); - ItemStorage_RefreshListMenu(); - } - } + MoveItemSlotInList(gSaveBlock1Ptr->pcItems, sItemStorageMenu->toSwapPos, newPos); + ItemStorage_RefreshListMenu(); } - if (gUnknown_0203BCC4->unk666 < b) - playerPCItemPageInfo.cursorPos--; - SetSwapLineSpritesInvisibility(gUnknown_0203BCC4->spriteIds, 7, TRUE); - gUnknown_0203BCC4->unk666 = 0xFF; - data[5] = ListMenuInit(&gMultiuseListMenuTemplate, playerPCItemPageInfo.itemsAbove, playerPCItemPageInfo.cursorPos); + if (sItemStorageMenu->toSwapPos < newPos) + gPlayerPCItemPageInfo.cursorPos--; + + SetSwapLineSpritesInvisibility(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH, TRUE); + sItemStorageMenu->toSwapPos = NOT_SWAPPING; + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gPlayerPCItemPageInfo.itemsAbove, gPlayerPCItemPageInfo.cursorPos); ScheduleBgCopyTilemapToVram(0); gTasks[taskId].func = ItemStorage_ProcessInput; } -static void UpdateSwapLinePos(u8 y) +static void ItemStorage_UpdateSwapLinePos(u8 y) { - UpdateSwapLineSpritesPos(gUnknown_0203BCC4->spriteIds, 7, 128, ((y+1) * 16)); + UpdateSwapLineSpritesPos(sItemStorageMenu->swapLineSpriteIds, SWAP_LINE_LENGTH, 128, (y+1) * 16); } -static void sub_816C6BC(u8 windowId, u16 value, u32 mode, u8 x, u8 y, u8 n) +static void ItemStorage_PrintItemQuantity(u8 windowId, u16 value, u32 mode, u8 x, u8 y, u8 n) { ConvertIntToDecimalStringN(gStringVar1, value, mode, n); StringExpandPlaceholders(gStringVar4, gText_xVar1); AddTextPrinterParameterized(windowId, 1, gStringVar4, GetStringCenterAlignXOffset(1, gStringVar4, 48), y, 0, NULL); } +// Start an item Withdraw/Toss static void ItemStorage_DoItemAction(u8 taskId) { - s16 *data; - u16 b; - - data = gTasks[taskId].data; - b = (playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove); + s16 *data = gTasks[taskId].data; + u16 pos = gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove; ItemStorage_RemoveScrollIndicator(); - data[2] = 1; - if (!data[3]) + tQuantity = 1; + + if (!tInTossMenu) { - if (gSaveBlock1Ptr->pcItems[b].quantity == 1) + if (gSaveBlock1Ptr->pcItems[pos].quantity == 1) { + // Withdrawing 1 item, do it automatically ItemStorage_DoItemWithdraw(taskId); return; } - CopyItemName(gSaveBlock1Ptr->pcItems[b].itemId, gStringVar1); - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(ITEMPC_HOW_MANY_TO_WITHDRAW)); + + // Withdrawing multiple items, show "how many" message + CopyItemName(gSaveBlock1Ptr->pcItems[pos].itemId, gStringVar1); + ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_HOW_MANY_TO_WITHDRAW)); } else { - if (gSaveBlock1Ptr->pcItems[b].quantity == 1) + if (gSaveBlock1Ptr->pcItems[pos].quantity == 1) { + // Tossing 1 item, do it automatically ItemStorage_DoItemToss(taskId); return; } - CopyItemName(gSaveBlock1Ptr->pcItems[b].itemId, gStringVar1); - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(ITEMPC_HOW_MANY_TO_TOSS)); + + // Tossing multiple items, show "how many" message + CopyItemName(gSaveBlock1Ptr->pcItems[pos].itemId, gStringVar1); + ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_HOW_MANY_TO_TOSS)); } - sub_816C6BC(sub_816BC7C(4), data[2], STR_CONV_MODE_LEADING_ZEROS, 8, 1, 3); + + // Set up "how many" prompt + ItemStorage_PrintItemQuantity(ItemStorage_AddWindow(ITEMPC_WIN_QUANTITY), tQuantity, STR_CONV_MODE_LEADING_ZEROS, 8, 1, 3); gTasks[taskId].func = ItemStorage_HandleQuantityRolling; } static void ItemStorage_HandleQuantityRolling(u8 taskId) { - s16 *data; - u16 b; + s16 *data = gTasks[taskId].data; + u16 pos = gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove; - data = gTasks[taskId].data; - b = (playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove); - if (AdjustQuantityAccordingToDPadInput(&(data[2]), gSaveBlock1Ptr->pcItems[b].quantity) == TRUE) - sub_816C6BC(sub_816BC7C(4), data[2], STR_CONV_MODE_LEADING_ZEROS, 8, 1, 3); + if (AdjustQuantityAccordingToDPadInput(&tQuantity, gSaveBlock1Ptr->pcItems[pos].quantity) == TRUE) + { + ItemStorage_PrintItemQuantity(ItemStorage_AddWindow(ITEMPC_WIN_QUANTITY), tQuantity, STR_CONV_MODE_LEADING_ZEROS, 8, 1, 3); + } else { if (JOY_NEW(A_BUTTON)) { + // Quantity confirmed, perform action PlaySE(SE_SELECT); - sub_816BCC4(4); - if (!data[3]) + ItemStorage_RemoveWindow(ITEMPC_WIN_QUANTITY); + if (!tInTossMenu) ItemStorage_DoItemWithdraw(taskId); else ItemStorage_DoItemToss(taskId); } else if (JOY_NEW(B_BUTTON)) { + // Canceled action PlaySE(SE_SELECT); - sub_816BCC4(4); - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(gSaveBlock1Ptr->pcItems[b].itemId)); - ItemStorage_StartScrollIndicatorAndProcessInput(taskId); + ItemStorage_RemoveWindow(ITEMPC_WIN_QUANTITY); + ItemStorage_PrintMessage(ItemStorage_GetMessage(gSaveBlock1Ptr->pcItems[pos].itemId)); + ItemStorage_ReturnToListInput(taskId); } } } static void ItemStorage_DoItemWithdraw(u8 taskId) { - s16 *data; - u16 b; + s16 *data = gTasks[taskId].data; + u16 pos = gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove; - data = gTasks[taskId].data; - b = (playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove); - if (AddBagItem(gSaveBlock1Ptr->pcItems[b].itemId, data[2]) == TRUE) + if (AddBagItem(gSaveBlock1Ptr->pcItems[pos].itemId, tQuantity) == TRUE) { - CopyItemName(gSaveBlock1Ptr->pcItems[b].itemId, gStringVar1); - ConvertIntToDecimalStringN(gStringVar2, data[2], STR_CONV_MODE_LEFT_ALIGN, 3); - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(ITEMPC_WITHDREW_THING)); + // Item withdrawn + CopyItemName(gSaveBlock1Ptr->pcItems[pos].itemId, gStringVar1); + ConvertIntToDecimalStringN(gStringVar2, tQuantity, STR_CONV_MODE_LEFT_ALIGN, 3); + ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_WITHDREW_ITEM)); gTasks[taskId].func = ItemStorage_HandleRemoveItem; } else { - data[2] = 0; - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(ITEMPC_NO_MORE_ROOM)); - gTasks[taskId].func = ItemStorage_WaitPressHandleResumeProcessInput; + // No room to withdraw items + tQuantity = 0; + ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_NO_MORE_ROOM)); + gTasks[taskId].func = ItemStorage_HandleErrorMessageInput; } } static void ItemStorage_DoItemToss(u8 taskId) { - s16 *data; - u16 b; + s16 *data = gTasks[taskId].data; + u16 pos = gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove; - data = gTasks[taskId].data; - b = (playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove); - if (!ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId)) + if (!ItemId_GetImportance(gSaveBlock1Ptr->pcItems[pos].itemId)) { - CopyItemName(gSaveBlock1Ptr->pcItems[b].itemId, gStringVar1); - ConvertIntToDecimalStringN(gStringVar2, data[2], STR_CONV_MODE_LEFT_ALIGN, 3); - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(ITEMPC_OKAY_TO_THROW_AWAY)); - CreateYesNoMenuWithCallbacks(taskId, &gUnknown_085DFF84, 1, 0, 1, 0x214, 0xE, &ResumeFromWithdrawYesNoFuncList); + // Show toss confirmation prompt + CopyItemName(gSaveBlock1Ptr->pcItems[pos].itemId, gStringVar1); + ConvertIntToDecimalStringN(gStringVar2, tQuantity, STR_CONV_MODE_LEFT_ALIGN, 3); + ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_OKAY_TO_THROW_AWAY)); + CreateYesNoMenuWithCallbacks(taskId, &sWindowTemplates_ItemStorage[ITEMPC_WIN_YESNO], 1, 0, 1, 0x214, 0xE, &ItemTossYesNoFuncs); } else { - data[2] = 0; - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(ITEMPC_TOO_IMPORTANT)); - gTasks[taskId].func = ItemStorage_WaitPressHandleResumeProcessInput; + // Can't toss important items + tQuantity = 0; + ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_TOO_IMPORTANT)); + gTasks[taskId].func = ItemStorage_HandleErrorMessageInput; } } -static void ItemStorage_ResumeInputFromYesToss(u8 taskId) +static void ItemStorage_TossItemYes(u8 taskId) { - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(ITEMPC_THREW_AWAY_ITEM)); + ItemStorage_PrintMessage(ItemStorage_GetMessage(MSG_THREW_AWAY_ITEM)); gTasks[taskId].func = ItemStorage_HandleRemoveItem; } -static void ItemStorage_ResumeInputFromNoToss(u8 taskId) +static void ItemStorage_TossItemNo(u8 taskId) { - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(gSaveBlock1Ptr->pcItems[(playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos)].itemId)); - ItemStorage_StartScrollIndicatorAndProcessInput(taskId); + ItemStorage_PrintMessage(ItemStorage_GetMessage(gSaveBlock1Ptr->pcItems[gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos].itemId)); + ItemStorage_ReturnToListInput(taskId); } +// Remove item from PC (was either Tossed or Withdrawn) static void ItemStorage_HandleRemoveItem(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; if (JOY_NEW(A_BUTTON | B_BUTTON)) { - RemovePCItem((playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove), data[2]); - DestroyListMenuTask(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); - sub_816C110(); - sub_816C140(); + RemovePCItem(gPlayerPCItemPageInfo.cursorPos + gPlayerPCItemPageInfo.itemsAbove, tQuantity); + DestroyListMenuTask(tListTaskId, &gPlayerPCItemPageInfo.itemsAbove, &gPlayerPCItemPageInfo.cursorPos); + ItemStorage_CompactList(); + ItemStorage_CompactCursor(); ItemStorage_RefreshListMenu(); - data[5] = ListMenuInit(&gMultiuseListMenuTemplate, playerPCItemPageInfo.itemsAbove, playerPCItemPageInfo.cursorPos); - ItemStorage_StartScrollIndicatorAndProcessInput(taskId); + tListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, gPlayerPCItemPageInfo.itemsAbove, gPlayerPCItemPageInfo.cursorPos); + ItemStorage_ReturnToListInput(taskId); } } -static void ItemStorage_WaitPressHandleResumeProcessInput(u8 taskId) +static void ItemStorage_HandleErrorMessageInput(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; if (JOY_NEW(A_BUTTON | B_BUTTON)) { - ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(gSaveBlock1Ptr->pcItems[(playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos)].itemId)); - ItemStorage_StartScrollIndicatorAndProcessInput(taskId); + ItemStorage_PrintMessage(ItemStorage_GetMessage(gSaveBlock1Ptr->pcItems[gPlayerPCItemPageInfo.itemsAbove + gPlayerPCItemPageInfo.cursorPos].itemId)); + ItemStorage_ReturnToListInput(taskId); } } -static void ItemStorage_StartScrollIndicatorAndProcessInput(u8 taskId) +static void ItemStorage_ReturnToListInput(u8 taskId) { - ItemStorage_StartScrollIndicator(); + ItemStorage_AddScrollIndicator(); gTasks[taskId].func = ItemStorage_ProcessInput; } diff --git a/src/region_map.c b/src/region_map.c index 1a25d140c..4e547b5fb 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -48,6 +48,12 @@ #define FLYDESTICON_RED_OUTLINE 6 +enum { + TAG_CURSOR, + TAG_PLAYER_ICON, + TAG_FLY_ICON, +}; + // Static type declarations struct MultiNameFlyDest @@ -237,13 +243,13 @@ static const union AnimCmd *const sRegionMapCursorAnimTable[] = static const struct SpritePalette sRegionMapCursorSpritePalette = { .data = sRegionMapCursorPal, - .tag = 0 + .tag = TAG_CURSOR }; static const struct SpriteTemplate sRegionMapCursorSpriteTemplate = { - .tileTag = 0, - .paletteTag = 0, + .tileTag = TAG_CURSOR, + .paletteTag = TAG_CURSOR, .oam = &sRegionMapCursorOam, .anims = sRegionMapCursorAnimTable, .images = NULL, @@ -419,7 +425,7 @@ static const struct WindowTemplate sFlyMapWindowTemplates[] = static const struct SpritePalette sFlyTargetIconsSpritePalette = { .data = sFlyTargetIcons_Pal, - .tag = 2 + .tag = TAG_FLY_ICON }; static const u16 sRedOutlineFlyDestinations[][2] = @@ -497,8 +503,8 @@ static const union AnimCmd *const sFlyDestIcon_Anims[] = static const struct SpriteTemplate sFlyDestIconSpriteTemplate = { - .tileTag = 2, - .paletteTag = 2, + .tileTag = TAG_FLY_ICON, + .paletteTag = TAG_FLY_ICON, .oam = &sFlyDestIcon_OamData, .anims = sFlyDestIcon_Anims, .images = NULL, @@ -1692,8 +1698,8 @@ void CB2_OpenFlyMap(void) break; case 4: InitRegionMap(&sFlyMap->regionMap, FALSE); - CreateRegionMapCursor(0, 0); - CreateRegionMapPlayerIcon(1, 1); + CreateRegionMapCursor(TAG_CURSOR, TAG_CURSOR); + CreateRegionMapPlayerIcon(TAG_PLAYER_ICON, TAG_PLAYER_ICON); sFlyMap->mapSecId = sFlyMap->regionMap.mapSecId; StringFill(sFlyMap->nameBuffer, CHAR_SPACE, MAP_NAME_LENGTH); sDrawFlyDestTextWindow = TRUE; @@ -1827,7 +1833,7 @@ static void LoadFlyDestIcons(void) LZ77UnCompWram(sFlyTargetIcons_Gfx, sFlyMap->tileBuffer); sheet.data = sFlyMap->tileBuffer; sheet.size = sizeof(sFlyMap->tileBuffer); - sheet.tag = 2; + sheet.tag = TAG_FLY_ICON; LoadSpriteSheet(&sheet); LoadSpritePalette(&sFlyTargetIconsSpritePalette); CreateFlyDestIcons(); diff --git a/src/secret_base.c b/src/secret_base.c index e1c62e2f2..ce455642b 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -1074,7 +1074,7 @@ void DeleteRegistry_Yes_Callback(u8 taskId) DestroyListMenuTask(tListTaskId, &tScrollOffset, &tSelectedRow); gSaveBlock1Ptr->secretBases[tSelectedBaseId].registryStatus = UNREGISTERED; BuildRegistryMenuItems(taskId); - sub_812225C(&tScrollOffset, &tSelectedRow, tMaxShownItems, tNumBases); + SetCursorWithinListBounds(&tScrollOffset, &tSelectedRow, tMaxShownItems, tNumBases); FinalizeRegistryMenu(taskId); gTasks[taskId].func = HandleRegistryMenuInput; } diff --git a/src/strings.c b/src/strings.c index 4987e32d2..e1a6d2efb 100644 --- a/src/strings.c +++ b/src/strings.c @@ -1,6 +1,7 @@ #include "global.h" #include "strings.h" #include "battle_pyramid_bag.h" +#include "item_menu.h" ALIGNED(4) const u8 gText_ExpandedPlaceholder_Empty[] = _(""); @@ -255,18 +256,18 @@ const u8 gText_ThePC[] = _("the PC"); const u8 *const gBagMenu_ReturnToStrings[] = { - gText_TheField, - gText_TheBattle, - gText_ThePokemonList, - gText_TheShop, - gText_TheField, - gText_TheField, - gText_ThePC, - gText_TheField, - gText_TheField, - gText_TheField, - gText_TheBattle, - gText_ThePC + [ITEMMENULOCATION_FIELD] = gText_TheField, + [ITEMMENULOCATION_BATTLE] = gText_TheBattle, + [ITEMMENULOCATION_PARTY] = gText_ThePokemonList, + [ITEMMENULOCATION_SHOP] = gText_TheShop, + [ITEMMENULOCATION_BERRY_TREE] = gText_TheField, + [ITEMMENULOCATION_BERRY_BLENDER_CRUSH] = gText_TheField, + [ITEMMENULOCATION_ITEMPC] = gText_ThePC, + [ITEMMENULOCATION_FAVOR_LADY] = gText_TheField, + [ITEMMENULOCATION_QUIZ_LADY] = gText_TheField, + [ITEMMENULOCATION_APPRENTICE] = gText_TheField, + [ITEMMENULOCATION_WALLY] = gText_TheBattle, + [ITEMMENULOCATION_PCBOX] = gText_ThePC }; const u8 *const gPyramidBagMenu_ReturnToStrings[] = @@ -286,15 +287,15 @@ const u8 gText_KeyItemsPocket[] = _("KEY ITEMS"); const u8 *const gPocketNamesStringsTable[] = { - gText_ItemsPocket, - gText_PokeBallsPocket, - gText_TMHMPocket, - gText_BerriesPocket, - gText_KeyItemsPocket + [ITEMS_POCKET] = gText_ItemsPocket, + [BALLS_POCKET] = gText_PokeBallsPocket, + [TMHM_POCKET] = gText_TMHMPocket, + [BERRIES_POCKET] = gText_BerriesPocket, + [KEYITEMS_POCKET] = gText_KeyItemsPocket }; -const u8 gText_NumberVar1Clear7Var2[] = _("{NO}{STR_VAR_1}{CLEAR 0x07}{STR_VAR_2}"); -const u8 gText_ClearTo11Var1Clear5Var2[] = _("{CLEAR_TO 0x11}{STR_VAR_1}{CLEAR 0x05}{STR_VAR_2}"); +const u8 gText_NumberItem_TMBerry[] = _("{NO}{STR_VAR_1}{CLEAR 0x07}{STR_VAR_2}"); +const u8 gText_NumberItem_HM[] = _("{CLEAR_TO 0x11}{STR_VAR_1}{CLEAR 0x05}{STR_VAR_2}"); const u8 gText_SizeSlash[] = _("SIZE /"); const u8 gText_FirmSlash[] = _("FIRM /"); const u8 gText_Var1DotVar2[] = _("{STR_VAR_1}.{STR_VAR_2}”");