From 74f2a55332a1ac46bc86c90e81007421f23f8b91 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Thu, 31 Aug 2023 19:27:39 +0200 Subject: [PATCH] Add new map setup script MAPSETUP_ENTERLEVEL (#4), and integrate overworld HUD setup in the corresponding setup scripts (#15) --- constants/map_setup_constants.asm | 1 + data/maps/setup_script_pointers.asm | 2 ++ data/maps/setup_scripts.asm | 30 +++++++++++++++++++++++++++ engine/menus/intro_menu.asm | 4 ++-- engine/menus/level_selection_menu.asm | 2 +- engine/overworld/events.asm | 5 ----- home/hud.asm | 7 +++++++ home/window.asm | 1 + 8 files changed, 44 insertions(+), 8 deletions(-) diff --git a/constants/map_setup_constants.asm b/constants/map_setup_constants.asm index 42d806a4b..ab2e54e22 100644 --- a/constants/map_setup_constants.asm +++ b/constants/map_setup_constants.asm @@ -13,6 +13,7 @@ const MAPSETUP_SUBMENU ; fa const MAPSETUP_BADWARP ; fb const MAPSETUP_FLY ; fc + const MAPSETUP_ENTERLEVEL ; fd DEF NUM_MAPSETUP_SCRIPTS EQU const_value - $f1 ; callback types diff --git a/data/maps/setup_script_pointers.asm b/data/maps/setup_script_pointers.asm index 9b913b3fc..4b0e4c75c 100644 --- a/data/maps/setup_script_pointers.asm +++ b/data/maps/setup_script_pointers.asm @@ -49,3 +49,5 @@ MapSetupCommands: add_mapsetup SuspendMapAnims ; 2a add_mapsetup ApplyMapPalettes ; 2b add_mapsetup EnableTextAcceleration ; 2c + add_mapsetup ConstructAndEnableOverworldHUD ; 2d + add_mapsetup EnableOverworldHUD ; 2e diff --git a/data/maps/setup_scripts.asm b/data/maps/setup_scripts.asm index 03824a09f..e3be5e1ea 100644 --- a/data/maps/setup_scripts.asm +++ b/data/maps/setup_scripts.asm @@ -13,6 +13,7 @@ MapSetupScripts: dw MapSetupScript_Submenu dw MapSetupScript_BadWarp dw MapSetupScript_Fly + dw MapSetupScript_EnterLevel assert_table_length NUM_MAPSETUP_SCRIPTS ; valid commands are listed in MapSetupCommands (see data/maps/setup_script_pointers.asm) @@ -20,6 +21,33 @@ MACRO mapsetup db (\1_MapSetupCmd - MapSetupCommands) / 3 ENDM +MapSetupScript_EnterLevel: +; same as MapSetupScript_Warp, but includes ConstructAndEnableOverworldHUD + mapsetup DisableLCD + mapsetup InitSound + mapsetup EnterMapSpawnPoint + mapsetup LoadMapAttributes + mapsetup HandleNewMap + mapsetup SpawnPlayer + mapsetup RefreshPlayerCoords + mapsetup GetMapScreenCoords + mapsetup LoadBlockData + mapsetup BufferScreen + mapsetup LoadMapGraphics + mapsetup LoadMapTimeOfDay + mapsetup ConstructAndEnableOverworldHUD + mapsetup LoadMapObjects + mapsetup EnableLCD + mapsetup LoadMapPalettes + mapsetup SpawnInFacingDown + mapsetup RefreshMapSprites + mapsetup PlayMapMusicBike + mapsetup FadeInToMusic + mapsetup FadeInPalettesFromWhite + mapsetup ActivateMapAnims + mapsetup LoadWildMonData + db -1 ; end + MapSetupScript_Teleport: mapsetup ResetPlayerObjectAction MapSetupScript_Fly: @@ -128,6 +156,7 @@ MapSetupScript_ReloadMap: mapsetup LoadConnectionBlockData mapsetup LoadMapGraphics mapsetup LoadMapTimeOfDay + mapsetup EnableOverworldHUD mapsetup EnableLCD mapsetup LoadMapPalettes mapsetup RefreshMapSprites @@ -167,6 +196,7 @@ MapSetupScript_Continue: mapsetup BufferScreen mapsetup LoadMapGraphics mapsetup LoadMapTimeOfDay + mapsetup ConstructAndEnableOverworldHUD mapsetup EnableLCD mapsetup LoadMapPalettes mapsetup RefreshMapSprites diff --git a/engine/menus/intro_menu.asm b/engine/menus/intro_menu.asm index 9ad8e7c1c..b2c57d817 100644 --- a/engine/menus/intro_menu.asm +++ b/engine/menus/intro_menu.asm @@ -327,7 +327,7 @@ Continue: call DelayFrames farcall JumpRoamMons ld a, [wSpawnAfterChampion] - cp SPAWN_LEVEL_1 + cp SPAWN_N_A jr z, .SpawnAfterE4 ld a, MAPSETUP_CONTINUE ldh [hMapEntryMethod], a @@ -378,7 +378,7 @@ FinishContinueFunction: res GAME_TIMER_MOBILE_F, [hl] farcall OverworldLoop ld a, [wSpawnAfterChampion] - cp SPAWN_LEVEL_1 + cp SPAWN_N_A jr z, .AfterRed jp Reset diff --git a/engine/menus/level_selection_menu.asm b/engine/menus/level_selection_menu.asm index 00648d3df..c0b5b3400 100755 --- a/engine/menus/level_selection_menu.asm +++ b/engine/menus/level_selection_menu.asm @@ -141,7 +141,7 @@ LevelSelectionMenu:: ld a, [wLevelSelectionMenuCurrentLandmark] call LevelSelectionMenu_GetLandmarkSpawnPoint ld [wDefaultSpawnpoint], a - ld a, MAPSETUP_WARP + ld a, MAPSETUP_ENTERLEVEL ld [hMapEntryMethod], a xor a ld [wDontPlayMapMusicOnReload], a ; play map music diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index efdf19f5a..9fa83ff66 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -110,8 +110,6 @@ EnterMap: ld [wXYComparePointer], a ld [wXYComparePointer + 1], a call SetUpFiveStepWildEncounterCooldown - ld hl, wTextboxFlags - set TEXT_2BPP_F, [hl] farcall RunMapSetupScript call DisableEvents @@ -128,9 +126,6 @@ EnterMap: ld [wPoisonStepCount], a .dontresetpoison - call ConstructOverworldHUDTilemap - call EnableOverworldHUD - xor a ; end map entry ldh [hMapEntryMethod], a ld a, MAPSTATUS_HANDLE diff --git a/home/hud.asm b/home/hud.asm index e36d7ffdd..d99d72c7c 100755 --- a/home/hud.asm +++ b/home/hud.asm @@ -117,3 +117,10 @@ endr pop af ld [rVBK], a ret + +ConstructAndEnableOverworldHUD:: +; map setup command used by MAPSETUP_ENTERLEVEL and MAPSETUP_CONTINUE + ld hl, wTextboxFlags + set TEXT_2BPP_F, [hl] + call ConstructOverworldHUDTilemap + jp EnableOverworldHUD diff --git a/home/window.asm b/home/window.asm index 4aea5a2e0..9321ecebe 100644 --- a/home/window.asm +++ b/home/window.asm @@ -67,6 +67,7 @@ OpenText1bpp:: ld a, BANK(ReanchorBGMap_NoOAMUpdate) ; aka BANK(LoadFont_NoOAMUpdate) rst Bankswitch + ; note: 1bpp text is NOT compatible with the overworld HUD enabled because it uses 2bpp font tiles. ld hl, wTextboxFlags res TEXT_2BPP_F, [hl]