From 8e436e3add955164fd1a739332986e21bfd1227d Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Mon, 4 Jul 2022 03:56:02 -0400 Subject: [PATCH] Fixed fadescreen interaction with weather on outdoor maps. --- asm/macros/event.inc | 12 +++++++----- data/event_scripts.s | 6 ++++-- data/maps/MtChimney/scripts.inc | 4 ++-- data/maps/MtPyre_Summit/scripts.inc | 5 ++--- src/field_weather.c | 6 ++++-- src/scrcmd.c | 9 +++++++++ 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 643d785618..046fa17658 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -276,7 +276,7 @@ .2byte SPECIAL_\function .endm - @ Blocks script execution until a command or C code manually unblocks it. Generally used with specific + @ Blocks script execution until a command or C code manually unblocks it. Generally used with specific @ commands and specials. Calling EnableBothScriptContexts for instance will allow execution to continue. .macro waitstate .byte 0x27 @@ -998,7 +998,7 @@ .endm @ Gives the player an Egg of the specified species. - @ VAR_RESULT will be set to MON_GIVEN_TO_PARTY, MON_GIVEN_TO_PC, or MON_CANT_GIVE depending on the outcome. + @ VAR_RESULT will be set to MON_GIVEN_TO_PARTY, MON_GIVEN_TO_PC, or MON_CANT_GIVE depending on the outcome. .macro giveegg species:req .byte 0x7a .2byte \species @@ -1416,7 +1416,7 @@ .2byte \out .endm - @ Gives 'count' coins to the player, up to a total of MAX_COINS. + @ Gives 'count' coins to the player, up to a total of MAX_COINS. @ If the player already has MAX_COINS then VAR_RESULT is set to TRUE, otherwise it is set to FALSE. .macro addcoins count:req .byte 0xb4 @@ -1677,9 +1677,11 @@ @ Equivalent to fadescreen but copies gPlttBufferUnfaded to gPaletteDecompressionBuffer on the fade out @ and the reverse on the fade in, in effect saving gPlttBufferUnfaded to restore it. - .macro fadescreenswapbuffers mode:req + @ If nowait set, does not wait for the fade to complete + .macro fadescreenswapbuffers mode:req, nowait=0 .byte 0xdc .byte \mode + .byte \nowait .endm @ Buffers the specified trainer's class name to the given string var. @@ -1893,7 +1895,7 @@ @ Gives 'amount' of the specified 'item' to the player and prints a message with fanfare. @ If the player doesn't have space for all the items then as many are added as possible, the - @ message indicates there is no room, and VAR_RESULT is set to FALSE. + @ message indicates there is no room, and VAR_RESULT is set to FALSE. @ Otherwise VAR_RESULT is set to TRUE, and the message indicates they have received the item(s). .macro giveitem item:req, amount=1 setorcopyvar VAR_0x8000, \item diff --git a/data/event_scripts.s b/data/event_scripts.s index 4318ca2eb0..19e1876847 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -716,12 +716,14 @@ Common_EventScript_PlayGymBadgeFanfare:: return Common_EventScript_OutOfCenterPartyHeal:: - fadescreen FADE_TO_BLACK + fadescreenswapbuffers FADE_TO_BLACK playfanfare MUS_HEAL waitfanfare special HealPlayerParty + @ start fade then immediately load following pokemon, and wait for fade + fadescreenswapbuffers FADE_FROM_BLACK, 1 callnative UpdateFollowingPokemon - fadescreen FADE_FROM_BLACK + callfunc ScrFunc_WaitPaletteNotActive return EventScript_RegionMap:: diff --git a/data/maps/MtChimney/scripts.inc b/data/maps/MtChimney/scripts.inc index 1931633258..6e8df88827 100644 --- a/data/maps/MtChimney/scripts.inc +++ b/data/maps/MtChimney/scripts.inc @@ -54,13 +54,13 @@ MtChimney_EventScript_Maxie:: msgbox MtChimney_Text_MaxieYouHaventSeenLastOfMagma, MSGBOX_DEFAULT closemessage delay 30 - fadescreen FADE_TO_BLACK + fadescreenswapbuffers FADE_TO_BLACK removeobject LOCALID_MAXIE removeobject LOCALID_MAGMA_GRUNT_1 removeobject LOCALID_TABITHA removeobject LOCALID_MAGMA_GRUNT_2 setflag FLAG_HIDE_MT_CHIMNEY_TEAM_MAGMA - fadescreen FADE_FROM_BLACK + fadescreenswapbuffers FADE_FROM_BLACK setobjectxyperm LOCALID_ARCHIE, 10, 12 addobject LOCALID_ARCHIE call_if_eq VAR_FACING, DIR_EAST, MtChimney_EventScript_ArchieApproachPlayerEast diff --git a/data/maps/MtPyre_Summit/scripts.inc b/data/maps/MtPyre_Summit/scripts.inc index 3de60df3f2..5a6d23797a 100644 --- a/data/maps/MtPyre_Summit/scripts.inc +++ b/data/maps/MtPyre_Summit/scripts.inc @@ -49,7 +49,7 @@ MtPyre_Summit_EventScript_TeamAquaExits:: call_if_eq VAR_0x8008, 2, MtPyre_Summit_EventScript_ArchieFacePlayer2 msgbox MtPyre_Summit_Text_ArchieWeGotTheOrbLetsGo, MSGBOX_DEFAULT closemessage - fadescreen FADE_TO_BLACK + fadescreenswapbuffers FADE_TO_BLACK removeobject LOCALID_ARCHIE removeobject LOCALID_GRUNT_1 removeobject LOCALID_GRUNT_2 @@ -58,7 +58,7 @@ MtPyre_Summit_EventScript_TeamAquaExits:: setflag FLAG_HIDE_MT_PYRE_SUMMIT_ARCHIE setflag FLAG_HIDE_MT_PYRE_SUMMIT_TEAM_AQUA fadedefaultbgm - fadescreen FADE_FROM_BLACK + fadescreenswapbuffers FADE_FROM_BLACK delay 20 setvar VAR_MT_PYRE_STATE, 1 call_if_eq VAR_0x8008, 0, MtPyre_Summit_EventScript_OldLadyApproachPlayer0 @@ -622,4 +622,3 @@ MtPyre_Summit_Text_HoennTrioTale: .string "becalmed the two enraged POKéMON.\p" .string "Then, its duty done, the green POKéMON\n" .string "flew off into the wild blue yonder…$" - diff --git a/src/field_weather.c b/src/field_weather.c index 721660adde..2d1f2a8096 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -811,8 +811,10 @@ void FadeScreen(u8 mode, s8 delay) if (fadeOut) { - if (TRUE || useWeatherPal) // TODO: Can copying Faded to Unfaded before fadeout cause problems ? - CpuFastCopy(gPlttBufferFaded, gPlttBufferUnfaded, PLTT_BUFFER_SIZE * 2); + // Note: Copying faded -> unfaded like this works fine, except if the screen is faded back in + // without transitioning to a different screen + // For cases like that, use fadescreenswapbuffers + CpuFastCopy(gPlttBufferFaded, gPlttBufferUnfaded, PLTT_BUFFER_SIZE * 2); BeginNormalPaletteFade(PALETTES_ALL, delay, 0, 16, fadeColor); gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_OUT; diff --git a/src/scrcmd.c b/src/scrcmd.c index 58be7085f5..1cef351d83 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -632,6 +632,12 @@ static bool8 IsPaletteNotActive(void) return FALSE; } +// pauses script until palette fade inactive +bool8 ScrFunc_WaitPaletteNotActive(struct ScriptContext *ctx) { + SetupNativeScript(ctx, IsPaletteNotActive); + return TRUE; +} + bool8 ScrCmd_fadescreen(struct ScriptContext *ctx) { FadeScreen(ScriptReadByte(ctx), 0); @@ -652,6 +658,7 @@ bool8 ScrCmd_fadescreenspeed(struct ScriptContext *ctx) bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx) { u8 mode = ScriptReadByte(ctx); + u8 nowait = ScriptReadByte(ctx); switch (mode) { @@ -668,6 +675,8 @@ bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx) break; } + if (nowait) + return FALSE; SetupNativeScript(ctx, IsPaletteNotActive); return TRUE; }