pokecrystal-board/engine/menus/start_menu.asm

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