pokecrystal-board/engine/board/menu.asm

108 lines
2.4 KiB
NASM
Raw Normal View History

2023-08-14 11:09:23 -07:00
BoardMenu::
; returns the selected menu item (BOARDMENUITEM_*) in wScriptVar upon exit
ld a, [wBoardMenuLastCursorPosition]
2023-08-17 04:51:29 -07:00
cp NUM_BOARD_MENU_ITEMS
jr c, .ok
ld a, BOARDMENUITEM_DIE
.ok
2023-08-14 11:09:23 -07:00
ld [wBoardMenuCursorPosition], a
2023-08-17 04:51:29 -07:00
; refresh overworld sprites to hide those behind textbox before drawing new graphics
call UpdateSprites
2023-08-14 11:09:23 -07:00
farcall LoadBoardMenuGFX
call DrawBoardMenuTiles
2023-08-17 04:51:29 -07:00
call ApplyBoardMenuSpritePalette
; allow Pal update to complete, then apply the tilemap
call DelayFrame
2023-08-14 11:09:23 -07:00
call ApplyTilemap
2023-08-17 04:51:29 -07:00
; update sprites again to display the sprites of the selected menu item
ld hl, wDisplaySecondarySprites
set SECONDARYSPRITES_BOARD_MENU_F, [hl]
2023-08-14 11:09:23 -07:00
call UpdateSprites
.loop
call GetBoardMenuSelection
jr c, .done
ld hl, wBoardMenuCursorPosition
ld a, [wBoardMenuLastCursorPosition]
cp [hl]
jr z, .loop
; menu item change: refresh board menu OAM and save cursor position
2023-08-17 04:51:29 -07:00
call ApplyBoardMenuSpritePalette
call UpdateSprites
2023-08-14 11:09:23 -07:00
ld a, [wBoardMenuCursorPosition]
ld [wBoardMenuLastCursorPosition], a
jr .loop
.done
2023-08-17 04:51:29 -07:00
ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_BOARD_MENU_F, [hl]
2023-08-14 11:09:23 -07:00
ld a, [wBoardMenuCursorPosition]
ld [wScriptVar], a
ret
DrawBoardMenuTiles:
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
ld a, BOARD_MENU_BG_FIRST_TILE
lb bc, 3, 18
jp FillBoxWithConsecutiveBytes
2023-08-17 04:51:29 -07:00
ApplyBoardMenuSpritePalette:
2023-08-14 11:09:23 -07:00
ld hl, BoardMenuItemPals
2023-08-17 04:51:29 -07:00
ld a, [wBoardMenuCursorPosition]
2023-08-14 11:09:23 -07:00
ld bc, PALETTE_SIZE
call AddNTimes
; set wOBPals2 directly rather than wOBPals1 to avoid calling ApplyPals and overwriting other overworld pals
ld de, wOBPals2 palette PAL_OW_MISC
ld bc, PALETTE_SIZE
ld a, BANK(wOBPals2)
call FarCopyWRAM
2023-08-17 04:51:29 -07:00
ld a, TRUE
ldh [hCGBPalUpdate], a
2023-08-14 11:09:23 -07:00
ret
GetBoardMenuSelection:
2023-08-17 04:51:29 -07:00
call JoyTextDelay
call GetMenuJoypad
bit A_BUTTON_F, a
jr nz, .a_button
bit D_RIGHT_F, a
jr nz, .d_right
bit D_LEFT_F, a
jr nz, .d_left
xor a
ret ; nc
.a_button
call PlayClickSFX
call WaitSFX
2023-08-14 11:09:23 -07:00
scf
ret
2023-08-17 04:51:29 -07:00
.d_right
call PlayClickSFX
ld a, [wBoardMenuCursorPosition]
inc a
cp NUM_BOARD_MENU_ITEMS
jr c, .right_dont_wrap_around
ld a, BOARDMENUITEM_DIE
.right_dont_wrap_around
ld [wBoardMenuCursorPosition], a
xor a
ret ; nc
.d_left
call PlayClickSFX
ld a, [wBoardMenuCursorPosition]
dec a
cp -1
jr nz, .left_dont_wrap_around
ld a, NUM_BOARD_MENU_ITEMS - 1 ; BOARDMENUITEM_EXIT
.left_dont_wrap_around
ld [wBoardMenuCursorPosition], a
xor a
ret ; nc
2023-08-14 11:09:23 -07:00
BoardMenuItemPals:
INCLUDE "gfx/board/menu.pal"