Board menu (#11) [Commit 2]

This commit is contained in:
xCrystal 2023-08-17 13:51:29 +02:00
parent 1f33436a64
commit 684c2eff78
10 changed files with 156 additions and 30 deletions

View File

@ -180,3 +180,8 @@ pushc
charmap "\n", $0a
charmap "\r", $0d
popc
; Special tiles
DEF OVERWORLD_FRAME_FIRST_TILE EQU "┌"
DEF BOARD_MENU_BG_FIRST_TILE EQU "A"
DEF BOARD_MENU_OAM_FIRST_TILE EQU BOARD_MENU_BG_FIRST_TILE + 18 * 3

View File

@ -6,6 +6,10 @@ DEF AUTO_INPUT EQU $ff
const DEBUG_BATTLE_F
const DEBUG_FIELD_F
; wDisplaySecondarySprites
const_def
const SECONDARYSPRITES_BOARD_MENU_F ; 0
; wCurDexMode::
const_def
const DEXMODE_NEW

View File

@ -0,0 +1,51 @@
BoardMenuOAM:
; BOARDMENUITEM_DIE
dbsprite 2, 16, 4, 0, BOARD_MENU_OAM_FIRST_TILE, PAL_OW_MISC
dbsprite 3, 16, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 1, PAL_OW_MISC
dbsprite 4, 16, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 2, PAL_OW_MISC
dbsprite 2, 17, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 3, PAL_OW_MISC
dbsprite 3, 17, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 4, PAL_OW_MISC
dbsprite 4, 17, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 5, PAL_OW_MISC
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
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
dbsprite 6, 17, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 12, PAL_OW_MISC
dbsprite 7, 17, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 13, PAL_OW_MISC
dbsprite 8, 17, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 14, PAL_OW_MISC
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
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
dbsprite 9, 17, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 21, PAL_OW_MISC
dbsprite 10, 17, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 22, PAL_OW_MISC
dbsprite 11, 17, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 23, PAL_OW_MISC
dbsprite 9, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 24, PAL_OW_MISC
dbsprite 10, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 25, PAL_OW_MISC
dbsprite 11, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 26, PAL_OW_MISC
; BOARDMENUITEM_POKEGEAR
dbsprite 13, 16, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 27, PAL_OW_MISC
dbsprite 14, 16, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 28, PAL_OW_MISC
dbsprite 15, 16, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 29, PAL_OW_MISC
dbsprite 13, 17, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 30, PAL_OW_MISC
dbsprite 14, 17, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 31, PAL_OW_MISC
dbsprite 15, 17, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 32, PAL_OW_MISC
dbsprite 13, 18, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 33, PAL_OW_MISC
dbsprite 14, 18, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 34, PAL_OW_MISC
dbsprite 15, 18, 0, 0, BOARD_MENU_OAM_FIRST_TILE + 35, PAL_OW_MISC
; BOARDMENUITEM_EXIT
dbsprite 16, 16, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 36, PAL_OW_MISC
dbsprite 17, 16, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 37, PAL_OW_MISC
dbsprite 18, 16, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 38, PAL_OW_MISC
dbsprite 16, 17, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 39, PAL_OW_MISC
dbsprite 17, 17, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 40, PAL_OW_MISC
dbsprite 18, 17, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 41, PAL_OW_MISC
dbsprite 16, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 42, PAL_OW_MISC
dbsprite 17, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 43, PAL_OW_MISC
dbsprite 18, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 44, PAL_OW_MISC

View File

@ -1,16 +1,23 @@
DEF BOARD_MENU_BG_FIRST_TILE EQU "A"
DEF BOARD_MENU_OAM_FIRST_TILE EQU BOARD_MENU_BG_FIRST_TILE + 18 * 3
BoardMenu::
; returns the selected menu item (BOARDMENUITEM_*) in wScriptVar upon exit
ld a, [wBoardMenuLastCursorPosition]
cp NUM_BOARD_MENU_ITEMS
jr c, .ok
ld a, BOARDMENUITEM_DIE
.ok
ld [wBoardMenuCursorPosition], a
; refresh overworld sprites to hide those behind textbox before drawing new graphics
call UpdateSprites
farcall LoadBoardMenuGFX
call DrawBoardMenuTiles
call ApplyBoardMenuSpritePalette
; allow Pal update to complete, then apply the tilemap
call DelayFrame
call ApplyTilemap
; update sprites again to display the sprites of the selected menu item
ld hl, wDisplaySecondarySprites
set SECONDARYSPRITES_BOARD_MENU_F, [hl]
call UpdateSprites
; draw board menu OAM after overworld sprites
call DrawBoardMenuOAM
.loop
call GetBoardMenuSelection
@ -21,12 +28,15 @@ BoardMenu::
jr z, .loop
; menu item change: refresh board menu OAM and save cursor position
call DrawBoardMenuOAM
call ApplyBoardMenuSpritePalette
call UpdateSprites
ld a, [wBoardMenuCursorPosition]
ld [wBoardMenuLastCursorPosition], a
jr .loop
.done
ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_BOARD_MENU_F, [hl]
ld a, [wBoardMenuCursorPosition]
ld [wScriptVar], a
ret
@ -37,9 +47,9 @@ DrawBoardMenuTiles:
lb bc, 3, 18
jp FillBoxWithConsecutiveBytes
DrawBoardMenuOAM:
ApplyBoardMenuSpritePalette:
ld hl, BoardMenuItemPals
ld a, [wBoardMenuLastCursorPosition]
ld a, [wBoardMenuCursorPosition]
ld bc, PALETTE_SIZE
call AddNTimes
; set wOBPals2 directly rather than wOBPals1 to avoid calling ApplyPals and overwriting other overworld pals
@ -47,28 +57,51 @@ DrawBoardMenuOAM:
ld bc, PALETTE_SIZE
ld a, BANK(wOBPals2)
call FarCopyWRAM
ld hl, .OAM
ld a, [wBoardMenuCursorPosition]
ld bc, 3 * 3 * SPRITEOAMSTRUCT_LENGTH
call AddNTimes
; find the beginning of free space in OAM, and assure there's space for 3 * 3 objects
ldh a, [hUsedSpriteIndex]
cp (NUM_SPRITE_OAM_STRUCTS * SPRITEOAMSTRUCT_LENGTH) - (3 * 3 * SPRITEOAMSTRUCT_LENGTH)
jr nc, .oam_full
; copy the sprite data (3 * 3 objects) of that item to the available space in OAM
ld e, a
ld d, HIGH(wShadowOAM)
ld bc, 3 * 3 * SPRITEOAMSTRUCT_LENGTH
call CopyBytes
.oam_full
ld a, TRUE
ldh [hCGBPalUpdate], a
ret
.OAM:
GetBoardMenuSelection:
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
scf
ret
.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
BoardMenuItemPals:
INCLUDE "gfx/board/menu.pal"

View File

@ -18,7 +18,7 @@ _LoadOverworldFontAndFrame::
call AddNTimes
ld d, h
ld e, l
ld hl, vTiles0 tile "┌" ; $f0
ld hl, vTiles0 tile OVERWORLD_FRAME_FIRST_TILE ; $f0
lb bc, BANK(.OverworldFrames), OW_TEXTBOX_FRAME_TILES
call Get2bppViaHDMA
ret

View File

@ -1,4 +1,4 @@
const_def "┌" ; $f0
const_def OVERWORLD_FRAME_FIRST_TILE ; $f0
const OW_TEXTBOX_FRAME_WHITE
const OW_TEXTBOX_FRAME_TOP_LEFT_CORNER
const OW_TEXTBOX_FRAME_TOP_2

View File

@ -2810,6 +2810,7 @@ DEF PRIORITY_NORM EQU $20
DEF PRIORITY_HIGH EQU $30
InitSprites:
call InitSecondarySprites
call .DeterminePriorities
ld c, PRIORITY_HIGH
call .InitSpritesByPriority
@ -3042,3 +3043,36 @@ InitSprites:
dw wObject10Struct
dw wObject11Struct
dw wObject12Struct
InitSecondarySprites:
ld a, [wDisplaySecondarySprites]
bit SECONDARYSPRITES_BOARD_MENU_F, a
call nz, .InitBoardMenuSprites
ret
.InitBoardMenuSprites:
push af
ld hl, BoardMenuOAM
ld a, [wBoardMenuCursorPosition]
ld bc, 3 * 3 * SPRITEOAMSTRUCT_LENGTH
call AddNTimes
; find the beginning of free space in OAM, and assure there's space for 3 * 3 objects
ldh a, [hUsedSpriteIndex]
cp (NUM_SPRITE_OAM_STRUCTS * SPRITEOAMSTRUCT_LENGTH) - (3 * 3 * SPRITEOAMSTRUCT_LENGTH) + 1
jr nc, .oam_full
; copy the sprite data (3 * 3 objects) of that item to the available space in OAM
ld e, a
ld d, HIGH(wShadowOAM)
ld bc, 3 * 3 * SPRITEOAMSTRUCT_LENGTH
call CopyBytes
ldh a, [hUsedSpriteIndex]
add (3 * 3 * SPRITEOAMSTRUCT_LENGTH)
ldh [hUsedSpriteIndex], a
.oam_full
pop af
ret
INCLUDE "data/sprites/secondary_sprites.asm"

View File

@ -2208,7 +2208,6 @@ Script_refreshscreen:
Script_writeunusedbyte:
call GetScriptByte
ld [wUnusedScriptByte], a
ret
Script_closetext:

View File

@ -125,7 +125,7 @@ wDebugFlags:: db
wGameLogicPaused:: db
wSpriteUpdatesEnabled:: db
wUnusedScriptByte:: db
wDisplaySecondarySprites:: db
wMapTimeOfDay:: db