ui: Added more strings and adjuted label position
authorLukas Krickl <lukas@krickl.dev>
Sun, 30 Mar 2025 05:41:21 +0000 (07:41 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 30 Mar 2025 05:41:21 +0000 (07:41 +0200)
src/macros.inc
src/strings.s
src/ui.s

index b4d616336384d272fa750eb7fb6c2052c15a20e3..12d26ac478dc74d92fe88f6242336cc6a9526d42 100644 (file)
 #macro ldnull 
   ld $1, 0
 #endmacro
+
+  ; creates a NUL terminated string 
+  ; inputs:
+  ;   $1: string
+#macro strt
+  .str $1
+  .db 0
+#endmacro
index 836899dbe840cc30bee5de0912f18081fd9559ed..124bd3b286351e710d67ca6f9942131b0206a6fa 100644 (file)
@@ -23,6 +23,11 @@ STR_WAREHOUSE:
 .str "WAREHOUSE"
 .db 0
 
+STR_ROAD: strt "ROAD"
+STR_FARM: strt "FARM"
+STR_LUMBER: strt "LUMBER"
+
+
 STR_PANIC:
 .str "PANIC"
 .db 0
index ef26bfc1c890a227f10de774703a1157de5c3e47..8fd09e760567d66aebfaf2a1e62804d37f81abb0 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -4,16 +4,23 @@
 #define UI_TILE_FARM 130
 #define UI_TILE_LUMBER 131
 
+#define UI_BUILDING_TEXT_X 2
+#define UI_BUILDING_TEXT_Y 120
+
 #define UI_CURSOR_BUILDING_BASE_X 2 
-#define UI_CURSOR_BUILDING_BASE_Y 120
+#define UI_CURSOR_BUILDING_BASE_Y 128
 
-#define UI_TEXT_SPRITE_0 shadow_oam+4
+#define UI_TEXT_SPRITE_LEN oamsize*10
+#define UI_TEXT_SPRITE_0 shadow_oam+oamsize
 
   ; lookup table for 
   ; labels displayed when hovering
   ; over a building
 ui_cursor_label_table:
   dw STR_WAREHOUSE
+  dw STR_ROAD
+  dw STR_FARM
+  dw STR_LUMBER
 
   ; inits UI
 ui_init:
@@ -24,7 +31,7 @@ ui_init:
   ; this should only be called 
   ; during blanking 
 ui_draw:
-  ld hl, SCRN1
+  ld hl, SCRN1+32
   inc hl
 
   ld a, UI_TILE_WAREHOUSE 
@@ -49,7 +56,10 @@ ui_building_selector_update:
   pop bc
   ret
 
+  ; draw building selector cursor 
+  ; and text
 ui_building_selector_draw:
+  ; draw cursor 
   ld hl, PLAYER_SPRITE1
   
   ld a, UI_CURSOR_BUILDING_BASE_Y 
@@ -69,7 +79,13 @@ ui_building_selector_draw:
   ld a, CURSOR_TILE
   ld [hl+], a
 
-  ; TODO: print based on cursor location
+  ; clear text objects
+  ld hl, UI_TEXT_SPRITE_0 
+  ld bc, UI_TEXT_SPRITE_LEN
+  ld d, 0
+  call memset
+
+  ; draw text 
   ld a, [ui_cursor_pos]
   sla a ; * 2
   ld hl, ui_cursor_label_table
@@ -85,8 +101,8 @@ ui_building_selector_draw:
   ld h, a 
   ; hl = string ptr
 
-  ld b, 10
-  ld c, 10
+  ld b, UI_BUILDING_TEXT_Y
+  ld c, UI_BUILDING_TEXT_X
   ld de, UI_TEXT_SPRITE_0
   call objputs
 
@@ -100,6 +116,7 @@ ui_building_selector_exit:
   ldnull bc
   ret
 
+  ; building selectr input reader
 ui_building_selector_inputs:
   input_just BTNSELECT
   jr z, @not_select REL