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 list of the items to buy or sell, by pages */
2
3#include "menus/item_shop.h"
4
5/* Creates the item list's windows: 14 items in two columns, the page number, the
6 L1 and R1 labels (lower when selling) and the cursor */
8 s32 i;
9 s32 y = list->selling * 0x28;
10
11 for (i = 0; i < 14; i++) {
12 win->items[i] = createTextWindow(list->layer, 1, (i % 2) * 0x83 + 0x37, (i / 2) * 0xE + 0x24);
13 win->items[i]->setDepth(win->items[i], list->depth - 1);
14 }
15 win->page = createTextWindow(list->layer, 1, 0x9B, y + 0x60);
16 win->slash = createTextWindow(list->layer, 1, 0x9C, y + 0x60);
17 win->pages = createTextWindow(list->layer, 1, 0xB0, y + 0x60);
18 win->l1Label = createTextWindow(list->layer, 1, 0x2D, y + 0x5C + list->selling * 2);
19 win->r1Label = createTextWindow(list->layer, 1, 0x102, y + 0x5C + list->selling * 2);
20 win->cursor = createCursor(list->layer, list->depth - 1, 0x1D, 0x24);
21 win->cursor->setVisible(win->cursor, 0);
22}
23
24/* Shows the page of items, the page number and the arrows' labels; or hides
25 them */
27 s32 index;
28 s32 item;
29 s32 i;
30
31 if (show) {
32 for (i = 0; i < list->pageSize; i++) {
33 index = list->page * list->pageSize + i;
34 if (list->selling == 0) {
35 item = list->shopItems[index];
36 } else {
37 item = list->items[index];
38 }
39 if (index < list->count && item != 0) {
40 win->items[i]->setString(win->items[i], FILE_CACHE.load(TEXT_FILE(TEXT_ITEM_NAMES)), item);
41 } else {
42 win->items[i]->setVisible(win->items[i], 0);
43 }
44 }
45 win->page->setNumber(win->page, 0, list->page + 1);
46 win->page->setRightAlign(win->page, 1);
48 win->pages->setNumber(win->pages, 0, list->pages);
49 win->pages->setRightAlign(win->pages, 1);
50 if (list->pages >= 2) {
51 if (list->page != 0) {
53 } else {
54 win->l1Label->setVisible(win->l1Label, 0);
55 }
56 if (list->page < list->pages - 1) {
58 return;
59 }
60 win->r1Label->setVisible(win->r1Label, 0);
61 }
62 } else {
63 for (i = 0; i < list->pageSize; i++) {
64 win->items[i]->setVisible(win->items[i], 0);
65 }
66 win->page->setVisible(win->page, 0);
67 win->slash->setVisible(win->slash, 0);
68 win->pages->setVisible(win->pages, 0);
69 win->l1Label->setVisible(win->l1Label, 0);
70 win->r1Label->setVisible(win->r1Label, 0);
71 }
72}
73
74/* Draws the list's frame, the items' icons and the blinking page arrows */
76 SpriteDrawer sprite;
77 s32 index;
78 s32 item;
79 s32 x;
80 s32 y;
81 s32 i;
82
83 initSpriteDrawer(&sprite);
84 sprite.setLayerId(list->layer, list->depth);
85 sprite.setTexture(0x280, 0x100);
86 if (list->panel.level != 0) {
87 if (list->panel.level != ONE) {
88 sprite.setScale(ONE, list->panel.level, ONE);
89 sprite.setPivot(0xA0, 0x47);
90 } else {
91 for (i = 0; i < list->pageSize; i++) {
92 index = list->page * list->pageSize + i;
93 if (list->selling == 0) {
94 item = list->shopItems[index];
95 } else {
96 item = list->items[index];
97 }
98 if (index >= list->count || item == 0) {
99 break;
100 }
101 x = (i % 2) * 0x83 + 0x28;
102 y = (i % list->pageSize) / 2 * 0xE + 0x24;
103 sprite.setTexture(0x140, 0);
105 sprite.setTexture(0x280, 0x100);
106 sprite.draw(FILE_CACHE.getEntry(FILE_SHOP_SPRITES << 16), 0x31, x, y);
107 }
108 if (list->pages >= 2) {
109 if (GFX.funcs.getTime() - list->blinkTime >= 11) {
110 list->blinkTime = GFX.funcs.getTime();
111 if (++list->clutRow >= 4) {
112 list->clutRow = 0;
113 }
114 }
115 sprite.setTexture(0x280, 0x100);
116 sprite.setClutRow(list->clutRow);
117 if (list->page != 0) {
118 sprite.draw(FILE_CACHE.getEntry(FILE_SHOP_SPRITES << 16), 0x10, 0x1E, list->selling * 0x2A + 0x5F);
119 }
120 if (list->page < list->pages - 1) {
121 sprite.draw(FILE_CACHE.getEntry(FILE_SHOP_SPRITES << 16), 0x11, 0xFD, list->selling * 0x2A + 0x5F);
122 }
123 sprite.setClutRow(0);
124 }
125 }
126 sprite.setTexture(0x280, 0x100);
127 sprite.draw(FILE_CACHE.getEntry(FILE_SHOP_SPRITES << 16), list->selling + 6, 0, 0x1D);
128 }
129}
130
131/* The list's states: lists the shop's items or the bag's, fades in, then
132 fades out when closed */
134 switch (list->substate) {
135 case 0:
136 default:
137 if (list->selling == 0) {
139 list->count = STITSHOP_funcs.count;
140 list->pageSize = 8;
141 list->substate++;
142 } else {
144 list->pageSize = 14;
145 list->substate = 100;
146 }
147 list->pages = list->count / list->pageSize + (list->count % list->pageSize != 0);
148 break;
149 case 1:
150 STITSHOP_funcs.startFade(&list->panel, 1);
151 list->substate++;
152 break;
153 case 2:
154 if (STITSHOP_funcs.updateFade(&list->panel)) {
155 STITSHOP_showItemPage(list, win, 1);
156 list->setState(list, TASK_DONE);
157 }
158 break;
159 case 50:
160 STITSHOP_funcs.startFade(&list->panel, 0);
161 STITSHOP_showItemPage(list, win, 0);
162 list->substate++;
163 break;
164 case 51:
165 if (STITSHOP_funcs.updateFade(&list->panel)) {
166 list->setState(list, TASK_DONE);
167 }
168 break;
169 case 100:
170 break;
171 }
172}
173
174/* The item list: L1 and R1 turn its pages, the d-pad moves in the page, and
175 the dialog shows the selected item */
177 s32 page;
178 s32 first;
179 s32 last;
180 s32 old;
181 s32 item;
182
183 switch (list->state) {
184 case TASK_INIT:
185 default:
186 list->nextState(list);
188 list->panel.duration = 10;
189 break;
190 case TASK_RUN:
191 STITSHOP_runItemList(list, win);
193 break;
194 case TASK_DONE:
195 if (list->active) {
196 page = list->page;
198 if (--list->page < 0) {
199 list->page = 0;
200 }
201 } else if ((!PAD_HELD(PAD_L1) && PAD_PRESSED(PAD_R1)) || (!PAD_HELD(PAD_L1) && PAD_REPEATED(PAD_R1))) {
202 if (++list->page > list->pages - 1) {
203 list->page = list->pages - 1;
204 }
205 }
206 if (page != list->page) {
208 list->selection = list->page * list->pageSize;
209 if (list->selling == 0) {
210 item = list->shopItems[list->selection];
211 } else {
212 item = list->items[list->selection];
213 }
214 list->dialog->showItem(list->dialog, item, 1);
215 STITSHOP_showItemPage(list, win, 1);
216 win->cursor->setPos(win->cursor, (list->selection % 2) * 0x83 + 0x1D,
217 (list->selection % list->pageSize) / 2 * 0xE + 0x24);
218 } else {
219 first = page * list->pageSize;
220 old = list->selection;
221 last = (page + 1) * list->pageSize - 1;
222 if (last > list->count - 1) {
223 last = list->count - 1;
224 }
226 list->selection -= 2;
227 if (list->selection < first) {
228 list->selection = first;
229 }
230 } else if (PAD_PRESSED(PAD_DOWN) || PAD_REPEATED(PAD_DOWN)) {
231 list->selection += 2;
232 if (list->selection > last) {
233 list->selection = last;
234 }
235 }
237 if (!PAD_HELD(PAD_DOWN)) {
238 if (--list->selection < first) {
239 list->selection = first;
240 }
241 }
243 if (!PAD_HELD(PAD_UP)) {
244 if (++list->selection > last) {
245 list->selection = last;
246 }
247 }
248 }
249 if (old != list->selection) {
250 if (list->selling == 0) {
251 item = list->shopItems[list->selection];
252 } else {
253 item = list->items[list->selection];
254 }
255 list->dialog->showItem(list->dialog, item, 1);
256 win->cursor->setPos(win->cursor, (list->selection % 2) * 0x83 + 0x1D,
257 (list->selection % list->pageSize) / 2 * 0xE + 0x24);
259 }
260 }
261 }
263 break;
264 case TASK_KILL:
265 break;
266 }
267}
268
269/* Freezes the list's cursor (still, in palette 7) and its input, or lets them go
270 again (list->freezeCursor): while the details panel turns its page */
272 ShopItemListWindows *win = list->children;
273
274 if (frozen) {
276 win->cursor->setStill(win->cursor, 1);
277 list->active = 0;
278 } else {
280 win->cursor->setStill(win->cursor, 0);
281 list->active = 1;
282 }
283}
284
285/* Shows the list's cursor at the selection and takes the d-pad, or hides it and
286 stops (list->showCursor) */
288 ShopItemListWindows *win = list->children;
289 s32 row;
290
291 list->active = visible;
292 row = (list->selection % list->pageSize) / 2;
293 win->cursor->setPos(win->cursor, (list->selection % 2) * 0x83 + 0x1D, row * 0xE + 0x24);
294 win->cursor->setVisible(win->cursor, visible);
295}
296
297/* Runs the list's states again (list->start), to reopen it after the quantity
298 and the yes/no */
300 list->setState(list, TASK_RUN);
301}
302
303/* Closes the list (list->close): hides the cursor and fades it out */
305 list->setState(list, TASK_RUN);
306 list->substate = 50;
308}
309
310/* The item at the list's selection, of the shop's or of the bag's sellable ones
311 (list->getSelected) */
313 if (!list->selling) {
314 return list->shopItems[list->selection];
315 }
316 return list->items[list->selection];
317}
318
319/* Lists the sellable items again, shows the page and the selection in the
320 dialog (list->refresh) */
322 ShopItemListWindows *win = list->children;
323
325 STITSHOP_showItemPage(list, win, 1);
326 list->dialog->showItem(list->dialog, list->items[list->selection], 1);
327}
328
329/* Lists the bag's items of the list's type that can be sold, those with a sell
330 price (list->listBag, again after a sale) */
332 s32 i;
333 s32 n;
334
335 list->count = 0;
336 n = ITEM_FUNCS.list(list->type, list->bag);
337 for (i = 0; i < n; i++) {
338 if (ITEM_FUNCS.get(list->bag[i])->sellPrice != 0) {
339 list->items[list->count++] = list->bag[i];
340 }
341 }
342}
343
344/* Creates the item list (task) of a dialog: the items of the shop type when
345 buying, the bag's of the item type when selling */
348
356 list->layer = SCREEN_LAYER;
357 list->depth = 4;
358 list->dialog = dialog;
359 list->selling = selling;
360 list->type = type;
361 return list;
362}
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
#define TEXT_ITEM_SHOP
ITSHOP: STITSHOP's.
Definition file.h:216
#define TEXT_FILE(file)
Definition file.h:190
#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 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
void STITSHOP_listSellable(ShopItemList *list)
Lists the bag's items of the list's type that can be sold, those with a sell price (list->listBag,...
Definition item_list.c:331
void STITSHOP_refreshItemList(ShopItemList *list)
Lists the sellable items again, shows the page and the selection in the dialog (list->refresh)
Definition item_list.c:321
s32 STITSHOP_getSelectedItem(ShopItemList *list)
The item at the list's selection, of the shop's or of the bag's sellable ones (list->getSelected)
Definition item_list.c:312
void STITSHOP_closeItemList(ShopItemList *list)
Closes the list (list->close): hides the cursor and fades it out.
Definition item_list.c:304
void STITSHOP_createItemListWindows(ShopItemList *list, ShopItemListWindows *win)
Creates the item list's windows: 14 items in two columns, the page number, the L1 and R1 labels (lowe...
Definition item_list.c:7
void STITSHOP_updateItemList(ShopItemList *list, ShopItemListWindows *win)
The item list: L1 and R1 turn its pages, the d-pad moves in the page, and the dialog shows the select...
Definition item_list.c:176
void STITSHOP_showItemPage(ShopItemList *list, ShopItemListWindows *win, s32 show)
Shows the page of items, the page number and the arrows' labels; or hides them.
Definition item_list.c:26
ShopItemList * STITSHOP_createItemList(ShopDialog *dialog, s32 type, s32 selling)
Creates the item list (task) of a dialog: the items of the shop type when buying, the bag's of the it...
Definition item_list.c:346
void STITSHOP_runItemList(ShopItemList *list, ShopItemListWindows *win)
The list's states: lists the shop's items or the bag's, fades in, then fades out when closed.
Definition item_list.c:133
void STITSHOP_drawItemList(ShopItemList *list)
Draws the list's frame, the items' icons and the blinking page arrows.
Definition item_list.c:75
void STITSHOP_showListCursor(ShopItemList *list, s32 visible)
Shows the list's cursor at the selection and takes the d-pad, or hides it and stops (list->showCursor...
Definition item_list.c:287
void STITSHOP_startItemList(ShopItemList *list)
Runs the list's states again (list->start), to reopen it after the quantity and the yes/no.
Definition item_list.c:299
void STITSHOP_freezeListCursor(ShopItemList *list, s32 frozen)
Freezes the list's cursor (still, in palette 7) and its input, or lets them go again (list->freezeCur...
Definition item_list.c:271
STITSHOP.PRO: the item shop.
#define FILE_SHOP_SPRITES
The shop's sprite sheet; the next file is its texture archive.
Definition item_shop.h:19
ItemFuncs ITEM_FUNCS
Definition items.c:890
#define PAD_DOWN
Definition pad.h:24
#define PAD_RIGHT
Definition pad.h:23
#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_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...
ItemShopFuncs STITSHOP_funcs
The shop's helpers.
Definition stitshop.c:228
void(* setPalette)()
Definition text.h:35
void(* setPos)()
(cursor, x, y)
Definition text.h:34
void(* setStill)()
Definition text.h:38
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
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
u16 sellPrice
0: cannot be sold
Definition game_state.h:228
s32 count
the items of the shop getShopItems returned
Definition item_shop.h:225
s32(* updateFade)(PanelAnim *fade)
Definition item_shop.h:229
void(* startFade)(PanelAnim *fade, s32 fadeIn)
Definition item_shop.h:228
s16 *(* getShopItems)(s32 shop)
Definition item_shop.h:232
s32 level
Definition menu.h:21
s32 duration
Definition menu.h:19
What ShopBuy and ShopSell start with, and are passed to the item list as: the list shows its selectio...
Definition item_shop.h:110
void(* showItem)(struct ShopDialog *dialog, s32 item, s32 quantity)
Definition item_shop.h:112
TextWindow * slash
Definition item_shop.h:147
TextWindow * page
Definition item_shop.h:146
TextWindow * pages
Definition item_shop.h:148
TextWindow * items[14]
Definition item_shop.h:145
TextWindow * l1Label
Definition item_shop.h:149
TextWindow * r1Label
Definition item_shop.h:150
The list of the items to buy or sell (STITSHOP_createItemList)
Definition item_shop.h:116
void(* freezeCursor)(struct ShopItemList *list, s32 frozen)
Definition item_shop.h:139
s16 * shopItems
Definition item_shop.h:125
void(* close)(struct ShopItemList *list)
Definition item_shop.h:136
void(* refresh)(struct ShopItemList *list)
Definition item_shop.h:140
void(* nextState)(struct ShopItemList *task)
Definition item_shop.h:117
s16 items[0x194]
the bag's items that can be sold
Definition item_shop.h:123
void(* showCursor)(struct ShopItemList *list, s32 visible)
Definition item_shop.h:138
void(* start)(struct ShopItemList *list)
Definition item_shop.h:135
void(* listBag)(struct ShopItemList *list)
Definition item_shop.h:141
s32(* getSelected)(struct ShopItemList *list)
Definition item_shop.h:137
s32 clutRow
the arrows' blink
Definition item_shop.h:131
s32 type
the shop, or the item type to sell
Definition item_shop.h:122
ShopDialog * dialog
ShopBuy or ShopSell.
Definition item_shop.h:118
s32 selling
0: the shop's items, 1: the bag's
Definition item_shop.h:121
void * children
Definition item_shop.h:117
s16 bag[0x194]
Definition item_shop.h:124
void(* setState)(struct ShopItemList *task, s32 state)
Definition item_shop.h:117
PanelAnim panel
Definition item_shop.h:134
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
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
#define PALETTE_WHITE
The text windows' palettes (TextWindow.palette, setPalette): rows of the font's CLUTs,...
Definition text.h:112
#define PALETTE_GREY
what is unavailable
Definition text.h:119
TextWindow * createTextWindow(s16 layerId, s16 style, s16 x, s16 y)
A text window on a layer, in a font style, at (x, y)