From b54cf221d8098cc0a1d53ec5adb867db7d324cd3 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Mon, 15 Jul 2024 22:13:33 -0700 Subject: [PATCH] Renamed and refactored FieldInput_HandleCancelSignpost into CancelSignPostMessageBox --- include/config/overworld.h | 2 +- include/event_scripts.h | 7 ++-- include/field_control_avatar.h | 2 +- src/field_control_avatar.c | 59 ++++++++++++++++++++-------------- src/overworld.c | 2 +- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/include/config/overworld.h b/include/config/overworld.h index 412ced44e6..aeaf88be58 100644 --- a/include/config/overworld.h +++ b/include/config/overworld.h @@ -3,7 +3,7 @@ // Movement config #define OW_RUNNING_INDOORS GEN_LATEST // In Gen4+, players are allowed to run indoors. -#define OW_AUTO_SIGNPOST FALSE // When enabled, if the tile that the player is facing has MB_SIGNPOST, the player will automatically read the signpost. +#define OW_AUTO_SIGNPOST TRUE // When enabled, if the tile that the player is facing has MB_SIGNPOST, the player will automatically read the signpost. // Other settings #define OW_POISON_DAMAGE GEN_LATEST // In Gen4, Pokémon no longer faint from Poison in the overworld. In Gen5+, they no longer take damage at all. diff --git a/include/event_scripts.h b/include/event_scripts.h index 7b7ce54e67..f66e52866d 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -28,6 +28,9 @@ extern const u8 EventScript_FollowerFaceUp[]; extern const u8 EventScript_FollowerFaceResult[]; extern const u8 EnterPokeballMovement[]; +extern const u8 Common_Movement_FollowerSafeStart[]; +extern const u8 Common_Movement_FollowerSafeEnd[]; + extern const u8 EventScript_TestSignpostMsg[]; extern const u8 EventScript_TryGetTrainerScript[]; extern const u8 EventScript_StartTrainerApproach[]; @@ -643,10 +646,6 @@ extern const u8 VSSeeker_Text_BatteryNotChargedNeedXSteps[]; extern const u8 VSSeeker_Text_NoTrainersWithinRange[]; extern const u8 VSSeeker_Text_TrainersNotReady[]; extern const u8 EventScript_VsSeekerChargingDone[]; - -extern const u8 Common_Movement_FollowerSafeStart[]; -extern const u8 Common_Movement_FollowerSafeEnd[]; - extern const u8 EventScript_CancelMessageBox[]; #endif // GUARD_EVENT_SCRIPTS_H diff --git a/include/field_control_avatar.h b/include/field_control_avatar.h index 994b4b6712..cbee293a31 100644 --- a/include/field_control_avatar.h +++ b/include/field_control_avatar.h @@ -34,6 +34,6 @@ u8 TrySetDiveWarp(void); const u8 *GetInteractedLinkPlayerScript(struct MapPosition *position, u8 metatileBehavior, u8 direction); const u8 *GetCoordEventScriptAtMapPosition(struct MapPosition *position); void ClearPoisonStepCounter(void); -void FieldInput_HandleCancelSignpost(struct FieldInput *input); +void CancelSignPostMessageBox(struct FieldInput *input); #endif // GUARD_FIELDCONTROLAVATAR_H diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 044c1c1779..85bbb4cf2b 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -1167,29 +1167,40 @@ static void Task_OpenStartMenu(u8 taskId) } } -void FieldInput_HandleCancelSignpost(struct FieldInput *input) +bool32 IsDpadPushedToTurnOrMovePlayer(struct FieldInput *input) { - if (ScriptContext_IsEnabled() == TRUE) - { - if (gWalkAwayFromSignInhibitTimer != 0) - { - gWalkAwayFromSignInhibitTimer--; - } - else if (CanWalkAwayToCancelMsgBox() == TRUE) - { - //ClearMsgBoxCancelableState(); - if (input->dpadDirection != 0 && GetPlayerFacingDirection() != input->dpadDirection) - { - ScriptContext_SetupScript(EventScript_CancelMessageBox); - LockPlayerFieldControls(); - } - else if (input->pressedStartButton) - { - ScriptContext_SetupScript(EventScript_CancelMessageBox); - LockPlayerFieldControls(); - if (!FuncIsActiveTask(Task_OpenStartMenu)) - CreateTask(Task_OpenStartMenu, 8); - } - } - } + return (input->dpadDirection != 0 && GetPlayerFacingDirection() != input->dpadDirection); +} + +void CancelSignPostMessageBox(struct FieldInput *input) +{ + if (!ScriptContext_IsEnabled()) + return; + + if (gWalkAwayFromSignInhibitTimer) + { + gWalkAwayFromSignInhibitTimer--; + return; + } + + if (!CanWalkAwayToCancelMsgBox()) + return; + + if (IsDpadPushedToTurnOrMovePlayer(input)) + { + ScriptContext_SetupScript(EventScript_CancelMessageBox); + LockPlayerFieldControls(); + return; + } + + if (!input->pressedStartButton) + return; + + ScriptContext_SetupScript(EventScript_CancelMessageBox); + LockPlayerFieldControls(); + + if (FuncIsActiveTask(Task_OpenStartMenu)) + return; + + CreateTask(Task_OpenStartMenu, 8); } diff --git a/src/overworld.c b/src/overworld.c index 2d787b3cea..866ba27e8e 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1489,7 +1489,7 @@ static void DoCB1_Overworld(u16 newKeys, u16 heldKeys) UpdatePlayerAvatarTransitionState(); FieldClearPlayerInput(&inputStruct); FieldGetPlayerInput(&inputStruct, newKeys, heldKeys); - FieldInput_HandleCancelSignpost(&inputStruct); + CancelSignPostMessageBox(&inputStruct); if (!ArePlayerFieldControlsLocked()) { if (ProcessPlayerFieldInput(&inputStruct) == 1)