ui: Added basic mapping for cursor selector
authorLukas Krickl <lukas@krickl.dev>
Sun, 30 Mar 2025 16:31:48 +0000 (18:31 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 30 Mar 2025 16:31:48 +0000 (18:31 +0200)
This is the first step to being able to place buildings

src/buildings.s [new file with mode: 0644]
src/defs.s
src/main.s
src/ui.s
src/wram.s

diff --git a/src/buildings.s b/src/buildings.s
new file mode 100644 (file)
index 0000000..518a8e1
--- /dev/null
@@ -0,0 +1,6 @@
+  ; places a building at the current cursor position
+  ; performs pre-checks and displays an error 
+  ; if pre-conditions for building fail
+  ; e.g. not enough resources, not enough space
+building_build:
+  ret
index caddd6f5cce81423d1487f222a8bc5d8bd12d350..8f9f21a445239eabc40306f7c3cd589543e29106 100644 (file)
   ; custom parameter
 .de act_p0, 1
 .de act_size, 0
+
+  ; building selection
+.se 0
+.de BT_ROAD, 1
+.de BT_WAREHOUSE, 1
+.de BT_FARM, 1
+.de BT_LUMBER, 1
index 87541bac918b28b5b700063e48d9020ada7f7601..67da84008f17d46e3dcaf07fc1331dc0380607b1 100644 (file)
@@ -65,6 +65,7 @@ main:
 #include "map.s"
 #include "simulation.s"
 #include "state.s"
+#include "buildings.s"
 #include "tiles.inc"
 
 ; fill bank
index 8fd09e760567d66aebfaf2a1e62804d37f81abb0..90a72b0847de783990f095f7351b9fcfa523f22b 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -22,6 +22,15 @@ ui_cursor_label_table:
   dw STR_FARM
   dw STR_LUMBER
 
+  ; converts from UI cursor position
+  ; to building type 
+ui_to_building_selecction_table:
+  .db BT_WAREHOUSE
+  .db BT_ROAD
+  .db BT_FARM
+  .db BT_LUMBER
+
+
   ; inits UI
 ui_init:
   call ui_draw
@@ -148,5 +157,20 @@ ui_building_selector_inputs:
     ret
 @not_left:
 
+  input_just BTNA
+  jr z, @not_a REL
+    
+    ; load building to be built into building selector 
+    ld a, [ui_cursor_pos]
+    ld d, 0
+    ld e, a
+    ld hl, ui_to_building_selecction_table
+    add hl, de ; hl = correct value 
+    ld a, [hl]
+    ld [cursor_selected_building], a 
+    ld bc, st_ui_buildung_selector_exit
+    ret
+@not_a:
+
   ldnull bc
   ret
index 0a02205a807e9a3e2ff358b08b130cdc436a46fe..cc254c2b13604d00e0fbc37e1adc5297480d64ad 100644 (file)
@@ -37,6 +37,9 @@ cursor_x: .adv 1
 cursor_move_y: .adv 1
 cursor_move_x: .adv 1
 
+  ; enum of type BT_
+cursor_selected_building: .adv 1
+
   ; +/-1 for each time the cursor moves
   ; allows us to move scroll when needed 
 scroll_move_y: .adv 1
@@ -46,12 +49,12 @@ scroll_move_x: .adv 1
 scroll_y: .adv 1
 scroll_x: .adv 1
 
-money: .adv 3
-debt: .adv 3
-demand_house: .adv 1
-demand_shop: .adv 1
-demand_factory: .adv 1
-population: .adv 3
+  ; resources
+r_gold: .adv 2
+r_lumber: .adv 2
+r_stone: .adv 2
+r_food: .adv 2
+r_population: .adv 2
 
 state_cells: .adv c_size * MAP_SIZE
 state_cells_end: