icon_menu.c
The command icon menus of the field, title and transfer screens.
games/tbs/src/window/battle_command/icon_menu.c on GitHub
The command icon menus of the field, title and transfer screens. Part of battle_command.c, the menu object, compiled only through it.
Functions
AffineEffect_UpdateFrame
void AffineEffect_UpdateFrame(void)
Draws the resource-menu icons, pulsing the selected icon with one affine matrix, and updates the horizontal window spans to reveal the active icon row. A scheduler callback of the command icon menus (AffineEffect_InitializeWork). Each icon is a 32x32, 256-colour sprite; the selected one is double-size affine, pulsing between 1.19 and 1.31 times, on layer 246, the others on 245, and one at x 0 is not drawn. While a window transition runs (gDisplayTransition), it widens window 1 over the icon row so the icons show through: from the first icon on the row's 24 lines, keeping each line's right edge, and around the selected icon on the lines it overhangs (below a row at the top, above one at the bottom, whose lines are 136 to 159).
Used by AffineEffect_InitializeWork, Menu_EndResourceSelection.
AffineEffect_InitializeWork
void *AffineEffect_InitializeWork(void)
Allocates and clears the resource-menu state, then schedules its icon pulse. The work (struct ResourceMenuWork, 152 bytes) lives in heap slot 58 until Menu_EndResourceSelection frees it; it is returned, and also reached as gMenuSelectWork. Every command icon menu starts here.
Used by Menu_AnimateSelectionToEntry, Menu_RunConfirmSelection, Menu_RunConfirmSelectionAt, Menu_SelectCoinsOrMedals, Menu_SelectResourceLayout, Menu_SelectSanctumService, Menu_SelectSaveSlotAction, Menu_SelectShopCommand, Menu_SelectTopEntry.
Menu_EndResourceSelection
void Menu_EndResourceSelection(void)
Stops the icon pulse, closes the label window and releases each loaded icon before freeing the resource-menu state (heap slot 58, 0x3a), then waits a frame.
Used by Menu_AnimateSelectionToEntry, Menu_RunConfirmSelection, Menu_RunConfirmSelectionAt, Menu_SelectCoinsOrMedals, Menu_SelectResourceLayout, Menu_SelectSanctumService, Menu_SelectSaveSlotAction, Menu_SelectShopCommand, Menu_SelectTopEntry.
Menu_RunResourceSelectionLoop
s32 Menu_RunResourceSelectionLoop(s32 initial)
Selects an icon position with wrapped directional input. A returns the position; B or Start returns -1. Redraws the label only after a move. The label is message resourceBase + position when the layout set a resourceBase, else the icon's command name (MsgCommandName + its icon).
Used by Menu_RunConfirmSelection, Menu_RunConfirmSelectionAt, Menu_SelectCoinsOrMedals, Menu_SelectResourceLayout, Menu_SelectSanctumService, Menu_SelectSaveSlotAction, Menu_SelectShopCommand, Menu_SelectTopEntry.
AbsoluteDifference
static inline s32 AbsoluteDifference(s32 diff, s32 lhs, s32 rhs)
Returns the distance between lhs and rhs, reusing their supplied difference.
Used by Menu_SelectResource.
Menu_SelectResource
s32 Menu_SelectResource(s32 start, s32 goal)
Animates a cursor from start to goal with table-driven delays. Draws each intervening label, pauses at the destination, and returns its position. It moves one icon at a time with the cursor sound, waiting gMenu_SelectionStepDelays[icons still to go] frames at each (12 more at the first), then 48 frames on the goal before the confirm sound: a menu choice made for the player to watch (Menu_AnimateSelectionToEntry).
Used by Menu_AnimateSelectionToEntry.
Menu_LoadResourceSlot
void Menu_LoadResourceSlot(s32 slot, s32 index)
Decodes one command-icon table entry into the requested VRAM cache slot, through a 1 KB block it allocates and frees.
Used by Menu_AppendResourceEntry.
Menu_AppendResourceEntry
void Menu_AppendResourceEntry(s32 icon)
Appends a command icon if fewer than six are present. Its initial position is on the bottom icon row; a layout routine places the final row. The icon's number (ResourceId_CommandIcons) is also its command name's (MsgCommandName + icon). Its VRAM slot is taken unchecked.
Used by Menu_AnimateSelectionToEntry, Menu_RunConfirmSelection, Menu_RunConfirmSelectionAt, Menu_SelectCoinsOrMedals, Menu_SelectResourceLayout, Menu_SelectSanctumService, Menu_SelectSaveSlotAction, Menu_SelectShopCommand, Menu_SelectTopEntry.
Menu_CenterResourceEntries
void Menu_CenterResourceEntries(s32 row, s32 width, s32 resourceBase)
Centers the icons and their label window together on the given tile row.
A nonzero resourceBase supplies labels; otherwise command-name IDs do.
The icons stand three tiles apart and the label window, width + 2 tiles
wide and 3 tall, follows them; the centring counts two thirds of the
window's width.
Used by Menu_AnimateSelectionToEntry, Menu_RunConfirmSelection, Menu_SelectCoinsOrMedals, Menu_SelectResourceLayout, Menu_SelectSanctumService, Menu_SelectSaveSlotAction, Menu_SelectShopCommand, Menu_SelectTopEntry.
Menu_LayoutResourceEntries
void Menu_LayoutResourceEntries(s32 x, s32 y, s32 width, s32 resourceBase)
Places icons at three-tile intervals from (x, y), then creates their label window immediately to the right. Coordinates and label width are in tiles.
Used by Menu_RunConfirmSelectionAt.
ResourceMenu_ReadCommandPosition
static __inline__ s32 ResourceMenu_ReadCommandPosition(s8 *table, s32 index)
Reads the signed command-position mapping used by the top resource menu.
Used by Menu_SelectTopEntry.
Menu_SelectTopEntry
s32 Menu_SelectTopEntry(s32 selection)
Builds the field command menu, omitting Djinn when none are owned.
Translates between command IDs and visible icon positions using the two
lookup rows. The icons are Psynergy, Djinn, Item and Status on row 17;
selection is the command to start on and the result the command
chosen: 1 Psynergy, 2 Djinn, 3 Item, 4 Status, or -1 when cancelled. The
field's menu runs it (window/window/selection.c).
Used by Menu_RunTopSelection.
Menu_AnimateSelectionToEntry
s32 Menu_AnimateSelectionToEntry(s32 start, s32 command)
Opens the field command menu and animates from start to the command's icon.
Returns the final icon position after closing the menu. The Djinn icon is
always shown, so command (1 to 4, as Menu_SelectTopEntry gives it) is
position command - 1. The world map's scenes show it picking Djinn
(scene/world_map.c).
Used by Event_MeetFlint, WorldMap_ShowDjinnTutorial.
Menu_SelectSaveSlotAction
s32 Menu_SelectSaveSlotAction(void)
Builds the title menu from the save summaries and optional send flags. Translates the chosen visible position back to its save-action code: 0 New Game, 1 Continue, 2 Copy, 3 Erase, 4 Battle, 5 Send, or -1 when cancelled or the backup memory cannot be read. With no files it returns 0 at once. The icons, by SaveState_ScanRecordFlags' count: New Game, Continue, Copy and Erase for one or two files (starting on Continue); no New Game or Copy with three; with every file cleared no Continue, and only Erase with three such files. Battle and Send follow when enabled. XXX: with Send shown but not Battle, Send's place maps to 4 (Battle), because gMenu_SaveSlotActionByPosition lists Battle before Send in every row; whether a file can ever be cleared without any of flags 48-127 set is not established. The file menu runs it (menu/clear.c).
Used by SaveMenu_Run.
Menu_DrawModeLabel
void Menu_DrawModeLabel(void)
Redraws the password-level explanation when the selected level changes. A scheduler callback of the password level menu: what each level's password carries, from MsgPasswordLevel on: Gold (0) "Level", "Djinn", "Character stats", "Items" and "Coins", Silver (1) the first three, Bronze (2) the first two.
Used by Menu_SelectResourceLayout.
Menu_DrawModeIndicator
void Menu_DrawModeIndicator(void)
Redraws password/cable transfer help when the chosen method changes. The French layout keeps its distinct line splitting and redraw path. A scheduler callback of the transfer method menu: Password (0) or Cable.
Used by Menu_SelectResourceLayout.
Menu_DrawModeIndicator
void Menu_DrawModeIndicator(void)
Redraws password/cable transfer help when the chosen method changes. A scheduler callback of the transfer method menu: Password (0) or Cable.
Used by Menu_SelectResourceLayout.
Menu_SelectResourceLayout
s32 Menu_SelectResourceLayout(s32 mode)
Selects either the transfer method (mode 0) or password level. Schedules the appropriate help redraw while the icon menu is active, then closes both help windows and the icon menu. Mode 0 offers Password and Cable (icons 44 and 45), mode 1 Gold, Silver and Bronze (46 to 48). Returns the place chosen, or -1 when cancelled. The Send screens run it (menu/clear.c).
Used by SaveMenu_Run.
Menu_SelectShopCommand
s32 Menu_SelectShopCommand(s32 selection)
Selects a shop command, icons 0x11-0x14 (Buy, Sell, Artifacts, Repair),
centered on row 17, starting on position selection. Returns the
position chosen, or -1 when cancelled.
Menu_SelectSanctumService
s32 Menu_SelectSanctumService(s32 selection)
Selects a Sanctum service, icons 0x19-0x1c (Revive, Cure Poison, Repel
Evil, Remove Curse), centered on row 17, starting on position
selection. Returns the position chosen, or -1 when cancelled.
Menu_RunConfirmSelection
s32 Menu_RunConfirmSelection(s32 bottom, s32 message, s32 labelWidth, s32 selection)
Selects Yes/No (icons 5/6), returning 0 for Yes and 1 for No; cancelling
returns 1 (No). The menu sits on row 17 when bottom is nonzero, else on
row 0. message is the first of the two names to show, or 0 for the
command names; labelWidth is the name window's width inside its frame,
or 0 for 3. The cursor starts on position selection.
Used by SaveMenu_Run, SaveState_ConfirmAndProcessSelectedSlot, SaveState_DeleteSelectedSlot, Save_WriteSelectedSlot.
Menu_RunConfirmSelectionAt
s32 Menu_RunConfirmSelectionAt(s32 x, s32 y, s32 selection)
Selects Yes/No with the icons from tile (x, y) and the name window after them, returning 0 for Yes and 1 for No; cancelling returns 1 (No).
Menu_SelectCoinsOrMedals
s32 Menu_SelectCoinsOrMedals(s32 selection)
Selects icons 0x20 and 0x21 (Coins, Lucky Medals) centered on row 17,
starting on position selection. Returns the position chosen, or -1 when
cancelled. Tolbi's spring asks it (scene/tolbi_spring.c).
Used by TolbiSpring_RunSpringGame.
Structures
WindowLine
struct WindowLine
One line's horizontal window edges: window 0's and window 1's, each (left << 8 | right).
| Field | Declared as | |
|---|---|---|
left | u16 left | window 0's edges, for WIN0H |
span | u16 span | window 1's edges, for WIN1H |
WindowBuffer
struct WindowBuffer
A page of the display transition's window edges: WININ and WINOUT, then each of the 160 lines' edges.
| Field | Declared as | |
|---|---|---|
unk000 | u8 unk000[4] | WININ and WINOUT, not touched here |
lines | struct WindowLine lines[160] |
Used by AffineEffect_UpdateFrame.
Macros, without a comment: TRANSFER_MODE_DRAW_HELP, TRANSFER_PASSWORD_HELP_X, TRANSFER_PASSWORD_HELP_FIRST_Y, TRANSFER_PASSWORD_HELP_LAST_Y, TRANSFER_CABLE_HELP_FIRST_Y, TRANSFER_CABLE_HELP_LAST_Y, TRANSFER_MODE_DRAW_HELP, TRANSFER_PASSWORD_HELP_X, TRANSFER_PASSWORD_HELP_FIRST_Y, TRANSFER_PASSWORD_HELP_LAST_Y, TRANSFER_CABLE_HELP_FIRST_Y, TRANSFER_CABLE_HELP_LAST_Y, ANIMATE_ENTRIES_ROW, ANIMATE_ENTRIES_ROW, MODE_LABEL_X, MODE_LABEL_RIGHT, MODE_LABEL_X, MODE_LABEL_RIGHT, PASSWORD_HELP_X, PASSWORD_HELP_X, PAIR_WIDTH, PAIR_WIDTH, PAIR_WIDTH.