Alchemy
Loading...
Searching...
No Matches

menu_list.h

Go to the documentation of this file.
1#ifndef ALCHEMY_MENU_LIST_H
2#define ALCHEMY_MENU_LIST_H
3
4/// @file
5/// Menu lists: sprites, cursors, the party status window and paged selections.
6
9#include "types.h"
10#include "resource.h"
11#include "callback_scheduler.h"
12#include "tbs_edition.h"
13#include "text_render_runtime.h"
14#include "window.h"
15#include "static_assert.h"
16#include "keystate.h"
17#include "farcall.h"
18#include "frame.h"
19
20enum { BATTLE_LIST_ROWS = 5 };
21
22/// A menu sprite: a list link and its OAM attributes, as two words or as
23/// fields.
24struct MenuSprite {
26 union {
27 struct {
28 unsigned long attr01;
29 unsigned long attr23;
30 } word;
31 struct {
32 u16 y : 8;
33 u16 affine : 2;
34 u16 mode : 2;
35 u16 mosaic : 1;
36 u16 colors : 1;
37 u16 shape : 2;
38 u16 x : 9;
39 u16 affineIndex : 5;
40 u16 size : 2;
41 u16 tile : 10;
42 u16 priority : 2;
43 u16 palette : 4;
44 u16 unused;
45 } f;
46 } oam;
47};
48
49/// A cursor or prompt sprite: a list link and its OAM attributes as fields.
52 u16 y : 8;
54 u16 mode : 2;
58 u16 x : 9;
60 u16 size : 2;
61 u16 tile : 10;
65};
66
67#define MENU_SPRITE_SIZE_16 0x40000000
68
69/// Sets sprite shape (attr0/attr1) and clears the remaining fields.
70/* FAKEMATCH: the one-pass block keeps both attribute words ahead of the stores
71 * that follow (the x/y fields in the list setup loops of ItemList_SelectEntry,
72 * BattleMenu_RunActionSelection and SummonMenu_SelectSummon; the tile in
73 * UiText_DrawCharacter). Not source: the same two stores match only as plain
74 * statements in Battle_CollectPartyCommands (resource_menu.c, five times) and
75 * Ui_RunOwnerStatusScreen (preview.c, three times). */
76#define MenuSprite_Init(sprite, shape) \
77 do { \
78 (sprite).oam.word.attr01 = (shape); \
79 (sprite).oam.word.attr23 = 0; \
80 } while (0)
81
82/// The party status window's layout: its window, its place and size, and what
83/// it shows (PARTY_STATUS_ flags).
86 u16 x; ///< tiles
87 u16 y; ///< tiles
88 u16 width; ///< tiles
89 u16 height; ///< tiles
90 u16 flags; ///< PARTY_STATUS_ flags
91};
92
93STATIC_ASSERT(sizeof(struct PartyStatusWindow) == 16);
95
96/// A point on the screen where a menu shows its cursor.
97struct MenuPoint {
98 s32 x; ///< screen pixels
99 s32 y; ///< screen pixels
100};
101
102/// The battle command menus' work, heap slot 57 (0x104 bytes), reached as
103/// gLinkCountdownWork. Battle_CollectPartyCommands allocates it each round; it
104/// holds the icons beside the command window, the camera slide, the cursor
105/// each list remembers, the link battle's timer, the Djinn tutorial's
106/// key presses and what each command has spent.
108 /// The sprites UpdateLinkSessionCountdown draws each frame: the chosen
109 /// command's icon, the chosen ability's icon and the member's portrait.
110 struct MenuSprite icons[3];
111 u8 iconShown[3]; ///< whether each of icons is drawn
113 /// Where the battle scene slides to (Camera_ConfigureScene's vertical
114 /// offset): -2 or 16 by the target menu's mode, 0 otherwise.
116 s32 sceneOffset; ///< where the slide has reached; a third of the way a frame
117 s32 row; ///< the list row chosen last
118 s32 page; ///< the list page chosen last
119 s32 preferredRow; ///< the row to return to
120 /// The command row's choice: [0] for the party's row (fight, flee,
121 /// status), [1] for a member's commands.
123 /// The window that shows the link battle's seconds left, a struct UiWindow
124 /// pointer kept as a word (as a pointer, two of the round's first stores
125 /// swap), or 0.
127 /// Set while the status screen is open, so the timer opens no window.
129 /// Frames left to choose commands in a link battle; -1 outside link battles.
130 /// At 0 a menu ends as if cancelled, or takes the first command.
132 s32 linkTimer; ///< 1 while the link battle's timer runs
133 /// The party's standby Djinn by element before each command: what the
134 /// summons chosen by the earlier commands leave.
136 u8 listSlots[34]; ///< the Psynergy list's action slots, ended by 0
137 u16 listAbilities[33]; ///< the Psynergy list's ability ids, ended by 0
138 /// The Djinn tutorial's step: 0 off, 1 from the start of each round while
139 /// FLAG_DJINN_TUTORIAL is set, then one more for each hint shown. While it
140 /// is not 0 the menus press keys for the player.
142 s32 tutorialDelay; ///< frames until the tutorial's next key press
143 /// The member whose commands are being chosen; -1 between members.
145 /// The Djinni each command has chosen, element << 8 | index, or 0x80000000.
147};
148
149STATIC_ASSERT(sizeof(struct BattleMenuWork) == 0x104);
150STATIC_ASSERT(offsetof(struct BattleMenuWork, targetSceneOffset) == 0x28);
152STATIC_ASSERT(offsetof(struct BattleMenuWork, commandSelection) == 0x3c);
153STATIC_ASSERT(offsetof(struct BattleMenuWork, timerWindow) == 0x44);
154STATIC_ASSERT(offsetof(struct BattleMenuWork, timer) == 0x4c);
155STATIC_ASSERT(offsetof(struct BattleMenuWork, standbyDjinn) == 0x54);
156STATIC_ASSERT(offsetof(struct BattleMenuWork, tutorialStep) == 0xd8);
157STATIC_ASSERT(offsetof(struct BattleMenuWork, commandActor) == 0xe0);
158STATIC_ASSERT(offsetof(struct BattleMenuWork, chosenDjinn) == 0xe4);
159
160/// Restores the previous selection: page, row and return row.
161// A statement macro (S2: a layer, 4 sites): the three cursor reads stay
162// together at every use; as a plain block, tbs-en differs.
163#define BATTLE_MENU_GET_CURSOR(page_, row_, preferred_) \
164 do { \
165 (page_) = ((struct BattleMenuWork *)gWindowWork[42])->page; \
166 (row_) = ((struct BattleMenuWork *)gWindowWork[42])->row; \
167 (preferred_) = ((struct BattleMenuWork *)gWindowWork[42])->preferredRow; \
168 } while (0)
169
170/// Saves the selection: page, row and return row.
171/* FAKEMATCH(one-pass): the do { } while (0) wrapper steers, so this is a device
172 * at each of its 7 sites, not a layer (S2: not every use matches through it).
173 * Battle_SelectAbility writes the same three stores plainly through its already
174 * loaded menu pointer, and through this macro it differs 2 in all six editions.
175 * At the 7 sites the work-cell pointer it loads stays
176 * apart from the reload after it, and the three stores finish before the keys
177 * are read; written as three plain stores, with the dead-store pads gone,
178 * SummonMenu_SelectSummon differs 84 (stores through its nav pointer; through
179 * gLinkCountdownWork, the macro's own stores unwrapped, it differs 4),
180 * ItemList_SelectEntry 46 and BattleMenu_RunActionSelection 42 in tbs-en, and
181 * elsewhere the row store goes first (differ 4) or the base is loaded before
182 * mode = 0 (differ 2 to 4). */
183#define BATTLE_MENU_SET_CURSOR(page_, row_, preferred_) \
184 do { \
185 gLinkCountdownWork->page = (page_); \
186 gLinkCountdownWork->row = (row_); \
187 gLinkCountdownWork->preferredRow = (preferred_); \
188 } while (0)
189
192extern const u8 gMenu_AnimatedCursorTiles[];
193
194#endif
The task scheduler: tasks, their order and the scheduler's state.
Public interfaces to the engine's code banks.
The frame loop's globals: lag counts, the CPU load display and the VBlank flags.
u8 gResource_FixedBlockBTiles[]
The keypad state the VBlank interrupt keeps.
struct BattleMenuWork * gLinkCountdownWork
const u8 gMenu_AnimatedCursorTiles[]
@ BATTLE_LIST_ROWS
Definition menu_list.h:20
STATIC_ASSERT, a compile-time check that emits nothing.
#define STATIC_ASSERT(condition)
C89 permits repeated extern declarations of the same array.
#define offsetof(type, member)
Definition stddef.h:19
The battle command menus' work, heap slot 57 (0x104 bytes), reached as gLinkCountdownWork.
Definition menu_list.h:107
s32 page
the list page chosen last
Definition menu_list.h:118
s32 tutorialDelay
frames until the tutorial's next key press
Definition menu_list.h:142
s32 commandActor
The member whose commands are being chosen; -1 between members.
Definition menu_list.h:144
u8 listSlots[34]
the Psynergy list's action slots, ended by 0
Definition menu_list.h:136
s32 linkTimer
1 while the link battle's timer runs
Definition menu_list.h:132
s32 timerWindow
The window that shows the link battle's seconds left, a struct UiWindow pointer kept as a word (as a ...
Definition menu_list.h:126
s32 preferredRow
the row to return to
Definition menu_list.h:119
s32 timerHidden
Set while the status screen is open, so the timer opens no window.
Definition menu_list.h:128
u16 listAbilities[33]
the Psynergy list's ability ids, ended by 0
Definition menu_list.h:137
s32 sceneOffset
where the slide has reached; a third of the way a frame
Definition menu_list.h:116
s32 timer
Frames left to choose commands in a link battle; -1 outside link battles.
Definition menu_list.h:131
u8 iconShown[3]
whether each of icons is drawn
Definition menu_list.h:111
u8 standbyDjinn[8][4]
The party's standby Djinn by element before each command: what the summons chosen by the earlier comm...
Definition menu_list.h:135
s32 targetSceneOffset
Where the battle scene slides to (Camera_ConfigureScene's vertical offset): -2 or 16 by the target me...
Definition menu_list.h:115
s32 row
the list row chosen last
Definition menu_list.h:117
s32 commandSelection[2]
The command row's choice: [0] for the party's row (fight, flee, status), [1] for a member's commands.
Definition menu_list.h:122
s32 tutorialStep
The Djinn tutorial's step: 0 off, 1 from the start of each round while FLAG_DJINN_TUTORIAL is set,...
Definition menu_list.h:141
u32 chosenDjinn[8]
The Djinni each command has chosen, element << 8 | index, or 0x80000000.
Definition menu_list.h:146
struct MenuSprite icons[3]
The sprites UpdateLinkSessionCountdown draws each frame: the chosen command's icon,...
Definition menu_list.h:110
A cursor or prompt sprite: a list link and its OAM attributes as fields.
Definition menu_list.h:50
u16 affineIndex
Definition menu_list.h:59
struct CursorSprite * next
Definition menu_list.h:51
A point on the screen where a menu shows its cursor.
Definition menu_list.h:97
s32 y
screen pixels
Definition menu_list.h:99
s32 x
screen pixels
Definition menu_list.h:98
A menu sprite: a list link and its OAM attributes, as two words or as fields.
Definition menu_list.h:24
struct MenuSprite * next
Definition menu_list.h:25
union MenuSprite::@002225022013150231017316170057321303227123371224 oam
The party status window's layout: its window, its place and size, and what it shows (PARTY_STATUS_ fl...
Definition menu_list.h:84
u16 height
tiles
Definition menu_list.h:89
u16 flags
PARTY_STATUS_ flags.
Definition menu_list.h:90
struct UiWindow * window
Definition menu_list.h:85
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
Definition uiwindow.h:11
u16 flags
UI_WINDOW_ flags; 0 once closing or free.
Definition uiwindow.h:25
Values that differ by patch level or language, chosen once for their code.
Declares nothing of its own: it only includes edition.h and render_input.h.
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
struct MenuSprite::@002225022013150231017316170057321303227123371224::@325330370321370255050363352365103065001073105301 word
struct MenuSprite::@002225022013150231017316170057321303227123371224::@041012054333166274217104264025345003373326225271 f
The window renderer's work.