options.c
Window colours, the option screen and the system menu.
games/tbs/src/window/window/options.c on GitHub
Window colours, the option screen and the system menu. Part of window.c, the window object, compiled only through it.
Functions
GraphicsPalette_ReservedNoOpC9BC
UNUSED void GraphicsPalette_ReservedNoOpC9BC(void)
Nothing calls them.
OptionMenu_ResetEntries
UNUSED void OptionMenu_ResetEntries(struct WorkspaceWork *work)
Clears the option screen's seven entry states, its row, its tint and its cursor animation. Nothing calls it.
WindowColor_ComputeTint
UNUSED void WindowColor_ComputeTint(struct WorkspaceWork *work)
Works out the window tint (red, green and blue, 0 to 31) from the window colour settings: the hue picks a point on the colour wheel and the brightness shifts all three channels. The three wave samples are one third of the 96-step colour cycle apart. The arithmetic is PaletteGlow_Update's. Nothing calls it.
WindowColor_WritePalette
UNUSED void WindowColor_WritePalette(struct WorkspaceWork *work)
Writes window colours 4 to 10 of BG palette 15, each a fixed scale of the window tint. Nothing calls it.
WindowColor_ScaleTint
u16 WindowColor_ScaleTint(struct WorkspaceWork *work, s32 redScale, s32 greenScale, s32 blueScale)
Returns the window tint with each channel scaled (16.16 fixed point) and clamped to 0 to 31, as a BGR555 colour.
Used by WindowColor_WritePalette.
Color_ScaleComponents
u16 Color_ScaleComponents(s16 *rgb, s32 redScale, s32 greenScale, s32 blueScale)
Returns rgb with each channel scaled (16.16 fixed point) and clamped to 0 to 31, as a BGR555 colour. rgb holds three components, not an already packed palette word.
Used by PaletteGlow_Update.
PaletteGlow_Update
void PaletteGlow_Update(s32 phase, s32 brightness)
Sets the window colours (BG palette 15, colours 4 to 10) for a window hue (0 to 23) and brightness (0 to 14, 7 neutral). The live palette path leaves the saved colour settings untouched. The option screen calls it as the player changes the settings, and with the saved ones when the screen is cancelled. The save file menu (SaveMenu_SelectSlot) shows the colours of the file under the cursor, and the saved ones for an empty file and on leaving. The file select (menu/clear.c), the main loop's start (Game_ResetForNewGame), the end of the Mind Read wave (Ui_SetBank15PaletteAndClearRenderMode) and the Vale and world map scenes call it with the saved settings.
Used by Menu_RunWorkspaceOptions, SaveMenu_Run, SaveMenu_SelectSlot, WorldMap_ShowEndingScene.
OptionMenu_PreviousRow
UNUSED void OptionMenu_PreviousRow(struct WorkspaceWork *work)
Moves the three-row settings cursor up, wrapping to the bottom. The three rows are those of OptionMenu_LowerSetting. XXX: likely left from an earlier option screen, because the five-row one Menu_RunWorkspaceOptions runs uses none of these four functions. Nothing calls it.
OptionMenu_NextRow
UNUSED void OptionMenu_NextRow(struct WorkspaceWork *work)
Moves the three-row settings cursor down, wrapping to the top. Nothing calls it.
OptionMenu_LowerSetting
UNUSED void OptionMenu_LowerSetting(struct WorkspaceWork *work)
Lowers the setting on the three-row cursor's row: message speed, window hue or window brightness. Nothing calls it.
OptionMenu_RaiseSetting
UNUSED void OptionMenu_RaiseSetting(struct WorkspaceWork *work)
Raises the setting on the three-row cursor's row: message speed, window hue or window brightness. Nothing calls it.
GraphicsPalette_SelectionNoOp
void GraphicsPalette_SelectionNoOp(void)
An empty function, reached only through a bare entry of the window far-call table.
OptionMenu_AnimateCursors
void OptionMenu_AnimateCursors(void)
The option screen's per-frame callback: moves the cursor and the two slider markers, animates the marker of the slider in use, and pulses the chosen setting's icon. The markers' pictures, 256 bytes each, are loaded every frame: the marker of the row in use steps through 8 frames of ResourceId_ShopCursorFrames, the other shows the first. Rows 2 to 4 (speed, speech, sleep) pulse their chosen icon.
Used by OptionMenu_InitializeWork, OptionMenu_Release.
OptionMenu_InitializeWork
void OptionMenu_InitializeWork(void)
Allocates the option screen's work block, copies the settings into it with how many values each takes, and starts its per-frame callback. The copy lets cancelling discard the edits. The block is heap slot 20 (gSelectionWork), which OptionMenu_Release frees. The rows: 0 the window hue (24 values), 1 its brightness (15), 2 the message speed (3), 3 speech (2) and 4 auto-sleep (2).
Used by Menu_RunWorkspaceOptions.
OptionMenu_Release
void OptionMenu_Release(void)
Stops the option screen's per-frame callback and frees its work block. The callback goes first, since it reads the work block.
Used by Menu_RunWorkspaceOptions.
OptionMenu_Open
struct UiWindow *OptionMenu_Open(void)
Opens the option screen's window: the labels, the hue and brightness sliders with their markers, the cursor and the setting icons. Returns the window. Its sprites belong to the window and go when it closes. A slider's marker stands option * 60 / count pixels right of OPTION_SLIDER_X.
Used by Menu_RunWorkspaceOptions.
Menu_RunWorkspaceOptions
s32 Menu_RunWorkspaceOptions(void)
Runs the option screen (window colour and brightness, message speed, speech, auto-sleep) until A or START keeps the settings (returns 0) or B drops them (returns -1). SELECT cycles through the colour presets. Preview edits affect the live palette; only confirmation saves the settings. Every setting wraps at its ends. While sleep is held off (gSleepDisabled, as in the link lobby) auto-sleep shows as off and is saved so. The system menu's Change settings runs it (Menu_RunWorkspaceResultLoop, battle_command/debug.c), and reopens the menu when it is cancelled.
SystemMenu_AnimateCursor
void SystemMenu_AnimateCursor(void)
The system menu's per-frame callback: moves the cursor and pulses the chosen entry's icon.
Used by SystemMenu_Initialize, SystemMenu_Release.
SystemMenu_Initialize
void SystemMenu_Initialize(void)
Allocates the system menu's work block and starts its per-frame callback. The system menu shares the option workspace slot and cannot run concurrently: Menu_RunWorkspaceSelectionLoop frees it before Menu_RunWorkspaceResultLoop opens the option screen. 3200 is 0xc80, the main loop's pass.
Used by Menu_RunWorkspaceSelectionLoop.
SystemMenu_Release
void SystemMenu_Release(void)
Stops the system menu's per-frame callback and frees its work block. The callback goes first, since it reads the work block.
Used by Menu_RunWorkspaceSelectionLoop.
SystemMenu_Open
struct UiWindow *SystemMenu_Open(void)
Opens the system menu's window with its entries (Save your quest, Sleep, Change settings, and the debug entries in debug mode; only Change settings while FLAG_IN_LINK_LOBBY is set), their icons and the cursor. Returns the window.
Used by Menu_RunWorkspaceSelectionLoop.
Menu_RunWorkspaceSelectionLoop
s32 Menu_RunWorkspaceSelectionLoop(void)
Runs the system menu until the player picks an entry (its number, counting Save your quest as 0) or cancels with B or START (-1). The result counts in the full entry table even when only Change settings is shown. The menu's window and work block are freed before it returns; Menu_RunWorkspaceResultLoop (battle_command/debug.c) acts on the result.
Also, functions without a comment: GraphicsPalette_ReservedNoOpC9C0, GraphicsPalette_ReservedNoOpC9C4.
Structures
MenuWorkspaceEntry
struct MenuWorkspaceEntry
One of the seven entries of the option screen's work from offset 0x400; only its state is known, and only the unused OptionMenu_ResetEntries writes it.
| Field | Declared as | |
|---|---|---|
unk00 | u8 unk00[10] | |
state | u16 state | cleared to 0 by OptionMenu_ResetEntries; nothing reads it |
unk0c | u8 unk0c[40] |
Used by OptionMenu_ResetEntries.
Macros
RESOURCE_SLOTS
#define RESOURCE_SLOTS 96
VRAM_CACHE_ENTRY_COUNT, which Resource_FindFreeEntry returns when no entry is free.
Used by OptionMenu_Open, SystemMenu_Open.
Also, macros without a comment: SLIDER_PALETTE, WORKSPACE_ROWS, WORKSPACE_DEBUG_ROWS, WORKSPACE_ROW_HEIGHT, WORKSPACE_TEXT_X.