Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
shop.c
Go to the documentation of this file.
1/* The shop's main task, with its menu and the money; the files it loads; and
2 the panels' openings and moves */
3
4#include "menus/item_shop.h"
5
6/* Creates the shop's windows: the help, the shop's name, the money, buy and sell,
7 and the cursor */
9 win->help = createTextWindow(shop->layer, 1, 0xD3, 0xCC);
10 win->title = createTextWindow(shop->layer, 1, 0x1D, 0x14);
11 win->money = createTextWindow(shop->layer, 3, 0x117, 0x17);
12 win->moneyLabel = createTextWindow(shop->layer, 3, 0x11A, 0x17);
13 win->buy = createTextWindow(shop->layer, 1, 0xBE, 0x2F);
14 win->sell = createTextWindow(shop->layer, 1, 0xBE, 0x3D);
15 win->cursor = createCursor(shop->layer, 0, 0xB0, 0x2F);
16 win->cursor->setVisible(win->cursor, 0);
17}
18
19/* Draws the shop's four frames as they open by scaling, and the background,
20 which scrolls one pixel every other frame, wrapping at 96 */
22 SpriteDrawer sprite;
23
24 initSpriteDrawer(&sprite);
25 sprite.setLayerId(shop->layer, 1);
26 sprite.setTexture(0x280, 0x100);
27 if (shop->panels[0].level != 0) {
28 if (shop->panels[0].level != ONE) {
29 sprite.setScale(shop->panels[0].level, ONE, ONE);
30 sprite.setPivot(0x57, 0x19);
31 }
32 sprite.draw(FILE_CACHE.getEntry(FILE_SHOP_SPRITES << 16), 1, 0x16, 0x12);
33 }
34 if (shop->panels[1].level != 0) {
35 STRETCH_SPRITE(sprite, shop->panels[1].level, 0x140, 0x18);
36 sprite.draw(FILE_CACHE.getEntry(FILE_SHOP_SPRITES << 16), 2, 0xD6, 0xF);
37 }
38 if (shop->panels[2].level != 0) {
39 STRETCH_SPRITE(sprite, shop->panels[2].level, 0x140, 0x3B);
40 sprite.draw(FILE_CACHE.getEntry(FILE_SHOP_SPRITES << 16), 5, 0xA9, 0x26);
41 }
42 if (shop->panels[3].level != 0) {
43 STRETCH_SPRITE(sprite, shop->panels[3].level, 0x140, 0xD2);
44 sprite.draw(FILE_CACHE.getEntry(FILE_SHOP_SPRITES << 16), 0, 0xC6, 0xC4);
45 }
46 sprite.setLayerId(shop->layer, 7);
47 if (shop->bgTick != 0) {
48 shop->bgScroll++;
49 shop->bgScroll = shop->bgScroll < 0x60 ? shop->bgScroll : 0;
50 shop->bgTick = 0;
51 } else {
52 shop->bgTick = 1;
53 }
54 sprite.setScale(ONE, ONE, ONE);
55 sprite.draw(FILE_CACHE.getEntry(FILE_SHOP_SPRITES << 16), 0x14, shop->bgScroll, shop->bgScroll);
56}
57
58/* Opens the shop's panels, then up/down and cross pick buy or sell and run that
59 dialog, reopening after it; triangle closes the panels and fades out */
61 s32 choice;
62
63 switch (shop->substate) {
64 case 0:
65 default:
66 STITSHOP_funcs.startFade(&shop->panels[0], 1);
67 STITSHOP_funcs.startFade(&shop->panels[1], 1);
68 shop->substate++;
69 break;
70 case 1:
72 if (STITSHOP_funcs.updateFade(&shop->panels[1]) != 0) {
73 STITSHOP_funcs.startFade(&shop->panels[2], 1);
74 STITSHOP_funcs.startFade(&shop->panels[3], 1);
77 win->money->setNumber(win->money, 0, GAME.money);
78 win->money->setRightAlign(win->money, 1);
79 shop->substate++;
80 }
81 break;
82 case 2:
84 if (STITSHOP_funcs.updateFade(&shop->panels[3]) != 0) {
87 win->cursor->setVisible(win->cursor, 1);
89 shop->substate++;
90 }
91 break;
92 case 3:
93 choice = shop->choice;
94 if (PAD_PRESSED(PAD_UP)) {
95 shop->choice = 0;
96 } else if (PAD_PRESSED(PAD_DOWN)) {
97 shop->choice = 1;
98 }
99 if (choice != shop->choice) {
101 win->cursor->setPos(win->cursor, 0xB0, shop->choice * 0xE + 0x2F);
102 }
103 if (PAD_PRESSED(PAD_CROSS)) {
105 shop->substate = 20;
106 shop->step = 1;
107 } else if (PAD_PRESSED(PAD_TRIANGLE)) {
109 shop->setSubstate(shop, 20);
110 }
111 break;
112 case 10:
113 if (shop->choice == 0) {
114 win->dialog = (Task *)STITSHOP_createBuy(shop);
115 } else {
116 win->dialog = (Task *)STITSHOP_createSell(shop);
117 }
118 shop->substate++;
119 break;
120 case 11:
121 if (win->dialog == NULL) {
122 STITSHOP_funcs.startFade(&shop->panels[2], 1);
123 STITSHOP_funcs.startFade(&shop->panels[3], 1);
124 shop->substate = 2;
125 }
126 break;
127 case 20:
128 if (shop->step == 0) {
129 win->fade = STITSHOP_createFader();
130 win->fade->start(win->fade, 0, 0x1E);
131 }
132 STITSHOP_funcs.startFade(&shop->panels[2], 0);
133 STITSHOP_funcs.startFade(&shop->panels[3], 0);
134 win->help->setVisible(win->help, 0);
135 win->buy->setVisible(win->buy, 0);
136 win->sell->setVisible(win->sell, 0);
137 win->cursor->setVisible(win->cursor, 0);
138 shop->substate++;
139 break;
140 case 21:
142 if (STITSHOP_funcs.updateFade(&shop->panels[3]) != 0) {
143 if (shop->step != 0) {
144 shop->setSubstate(shop, 10);
145 } else {
146 STITSHOP_funcs.startFade(&shop->panels[0], 0);
147 STITSHOP_funcs.startFade(&shop->panels[1], 0);
148 win->title->setVisible(win->title, 0);
149 win->moneyLabel->setVisible(win->moneyLabel, 0);
150 win->money->setVisible(win->money, 0);
151 shop->substate++;
152 }
153 }
154 break;
155 case 22:
157 if (STITSHOP_funcs.updateFade(&shop->panels[1]) != 0) {
158 shop->substate++;
159 }
160 break;
161 case 23:
162 if (win->fade->state == TASK_DONE) {
163 shop->state = TASK_KILL;
164 }
165 break;
166 }
167}
168
169/* The shop's task: loads its files, then runs it; goes back to the field when
170 killed */
172 switch (shop->state) {
173 case TASK_INIT:
174 default:
175 switch (shop->substate) {
176 case 0:
177 default:
179 shop->substate++;
180 break;
181 case 1:
182 if (STITSHOP_funcs.filesLoading() == 0) {
184 shop->panels[0].duration = 10;
185 shop->panels[1].duration = 10;
186 shop->panels[2].duration = 10;
187 shop->panels[3].duration = 10;
188 shop->nextState(shop);
189 }
190 break;
191 }
192 break;
193 case TASK_RUN:
194 STITSHOP_runShop(shop, win);
195 STITSHOP_drawShop(shop, win);
196 break;
197 case TASK_DONE:
198 break;
199 case TASK_KILL:
201 break;
202 }
203}
204
205/* Shows the money left (shop->showMoney), after buying or selling */
207 ItemShopWindows *win = shop->children;
208
209 win->money->setNumber(win->money, 0, GAME.money);
210 win->money->setRightAlign(win->money, 1);
211}
212
213/* Creates the item shop (task) for the shop of the mode's argument */
216
218 shop->layer = SCREEN_LAYER;
219 shop->shop = GAME.funcs.getModeArg();
220 return shop;
221}
222
223/* Loads the shop's textures and requests its strings */
235
236/* Whether the shop's strings are still loading */
239 return 1;
240 }
242 return 1;
243 }
245 return 1;
246 }
248}
249
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
#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_INFO
ITMINF.
Definition file.h:214
#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 TEXT_SHOP_NAMES
SHPNAM.
Definition file.h:221
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
#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
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
ScreenFade * STITSHOP_createFader(void)
void STITSHOP_drawShop(ItemShop *shop, ItemShopWindows *win)
Draws the shop's four frames as they open by scaling, and the background, which scrolls one pixel eve...
Definition shop.c:21
s32 STITSHOP_filesLoading(void)
Whether the shop's strings are still loading.
Definition shop.c:237
void STITSHOP_showMoney(ItemShop *shop)
Shows the money left (shop->showMoney), after buying or selling.
Definition shop.c:206
ItemShop * STITSHOP_createShop(void)
Creates the item shop (task) for the shop of the mode's argument.
Definition shop.c:214
void STITSHOP_updateShop(ItemShop *shop, ItemShopWindows *win)
The shop's task: loads its files, then runs it; goes back to the field when killed.
Definition shop.c:171
void STITSHOP_createShopWindows(ItemShop *shop, ItemShopWindows *win)
Creates the shop's windows: the help, the shop's name, the money, buy and sell, and the cursor.
Definition shop.c:8
void STITSHOP_runShop(ItemShop *shop, ItemShopWindows *win)
Opens the shop's panels, then up/down and cross pick buy or sell and run that dialog,...
Definition shop.c:60
void STITSHOP_loadFiles(void)
Loads the shop's textures and requests its strings.
Definition shop.c:224
#define PAD_CROSS
Definition pad.h:31
#define PAD_DOWN
Definition pad.h:24
#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
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...
ItemShopFuncs STITSHOP_funcs
The shop's helpers.
Definition stitshop.c:228
s32 STITSHOP_shopNames[]
The shops' names, by ItemShop.shop.
Definition stitshop.c:27
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
s32(* isLoading)(s32 file)
Definition file.h:88
void(* request)(s32 file)
Definition file.h:90
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s32(* getModeArg)()
Definition game_state.h:20
void(* requestMode)(s32 mode, s32 arg)
Definition game_state.h:21
s32 fieldMode
where the menu returns to
Definition game_state.h:503
GameFuncs funcs
Definition game_state.h:582
void(* loadFiles)(void)
Definition item_shop.h:226
s32(* updateFade)(PanelAnim *fade)
Definition item_shop.h:229
void(* startFade)(PanelAnim *fade, s32 fadeIn)
Definition item_shop.h:228
s32(* filesLoading)(void)
Definition item_shop.h:227
The children of the shop.
Definition item_shop.h:36
TextWindow * buy
Definition item_shop.h:41
Task * dialog
ShopBuy or ShopSell.
Definition item_shop.h:44
TextWindow * moneyLabel
Definition item_shop.h:40
TextWindow * money
Definition item_shop.h:39
Cursor * cursor
Definition item_shop.h:43
TextWindow * title
the shop's name
Definition item_shop.h:37
TextWindow * sell
Definition item_shop.h:42
ScreenFade * fade
Definition item_shop.h:45
TextWindow * help
Definition item_shop.h:38
The main task of the shop (STITSHOP_createShop)
Definition item_shop.h:23
s32 bgScroll
Definition item_shop.h:27
s32 shop
the game mode's argument
Definition item_shop.h:29
PanelAnim panels[4]
Definition item_shop.h:31
s32 choice
Definition item_shop.h:30
void(* showMoney)(struct ItemShop *shop)
Definition item_shop.h:32
void(* nextState)(struct ItemShop *task)
Definition item_shop.h:24
s32 state
Definition item_shop.h:24
s32 substate
Definition item_shop.h:24
void(* setSubstate)(struct ItemShop *task, s32 substate)
Definition item_shop.h:24
s32 bgTick
Definition item_shop.h:28
s32 step
Definition item_shop.h:24
void * children
Definition item_shop.h:24
s32 layer
Definition item_shop.h:25
s32 level
Definition menu.h:21
s32 duration
Definition menu.h:19
void(* start)(struct ScreenFade *fade, s32 fadeIn, s32 frames)
TASK_DONE when done.
Definition gfx.h:368
s32 state
Definition gfx.h:362
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(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setTexture)()
(x, y)
Definition gfx.h:242
Any task, seen through its header.
Definition task.h:62
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
Uploads TIM images to VRAM (initTimLoader); acts on TIM_LOADER.
Definition gfx.h:325
void(* setImagePos)()
(x, y)
Definition gfx.h:336
void(* loadArchive)()
(archive): each image 64 halfwords to the right
Definition gfx.h:338
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
TextWindow * createTextWindow(s16 layerId, s16 style, s16 x, s16 y)
A text window on a layer, in a font style, at (x, y)
void initTimLoader(TimLoader *obj)
Clears a TIM loader, gives it its methods and binds it.
Definition tim_loader.c:119
ShopSell * STITSHOP_createSell(ItemShop *shop)
Creates the selling dialog (task), when sell is chosen in the shop.
Definition trade.c:1206
ShopBuy * STITSHOP_createBuy(ItemShop *shop)
Creates the buying dialog (task), when buy is chosen in the shop.
Definition trade.c:683