From deb0ea6fcba79944af6b5e0fe526737180d19b47 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 30 Mar 2025 06:47:38 +0200 Subject: [PATCH] ui: added cursor movemnet the ui cursor can now move and displays strings from a table --- src/macros.inc | 9 +++++++++ src/state.s | 2 ++ src/ui.s | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/macros.inc b/src/macros.inc index fc5b0a0..b4d6163 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -67,6 +67,15 @@ srl $1 ; / 16 #endmacro + ; multiplies a regiser with 8 + ; inputs: + ; $1: the register +#macro mul8 + sla $1 ; * 2 + sla $1 ; * 4 + sla $1 ; * 8 +#endmacro + ; asserts. if $1 != $2 causes a ld b, b ; inputs: ; $1: register to assert diff --git a/src/state.s b/src/state.s index d7911e1..749f1d2 100644 --- a/src/state.s +++ b/src/state.s @@ -90,6 +90,8 @@ st_cursor_delay: st_ui_building_selector: st_def 0, ui_building_selector_update, st_ui_building_selector +st_ui_building_selector_delay: + st_def CURSOR_MOVE_TIMER, st_null_fn, st_ui_building_selector st_ui_buildung_selector_exit: st_def 0, ui_building_selector_exit, st_cursor diff --git a/src/ui.s b/src/ui.s index 03b5bb6..ef26bfc 100644 --- a/src/ui.s +++ b/src/ui.s @@ -9,6 +9,12 @@ #define UI_TEXT_SPRITE_0 shadow_oam+4 + ; lookup table for + ; labels displayed when hovering + ; over a building +ui_cursor_label_table: + dw STR_WAREHOUSE + ; inits UI ui_init: call ui_draw @@ -50,15 +56,35 @@ ui_building_selector_draw: add a, OBJ_OFF_Y ld [hl+], a + ld a, [ui_cursor_pos] + mul8 a + ld b, a ; b = curosr * 8 + ld a, UI_CURSOR_BUILDING_BASE_X add a, OBJ_OFF_X + ; add cursor pos * 8 + add a, b ld [hl+], a ld a, CURSOR_TILE ld [hl+], a ; TODO: print based on cursor location - ld hl, STR_WAREHOUSE + ld a, [ui_cursor_pos] + sla a ; * 2 + ld hl, ui_cursor_label_table + ld d, 0 + ld e, a + add hl, de + push hl + pop de ; de = pointing to label ptr + ld a, [de] + ld l, a + inc de + ld a, [de] + ld h, a + ; hl = string ptr + ld b, 10 ld c, 10 ld de, UI_TEXT_SPRITE_0 @@ -82,5 +108,28 @@ ui_building_selector_inputs: ld bc, st_ui_buildung_selector_exit ret @not_select: + + input_held BTNRIGHT + jr z, @not_right REL + + ld a, [ui_cursor_pos] + inc a + ld [ui_cursor_pos], a + + ld bc, st_ui_building_selector_delay + ret +@not_right: + + input_held BTNLEFT + jr z, @not_left REL + + ld a, [ui_cursor_pos] + dec a + ld [ui_cursor_pos], a + + ld bc, st_ui_building_selector_delay + ret +@not_left: + ldnull bc ret -- 2.30.2