diff options
author | froggestspirit <froggestspirit@gmail.com> | 2021-09-06 10:32:14 -0400 |
---|---|---|
committer | froggestspirit <froggestspirit@gmail.com> | 2021-09-06 10:32:14 -0400 |
commit | 73554ec88d4f269b6146f6d1ab5d2742cb0a6f89 (patch) | |
tree | fac5bee8a4ce4757816dbbe42265523478b78781 /src/menu_helpers.c | |
parent | ec6b1ea3735ff98a9714b219e4a999894ecc6010 (diff) | |
parent | 63e6b914e4d9b9bdb0a8d621b2ed233990f2ef66 (diff) |
Merge remote-tracking branch 'pret/master'
Diffstat (limited to 'src/menu_helpers.c')
-rw-r--r-- | src/menu_helpers.c | 168 |
1 files changed, 88 insertions, 80 deletions
diff --git a/src/menu_helpers.c b/src/menu_helpers.c index e7385a5ed..95b67f78c 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -18,19 +18,17 @@ #include "constants/items.h" #include "constants/maps.h" -// this file's functions +#define TAG_SWAP_LINE 109 + static void Task_ContinueTaskAfterMessagePrints(u8 taskId); static void Task_CallYesOrNoCallback(u8 taskId); -// EWRAM vars -EWRAM_DATA static struct YesNoFuncTable gUnknown_0203A138 = {0}; -EWRAM_DATA static u8 gUnknown_0203A140 = 0; +EWRAM_DATA static struct YesNoFuncTable sYesNo = {0}; +EWRAM_DATA static u8 sMessageWindowId = 0; -// IWRAM bss vars -static TaskFunc gUnknown_0300117C; +static TaskFunc sMessageNextTask; -// const rom data -static const struct OamData sOamData_859F4E8 = +static const struct OamData sOamData_SwapLine = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -47,47 +45,47 @@ static const struct OamData sOamData_859F4E8 = .affineParam = 0 }; -static const union AnimCmd sSpriteAnim_859F4F0[] = +static const union AnimCmd sAnim_SwapLine_RightArrow[] = { ANIMCMD_FRAME(0, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_859F4F8[] = +static const union AnimCmd sAnim_SwapLine_Line[] = { ANIMCMD_FRAME(4, 0), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_859F500[] = +static const union AnimCmd sAnim_SwapLine_LeftArrow[] = { - ANIMCMD_FRAME(0, 0, 1, 0), + ANIMCMD_FRAME(0, 0, .hFlip = TRUE), ANIMCMD_END }; -static const union AnimCmd *const sSpriteAnimTable_859F508[] = +static const union AnimCmd *const sAnims_SwapLine[] = { - sSpriteAnim_859F4F0, - sSpriteAnim_859F4F8, - sSpriteAnim_859F500 + sAnim_SwapLine_RightArrow, + sAnim_SwapLine_Line, + sAnim_SwapLine_LeftArrow }; -static const struct CompressedSpriteSheet gUnknown_0859F514 = +static const struct CompressedSpriteSheet sSpriteSheet_SwapLine = { - gBagSwapLineGfx, 0x100, 109 + gBagSwapLineGfx, 0x100, TAG_SWAP_LINE }; -static const struct CompressedSpritePalette gUnknown_0859F51C = +static const struct CompressedSpritePalette sSpritePalette_SwapLine = { - gBagSwapLinePal, 109 + gBagSwapLinePal, TAG_SWAP_LINE }; -static const struct SpriteTemplate gUnknown_0859F524 = +static const struct SpriteTemplate sSpriteTemplate_SwapLine = { - .tileTag = 109, - .paletteTag = 109, - .oam = &sOamData_859F4E8, - .anims = sSpriteAnimTable_859F508, + .tileTag = TAG_SWAP_LINE, + .paletteTag = TAG_SWAP_LINE, + .oam = &sOamData_SwapLine, + .anims = sAnims_SwapLine, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy, @@ -124,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; } @@ -146,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; } @@ -169,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; } } @@ -277,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; @@ -289,7 +289,7 @@ bool8 sub_8122148(u16 itemId) return FALSE; } -bool8 itemid_80BF6D8_mail_related(u16 itemId) +bool8 IsWritingMailAllowed(u16 itemId) { if (IsUpdateLinkStateCBActive() != TRUE && InUnionRoom() != TRUE) return TRUE; @@ -325,84 +325,90 @@ 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)++; } } } } -void LoadListMenuArrowsGfx(void) +void LoadListMenuSwapLineGfx(void) { - LoadCompressedSpriteSheet(&gUnknown_0859F514); - LoadCompressedSpritePalette(&gUnknown_0859F51C); + LoadCompressedSpriteSheet(&sSpriteSheet_SwapLine); + LoadCompressedSpritePalette(&sSpritePalette_SwapLine); } -void sub_8122344(u8 *spriteIds, u8 count) +void CreateSwapLineSprites(u8 *spriteIds, u8 count) { u8 i; for (i = 0; i < count; i++) { - spriteIds[i] = CreateSprite(&gUnknown_0859F524, i * 16, 0, 0); + spriteIds[i] = CreateSprite(&sSpriteTemplate_SwapLine, i * 16, 0, 0); if (i != 0) StartSpriteAnim(&gSprites[spriteIds[i]], 1); @@ -410,7 +416,7 @@ void sub_8122344(u8 *spriteIds, u8 count) } } -void sub_81223B0(u8 *spriteIds, u8 count) +void DestroySwapLineSprites(u8 *spriteIds, u8 count) { u8 i; @@ -423,29 +429,31 @@ void sub_81223B0(u8 *spriteIds, u8 count) } } -void sub_81223FC(u8 *spriteIds, u8 count, bool8 invisible) +void SetSwapLineSpritesInvisibility(u8 *spriteIds, u8 count, bool8 invisible) { u8 i; for (i = 0; i < count; i++) - { gSprites[spriteIds[i]].invisible = invisible; - } } -void sub_8122448(u8 *spriteIds, u8 count, s16 x, u16 y) +void UpdateSwapLineSpritesPos(u8 *spriteIds, u8 count, s16 x, u16 y) { u8 i; - bool8 unknownBit = count & 0x80; - count &= ~(0x80); + bool8 hasMargin = count & SWAP_LINE_HAS_MARGIN; + count &= ~SWAP_LINE_HAS_MARGIN; for (i = 0; i < count; i++) { - if (i == count - 1 && unknownBit) - gSprites[spriteIds[i]].pos2.x = x - 8; + // If the list menu has a right margin, the swap line + // shouldn't extend all the way to the edge of the screen. + // If this is the last sprite in the line, move it a bit + // to the left to keep it out of the margin. + if (i == count - 1 && hasMargin) + gSprites[spriteIds[i]].x2 = x - 8; else - gSprites[spriteIds[i]].pos2.x = x; + gSprites[spriteIds[i]].x2 = x; - gSprites[spriteIds[i]].pos1.y = 1 + y; + gSprites[spriteIds[i]].y = 1 + y; } } |