Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
menus.c
Go to the documentation of this file.
1#include "common_structs.h"
2#include "hud_element.h"
3#include "world/partners.h"
4#include "macros.h"
5#include "common.h"
6#include "sprite.h"
7#include "game_modes.h"
9#include "world/partners.h"
11
20
26
34
35extern s32 MenuIndexFromPartnerID[];
36
38 PlayerStatus* playerStatus = &gPlayerStatus;
39
41 Npc* partner = get_npc_unsafe(NPC_PARTNER);
42
44 npc_set_imgfx_params(partner, IMGFX_SET_ALPHA, playerStatus->curAlpha, 0, 0, 0, 0);
45 playerStatus->prevAlpha = 0;
46 }
47}
48
50 PartnerStatus* partnerStatus = &gPartnerStatus;
51 PlayerStatus* playerStatus = &gPlayerStatus;
52 s32 actionState = playerStatus->actionState;
53
54 if (playerStatus->animFlags & PA_FLAG_CHANGING_MAP) {
55 return FALSE;
56 }
57
58 if (partnerStatus->partnerActionState == PARTNER_ACTION_NONE) {
59 if (!(playerStatus->flags & PS_FLAG_NO_STATIC_COLLISION) &&
60 (actionState == ACTION_STATE_IDLE || actionState == ACTION_STATE_WALK || actionState == ACTION_STATE_RUN))
61 {
62 return TRUE;
63 }
64 } else if (partner_can_open_world_menus()) {
65 if (partnerStatus->actingPartner == PARTNER_WATT) {
66 return TRUE;
67 } else if (partnerStatus->actingPartner == PARTNER_BOW) {
68 if (actionState == ACTION_STATE_RIDE) {
69 return TRUE;
70 }
71 } else if (partnerStatus->actingPartner == PARTNER_LAKILESTER) {
72 if (actionState == ACTION_STATE_RIDE) {
73 return TRUE;
74 }
76 }
77 }
78 return FALSE;
79}
80
81b32 can_open_world_menu(s32 currentButtons, s32 pressedButtons) {
82 PartnerStatus* partnerStatus = &gPartnerStatus;
83 s32 actionState = gPlayerStatus.actionState;
84
87 && !(currentButtons & (BUTTON_Z | BUTTON_R))
88 && (pressedButtons & (BUTTON_START | BUTTON_C_LEFT | BUTTON_C_RIGHT))
92 ) {
95 return FALSE;
96 }
97 if (partnerStatus->partnerActionState == PARTNER_ACTION_NONE) {
99 if (actionState == ACTION_STATE_IDLE ||
100 actionState == ACTION_STATE_WALK ||
101 actionState == ACTION_STATE_RUN
102 ) {
103 return TRUE;
104 }
105 }
106 } else if (partner_can_open_world_menus()) {
107 if (partnerStatus->actingPartner == PARTNER_WATT) {
108 return actionState == ACTION_STATE_IDLE ||
109 actionState == ACTION_STATE_WALK ||
110 actionState == ACTION_STATE_RUN;
111 } else if (partnerStatus->actingPartner == PARTNER_BOW) {
112 if (actionState == ACTION_STATE_RIDE) {
114 return TRUE;
115 }
116 } else if (partnerStatus->actingPartner == PARTNER_LAKILESTER) {
117 if (actionState == ACTION_STATE_RIDE) {
119 return TRUE;
120 }
122 }
123 } else if (partnerStatus->actingPartner == PARTNER_SUSHIE) {
125 }
126 }
127 }
128 return FALSE;
129}
130
134
136 PlayerData* playerData = &gPlayerData;
137 s32 optionCount = 0;
138 s32 i;
139
140 for (i = 1; i < ARRAY_COUNT(PartnerIDFromMenuIndex); i++) {
141 s32 partnerID = PartnerIDFromMenuIndex[i];
142
143 if (playerData->partners[partnerID].enabled && partnerID != PARTNER_GOOMPA) {
144 PartnerPopupProperties* properties = &gPartnerPopupProperties[partnerID];
145
146 menu->ptrIcon[optionCount] = wPartnerHudScripts[partnerID];
147 menu->userIndex[optionCount] = partnerID;
148 menu->enabled[optionCount] = TRUE;
149 menu->nameMsg[optionCount] = properties->nameMsg;
150 menu->descMsg[optionCount] = properties->worldDescMsg;
151 menu->value[optionCount] = playerData->partners[partnerID].level;
152 if (playerData->curPartner == partnerID) {
153 menu->enabled[optionCount] = FALSE;
154 menu->ptrIcon[optionCount] = wDisabledPartnerHudScripts[partnerID];
155 }
156 optionCount++;
157 }
158 }
159 return optionCount;
160}
161
163 PlayerData* playerData = &gPlayerData;
164 s32 optionCount = 0;
165 s32 i;
166
167 for (i = 0; i < ARRAY_COUNT(playerData->invItems); i++) {
168 s32 itemIdx = playerData->invItems[i];
169
170 if (itemIdx != 0) {
171 ItemData* item = &gItemTable[itemIdx];
172 IconHudScriptPair* itemScripts = &gItemHudScripts[item->hudElemID];
173
175 menu->ptrIcon[optionCount] = itemScripts->enabled;
176 menu->userIndex[optionCount] = i;
177 menu->enabled[optionCount] = 1;
178 } else {
179 menu->ptrIcon[optionCount] = itemScripts->disabled;
180 menu->userIndex[optionCount] = i;
181 menu->enabled[optionCount] = FALSE;
182 }
183 menu->nameMsg[optionCount] = item->nameMsg;
184 menu->descMsg[optionCount] = item->shortDescMsg;
185 optionCount++;
186 }
187 }
188 return optionCount;
189}
190
192 static s16 SwappedWorldMenus;
193
194 PartnerStatus* partnerStatus;
195 PlayerStatus* playerStatus;
196 PlayerData* playerData;
197 PopupMenu* popup;
198 s32 flags;
199 s32 numEntries;
200 s32 pressedButtons;
201 s32 currentButtons;
202 s8* partnerActionState;
203
204 partnerStatus = &gPartnerStatus;
205 playerStatus = &gPlayerStatus;
206 playerData = &gPlayerData;
207 popup = &WorldPopupMenu;
208
212 ) {
213 return;
214 }
215
216 if (partnerStatus->partnerActionState != PARTNER_ACTION_NONE &&
217 (partnerStatus->actingPartner == PARTNER_SUSHIE ||
218 partnerStatus->actingPartner == PARTNER_LAKILESTER ||
219 partnerStatus->actingPartner == PARTNER_BOW))
220 {
221 currentButtons = partnerStatus->curButtons;
222 pressedButtons = partnerStatus->pressedButtons;
223 } else {
224 currentButtons = playerStatus->curButtons;
225 pressedButtons = playerStatus->pressedButtons;
226 }
227 partnerActionState = &partnerStatus->partnerActionState;
228
229 // prevent opening popup menus during the epilogue
231 currentButtons &= ~(BUTTON_C_LEFT | BUTTON_C_RIGHT);
232 pressedButtons &= ~(BUTTON_C_LEFT | BUTTON_C_RIGHT);
233 }
234
235 switch (WorldMenuState) {
237 if (can_open_world_menu(currentButtons, pressedButtons)) {
239 if (pressedButtons & BUTTON_C_RIGHT) {
241 }
242 if (pressedButtons & BUTTON_START) {
244 }
245 SwappedWorldMenus = FALSE;
246block_17:
247 switch (WorldMenuType) {
249 if (playerStatus->flags & PS_FLAG_NO_CHANGE_PARTNER) {
251 if (SwappedWorldMenus) {
253 playerStatus->flags &= ~PS_FLAG_PAUSED;
254 gOverrideFlags &= ~GLOBAL_OVERRIDES_40;
256 }
257 } else {
258 numEntries = setup_partner_popup(popup);
259 if (numEntries == 0) {
260 return;
261 }
262 popup->numEntries = numEntries;
264 popup->initialPos = MenuIndexFromPartnerID[playerData->curPartner] - 1;
265 break;
266 }
267 return;
269 numEntries = setup_item_popup(popup);
270 if (numEntries == 0) {
271 return;
272 }
274 popup->numEntries = numEntries;
275 popup->initialPos = 0;
276 break;
277 }
278 playerStatus->flags |= PS_FLAG_PAUSED;
281 WorldMenuDelay = 3;
284 }
285 break;
287 flags = ~PS_FLAG_PAUSED;
288 if (!should_cancel_open_world_menu() || is_picking_up_item() || OpenMenuDisableCount < playerStatus->inputDisabledCount != 0) {
289 playerStatus->flags &= flags;
293 if (SwappedWorldMenus) {
295 playerStatus->flags &= ~PS_FLAG_PAUSED;
296 gOverrideFlags &= ~GLOBAL_OVERRIDES_40;
298 }
299 } else {
301 if (WorldMenuDelay == 0) {
304 }
305 }
306 break;
311 WorldMenuDelay = 10;
313 return;
314 }
317 if (*partnerActionState == PARTNER_ACTION_NONE) {
319 }
321 break;
323 if (popup->result != POPUP_RESULT_INVALID) {
324 WorldPopupResult = popup->result;
327 WorldMenuDelay = 15;
329 }
330 }
331 break;
334 if (WorldMenuDelay != 0) {
335 break;
336 }
342 if ((setup_partner_popup(popup) == 0) || (setup_item_popup(popup) == 0)) {
344 } else {
345 // swap to other menu
346 switch (WorldMenuType) {
349 break;
352 break;
353 }
354 SwappedWorldMenus = TRUE;
355 goto block_17; // TODO required to match
356 }
357 }
358
360 switch (WorldMenuType) {
363 break;
366#ifndef VERSION_JP
368#endif
369 break;
370 }
371 }
373 playerStatus->flags &= ~PS_FLAG_PAUSED;
374 gOverrideFlags &= ~GLOBAL_OVERRIDES_40;
376 break;
379 if (WorldMenuDelay == 0) {
382 playerStatus->flags &= ~PS_FLAG_PAUSED;
383 gOverrideFlags &= ~GLOBAL_OVERRIDES_40;
386 }
387 break;
388 }
389}
390
392 PlayerStatus* playerStatus = &gPlayerStatus;
393 s32 pressedButtons;
394
396 if (playerStatus->actionState != ACTION_STATE_RIDE) {
397 pressedButtons = playerStatus->pressedButtons;
398 } else {
399 pressedButtons = gGameStatusPtr->pressedButtons[0];
400 }
401
402 if (!is_status_bar_visible()) {
403 if (!(playerStatus->curButtons & (Z_TRIG | R_TRIG))
404 && (pressedButtons & BUTTON_C_UP)
406 ) {
408#if VERSION_JP
410#else
411 if (!is_picking_up_item()) {
413 }
414#endif
415 }
416 } else if (!(playerStatus->curButtons & (Z_TRIG | R_TRIG))
417 && (pressedButtons & BUTTON_C_UP)
419 ) {
421#if VERSION_JP
423#else
424 if (!is_picking_up_item()) {
426 }
427#endif
428 }
429 }
430}
PartnerPopupProperties gPartnerPopupProperties[]
Definition 5B320.c:331
void create_standard_popup_menu(PopupMenu *popup)
IconHudScriptPair gItemHudScripts[]
u32 pressedButtons[4]
struct Shop * mapShop
PartnerData partners[12]
s32 b32
s16 invItems[10]
s8 flags
Definition demo_api.c:15
@ DEBUG_SCRIPTS_NONE
Definition enums.h:4275
@ BUTTON_C_UP
Definition enums.h:2780
@ BUTTON_START
Definition enums.h:2787
@ BUTTON_R
Definition enums.h:2781
@ BUTTON_C_RIGHT
Definition enums.h:2777
@ BUTTON_C_LEFT
Definition enums.h:2778
@ BUTTON_Z
Definition enums.h:2788
@ IMGFX_SET_ALPHA
Definition enums.h:5124
@ PEACH_FLAG_IS_PEACH
Definition enums.h:2488
@ STORY_INTRO
Definition enums.h:10
@ STORY_EPILOGUE
Definition enums.h:234
@ POPUP_MENU_USE_ITEM
Definition enums.h:3131
@ POPUP_MENU_SWITCH_PARTNER
Definition enums.h:3132
@ PS_FLAG_PAUSED
Definition enums.h:3040
@ PS_FLAG_NO_CHANGE_PARTNER
Definition enums.h:3041
@ PS_FLAG_PAUSE_DISABLED
Definition enums.h:3044
@ PS_FLAG_NO_STATIC_COLLISION
Definition enums.h:3051
@ PARTNER_ACTION_NONE
Definition enums.h:2932
@ ITEM_TYPE_FLAG_WORLD_USABLE
Definition enums.h:1834
@ NPC_PARTNER
Definition enums.h:2528
@ POPUP_RESULT_CANCEL
Definition enums.h:3178
@ POPUP_RESULT_CHOOSING
Definition enums.h:3177
@ POPUP_RESULT_INVALID
Definition enums.h:3175
@ POPUP_RESULT_SWAP_MENU
Definition enums.h:3176
@ PA_FLAG_8BIT_MARIO
Definition enums.h:3105
@ PA_FLAG_CHANGING_MAP
Definition enums.h:3112
@ TIME_FREEZE_POPUP_MENU
Definition enums.h:3467
@ TIME_FREEZE_NONE
Definition enums.h:3464
@ SHOP_FLAG_SHOWING_ITEM_INFO
Definition enums.h:4946
@ SOUND_LOWER_STATUS_BAR
Definition enums.h:550
@ SOUND_MENU_OPEN
Definition enums.h:696
@ SOUND_RAISE_STATUS_BAR
Definition enums.h:551
@ SOUND_MENU_ERROR
Definition enums.h:933
@ PARTNER_LAKILESTER
Definition enums.h:2893
@ PARTNER_WATT
Definition enums.h:2891
@ PARTNER_BOW
Definition enums.h:2894
@ PARTNER_SUSHIE
Definition enums.h:2892
@ PARTNER_GOOMPA
Definition enums.h:2890
@ ACTION_STATE_RIDE
Definition enums.h:2461
@ ACTION_STATE_IDLE
Definition enums.h:2426
@ ACTION_STATE_WALK
Definition enums.h:2427
@ ACTION_STATE_RUN
Definition enums.h:2428
@ GLOBAL_OVERRIDES_CANT_PICK_UP_ITEMS
Definition enums.h:4339
@ GLOBAL_OVERRIDES_40
Definition enums.h:4325
@ GLOBAL_OVERRIDES_DISABLE_MENUS
Definition enums.h:4337
b32 can_control_status_bar(void)
Definition inventory.c:1481
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
void hide_popup_menu(void)
void partner_disable_input(void)
Definition partners.c:2489
s32 disable_player_input(void)
Definition 77480.c:990
void close_status_bar(void)
Definition inventory.c:1440
s32 enable_player_input(void)
Definition 77480.c:998
void destroy_popup_menu(void)
void switch_to_partner(s32 arg0)
Definition partners.c:906
s32 is_picking_up_item(void)
void set_action_state(s32 actionState)
Definition 7E9D0.c:209
s32 use_consumable(s32 invSlot)
Definition partners.c:479
s32 partner_can_open_world_menus(void)
Definition partners.c:983
void set_time_freeze_mode(s32)
Time freeze modes: 0: none 1: NPCs move, can't be interacted with 2: NPCs don't move,...
Definition main_loop.c:358
s32 is_status_bar_visible(void)
Definition inventory.c:1526
void open_status_bar_slowly(void)
Definition inventory.c:1420
void set_game_mode(s32 modeID)
Definition game_modes.c:127
@ GAME_MODE_PAUSE
Definition game_modes.h:17
HudScript * wDisabledPartnerHudScripts[]
Definition partners.c:136
s32 userIndex[32]
HudScript * wPartnerHudScripts[]
Definition partners.c:130
s32 nameMsg[32]
HudScript * disabled
HudScript * ptrIcon[32]
s32 value[32]
s32 enabled[32]
s16 flags
HudScript * enabled
s32 descMsg[32]
s32 world_lakilester_can_dismount(void)
void reset_outta_sight_alpha_on_menu_close(void)
Definition menus.c:37
BSS s16 WorldMenuState
Definition menus.c:33
void clear_world_menus(void)
Definition menus.c:131
b32 should_cancel_open_world_menu(void)
Definition menus.c:49
BSS s16 OpenMenuDisableCount
Definition menus.c:32
BSS s32 D_8010C9C4
Definition menus.c:27
WorldMenuStates
Definition menus.c:12
@ WORLD_MENU_STATE_CLOSE
Definition menus.c:17
@ WORLD_MENU_STATE_UNPAUSE
Definition menus.c:18
@ WORLD_MENU_STATE_HOLD
Definition menus.c:16
@ WORLD_MENU_STATE_NONE
Definition menus.c:13
@ WORLD_MENU_STATE_OPEN
Definition menus.c:15
@ WORLD_MENU_STATE_DELAY
Definition menus.c:14
BSS s16 WorldPopupResult
Definition menus.c:31
void check_input_open_menus(void)
Definition menus.c:191
b32 can_open_world_menu(s32 currentButtons, s32 pressedButtons)
Definition menus.c:81
s32 MenuIndexFromPartnerID[]
Definition 5B320.c:316
s32 setup_item_popup(PopupMenu *menu)
Definition menus.c:162
WorldMenuTypes
Definition menus.c:21
@ WORLD_MENU_USE_ITEM
Definition menus.c:23
@ WORLD_MENU_PAUSE
Definition menus.c:24
@ WORLD_MENU_CHANGE_PARTNER
Definition menus.c:22
void check_input_status_bar(void)
Definition menus.c:391
BSS s16 WorldMenuDelay
Definition menus.c:30
s32 setup_partner_popup(PopupMenu *menu)
Definition menus.c:135
BSS PopupMenu WorldPopupMenu
Definition menus.c:28
BSS s16 WorldMenuType
Definition menus.c:29
void npc_set_imgfx_params(Npc *npc, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6)
Definition npc.c:2162
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
void partner_enable_input(void)
Definition partners.c:2480
void sfx_play_sound(s32 soundID)
Definition sfx.c:517
@ GB_StoryProgress
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
void set_player_imgfx_comp(s32 spriteIdx, s32 compIdx, ImgFXType imgfx, s32 imgfxArg1, s32 imgfxArg2, s32 imgfxArg3, s32 imgfxArg4, s32 flags)
Definition sprite.c:969
@ PLAYER_SPRITE_MAIN
Definition sprite.h:26
s32 gOverrideFlags
Definition main_loop.c:11
ItemData gItemTable[]
s32 PartnerIDFromMenuIndex[12]
Definition 5B320.c:300
PartnerStatus gPartnerStatus
Definition partners.c:42
GameStatus * gGameStatusPtr
Definition main_loop.c:32
PlayerData gPlayerData
Definition 77480.c:40
PlayerStatus gPlayerStatus
Definition 77480.c:39