Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
item_list.c
Go to the documentation of this file.
1/* The seventh object of STSTATUS.PRO (see card_screen.c), the first screen's
2 panels (STSTATUS_createItemList): its rodata starts at 0x80082B90 (USA). */
3
4#include "menus/field_menu.h"
5
6/* Creates the item list's windows: its title, two columns of 8 items, the page
7 number, the page arrows and the cursor */
9 TextWindow *window;
10 s32 i;
11 s32 j;
12
13 windows->title = createTextWindow(panel->layer, 1, 0x13, 0x14);
14 for (i = 0; i < 8; i++) {
15 for (j = 0; j < 2; j++) {
16 window = createTextWindow(panel->layer, 1, j * 0x83 + 0x38, i * 14 + 0x25);
17 windows->items[i][j] = window;
18 window->setDepth(window, panel->depth - 1);
19 }
20 }
21 windows->page = createTextWindow(panel->layer, 1, 0x9B, 0x9C);
22 windows->pageSeparator = createTextWindow(panel->layer, 1, 0x9E, 0x9C);
23 windows->pageCount = createTextWindow(panel->layer, 1, 0xB2, 0x9C);
24 windows->prev = createTextWindow(panel->layer, 1, 0x2D, 0x97);
25 windows->next = createTextWindow(panel->layer, 1, 0x102, 0x97);
26 windows->cursor = createCursor(panel->layer, panel->depth - 1, (panel->cursor % 2) * 0x83 + 0x1E,
27 (panel->cursor % 16) / 2 * 14 + 0x25);
28 windows->cursor->setVisible(windows->cursor, 0);
29}
30
31/* Shows or hides the list's page and its arrows */
33 s32 first;
34 s32 i;
35 s32 j;
36
37 if (show) {
38 windows->title->setString(windows->title, FILE_CACHE.load(TEXT_FILE(TEXT_STATUS)), panel->list + 0x16);
39 first = panel->page * 16;
40 for (i = 0; i < 8; i++) {
41 for (j = 0; j < 2; j++) {
42 if (panel->items[first + i * 2 + j] != 0) {
43 windows->items[i][j]->setString(windows->items[i][j], FILE_CACHE.load(TEXT_FILE(TEXT_ITEM_NAMES)),
44 panel->items[first + i * 2 + j]);
45 } else {
46 windows->items[i][j]->setVisible(windows->items[i][j], 0);
47 }
48 }
49 }
50 if (panel->page == 0) {
51 panel->hasPrev = 0;
52 windows->prev->setVisible(windows->prev, 0);
53 } else {
54 panel->hasPrev = 1;
55 windows->prev->setString(windows->prev, FILE_CACHE.load(TEXT_FILE(TEXT_STATUS)), 0x22);
56 }
57 if (panel->page != panel->pageCount - 1) {
58 panel->hasNext = 1;
59 windows->next->setString(windows->next, FILE_CACHE.load(TEXT_FILE(TEXT_STATUS)), 0x23);
60 } else {
61 panel->hasNext = 0;
62 windows->next->setVisible(windows->next, 0);
63 }
64 } else {
65 windows->title->setVisible(windows->title, 0);
66 for (i = 0; i < 8; i++) {
67 for (j = 0; j < 2; j++) {
68 windows->items[i][j]->setVisible(windows->items[i][j], 0);
69 }
70 }
71 panel->hasPrev = 0;
72 windows->prev->setVisible(windows->prev, 0);
73 panel->hasNext = 0;
74 windows->next->setVisible(windows->next, 0);
75 }
76}
77
78/* Shows the page with the arrows, the chosen item and the page number */
80 if (panel->page == 0) {
81 panel->hasPrev = 0;
82 windows->prev->setVisible(windows->prev, 0);
83 } else {
84 panel->hasPrev = 1;
85 windows->prev->setString(windows->prev, FILE_CACHE.load(TEXT_FILE(TEXT_STATUS)), 0x22);
86 }
87 if (panel->page == panel->pageCount - 1) {
88 panel->hasNext = 0;
89 windows->next->setVisible(windows->next, 0);
90 } else {
91 panel->hasNext = 1;
92 windows->next->setString(windows->next, FILE_CACHE.load(TEXT_FILE(TEXT_STATUS)), 0x23);
93 }
94 STSTATUS_showItemListPage(panel, windows, 1);
95 panel->screen->item = panel->items[panel->cursor];
98 windows->page->setNumber(windows->page, 0, panel->page + 1);
99 windows->page->setRightAlign(windows->page, 1);
101 windows->pageCount->setNumber(windows->pageCount, 0, panel->pageCount);
102 windows->pageCount->setRightAlign(windows->pageCount, 1);
103}
104
105/* Moves the item list's cursor: L1 and R1 turn the pages; returns whether
106 it moved */
108 s32 page;
109 s32 cursor;
110 s32 first;
111 s32 last;
112
113 page = panel->page;
114 cursor = panel->cursor;
116 panel->page--;
117 if (panel->page < 0) {
118 panel->page = 0;
119 }
120 } else if ((!PAD_HELD(PAD_L1) && PAD_PRESSED(PAD_R1)) || (!PAD_HELD(PAD_L1) && PAD_REPEATED(PAD_R1))) {
121 panel->page++;
122 if (panel->page > panel->pageCount - 1) {
123 panel->page = panel->pageCount - 1;
124 }
125 }
126 if (page != panel->page) {
128 panel->cursor = panel->page * 16;
129 /* the column is always 0: the match depends on computing it */
130 windows->cursor->setPos(windows->cursor, (panel->cursor % 2) * 0x83 + 0x1E, (panel->cursor % 16) / 2 * 14 + 0x25);
131 STSTATUS_refreshItemList(panel, windows);
132 return 1;
133 }
134 first = page * 16;
135 /* the match depends on this form, which CSE doesn't share with first */
136 last = (page + 1) * 16 - 1;
137 if (last > panel->count - 1) {
138 last = panel->count - 1;
139 }
141 panel->cursor -= 2;
142 if (panel->cursor < first) {
143 panel->cursor = first;
144 }
145 } else if (PAD_PRESSED(PAD_DOWN) || PAD_REPEATED(PAD_DOWN)) {
146 panel->cursor += 2;
147 if (panel->cursor > last) {
148 panel->cursor = last;
149 }
150 }
152 if (!PAD_HELD(PAD_DOWN)) {
153 panel->cursor--;
154 if (panel->cursor < first) {
155 panel->cursor = first;
156 }
157 }
159 if (!PAD_HELD(PAD_UP)) {
160 panel->cursor++;
161 if (panel->cursor > last) {
162 panel->cursor = last;
163 }
164 }
165 }
166 if (cursor != panel->cursor) {
168 windows->cursor->setPos(windows->cursor, (panel->cursor % 2) * 0x83 + 0x1E, (panel->cursor % 16) / 2 * 14 + 0x25);
169 panel->screen->item = panel->items[panel->cursor];
171 STSTATUS_showItemHelp(panel->screen, 1);
172 return 1;
173 }
174 return 0;
175}
176
177/* The item list's update: fades in, lets an item be chosen, fades out */
179 switch (panel->substate) {
180 case 0:
181 default:
182 panel->fades[0].duration = 10;
183 panel->fades[1].duration = 10;
184 STSTATUS_data.funcs.startFade(&panel->fades[0], 1);
185 STSTATUS_data.funcs.startFade(&panel->fades[1], 1);
186 panel->substate++;
187 break;
188 case 1:
190 if (STSTATUS_data.funcs.updateFade(&panel->fades[1])) {
191 windows->cursor->setVisible(windows->cursor, 1);
192 STSTATUS_refreshItemList(panel, windows);
193 windows->cursor->setPos(windows->cursor, (panel->cursor % 2) * 0x83 + 0x1E,
194 (panel->cursor % 16) / 2 * 14 + 0x25);
195 panel->active = 1;
196 panel->substate++;
197 }
198 break;
199 case 2:
200 if (STSTATUS_moveItemListCursor(panel, windows) == 0) {
201 if (PAD_PRESSED(PAD_CROSS)) {
202 if (panel->list == 0) {
203 panel->screen->itemIndex = panel->cursor;
204 panel->screen->item = panel->items[panel->cursor];
207 STSTATUS_showItemHelp(panel->screen, -1);
208 panel->substate++;
209 }
210 }
211 } else if (PAD_PRESSED(PAD_TRIANGLE)) {
213 panel->screen->itemIndex = -1;
214 STSTATUS_fadeItemInfo(panel->screen, 0);
215 panel->substate++;
216 }
217 }
218 break;
219 case 3:
220 STSTATUS_showItemListPage(panel, windows, 0);
221 windows->cursor->setVisible(windows->cursor, 0);
222 windows->page->setVisible(windows->page, 0);
223 windows->pageSeparator->setVisible(windows->pageSeparator, 0);
224 windows->pageCount->setVisible(windows->pageCount, 0);
225 STSTATUS_data.funcs.startFade(&panel->fades[0], 0);
226 STSTATUS_data.funcs.startFade(&panel->fades[1], 0);
227 panel->hasPrev = 0;
228 panel->hasNext = 0;
229 panel->active = 0;
230 panel->substate++;
231 break;
232 case 4:
235 if (STSTATUS_data.funcs.updateFade(&panel->fades[1])) {
236 panel->state = TASK_KILL;
237 }
238 break;
239 }
240}
241
242/* Draws the item list's icons, page arrows and frames */
244 SpriteDrawer sprite;
245 ItemInfo *info;
246 s32 first;
247 s32 i;
248 s32 j;
249
250 initSpriteDrawer(&sprite);
251 sprite.setTexture(0x280, 0x100);
252 sprite.setLayerId(panel->layer, panel->depth);
253 if (panel->pageCount >= 2) {
254 if (GFX.funcs.getTime() - panel->time >= 11) {
255 panel->time = GFX.funcs.getTime();
256 panel->arrowFrame++;
257 if (panel->arrowFrame >= 4) {
258 panel->arrowFrame = 0;
259 }
260 }
261 sprite.setClutRow(panel->arrowFrame);
262 }
263 if (panel->hasPrev) {
264 sprite.draw(FILE_CACHE.getEntry(FILE_STATUS_SPRITES << 16), 0x34, 0x1E, 0x98);
265 }
266 if (panel->hasNext) {
267 sprite.draw(FILE_CACHE.getEntry(FILE_STATUS_SPRITES << 16), 0x35, 0xFD, 0x98);
268 }
269 sprite.setClutRow(0);
270 if (panel->active) {
271 info = ITEM_FUNCS.get(panel->items[panel->cursor]);
272 if ((info->type == 25 || info->type == 26) && (info->data.effect->flags & ITEM_USE_MENU)) {
273 sprite.setTexture(0x140, 0);
274 sprite.draw(FILE_CACHE.getEntry(FILE_MENU_SPRITES << 16), 0x40, (panel->cursor % 2) * 0x83 + 0x29,
275 (panel->cursor % 16) / 2 * 14 + 0x25);
276 }
277 first = panel->page * 16;
278 for (i = 0; i < 8; i++) {
279 for (j = 0; j < 2; j++) {
280 if (panel->items[first + i * 2 + j]) {
281 sprite.setTexture(0x140, 0);
283 ITEM_FUNCS.getCategory(panel->items[first + i * 2 + j]), j * 0x83 + 0x29,
284 i * 14 + 0x25);
285 sprite.setTexture(0x280, 0x100);
286 sprite.draw(FILE_CACHE.getEntry(FILE_STATUS_SPRITES << 16), 0x31, j * 0x83 + 0x29, i * 14 + 0x25);
287 }
288 }
289 }
290 }
291 if (panel->fades[1].level != ONE) {
292 sprite.setScale(panel->fades[1].level, ONE, ONE);
293 sprite.setPivot(0xC, 0x17);
294 }
295 sprite.draw(FILE_CACHE.getEntry(FILE_STATUS_SPRITES << 16), 0x30, 0xC, 0x12);
296 STRETCH_SPRITE_V(sprite, panel->fades[0].level, 0xA0, 0x60);
297 sprite.draw(FILE_CACHE.getEntry(FILE_STATUS_SPRITES << 16), 0x2E, 0, 0x1E);
298 if (panel->fades[2].level) {
299 sprite.setLayerId(panel->layer, panel->depth - 2);
300 STRETCH_SPRITE(sprite, panel->fades[2].level, 0x140, 0x26);
301 sprite.draw(FILE_CACHE.getEntry(FILE_STATUS_SPRITES << 16), 0x26, 0xA0, 0x12);
302 }
303}
304
305/* The item list's task: fills the list, counts its pages of 16 and puts the
306 cursor on the start item (else where the last chosen one was), then runs and
307 draws the list */
309 s32 found;
310 s32 last;
311 s32 i;
312
313 switch (panel->state) {
314 case TASK_INIT:
315 default:
316 panel->nextState(panel);
318 if (panel->count / 16 != 0) {
319 panel->pageCount = panel->count / 16 + ((panel->count & 15) != 0);
320 } else {
321 panel->pageCount = 1;
322 }
323 if (panel->startItem != 0) {
324 found = 0;
325 for (i = 0; panel->items[i] != 0; i++) {
326 if (panel->startItem == panel->items[i]) {
327 panel->cursor = i;
328 panel->page = i / 16;
329 found = 1;
330 break;
331 }
332 }
333 if (!found) {
334 last = panel->screen->itemIndex;
335 if (panel->items[last] > 0) {
336 panel->cursor = last;
337 panel->page = panel->screen->itemIndex / 16;
338 } else if (last - 1 > 0) {
339 panel->cursor = last - 1;
340 panel->page = (last - 1) / 16;
341 }
342 }
343 }
344 STSTATUS_createItemListWindows(panel, windows);
345 break;
346 case TASK_RUN:
347 STSTATUS_runItemList(panel, windows);
349 break;
350 case TASK_DONE:
351 case TASK_KILL:
352 break;
353 }
354}
355
356/* Creates the first screen's list of the items of a list (task), the cursor on
357 ITEM when it is not 0 */
360
361 panel->layer = SCREEN_LAYER;
362 panel->depth = 3;
363 panel->screen = screen;
364 if (item != 0) {
365 panel->startItem = item;
366 }
367 panel->list = list;
368 return panel;
369}
signed int s32
Definition common.h:11
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
#define TASK_RUN
Definition task.h:35
#define TASK_KILL
Definition task.h:37
#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 TASK_DONE
Definition task.h:36
Cursor * createCursor(s16 layerId, s32 depth, s16 x, s16 y)
A menu cursor on a layer at (x, y)
Definition cursor.c:92
ItemList * STSTATUS_createItemList(ItemScreen *screen, s32 list, s32 item)
Creates the first screen's list of the items of a list (task), the cursor on ITEM when it is not 0.
Definition item_list.c:358
void STSTATUS_createItemListWindows(ItemList *panel, ItemListWindows *windows)
Creates the item list's windows: its title, two columns of 8 items, the page number,...
Definition item_list.c:8
s32 STSTATUS_moveItemListCursor(ItemList *panel, ItemListWindows *windows)
Moves the item list's cursor: L1 and R1 turn the pages; returns whether it moved.
Definition item_list.c:107
void STSTATUS_runItemList(ItemList *panel, ItemListWindows *windows)
The item list's update: fades in, lets an item be chosen, fades out.
Definition item_list.c:178
void STSTATUS_updateItemList(ItemList *panel, ItemListWindows *windows)
The item list's task: fills the list, counts its pages of 16 and puts the cursor on the start item (e...
Definition item_list.c:308
void STSTATUS_refreshItemList(ItemList *panel, ItemListWindows *windows)
Shows the page with the arrows, the chosen item and the page number.
Definition item_list.c:79
void STSTATUS_drawItemList(ItemList *panel)
Draws the item list's icons, page arrows and frames.
Definition item_list.c:243
void STSTATUS_showItemListPage(ItemList *panel, ItemListWindows *windows, s32 show)
Shows or hides the list's page and its arrows.
Definition item_list.c:32
STSTATUS.PRO: the field menu's screens.
#define FILE_STATUS_SPRITES
The menu's sprite sheet; the next file is its texture archive.
Definition field_menu.h:20
#define TEXT_FILE(file)
Definition file.h:190
#define TEXT_STATUS
STATUS: the field menu's and STSTATUS's.
Definition file.h:225
#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_MENU
ItemEffect.flags.
Definition game_state.h:195
#define STRETCH_SPRITE(sprite, level, x, y)
Definition gfx.h:273
#define SCREEN_LAYER
The layer over the whole screen that most modes create first and draw their menus on (FIELDSTG and ST...
Definition gfx.h:45
#define STRETCH_SPRITE_V(sprite, level, x, y)
Definition gfx.h:274
StatusData STSTATUS_data
Definition helpers.c:356
void STSTATUS_fadeItemInfo(ItemScreen *screen, s32 show)
Opens or closes the chosen item's panel (its icon and frame); closing it also hides the item's name,...
s32 STSTATUS_itemInfoFaded(ItemScreen *screen)
Moves the chosen item's panel on; 1 once it is fully open or closed.
void STSTATUS_showItemHelp(ItemScreen *screen, s32 mode)
The help line: 1 the chosen item and the kind of a weapon, 2 a question with two answers,...
void STSTATUS_showChosenItem(ItemScreen *screen, s32 show)
Shows or hides the chosen item's name and how many are equipped and owned.
ItemFuncs ITEM_FUNCS
Definition items.c:890
#define PAD_CROSS
Definition pad.h:31
#define PAD_DOWN
Definition pad.h:24
#define PAD_RIGHT
Definition pad.h:23
#define PAD_TRIANGLE
Definition pad.h:32
#define PAD_PRESSED(button)
One button of pad 1: newly pressed, auto-repeated while held, or held.
Definition pad.h:140
#define PAD_UP
Definition pad.h:22
#define PAD_L1
Definition pad.h:28
#define PAD_LEFT
Definition pad.h:25
#define PAD_HELD(button)
Definition pad.h:142
#define PAD_R1
Definition pad.h:29
#define PAD_REPEATED(button)
Definition pad.h:141
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_SELECT
Sounds the overlays share, with SOUNDTST's names.
Definition sound.h:38
#define SOUND_MENU_CANCEL
SYSTEM01.
Definition sound.h:39
#define SOUND_CURSOR
SYSTEM02: a cursor moves.
Definition sound.h:40
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
void(* setPos)()
(cursor, x, y)
Definition text.h:34
void(* setVisible)()
(cursor, visible)
Definition text.h:33
void *(* load)(u32 file)
Definition file.h:92
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
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
An item (ITEMS, ITEM_FUNCS)
Definition game_state.h:225
u8 type
2-14 weapons, 15-20 armour, 21-24 accessories
Definition game_state.h:230
ItemRecord data
the type's record, or the usable items' effect
Definition game_state.h:226
TextWindow * prev
arrows
Definition field_menu.h:265
TextWindow * pageSeparator
Definition field_menu.h:263
Cursor * cursor
Definition field_menu.h:267
TextWindow * pageCount
Definition field_menu.h:264
TextWindow * next
Definition field_menu.h:266
TextWindow * page
Definition field_menu.h:262
TextWindow * items[8][2]
Definition field_menu.h:261
TextWindow * title
Definition field_menu.h:260
A list of the first screen (STSTATUS_createItemList)
Definition field_menu.h:237
void(* nextState)(struct ItemList *task)
Definition field_menu.h:238
PanelAnim fades[3]
Definition field_menu.h:256
s32 arrowFrame
the page arrows' palette
Definition field_menu.h:249
ItemScreen * screen
Definition field_menu.h:239
s32 pageCount
Definition field_menu.h:252
s32 page
of 16 items
Definition field_menu.h:251
s32 hasPrev
pages before and after this one
Definition field_menu.h:253
s32 active
the player can move the cursor
Definition field_menu.h:244
s32 startItem
an item to put the cursor on
Definition field_menu.h:243
s16 items[0x194]
Definition field_menu.h:246
s32 list
into STSTATUS_itemLists
Definition field_menu.h:242
s32 hasNext
Definition field_menu.h:254
s32 substate
Definition field_menu.h:238
The field menu's first screen (STSTATUS_createItemScreen)
Definition field_menu.h:68
s32 item
the chosen one
Definition field_menu.h:78
s32 itemIndex
Definition field_menu.h:79
s32 level
Definition menu.h:21
s32 duration
Definition menu.h:19
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(* setPivot)()
(x, y)
Definition gfx.h:250
void(* setScale)()
(x, y, z), ONE = 1.0
Definition gfx.h:248
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
void(* setClutRow)()
(row)
Definition gfx.h:247
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setTexture)()
(x, y)
Definition gfx.h:242
StatusFuncs funcs
Definition field_menu.h:445
s32(* updateFade)(PanelAnim *fade)
Definition field_menu.h:276
void(* startFade)(PanelAnim *fade, s32 fadeIn)
Definition field_menu.h:275
A text window (createTextWindow): up to six text buffers (0 is shown, 1-5 are "work" buffers that con...
Definition text.h:131
void(* setDepth)()
Definition text.h:183
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
void STSTATUS_fillItemList(ItemList *panel)
Fills the item list with the owned items of its option's list (STSTATUS_itemLists) and counts them.
Definition tech_screen.c:8
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