Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
panel.c
Go to the documentation of this file.
1/* The panel that fills up while a card operation runs */
2
3#include "menus/memory_card.h"
4
5/* Empties the panel and stops it (panel->reset) */
7 panel->substate = 0;
8 panel->duration = 0;
9 panel->rate = 0;
10 panel->done = 0;
11 panel->scale.vx = 0;
12 panel->scale.vz = ONE;
13 panel->scale.vy = ONE;
14 panel->pivotX = panel->x;
15 panel->pivotY = panel->y;
16}
17
18/* Starts the panel (panel->start): substate 1 opens it to 95% over `duration` frames
19 while a card operation runs, 2 opens it fully and sets done */
20void STGMCARD_startPanel(MemCardPanel *panel, s32 substate, s32 duration) {
21 panel->substate = substate;
22 panel->duration = duration;
23 panel->rate = 0;
24}
25
26/* Sets the color of the panel's gradient at its top (panel->setTopColor) */
28 panel->top.r = r;
29 panel->top.g = g;
30 panel->top.b = b;
31 panel->top.cd = 0;
32}
33
34/* Sets the color of the panel's gradient at its bottom (panel->setBottomColor) */
36 panel->bottom.r = r;
37 panel->bottom.g = g;
38 panel->bottom.b = b;
39 panel->bottom.cd = 0;
40}
41
42/* Moves the panel (panel->setPos) */
44 panel->x = x;
45 panel->y = y;
46}
47
48/* The panel's task: opens it by scaling it horizontally, then draws it as a
49 gradient with a sprite */
51 SVECTOR out[4];
52 SVECTOR in[4];
53 SpriteDrawer sprite;
54 Layer *layer;
55 u_long *ot;
56 POLY_G4 *poly;
57 s32 i;
58
59 switch (panel->state) {
60 case TASK_INIT:
61 default:
62 panel->nextState(panel);
64 break;
65 case TASK_RUN:
66 if (panel->duration == 0) {
67 break;
68 }
69 switch (panel->substate) {
70 case 0:
71 default:
72 return;
73 case 1:
74 if (panel->rate == 0) {
75 panel->rate = ONE / panel->duration;
76 }
77 panel->scale.vx += panel->rate;
78 if (panel->scale.vx > 0xF33) {
79 panel->scale.vx = 0xF33;
80 }
81 break;
82 case 2:
83 if (panel->rate == 0) {
84 panel->rate = ONE / panel->duration;
85 }
86 panel->scale.vx += panel->rate;
87 if (panel->scale.vx > ONE) {
88 panel->scale.vx = ONE;
89 panel->done = 1;
90 }
91 break;
92 }
93 if (panel->scale.vx == 0) {
94 break;
95 }
96 layer = GFX.funcs.getLayer(panel->layer);
97 ot = layer->getOtEntry(layer, panel->depth);
98 RotMatrixYXZ_gte(&panel->rot, &panel->matrix);
99 ScaleMatrix(&panel->matrix, &panel->scale);
100 poly = GFX.funcs.getPrim();
101 setlen(poly, 8);
102 poly->code = 0x38;
103 poly->r0 = panel->top.r;
104 poly->g0 = panel->top.g;
105 poly->b0 = panel->top.b;
106 poly->r1 = panel->bottom.r;
107 poly->g1 = panel->bottom.g;
108 poly->b1 = panel->bottom.b;
109 poly->r2 = panel->top.r;
110 poly->g2 = panel->top.g;
111 poly->b2 = panel->top.b;
112 poly->r3 = panel->bottom.r;
113 poly->g3 = panel->bottom.g;
114 poly->b3 = panel->bottom.b;
115 in[0].vx = in[2].vx = panel->x - panel->pivotX;
116 in[1].vx = in[3].vx = in[0].vx + panel->w;
117 in[0].vy = in[1].vy = panel->y - panel->pivotY;
118 in[2].vy = in[3].vy = in[0].vy + panel->h;
119 in[0].vz = in[1].vz = in[2].vz = in[3].vz = 0;
120 for (i = 0; i < 4; i++) {
121 ApplyMatrixSV(&panel->matrix, &in[i], &out[i]);
122 out[i].vx += panel->pivotX;
123 out[i].vy += panel->pivotY;
124 }
125 poly->x0 = out[0].vx;
126 poly->y0 = out[0].vy;
127 poly->x1 = out[1].vx;
128 poly->y1 = out[1].vy;
129 poly->x2 = out[2].vx;
130 poly->y2 = out[2].vy;
131 poly->x3 = out[3].vx;
132 poly->y3 = out[2].vy; /* the same as out[3].vy unless the panel is rotated */
133 addPrim(ot, poly);
134 GFX.funcs.setPrim(poly + 1);
135 initSpriteDrawer(&sprite);
136 sprite.setLayerId(panel->layer, panel->depth);
137 sprite.setTexture(0x280, 0);
138 sprite.draw(FILE_CACHE.getEntry(FILE_GMCARD_SHEET << 16), 38, 204, 192);
139 break;
140 case TASK_DONE:
141 case TASK_KILL:
142 break;
143 }
144}
145
146/* Creates a gradient panel (task) at x, y, w by h, empty until started */
149
150 panel->reset = STGMCARD_resetPanel;
151 panel->start = STGMCARD_startPanel;
155 panel->layer = SCREEN_LAYER;
156 panel->depth = 1;
157 panel->x = x;
158 panel->y = y;
159 panel->w = w;
160 panel->h = h;
161 return panel;
162}
signed int s32
Definition common.h:11
unsigned char u8
Definition common.h:8
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
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
STGMCARD.PRO: the memory card screen (MODE_CONTINUE).
#define FILE_GMCARD_SHEET
Definition memory_card.h:19
MemCardPanel * STGMCARD_createPanel(s32 x, s32 y, s32 w, s32 h)
Creates a gradient panel (task) at x, y, w by h, empty until started.
Definition panel.c:147
void STGMCARD_setPanelBottomColor(MemCardPanel *panel, u8 r, u8 g, u8 b)
Sets the color of the panel's gradient at its bottom (panel->setBottomColor)
Definition panel.c:35
void STGMCARD_updatePanel(MemCardPanel *panel)
The panel's task: opens it by scaling it horizontally, then draws it as a gradient with a sprite.
Definition panel.c:50
void STGMCARD_setPanelPos(MemCardPanel *panel, s32 x, s32 y)
Moves the panel (panel->setPos)
Definition panel.c:43
void STGMCARD_setPanelTopColor(MemCardPanel *panel, u8 r, u8 g, u8 b)
Sets the color of the panel's gradient at its top (panel->setTopColor)
Definition panel.c:27
void STGMCARD_resetPanel(MemCardPanel *panel)
Empties the panel and stops it (panel->reset)
Definition panel.c:6
void STGMCARD_startPanel(MemCardPanel *panel, s32 substate, s32 duration)
Starts the panel (panel->start): substate 1 opens it to 95% over duration frames while a card operati...
Definition panel.c:20
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
void *(* getPrim)(void)
Definition gfx.h:19
struct Layer *(* getLayer)(s32 id)
Definition gfx.h:28
void(* setPrim)(void *next)
Definition gfx.h:20
GfxFuncs funcs
Definition gfx.h:77
A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering tables,...
Definition gfx.h:128
u_long *(* getOtEntry)(struct Layer *, s32 depth)
Definition gfx.h:155
A gradient panel that opens by scaling (STGMCARD_updatePanel)
void(* nextState)(struct MemCardPanel *task)
void(* setPos)(struct MemCardPanel *panel, s32 x, s32 y)
void(* setBottomColor)(struct MemCardPanel *panel, u8 r, u8 g, u8 b)
void(* start)(struct MemCardPanel *panel, s32 substate, s32 duration)
s32 rate
ONE / duration.
void(* reset)(struct MemCardPanel *panel)
void(* setTopColor)(struct MemCardPanel *panel, u8 r, u8 g, u8 b)
CVECTOR bottom
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(* 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
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105