diff --git a/constants/wram_constants.asm b/constants/wram_constants.asm index 484a61914..bb6455d9f 100644 --- a/constants/wram_constants.asm +++ b/constants/wram_constants.asm @@ -60,7 +60,8 @@ DEF NUM_FRAMES EQU const_value ; wTextboxFlags:: const_def const FAST_TEXT_DELAY_F ; 0 - const TEXT_DELAY_F ; 1 + const TEXT_DELAY_F ; 1 + const TEXT_2BPP_F ; 2 ; wGBPrinterBrightness:: DEF GBPRINTER_LIGHTEST EQU $00 diff --git a/docs/develop/index.md b/docs/develop/index.md index 58d15fea2..a50fb982a 100755 --- a/docs/develop/index.md +++ b/docs/develop/index.md @@ -15,8 +15,8 @@ #### Textboxes -- **Textbox1bpp**: TextboxBorder + TextboxPalette -- **Textbox2bpp**: _OverworldTextbox + TextboxPalette +- **Textbox1bpp**: TextboxBorder + TextboxAttributes1bpp +- **Textbox2bpp**: _OverworldTextbox + TextboxAttributes2bpp - **SpeechTextbox1bpp**: Textbox1bpp with speech location and dimensions - **SpeechTextbox2bpp**: Textbox2bpp with speech location and dimensions - **ClearTextbox**: Clear the inside of a speech textbox (fill with " ") @@ -24,7 +24,7 @@ - **PrintText1bpp**, **FarPrintText1bpp**: SpeechTextbox1bpp + UpdateSprites + ApplyTilemap + ClearTextbox + PrintTextboxText - **PrintText2bpp**: SpeechTextbox2bpp + UpdateSprites + ApplyTilemap + ClearTextbox + PrintTextboxText - **MapTextbox**: ClearTextbox + redraw tile behind cursor + SafeUpdateSprites + disable OAM update + ApplyTilemap + PrintTextboxText + enable OAM update -- **MenuBox**: Calls Textbox1bpp or Textbox2bpp, depending on the value at wMenuBoxUse2bppFrame, with menu location and dimensions. wMenuBoxUse2bppFrame, as part of menu data, is cleared (FALSE means 1bpp) by ClearMenuAndWindowData +- **MenuBox**: Calls Textbox1bpp or Textbox2bpp, depending on the value at wTextboxFlags[TEXT_2BPP_F], with menu location and dimensions. #### Overworld map scrolling diff --git a/engine/menus/start_menu.asm b/engine/menus/start_menu.asm index 0de3b812a..a4f04671d 100644 --- a/engine/menus/start_menu.asm +++ b/engine/menus/start_menu.asm @@ -13,6 +13,9 @@ StartMenu:: call ClearMenuAndWindowData + ld hl, wTextboxFlags + res TEXT_2BPP_F, [hl] + ld de, SFX_MENU call PlaySFX @@ -378,7 +381,7 @@ endr hlcoord 0, 13 ld b, 3 ld c, 8 - jp TextboxPalette + jp TextboxAttributes1bpp .IsMenuAccountOn: ld a, [wOptions2] diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index ff9c9e8cb..efdf19f5a 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -110,6 +110,8 @@ EnterMap: ld [wXYComparePointer], a ld [wXYComparePointer + 1], a call SetUpFiveStepWildEncounterCooldown + ld hl, wTextboxFlags + set TEXT_2BPP_F, [hl] farcall RunMapSetupScript call DisableEvents diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index 061795e47..2423525bc 100644 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -2252,14 +2252,14 @@ UpdateObjectFrozen: call CheckObjectOnScreen jr c, SetFacing_Standing call UpdateObjectTile - farcall HandleFrozenObjectAction ; no need to farcall + call HandleFrozenObjectAction xor a ret UpdateRespawnedObjectFrozen: call CheckObjectOnScreen jr c, SetFacing_Standing - farcall HandleFrozenObjectAction ; no need to farcall + call HandleFrozenObjectAction xor a ret @@ -2283,7 +2283,7 @@ UpdateObjectTile: ld hl, OBJECT_TILE add hl, bc ld [hl], a - farcall UpdateTallGrassFlags ; no need to farcall + call UpdateTallGrassFlags ret CheckObjectOnScreen: @@ -2332,7 +2332,7 @@ CheckObjectCoveredByTextbox: cp $f0 jr nc, .ok1 cp SCREEN_WIDTH_PX - jp nc, .nope + jp nc, .disappear .ok1 ; Account for objects currently moving left/right. and %00000111 @@ -2365,7 +2365,7 @@ CheckObjectCoveredByTextbox: cp $f0 jr nc, .ok4 cp SCREEN_HEIGHT_PX - jr nc, .nope + jr nc, .disappear .ok4 ; Account for objects currently moving up/down. and %00000111 @@ -2419,23 +2419,50 @@ CheckObjectCoveredByTextbox: push bc call Coord2Tile pop bc -; NPCs disappear if standing on tile $60-$7f (or $e0-$ff), +; NPCs disappear if standing on tiles FIRST_REGULAR_TEXT_CHAR or above, ; since those IDs are for text characters and textbox frames. +; - if 1bpp text, a single textbox tile overlapping with the sprite makes it disappear. +; - if 2bpp text, sprite only disappears if ALL overlapping tiles are textbox tiles. ld a, [hl] cp FIRST_REGULAR_TEXT_CHAR - jr nc, .nope + jr c, .object_not_in_textbox + +;.object_in_textbox + ld a, [wTextboxFlags] + bit TEXT_2BPP_F, a + jr z, .disappear + jr .ok8 + +.object_not_in_textbox + ld a, [wTextboxFlags] + bit TEXT_2BPP_F, a + jr nz, .not_disappear + .ok8 dec d jr nz, .next .ok9 +; while sprites are centered to tiles in the X axis exactly on top of two adjacent horizonal tiles, +; in the Y axis they occupy 4-8-4 pixels of adjacent vertical tiles instead. +; this is why we loop here one more time (thrice for regular-sized sprites) than horizontally. dec e + ld a, e + cp $ff jr nz, .loop - and a +; if we managed make it here without returning early, there are only two options: +; - if 1bpp text, the sprite is wholly outside of a textbox +; - if 2bpp text, the sprite is wholly inside a textbox + ld a, [wTextboxFlags] + bit TEXT_2BPP_F, a + jr z, .not_disappear + +.disappear + scf ret -.nope - scf +.not_disappear + and a ret HandleNPCStep:: @@ -2584,7 +2611,7 @@ ResetFollower: cp -1 ret z call GetObjectStruct - farcall ResetObject ; no need to farcall + call ResetObject ld a, -1 ld [wObjectFollow_Follower], a ret diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm index be2a2e649..b74900b84 100644 --- a/engine/overworld/scripting.asm +++ b/engine/overworld/scripting.asm @@ -383,8 +383,6 @@ Script_promptbutton: ret Script_yesorno: - ld a, TRUE - ld [wMenuBoxUse2bppFrame], a call YesNoBox ld a, FALSE jr c, .no @@ -425,8 +423,6 @@ Script_closepokepic: ret Script_verticalmenu: - ld a, TRUE - ld [wMenuBoxUse2bppFrame], a ld a, [wScriptBank] ld hl, VerticalMenu rst FarCall @@ -438,8 +434,6 @@ Script_verticalmenu: ret Script__2dmenu: - ld a, TRUE - ld [wMenuBoxUse2bppFrame], a ld a, [wScriptBank] ld hl, _2DMenu rst FarCall diff --git a/home/menu.asm b/home/menu.asm index d60e96df6..1589f8652 100644 --- a/home/menu.asm +++ b/home/menu.asm @@ -209,8 +209,8 @@ MenuBox:: call GetMenuBoxDims dec b dec c - ld a, [wMenuBoxUse2bppFrame] - and a + ld a, [wTextboxFlags] + bit TEXT_2BPP_F, a jp z, Textbox1bpp ld d, h ld e, l diff --git a/home/text.asm b/home/text.asm index a619bef1c..342b0dfe0 100644 --- a/home/text.asm +++ b/home/text.asm @@ -72,7 +72,7 @@ Textbox1bpp:: call TextboxBorder pop hl pop bc - jr TextboxPalette + jr TextboxAttributes1bpp TextboxBorder:: ; Top @@ -120,15 +120,23 @@ TextboxBorder:: jr nz, .loop ret -TextboxPalette:: -; Fill text box width c height b at hl with pal 7 +TextboxAttributes1bpp:: +; Fill text box width c height b at hl with PAL_BG_TEXT + ld a, PAL_BG_TEXT + jr _TextboxAttributes + +TextboxAttributes2bpp:: +; Fill text box width c height b at hl with PAL_BG_TEXT | PRIORITY + ld a, PAL_BG_TEXT | PRIORITY + ; fallthrough + +_TextboxAttributes: ld de, wAttrmap - wTilemap add hl, de inc b inc b inc c inc c - ld a, PAL_BG_TEXT .col push bc push hl @@ -155,7 +163,7 @@ Textbox2bpp:: farcall _OverworldTextbox pop hl pop bc - jp TextboxPalette + jp TextboxAttributes2bpp RadioTerminator:: ld hl, .stop diff --git a/home/window.asm b/home/window.asm index 92c2ad188..4aea5a2e0 100644 --- a/home/window.asm +++ b/home/window.asm @@ -46,6 +46,9 @@ OpenText2bpp:: ld a, BANK(ReanchorBGMap_NoOAMUpdate) rst Bankswitch + ld hl, wTextboxFlags + set TEXT_2BPP_F, [hl] + ; assumes that the overworld 2bpp font and frame are loaded when calling this call ReanchorBGMap_NoOAMUpdate ; anchor bgmap call SpeechTextbox2bpp @@ -64,6 +67,9 @@ OpenText1bpp:: ld a, BANK(ReanchorBGMap_NoOAMUpdate) ; aka BANK(LoadFont_NoOAMUpdate) rst Bankswitch + ld hl, wTextboxFlags + res TEXT_2BPP_F, [hl] + call ReanchorBGMap_NoOAMUpdate ; anchor bgmap call SpeechTextbox1bpp call HDMATransferTilemapAndAttrmap_OpenAndCloseMenu ; transfer bgmap diff --git a/ram/wram.asm b/ram/wram.asm index 948827b69..ec552dfd2 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -1192,8 +1192,7 @@ wMenuCursorY:: db wMenuCursorX:: db wCursorOffCharacter:: db wCursorCurrentTile:: dw -wMenuBoxUse2bppFrame:: db - ds 2 + ds 3 wMoreMenuDataEnd:: wOverworldDelay:: db @@ -1253,7 +1252,8 @@ wTextboxFrame:: db wTextboxFlags:: ; bit 0: 1-frame text delay -; bit 4: no text delay +; bit 1: no text delay +; bit 2: 2bpp textbox (and text) db wGBPrinterBrightness:: ; bit 0-6: brightness