From dfce7f15489de5e94d9476dc76e33e2b60672130 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Thu, 1 Apr 2021 09:45:17 -0600 Subject: [PATCH 1/2] add auto read signposts --- data/event_scripts.s | 4 + .../primary/general/metatile_attributes.bin | Bin 1024 -> 1024 bytes include/constants/metatile_behaviors.h | 2 +- include/event_scripts.h | 2 + include/field_control_avatar.h | 1 + include/field_message_box.h | 2 + include/metatile_behavior.h | 1 + include/script.h | 8 ++ include/text_window.h | 1 + src/field_control_avatar.c | 124 +++++++++++++++++- src/field_message_box.c | 10 +- src/metatile_behavior.c | 8 +- src/overworld.c | 1 + src/scrcmd.c | 2 + src/script.c | 35 +++++ src/text_window.c | 9 ++ 16 files changed, 206 insertions(+), 4 deletions(-) diff --git a/data/event_scripts.s b/data/event_scripts.s index 8039be6876..886c55f71c 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -690,6 +690,10 @@ EventScript_BackupMrBrineyLocation:: @ 8271E95 .include "data/scripts/rival_graphics.inc" .include "data/scripts/set_gym_trainers.inc" +EventScript_CancelMessageBox:: + release + end + Common_EventScript_ShowBagIsFull:: @ 8272054 msgbox gText_TooBadBagIsFull, MSGBOX_DEFAULT release diff --git a/data/tilesets/primary/general/metatile_attributes.bin b/data/tilesets/primary/general/metatile_attributes.bin index d9cd29016d792fb568494dbf2f820100081a14f8..af9326451d561c4103afe500c5ae8c7656092fc6 100644 GIT binary patch delta 21 ZcmZqRXy9OH00Y^H?D~wd8_iEL0{|lp1I_>d delta 21 YcmZqRXy9OHfPjhY`iu-4%}+7|03liflmGw# diff --git a/include/constants/metatile_behaviors.h b/include/constants/metatile_behaviors.h index 94cb0ffcaa..cd2f70fe0f 100755 --- a/include/constants/metatile_behaviors.h +++ b/include/constants/metatile_behaviors.h @@ -30,7 +30,7 @@ #define MB_UNUSED_SOOTOPOLIS_DEEP_WATER_2 0x1A #define MB_STAIRS_OUTSIDE_ABANDONED_SHIP 0x1B #define MB_SHOAL_CAVE_ENTRANCE 0x1C -#define MB_UNUSED_1D 0x1D +#define MB_SIGNPOST 0x1D #define MB_UNUSED_1E 0x1E #define MB_UNUSED_1F 0x1F #define MB_ICE 0x20 diff --git a/include/event_scripts.h b/include/event_scripts.h index 79ef0ea142..eff980f138 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -610,4 +610,6 @@ extern const u8 EventScript_TradeCenter_Chair0[]; extern const u8 EventScript_ConfirmLeaveTradeRoom[]; extern const u8 EventScript_TerminateLink[]; +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 17e5afb63e..e6c90e8e5b 100644 --- a/include/field_control_avatar.h +++ b/include/field_control_avatar.h @@ -40,5 +40,6 @@ u8 TrySetDiveWarp(void); const u8 *GetInteractedLinkPlayerScript(struct MapPosition *position, u8 metatileBehavior, u8 direction); u8 *GetCoordEventScriptAtMapPosition(struct MapPosition *position); void ClearPoisonStepCounter(void); +void FieldInput_HandleCancelSignpost(struct FieldInput *input); #endif // GUARD_FIELDCONTROLAVATAR_H diff --git a/include/field_message_box.h b/include/field_message_box.h index 34b3324e72..eed6c7a9c0 100644 --- a/include/field_message_box.h +++ b/include/field_message_box.h @@ -19,4 +19,6 @@ u8 GetFieldMessageBoxMode(void); void StopFieldMessage(void); void InitFieldMessageBox(void); +extern u8 gWalkAwayFromSignInhibitTimer; + #endif // GUARD_FIELD_MESSAGE_BOX_H diff --git a/include/metatile_behavior.h b/include/metatile_behavior.h index d4bd9e6832..886422e63e 100644 --- a/include/metatile_behavior.h +++ b/include/metatile_behavior.h @@ -145,5 +145,6 @@ bool8 MetatileBehavior_IsQuestionnaire(u8); bool8 MetatileBehavior_IsLongGrass_Duplicate(u8); bool8 MetatileBehavior_IsLongGrassSouthEdge(u8); bool8 MetatileBehavior_IsTrainerHillTimer(u8); +bool8 MetatileBehavior_IsSignpost(u8 mb); #endif // GUARD_METATILE_BEHAVIOR diff --git a/include/script.h b/include/script.h index 63f6f5aef9..92309eb653 100644 --- a/include/script.h +++ b/include/script.h @@ -62,4 +62,12 @@ void InitRamScript_NoObjectEvent(u8 *script, u16 scriptSize); // srccmd.h void SetMovingNpcId(u16 npcId); +// auto read signs +void SetWalkingIntoSignVars(void); +void MsgSetSignPost(void); +void ResetFacingNpcOrSignPostVars(void); +bool32 IsMsgSignPost(void); +bool32 CanWalkAwayToCancelMsgBox(void); +void ClearMsgBoxCancelableState(void); + #endif // GUARD_SCRIPT_H diff --git a/include/text_window.h b/include/text_window.h index 7bdcacd17c..d6bf83e0b3 100644 --- a/include/text_window.h +++ b/include/text_window.h @@ -23,5 +23,6 @@ void rbox_fill_rectangle(u8 windowId); const u16 *GetTextWindowPalette(u8 id); const u16 *GetOverworldTextboxPalettePtr(void); void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset); +void LoadSignPostWindowFrameGfx(void); #endif // GUARD_TEXT_WINDOW_H diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 6ec280fd0d..16e334f429 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -9,6 +9,7 @@ #include "event_scripts.h" #include "fieldmap.h" #include "field_control_avatar.h" +#include "field_message_box.h" #include "field_player_avatar.h" #include "field_poison.h" #include "field_screen_effect.h" @@ -41,6 +42,13 @@ static EWRAM_DATA u16 sPreviousPlayerMetatileBehavior = 0; u8 gSelectedObjectEvent; +#define SIGNPOST_POKECENTER 0 +#define SIGNPOST_POKEMART 1 +#define SIGNPOST_INDIGO_1 2 +#define SIGNPOST_INDIGO_2 3 +#define SIGNPOST_SCRIPTED 240 +#define SIGNPOST_NA 255 + static void GetPlayerPosition(struct MapPosition *); static void GetInFrontOfPlayerPosition(struct MapPosition *); static u16 GetPlayerCurMetatileBehavior(int); @@ -69,6 +77,10 @@ static bool8 TryStartMiscWalkingScripts(u16); static bool8 TryStartStepCountScript(u16); static void UpdateFriendshipStepCounter(void); static bool8 UpdatePoisonStepCounter(void); +static bool8 TrySetUpWalkIntoSignpostScript(struct MapPosition * position, u16 metatileBehavior, u8 playerDirection); +static void SetUpWalkIntoSignScript(const u8 *script, u8 playerDirection); +static u8 GetFacingSignpostType(u16 metatileBehvaior, u8 direction); +static const u8 *GetSignpostScriptAtMapPosition(struct MapPosition * position); void FieldClearPlayerInput(struct FieldInput *input) { @@ -140,7 +152,8 @@ int ProcessPlayerFieldInput(struct FieldInput *input) gSpecialVar_LastTalked = 0; gSelectedObjectEvent = 0; - + + ResetFacingNpcOrSignPostVars(); playerDirection = GetPlayerFacingDirection(); GetPlayerPosition(&position); metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y); @@ -160,6 +173,20 @@ int ProcessPlayerFieldInput(struct FieldInput *input) if (TryStartStepBasedScript(&position, metatileBehavior, playerDirection) == TRUE) return TRUE; } + + if (input->checkStandardWildEncounter) + { + if (input->dpadDirection == 0 || input->dpadDirection == playerDirection) + { + GetInFrontOfPlayerPosition(&position); + metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y); + if (TrySetUpWalkIntoSignpostScript(&position, metatileBehavior, playerDirection) == TRUE) + return TRUE; + GetPlayerPosition(&position); + metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y); + } + } + if (input->checkStandardWildEncounter && CheckStandardWildEncounter(metatileBehavior) == TRUE) return TRUE; if (input->heldDirection && input->dpadDirection == playerDirection) @@ -170,6 +197,13 @@ int ProcessPlayerFieldInput(struct FieldInput *input) GetInFrontOfPlayerPosition(&position); metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y); + + if (input->heldDirection && input->dpadDirection == playerDirection) + { + if (TrySetUpWalkIntoSignpostScript(&position, metatileBehavior, playerDirection) == TRUE) + return TRUE; + } + if (input->pressedAButton && TryStartInteractionScript(&position, metatileBehavior, playerDirection) == TRUE) return TRUE; @@ -1005,3 +1039,91 @@ int SetCableClubWarp(void) SetupWarp(&gMapHeader, GetWarpEventAtMapPosition(&gMapHeader, &position), &position); return 0; } + +// auto read signposts +// signposts +static bool8 TrySetUpWalkIntoSignpostScript(struct MapPosition *position, u16 metatileBehavior, u8 playerDirection) +{ + u8 signpostType; + const u8 *script; + + if (JOY_HELD(DPAD_LEFT | DPAD_RIGHT)) + return FALSE; + if (playerDirection != DIR_NORTH) + return FALSE; + + switch (GetFacingSignpostType(metatileBehavior, playerDirection)) + { + /* leaving this commented out for examples of custom signpost types + case SIGNPOST_POKECENTER: + SetUpWalkIntoSignScript(EventScript_PokecenterSign, playerDirection); + return TRUE; + case SIGNPOST_POKEMART: + SetUpWalkIntoSignScript(EventScript_PokemartSign, playerDirection); + return TRUE;*/ + case SIGNPOST_SCRIPTED: + script = GetSignpostScriptAtMapPosition(position); + if (script == NULL) + return FALSE; + SetUpWalkIntoSignScript(script, playerDirection); + return TRUE; + default: + return FALSE; + } +} + +static u8 GetFacingSignpostType(u16 metatileBehavior, u8 playerDirection) +{ + /*if (MetatileBehavior_IsPlayerFacingPokemonCenterSign(metatileBehavior, playerDirection) == TRUE) + return SIGNPOST_POKECENTER; + if (MetatileBehavior_IsPlayerFacingPokeMartSign(metatileBehavior, playerDirection) == TRUE) + return SIGNPOST_POKEMART;*/ + + if (MetatileBehavior_IsSignpost(metatileBehavior) == TRUE) + return SIGNPOST_SCRIPTED; + + return SIGNPOST_NA; +} + +static void SetUpWalkIntoSignScript(const u8 *script, u8 playerDirection) +{ + gSpecialVar_Facing = playerDirection; + ScriptContext1_SetupScript(script); + SetWalkingIntoSignVars(); + MsgSetSignPost(); +} + +static const u8 *GetSignpostScriptAtMapPosition(struct MapPosition *position) +{ + const struct BgEvent *event = GetBackgroundEventAtPosition(&gMapHeader, position->x - 7, position->y - 7, position->height); + if (event == NULL) + return NULL; + if (event->bgUnion.script != NULL) + return event->bgUnion.script; + return EventScript_TestSignpostMsg; +} + +void FieldInput_HandleCancelSignpost(struct FieldInput *input) +{ + if (ScriptContext1_IsScriptSetUp() == TRUE) + { + if (gWalkAwayFromSignInhibitTimer != 0) + { + gWalkAwayFromSignInhibitTimer--; + } + else if (CanWalkAwayToCancelMsgBox() == TRUE) + { + //ClearMsgBoxCancelableState(); + if (input->dpadDirection != 0 && GetPlayerFacingDirection() != input->dpadDirection) + { + ScriptContext1_SetupScript(EventScript_CancelMessageBox); + ScriptContext2_Enable(); + } + else if (input->pressedStartButton) + { + ScriptContext1_SetupScript(EventScript_CancelMessageBox); + ScriptContext2_Enable(); + } + } + } +} diff --git a/src/field_message_box.c b/src/field_message_box.c index 69d470b84e..9bb1bd52c4 100755 --- a/src/field_message_box.c +++ b/src/field_message_box.c @@ -5,8 +5,11 @@ #include "text.h" #include "match_call.h" #include "field_message_box.h" +#include "text_window.h" +#include "script.h" static EWRAM_DATA u8 sFieldMessageBoxMode = 0; +EWRAM_DATA u8 gWalkAwayFromSignInhibitTimer = 0; static void ExpandStringAndStartDrawFieldMessage(const u8*, bool32); static void StartDrawFieldMessage(void); @@ -29,7 +32,12 @@ static void Task_DrawFieldMessage(u8 taskId) switch (task->tState) { case 0: - LoadMessageBoxAndBorderGfx(); + if (IsMsgSignPost()) + LoadSignPostWindowFrameGfx(); + else + LoadMessageBoxAndBorderGfx(); + task->tState++; + break; task->tState++; break; case 1: diff --git a/src/metatile_behavior.c b/src/metatile_behavior.c index 2a9304a4d8..4656e94b0f 100644 --- a/src/metatile_behavior.c +++ b/src/metatile_behavior.c @@ -39,7 +39,7 @@ static const u8 sTileBitAttributes[] = [MB_UNUSED_SOOTOPOLIS_DEEP_WATER_2] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_STAIRS_OUTSIDE_ABANDONED_SHIP] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_SHOAL_CAVE_ENTRANCE] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_UNUSED_1D] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), + [MB_SIGNPOST] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_UNUSED_1E] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_UNUSED_1F] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_ICE] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), @@ -1495,3 +1495,9 @@ bool8 MetatileBehavior_IsTrainerHillTimer(u8 metatileBehavior) else return FALSE; } + +bool8 MetatileBehavior_IsSignpost(u8 mb) +{ + return (mb == MB_SIGNPOST); +} + diff --git a/src/overworld.c b/src/overworld.c index 9d5e40fb37..7082eb078c 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1422,6 +1422,7 @@ static void DoCB1_Overworld(u16 newKeys, u16 heldKeys) UpdatePlayerAvatarTransitionState(); FieldClearPlayerInput(&inputStruct); FieldGetPlayerInput(&inputStruct, newKeys, heldKeys); + FieldInput_HandleCancelSignpost(&inputStruct); if (!ScriptContext2_IsEnabled()) { if (ProcessPlayerFieldInput(&inputStruct) == 1) diff --git a/src/scrcmd.c b/src/scrcmd.c index 7dc02b6a8f..710a58c246 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1248,6 +1248,7 @@ bool8 ScrCmd_releaseall(struct ScriptContext *ctx) ObjectEventClearHeldMovementIfFinished(&gObjectEvents[playerObjectId]); ScriptMovement_UnfreezeObjectEvents(); UnfreezeObjectEvents(); + ClearMsgBoxCancelableState(); return FALSE; } @@ -1262,6 +1263,7 @@ bool8 ScrCmd_release(struct ScriptContext *ctx) ObjectEventClearHeldMovementIfFinished(&gObjectEvents[playerObjectId]); ScriptMovement_UnfreezeObjectEvents(); UnfreezeObjectEvents(); + ClearMsgBoxCancelableState(); return FALSE; } diff --git a/src/script.c b/src/script.c index 726c065439..977298f833 100644 --- a/src/script.c +++ b/src/script.c @@ -3,6 +3,7 @@ #include "event_data.h" #include "mevent.h" #include "util.h" +#include "field_message_box.h" #include "constants/map_scripts.h" #define RAM_SCRIPT_MAGIC 51 @@ -19,6 +20,8 @@ static u8 sScriptContext1Status; static struct ScriptContext sScriptContext1; static struct ScriptContext sScriptContext2; static bool8 sScriptContext2Enabled; +static u8 sMsgIsSignPost; +static u8 sMsgBoxIsCancelable; extern ScrCmdFunc gScriptCmdTable[]; extern ScrCmdFunc gScriptCmdTableEnd[]; @@ -444,3 +447,35 @@ void InitRamScript_NoObjectEvent(u8 *script, u16 scriptSize) scriptSize = sizeof(gSaveBlock1Ptr->ramScript.data.script); InitRamScript(script, scriptSize, 0xFF, 0xFF, 0xFF); } + +// auto read signposts +void SetWalkingIntoSignVars(void) +{ + gWalkAwayFromSignInhibitTimer = 6; + sMsgBoxIsCancelable = TRUE; +} + +bool32 IsMsgSignPost(void) +{ + return sMsgIsSignPost; +} + +void ResetFacingNpcOrSignPostVars(void) +{ + sMsgIsSignPost = FALSE; +} + +void MsgSetSignPost(void) +{ + sMsgIsSignPost = TRUE; +} + +void ClearMsgBoxCancelableState(void) +{ + sMsgBoxIsCancelable = FALSE; +} + +bool32 CanWalkAwayToCancelMsgBox(void) +{ + return sMsgBoxIsCancelable; +} diff --git a/src/text_window.c b/src/text_window.c index 864bd08316..7d59ce2d35 100644 --- a/src/text_window.c +++ b/src/text_window.c @@ -5,6 +5,7 @@ #include "palette.h" #include "bg.h" #include "graphics.h" +#include "menu.h" // const rom data const u8 gTextWindowFrame1_Gfx[] = INCBIN_U8("graphics/text_window/1.4bpp"); @@ -195,3 +196,11 @@ void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset) LoadBgTiles(bg, sWindowFrames[gSaveBlock2Ptr->optionsWindowFrameType].tiles, 0x120, destOffset); LoadPalette(GetWindowFrameTilesPal(gSaveBlock2Ptr->optionsWindowFrameType)->pal, palOffset, 0x20); } + +void LoadSignPostWindowFrameGfx(void) +{ + // TODO signpost msgbox frames + //LoadBgTiles(GetWindowAttribute(windowId, WINDOW_BG), gUnknown_8470B0C, 0x260, destOffset); + //LoadPalette(GetWindowFrameTilesPal(1), palIdx, 32); + LoadMessageBoxAndBorderGfx(); +} From 7bb81150999f6585e3e6eeb8c4bc22c42e27893f Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Fri, 3 Mar 2023 09:08:05 -0500 Subject: [PATCH 2/2] add start menu funcs, credit deokishisu --- data/event_scripts.s | 1 + data/specials.inc | 1 + src/field_control_avatar.c | 12 ++++++++++++ src/field_specials.c | 7 +++++++ 4 files changed, 21 insertions(+) diff --git a/data/event_scripts.s b/data/event_scripts.s index 886c55f71c..3d2a9b2a81 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -691,6 +691,7 @@ EventScript_BackupMrBrineyLocation:: @ 8271E95 .include "data/scripts/set_gym_trainers.inc" EventScript_CancelMessageBox:: + special DoPicboxCancel release end diff --git a/data/specials.inc b/data/specials.inc index 620fae369b..9c23506d20 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -535,3 +535,4 @@ gSpecials:: @ 81DBA64 def_special RemoveRecordsWindow def_special CloseDeptStoreElevatorWindow def_special TrySetBattleTowerLinkType + def_special DoPicboxCancel diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 16e334f429..6547855610 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -1103,6 +1103,16 @@ static const u8 *GetSignpostScriptAtMapPosition(struct MapPosition *position) return EventScript_TestSignpostMsg; } +static void Task_OpenStartMenu(u8 taskId) +{ + if (!ArePlayerFieldControlsLocked()) + { + PlaySE(SE_WIN_OPEN); + ShowStartMenu(); + DestroyTask(taskId); + } +} + void FieldInput_HandleCancelSignpost(struct FieldInput *input) { if (ScriptContext1_IsScriptSetUp() == TRUE) @@ -1123,6 +1133,8 @@ void FieldInput_HandleCancelSignpost(struct FieldInput *input) { ScriptContext1_SetupScript(EventScript_CancelMessageBox); ScriptContext2_Enable(); + if (!FuncIsActiveTask(Task_OpenStartMenu)) + CreateTask(Task_OpenStartMenu, 8); } } } diff --git a/src/field_specials.c b/src/field_specials.c index 86be21edac..93e5c0d1c1 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4376,3 +4376,10 @@ u8 Script_TryGainNewFanFromCounter(void) { return TryGainNewFanFromCounter(gSpecialVar_0x8004); } + +void DoPicboxCancel(void) +{ + u8 t = EOS; + AddTextPrinterParameterized(0, FONT_NORMAL, &t, 0, 1, 0, NULL); + ScriptMenu_HidePokemonPic(); +}