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 "\n", $0a
charmap "\r", $0d charmap "\r", $0d
popc 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_BATTLE_F
const DEBUG_FIELD_F const DEBUG_FIELD_F
; wDisplaySecondarySprites
const_def
const SECONDARYSPRITES_BOARD_MENU_F ; 0
; wCurDexMode:: ; wCurDexMode::
const_def const_def
const DEXMODE_NEW 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:: BoardMenu::
; returns the selected menu item (BOARDMENUITEM_*) in wScriptVar upon exit ; returns the selected menu item (BOARDMENUITEM_*) in wScriptVar upon exit
ld a, [wBoardMenuLastCursorPosition] ld a, [wBoardMenuLastCursorPosition]
cp NUM_BOARD_MENU_ITEMS
jr c, .ok
ld a, BOARDMENUITEM_DIE
.ok
ld [wBoardMenuCursorPosition], a ld [wBoardMenuCursorPosition], a
; refresh overworld sprites to hide those behind textbox before drawing new graphics
call UpdateSprites
farcall LoadBoardMenuGFX farcall LoadBoardMenuGFX
call DrawBoardMenuTiles call DrawBoardMenuTiles
call ApplyBoardMenuSpritePalette
; allow Pal update to complete, then apply the tilemap
call DelayFrame
call ApplyTilemap 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 call UpdateSprites
; draw board menu OAM after overworld sprites
call DrawBoardMenuOAM
.loop .loop
call GetBoardMenuSelection call GetBoardMenuSelection
@ -21,12 +28,15 @@ BoardMenu::
jr z, .loop jr z, .loop
; menu item change: refresh board menu OAM and save cursor position ; menu item change: refresh board menu OAM and save cursor position
call DrawBoardMenuOAM call ApplyBoardMenuSpritePalette
call UpdateSprites
ld a, [wBoardMenuCursorPosition] ld a, [wBoardMenuCursorPosition]
ld [wBoardMenuLastCursorPosition], a ld [wBoardMenuLastCursorPosition], a
jr .loop jr .loop
.done .done
ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_BOARD_MENU_F, [hl]
ld a, [wBoardMenuCursorPosition] ld a, [wBoardMenuCursorPosition]
ld [wScriptVar], a ld [wScriptVar], a
ret ret
@ -37,9 +47,9 @@ DrawBoardMenuTiles:
lb bc, 3, 18 lb bc, 3, 18
jp FillBoxWithConsecutiveBytes jp FillBoxWithConsecutiveBytes
DrawBoardMenuOAM: ApplyBoardMenuSpritePalette:
ld hl, BoardMenuItemPals ld hl, BoardMenuItemPals
ld a, [wBoardMenuLastCursorPosition] ld a, [wBoardMenuCursorPosition]
ld bc, PALETTE_SIZE ld bc, PALETTE_SIZE
call AddNTimes call AddNTimes
; set wOBPals2 directly rather than wOBPals1 to avoid calling ApplyPals and overwriting other overworld pals ; 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 bc, PALETTE_SIZE
ld a, BANK(wOBPals2) ld a, BANK(wOBPals2)
call FarCopyWRAM call FarCopyWRAM
ld a, TRUE
ld hl, .OAM ldh [hCGBPalUpdate], a
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
ret ret
.OAM:
GetBoardMenuSelection: 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 scf
ret 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: BoardMenuItemPals:
INCLUDE "gfx/board/menu.pal" INCLUDE "gfx/board/menu.pal"

View File

@ -18,7 +18,7 @@ _LoadOverworldFontAndFrame::
call AddNTimes call AddNTimes
ld d, h ld d, h
ld e, l 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 lb bc, BANK(.OverworldFrames), OW_TEXTBOX_FRAME_TILES
call Get2bppViaHDMA call Get2bppViaHDMA
ret 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_WHITE
const OW_TEXTBOX_FRAME_TOP_LEFT_CORNER const OW_TEXTBOX_FRAME_TOP_LEFT_CORNER
const OW_TEXTBOX_FRAME_TOP_2 const OW_TEXTBOX_FRAME_TOP_2

View File

@ -2810,6 +2810,7 @@ DEF PRIORITY_NORM EQU $20
DEF PRIORITY_HIGH EQU $30 DEF PRIORITY_HIGH EQU $30
InitSprites: InitSprites:
call InitSecondarySprites
call .DeterminePriorities call .DeterminePriorities
ld c, PRIORITY_HIGH ld c, PRIORITY_HIGH
call .InitSpritesByPriority call .InitSpritesByPriority
@ -3042,3 +3043,36 @@ InitSprites:
dw wObject10Struct dw wObject10Struct
dw wObject11Struct dw wObject11Struct
dw wObject12Struct 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: Script_writeunusedbyte:
call GetScriptByte call GetScriptByte
ld [wUnusedScriptByte], a
ret ret
Script_closetext: Script_closetext:

View File

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