Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
menu_moves.c
Go to the documentation of this file.
1#include "battle/battle.h"
2#include "hud_element.h"
3
4#define MENU_CAPACITY 24
5#define MENU_LINE_HEIGHT 13
6#define MENU_MAX_VISIBLE 6
7
8enum {
9 BTL_SUBMENU_STATE_CANCEL = -2, // selection is canceled
10 BTL_SUBMENU_STATE_SELECT = -1, // a result is selected
11 BTL_SUBMENU_STATE_INIT = 0, // build and initialize the menu
12 BTL_SUBMENU_STATE_CHOOSING = 1, // selecting an option
13 BTL_SUBMENU_STATE_HIDE_INIT = 10, // begin hiding the menu, will quickly change to HIDE_HOLD
15 BTL_SUBMENU_STATE_RESTORE = 20, // reappear and resume choosing
20};
21
25
30
41
44
46BSS s32 MovesPrevSelected; // index of previously selected option, set by caller before initializing the menu
47
48// menu options are sorted before being displayed (according to priority and fp/bp cost)
49// the arrays for option data are NOT sorted, so we use this to look up display order indices --> data array indices
51
66
69BSS s8 MovesVisibleStart; // index of the first visible option (inclusive)
70BSS s8 MovesVisibleEnd; // index one past the last visible option (exclusive)
75
77BSS s8 MovesErrorTimer; // how much time is left for showing an error message
78
81
84
85s16 ErrorMessageHeight[] = { 28, 40 };
87
88void btl_menu_moves_draw_content(void* data, s32 x, s32 y);
89void btl_menu_moves_show_title(void* data, s32 x, s32 y);
90void btl_menu_moves_show_icon(void* data, s32 x, s32 y);
91void btl_menu_moves_show_desc(void* data, s32 x, s32 y);
92void btl_menu_moves_show_error(void* data, s32 x, s32 y);
93
133
137
166
206
245
246// reopen submenu in a locked/selected state
247// sets state to LOCK; next update switches to SELECT (grayed out and non-interactive)
248// use this when the menu should be visibile, but in the background of another menu
253
256 s32 x, y;
257 s32 msgWidth;
258 s32 msgHeight;
259 s32 msgX;
260 s32 msgID;
261 s32 cond;
263 s32 i;
264 s32 j;
265
266 switch (MovesMenuState) {
270 MovesMenuPosX = 20;
271 MovesMenuPosY = 68;
272
273 for (i = 0; i < MovesOptionCount; i++) {
274 MovesOptionIndexMap[i] = i;
275 }
276
277 if (!UsingSpiritsSubmenu) {
278 for (i = 0; i < (MovesOptionCount - 1); i++) {
279 for (j = i + 1; j < MovesOptionCount; j++) {
282
284 continue;
285 }
286
287 if (
292 )
293 {
297 }
298 }
299 }
300 }
301
302 for (i = 0; i < MovesOptionCount; i++) {
304 MovesOptionHIDs[i] = hid;
307 }
308
313
318
323
324 if (!UsingSpiritsSubmenu) {
328 } else {
333 }
335
336 for (i = 0; i < MovesOptionCount; i++) {
337 if (!UsingSpiritsSubmenu) {
338 switch (MovesOptionDiscountColors[i]) {
339 case 0:
342 break;
343 case 1:
346 break;
347 default:
350 break;
351 }
352 } else {
353 switch (MovesOptionDiscountColors[i]) {
354 case 0:
357 break;
358 case 1:
361 break;
362 default:
365 break;
366 }
367 }
370 }
371
373 x = MovesMenuPosX;
374 y = MovesMenuPosY;
375 if (!UsingSpiritsSubmenu) {
379 } else {
382 set_window_properties(WIN_BTL_SPIRITS_ICON, x + 110, y - 12, 32, 35, 1, btl_menu_moves_show_icon, 0, -1);
383 }
384
387 if (!UsingSpiritsSubmenu) {
390 } else {
393 }
395
396 do {
397 cond = FALSE;
402 if (MovesVisibleStart < 0) {
404 }
405 } else {
406 cond = TRUE;
407 }
408 }
409 } while (cond);
410
415 break;
418
419 // only wrap selection on stick press, not when held
420 if (battleStatus->curButtonsHeld & (BUTTON_STICK_UP | BUTTON_Z)) {
421 if (MovesCursorPos > 0) {
423 } else if (battleStatus->curButtonsPressed & (BUTTON_STICK_UP | BUTTON_Z)) {
425 }
426 }
427
428 if (battleStatus->curButtonsHeld & (BUTTON_STICK_DOWN | BUTTON_R)) {
431 } else if (battleStatus->curButtonsPressed & (BUTTON_STICK_DOWN | BUTTON_R)) {
433 }
434 }
435
436 // wrap the selected index
437 if (MovesCursorPos < 0) {
439 }
441 MovesCursorPos = 0;
442 }
443
447 }
448
451 if (MovesVisibleStart < 0) {
453 }
454 }
455
456 if (MovesCursorPos >= (MovesVisibleEnd - 1)) {
460 if (MovesVisibleStart < 0) {
462 }
463 }
464 }
465
467 if (battleStatus->curButtonsPressed & BUTTON_A) {
471 } else {
475 }
476 break;
477 }
478
479 if (battleStatus->curButtonsPressed & BUTTON_B) {
483 }
484 break;
486 for (i = 0; i < MovesOptionCount; i++) {
487 hid = MovesOptionHIDs[i];
488 hud_element_set_tint(hid, 160, 160, 160);
489 }
493 hud_element_set_tint(HID_MovesTitle, 160, 160, 160);
494
495 for (i = 0; i < MovesOptionCount; i++) {
497 hud_element_set_tint(hid, 160, 160, 160);
498 }
499
503 if (!UsingSpiritsSubmenu) {
506 } else {
509 }
511 if (!UsingSpiritsSubmenu) {
513 } else {
515 }
519 if (!UsingSpiritsSubmenu) {
521 } else {
523 }
524 return POPUP_RESULT_CANCEL;
527 if (!UsingSpiritsSubmenu) {
530 } else {
533 }
535 if (!UsingSpiritsSubmenu) {
537 } else {
539 }
548 if (!UsingSpiritsSubmenu) {
551 } else {
554 }
561 if (!UsingSpiritsSubmenu) {
564 } else {
567 }
570 break;
577 if (!UsingSpiritsSubmenu) {
580 } else {
583 }
585
586 if (MovesErrorCode != 0) {
588 } else if (UsingSpiritsSubmenu) {
590 } else {
591 msgID = MSG_Menus_NotEnoughFP;
592 }
593
594 msgWidth = get_msg_width(msgID, 0) + 23;
595 msgHeight = ErrorMessageHeight[get_msg_lines(msgID) - 1];
596 x = (SCREEN_WIDTH / 2) - (msgWidth / 2);
597 set_window_properties(WIN_BTL_POPUP, x, 80, msgWidth, msgHeight, 20, btl_menu_moves_show_error, NULL, -1);
599 MovesErrorTimer = 60;
604 MovesErrorTimer = 0;
605 }
606 if (MovesErrorTimer != 0) {
609 }
612 if (!UsingSpiritsSubmenu) {
615 } else {
618 }
621 break;
622 }
624}
625
626#if VERSION_IQUE
627#define Y_VAR1 2
628#define X_VAR1 104
629#define X_VAR2 89
630#else
631#define Y_VAR1 0
632#define X_VAR1 108
633#define X_VAR2 93
634#endif
635
636void btl_menu_moves_draw_content(void* data, s32 x, s32 y) {
637 s32 target, cur, delta;
638 s32 x1, y1, x2, y2;
639 s32 xPos, yPos;
641 s32 palette;
642 s32 hid;
643 s32 index;
644 s32 i;
645
646 switch (MovesMenuState) {
654 // simple midpoint easing, move half the distance each frame
657 delta = (target - cur) * 0.5;
658 MovesScrollOffset = (delta != 0) ? cur + delta : target;
659
660 x1 = x + 2;
661 x2 = x + 153;
662 y1 = y + 18;
663 y2 = y + 19 + (MovesMenuLines * MENU_LINE_HEIGHT);
665
666 xPos = x + 31;
667 yPos = y + 19 + MovesScrollOffset;
668
669 for (i = 0; i < MovesOptionCount; i++) {
670 // find the array index for current list display index
671 index = MovesOptionIndexMap[i];
672
673 if (i >= MovesVisibleStart - 1 && MovesVisibleStart + MovesMenuLines >= i) {
674 palette = MovesTextColor;
675
676 if (MovesOptionEnabled[index] <= 0) {
677 palette = MSG_PAL_0B;
678 }
679
680 if (MovesOptionNames[index] >= 0) {
681 draw_msg(
683 );
684 }
685
688
689 if (baseCost != 0 && cost <= 0) {
690 cost = 1;
691 }
692
693 if (UsingSpiritsSubmenu ) {
694 if (i == MovesCursorPos) {
695 if (cost == 0 || MovesOptionEnabled[index] <= 0) {
697 } else {
699 }
700 }
701 } else {
702 if (i == MovesCursorPos) {
703 if (cost == 0 || MovesOptionEnabled[index] <= 0) {
705 } else {
707 }
708 }
709 }
710
711 switch (MovesOptionDiscountColors[i]) {
712 case 0:
713 palette = MSG_PAL_STANDARD;
714 break;
715 case 1:
716 palette = MSG_PAL_37;
717 break;
718 default:
719 palette = MSG_PAL_38;
720 break;
721 }
722
723 if (MovesOptionEnabled[index] <= 0) {
724 palette = MSG_PAL_0B;
725 }
726
727 if (MovesOptionDisplayCosts[index] != 0) {
729
734 );
735 if (MovesOptionEnabled[index] <= 0) {
737 }
739 } else {
743 );
744 if (MovesOptionEnabled[index] <= 0) {
746 }
748 }
751 }
752 }
754 }
755
756 // draw option icons
757 xPos = x + 24;
758 yPos = y + 24 + MovesScrollOffset;
759
760 for (i = 0; i < MovesOptionCount; i++) {
761 if (i < MovesVisibleStart - 1) {
763 } else if (MovesVisibleStart + MovesMenuLines < i) {
765 } else {
766 hid = MovesOptionHIDs[i];
771 }
772 }
773
774 // instant snap to target, no easing
777 delta = (target - cur) * 1.0;
778 MovesCursorOffset = (delta != 0) ? cur + delta : target;
779
780 // draw the cursor
781 xPos = x + 10;
782 yPos = y + 26 + MovesCursorOffset;
783
788
789 // draw nav arrows
790 if (MovesVisibleStart > 0) {
792 hud_element_set_render_pos(hid, x + 72, y + 15);
795 }
798 hud_element_set_render_pos(hid, x + 72, y + 100);
801 }
802
804 if (!UsingSpiritsSubmenu) {
806 } else {
808 }
809 }
810 break;
811 }
812}
813
814void btl_menu_moves_show_title(void* data, s32 x, s32 y) {
815 s32 msgID;
816 s32 posX;
817 s32 posY;
818 s32 opacity;
819 s32 palette;
820
821 if (!UsingSpiritsSubmenu) {
822 msgID = MSG_Menus_Abilities;
823 posX = x + 16;
824 posY = y + 2;
825 opacity = MovesTextAlpha;
826 palette = MSG_PAL_30;
827 } else {
828 msgID = MSG_Menus_StarSpirits;
829 posX = x + 6;
830 posY = y + 2;
831 opacity = MovesTextAlpha;
832 palette = MSG_PAL_31;
833 }
834 draw_msg(msgID, posX, posY, opacity, palette, DRAW_MSG_STYLE_MENU);
835}
836
844
859
860void btl_menu_moves_show_error(void* data, s32 posX, s32 posY) {
861 s32 msgID;
862
863 posX += 11;
864 posY += 6;
865 posY += ErrorMessageAdjustY[get_msg_lines(msgID) - 1];
866
867 if (MovesErrorCode != 0) {
869 } else if (UsingSpiritsSubmenu) {
871 } else {
872 msgID = MSG_Menus_NotEnoughFP;
873 }
874 draw_msg(msgID, posX, posY, 255, MSG_PAL_0F, 0);
875}
BSS s32 PopupMenu_SelectedIndex
u32 pressedButtons[4]
s32 HudElemID
s32 b32
s8 b8
s32 MsgID
#define get_msg_width
#define draw_msg
@ DRAW_MSG_STYLE_MENU
Definition enums.h:4970
@ DRAW_NUMBER_STYLE_ALIGN_RIGHT
drawn to the left of posX
Definition enums.h:4978
@ DRAW_NUMBER_STYLE_MONOSPACE
Definition enums.h:4979
@ BUTTON_A
Definition enums.h:2776
@ BUTTON_R
Definition enums.h:2767
@ BUTTON_STICK_UP
Definition enums.h:2777
@ BUTTON_STICK_DOWN
Definition enums.h:2778
@ BUTTON_B
Definition enums.h:2775
@ BUTTON_Z
Definition enums.h:2774
@ WINDOW_PRIORITY_20
Definition enums.h:3220
@ MSG_PAL_38
Definition enums.h:5046
@ MSG_PAL_37
Definition enums.h:5045
@ MSG_PAL_0F
Definition enums.h:5005
@ MSG_PAL_0D
Definition enums.h:5003
@ MSG_PAL_STANDARD
Definition enums.h:5000
@ MSG_PAL_0B
Definition enums.h:5001
@ MSG_PAL_30
Definition enums.h:5038
@ MSG_PAL_31
Definition enums.h:5039
@ WINDOW_UPDATE_SHOW
Definition enums.h:4896
@ WINDOW_UPDATE_TRANSPARENT
Definition enums.h:4900
@ WINDOW_UPDATE_9
Definition enums.h:4904
@ WINDOW_UPDATE_HIDE
Definition enums.h:4897
@ WINDOW_UPDATE_DARKENED
Definition enums.h:4899
@ DRAW_NUMBER_CHARSET_THIN
Definition enums.h:4986
@ POPUP_RESULT_CANCEL
Definition enums.h:3212
@ POPUP_RESULT_CHOOSING
Definition enums.h:3211
@ POPUP_RESULT_INVALID
Definition enums.h:3209
@ SOUND_MENU_BACK
Definition enums.h:704
@ SOUND_MENU_CHANGE_SELECTION
Definition enums.h:701
@ SOUND_MENU_NEXT
Definition enums.h:703
@ SOUND_MENU_ERROR
Definition enums.h:936
@ WIN_BTL_MOVES_ICON
Definition enums.h:4829
@ WIN_BTL_SPIRITS_TITLE
Definition enums.h:4830
@ WIN_BTL_MOVES_MENU
Definition enums.h:4827
@ WIN_BTL_POPUP
Definition enums.h:4835
@ WIN_BTL_MOVES_TITLE
Definition enums.h:4828
@ WIN_BTL_SPIRITS_ICON
Definition enums.h:4831
@ WIN_BTL_DESC_BOX
Definition enums.h:4834
void set_window_update(s32 panelID, s32)
Definition windows.c:434
void status_bar_start_blinking_fp(void)
Definition inventory.c:1563
void status_bar_stop_blinking_sp(void)
Definition inventory.c:1619
void status_bar_stop_blinking_fp(void)
Definition inventory.c:1576
void set_window_properties(s32 panelID, s32 posX, s32 posY, s32 width, s32 height, u8, void *drawContents, void *drawContentsArg, s8 parent)
Definition windows.c:373
void draw_number(s32 value, s32 x, s32 y, s32 variableWidthChars, s32 palette, s32 opacity, u16 style)
Definition msg.c:2229
s32 get_msg_lines(s32 messageID)
Definition msg.c:1985
void status_bar_start_blinking_sp_bars(s32 numBarsToBlink)
Definition inventory.c:1628
HudScript HES_AnimatedHandPointer
void hud_element_set_scale(s32 index, f32 scale)
void hud_element_set_alpha(s32 id, s32 opacity)
void hud_element_draw_without_clipping(s32 id)
void hud_element_set_script(s32 id, HudScript *anim)
void hud_element_set_tint(s32 id, s32 r, s32 g, s32 b)
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_draw_clipped(s32 id)
void hud_element_free(s32 id)
@ HUD_ELEMENT_FLAG_DROP_SHADOW
Definition hud_element.h:97
@ HUD_ELEMENT_FLAG_MANUAL_RENDER
Definition hud_element.h:78
@ HUD_ELEMENT_FLAG_FILTER_TEX
Definition hud_element.h:86
s32 HudScript[]
Definition hud_element.h:9
BSS s32 MovesOptionDiscountColors[24]
Definition menu_moves.c:59
HudScript HES_POWCostReducedTwice
@ BTL_SUBMENU_STATE_RESTORE
Definition menu_moves.c:15
@ BTL_SUBMENU_STATE_LOCK
Definition menu_moves.c:16
@ BTL_SUBMENU_STATE_HIDE_HOLD
Definition menu_moves.c:14
@ BTL_SUBMENU_STATE_CANCEL
Definition menu_moves.c:9
@ BTL_SUBMENU_STATE_SELECT
Definition menu_moves.c:10
@ BTL_SUBMENU_STATE_ERROR_DONE
Definition menu_moves.c:19
@ BTL_SUBMENU_STATE_HIDE_INIT
Definition menu_moves.c:13
@ BTL_SUBMENU_STATE_ERROR_SHOW
Definition menu_moves.c:18
@ BTL_SUBMENU_STATE_CHOOSING
Definition menu_moves.c:12
@ BTL_SUBMENU_STATE_INIT
Definition menu_moves.c:11
@ BTL_SUBMENU_STATE_ERROR_INIT
Definition menu_moves.c:17
void btl_menu_moves_show_error(void *data, s32 x, s32 y)
Definition menu_moves.c:860
HudScript HES_FPCostReducedTwice
BSS s32 MovesOptionCount
Definition menu_moves.c:65
HudScript HES_HandPointer
BSS HudElemID HID_MovesTitle
Definition menu_moves.c:29
BSS MsgID MovesOptionDesc[24]
Definition menu_moves.c:56
void btl_submenu_moves_restore_locked(void)
Definition menu_moves.c:249
BSS s16 MovesMenuPosY
Definition menu_moves.c:43
BSS HudElemID MovesOptionCostHIDs[24]
Definition menu_moves.c:54
void btl_submenu_moves_resume_choose(void)
Definition menu_moves.c:167
BSS s16 MovesTextAlpha
Definition menu_moves.c:80
s32 btl_submenu_moves_update(void)
Definition menu_moves.c:254
void btl_menu_moves_show_desc(void *data, s32 x, s32 y)
Definition menu_moves.c:845
BSS s8 MovesOptionSortPriority[24]
Definition menu_moves.c:63
BSS s32 MovesOptionIndices[24]
Definition menu_moves.c:61
void btl_menu_moves_show_title(void *data, s32 x, s32 y)
Definition menu_moves.c:814
BSS s32 MovesOptionEnabled[24]
Definition menu_moves.c:62
#define Y_VAR1
Definition menu_moves.c:631
void btl_submenu_moves_destroy(void)
Definition menu_moves.c:138
BSS s32 MovesOptionBPCosts[24]
Definition menu_moves.c:60
HudScript HES_NotEnoughFP
HudScript HES_GreenArrowDown
#define X_VAR2
Definition menu_moves.c:633
BSS HudElemID HID_MovesCursor
Definition menu_moves.c:28
BSS HudElemID HID_MovesArrowUp
Definition menu_moves.c:26
#define MENU_LINE_HEIGHT
Definition menu_moves.c:5
BSS s32 MovesOptionDiscounts[24]
Definition menu_moves.c:58
BSS s16 MovesMenuPosX
Definition menu_moves.c:42
HudScript HES_GreenArrowUp
BSS s16 MovesScrollOffset
Definition menu_moves.c:73
BSS s8 MovesPrevCursorPos
Definition menu_moves.c:68
BSS s32 MovesOptionIndexMap[24]
Definition menu_moves.c:50
BSS s16 MovesCursorOffset
Definition menu_moves.c:74
s16 ErrorMessageAdjustY[]
Definition menu_moves.c:86
void btl_submenu_moves_restore_choose(void)
Definition menu_moves.c:207
BSS HudElemID MovesOptionHIDs[24]
Definition menu_moves.c:53
s16 ErrorMessageHeight[]
Definition menu_moves.c:85
HudScript HES_FPCost
void btl_submenu_moves_hide(void)
Definition menu_moves.c:134
BSS HudScript * MovesOptionHudScripts[24]
Definition menu_moves.c:52
void btl_menu_moves_draw_content(void *data, s32 x, s32 y)
Definition menu_moves.c:636
BSS HudElemID HID_MovesArrowDown
Definition menu_moves.c:27
HudScript HES_NotEnoughPOW
BSS s8 MovesCursorPos
Definition menu_moves.c:67
BSS s8 MovesErrorTimer
Definition menu_moves.c:77
#define X_VAR1
Definition menu_moves.c:632
BSS b32 UsingSpiritsSubmenu
Definition menu_moves.c:82
BSS b8 MovesDescVisible
Definition menu_moves.c:72
BSS s8 MovesMenuState
Definition menu_moves.c:45
void btl_submenu_moves_init(void)
Definition menu_moves.c:94
HudScript HES_POWCostReduced
#define MENU_CAPACITY
Definition menu_moves.c:4
BSS s8 MovesMenuLines
Definition menu_moves.c:71
BSS s32 MovesOptionDisplayCosts[24]
Definition menu_moves.c:57
BSS s8 MovesOptionError[24]
Definition menu_moves.c:64
BSS s8 MovesVisibleEnd
Definition menu_moves.c:70
BSS s16 MovesTextColor
Definition menu_moves.c:79
BSS s32 SelectedMovesIndex
Definition menu_moves.c:83
HudScript HES_POWCost
void btl_menu_moves_show_icon(void *data, s32 x, s32 y)
Definition menu_moves.c:837
HudScript HES_FPCostReduced
BSS s32 MovesErrorCode
Definition menu_moves.c:76
BSS s8 MovesVisibleStart
Definition menu_moves.c:69
HudScript HES_StatusFlower
#define MENU_MAX_VISIBLE
Definition menu_moves.c:6
BSS MsgID MovesOptionNames[24]
Definition menu_moves.c:55
HudScript HES_MenuStarPower
BSS s32 MovesPrevSelected
Definition menu_moves.c:46
void sfx_play_sound(s32 soundID)
#define SCREEN_WIDTH
Definition macros.h:109
#define BSS
Definition macros.h:7
GameStatus * gGameStatusPtr
Definition main_loop.c:31
Gfx * gMainGfxPos
Definition cam_main.c:14
BattleStatus gBattleStatus
Definition battle.cpp:14