From: Lukas Krickl Date: Sun, 30 Mar 2025 16:31:48 +0000 (+0200) Subject: ui: Added basic mapping for cursor selector X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=b78eaae70e721caa7127c420b19055624b8dd0df;p=gbrg%2F.git ui: Added basic mapping for cursor selector This is the first step to being able to place buildings --- diff --git a/src/buildings.s b/src/buildings.s new file mode 100644 index 0000000..518a8e1 --- /dev/null +++ b/src/buildings.s @@ -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 diff --git a/src/defs.s b/src/defs.s index caddd6f..8f9f21a 100644 --- a/src/defs.s +++ b/src/defs.s @@ -88,3 +88,10 @@ ; 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 diff --git a/src/main.s b/src/main.s index 87541ba..67da840 100644 --- a/src/main.s +++ b/src/main.s @@ -65,6 +65,7 @@ main: #include "map.s" #include "simulation.s" #include "state.s" +#include "buildings.s" #include "tiles.inc" ; fill bank diff --git a/src/ui.s b/src/ui.s index 8fd09e7..90a72b0 100644 --- 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 diff --git a/src/wram.s b/src/wram.s index 0a02205..cc254c2 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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: