From ed7136cfc53ce4e5df8349f50aea247bb593865d Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:53:52 +0200 Subject: [PATCH] item_menu refactoring --- include/constants/item.h | 1 + include/item_menu.h | 6 +++--- src/battle_controller_pokedude.c | 3 ++- src/item.c | 4 ++-- src/item_menu.c | 23 ++++++++++++----------- src/party_menu.c | 1 + src/player_pc.c | 1 + src/pokemon_storage_system_tasks.c | 3 ++- src/shop.c | 7 ++++--- src/teachy_tv.c | 3 ++- 10 files changed, 30 insertions(+), 22 deletions(-) diff --git a/include/constants/item.h b/include/constants/item.h index e8910553d..604fdc4a9 100644 --- a/include/constants/item.h +++ b/include/constants/item.h @@ -9,6 +9,7 @@ #define POCKET_TM_HM 4 #define POCKET_BERRIES 5 #define NUM_BAG_POCKETS 5 +#define NUM_BAG_POCKETS_NO_CASES 3 // number of pockets without considering TM case or berry pouch #define ITEMS_POCKET 0 #define KEYITEMS_POCKET 1 diff --git a/include/item_menu.h b/include/item_menu.h index 3ba3de4a9..69aa7f825 100644 --- a/include/item_menu.h +++ b/include/item_menu.h @@ -3,7 +3,7 @@ #include "global.h" #include "task.h" -#include "constants/item_menu.h" +#include "constants/item.h" // Exported type declarations @@ -15,8 +15,8 @@ struct BagStruct u8 location; bool8 bagOpen; u16 pocket; - u16 itemsAbove[3]; - u16 cursorPos[3]; + u16 itemsAbove[NUM_BAG_POCKETS_NO_CASES]; + u16 cursorPos[NUM_BAG_POCKETS_NO_CASES]; }; extern struct BagStruct gBagMenuState; diff --git a/src/battle_controller_pokedude.c b/src/battle_controller_pokedude.c index e28a6fa0e..850ccc269 100644 --- a/src/battle_controller_pokedude.c +++ b/src/battle_controller_pokedude.c @@ -18,9 +18,10 @@ #include "reshow_battle_screen.h" #include "teachy_tv.h" #include "constants/battle_string_ids.h" -#include "constants/songs.h" +#include "constants/item_menu.h" #include "constants/moves.h" #include "constants/pokemon.h" +#include "constants/songs.h" struct PokedudeTextScriptHeader { diff --git a/src/item.c b/src/item.c index 035b0df9e..284b2406e 100644 --- a/src/item.c +++ b/src/item.c @@ -11,8 +11,8 @@ #include "quest_log.h" #include "strings.h" #include "constants/hold_effects.h" -#include "constants/item_effects.h" #include "constants/item.h" +#include "constants/item_effects.h" #include "constants/items.h" #include "constants/maps.h" @@ -345,7 +345,7 @@ void ClearBag(void) { u16 i; - for (i = 0; i < 5; i++) + for (i = 0; i < NUM_BAG_POCKETS; i++) { ClearItemSlots(gBagPockets[i].itemSlots, gBagPockets[i].capacity); } diff --git a/src/item_menu.c b/src/item_menu.c index 8fa7282b0..1631ead95 100644 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -32,9 +32,10 @@ #include "strings.h" #include "teachy_tv.h" #include "tm_case.h" +#include "constants/item_menu.h" #include "constants/items.h" -#include "constants/songs.h" #include "constants/quest_log.h" +#include "constants/songs.h" #define FREE_IF_SET(ptr) ({ if (ptr) Free(ptr); }) @@ -48,8 +49,8 @@ struct BagMenuAlloc u16 contextMenuSelectedItem; u8 pocketScrollArrowsTask; u8 pocketSwitchArrowsTask; - u8 nItems[3]; - u8 maxShowed[3]; + u8 nItems[NUM_BAG_POCKETS_NO_CASES]; + u8 maxShowed[NUM_BAG_POCKETS_NO_CASES]; u8 data[4]; }; @@ -58,8 +59,8 @@ struct BagSlots struct ItemSlot bagPocket_Items[BAG_ITEMS_COUNT]; struct ItemSlot bagPocket_KeyItems[BAG_KEYITEMS_COUNT]; struct ItemSlot bagPocket_PokeBalls[BAG_POKEBALLS_COUNT]; - u16 itemsAbove[3]; - u16 cursorPos[3]; + u16 itemsAbove[NUM_BAG_POCKETS_NO_CASES]; + u16 cursorPos[NUM_BAG_POCKETS_NO_CASES]; u16 registeredItem; u16 pocket; }; @@ -833,7 +834,7 @@ void ResetBagCursorPositions(void) u8 i; gBagMenuState.pocket = POCKET_ITEMS - 1; gBagMenuState.bagOpen = FALSE; - for (i = 0; i < 3; i++) + for (i = 0; i < NUM_BAG_POCKETS_NO_CASES; i++) { gBagMenuState.itemsAbove[i] = 0; gBagMenuState.cursorPos[i] = 0; @@ -858,7 +859,7 @@ void PocketCalculateInitialCursorPosAndItemsAbove(u8 pocketId) static void CalculateInitialCursorPosAndItemsAbove(void) { u8 i; - for (i = 0; i < 3; i++) + for (i = 0; i < NUM_BAG_POCKETS_NO_CASES; i++) { PocketCalculateInitialCursorPosAndItemsAbove(i); } @@ -869,7 +870,7 @@ static void UpdatePocketScrollPositions(void) u8 i; u8 j; - for (i = 0; i < 3; i++) + for (i = 0; i < NUM_BAG_POCKETS_NO_CASES; i++) { if (gBagMenuState.itemsAbove[i] > 3) { @@ -1012,7 +1013,7 @@ void Pocket_CalculateNItemsAndMaxShowed(u8 pocketId) static void All_CalculateNItemsAndMaxShowed(void) { u8 i; - for (i = 0; i < 3; i++) + for (i = 0; i < NUM_BAG_POCKETS_NO_CASES; i++) Pocket_CalculateNItemsAndMaxShowed(i); } @@ -2067,7 +2068,7 @@ static void BackUpPlayerBag(void) memcpy(sBackupPlayerBag->bagPocket_PokeBalls, gSaveBlock1Ptr->bagPocket_PokeBalls, BAG_POKEBALLS_COUNT * sizeof(struct ItemSlot)); sBackupPlayerBag->registeredItem = gSaveBlock1Ptr->registeredItem; sBackupPlayerBag->pocket = gBagMenuState.pocket; - for (i = 0; i < 3; i++) + for (i = 0; i < NUM_BAG_POCKETS_NO_CASES; i++) { sBackupPlayerBag->itemsAbove[i] = gBagMenuState.itemsAbove[i]; sBackupPlayerBag->cursorPos[i] = gBagMenuState.cursorPos[i]; @@ -2087,7 +2088,7 @@ static void RestorePlayerBag(void) memcpy(gSaveBlock1Ptr->bagPocket_PokeBalls, sBackupPlayerBag->bagPocket_PokeBalls, BAG_POKEBALLS_COUNT * sizeof(struct ItemSlot)); gSaveBlock1Ptr->registeredItem = sBackupPlayerBag->registeredItem; gBagMenuState.pocket = sBackupPlayerBag->pocket; - for (i = 0; i < 3; i++) + for (i = 0; i < NUM_BAG_POCKETS_NO_CASES; i++) { gBagMenuState.itemsAbove[i] = sBackupPlayerBag->itemsAbove[i]; gBagMenuState.cursorPos[i] = sBackupPlayerBag->cursorPos[i]; diff --git a/src/party_menu.c b/src/party_menu.c index 6f5ab9e39..57e8773be 100644 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -65,6 +65,7 @@ #include "constants/easy_chat.h" #include "constants/field_effects.h" #include "constants/item_effects.h" +#include "constants/item_menu.h" #include "constants/items.h" #include "constants/maps.h" #include "constants/moves.h" diff --git a/src/player_pc.c b/src/player_pc.c index cb86cb260..fa24eff86 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -19,6 +19,7 @@ #include "item_menu.h" #include "item_pc.h" #include "party_menu.h" +#include "constants/item_menu.h" #include "constants/items.h" #include "constants/songs.h" #include "constants/field_weather.h" diff --git a/src/pokemon_storage_system_tasks.c b/src/pokemon_storage_system_tasks.c index a3e7a5c8f..190f17d30 100644 --- a/src/pokemon_storage_system_tasks.c +++ b/src/pokemon_storage_system_tasks.c @@ -22,8 +22,9 @@ #include "text_window.h" #include "tilemap_util.h" #include "trig.h" -#include "constants/items.h" #include "constants/help_system.h" +#include "constants/item_menu.h" +#include "constants/items.h" #include "constants/songs.h" EWRAM_DATA struct PokemonStorageSystemData *gStorage = NULL; diff --git a/src/shop.c b/src/shop.c index ad9580c74..36df111f9 100644 --- a/src/shop.c +++ b/src/shop.c @@ -26,10 +26,11 @@ #include "money.h" #include "quest_log.h" #include "script.h" -#include "constants/songs.h" -#include "constants/items.h" -#include "constants/game_stat.h" #include "constants/field_weather.h" +#include "constants/game_stat.h" +#include "constants/item_menu.h" +#include "constants/items.h" +#include "constants/songs.h" #define tItemCount data[1] #define tItemId data[5] diff --git a/src/teachy_tv.c b/src/teachy_tv.c index 5fd50e8dd..4c62eb036 100644 --- a/src/teachy_tv.c +++ b/src/teachy_tv.c @@ -25,8 +25,9 @@ #include "graphics.h" #include "fieldmap.h" #include "strings.h" -#include "constants/field_effects.h" #include "constants/event_objects.h" +#include "constants/field_effects.h" +#include "constants/item_menu.h" struct TeachyTvCtrlBlk {