From 4dec74b7707ae1833ac903dfff8fa5a767db5d01 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Sun, 27 Aug 2023 13:11:42 +0200 Subject: [PATCH] Level selection menu: fading animations (#12) (#14) --- constants/cgb_pal_constants.asm | 7 ++ engine/gfx/cgb_layouts.asm | 36 +++------- engine/gfx/color.asm | 3 +- engine/gfx/rgb_fade.asm | 99 ++++++++++++++++++++++++++- engine/menus/intro_menu.asm | 1 - engine/menus/level_selection_menu.asm | 63 +++++++++++------ home/fade.asm | 4 ++ ram/wram.asm | 2 +- 8 files changed, 161 insertions(+), 54 deletions(-) diff --git a/constants/cgb_pal_constants.asm b/constants/cgb_pal_constants.asm index 820533088..8c1d7fa2a 100644 --- a/constants/cgb_pal_constants.asm +++ b/constants/cgb_pal_constants.asm @@ -124,3 +124,10 @@ DEF CGB_DEFAULT EQU $ff const PREDEFPAL_GAMEFREAK_LOGO_OB const PREDEFPAL_GAMEFREAK_LOGO_BG DEF NUM_PREDEF_PALS EQU const_value + +; RGBFadeEffectJumptable indexes (see engine/gfx/rgb_fade.asm:DoRGBFadeEffect) + const_def + const RGBFADE_TO_BLACK_6BGP + const RGBFADE_TO_LIGHTER_6BGP + const RGBFADE_TO_WHITE_6BGP_2OBP +DEF NUM_RGB_FADE_EFFECTS EQU const_value diff --git a/engine/gfx/cgb_layouts.asm b/engine/gfx/cgb_layouts.asm index 80d769e12..91d14f40d 100644 --- a/engine/gfx/cgb_layouts.asm +++ b/engine/gfx/cgb_layouts.asm @@ -4,7 +4,7 @@ LoadCGBLayout: ld a, b cp CGB_DEFAULT jr nz, .not_default - ld a, [wDefaultSGBLayout] + ld a, [wDefaultCGBLayout] .not_default cp CGB_PARTY_MENU_HP_BARS jp z, CGB_ApplyPartyMenuHPPals @@ -24,6 +24,7 @@ LoadCGBLayout: ret CGBLayoutJumptable: +; entries correspond to CGB_* constants (see constants/cgb_pal_constants.asm) table_width 2, CGBLayoutJumptable dw _CGB_BattleGrayscale dw _CGB_BattleColors @@ -104,7 +105,7 @@ _CGB_BattleColors: pop hl call LoadPalette_White_Col1_Col2_Black ; PAL_BATTLE_OB_PLAYER ld a, CGB_BATTLE_COLORS - ld [wDefaultSGBLayout], a + ld [wDefaultCGBLayout], a call ApplyPals _CGB_FinishBattleScreenLayout: call InitPartyMenuBGPal7 @@ -506,7 +507,7 @@ _CGB_Diploma: _CGB_MapPals: call LoadMapPals ld a, CGB_MAPPALS - ld [wDefaultSGBLayout], a + ld [wDefaultCGBLayout], a ret _CGB_PartyMenu: @@ -564,7 +565,7 @@ _CGB_GSTitleScreen: ld a, BANK(wOBPals1) call FarCopyWRAM ld a, CGB_DIPLOMA - ld [wDefaultSGBLayout], a + ld [wDefaultCGBLayout], a call ApplyPals ld a, TRUE ldh [hCGBPalUpdate], a @@ -581,6 +582,7 @@ _CGB_LevelSelectionMenu: ld bc, 2 palettes ld a, BANK(wOBPals1) call FarCopyWRAM + ; load daytime and gender-based background pals ld a, [wPlayerGender] bit PLAYERGENDER_FEMALE_F, a @@ -598,30 +600,8 @@ _CGB_LevelSelectionMenu: ld bc, 6 palettes ld a, BANK(wBGPals1) call FarCopyWRAM -; assign attrs based on tile ids according to LevelSelectionMenuAttrmap - hlcoord 0, 0 - decoord 0, 0, wAttrmap - ld bc, SCREEN_WIDTH * SCREEN_HEIGHT -.loop - push hl - ld a, [hl] ; tile id - ld hl, LevelSelectionMenuAttrmap - add l - ld l, a - ld a, h - adc 0 - ld h, a - ld a, [hl] ; attr value - ld [de], a - pop hl - inc hl - inc de - dec bc - ld a, b - or c - jr nz, .loop -; apply and commit pals and attrmap - call ApplyAttrmap + +; apply and commit pals call ApplyPals ld a, TRUE ldh [hCGBPalUpdate], a diff --git a/engine/gfx/color.asm b/engine/gfx/color.asm index a2799366a..3a859daab 100644 --- a/engine/gfx/color.asm +++ b/engine/gfx/color.asm @@ -822,5 +822,4 @@ LevelSelectionMenuFemalePals: INCLUDE "gfx/level_selection_menu/background_female.pal" assert_table_length NUM_DAYTIMES -LevelSelectionMenuAttrmap: -INCLUDE "gfx/level_selection_menu/attrmap.asm" +INCLUDE "engine/gfx/rgb_fade.asm" diff --git a/engine/gfx/rgb_fade.asm b/engine/gfx/rgb_fade.asm index 7ccf01010..8f5471afa 100755 --- a/engine/gfx/rgb_fade.asm +++ b/engine/gfx/rgb_fade.asm @@ -247,4 +247,101 @@ BlackRGB: RGB 00, 00, 00 WhiteRGB: - RGB 31, 31, 31 \ No newline at end of file + RGB 31, 31, 31 + +_DoRGBFadeEffect:: + ldh a, [rSVBK] + push af + ld a, BANK(wBGPals2) ; BANK(wOBPals2) + ldh [rSVBK], a + + ld l, b + ld h, 0 + add hl, hl + ld de, RGBFadeEffectJumptable + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + ld de, .done + push de + jp hl + +.done: + pop af + ldh [rSVBK], a + ret + +RGBFadeEffectJumptable: +; entries correspond to RGBFADE_* constants (see constants/cgb_pal_constants.asm) + table_width 2, RGBFadeEffectJumptable + dw _RGBFadeToBlack_6BGP + dw _RGBFadeToLighter_6BGP + dw _RGBFadeToWhite_6BGP_2OBP + assert_table_length NUM_RGB_FADE_EFFECTS + +_RGBFadeToBlack_6BGP: + ld c, 32 / 2 +.loop + push bc + +; fade BGP to black + ld de, wBGPals2 + ld c, 6 * NUM_PAL_COLORS + call FadeStepColorsToBlack + +; commit pals + ld a, TRUE + ldh [hCGBPalUpdate], a + call DelayFrame + + pop bc + dec c + jr nz, .loop + ret + +_RGBFadeToLighter_6BGP: + ld c, 32 / 2 +.loop + push bc + +; fade BGP to lighter (towards wBGPals1) + ld de, wBGPals2 + ld hl, wBGPals1 + ld c, 6 * NUM_PAL_COLORS + call FadeStepColorsToLighter + +; commit pals + ld a, TRUE + ldh [hCGBPalUpdate], a + call DelayFrame + + pop bc + dec c + jr nz, .loop + ret + +_RGBFadeToWhite_6BGP_2OBP: + ld c, 32 / 2 +.loop + push bc + +; fade BGP to white + ld de, wBGPals2 + ld c, 6 * NUM_PAL_COLORS + call FadeStepColorsToWhite + +; fade OBP to white + ld de, wOBPals2 + ld c, 2 * NUM_PAL_COLORS + call FadeStepColorsToWhite + +; commit pals + ld a, TRUE + ldh [hCGBPalUpdate], a + call DelayFrame + + pop bc + dec c + jr nz, .loop + ret \ No newline at end of file diff --git a/engine/menus/intro_menu.asm b/engine/menus/intro_menu.asm index 8a12bcd41..9ad8e7c1c 100644 --- a/engine/menus/intro_menu.asm +++ b/engine/menus/intro_menu.asm @@ -300,7 +300,6 @@ LoadOrRegenerateLuckyIDNumber: jp CloseSRAM Continue: - farcall LevelSelectionMenu farcall TryLoadSaveFile jr c, .FailToLoad call LoadStandardMenuHeader diff --git a/engine/menus/level_selection_menu.asm b/engine/menus/level_selection_menu.asm index 8a23d7f71..00648d3df 100755 --- a/engine/menus/level_selection_menu.asm +++ b/engine/menus/level_selection_menu.asm @@ -26,11 +26,13 @@ LevelSelectionMenu:: ld [wLevelSelectionMenuStandingStill], a call LevelSelectionMenu_InitTilemap - ld b, CGB_LEVEL_SELECTION_MENU - call GetCGBLayout ; apply and commit attrmap (takes 4 frames) and pals - call SetPalettes + call LevelSelectionMenu_InitAttrmap + call WaitBGMap2 xor a ldh [hBGMapMode], a + ld b, CGB_LEVEL_SELECTION_MENU + call GetCGBLayout ; apply and commit pals + call SetPalettes ld de, MUSIC_GAME_CORNER call PlayMusic @@ -122,8 +124,6 @@ LevelSelectionMenu:: call PlaySFX call LevelSelectionMenu_Delay10Frames call .EnterLevelFadeOut - ld c, 10 - call DelayFrames ld a, $8 ld [wMusicFade], a ld a, LOW(MUSIC_NONE) @@ -154,7 +154,8 @@ LevelSelectionMenu:: ret .EnterLevelFadeOut: - ret + ld b, RGBFADE_TO_WHITE_6BGP_2OBP + jp DoRGBFadeEffect .exit call LevelSelectionMenu_Delay10Frames @@ -196,7 +197,7 @@ LevelSelectionMenu_InitTilemap: .loop ld a, [de] cp $ff ; tilemaps are $ff-terminated - jp z, WaitBGMap ; commit tilemap (4 frames) + ret z ld a, [de] ld [hli], a inc de @@ -208,6 +209,31 @@ LevelSelectionMenu_InitTilemap: dw LevelSelectionMenuPage3Tilemap dw LevelSelectionMenuPage4Tilemap +LevelSelectionMenu_InitAttrmap: +; assign attrs based on tile ids according to LevelSelectionMenuAttrmap + hlcoord 0, 0 + decoord 0, 0, wAttrmap + ld bc, SCREEN_WIDTH * SCREEN_HEIGHT +.loop + push hl + ld a, [hl] ; tile id + ld hl, LevelSelectionMenuAttrmap + add l + ld l, a + ld a, h + adc 0 + ld h, a + ld a, [hl] ; attr value + ld [de], a + pop hl + inc hl + inc de + dec bc + ld a, b + or c + jr nz, .loop + ret + LevelSelectionMenu_InitPlayerSprite: ; initialize the anim struct of the player's sprite. ; because ClearSpriteAnims was called before, it's always loaded to wSpriteAnim1 @@ -397,10 +423,6 @@ DEF PAGE_EDGE_UP EQU $10 DEF PAGE_EDGE_LEFT EQU $08 DEF PAGE_EDGE_RIGHT EQU $a8 -DEF PAGE_CHANGE_FADE_FRAMES EQU 16 -DEF PAGE_CHANGE_NON_FADE_FRAMES EQU 13 -; total frame delay of page change is 16 + 13 + 16 = 45 frames - MACRO page_change_event ; SPRITE_ANIM_SEQ_* to match, Match object's X or Y, X/Y coordinate, Action if both SPRITE_ANIM_SEQ_* and X/Y match db \1, \2, \3 @@ -447,12 +469,10 @@ ENDM call LevelSelectionMenu_GetNewPage ld [wLevelSelectionMenuCurrentPage], a call LevelSelectionMenu_InitTilemap - ld b, CGB_LEVEL_SELECTION_MENU - call GetCGBLayout + call LevelSelectionMenu_InitAttrmap + call WaitBGMap2 xor a ldh [hBGMapMode], a - ld c, PAGE_CHANGE_NON_FADE_FRAMES - call DelayFrames call .PageChangeFadeIn ; adjust steps left for the "duplicate" movement of the player leaving and entering a page ld hl, wLevelSelectionMenuMovementStepsLeft @@ -462,14 +482,12 @@ ENDM ret .PageChangeFadeOut: - ld c, PAGE_CHANGE_FADE_FRAMES - call DelayFrames - ret + ld b, RGBFADE_TO_BLACK_6BGP + jp DoRGBFadeEffect .PageChangeFadeIn: - ld c, PAGE_CHANGE_FADE_FRAMES - call DelayFrames - ret + ld b, RGBFADE_TO_LIGHTER_6BGP + jp DoRGBFadeEffect LevelSelectionMenu_GetLandmarkPage: ; Return page number (a) of landmark a. @@ -760,5 +778,8 @@ INCBIN "gfx/level_selection_menu/page_3.tilemap" LevelSelectionMenuPage4Tilemap: INCBIN "gfx/level_selection_menu/page_4.tilemap" +LevelSelectionMenuAttrmap: +INCLUDE "gfx/level_selection_menu/attrmap.asm" + LevelSelectionMenuDirectionalArrowsGFX: INCBIN "gfx/level_selection_menu/directional_arrows.2bpp" diff --git a/home/fade.asm b/home/fade.asm index 149ab9fcc..a7ec9ec97 100644 --- a/home/fade.asm +++ b/home/fade.asm @@ -62,3 +62,7 @@ IncGradGBPalTable_05:: dc 2,1,0,0, 2,1,0,0, 2,1,0,0 IncGradGBPalTable_06:: dc 1,0,0,0, 1,0,0,0, 1,0,0,0 IncGradGBPalTable_07:: dc 0,0,0,0, 0,0,0,0, 0,0,0,0 + +DoRGBFadeEffect:: + farcall _DoRGBFadeEffect + ret diff --git a/ram/wram.asm b/ram/wram.asm index 4ba964566..fb0283fa0 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -944,7 +944,7 @@ wCreditsPos:: dw wCreditsTimer:: db ENDU -wDefaultSGBLayout:: db +wDefaultCGBLayout:: db wPlayerHPPal:: db wEnemyHPPal:: db