Document player pc

This commit is contained in:
GriffinR 2021-04-25 12:07:08 -04:00
parent f823cd224f
commit 06b909bcd8
11 changed files with 711 additions and 706 deletions

View File

@ -32,8 +32,8 @@ bool8 sub_8122148(u16 itemId);
bool8 itemid_80BF6D8_mail_related(u16 itemId); bool8 itemid_80BF6D8_mail_related(u16 itemId);
bool8 MenuHelpers_LinkSomething(void); bool8 MenuHelpers_LinkSomething(void);
bool8 MenuHelpers_CallLinkSomething(void); bool8 MenuHelpers_CallLinkSomething(void);
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);
void sub_812225C(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 numItems); void SetCursorWithinListBounds(u16 *scrollOffset, u16 *cursorPos, u8 maxShownItems, u8 totalItems);
void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4); void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4);
void LoadListMenuSwapLineGfx(void); void LoadListMenuSwapLineGfx(void);
void CreateSwapLineSprites(u8 *spriteIds, u8 count); void CreateSwapLineSprites(u8 *spriteIds, u8 count);

View File

@ -15,6 +15,14 @@
#define MAX_CONDITION_SPARKLES 10 #define MAX_CONDITION_SPARKLES 10
// Window IDs for the Player PC Mailbox
enum {
MAILBOXWIN_TITLE,
MAILBOXWIN_LIST,
MAILBOXWIN_OPTIONS,
MAILBOXWIN_COUNT
};
struct UnknownSubStruct_81D1ED4 struct UnknownSubStruct_81D1ED4
{ {
u16 unk0; u16 unk0;
@ -35,12 +43,12 @@ struct ConditionGraph
/*0x355*/ u8 state; /*0x355*/ u8 state;
}; };
bool8 sub_81D1C44(u8 count); bool8 MailboxMenu_Alloc(u8 count);
u8 sub_81D1C84(u8 a0); u8 MailboxMenu_AddWindow(u8 windowIdx);
u8 sub_81D1DC0(struct PlayerPCItemPageStruct *page); u8 MailboxMenu_CreateList(struct PlayerPCItemPageStruct *page);
void sub_81D1E90(struct PlayerPCItemPageStruct *page); void MailboxMenu_AddScrollArrows(struct PlayerPCItemPageStruct *page);
void sub_81D1EC0(void); void MailboxMenu_Free(void);
void sub_81D1D04(u8 a0); void MailboxMenu_RemoveWindow(u8 windowIdx);
void InitConditionGraphData(struct ConditionGraph *graph); void InitConditionGraphData(struct ConditionGraph *graph);
void sub_81D2108(struct ConditionGraph *graph); void sub_81D2108(struct ConditionGraph *graph);
void SetConditionGraphIOWindows(u8 bg); void SetConditionGraphIOWindows(u8 bg);

View File

@ -3,69 +3,6 @@
#include "menu.h" #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 struct PlayerPCItemPageStruct
{ {
u16 cursorPos; u16 cursorPos;
@ -76,16 +13,12 @@ struct PlayerPCItemPageStruct
u8 scrollIndicatorTaskId; u8 scrollIndicatorTaskId;
}; };
// Exported type declarations extern struct PlayerPCItemPageStruct gPlayerPCItemPageInfo;
// Exported RAM declarations
extern struct PlayerPCItemPageStruct playerPCItemPageInfo;
// Exported ROM declarations
extern const struct MenuAction gMailboxMailOptions[]; extern const struct MenuAction gMailboxMailOptions[];
void ReshowPlayerPC(u8 taskId); void ReshowPlayerPC(u8 taskId);
void sub_816B31C(void); void CB2_PlayerPCExitBagMenu(void);
void Mailbox_ReturnToMailListAfterDeposit(void); void Mailbox_ReturnToMailListAfterDeposit(void);
void NewGameInitPCItems(void); void NewGameInitPCItems(void);

View File

@ -862,7 +862,7 @@ static void InitDecorationItemsMenuLimits(void)
static void InitDecorationItemsMenuScrollAndCursor(void) static void InitDecorationItemsMenuScrollAndCursor(void)
{ {
sub_812225C(&sDecorationsScrollOffset, &sDecorationsCursorPos, sDecorationItemsMenu->maxShownItems, sDecorationItemsMenu->numMenuItems); SetCursorWithinListBounds(&sDecorationsScrollOffset, &sDecorationsCursorPos, sDecorationItemsMenu->maxShownItems, sDecorationItemsMenu->numMenuItems);
} }
static void InitDecorationItemsMenuScrollAndCursor2(void) static void InitDecorationItemsMenuScrollAndCursor2(void)

View File

@ -34,11 +34,11 @@ int GetStringWidthDifference(int fontId, const u8 *str, int totalWidth, int lett
return 0; return 0;
} }
int GetMaxWidthInMenuTable(const struct MenuAction *str, int arg1) int GetMaxWidthInMenuTable(const struct MenuAction *str, int numActions)
{ {
int i, var; 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); int stringWidth = GetStringWidth(1, str[i].text, 0);
if (stringWidth > var) if (stringWidth > var)

View File

@ -552,7 +552,7 @@ void CB2_GoToSellMenu(void)
void CB2_GoToItemDepositMenu(void) void CB2_GoToItemDepositMenu(void)
{ {
GoToBagMenu(ITEMMENULOCATION_ITEMPC, POCKETS_COUNT, sub_816B31C); GoToBagMenu(ITEMMENULOCATION_ITEMPC, POCKETS_COUNT, CB2_PlayerPCExitBagMenu);
} }
void ApprenticeOpenBagMenu(void) void ApprenticeOpenBagMenu(void)
@ -1078,7 +1078,7 @@ void All_CalculateNItemsAndMaxShowed(void)
void SetInitialScrollAndCursorPositions(u8 pocketId) void SetInitialScrollAndCursorPositions(u8 pocketId)
{ {
sub_812225C(&gBagPositionStruct.scrollPosition[pocketId], &gBagPositionStruct.cursorPosition[pocketId], gBagMenu->numShownItems[pocketId], gBagMenu->numItemStacks[pocketId]); SetCursorWithinListBounds(&gBagPositionStruct.scrollPosition[pocketId], &gBagPositionStruct.cursorPosition[pocketId], gBagMenu->numShownItems[pocketId], gBagMenu->numItemStacks[pocketId]);
} }
static void SetPocketListPositions(void) static void SetPocketListPositions(void)

View File

@ -323,36 +323,38 @@ bool8 MenuHelpers_CallLinkSomething(void)
return TRUE; 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; u16 i;
struct ItemSlot *slots_ = slots; struct ItemSlot *slots_ = slots;
(*usedSlotsCount) = 0; // Count the number of non-empty item slots
for (i = 0; i < count; i++) *totalItems = 0;
for (i = 0; i < slotsCount; i++)
{ {
if (slots_[i].itemId != ITEM_NONE) if (slots_[i].itemId != ITEM_NONE)
(*usedSlotsCount)++; (*totalItems)++;
} }
(*totalItems)++; // + 1 for 'Cancel'
(*usedSlotsCount)++; // Set number of items per page
if ((*usedSlotsCount) > maxUsedSlotsCount) if (*totalItems > maxPerPage)
*arg2 = maxUsedSlotsCount; *pageItems = maxPerPage;
else 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) if (*scrollOffset != 0 && *scrollOffset + maxShownItems > totalItems)
*scrollOffset = numItems - maxShownItems; *scrollOffset = totalItems - maxShownItems;
if (*scrollOffset + *cursorPos >= numItems) if (*scrollOffset + *cursorPos >= totalItems)
{ {
if (numItems == 0) if (totalItems == 0)
*cursorPos = 0; *cursorPos = 0;
else else
*cursorPos = numItems - 1; *cursorPos = totalItems - 1;
} }
} }

View File

@ -28,10 +28,10 @@
extern const struct CompressedSpriteSheet gMonFrontPicTable[]; extern const struct CompressedSpriteSheet gMonFrontPicTable[];
EWRAM_DATA static u8 sUnknown_0203CF48[3] = {0}; EWRAM_DATA static u8 sMailboxWindowIds[MAILBOXWIN_COUNT] = {0};
EWRAM_DATA static struct ListMenuItem *sUnknown_0203CF4C = NULL; 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_81D24A4(struct ConditionGraph *a0);
static void sub_81D2634(struct ConditionGraph *a0); static void sub_81D2634(struct ConditionGraph *a0);
static void MoveRelearnerCursorCallback(s32 itemIndex, bool8 onInit, struct ListMenu *list); 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 SpriteCB_ConditionSparkle(struct Sprite *sprite);
static void ShowAllConditionSparkles(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, .bg = 0,
.tilemapLeft = 1, .tilemapLeft = 1,
.tilemapTop = 1, .tilemapTop = 1,
.width = 8, .width = 8,
.height = 2, .height = 2,
.paletteNum = 0xF, .paletteNum = 15,
.baseBlock = 0x8 .baseBlock = 0x8
}, },
{ [MAILBOXWIN_LIST] = {
.bg = 0, .bg = 0,
.tilemapLeft = 21, .tilemapLeft = 21,
.tilemapTop = 1, .tilemapTop = 1,
.width = 8, .width = 8,
.height = 18, .height = 18,
.paletteNum = 0xF, .paletteNum = 15,
.baseBlock = 0x18 .baseBlock = 0x18
}, },
{ [MAILBOXWIN_OPTIONS] = {
.bg = 0, .bg = 0,
.tilemapLeft = 1, .tilemapLeft = 1,
.tilemapTop = 1, .tilemapTop = 1,
.width = 11, .width = 11,
.height = 8, .height = 8,
.paletteNum = 0xF, .paletteNum = 15,
.baseBlock = 0x18 .baseBlock = 0x18
} }
}; };
@ -207,53 +207,55 @@ static const struct ListMenuTemplate sMoveRelearnerMovesListTemplate =
.cursorKind = 0 .cursorKind = 0
}; };
bool8 sub_81D1C44(u8 count) bool8 MailboxMenu_Alloc(u8 count)
{ {
u8 i; u8 i;
sUnknown_0203CF4C = Alloc(count * sizeof(*sUnknown_0203CF4C) + sizeof(*sUnknown_0203CF4C)); // + 1 to count for 'Cancel'
if (sUnknown_0203CF4C == NULL) sMailboxList = Alloc((count + 1) * sizeof(*sMailboxList));
if (sMailboxList == NULL)
return FALSE; return FALSE;
for (i = 0; i < ARRAY_COUNT(sUnknown_0203CF48); i++) for (i = 0; i < ARRAY_COUNT(sMailboxWindowIds); i++)
sUnknown_0203CF48[i] = WINDOW_NONE; sMailboxWindowIds[i] = WINDOW_NONE;
return TRUE; 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); 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); ClearStdWindowAndFrameToTransparent(sMailboxWindowIds[windowIdx], 0);
ClearWindowTilemap(sUnknown_0203CF48[a0]); ClearWindowTilemap(sMailboxWindowIds[windowIdx]);
RemoveWindow(sUnknown_0203CF48[a0]); RemoveWindow(sMailboxWindowIds[windowIdx]);
sUnknown_0203CF48[a0] = WINDOW_NONE; 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, s32 itemId, u8 y) static void MailboxMenu_ItemPrintFunc(u8 windowId, s32 itemId, u8 y)
{ {
u8 buffer[30]; u8 buffer[30];
u16 length; u16 length;
@ -269,21 +271,21 @@ static void sub_81D1D44(u8 windowId, s32 itemId, u8 y)
AddTextPrinterParameterized4(windowId, 1, 8, y, 0, 0, sPlayerNameTextColors, -1, buffer); AddTextPrinterParameterized4(windowId, 1, 8, y, 0, 0, sPlayerNameTextColors, -1, buffer);
} }
u8 sub_81D1DC0(struct PlayerPCItemPageStruct *page) u8 MailboxMenu_CreateList(struct PlayerPCItemPageStruct *page)
{ {
u16 i; u16 i;
for (i = 0; i < page->count; i++) for (i = 0; i < page->count; i++)
{ {
sUnknown_0203CF4C[i].name = sEmptyItemName; sMailboxList[i].name = sEmptyItemName;
sUnknown_0203CF4C[i].id = i; sMailboxList[i].id = i;
} }
sUnknown_0203CF4C[i].name = gText_Cancel2; sMailboxList[i].name = gText_Cancel2;
sUnknown_0203CF4C[i].id = LIST_CANCEL; sMailboxList[i].id = LIST_CANCEL;
gMultiuseListMenuTemplate.items = sUnknown_0203CF4C; gMultiuseListMenuTemplate.items = sMailboxList;
gMultiuseListMenuTemplate.totalItems = page->count + 1; gMultiuseListMenuTemplate.totalItems = page->count + 1;
gMultiuseListMenuTemplate.windowId = sUnknown_0203CF48[1]; gMultiuseListMenuTemplate.windowId = sMailboxWindowIds[MAILBOXWIN_LIST];
gMultiuseListMenuTemplate.header_X = 0; gMultiuseListMenuTemplate.header_X = 0;
gMultiuseListMenuTemplate.item_X = 8; gMultiuseListMenuTemplate.item_X = 8;
gMultiuseListMenuTemplate.cursor_X = 0; gMultiuseListMenuTemplate.cursor_X = 0;
@ -292,8 +294,8 @@ u8 sub_81D1DC0(struct PlayerPCItemPageStruct *page)
gMultiuseListMenuTemplate.cursorPal = 2; gMultiuseListMenuTemplate.cursorPal = 2;
gMultiuseListMenuTemplate.fillValue = 1; gMultiuseListMenuTemplate.fillValue = 1;
gMultiuseListMenuTemplate.cursorShadowPal = 3; gMultiuseListMenuTemplate.cursorShadowPal = 3;
gMultiuseListMenuTemplate.moveCursorFunc = sub_81D1E7C; gMultiuseListMenuTemplate.moveCursorFunc = MailboxMenu_MoveCursorFunc;
gMultiuseListMenuTemplate.itemPrintFunc = sub_81D1D44; gMultiuseListMenuTemplate.itemPrintFunc = MailboxMenu_ItemPrintFunc;
gMultiuseListMenuTemplate.fontId = 1; gMultiuseListMenuTemplate.fontId = 1;
gMultiuseListMenuTemplate.cursorKind = 0; gMultiuseListMenuTemplate.cursorKind = 0;
gMultiuseListMenuTemplate.lettersSpacing = 0; gMultiuseListMenuTemplate.lettersSpacing = 0;
@ -302,20 +304,20 @@ u8 sub_81D1DC0(struct PlayerPCItemPageStruct *page)
return ListMenuInit(&gMultiuseListMenuTemplate, page->itemsAbove, page->cursorPos); 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) if (onInit != TRUE)
PlaySE(SE_SELECT); 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); 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) void InitConditionGraphData(struct ConditionGraph *graph)

View File

@ -5471,7 +5471,7 @@ static void TryGiveMailToSelectedMon(u8 taskId)
struct MailStruct *mail; struct MailStruct *mail;
gPartyMenuUseExitCallback = FALSE; 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) if (GetMonData(mon, MON_DATA_HELD_ITEM) != ITEM_NONE)
{ {
DisplayPartyMenuMessage(gText_PkmnHoldingItemCantHoldMail, TRUE); DisplayPartyMenuMessage(gText_PkmnHoldingItemCantHoldMail, TRUE);

File diff suppressed because it is too large Load Diff

View File

@ -1075,7 +1075,7 @@ void DeleteRegistry_Yes_Callback(u8 taskId)
DestroyListMenuTask(tListTaskId, &tScrollOffset, &tSelectedRow); DestroyListMenuTask(tListTaskId, &tScrollOffset, &tSelectedRow);
gSaveBlock1Ptr->secretBases[tSelectedBaseId].registryStatus = UNREGISTERED; gSaveBlock1Ptr->secretBases[tSelectedBaseId].registryStatus = UNREGISTERED;
BuildRegistryMenuItems(taskId); BuildRegistryMenuItems(taskId);
sub_812225C(&tScrollOffset, &tSelectedRow, tMaxShownItems, tNumBases); SetCursorWithinListBounds(&tScrollOffset, &tSelectedRow, tMaxShownItems, tNumBases);
FinalizeRegistryMenu(taskId); FinalizeRegistryMenu(taskId);
gTasks[taskId].func = HandleRegistryMenuInput; gTasks[taskId].func = HandleRegistryMenuInput;
} }