pokecrystal/engine/menus/start_menu.asm

542 lines
8.7 KiB
NASM
Raw Normal View History

; StartMenu.Items indexes
const_def
const STARTMENUITEM_POKEDEX ; 0
const STARTMENUITEM_POKEMON ; 1
const STARTMENUITEM_PACK ; 2
const STARTMENUITEM_STATUS ; 3
const STARTMENUITEM_SAVE ; 4
const STARTMENUITEM_OPTION ; 5
const STARTMENUITEM_EXIT ; 6
const STARTMENUITEM_POKEGEAR ; 7
const STARTMENUITEM_QUIT ; 8
2018-06-24 14:09:41 +00:00
StartMenu::
call ClearWindowData
2015-11-11 21:11:08 +00:00
ld de, SFX_MENU
call PlaySFX
2017-12-24 17:47:30 +00:00
farcall ReanchorBGMap_NoOAMUpdate
2015-11-11 21:11:08 +00:00
ld hl, wStatusFlags2
2018-01-22 20:40:43 +00:00
bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
ld hl, .MenuHeader
2015-11-11 21:11:08 +00:00
jr z, .GotMenuData
ld hl, .ContestMenuHeader
2015-11-11 21:11:08 +00:00
2018-06-25 16:24:18 +00:00
.GotMenuData:
call LoadMenuHeader
2015-11-11 21:11:08 +00:00
call .SetUpMenuItems
2017-12-10 00:41:03 +00:00
ld a, [wBattleMenuCursorBuffer]
2015-11-11 21:11:08 +00:00
ld [wMenuCursorBuffer], a
call .DrawMenuAccount
call DrawVariableLengthMenuBox
2015-11-11 21:11:08 +00:00
call .DrawBugContestStatusBox
call SafeUpdateSprites
call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap
2017-12-24 17:47:30 +00:00
farcall LoadFonts_NoOAMUpdate
2015-11-11 21:11:08 +00:00
call .DrawBugContestStatus
call UpdateTimePals
jr .Select
.Reopen:
2015-11-11 21:11:08 +00:00
call UpdateSprites
call UpdateTimePals
call .SetUpMenuItems
2017-12-10 00:41:03 +00:00
ld a, [wBattleMenuCursorBuffer]
2015-11-11 21:11:08 +00:00
ld [wMenuCursorBuffer], a
.Select:
2015-11-11 21:11:08 +00:00
call .GetInput
jr c, .Exit
call ._DrawMenuAccount
2015-11-11 21:11:08 +00:00
ld a, [wMenuCursorBuffer]
2017-12-10 00:41:03 +00:00
ld [wBattleMenuCursorBuffer], a
2015-11-11 21:11:08 +00:00
call PlayClickSFX
2015-12-18 03:31:16 +00:00
call PlaceHollowCursor
2015-11-11 21:11:08 +00:00
call .OpenMenu
; Menu items have different return functions.
; For example, saving exits the menu.
ld hl, .MenuReturns
ld e, a
ld d, 0
add hl, de
2015-12-27 02:59:03 +00:00
add hl, de
2015-11-11 21:11:08 +00:00
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
2015-11-11 21:11:08 +00:00
.MenuReturns:
2015-11-11 21:11:08 +00:00
dw .Reopen
dw .Exit
2015-11-25 15:16:29 +00:00
dw .ExitMenuCallFuncCloseText
dw .ExitMenuRunScriptCloseText
2015-11-11 21:11:08 +00:00
dw .ExitMenuRunScript
dw .ReturnEnd
dw .ReturnRedraw
.Exit:
ldh a, [hOAMUpdate]
2015-11-11 21:11:08 +00:00
push af
ld a, 1
ldh [hOAMUpdate], a
2015-11-11 21:11:08 +00:00
call LoadFontsExtra
pop af
ldh [hOAMUpdate], a
.ReturnEnd:
2015-11-11 21:11:08 +00:00
call ExitMenu
.ReturnEnd2:
2015-11-25 15:16:29 +00:00
call CloseText
2015-11-11 21:11:08 +00:00
call UpdateTimePals
ret
.GetInput:
2015-11-11 21:11:08 +00:00
; Return carry on exit, and no-carry on selection.
xor a
ldh [hBGMapMode], a
call ._DrawMenuAccount
2015-11-11 21:11:08 +00:00
call SetUpMenu
ld a, $ff
2018-01-23 22:39:09 +00:00
ld [wMenuSelection], a
2015-11-11 21:11:08 +00:00
.loop
call .PrintMenuAccount
2016-03-02 03:31:21 +00:00
call GetScrollingMenuJoypad
2015-12-15 23:59:49 +00:00
ld a, [wMenuJoypad]
2015-11-11 21:11:08 +00:00
cp B_BUTTON
jr z, .b
cp A_BUTTON
jr z, .a
jr .loop
.a
call PlayClickSFX
and a
ret
.b
scf
ret
2018-06-24 14:09:41 +00:00
.ExitMenuRunScript:
2015-11-11 21:11:08 +00:00
call ExitMenu
ld a, HMENURETURN_SCRIPT
ldh [hMenuReturn], a
2015-11-11 21:11:08 +00:00
ret
2018-06-24 14:09:41 +00:00
.ExitMenuRunScriptCloseText:
2015-11-11 21:11:08 +00:00
call ExitMenu
ld a, HMENURETURN_SCRIPT
ldh [hMenuReturn], a
2015-11-11 21:11:08 +00:00
jr .ReturnEnd2
2018-06-24 14:09:41 +00:00
.ExitMenuCallFuncCloseText:
2015-11-11 21:11:08 +00:00
call ExitMenu
ld hl, wQueuedScriptAddr
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wQueuedScriptBank]
rst FarCall
jr .ReturnEnd2
2018-06-24 14:09:41 +00:00
.ReturnRedraw:
2015-11-11 21:11:08 +00:00
call .Clear
jp .Reopen
2018-06-24 14:09:41 +00:00
.Clear:
2015-11-12 04:38:57 +00:00
call ClearBGPalettes
2015-11-11 21:11:08 +00:00
call Call_ExitMenu
2015-12-19 01:07:09 +00:00
call ReloadTilesetAndPalettes
call .DrawMenuAccount
call DrawVariableLengthMenuBox
2015-11-11 21:11:08 +00:00
call .DrawBugContestStatus
call UpdateSprites
2015-12-09 16:38:40 +00:00
call ret_d90
2016-01-06 12:44:50 +00:00
call FinishExitMenu
2015-11-11 21:11:08 +00:00
ret
.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 10, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
2015-11-11 21:11:08 +00:00
dw .MenuData
db 1 ; default selection
.ContestMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 10, 2, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
2015-11-11 21:11:08 +00:00
dw .MenuData
db 1 ; default selection
.MenuData:
db STATICMENU_CURSOR | STATICMENU_WRAP | STATICMENU_ENABLE_START ; flags
2015-11-11 21:11:08 +00:00
dn 0, 0 ; rows, columns
2018-01-23 22:39:09 +00:00
dw wMenuItemsList
2015-11-11 21:11:08 +00:00
dw .MenuString
dw .Items
.Items:
; entries correspond to STARTMENUITEM_* constants
2015-11-11 21:11:08 +00:00
dw StartMenu_Pokedex, .PokedexString, .PokedexDesc
dw StartMenu_Pokemon, .PartyString, .PartyDesc
dw StartMenu_Pack, .PackString, .PackDesc
dw StartMenu_Status, .StatusString, .StatusDesc
dw StartMenu_Save, .SaveString, .SaveDesc
dw StartMenu_Option, .OptionString, .OptionDesc
dw StartMenu_Exit, .ExitString, .ExitDesc
dw StartMenu_Pokegear, .PokegearString, .PokegearDesc
dw StartMenu_Quit, .QuitString, .QuitDesc
.PokedexString: db "#DEX@"
.PartyString: db "#MON@"
.PackString: db "PACK@"
.StatusString: db "<PLAYER>@"
.SaveString: db "SAVE@"
.OptionString: db "OPTION@"
.ExitString: db "EXIT@"
.PokegearString: db "<POKE>GEAR@"
.QuitString: db "QUIT@"
.PokedexDesc:
db "#MON"
2016-06-07 12:13:08 +00:00
next "database@"
2015-11-11 21:11:08 +00:00
.PartyDesc:
db "Party <PKMN>"
2016-06-07 12:13:08 +00:00
next "status@"
2015-11-11 21:11:08 +00:00
.PackDesc:
db "Contains"
2016-06-07 12:13:08 +00:00
next "items@"
2015-11-11 21:11:08 +00:00
.PokegearDesc:
db "Trainer's"
2016-06-07 12:13:08 +00:00
next "key device@"
2015-11-11 21:11:08 +00:00
.StatusDesc:
db "Your own"
2016-06-07 12:13:08 +00:00
next "status@"
2015-11-11 21:11:08 +00:00
.SaveDesc:
db "Save your"
2016-06-07 12:13:08 +00:00
next "progress@"
2015-11-11 21:11:08 +00:00
.OptionDesc:
db "Change"
2016-06-07 12:13:08 +00:00
next "settings@"
2015-11-11 21:11:08 +00:00
.ExitDesc:
db "Close this"
2016-06-07 12:13:08 +00:00
next "menu@"
2015-11-11 21:11:08 +00:00
.QuitDesc:
db "Quit and"
2016-06-07 12:13:08 +00:00
next "be judged.@"
2015-11-11 21:11:08 +00:00
2018-06-24 14:09:41 +00:00
.OpenMenu:
2018-01-23 22:39:09 +00:00
ld a, [wMenuSelection]
2015-11-11 21:11:08 +00:00
call .GetMenuAccountTextPointer
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
2015-11-11 21:11:08 +00:00
2018-06-24 14:09:41 +00:00
.MenuString:
2015-11-11 21:11:08 +00:00
push de
2018-01-23 22:39:09 +00:00
ld a, [wMenuSelection]
2015-11-11 21:11:08 +00:00
call .GetMenuAccountTextPointer
inc hl
2015-12-27 02:59:03 +00:00
inc hl
2015-11-11 21:11:08 +00:00
ld a, [hli]
ld d, [hl]
ld e, a
pop hl
call PlaceString
ret
2018-06-24 14:09:41 +00:00
.MenuDesc:
2015-11-11 21:11:08 +00:00
push de
2018-01-23 22:39:09 +00:00
ld a, [wMenuSelection]
2015-11-11 21:11:08 +00:00
cp $ff
jr z, .none
call .GetMenuAccountTextPointer
rept 4
inc hl
endr
ld a, [hli]
ld d, [hl]
ld e, a
pop hl
call PlaceString
ret
.none
pop de
ret
2018-06-24 14:09:41 +00:00
.GetMenuAccountTextPointer:
2015-11-11 21:11:08 +00:00
ld e, a
ld d, 0
ld hl, wMenuDataPointerTableAddr
2015-11-11 21:11:08 +00:00
ld a, [hli]
ld h, [hl]
ld l, a
rept 6
add hl, de
endr
ret
2018-06-24 14:09:41 +00:00
.SetUpMenuItems:
2015-11-11 21:11:08 +00:00
xor a
2015-12-19 01:07:09 +00:00
ld [wWhichIndexSet], a
2015-11-11 21:11:08 +00:00
call .FillMenuList
ld hl, wStatusFlags
2018-01-22 20:40:43 +00:00
bit STATUSFLAGS_POKEDEX_F, [hl]
2015-11-11 21:11:08 +00:00
jr z, .no_pokedex
ld a, STARTMENUITEM_POKEDEX
2015-11-11 21:11:08 +00:00
call .AppendMenuList
.no_pokedex
2018-01-23 22:39:09 +00:00
ld a, [wPartyCount]
2015-11-11 21:11:08 +00:00
and a
jr z, .no_pokemon
ld a, STARTMENUITEM_POKEMON
2015-11-11 21:11:08 +00:00
call .AppendMenuList
.no_pokemon
ld a, [wLinkMode]
and a
jr nz, .no_pack
ld hl, wStatusFlags2
2018-01-22 20:40:43 +00:00
bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
2015-11-11 21:11:08 +00:00
jr nz, .no_pack
ld a, STARTMENUITEM_PACK
2015-11-11 21:11:08 +00:00
call .AppendMenuList
.no_pack
ld hl, wPokegearFlags
bit POKEGEAR_OBTAINED_F, [hl]
2015-11-11 21:11:08 +00:00
jr z, .no_pokegear
ld a, STARTMENUITEM_POKEGEAR
2015-11-11 21:11:08 +00:00
call .AppendMenuList
.no_pokegear
2018-01-22 20:40:43 +00:00
ld a, STARTMENUITEM_STATUS
2015-11-11 21:11:08 +00:00
call .AppendMenuList
ld a, [wLinkMode]
and a
jr nz, .no_save
ld hl, wStatusFlags2
2018-01-22 20:40:43 +00:00
bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
ld a, STARTMENUITEM_QUIT
2015-11-11 21:11:08 +00:00
jr nz, .write
ld a, STARTMENUITEM_SAVE
2015-11-11 21:11:08 +00:00
.write
call .AppendMenuList
.no_save
ld a, STARTMENUITEM_OPTION
2015-11-11 21:11:08 +00:00
call .AppendMenuList
ld a, STARTMENUITEM_EXIT
2015-11-11 21:11:08 +00:00
call .AppendMenuList
ld a, c
2018-01-23 22:39:09 +00:00
ld [wMenuItemsList], a
2015-11-11 21:11:08 +00:00
ret
2018-06-24 14:09:41 +00:00
.FillMenuList:
2015-11-11 21:11:08 +00:00
xor a
2018-01-23 22:39:09 +00:00
ld hl, wMenuItemsList
2015-11-11 21:11:08 +00:00
ld [hli], a
ld a, -1
2018-01-23 22:39:09 +00:00
ld bc, wMenuItemsListEnd - (wMenuItemsList + 1)
2015-11-11 21:11:08 +00:00
call ByteFill
2018-01-23 22:39:09 +00:00
ld de, wMenuItemsList + 1
2015-11-11 21:11:08 +00:00
ld c, 0
ret
2018-06-24 14:09:41 +00:00
.AppendMenuList:
2015-11-11 21:11:08 +00:00
ld [de], a
inc de
inc c
ret
.DrawMenuAccount:
jp ._DrawMenuAccount
2015-11-11 21:11:08 +00:00
2018-06-24 14:09:41 +00:00
.PrintMenuAccount:
2015-11-11 21:11:08 +00:00
call .IsMenuAccountOn
ret z
call ._DrawMenuAccount
2015-11-11 21:11:08 +00:00
decoord 0, 14
jp .MenuDesc
._DrawMenuAccount:
2015-11-11 21:11:08 +00:00
call .IsMenuAccountOn
ret z
hlcoord 0, 13
lb bc, 5, 10
call ClearBox
hlcoord 0, 13
ld b, 3
ld c, 8
2019-04-08 12:15:10 +00:00
jp TextboxPalette
2015-11-11 21:11:08 +00:00
2018-06-24 14:09:41 +00:00
.IsMenuAccountOn:
2018-01-23 22:39:09 +00:00
ld a, [wOptions2]
and 1 << MENU_ACCOUNT
2015-11-11 21:11:08 +00:00
ret
2018-06-24 14:09:41 +00:00
.DrawBugContestStatusBox:
ld hl, wStatusFlags2
2018-01-22 20:40:43 +00:00
bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
2015-11-11 21:11:08 +00:00
ret z
2017-12-24 17:47:30 +00:00
farcall StartMenu_DrawBugContestStatusBox
2015-11-11 21:11:08 +00:00
ret
2018-06-24 14:09:41 +00:00
.DrawBugContestStatus:
ld hl, wStatusFlags2
2018-01-22 20:40:43 +00:00
bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
2015-11-11 21:11:08 +00:00
jr nz, .contest
ret
.contest
2017-12-24 17:47:30 +00:00
farcall StartMenu_PrintBugContestStatus
2015-11-11 21:11:08 +00:00
ret
2018-06-24 14:09:41 +00:00
StartMenu_Exit:
2015-11-11 21:11:08 +00:00
; Exit the menu.
ld a, 1
ret
2018-06-24 14:09:41 +00:00
StartMenu_Quit:
2015-11-11 21:11:08 +00:00
; Retire from the bug catching contest.
ld hl, .StartMenuContestEndText
2015-11-17 22:56:49 +00:00
call StartMenuYesNo
2015-11-11 21:11:08 +00:00
jr c, .DontEndContest
ld a, BANK(BugCatchingContestReturnToGateScript)
ld hl, BugCatchingContestReturnToGateScript
call FarQueueScript
ld a, 4
ret
.DontEndContest:
2015-11-11 21:11:08 +00:00
ld a, 0
ret
.StartMenuContestEndText:
text_far _StartMenuContestEndText
text_end
2015-11-11 21:11:08 +00:00
2018-06-24 14:09:41 +00:00
StartMenu_Save:
2015-11-11 21:11:08 +00:00
; Save the game.
call BufferScreen
2017-12-24 17:47:30 +00:00
farcall SaveMenu
2015-11-11 21:11:08 +00:00
jr nc, .asm_12919
ld a, 0
ret
.asm_12919
ld a, 1
ret
2018-06-24 14:09:41 +00:00
StartMenu_Option:
2015-11-11 21:11:08 +00:00
; Game options.
call FadeToMenu
2017-12-24 17:47:30 +00:00
farcall OptionsMenu
2015-11-11 21:11:08 +00:00
ld a, 6
ret
2018-06-24 14:09:41 +00:00
StartMenu_Status:
2015-11-11 21:11:08 +00:00
; Player status.
call FadeToMenu
2017-12-24 17:47:30 +00:00
farcall TrainerCard
call CloseSubmenu
2015-11-11 21:11:08 +00:00
ld a, 0
ret
2018-06-24 14:09:41 +00:00
StartMenu_Pokedex:
2018-01-23 22:39:09 +00:00
ld a, [wPartyCount]
2015-11-11 21:11:08 +00:00
and a
jr z, .asm_12949
call FadeToMenu
2017-12-24 17:47:30 +00:00
farcall Pokedex
call CloseSubmenu
2015-11-11 21:11:08 +00:00
.asm_12949
ld a, 0
ret
2018-06-24 14:09:41 +00:00
StartMenu_Pokegear:
2015-11-11 21:11:08 +00:00
call FadeToMenu
2017-12-24 17:47:30 +00:00
farcall PokeGear
call CloseSubmenu
2015-11-11 21:11:08 +00:00
ld a, 0
ret
2018-06-24 14:09:41 +00:00
StartMenu_Pack:
2015-11-11 21:11:08 +00:00
call FadeToMenu
2017-12-24 17:47:30 +00:00
farcall Pack
2018-01-11 20:36:11 +00:00
ld a, [wPackUsedItem]
2015-11-11 21:11:08 +00:00
and a
2015-11-17 22:56:49 +00:00
jr nz, .used_item
call CloseSubmenu
2015-11-11 21:11:08 +00:00
ld a, 0
ret
2015-11-17 22:56:49 +00:00
.used_item
call ExitAllMenus
2015-11-11 21:11:08 +00:00
ld a, 4
ret
2018-06-24 14:09:41 +00:00
StartMenu_Pokemon:
2018-01-23 22:39:09 +00:00
ld a, [wPartyCount]
2015-11-11 21:11:08 +00:00
and a
jr z, .return
call FadeToMenu
.choosemenu
xor a
2018-01-23 22:39:09 +00:00
ld [wPartyMenuActionText], a ; Choose a POKéMON.
2015-11-12 04:38:57 +00:00
call ClearBGPalettes
2015-11-11 21:11:08 +00:00
.menu
2017-12-24 17:47:30 +00:00
farcall LoadPartyMenuGFX
farcall InitPartyMenuWithCancel
farcall InitPartyMenuGFX
2015-11-11 21:11:08 +00:00
.menunoreload
2017-12-24 17:47:30 +00:00
farcall WritePartyMenuTilemap
farcall PrintPartyMenuText
2015-11-11 21:11:08 +00:00
call WaitBGMap
call SetPalettes ; load regular palettes?
call DelayFrame
2017-12-24 17:47:30 +00:00
farcall PartyMenuSelect
2015-11-11 21:11:08 +00:00
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
.return
call CloseSubmenu
2015-11-11 21:11:08 +00:00
ld a, 0
ret
.quit
ld a, b
push af
2015-11-17 22:56:49 +00:00
call ExitAllMenus
2015-11-11 21:11:08 +00:00
pop af
ret