Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
pause_map.c
Go to the documentation of this file.
1#include "pause_common.h"
2#include "message_ids.h"
3
4#if VERSION_PAL
5#define MAP_TITLE_X 36
6#define MAP_TITLE_WIDTH 220
7#else
8#define MAP_TITLE_X 56
9#define MAP_TITLE_WIDTH 180
10#endif
11
12extern Gfx PauseGfxWorldMap[];
13extern Gfx PauseGfxPathPoints[];
14extern Gfx PauseGfxArrows[];
15extern u8 pause_world_map_png[];
16
17void pause_map_draw_contents(MenuPanel* menu, s32 baseX, s32 baseY, s32 width, s32 height, s32 opacity, s32 darkening);
18void pause_map_draw_title(MenuPanel* menu, s32 baseX, s32 baseY, s32 width, s32 height, s32 opacity, s32 darkening);
19void pause_map_init(MenuPanel* tab);
23
24static HudElemID PauseMapHIDs[1];
25static f32 PauseMapCameraX;
26static f32 PauseMapCameraY;
27static s32 PauseMapMarioX;
28static s32 PauseMapMarioY;
29static f32 PauseMapTargetX;
30static f32 PauseMapTargetY;
31static s32 PauseMapCursorCurrentOption;
32static s32 PauseMapCursorCurrentOptionCopy;
33static s32 PauseMapSpacesInSnapRange;
34
36s32 D_8024FA34 = -1;
37
38#include "world_map.inc.c"
39
40s32 PauseMapArrowWobble[] = { 0, 2, 3, 3, 4, 4, 4, 4, 3, 2, 1, 0 };
42 {
44 .unk_01 = 0,
45 .pos = { .x = 3, .y = 16 },
46 .width = 289,
47 .height = 154,
48 .priority = WINDOW_PRIORITY_1,
49 .fpDrawContents = &pause_map_draw_contents,
50 .tab = NULL,
51 .parentID = WIN_PAUSE_MAIN,
52 .fpUpdate = { WINDOW_UPDATE_HIDE },
53 .extraFlags = 0,
54 .style = { .customStyle = &gPauseWS_26 }
55 },
56 {
57 .windowID = WIN_PAUSE_MAP_TITLE,
58 .unk_01 = 0,
59 .pos = { .x = MAP_TITLE_X, .y = 124 },
60 .width = MAP_TITLE_WIDTH,
61 .height = 20,
62 .priority = WINDOW_PRIORITY_0,
63 .fpDrawContents = &pause_map_draw_title,
64 .tab = NULL,
65 .parentID = WIN_PAUSE_MAP,
66 .fpUpdate = { WINDOW_UPDATE_SHOW },
67 .extraFlags = 0,
68 .style = { .customStyle = &gPauseWS_28 }
69 },
70 {},
71 {},
72 {},
73 {},
74 {}
75};
77 .initialized = FALSE,
78 .col = 0,
79 .row = 0,
80 .selected = 0,
81 .state = 0,
82 .numCols = 0,
83 .numRows = 0,
84 .numPages = 0,
85 .gridData = NULL,
86 .fpInit = &pause_map_init,
87 .fpHandleInput = &pause_map_handle_input,
88 .fpUpdate = &pause_map_update,
89 .fpCleanup = &pause_map_cleanup
90};
91
93 Vec2b* path = space->path;
94 s32 pathLength = space->pathLength;
95 s32 x1 = PauseMapSpaces[space->parent].pos.x;
96 s32 y1 = PauseMapSpaces[space->parent].pos.y;
97 s32 x2 = space->pos.x;
98 s32 y2 = space->pos.y;
99 s32 xThingPrev = 0;
100 s32 yThingPrev = 0;
101 s32 i;
102
103 for (i = 0; i < pathLength; i++) {
104 s32 xThing = ((x1 - x2) * (i + 1)) / (pathLength + 1);
105 s32 yThing = ((y1 - y2) * (i + 1)) / (pathLength + 1);
106
107 path[i].x = xThing - xThingPrev;
108 path[i].y = yThing - yThingPrev;
109 xThingPrev = xThing;
110 yThingPrev = yThing;
111 }
112}
113
114void pause_map_draw_border_arrows(s32 imageIndex, s32 x, s32 y) {
115 s32 size = 16;
116
117 switch (imageIndex) {
118 case 0:
119 pause_draw_rect(x * 4, y * 4, (x + size) * 4, (y + size) * 4, 0, 0, 0, 0x400, 0x400);
120 break;
121 case 1:
122 pause_draw_rect(x * 4, y * 4, (x + size) * 4, (y + size) * 4, 0, 0, 0x200, 0x400, 0x400);
123 break;
124 case 2:
125 pause_draw_rect(x * 4, y * 4, (x + size) * 4, (y + size) * 4, 0, 0, 0x400, 0x400, 0x400);
126 break;
127 default:
128 pause_draw_rect(x * 4, y * 4, (x + size) * 4, (y + size) * 4, 0, 0, 0x600, 0x400, 0x400);
129 break;
130 }
131}
132
133void pause_map_draw_contents(MenuPanel* menu, s32 baseX, s32 baseY, s32 width, s32 height, s32 opacity, s32 darkening) {
134 s32 cameraX = PauseMapCameraX;
135 s32 cameraY = PauseMapCameraY;
136 s32 i, j;
137 s32 tileHeight;
138 s32 x1, y1, x2, y2;
139 s32 x1a, y1a, x2a, y2a;
140 s32 posX, posY;
141 s32 ult;
142 PauseMapSpace* mapSpace;
143 s32 camX, camY;
144 s32 pathX, pathY;
145 s32 currentTab;
146 s32 offset, offsetLeft, offsetRight, offsetUp, offsetDown;
147 s32 mapULX, mapULY;
148 s32 bigPointX, bigPointY;
149 Vec2b* path;
150 s32 pathLength;
151
152 gSPDisplayList(gMainGfxPos++, PauseGfxWorldMap);
153 ult = -cameraX * 32;
154 for (i = 0; i < 60; i++) {
155 if (4 * i + 4 < 111) {
156 tileHeight = 4;
157 } else {
158 tileHeight = 111 - 4 * i;
159 }
160
161 gDPLoadTextureTile(gMainGfxPos++, pause_world_map_png, G_IM_FMT_CI, G_IM_SIZ_8b, 320, 320,
162 0, i * 4 - cameraY, 319, i * 4 + tileHeight - 1 - cameraY, 0,
163 G_TX_CLAMP, G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
164 pause_draw_rect((baseX + 26) * 4, (baseY + 22 + 4 * i) * 4, (baseX + 260) * 4,
165 (baseY + 22 + i * 4 + tileHeight) * 4, 0, ult, (-cameraY + i * 4) * 32, 0x400, 0x400);
166 gDPPipeSync(gMainGfxPos++);
167
168 if (4 * i + 4 >= 110) {
169 break;
170 }
171 }
172
173 gSPDisplayList(gMainGfxPos++, PauseGfxPathPoints);
174
175 x1 = baseX + 26;
176 y1 = baseY + 22;
177 x2 = baseX + 260;
178 y2 = baseY + 132;
179
180 if (x1 <= 0) {
181 x1 = 1;
182 }
183 if (y1 <= 0) {
184 y1 = 1;
185 }
186
187 if (x2 <= 0 || y2 <= 0 || x1 >= SCREEN_WIDTH - 1 || y1 >= SCREEN_HEIGHT - 1) {
188 return;
189 }
190
191 if (x2 >= SCREEN_WIDTH - 1) {
192 x2 = SCREEN_WIDTH - 1;
193 }
194 if (y2 >= SCREEN_HEIGHT - 1) {
195 y2 = SCREEN_HEIGHT - 1;
196 }
197
198 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, x1, y1, x2, y2);
199
200 mapSpace = PauseMapSpaces;
201 camX = cameraX + baseX;
202 camY = cameraY + baseY;
203 for (i = 0; i < ARRAY_COUNT(PauseMapSpaces); i++, mapSpace++) {
204 posX = mapSpace->pos.x;
205 posY = mapSpace->pos.y;
206
207 if (evt_get_variable(NULL, GF_MAP_ToadTown + i) == 0) {
208 continue;
209 }
210
211 if (i != PauseMapCursorCurrentOption) {
212 gDPSetPrimColor(gMainGfxPos++, 0, 0, 220, 80, 30, 255);
213 } else {
214 gDPSetPrimColor(gMainGfxPos++, 0, 0, (gGameStatusPtr->frameCounter * 10) % 120 + 120,
215 (gGameStatusPtr->frameCounter * 10) % 120 + 120,
216 (gGameStatusPtr->frameCounter * 10) % 120, 255);
217 }
218
219 bigPointX = camX + 26 + posX;
220 bigPointY = camY + 22 + posY;
221 pause_draw_rect((bigPointX - 8) * 4, (bigPointY - 8) * 4, (bigPointX + 8) * 4, (bigPointY + 8) * 4, 0, 0, 0, 0x400, 0x400);
222 gDPPipeSync(gMainGfxPos++);
223 gDPSetPrimColor(gMainGfxPos++, 0, 0, 230, 190, 180, 255);
224
225 pathLength = mapSpace->pathLength;
226 path = mapSpace->path;
227 if (path) {
228 pathX = 0;
229 pathY = 0;
230 for (j = 0; j < pathLength; j++, path++) {
231 pathX += path->x;
232 pathY += path->y;
233 pause_draw_rect((camX + 26 + posX + pathX - 8) * 4, (camY + 22 + posY + pathY - 8) * 4, (camX + 26 + posX + pathX + 8) * 4, (camY + 22 + posY + pathY + 8) * 4, 1, 0, 0, 0x400, 0x400);
234 }
235 }
236 }
237
238 mapULX = baseX + 26 + cameraX;
239 mapULY = baseY + 22 + cameraY;
240 hud_element_set_render_pos(PauseMapHIDs[0], mapULX + PauseMapMarioX, mapULY + PauseMapMarioY - 7);
241 hud_element_draw_without_clipping(PauseMapHIDs[0]);
242
243 currentTab = gPauseMenuCurrentTab;
244 if (currentTab == 6) {
245 pause_set_cursor_pos(WIN_PAUSE_MAP, mapULX + PauseMapTargetX - 8.0f, mapULY + PauseMapTargetY);
246
247 if (gPauseMenuCurrentTab == currentTab) {
249 offsetLeft = offset;
250 offsetRight = offset;
251 offsetUp = offset;
252 offsetDown = offset;
253
254 gSPDisplayList(gMainGfxPos++, PauseGfxArrows);
255
256 if (!(PauseMapCameraX < 0.0f)) {
257 offsetLeft = 0;
258 }
259 pause_map_draw_border_arrows(0, baseX + 26 - offsetLeft, baseY + height / 2 - 8);
260
261 if (!(PauseMapCameraX > -86.0f)) {
262 offsetRight = 0;
263 }
264 pause_map_draw_border_arrows(1, baseX + width - 50 + offsetRight, baseY + height / 2 - 8);
265
266 if (!(PauseMapCameraY < 0.0f)) {
267 offsetUp = 0;
268 }
269 pause_map_draw_border_arrows(2, baseX + width / 2 - 8, baseY + 24 - offsetUp);
270
271 if (!(PauseMapCameraY > -210.0f)) {
272 offsetDown = 0;
273 }
274 pause_map_draw_border_arrows(3, baseX + width / 2 - 8, baseY + height - 44 + offsetDown);
275 }
276 }
277 {
278 s32 x1, y1, x2, y2;
279
280 x1 = baseX + 18;
281 y1 = baseY + 14;
282 x2 = baseX + 268;
283 y2 = baseY + 140;
284
285 if (x1 <= 0) {
286 x1 = 1;
287 }
288 if (y1 <= 0) {
289 y1 = 1;
290 }
291
292 if (x2 <= 0 || y2 <= 0 || x1 >= SCREEN_WIDTH - 1 || y1 >= SCREEN_HEIGHT - 1) {
293 return;
294 }
295
296 if (x2 >= SCREEN_WIDTH - 1) {
297 x2 = SCREEN_WIDTH - 1;
298 }
299 if (y2 >= SCREEN_HEIGHT - 1) {
300 y2 = SCREEN_HEIGHT - 1;
301 }
302
303 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, x1, y1, x2, y2);
304 }
305 draw_box(0, &gPauseWS_27, baseX + 18, baseY + 14, 0, 250, 126, opacity, darkening, 1.0f, 1.0f, 0, 0, 0, 0, 0, 0, width, height, 0);
306}
307
308void pause_map_draw_title(MenuPanel* menu, s32 baseX, s32 baseY, s32 width, s32 height, s32 opacity, s32 darkening) {
309 s32 msgWidth;
310 s32 msgID;
311
312 if (gPauseMenuCurrentTab == 6) {
313 if (PauseMapCursorCurrentOption != -1) {
314 msgWidth = get_msg_width(MSG_Menus_00F2 + (PauseMapCursorCurrentOption * 3), 0);
315 msgID = MSG_Menus_00F2 + (PauseMapCursorCurrentOption * 3);
316 draw_msg(msgID, baseX + ((width - msgWidth) >> 1), baseY + 1, 255, MSG_PAL_WHITE, 0);
317 }
318 }
319}
320
322 s32 currentLocation;
323 s32 i;
324
325 for (i = 0; i < ARRAY_COUNT(PauseMapHudScripts); i++) {
326 PauseMapHIDs[i] = hud_element_create(PauseMapHudScripts[i]);
328 }
329
330 for (i = 0; i < ARRAY_COUNT(PauseMapWindowBPs); i++) {
331 PauseMapWindowBPs[i].tab = tab;
332 }
333
335 PauseMapCursorCurrentOption = -1;
336 PauseMapSpacesInSnapRange = 0;
337 PauseMapCursorCurrentOptionCopy = -1;
338 currentLocation = evt_get_variable(0, GB_WorldLocation);
339
340 for (i = 0; i < ARRAY_COUNT(PauseMapSpaces); i++) {
341 if (PauseMapSpaces[i].id == currentLocation) {
342 break;
343 }
344 }
345
346 if (i < ARRAY_COUNT(PauseMapSpaces)) {
347 PauseMapMarioX = PauseMapSpaces[i].pos.x;
348 PauseMapMarioY = PauseMapSpaces[i].pos.y;
349 } else {
350 PauseMapMarioX = 0;
351 PauseMapMarioY = 0;
352 }
353 PauseMapTargetX = PauseMapMarioX;
354 PauseMapTargetY = PauseMapMarioY;
355
356 PauseMapCameraX = 0.0f;
357 PauseMapCameraY = 0.0f;
358 PauseMapCameraX -= (s32)(PauseMapTargetX + PauseMapCameraX - 117.0);
359 PauseMapCameraY -= (s32)(PauseMapTargetY + PauseMapCameraY - 55.0);
360
361 if (PauseMapCameraX > 0) {
362 PauseMapCameraX = 0;
363 }
364 if (PauseMapCameraY > 0) {
365 PauseMapCameraY = 0;
366 }
367
368 if (PauseMapCameraX <= -86.0f) {
369 PauseMapCameraX = -85.0f;
370 }
371 if (PauseMapCameraY <= -210.0f) {
372 PauseMapCameraY = -209.0f;
373 }
374
375 tab->initialized = TRUE;
376}
377
379 f32 xMovement = gGameStatusPtr->stickX[0] * 0.05f;
380 f32 yMovement = -gGameStatusPtr->stickY[0] * 0.05f;
381 f32 PauseMapTargetYPosTemp = PauseMapTargetY;
382 f32 PauseMapTargetXPosTemp = PauseMapTargetX;
383 s32 xTemp;
384 s32 yTemp;
385
386 if (xMovement == 0.0f && yMovement == 0.0f && PauseMapCursorCurrentOption != -1) {
387 PauseMapSpace* mapSpace = &PauseMapSpaces[PauseMapCursorCurrentOption];
388
389 xMovement = mapSpace->pos.x - PauseMapTargetXPosTemp;
390 yMovement = mapSpace->pos.y - PauseMapTargetYPosTemp;
391
392 xMovement *= 0.32;
393 yMovement *= 0.32;
394 }
395
396 PauseMapTargetX += xMovement;
397 PauseMapTargetY += yMovement;
398
399 if (PauseMapTargetX < 16.0f) {
400 PauseMapTargetX = 16.0f;
401 }
402
403 if (PauseMapTargetY < 8.0f) {
404 PauseMapTargetY = 8.0f;
405 }
406
407 if (PauseMapTargetX >= 316.0f) {
408 PauseMapTargetX = 315.0f;
409 }
410
411 if (PauseMapTargetY >= 308.0f) {
412 PauseMapTargetY = 307.0f;
413 }
414
415 xTemp = PauseMapTargetX + PauseMapCameraX - 117.0;
416 yTemp = PauseMapTargetY + PauseMapCameraY - 55.0;
417
418 if (xTemp >= 53.0) {
419 PauseMapCameraX -= xTemp - 53.0;
420 }
421
422 if (xTemp <= -37.0) {
423 PauseMapCameraX -= xTemp + 37.0;
424 }
425
426 if (yTemp >= 15.0) {
427 PauseMapCameraY -= yTemp - 15.0;
428 }
429
430 if (yTemp <= -15.0) {
431 PauseMapCameraY -= yTemp + 15.0;
432 }
433
434 if (PauseMapCameraX > 0.0f) {
435 PauseMapCameraX = 0.0f;
436 }
437
438 if (PauseMapCameraY > 0.0f) {
439 PauseMapCameraY = 0.0f;
440 }
441
442 if (PauseMapCameraX < -86.0f) {
443 PauseMapCameraX = -86.0f;
444 }
445
446 if (PauseMapCameraY < -210.0f) {
447 PauseMapCameraY = -210.0f;
448 }
449
453 return;
454 }
455
457 if (PauseMapCursorCurrentOption == -1) {
458 gPauseCurrentDescMsg = MSG_NONE;
459 return;
460 }
461
462 gPauseCurrentDescMsg = MSG_Menus_00F3 + (PauseMapCursorCurrentOption * 3);
463
464 // If the story has progressed enough, show the "after" description
465 if (evt_get_variable(0, GB_StoryProgress) >= PauseMapSpaces[PauseMapCursorCurrentOption].afterRequirement) {
467 }
468}
469
471 PauseMapSpace* mapSpace = &PauseMapSpaces[0];
472 f32 lowestSqSum = 10000.0f;
473 f32 cursorOption = -1.0f;
474 s32 i;
475
476 PauseMapCursorCurrentOption = -1;
477 PauseMapSpacesInSnapRange = 0;
478
479 for (i = 0; i < ARRAY_COUNT(PauseMapSpaces); i++, mapSpace++) {
480 if (evt_get_variable(0, GF_MAP_ToadTown + i) != 0) {
481 f32 deltaX = PauseMapTargetX - mapSpace->pos.x;
482 f32 deltaY = PauseMapTargetY - mapSpace->pos.y;
483 f32 sqSum = SQ(deltaX) + SQ(deltaY);
484
485 if (sqSum < 400.0f) {
486 PauseMapSpacesInSnapRange++;
487 }
488
489 if (sqSum < lowestSqSum && sqSum < 200.0f) {
490 lowestSqSum = sqSum;
491 cursorOption = i;
492 }
493 }
494 }
495
496 PauseMapCursorCurrentOption = cursorOption;
497 PauseMapCursorCurrentOptionCopy = cursorOption;
498}
499
501 s32 i;
502
503 for (i = 0; i < ARRAY_COUNT(PauseMapHIDs); i++) {
504 hud_element_free(PauseMapHIDs[i]);
505 }
506}
s32 HudElemID
#define get_msg_width
#define draw_msg
#define draw_box
@ BUTTON_B
Definition enums.h:2789
@ WINDOW_PRIORITY_1
Definition enums.h:3183
@ WINDOW_PRIORITY_0
Definition enums.h:3182
@ MSG_PAL_WHITE
Definition enums.h:5404
@ WINDOW_UPDATE_SHOW
Definition enums.h:5310
@ WINDOW_UPDATE_HIDE
Definition enums.h:5311
@ SOUND_MENU_BACK
Definition enums.h:701
@ WIN_PAUSE_MAP
Definition enums.h:5283
@ WIN_PAUSE_MAP_TITLE
Definition enums.h:5284
@ WIN_PAUSE_MAIN
Definition enums.h:5262
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1689
void setup_pause_menu_tab(MenuWindowBP *bpArray, s32 arraySize)
Definition windows.c:461
void hud_element_draw_without_clipping(s32 id)
void hud_element_set_render_pos(s32 id, s32 x, s32 y)
s32 hud_element_create(HudScript *anim)
Creates a new HUD element and returns its ID.
void hud_element_set_flags(s32 id, s32 flags)
Turns on the given flags.
void hud_element_free(s32 id)
@ HUD_ELEMENT_FLAG_80
Definition hud_element.h:78
s32 HudScript[]
Definition hud_element.h:9
HudScript HES_MapWalk0
s32 gPausePressedButtons
Definition pause_main.c:24
HudScript * gPauseCurrentDescIconScript
Definition pause_main.c:26
WindowStyleCustom gPauseWS_26
WindowStyleCustom gPauseWS_27
s8 gPauseMenuCurrentTab
Definition pause_main.c:28
void pause_set_cursor_pos(s32 windowID, s32 posX, s32 posY)
Definition pause_main.c:228
void pause_draw_rect(s32 ulx, s32 uly, s32 lrx, s32 lry, s32 tileIdx, s32 uls, s32 ult, s32 dsdx, s32 dtdy)
Definition pause_main.c:841
WindowStyleCustom gPauseWS_28
s32 gPauseCurrentDescMsg
Definition pause_main.c:25
#define MAP_TITLE_WIDTH
Definition pause_map.c:9
MenuPanel gPausePanelMap
Definition pause_map.c:76
#define MAP_TITLE_X
Definition pause_map.c:8
void pause_map_draw_border_arrows(s32 imageIndex, s32 x, s32 y)
Definition pause_map.c:114
HudScript * PauseMapHudScripts[]
Definition pause_map.c:35
void pause_map_update(MenuPanel *tab)
Definition pause_map.c:470
s32 PauseMapArrowWobble[]
Definition pause_map.c:40
void pause_map_handle_input(MenuPanel *tab)
Definition pause_map.c:378
Gfx PauseGfxArrows[]
Definition pause_gfx.c:246
Gfx PauseGfxPathPoints[]
Definition pause_gfx.c:226
void pause_map_calc_path_points(PauseMapSpace *space)
Definition pause_map.c:92
s32 D_8024FA34
Definition pause_map.c:36
void pause_map_draw_title(MenuPanel *menu, s32 baseX, s32 baseY, s32 width, s32 height, s32 opacity, s32 darkening)
Definition pause_map.c:308
void pause_map_init(MenuPanel *tab)
Definition pause_map.c:321
void pause_map_cleanup(MenuPanel *tab)
Definition pause_map.c:500
void pause_map_draw_contents(MenuPanel *menu, s32 baseX, s32 baseY, s32 width, s32 height, s32 opacity, s32 darkening)
Definition pause_map.c:133
MenuWindowBP PauseMapWindowBPs[]
Definition pause_map.c:41
Gfx PauseGfxWorldMap[]
Definition pause_gfx.c:208
u8 pause_world_map_png[]
void sfx_play_sound(s32 soundID)
Definition sfx.c:517
@ GB_WorldLocation
@ GB_StoryProgress
@ GF_MAP_ToadTown
#define SCREEN_WIDTH
Definition macros.h:109
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define SCREEN_HEIGHT
Definition macros.h:110
#define SQ(x)
Definition macros.h:170
MenuPanel * tab
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Gfx * gMainGfxPos
Definition cam_main.c:15