Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
message_box.c
Go to the documentation of this file.
1#include "engine/game.h"
2
3/* Draws the two halves of a message box's panel, growing, still or fading */
5 SpriteDrawer obj;
6 s32 i;
7 s32 x;
8 FileCache *cache;
9
10 i = 0;
11 cache = &FILE_CACHE;
12 x = 0;
13 for (; i < 2; i++) {
14 initSpriteDrawer(&obj);
15 obj.setLayerId(task->layerId, 0);
16 obj.setTexture(0x140, 0);
17 if (task->substate == 0) {
18 obj.setScale(task->scale, ONE, ONE);
19 obj.setPivot(0x140 - x, 0xC4);
20 } else if (task->substate == 2) {
21 obj.setClutRow(task->fadeRow);
22 }
23 obj.draw(cache->getEntry(FILE_MENU_SPRITES << 16), i + 8, 0, 0xA6);
24 x += 0x140;
25 }
26}
27
28/* Draws a message box's blinking "next" arrow */
30 SpriteDrawer obj;
31
32 initSpriteDrawer(&obj);
33 obj.setLayerId(task->layerId, 0);
34 obj.setTexture(0x140, 0);
35 if (GFX.funcs.getTime() - task->arrowTime >= 4) {
36 task->arrowTime = GFX.funcs.getTime();
37 if (++task->arrowFrame >= 5) {
38 task->arrowFrame = 0;
39 }
40 }
41 obj.setClutRow(task->arrowFrame);
42 obj.draw(FILE_CACHE.getEntry(FILE_MENU_SPRITES << 16), 10, 0x124, 0xCD);
43}
44
45/* The message box frame task: grows, waits with the arrow when asked, then fades out and ends */
47 switch (task->state) {
48 case 0:
49 default:
50 task->nextState(task);
51 task->scaleStep = 0x199;
52 break;
53 case 1:
54 switch (task->substate) {
55 case 0:
56 default:
57 task->scale += task->scaleStep;
58 if (task->scale > ONE) {
59 task->scale = ONE;
60 task->nextSubstate(task);
61 }
62 break;
63 case 1:
64 if (task->showArrow != 0) {
66 }
67 break;
68 case 2:
69 if (GFX.funcs.getTime() - task->time >= 3) {
70 task->time = GFX.funcs.getTime();
71 if (++task->fadeRow >= 5) {
72 task->setState(task, TASK_KILL);
73 return;
74 }
75 }
76 break;
77 }
79 break;
80 case 2:
81 case 3:
82 break;
83 }
84}
85
86/* A message box frame on a layer, with the menu sound */
89
90 task->layerId = layerId;
92 return task;
93}
94
95/* The message box task: shows the text once the frame is open, closes when the text ends */
96void updateMessageBox(Task *task, MessageBox *data) {
97 switch (task->state) {
98 case 0:
99 default:
100 task->nextState(task);
101 break;
102 case 1:
103 switch (task->substate) {
104 case 0:
105 default:
106 if (data->window->isVisible(data->window) == 0 && data->frame->substate == 1) {
107 data->window->setVisible(data->window, 1);
108 task->substate++;
109 }
110 break;
111 case 1:
112 if (data->window->isFinished(data->window) != 0) {
113 data->frame->substate = 2;
114 data->window->setVisible(data->window, 0);
115 task->substate++;
117 break;
118 }
119 if (PAD_PRESSED(PAD_CROSS)) {
120 data->window->showPage(data->window);
121 }
122 if (data->window->isWaitingForButton(data->window) != 0) {
123 data->frame->showArrow = 1;
124 } else {
125 data->frame->showArrow = 0;
126 }
127 break;
128 case 2:
129 if (data->frame == NULL) {
130 task->setState(task, TASK_KILL);
131 }
132 break;
133 }
134 break;
135 case 2:
136 case 3:
137 break;
138 }
139}
140
141/* A message box with string `index` of a table, typed out in three-line pages */
142Task *createMessageBox(s32 layerId, void *strings, s32 index) {
143 Task *task = createTask(updateMessageBox, sizeof(Task), sizeof(MessageBox));
144 MessageBox *data = task->children;
145
146 data->window = createTextWindow(layerId, 1, 0x12, 0xB0);
147 data->window->setLines(data->window, 3);
148 data->window->setString(data->window, strings, index);
149 data->window->setVisible(data->window, 0);
150 data->window->setTypeDelay(data->window, 6);
151 data->frame = createMessageBoxFrame(layerId);
152 return task;
153}
#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
#define TASK_KILL
Definition task.h:37
#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
void updateMessageBoxFrame(MessageBoxFrame *task)
The message box frame task: grows, waits with the arrow when asked, then fades out and ends.
Definition message_box.c:46
void drawMessageBoxFrame(MessageBoxFrame *task)
Draws the two halves of a message box's panel, growing, still or fading.
Definition message_box.c:4
MessageBoxFrame * createMessageBoxFrame(s32 layerId)
A message box frame on a layer, with the menu sound.
Definition message_box.c:87
Task * createMessageBox(s32 layerId, void *strings, s32 index)
A message box with string index of a table, typed out in three-line pages.
void updateMessageBox(Task *task, MessageBox *data)
The message box task: shows the text once the frame is open, closes when the text ends.
Definition message_box.c:96
void drawMessageBoxArrow(MessageBoxFrame *task)
Draws a message box's blinking "next" arrow.
Definition message_box.c:29
#define PAD_CROSS
Definition pad.h:31
#define PAD_PRESSED(button)
One button of pad 1: newly pressed, auto-repeated while held, or held.
Definition pad.h:140
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_CLOSE
SYSTEM04.
Definition sound.h:42
#define SOUND_MENU_OPEN
SYSTEM03.
Definition sound.h:41
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
The file cache (FILE_CACHE): up to 64 files loaded in the heap (tag 3), read in the background one at...
Definition file.h:85
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
The frame of a message box: two halves of the bottom panel that grow from the sides (substate 0),...
Definition text.h:46
s32 fadeRow
Definition text.h:50
s32 arrowFrame
Definition text.h:53
s32 arrowTime
Definition text.h:52
void(* nextState)(struct MessageBoxFrame *task)
Definition text.h:47
s32 substate
Definition text.h:47
s32 layerId
Definition text.h:48
s16 scaleStep
Definition text.h:55
s32 showArrow
Definition text.h:51
void(* nextSubstate)(struct MessageBoxFrame *task)
Definition text.h:47
void(* setState)(struct MessageBoxFrame *task, s32 state)
Definition text.h:47
The children of a message box (createMessageBox)
Definition text.h:264
struct TextWindow * window
Definition text.h:265
struct MessageBoxFrame * frame
Definition text.h:266
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
Any task, seen through its header.
Definition task.h:62
void(* setState)(struct Task *task, s32 state)
Definition task.h:63
s32 substate
Definition task.h:63
void(* nextState)(struct Task *task)
Definition task.h:63
s32 state
Definition task.h:63
void * children
Definition task.h:63
s32(* isWaitingForButton)()
Definition text.h:188
s32(* isFinished)()
s32: callers don't truncate the result to a byte
Definition text.h:186
s32(* isVisible)()
s32: callers don't truncate the result to a byte
Definition text.h:187
void(* setTypeDelay)()
Definition text.h:172
void(* setLines)()
no prototype: callers would truncate u8 args
Definition text.h:184
void(* setString)()
Definition text.h:165
void(* showPage)()
Definition text.h:170
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
TextWindow * createTextWindow(s16 layerId, s16 style, s16 x, s16 y)
A text window on a layer, in a font style, at (x, y)