Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
windows.c
Go to the documentation of this file.
1/* CARDGAME's screen background, numbers, gauges and windows. */
2
4
5/* Draws the scrolling background, which fades in through its palettes (fadeState
6 1) and then stays */
8 SpriteDrawer drawer;
9 s32 row;
10 s32 x;
11
12 initSpriteDrawer(&drawer);
13 drawer.setLayerId(0x100, 2);
14 row = 0;
15 drawer.setTexture(0x340, 0);
16 switch (screen->fadeState) {
17 case 1:
18 if (screen->fadeTime >= 4) {
19 screen->fadeTime -= 4;
20 if (++screen->fadeRow >= 11) {
21 screen->fadeRow = 11;
22 screen->fadeState = 2;
23 }
24 }
25 row = screen->fadeRow;
26 screen->fadeTime += GFX.funcs.getFrameTime();
27 break;
28 case 2:
29 row = 11;
30 break;
31 case 0:
32 break;
33 }
34 drawer.setClutRow(row);
35 x = (screen->time >> 1) & 0x3F;
36 drawer.draw(FILE_CACHE.getEntry(FILE_CARDGAME_TIMS << 16 | 3), 0, x, x);
37}
38
39/* Draws a number with the TIM archive's digits, seven pixels apart, without
40 leading zeros unless asked; scaled about its pivot when scaled */
41void CARDGAME_drawNumber(CardNumber *number, s32 scaled) {
42 SpriteDrawer drawer;
43 s32 value;
44 s32 digit;
45 s32 i;
46
47 initSpriteDrawer(&drawer);
48 drawer.setLayerId(0x100, number->depth);
49 drawer.setTexture(0x340, 0);
50 if (scaled != 0) {
51 drawer.setPivot(number->pivotX, number->pivotY);
52 drawer.setScale(number->scaleX, number->scaleY, 0x1000);
53 }
54 value = number->value;
55 for (i = 0; i < number->digits; i++) {
56 digit = value % 10;
57 if (i == 0 || number->leadingZeros != 0 || digit != 0 || value / 10 != 0) {
58 drawer.draw(FILE_CACHE.getEntry(FILE_CARDGAME_TIMS << 16 | 3), digit + 0x14,
59 number->x + (number->digits - 1 - i) * 7, number->y);
60 }
61 value /= 10;
62 }
63}
64
65/* Draws a gauge at its place (CARDGAME_gaugePositions), at its scale */
66void CARDGAME_drawGauge(CardScreen *screen, CardScreenItems *items, s32 index, CardGauge *p) {
67 SpriteDrawer drawer;
68
69 initSpriteDrawer(&drawer);
70 drawer.setLayerId(0x100, 1);
71 drawer.setTexture(0x340, 0);
72 drawer.setPivot(CARDGAME_gaugePositions[index].x + 4, CARDGAME_gaugePositions[index].y + 23);
73 drawer.setScale(0x1000, p->to, 0x1000);
75}
76
77/* Grows (state 1), holds (2) or shrinks (3) a gauge, and draws it */
79 if (p->state != 0) {
80 switch (p->state) {
81 case 1:
82 default:
83 p->to = 0x1000 - (p->time << 12) / p->duration;
84 p->time -= GFX.funcs.getFrameTime();
85 if (p->time <= 0) {
86 p->state = 2;
87 }
88 break;
89 case 2:
90 p->to = 0x1000;
91 break;
92 case 3:
93 p->time -= GFX.funcs.getFrameTime();
94 if (p->time <= 0) {
95 p->state = 0;
96 }
97 p->to = (p->time << 12) / p->duration;
98 break;
99 }
100 CARDGAME_drawGauge(screen, items, index, p);
101 }
102}
103
104/* Runs and draws the three gauges */
106 s32 i;
107
108 for (i = 0; i < 3; i++) {
109 CARDGAME_updateGauge(screen, items, i, &screen->gauges[i]);
110 }
111}
112
113/* Draws the number in a type 3 window: its low four bits, and the sprite
114 for its high bits */
115static inline void drawWindowCount(CardWindow *window) {
116 CardNumber number;
117 SpriteDrawer digits;
118
119 number.depth = 1;
120 number.digits = 2;
121 number.leadingZeros = 0;
122 number.x = window->x + 0x18;
123 number.y = window->y + 4;
124 number.value = window->value & 0xF;
125 number.pivotX = window->x + CARDGAME_windowLayouts[window->layout].x;
126 number.pivotY = window->y + CARDGAME_windowLayouts[window->layout].y;
127 number.scaleX = window->from;
128 number.scaleY = 0x1000;
129 CARDGAME_drawNumber(&number, 1);
130 initSpriteDrawer(&digits);
131 digits.setLayerId(0x100, 1);
132 digits.setTexture(0x280, 0);
133 digits.setPivot(window->x + CARDGAME_windowLayouts[window->layout].x,
134 window->y + CARDGAME_windowLayouts[window->layout].y);
135 digits.setScale(window->from, 0x1000, 0x1000);
136 digits.draw(FILE_CACHE.getEntry(FILE_CARDGAME_TIMS << 16 | 2), (window->value >> 4) * 3 + 0x1D,
137 window->x + 6, window->y + 2);
138}
139
140/* Draws a window's frame (CARDGAME_windowLayouts), scaled while it opens, and
141 its count */
143 s32 offset = 0;
144
145 if (window->layout == 2 && window->numbers[2] == 1) {
146 offset = 0x45;
147 }
148 if (window->state == 2 && window->layout == 3 && window->showCount != 0) {
149 drawWindowCount(window);
150 }
151 {
152 SpriteDrawer frame;
153
154 if (CARDGAME_windowLayouts[window->layout].kind == 2) {
155 initSpriteDrawer(&frame);
156 frame.setLayerId(0x100, 1);
157 frame.setTexture(0x340, 0);
158 if (window->from != 0x1000) {
159 frame.setPivot(window->x + CARDGAME_windowLayouts[window->layout].x,
160 window->y + CARDGAME_windowLayouts[window->layout].y);
161 frame.setScale(window->from, 0x1000, 0x1000);
162 }
164 window->x + offset, window->y);
165 } else {
166 initSpriteDrawer(&frame);
167 frame.setLayerId(0x100, 1);
168 frame.setTexture(0x280, 0);
169 if (window->from != 0x1000) {
170 frame.setPivot(window->x + CARDGAME_windowLayouts[window->layout].x,
171 window->y + CARDGAME_windowLayouts[window->layout].y);
172 frame.setScale(window->from, 0x1000, 0x1000);
173 }
175 window->x + offset, window->y);
176 }
177 }
178}
179
180/* Puts a window's two numbers (numbers) on its texts, right aligned */
182 s32 values[2];
183 s32 i;
184
185 values[0] = window->numbers[0];
186 values[1] = window->numbers[1];
187 for (i = 0; i < 2; i++) {
188 items->texts[i]->setPos(items->texts[i], window->x + 0x67, window->y + 4 + i * 13);
189 items->texts[i]->setNumber(items->texts[i], 0, values[i]);
190 items->texts[i]->setRightAlign(items->texts[i], 1);
191 }
192}
193
194/* Puts a window's string value of file on text, or hides text when it has
195 none */
196void CARDGAME_drawWindowText(CardScreen *screen, CardWindow *window, TextWindow *text, s32 file, s32 index) {
197 if (window->value != 0) {
198 text->setPos(text, window->x + CARDGAME_windowTextOffsets[index], window->y + 4);
199 text->setString(text, FILE_CACHE.load(file), window->value);
200 } else {
201 text->setVisible(text, 0);
202 }
203}
204
205/* Puts a window's string value of file on text, centred on the screen (string
206 0x1F in palette 3), or hides text */
208 TextTools tools;
209 s32 width;
210
211 if (window->value != 0) {
212 text->setString(text, FILE_CACHE.load(file), window->value);
213 initTextTools(&tools);
214 width = tools.measure(text->text, text->style, text->spacingX);
215 if (window->value == 0x1F) {
216 text->setPalette(text, PALETTE_YELLOW);
217 } else {
218 text->setPalette(text, PALETTE_WHITE);
219 }
220 text->setVisible(text, 1);
221 text->setPos(text, 0xA0 - width / 2, window->y + 4);
222 } else {
223 text->setVisible(text, 0);
224 }
225}
226
227/* Opens (state 1), shows (2) or closes (3) window index, each its own way */
228void CARDGAME_updateWindow(CardScreen *screen, CardScreenItems *items, CardWindow *window, s32 index) {
229 if (window->state == 0) {
230 return;
231 }
232 switch (window->state) {
233 case 1:
234 default:
235 window->from = 0x1000 - (window->time << 12) / window->duration;
236 window->time -= GFX.funcs.getFrameTime();
237 if (window->time <= 0) {
238 window->state = 2;
239 switch (index) {
240 case 0:
241 CARDGAME_drawWindowText(screen, window, items->moreTexts[2], TEXT_FILE(TEXT_CARD_GAME), 1);
242 break;
243 case 2:
244 CARDGAME_drawWindowText(screen, window, items->moreTexts[4], TEXT_FILE(TEXT_CARD_NAMES), 0);
245 break;
246 case 3:
247 CARDGAME_drawWindowText(screen, window, items->moreTexts[3], TEXT_FILE(TEXT_CARD_GAME), 0);
248 break;
249 case 5:
250 if (window->layout == 5) {
251 CARDGAME_drawCenteredText(screen, items, window, items->moreTexts[0], TEXT_FILE(TEXT_CARD_GAME));
252 } else {
253 CARDGAME_drawWindowText(screen, window, items->moreTexts[0], TEXT_FILE(TEXT_CARD_GAME), window->value != 0x24);
254 }
255 break;
256 case 1:
257 case 4:
258 break;
259 }
260 }
261 break;
262 case 2:
263 window->from = 0x1000;
264 switch (index) {
265 case 2:
266 CARDGAME_drawWindowText(screen, window, items->moreTexts[4], TEXT_FILE(TEXT_CARD_NAMES), 0);
267 break;
268 case 3:
269 CARDGAME_drawWindowText(screen, window, items->moreTexts[3], TEXT_FILE(TEXT_CARD_GAME), 0);
270 break;
271 case 4:
272 if (window->value == 0x1F4) {
273 if (window->numbers[2] == 0) {
274 window->value = 0x2A;
275 CARDGAME_drawWindowText(screen, window, items->moreTexts[5], TEXT_FILE(TEXT_CARD_GAME), 1);
276 } else {
277 window->value = 0x40;
278 CARDGAME_drawWindowNumbers(screen, items, window);
279 CARDGAME_drawWindowText(screen, window, items->moreTexts[5], TEXT_FILE(TEXT_CARD_GAME), 2);
280 }
281 } else {
282 items->texts[0]->setVisible(items->texts[0], 0);
283 items->texts[1]->setVisible(items->texts[1], 0);
284 CARDGAME_drawWindowText(screen, window, items->moreTexts[5], TEXT_FILE(TEXT_CARD_EFFECTS), 0);
285 }
286 break;
287 }
288 break;
289 case 3:
290 switch (index) {
291 case 0:
292 items->moreTexts[2]->setVisible(items->moreTexts[2], 0);
293 break;
294 case 2:
295 items->moreTexts[4]->setVisible(items->moreTexts[4], 0);
296 break;
297 case 3:
298 items->moreTexts[3]->setVisible(items->moreTexts[3], 0);
299 break;
300 case 4:
301 items->texts[0]->setVisible(items->texts[0], 0);
302 items->texts[1]->setVisible(items->texts[1], 0);
303 items->moreTexts[5]->setVisible(items->moreTexts[5], 0);
304 break;
305 case 5:
306 items->moreTexts[0]->setVisible(items->moreTexts[0], 0);
307 break;
308 case 1:
309 break;
310 }
311 window->time -= GFX.funcs.getFrameTime();
312 if (window->time <= 0) {
313 window->state = 0;
314 }
315 window->from = (window->time << 12) / window->duration;
316 break;
317 }
318 CARDGAME_drawWindowFrame(screen, items, window);
319}
320
321/* Runs and draws the six windows */
323 s32 i;
324
325 for (i = 0; i < 6; i++) {
326 CARDGAME_updateWindow(screen, items, &screen->windows[i], i);
327 }
328}
CARDGAME.PRO: the card battle (mode 0x700).
u16 CARDGAME_windowTextOffsets[]
a window's text x, by CARDGAME_drawWindowText's index
Definition cardgame_3.c:27
CardOffset CARDGAME_gaugePositions[]
where the three CardGauge gauges are
Definition cardgame_3.c:20
CardWindowLayout CARDGAME_windowLayouts[]
Definition cardgame_3.c:23
signed int s32
Definition common.h:11
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
#define TEXT_CARD_GAME
CARDGM: the card battle's.
Definition file.h:202
#define TEXT_CARD_NAMES
CARDNM.
Definition file.h:203
#define TEXT_CARD_EFFECTS
CARDST.
Definition file.h:204
#define TEXT_FILE(file)
Definition file.h:190
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
#define FILE_CARDGAME_TIMS
CARDGAME's own pictures, a TIM archive.
Definition screen.h:15
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
A value that goes from from to to (0x1000 is 1) over duration frames.
Definition screen.h:222
s16 state
Definition screen.h:227
s16 time
Definition screen.h:225
s16 value
Definition screen.h:228
s16 duration
Definition screen.h:226
s16 to
Definition screen.h:224
A number drawn with the TIM archive's digits (CARDGAME_drawNumber)
Definition screen.h:73
s16 x
Definition screen.h:75
u8 leadingZeros
Definition screen.h:82
s16 pivotX
Definition screen.h:79
s16 scaleX
Definition screen.h:77
u8 digits
Definition screen.h:81
s16 y
Definition screen.h:76
s16 value
Definition screen.h:74
s16 scaleY
Definition screen.h:78
u8 depth
Definition screen.h:83
s16 pivotY
Definition screen.h:80
s16 x
Definition screen.h:60
s16 y
Definition screen.h:61
The battle screen's task items.
Definition screen.h:87
TextWindow * moreTexts[8]
Definition screen.h:91
TextWindow * texts[3]
Definition screen.h:89
The battle screen (created by CARDGAME_createScreen): the two panels, the cards on the table and the ...
Definition screen.h:263
u8 fadeRow
the background's palette row, 0 to 11
Definition screen.h:282
u32 time
Definition screen.h:267
CardGauge gauges[3]
Definition screen.h:273
u8 fadeTime
four frames a row
Definition screen.h:283
CardWindow windows[6]
Definition screen.h:281
u8 fadeState
0 dark, 1 fading in, 2 shown
Definition screen.h:284
u8 kind
2: a sprite of the fourth TIM, else of the third
Definition screen.h:69
s16 x
its pivot, from the window's corner
Definition screen.h:66
A window that opens (its scale goes from from to to)
Definition screen.h:232
s16 time
Definition screen.h:237
s16 duration
Definition screen.h:238
u8 numbers[3]
two numbers, and whether they are shown
Definition screen.h:242
s16 from
Definition screen.h:235
s16 showCount
Definition screen.h:240
s32 value
by its layout: a string, a card, or points | colour << 4
Definition screen.h:241
s16 layout
in CARDGAME_windowLayouts
Definition screen.h:239
void *(* load)(u32 file)
Definition file.h:92
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s32(* getFrameTime)(void)
Definition gfx.h:32
GfxFuncs funcs
Definition gfx.h:77
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
Text helpers (initTextTools)
Definition text.h:93
s32(* measure)()
(TextBuffer *, style, spacing)
Definition text.h:95
A text window (createTextWindow): up to six text buffers (0 is shown, 1-5 are "work" buffers that con...
Definition text.h:131
void(* setPalette)(struct TextWindow *obj, u8 arg)
Definition text.h:174
TextBuffer text[6]
Definition text.h:136
void(* setRightAlign)()
no prototype: callers would truncate u8 args
Definition text.h:178
void(* setNumber)()
Definition text.h:166
void(* setPos)(struct TextWindow *obj, s16 x, s16 y)
Definition text.h:173
void(* setString)()
Definition text.h:165
s16 spacingX
Definition text.h:145
struct TextStyle * style
Definition text.h:133
void(* setVisible)(struct TextWindow *obj, u8 arg)
Definition text.h:177
#define PALETTE_WHITE
The text windows' palettes (TextWindow.palette, setPalette): rows of the font's CLUTs,...
Definition text.h:112
#define PALETTE_YELLOW
Definition text.h:115
void initTextTools(TextTools *obj)
Clears a text tools object, gives it its methods and binds it.
Definition text_tools.c:193
void CARDGAME_drawWindowNumbers(CardScreen *screen, CardScreenItems *items, CardWindow *window)
Puts a window's two numbers (numbers) on its texts, right aligned.
Definition windows.c:181
void CARDGAME_drawCenteredText(CardScreen *screen, CardScreenItems *items, CardWindow *window, TextWindow *text, s32 file)
Puts a window's string value of file on text, centred on the screen (string 0x1F in palette 3),...
Definition windows.c:207
void CARDGAME_drawWindowFrame(CardScreen *screen, CardScreenItems *items, CardWindow *window)
Draws a window's frame (CARDGAME_windowLayouts), scaled while it opens, and its count.
Definition windows.c:142
void CARDGAME_updateWindows(CardScreen *screen, CardScreenItems *items)
Runs and draws the six windows.
Definition windows.c:322
void CARDGAME_drawNumber(CardNumber *number, s32 scaled)
Draws a number with the TIM archive's digits, seven pixels apart, without leading zeros unless asked;...
Definition windows.c:41
void CARDGAME_drawBackground(CardScreen *screen)
Draws the scrolling background, which fades in through its palettes (fadeState 1) and then stays.
Definition windows.c:7
static void drawWindowCount(CardWindow *window)
Draws the number in a type 3 window: its low four bits, and the sprite for its high bits.
Definition windows.c:115
void CARDGAME_updateGauges(CardScreen *screen, CardScreenItems *items)
Runs and draws the three gauges.
Definition windows.c:105
void CARDGAME_updateGauge(CardScreen *screen, CardScreenItems *items, s32 index, CardGauge *p)
Grows (state 1), holds (2) or shrinks (3) a gauge, and draws it.
Definition windows.c:78
void CARDGAME_drawWindowText(CardScreen *screen, CardWindow *window, TextWindow *text, s32 file, s32 index)
Puts a window's string value of file on text, or hides text when it has none.
Definition windows.c:196
void CARDGAME_drawGauge(CardScreen *screen, CardScreenItems *items, s32 index, CardGauge *p)
Draws a gauge at its place (CARDGAME_gaugePositions), at its scale.
Definition windows.c:66
void CARDGAME_updateWindow(CardScreen *screen, CardScreenItems *items, CardWindow *window, s32 index)
Opens (state 1), shows (2) or closes (3) window index, each its own way.
Definition windows.c:228