ui: added cursor movemnet
authorLukas Krickl <lukas@krickl.dev>
Sun, 30 Mar 2025 04:47:38 +0000 (06:47 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 30 Mar 2025 04:47:38 +0000 (06:47 +0200)
the ui cursor can now move and displays strings from a table

src/macros.inc
src/state.s
src/ui.s

index fc5b0a0433e339d52c92f935e0e5f9bc9ada77e2..b4d616336384d272fa750eb7fb6c2052c15a20e3 100644 (file)
   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
index d7911e1c3c8fb9e375e4bc6fe6cf414d82e90d1f..749f1d274ae0dd558ae3bf50bd714da3a455f2ad 100644 (file)
@@ -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 
 
index 03b5bb6f7f3763dc07df581525e774ca368f3641..ef26bfc1c890a227f10de774703a1157de5c3e47 100644 (file)
--- 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