Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
item_menu.c
Go to the documentation of this file.
1/* FIGHTSTG's item menu, with the cursors of the technique and switch menus
2 too, which the original has here. */
3
5
6/* Draws the page's item icons, the page arrows (blinking) and the frame */
8 SpriteDrawer drawer;
9 void *sheet;
10 s32 index;
11 s32 i;
12
13 initSpriteDrawer(&drawer);
15 drawer.setTexture(0x140, 0);
17 for (i = 0; i < ITEM_MENU_LINES; i++) {
18 index = task->page * ITEM_MENU_LINES + i;
19 if (index > task->count - 1) {
20 break;
21 }
22 drawer.draw(sheet, ITEM_FUNCS.getCategory(task->usable[index]), 0x1D, 0x45 + i * 0xE);
23 }
25 drawer.setTexture(0x200, 0);
26 if (GFX.funcs.getTime() & 0x10) {
27 if (task->page > 0) {
28 drawer.draw(sheet, 0x1F, 0x10, 0xA9);
29 }
30 if (task->page < task->pageCount - 1) {
31 drawer.draw(sheet, 0x20, 0x90, 0xA9);
32 }
33 }
34 drawer.draw(sheet, 0x27, 8, 0x3E);
35 drawer.draw(sheet, 0x28, 0xA6, 0xA0);
36 drawer.draw(sheet, 0x31, 0xB, 0xBC);
37}
38
39/* Makes the item menu's windows: the page buttons, the count's label, the
40 seven names, the description and the count */
42 char *text;
43 s32 i;
44
47 w->prevButton->setString(w->prevButton, text, 0x11);
50 w->nextButton->setString(w->nextButton, text, 0x12);
53 w->countLabel->setString(w->countLabel, text, 0xC);
54 for (i = 0; i < ITEM_MENU_LINES; i++) {
55 w->names[i] = createTextWindow(BATTLE_LAYER_MENUS, 1, 0x2A, 0x45 + i * 0xE);
56 }
57 w->message = createTextWindow(BATTLE_LAYER_MENUS, 1, 0x14, 0xC2);
58 w->count = createTextWindow(BATTLE_LAYER_MENUS, 1, 0xC6, 0xA5);
59}
60
61/* Shows the page's names and the description and count of the item under
62 the cursor, or text 0x15 and 0x1A when there are none */
64 s32 index;
65 s32 item;
66 s32 i;
67
68 if (task->count != 0) {
69 for (i = 0; i < ITEM_MENU_LINES; i++) {
70 index = task->page * ITEM_MENU_LINES + i;
71 if (index > task->count - 1) {
72 w->names[i]->setVisible(w->names[i], 0);
73 } else {
74 item = task->usable[index];
75 if (item != 0) {
77 }
78 }
79 }
80 item = task->usable[task->page * ITEM_MENU_LINES + w->cursor->sel];
82 w->count->setNumber(w->count, 0, GAME.items[item]);
83 } else {
86 }
87 w->count->setRightAlign(w->count, 1);
88}
89
90/* the cursors of the items' (FIGHTSTG_updateItemMenu), the techniques'
91 (FIGHTSTG_updateTechMenu) and the partner switch's (FIGHTSTG_updateSwitchMenu) menus */
93 1, 14, 69, 14, -1, 0, 0, 0,
94};
96 1, 14, 69, 14, -1, 0, 0, 0,
97};
99 2, 17, 78, 32, 47, 16, 77, 32,
100};
101
102/* The item menu's task: lists the items usable in battle (flag 2), then L1
103 and R1 turn the pages, cross picks the item under the cursor into *result
104 and triangle gives -2; frees the list when killed */
106 s32 total;
107 s32 pressed;
108 s32 page;
109 s32 rows;
110 s32 n;
111 s32 i;
112
113 switch (task->state) {
114 case TASK_INIT:
115 default:
116 total = ITEM_FUNCS.list(1, task->items);
117 task->count = 0;
118 for (i = 0; i < total; i++) {
119 if (task->items[i] == 0) {
120 break;
121 }
122 if (ITEM_FUNCS.get(task->items[i])->data.effect->flags & ITEM_USE_BATTLE) {
123 task->count++;
124 }
125 }
126 if (task->count != 0) {
127 task->usable = HEAP.alloc(task->count * 2, 2);
128 n = 0;
129 for (i = 0; i < total; i++) {
130 if (task->items[i] == 0) {
131 break;
132 }
133 if (ITEM_FUNCS.get(task->items[i])->data.effect->flags & ITEM_USE_BATTLE) {
134 task->usable[n++] = task->items[i];
135 }
136 }
137 if (task->count % ITEM_MENU_LINES != 0) {
138 task->pageCount = task->count / ITEM_MENU_LINES + 1;
139 } else {
140 task->pageCount = task->count / ITEM_MENU_LINES;
141 }
142 if (task->count != 0) {
143 if (task->count > ITEM_MENU_LINES) {
145 } else {
147 }
148 }
149 }
152 FIGHTSTG_showItemPage(task, w);
153 task->nextState(task);
154 break;
155 case TASK_RUN:
157 pressed = PAD.getPressed(0);
158 page = task->page;
159 if (task->pageCount != 0) {
160 if (pressed & (1 << PAD_L1)) {
161 if (--task->page < 0) {
162 task->page = 0;
163 }
164 } else if (pressed & (1 << PAD_R1)) {
165 if (++task->page > task->pageCount - 1) {
166 task->page = task->pageCount - 1;
167 }
168 }
169 }
170 if (page != task->page) {
171 w->cursor->sel = 0;
172 rows = task->count - task->page * ITEM_MENU_LINES;
173 if (rows > ITEM_MENU_LINES) {
174 rows = ITEM_MENU_LINES;
175 }
176 w->cursor->params.count = rows;
177 FIGHTSTG_showItemPage(task, w);
179 } else if (task->sel != w->cursor->sel) {
180 FIGHTSTG_showItemPage(task, w);
181 } else if (pressed & (1 << PAD_CROSS)) {
183 if (task->count != 0) {
184 *task->result = task->usable[task->page * ITEM_MENU_LINES + w->cursor->sel];
185 task->setState(task, 3);
186 w->cursor->locked = 1;
187 break;
188 }
189 } else if (pressed & (1 << PAD_TRIANGLE)) {
190 /* the match depends on the goto, which puts the cancel after the
191 cursor's line */
192 goto cancel;
193 }
194 task->sel = w->cursor->sel;
195 break;
196 cancel:
198 *task->result = -2;
199 task->setState(task, 3);
200 break;
201 case 2:
202 break;
203 case 3:
204 if (task->usable != NULL) {
205 HEAP.free(task->usable);
206 }
207 break;
208 }
209}
210
211/* Opens the battle's item menu; *result gets the item picked, or -2 to go
212 back */
215
216 task->result = result;
217 *result = -1;
218 return task;
219}
MenuCursor * FIGHTSTG_createCursor(CursorLayout *layout)
Creates a menu cursor laid out by layout.
Definition cursor.c:136
#define ITEM_MENU_LINES
The lines of a page of the item menu.
Definition menu.h:81
#define BATTLE_LAYER_MENUS
the HUD, the menus and the messages
Definition types.h:31
FIGHTSTG.PRO: the battle.
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
#define TASK_RUN
Definition task.h:35
#define TASK_INIT
Tasks: every game object is a task, a heap block that starts with this header and is updated once per...
Definition task.h:34
#define TEXT_ITEM_INFO
ITMINF.
Definition file.h:214
#define TEXT_BATTLE_MENU
MFIGHT: WFIGHTMN's.
Definition file.h:218
#define TEXT_FILE(file)
Definition file.h:190
#define FILE_BATTLE_MENU
The battle menu's files (WFIGHTMN, WFIGHTTS): FILE_BATTLE_IMAGES is an archive whose entries go throu...
Definition file.h:294
#define TEXT_ITEM_NAMES
ITMNAM.
Definition file.h:215
#define FILE_MENU_SPRITES
Files the engine loads by number.
Definition file.h:188
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
#define ITEM_USE_BATTLE
usable in battle (FIGHTSTG's item menu)
Definition game_state.h:196
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
ItemMenu * FIGHTSTG_createItemMenu(s32 *result)
Opens the battle's item menu; *result gets the item picked, or -2 to go back.
Definition item_menu.c:213
CursorLayout FIGHTSTG_itemCursor
the cursors of the items' (FIGHTSTG_updateItemMenu), the techniques' (FIGHTSTG_updateTechMenu) and th...
Definition item_menu.c:92
CursorLayout FIGHTSTG_switchCursor
FIGHTSTG_updateSwitchMenu's cursor.
Definition item_menu.c:98
void FIGHTSTG_updateItemMenu(ItemMenu *task, ItemMenuWindows *w)
The item menu's task: lists the items usable in battle (flag 2), then L1 and R1 turn the pages,...
Definition item_menu.c:105
void FIGHTSTG_drawItemMenu(ItemMenu *task)
Draws the page's item icons, the page arrows (blinking) and the frame.
Definition item_menu.c:7
CursorLayout FIGHTSTG_techCursor
FIGHTSTG_updateTechMenu's cursor.
Definition item_menu.c:95
void FIGHTSTG_createItemWindows(ItemMenu *task, ItemMenuWindows *w)
Makes the item menu's windows: the page buttons, the count's label, the seven names,...
Definition item_menu.c:41
void FIGHTSTG_showItemPage(ItemMenu *task, ItemMenuWindows *w)
Shows the page's names and the description and count of the item under the cursor,...
Definition item_menu.c:63
ItemFuncs ITEM_FUNCS
Definition items.c:890
PadState PAD
Controller input: cleared by initPad, then the methods.
Definition pad.c:168
#define PAD_CROSS
Definition pad.h:31
#define PAD_TRIANGLE
Definition pad.h:32
#define PAD_L1
Definition pad.h:28
#define PAD_R1
Definition pad.h:29
SoundState SOUND
rsin and rcos (libgte) read rsin_tbl[a - 0x800] and the like: their addresses before the table fall i...
Definition sound.c:180
#define SOUND_MENU_CONFIRM
SYSTEM07.
Definition sound.h:44
#define SOUND_MENU_CANCEL
SYSTEM01.
Definition sound.h:39
#define SOUND_MENU_MOVE
SYSTEM06.
Definition sound.h:43
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
A menu cursor's layout, which FIGHTSTG_createCursor copies into its task: a highlight bar over count ...
Definition menu.h:288
s32 count
Definition menu.h:289
void *(* load)(u32 file)
Definition file.h:92
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s8 items[0x193]
counts, up to 99
Definition game_state.h:512
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
void *(* alloc)(s32 size, s32 tag)
Definition heap.h:29
void(* free)(void *ptr)
Definition heap.h:27
u8 flags
ITEM_USE_*.
Definition game_state.h:201
s32(* getCategory)(s32 item)
getItemCategory
Definition game_state.h:671
struct ItemInfo *(* get)(s32 item)
getItem
Definition game_state.h:670
s32(* list)(s32 type, s16 *out)
listItems
Definition game_state.h:673
ItemRecord data
the type's record, or the usable items' effect
Definition game_state.h:226
FIGHTSTG_updateItemMenu's children.
Definition menu.h:96
TextWindow * count
how many of the item
Definition menu.h:101
TextWindow * message
its description
Definition menu.h:102
TextWindow * names[7]
Definition menu.h:103
TextWindow * nextButton
Definition menu.h:99
TextWindow * countLabel
text 0xC
Definition menu.h:100
struct MenuCursor * cursor
Definition menu.h:97
TextWindow * prevButton
the page buttons, texts 0x11 and 0x12
Definition menu.h:98
The battle's item menu (FIGHTSTG_updateItemMenu): the usable items, seven a page.
Definition menu.h:84
s32 * result
-1 until it is done, then the item or -2
Definition menu.h:86
void(* setState)(struct ItemMenu *task, s32 state)
Definition menu.h:85
s16 * usable
the items with flag 2
Definition menu.h:89
s32 count
Definition menu.h:90
s32 sel
the cursor's line last frame
Definition menu.h:87
s16 items[0x194]
the bag's (ITEM_FUNCS.list)
Definition menu.h:88
s32 pageCount
Definition menu.h:92
void(* nextState)(struct ItemMenu *task)
Definition menu.h:85
s32 state
Definition menu.h:85
s32 page
Definition menu.h:91
s32 sel
Definition menu.h:304
s32 locked
Definition menu.h:305
CursorLayout params
Definition menu.h:306
s32(* getPressed)(s32 pad)
Definition pad.h:125
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187
Draws sprites from a sprite sheet (such as file 0x277, the menu graphics): a sheet has a table of fra...
Definition gfx.h:223
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setTexture)()
(x, y)
Definition gfx.h:242
void(* setPalette)(struct TextWindow *obj, u8 arg)
Definition text.h:174
void(* setRightAlign)()
no prototype: callers would truncate u8 args
Definition text.h:178
void(* setNumber)()
Definition text.h:166
void(* setString)()
Definition text.h:165
void(* setVisible)(struct TextWindow *obj, u8 arg)
Definition text.h:177
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
#define PALETTE_DARK_BLUE
Definition text.h:114
TextWindow * createTextWindow(s16 layerId, s16 style, s16 x, s16 y)
A text window on a layer, in a font style, at (x, y)
ItemEffect * effect
Definition game_state.h:211