From: Lukas Krickl Date: Tue, 13 May 2025 18:09:40 +0000 (+0200) Subject: ui: Added basic ui element for remaining moves X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=d52a785b6e902a6561479a8eac81a1836d664b7f;p=gbrg%2F.git ui: Added basic ui element for remaining moves --- diff --git a/src/defs.s b/src/defs.s index 9a7eba9..50d9010 100644 --- a/src/defs.s +++ b/src/defs.s @@ -33,8 +33,12 @@ #define CURSOR_MIN_Y 0 #define CURSOR_MAX_Y 0xB8 + ; draw flags +.se 1 +.de DRAWF_UPDATE_UI, 1 + ; cell flags -.se 0 +.se 1 .de CF_COLLISION, 1 ; cells struct diff --git a/src/ui.s b/src/ui.s index ab6b7e1..872ce05 100644 --- a/src/ui.s +++ b/src/ui.s @@ -4,11 +4,49 @@ ; inits UI ui_init: - call ui_draw + ret + + ; schedules a unit draw + ; inputs: + ; de: unit +ui_unit_need_draw: + ld a, [draw_flags] + or a, DRAWF_UPDATE_UI + ld [draw_flags], a + + ; store actor + ld hl, ui_draw_actor + ld a, e + ld [hl+], a + ld a, d + ld [hl], a + ret ; update the UI ; this should only be called ; during blanking ui_draw: + ld a, [draw_flags] + xor a, DRAWF_UPDATE_UI + ld [draw_flags], a + + ld a, [ui_draw_actor] + ld l, a + ld a, [ui_draw_actor+1] + ld h, a + ; hl = actor + ld de, act_moves + add hl, de ; hl = current moves + ld a, [hl] ; a = counter + ld d, a ; d = counter + + ; draw to screen + ld a, UI_TILE_MOVE + ld hl, SCRN1+1 +@loop: + ld [hl+], a + dec d + jr nz, @loop REL + ret diff --git a/src/unit.s b/src/unit.s index d4cb195..8a6f664 100644 --- a/src/unit.s +++ b/src/unit.s @@ -42,6 +42,7 @@ units_update: ret unit_demo_1_init: + call ui_unit_need_draw ldnull bc ret @@ -252,7 +253,6 @@ unit_scroll_center: ; x position scroll ld a, [hl] - BREAK ; max x cp a, 0x16 jr c, @not_max_x REL @@ -307,7 +307,7 @@ unit_next: unit_demo_1: st_def 0x00, unit_demo_1_init, st_unit_demo_1_update - act_def ACT_T_DEMO_1, 0, 1, 1, 1, 1, 1, 2, 2, 0 + act_def ACT_T_DEMO_1, 0, 1, 2, 3, 4, 5, 2, 2, 0 act_st_def NULL, NULL, st_unit_demo_1_update, NULL st_unit_demo_1_update: diff --git a/src/update.s b/src/update.s index 1edf380..95c051c 100644 --- a/src/update.s +++ b/src/update.s @@ -5,6 +5,10 @@ update_game: ; tick rng every frame call rand call rand_save_srand + + ld a, [draw_flags] + and a, DRAWF_UPDATE_UI + call nz, ui_draw ld hl, p0_units call units_update diff --git a/src/wram.s b/src/wram.s index 1fbe1b9..77cc0e1 100644 --- a/src/wram.s +++ b/src/wram.s @@ -27,6 +27,11 @@ actor_player: .adv act_size bg_update_index: .adv 2 bg_update_queue: .adv bge_size * BGE_MAX +draw_flags: .adv 1 + + ; ptr to actor for next UI update +ui_draw_actor: .adv 2 + ; game state ; this region holds the entire game state ; everything thats needed for a savme game should be