Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
cursor.c
Go to the documentation of this file.
1/* FIGHTSTG's menu cursor. */
2
4
5/* where FIGHTSTG_drawCursorBar puts the cursor's bar in VRAM */
6RECT FIGHTSTG_cursorBarRect = { 0, 0xF4, 12, 12 };
7
8/* The vsync callback while the list is open: draws the picked line's bar,
9 moving through its frames, and the bar off the line picked before when the
10 pick has changed, over the frame being drawn. The match depends on the task
11 coming as the callback's s32 argument, cast into a variable. */
13 MenuCursor *task = (MenuCursor *)arg;
14 u_long *saved;
15 s32 i;
16 s32 y;
17
18 saved = BreakDraw();
19 if (saved != (u_long *)-1) {
20 if (++task->frame == 12) {
21 task->frame = 0;
22 }
23 ClearOTag(FIGHTSTG_cursorBarOt, 2);
24 for (i = 0; i < 4; i += 2) {
25 if (i == 2 && task->prevSel == task->sel) {
26 break;
27 }
28 if (i < 2) {
29 FIGHTSTG_cursorBarRect.x = task->frame * 12;
30 y = task->params.y + task->sel * task->params.step;
31 } else {
33 y = task->params.y + task->prevSel * task->params.step;
34 }
35 SetDrawMove(&FIGHTSTG_cursorBarMoves[i], &FIGHTSTG_cursorBarRect, task->params.x, y);
37 SetDrawMove(&FIGHTSTG_cursorBarMoves[i + 1], &FIGHTSTG_cursorBarRect, task->params.x, y + 0x100);
39 }
40 while (IsIdleGPU(0)) {
41 }
42 ContinueDraw(FIGHTSTG_cursorBarOt, saved);
43 }
44 task->prevSel = task->sel;
45}
46
47/* Draws each line's sprite of the cursor, the picked one blinking through the
48 palettes and the one left fading out */
50 SpriteDrawer drawer;
51 void *sheet;
52 s32 i;
53 s32 y;
54 s32 row;
55
56 initSpriteDrawer(&drawer);
57 i = 0;
59 drawer.setTexture(0x200, i);
61 y = task->params.spriteY;
62 for (; i < task->params.count; i++) {
63 if (task->blink[i] != 0 || task->sel == i) {
64 task->blink[i] += GFX.funcs.getFrameTime();
65 if (task->blink[i] >= 0x14) {
66 if (task->sel != i) {
67 task->blink[i] = 0;
68 } else {
69 task->blink[i] -= 0x14;
70 }
71 }
72 }
73 row = task->blink[i] >> 2;
74 if (row >= 0 && row < 5) {
75 drawer.setClutRow(row);
76 } else {
77 drawer.setClutRow(0);
78 }
79 drawer.draw(sheet, task->params.sprite, task->params.spriteX, y);
80 y += task->params.spriteStep;
81 }
82}
83
84/* The menu cursor's task: sets FIGHTSTG_drawCursorBar as the vsync callback,
85 draws the lines' sprites and moves with up and down until locked; when
86 killed, takes the callback off */
88 s32 pressed;
89
90 switch (task->state) {
91 case TASK_INIT:
92 default:
93 task->nextState(task);
94 break;
95 case TASK_RUN:
96 switch (task->substate) {
97 case 2:
98 default:
100 GFX.vsyncArg = (s32)task;
101 /* fallthrough */
102 case 0:
103 case 1:
104 task->nextSubstate(task);
105 /* fallthrough */
106 case 3:
107 if (task->params.sprite != -1) {
109 }
110 if (task->locked == 0) {
111 pressed = PAD.getRepeated(0) | PAD.getPressed(0);
112 if (pressed & (1 << PAD_UP)) {
113 if (task->sel != 0) {
114 task->sel--;
116 }
117 } else if (pressed & (1 << PAD_DOWN)) {
118 if (task->sel != task->params.count - 1) {
119 task->sel++;
121 }
122 }
123 }
124 break;
125 }
126 break;
127 case TASK_DONE:
128 break;
129 case TASK_KILL:
131 break;
132 }
133}
134
135/* Creates a menu cursor laid out by layout */
138
139 task->params = *layout;
140 return task;
141}
RECT FIGHTSTG_cursorBarRect
where FIGHTSTG_drawCursorBar puts the cursor's bar in VRAM
Definition cursor.c:6
void FIGHTSTG_drawCursorBar(s32 arg)
The vsync callback while the list is open: draws the picked line's bar, moving through its frames,...
Definition cursor.c:12
void FIGHTSTG_updateCursor(MenuCursor *task)
The menu cursor's task: sets FIGHTSTG_drawCursorBar as the vsync callback, draws the lines' sprites a...
Definition cursor.c:87
void FIGHTSTG_drawCursorSprites(MenuCursor *task)
Draws each line's sprite of the cursor, the picked one blinking through the palettes and the one left...
Definition cursor.c:49
MenuCursor * FIGHTSTG_createCursor(CursorLayout *layout)
Creates a menu cursor laid out by layout.
Definition cursor.c:136
#define BATTLE_LAYER_MENUS
the HUD, the menus and the messages
Definition types.h:31
FIGHTSTG.PRO: the battle.
#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_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
#define FILE_BATTLE_MENU
The battle menu's files (WFIGHTMN, WFIGHTTS): FILE_BATTLE_IMAGES is an archive whose entries go throu...
Definition file.h:294
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
u_long FIGHTSTG_cursorBarOt[2]
and their ordering table
DR_MOVE FIGHTSTG_cursorBarMoves[4]
FIGHTSTG_drawCursorBar draws its bar with them.
PadState PAD
Controller input: cleared by initPad, then the methods.
Definition pad.c:168
#define PAD_DOWN
Definition pad.h:24
#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_MENU_MOVE
SYSTEM06.
Definition sound.h:43
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
A menu cursor's layout, which FIGHTSTG_createCursor copies into its task: a highlight bar over count ...
Definition menu.h:288
s32 step
Definition menu.h:292
s32 sprite
Definition menu.h:293
s32 spriteStep
Definition menu.h:296
s32 spriteY
Definition menu.h:295
s32 spriteX
Definition menu.h:294
s32 count
Definition menu.h:289
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s32(* getFrameTime)(void)
Definition gfx.h:32
void(* vsyncFunc)(s32 arg)
Definition gfx.h:61
GfxFuncs funcs
Definition gfx.h:77
s32 vsyncArg
Definition gfx.h:62
A menu cursor (FIGHTSTG_createCursor): up and down move it, its bar is drawn by FIGHTSTG_drawCursorBa...
Definition menu.h:302
s32 sel
Definition menu.h:304
void(* nextState)(struct MenuCursor *task)
Definition menu.h:303
s32 blink[6]
the time of each line's sprite
Definition menu.h:309
s32 substate
Definition menu.h:303
s32 locked
Definition menu.h:305
s32 frame
of the bar, 0-11
Definition menu.h:308
s32 state
Definition menu.h:303
CursorLayout params
Definition menu.h:306
void(* nextSubstate)(struct MenuCursor *task)
Definition menu.h:303
s32 prevSel
where the bar was drawn last
Definition menu.h:307
s32(* getRepeated)(s32 pad)
Definition pad.h:127
s32(* getPressed)(s32 pad)
Definition pad.h:125
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(* 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 * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105