From 79dd97fb92f27422ab086eb599dc353ebc6fb8eb Mon Sep 17 00:00:00 2001 From: Pseurae Date: Sat, 5 Oct 2024 10:49:45 +0000 Subject: [PATCH] Add scroll indicators to list menu --- include/menu.h | 22 +++++++++++++++++++++- linker/text.ld | 5 +++++ src/script_menu.c | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/include/menu.h b/include/menu.h index 10fdad1..f857b4a 100644 --- a/include/menu.h +++ b/include/menu.h @@ -22,4 +22,24 @@ u8 LONG_CALL PrintStringWithNewlines( void LONG_CALL Menu_PrintItems(u8, u8, u8, const void *); void LONG_CALL Menu_DestroyCursor(void); u8 LONG_CALL InitMenu(u8, u8, u8, u8, u8, u8); -u8 LONG_CALL Menu_MoveCursor(s8); \ No newline at end of file +u8 LONG_CALL Menu_MoveCursor(s8); + +enum +{ + TOP_ARROW, + BOTTOM_ARROW, + LEFT_ARROW, // Bag arrows + RIGHT_ARROW +}; + +enum +{ + VISIBLE, + INVISIBLE +}; + +void LONG_CALL CreateVerticalScrollIndicators(u8, u16, u16); +void LONG_CALL SetVerticalScrollIndicators(u8, bool8); +void LONG_CALL DestroyVerticalScrollIndicator(u8); +void LONG_CALL LoadScrollIndicatorPalette(void); +void LONG_CALL ClearVerticalScrollIndicatorPalettes(void); \ No newline at end of file diff --git a/linker/text.ld b/linker/text.ld index f508279..a14d636 100644 --- a/linker/text.ld +++ b/linker/text.ld @@ -231,3 +231,8 @@ CalculateBoxMonChecksum = 0x803b124 | 1; EncryptBoxMon = 0x803c5f0 | 1; DecryptBoxMon = 0x803c614 | 1; CalculateMonStats = 0x803b1b8 | 1; +CreateVerticalScrollIndicators = 0x80f953c | 1; +SetVerticalScrollIndicators = 0x80f979c | 1; +DestroyVerticalScrollIndicator = 0x80f97e0 | 1; +LoadScrollIndicatorPalette = 0x80f9818 | 1; +ClearVerticalScrollIndicatorPalettes = 0x80f944c | 1; \ No newline at end of file diff --git a/src/script_menu.c b/src/script_menu.c index 45ae462..06889f0 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -220,6 +220,14 @@ static void StartListMenuTask(const struct MenuAction *list, u8 left, u8 top, u8 gTasks[taskId].tDoWrap = TRUE; else gTasks[taskId].tDoWrap = FALSE; + + if (totalCount > displayCount) + { + ClearVerticalScrollIndicatorPalettes(); + CreateVerticalScrollIndicators(TOP_ARROW, (left + right + 1) << 2, top << 3); + CreateVerticalScrollIndicators(BOTTOM_ARROW, (left + right + 1) << 2, bottom << 3); + SetVerticalScrollIndicators(TOP_ARROW, INVISIBLE); + } } static void Task_HandleListMenuInput(u8 taskId) @@ -234,6 +242,8 @@ static void Task_HandleListMenuInput(u8 taskId) Menu_EraseWindowRect(gTasks[taskId].tLeft, gTasks[taskId].tTop, gTasks[taskId].tRight, gTasks[taskId].tBottom); DestroyTask(taskId); EnableBothScriptContexts(); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); } else if (gMain.newKeys & B_BUTTON) { if (tIgnoreBPress) return; @@ -242,6 +252,8 @@ static void Task_HandleListMenuInput(u8 taskId) Menu_EraseWindowRect(gTasks[taskId].tLeft, gTasks[taskId].tTop, gTasks[taskId].tRight, gTasks[taskId].tBottom); DestroyTask(taskId); EnableBothScriptContexts(); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); } else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { if (tCursor == tDisplayCount - 1) { if (tCursor + tScrollOffset == tTotalCount - 1) return; @@ -265,4 +277,14 @@ static void Task_HandleListMenuInput(u8 taskId) tCursor = Menu_MoveCursor(-1); } } + + if (tScrollOffset == 0) + SetVerticalScrollIndicators(TOP_ARROW, INVISIBLE); + else + SetVerticalScrollIndicators(TOP_ARROW, VISIBLE); + + if (tScrollOffset + tDisplayCount == tTotalCount) + SetVerticalScrollIndicators(BOTTOM_ARROW, INVISIBLE); + else + SetVerticalScrollIndicators(BOTTOM_ARROW, VISIBLE); } \ No newline at end of file