Skip to content

Commit

Permalink
Add scroll indicators to list menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseurae committed Oct 5, 2024
1 parent 3008001 commit 79dd97f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
22 changes: 21 additions & 1 deletion include/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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);
5 changes: 5 additions & 0 deletions linker/text.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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;
22 changes: 22 additions & 0 deletions src/script_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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);
}

0 comments on commit 79dd97f

Please sign in to comment.