diff --git a/constants/menu_constants.asm b/constants/menu_constants.asm index 69189f787..626dcefe2 100644 --- a/constants/menu_constants.asm +++ b/constants/menu_constants.asm @@ -115,8 +115,8 @@ DEF NUM_NAME_TYPES EQU const_value ; Board menu items (see engine/board/menu.asm) const_def const BOARDMENUITEM_DIE - const BOARDMENUITEM_POKEMON - const BOARDMENUITEM_BAG + const BOARDMENUITEM_PARTY + const BOARDMENUITEM_PACK const BOARDMENUITEM_POKEGEAR const BOARDMENUITEM_EXIT DEF NUM_BOARD_MENU_ITEMS EQU const_value diff --git a/constants/script_constants.asm b/constants/script_constants.asm index a1a7033a9..50df3c2a4 100644 --- a/constants/script_constants.asm +++ b/constants/script_constants.asm @@ -322,3 +322,8 @@ DEF NUM_UNOWN_PUZZLES EQU const_value const MOVETUTOR_FLAMETHROWER ; 1 const MOVETUTOR_THUNDERBOLT ; 2 const MOVETUTOR_ICE_BEAM ; 3 + +; board events (tracked by hCurBoardEvent) + const_def 1 + const BOARDEVENT_DISPLAY_MENU ; 1 +DEF NUM_BOARD_EVENTS EQU const_value - 1 diff --git a/data/sprites/secondary_sprites.asm b/data/sprites/secondary_sprites.asm index dd0a1456c..4ef9e7bf8 100755 --- a/data/sprites/secondary_sprites.asm +++ b/data/sprites/secondary_sprites.asm @@ -9,7 +9,7 @@ BoardMenuOAM: dbsprite 2, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 6, PAL_OW_MISC dbsprite 3, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 7, PAL_OW_MISC dbsprite 4, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 8, PAL_OW_MISC -; BOARDMENUITEM_POKEMON +; BOARDMENUITEM_PARTY dbsprite 6, 16, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 9, PAL_OW_MISC dbsprite 7, 16, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 10, PAL_OW_MISC dbsprite 8, 16, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 11, PAL_OW_MISC @@ -19,7 +19,7 @@ BoardMenuOAM: dbsprite 6, 18, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 15, PAL_OW_MISC dbsprite 7, 18, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 16, PAL_OW_MISC dbsprite 8, 18, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 17, PAL_OW_MISC -; BOARDMENUITEM_BAG +; BOARDMENUITEM_PACK dbsprite 9, 16, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 18, PAL_OW_MISC dbsprite 10, 16, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 19, PAL_OW_MISC dbsprite 11, 16, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 20, PAL_OW_MISC diff --git a/engine/board/menu.asm b/engine/board/menu.asm index 6a4b33229..f0c2390f9 100755 --- a/engine/board/menu.asm +++ b/engine/board/menu.asm @@ -1,3 +1,70 @@ +BoardMenuScript:: + opentext +.display_menu + callasm BoardMenu + ifequal BOARDMENUITEM_DIE, .Die + ifequal BOARDMENUITEM_PARTY, .Party + ifequal BOARDMENUITEM_PACK, .Pack + ifequal BOARDMENUITEM_POKEGEAR, .Pokegear + ifequal BOARDMENUITEM_EXIT, .Exit + closetext + end + +.Die: + closetext + end + +.Party: + callasm BoardMenu_Party + scall .SubmenuCallback + sjump .display_menu + +.Pack: + callasm BoardMenu_Pack + scall .SubmenuCallback + sjump .display_menu + +.Pokegear: + callasm BoardMenu_Pokegear + scall .SubmenuCallback + sjump .display_menu + +.Exit: + writetext .EmptyText + callasm RestoreOverworldFontOverBoardMenuGFX + writetext .ConfirmExitText + yesorno + iftrue .exit + writetext .EmptyText + sjump .display_menu + +.exit: + exitoverworld $00 + +.ConfirmExitText: + text "Abandon level and" + line "return to menu?" + done + +.EmptyText: + text "" + done + +.SubmenuCallback: +; if submenu has requested a callback through hMenuReturn, +; it has also taken care of queuing it into wQueuedScriptBank/wQueuedScriptAddr. + readmem hMenuReturn + ifequal HMENURETURN_SCRIPT, .CallbackScript + ifequal HMENURETURN_ASM, .CallbackAsm + end + +.CallbackScript: + memjump wQueuedScriptBank + +.CallbackAsm: + memcallasm wQueuedScriptBank + end + BoardMenu:: ; returns the selected menu item (BOARDMENUITEM_*) in wScriptVar upon exit ld a, [wBoardMenuLastCursorPosition] @@ -56,10 +123,16 @@ ApplyBoardMenuSpritePalette: ld a, [wBoardMenuCursorPosition] ld bc, PALETTE_SIZE call AddNTimes - ; set wOBPals2 directly rather than wOBPals1 to avoid calling ApplyPals and overwriting other overworld pals +; write to wOBPals2 directly as well to avoid calling ApplyPals and overwriting other overworld pals +; writing to wOBPals1 is still necessary to make fading animations consistent + ld de, wOBPals1 palette PAL_OW_MISC + ld bc, PALETTE_SIZE + ld a, BANK(wOBPals1) + call FarCopyWRAM + ld hl, wOBPals1 palette PAL_OW_MISC ld de, wOBPals2 palette PAL_OW_MISC ld bc, PALETTE_SIZE - ld a, BANK(wOBPals2) + ld a, BANK(wOBPals1) call FarCopyWRAM ld a, TRUE ldh [hCGBPalUpdate], a @@ -107,5 +180,73 @@ GetBoardMenuSelection: xor a ret ; nc +BoardMenu_Party: + ld a, [wPartyCount] + and a + ret z + + call BoardMenu_OpenSubmenu + farcall Party + jr nc, .quit + +.return +; if cancelled or pressed B + call BoardMenu_CloseSubmenu + ret + +.quit +; if quitted party menu after using field move + call BoardMenu_CloseSubmenu + ld a, HMENURETURN_SCRIPT + ldh [hMenuReturn], a + ret + +BoardMenu_Pack: + call BoardMenu_OpenSubmenu + farcall Pack + call BoardMenu_CloseSubmenu + ld a, [wPackUsedItem] + and a + ret z + ld a, HMENURETURN_SCRIPT + ldh [hMenuReturn], a + ret + +BoardMenu_Pokegear: + call BoardMenu_OpenSubmenu + farcall PokeGear + jp BoardMenu_CloseSubmenu + +BoardMenu_OpenSubmenu: + xor a + ldh [hMenuReturn], a + ldh [hBGMapMode], a + call LoadStandardMenuHeader + farcall FadeOutPalettesToWhite + call DisableOverworldHUD + ld hl, wTextboxFlags + res TEXT_2BPP_F, [hl] + call LoadStandardFont + call LoadFrame + call ClearSprites + call DisableSpriteUpdates + ret + +BoardMenu_CloseSubmenu: + call ClearBGPalettes + ld hl, wTextboxFlags + set TEXT_2BPP_F, [hl] + call EnableOverworldHUD + call ReloadTilesetAndPalettes + call UpdateSprites + call ExitMenu + call ClearTextbox + ld b, CGB_MAPPALS + call GetCGBLayout + call WaitBGMap2 + farcall FadeInPalettesFromWhite + call EnableSpriteUpdates + ret + BoardMenuItemPals: INCLUDE "gfx/board/menu.pal" diff --git a/engine/events/overworld.asm b/engine/events/overworld.asm index a0ffc9705..3f537aae8 100644 --- a/engine/events/overworld.asm +++ b/engine/events/overworld.asm @@ -1706,10 +1706,6 @@ Script_GetOnBike_Register: special UpdatePlayerSprite end -Overworld_DummyFunction: ; unreferenced - nop - ret - Script_GetOffBike: reloadmappart special UpdateTimePals diff --git a/engine/gfx/load_board_gfx.asm b/engine/gfx/load_board_gfx.asm index b1ad90156..b3724d4ff 100755 --- a/engine/gfx/load_board_gfx.asm +++ b/engine/gfx/load_board_gfx.asm @@ -15,8 +15,8 @@ INCBIN "gfx/board/menu.2bpp" .BoardMenuOAMGFX: table_width 3 * 3 * LEN_2BPP_TILE, .BoardMenuOAMGFX INCBIN "gfx/board/menu_die.2bpp" -INCBIN "gfx/board/menu_pokemon.2bpp" -INCBIN "gfx/board/menu_bag.2bpp" +INCBIN "gfx/board/menu_party.2bpp" +INCBIN "gfx/board/menu_pack.2bpp" INCBIN "gfx/board/menu_pokegear.2bpp" INCBIN "gfx/board/menu_exit.2bpp" assert_table_length NUM_BOARD_MENU_ITEMS diff --git a/engine/gfx/load_overworld_font.asm b/engine/gfx/load_overworld_font.asm index 16c043387..e7b28fcb7 100644 --- a/engine/gfx/load_overworld_font.asm +++ b/engine/gfx/load_overworld_font.asm @@ -1,36 +1,41 @@ _LoadOverworldFontAndFrame:: - ld de, .OverworldFontGFX + ld de, OverworldFontGFX ld hl, vTiles1 - lb bc, BANK(.OverworldFontGFX), 64 + lb bc, BANK(OverworldFontGFX), 64 call Get2bppViaHDMA - ld de, .OverworldFontGFX + 64 * LEN_2BPP_TILE + ld de, OverworldFontGFX + 64 * LEN_2BPP_TILE ld hl, vTiles1 tile $40 - lb bc, BANK(.OverworldFontGFX), 56 + lb bc, BANK(OverworldFontGFX), 48 call Get2bppViaHDMA - ld de, .OverworldFontSpaceGFX + ld de, OverworldFontSpaceGFX ld hl, vTiles2 tile " " - lb bc, BANK(.OverworldFontSpaceGFX), 1 + lb bc, BANK(OverworldFontSpaceGFX), 1 call Get2bppViaHDMA ld a, [wEnvironment] maskbits NUM_ENVIRONMENTS ld bc, OW_TEXTBOX_FRAME_TILES * LEN_2BPP_TILE - ld hl, .OverworldFrames + ld hl, OverworldFrames call AddNTimes ld d, h ld e, l ld hl, vTiles0 tile OVERWORLD_FRAME_FIRST_TILE ; $f0 - lb bc, BANK(.OverworldFrames), OW_TEXTBOX_FRAME_TILES - call Get2bppViaHDMA - ret + lb bc, BANK(OverworldFrames), OW_TEXTBOX_FRAME_TILES + jp Get2bppViaHDMA -.OverworldFontGFX: +RestoreOverworldFontOverBoardMenuGFX:: + ld de, OverworldFontGFX + ld hl, vTiles1 + lb bc, BANK(OverworldFontGFX), 18 * 3 + jp Get2bppViaHDMA + +OverworldFontGFX: INCBIN "gfx/font/overworld.2bpp" -.OverworldFontSpaceGFX: +OverworldFontSpaceGFX: INCBIN "gfx/font/overworld_space.2bpp" -.OverworldFrames: - table_width OW_TEXTBOX_FRAME_TILES * LEN_2BPP_TILE, .OverworldFrames +OverworldFrames: + table_width OW_TEXTBOX_FRAME_TILES * LEN_2BPP_TILE, OverworldFrames INCBIN "gfx/frames/ow1.2bpp" INCBIN "gfx/frames/ow2.2bpp" INCBIN "gfx/frames/ow3.2bpp" diff --git a/engine/menus/start_menu.asm b/engine/menus/start_menu.asm index a4f04671d..33ad45955 100644 --- a/engine/menus/start_menu.asm +++ b/engine/menus/start_menu.asm @@ -501,35 +501,8 @@ StartMenu_Pokemon: jr z, .return call FadeToMenu - -.choosemenu - xor a - ld [wPartyMenuActionText], a ; Choose a POKéMON. - call ClearBGPalettes - -.menu - farcall LoadPartyMenuGFX - farcall InitPartyMenuWithCancel - farcall InitPartyMenuGFX - -.menunoreload - farcall WritePartyMenuTilemap - farcall PlacePartyMenuText - call WaitBGMap - call SetPalettes ; load regular palettes? - call DelayFrame - farcall PartyMenuSelect - jr c, .return ; if cancelled or pressed B - - call PokemonActionSubmenu - cp 3 - jr z, .menu - cp 0 - jr z, .choosemenu - cp 1 - jr z, .menunoreload - cp 2 - jr z, .quit + farcall Party + jr nc, .quit .return call CloseSubmenu diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index c3ed8ca50..2c4fb4615 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -11,6 +11,9 @@ OverworldLoop:: cp MAPSTATUS_DONE jr nz, .loop .done + call DisableOverworldHUD + ld hl, wGameTimerPaused + res GAME_TIMER_PAUSED_F, [hl] ; stop game timer counter ret .Jumptable: @@ -105,6 +108,8 @@ StartMap: call ByteFill farcall InitCallReceiveDelay call ClearJoypad + ld a, BOARDEVENT_DISPLAY_MENU + ld [hCurBoardEvent], a EnterMap: xor a ld [wXYComparePointer], a @@ -238,6 +243,9 @@ PlayerEvents: and a ret nz + call CheckBoardEvent + jr c, .ok + call CheckTrainerBattle_GetPlayerEvent jr c, .ok @@ -269,6 +277,28 @@ PlayerEvents: scf ret +CheckBoardEvent: + jumptable .Jumptable, hCurBoardEvent + +.Jumptable: + table_width 2, .Jumptable + dw .none + dw .menu + assert_table_length NUM_BOARD_EVENTS + 1 + +.none + xor a + ret + +.menu + ld a, BANK(BoardMenuScript) + ld hl, BoardMenuScript + call CallScript + xor a + ld [hCurBoardEvent], a + scf + ret + CheckTrainerBattle_GetPlayerEvent: call CheckTrainerBattle jr nc, .nope diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm index 12ab4ee84..65c802ab9 100644 --- a/engine/overworld/scripting.asm +++ b/engine/overworld/scripting.asm @@ -234,6 +234,7 @@ ScriptCommandTable: dw Script_getname ; a7 dw Script_wait ; a8 dw Script_checksave ; a9 + dw Script_exitoverworld ; aa assert_table_length NUM_EVENT_COMMANDS StartScript: @@ -2329,6 +2330,14 @@ ReturnFromCredits: call StopScript ret +Script_exitoverworld: + call GetScriptByte + call Script_endall + ld a, MAPSTATUS_DONE + call LoadMapStatus + call StopScript + ret + Script_wait: push bc call GetScriptByte diff --git a/engine/pokemon/mon_menu.asm b/engine/pokemon/mon_menu.asm index 4c6ed3a21..7972f7944 100644 --- a/engine/pokemon/mon_menu.asm +++ b/engine/pokemon/mon_menu.asm @@ -104,6 +104,37 @@ CancelPokemonAction: ld a, 1 ret +Party:: +.choosemenu + xor a + ld [wPartyMenuActionText], a ; Choose a POKéMON. + call ClearBGPalettes + +.menu + farcall LoadPartyMenuGFX + farcall InitPartyMenuWithCancel + farcall InitPartyMenuGFX + +.menunoreload + farcall WritePartyMenuTilemap + farcall PlacePartyMenuText + call WaitBGMap + call SetPalettes ; load regular palettes? + call DelayFrame + farcall PartyMenuSelect + ret c ; if cancelled or pressed B + + call PokemonActionSubmenu + and 3 + cp 3 + jr z, .menu + cp 0 + jr z, .choosemenu + cp 1 + jr z, .menunoreload + and a ; must be 2, which means quit after using field move + ret ; nc + PokemonActionSubmenu: hlcoord 1, 15 lb bc, 2, 18 diff --git a/gfx/board/menu.pal b/gfx/board/menu.pal index 980d2d7dd..5205defa5 100755 --- a/gfx/board/menu.pal +++ b/gfx/board/menu.pal @@ -4,13 +4,13 @@ RGB 00, 00, 21 RGB 00, 00, 00 -; item 2 (BOARDMENUITEM_POKEMON) +; item 2 (BOARDMENUITEM_PARTY) RGB 31, 31, 31 RGB 31, 26, 26 RGB 30, 00, 00 RGB 00, 00, 00 -; item 3 (BOARDMENUITEM_BAG) +; item 3 (BOARDMENUITEM_PACK) RGB 31, 31, 31 RGB 10, 31, 10 RGB 00, 21, 10 diff --git a/gfx/board/menu_bag.png b/gfx/board/menu_pack.png similarity index 100% rename from gfx/board/menu_bag.png rename to gfx/board/menu_pack.png diff --git a/gfx/board/menu_pokemon.png b/gfx/board/menu_party.png similarity index 100% rename from gfx/board/menu_pokemon.png rename to gfx/board/menu_party.png diff --git a/home/map.asm b/home/map.asm index e68f8ccea..b2e83ad2e 100644 --- a/home/map.asm +++ b/home/map.asm @@ -1916,7 +1916,7 @@ ReturnToMapWithSpeechTextbox:: call ClearBGPalettes call ClearSprites call ReloadTilesetAndPalettes - call SpeechTextbox1bpp + call SpeechTextbox ; 1bpp or 2bpp according to wTextboxFlags[TEXT_2BPP_F] ld hl, wVramState set 0, [hl] call UpdateSprites @@ -1934,8 +1934,15 @@ ReloadTilesetAndPalettes:: call DisableLCD call ClearSprites farcall RefreshSprites + ld a, [wTextboxFlags] + bit TEXT_2BPP_F, a + jr nz, .2bpp call LoadStandardFont call LoadFrame + jr .font_done +.2bpp + call LoadOverworldFontAndFrame +.font_done ldh a, [hROMBank] push af ld a, [wMapGroup] diff --git a/home/text.asm b/home/text.asm index 342b0dfe0..d282e3ed6 100644 --- a/home/text.asm +++ b/home/text.asm @@ -165,6 +165,13 @@ Textbox2bpp:: pop bc jp TextboxAttributes2bpp +SpeechTextbox: +; Standard 1bpp or 2bpp textbox according to wTextboxFlags[TEXT_2BPP_F] + ld a, [wTextboxFlags] + bit TEXT_2BPP_F, a + jr z, SpeechTextbox1bpp + jr SpeechTextbox2bpp + RadioTerminator:: ld hl, .stop ret @@ -172,7 +179,7 @@ RadioTerminator:: .stop: text_end -ClearTextbox: +ClearTextbox:: hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY lb bc, TEXTBOX_INNERH - 1, TEXTBOX_INNERW jp ClearBox diff --git a/macros/code.asm b/macros/code.asm index da1c4776d..bb3b904ba 100644 --- a/macros/code.asm +++ b/macros/code.asm @@ -11,7 +11,11 @@ ENDM ; Design patterns MACRO jumptable +if STRIN("\2", "h") == 1 + ldh a, [\2] +else ld a, [\2] +endc ld e, a ld d, 0 ld hl, \1 diff --git a/macros/scripts/events.asm b/macros/scripts/events.asm index fb048daf4..9efe98c02 100644 --- a/macros/scripts/events.asm +++ b/macros/scripts/events.asm @@ -1065,4 +1065,10 @@ MACRO checksave db checksave_command ENDM + const exitoverworld_command ; $aa +MACRO exitoverworld + db exitoverworld_command + db \1 ; exit reason +ENDM + DEF NUM_EVENT_COMMANDS EQU const_value diff --git a/ram/hram.asm b/ram/hram.asm index ec5abe56a..22b07f59b 100644 --- a/ram/hram.asm +++ b/ram/hram.asm @@ -152,3 +152,5 @@ hWindowHUDLY:: ; Window HUD is enabled when non-0. ; Its value indicates the last scanline that the window spans from the top. db + +hCurBoardEvent:: db