From f75456cfdeeefafc6b4af43db5e0735fe5dc065f Mon Sep 17 00:00:00 2001 From: Ategon Date: Sun, 15 Sep 2024 00:22:02 -0400 Subject: [PATCH] Add building costs --- BuildingLevel.gd | 7 +++++++ Main.tscn | 9 +++------ parts/buildings/essencecompressor.txt | 3 +++ parts/buildings/foodgathering.txt | 2 ++ parts/buildings/foodprocessing.txt | 3 +++ parts/buildings/house.txt | 3 +++ parts/buildings/quarter.txt | 3 +++ parts/buildings/stoneminer.txt | 2 ++ parts/buildings/tents.txt | 3 +++ parts/buildings/waterprocessor.txt | 3 +++ parts/buildings/waterpump.txt | 2 ++ parts/buildings/woodcutter.txt | 2 ++ tile_map.gd | 1 + ui/building_menu.gd | 16 ++++++++++++++++ 14 files changed, 53 insertions(+), 6 deletions(-) diff --git a/BuildingLevel.gd b/BuildingLevel.gd index 62cd412..0032be0 100644 --- a/BuildingLevel.gd +++ b/BuildingLevel.gd @@ -104,6 +104,13 @@ func place_building(): building_data[tile] = { "key": Persister.get_value("building_key"), } + + var cost = Data.data.buildings[Persister.get_value("building_key")].cost + + if cost.has("wood"): + Persister.change_value("wood", -int(cost.wood)) + if cost.has("stone"): + Persister.change_value("stone", -int(cost.stone)) Persister.persist_data("drag_mode", false) diff --git a/Main.tscn b/Main.tscn index ad6f8c7..385e200 100644 --- a/Main.tscn +++ b/Main.tscn @@ -465,9 +465,8 @@ key = "essence" [node name="Control" type="Control" parent="CanvasLayer/UI/Background"] anchors_preset = 0 -offset_top = -28.0 offset_right = 40.0 -offset_bottom = 12.0 +offset_bottom = 40.0 [node name="WoodIcon" type="TextureRect" parent="CanvasLayer/UI/Background/Control"] layout_mode = 0 @@ -495,9 +494,8 @@ key = "wood" [node name="Control3" type="Control" parent="CanvasLayer/UI/Background"] anchors_preset = 0 offset_left = 41.0 -offset_top = -28.0 offset_right = 81.0 -offset_bottom = 12.0 +offset_bottom = 40.0 [node name="WoodIcon" type="TextureRect" parent="CanvasLayer/UI/Background/Control3"] layout_mode = 0 @@ -523,9 +521,8 @@ script = ExtResource("16_knn3d") [node name="Control2" type="Control" parent="CanvasLayer/UI/Background"] anchors_preset = 0 -offset_top = -28.0 offset_right = 40.0 -offset_bottom = 12.0 +offset_bottom = 40.0 [node name="StoneIcon" type="TextureRect" parent="CanvasLayer/UI/Background/Control2"] layout_mode = 0 diff --git a/parts/buildings/essencecompressor.txt b/parts/buildings/essencecompressor.txt index 09cb936..de2a504 100644 --- a/parts/buildings/essencecompressor.txt +++ b/parts/buildings/essencecompressor.txt @@ -4,3 +4,6 @@ resource: essence amount: 1 time: 10 max_workers: 6 +cost[] + stone: 3 + wood: 2 diff --git a/parts/buildings/foodgathering.txt b/parts/buildings/foodgathering.txt index 35e45b1..e9feea4 100644 --- a/parts/buildings/foodgathering.txt +++ b/parts/buildings/foodgathering.txt @@ -1,2 +1,4 @@ name: Field type: utility +cost[] + wood: 2 diff --git a/parts/buildings/foodprocessing.txt b/parts/buildings/foodprocessing.txt index e72ed63..72e5bc5 100644 --- a/parts/buildings/foodprocessing.txt +++ b/parts/buildings/foodprocessing.txt @@ -1,2 +1,5 @@ name: Farmhouse type: utility +cost[] + wood: 4 + stone: 8 diff --git a/parts/buildings/house.txt b/parts/buildings/house.txt index c3cfbc6..56a19fe 100644 --- a/parts/buildings/house.txt +++ b/parts/buildings/house.txt @@ -1,3 +1,6 @@ name: House type: housing amount: 5 +cost[] + wood: 18 + stone: 10 diff --git a/parts/buildings/quarter.txt b/parts/buildings/quarter.txt index 79268bb..0202499 100644 --- a/parts/buildings/quarter.txt +++ b/parts/buildings/quarter.txt @@ -1,3 +1,6 @@ name: Quarter type: housing amount: 3 +cost[] + wood: 12 + stone: 7 diff --git a/parts/buildings/stoneminer.txt b/parts/buildings/stoneminer.txt index bf4ea1b..24aba43 100644 --- a/parts/buildings/stoneminer.txt +++ b/parts/buildings/stoneminer.txt @@ -4,3 +4,5 @@ resource: stone amount: 1 time: 10 max_workers: 6 +cost[] + stone: 2 diff --git a/parts/buildings/tents.txt b/parts/buildings/tents.txt index 9c6e097..2ede8d7 100644 --- a/parts/buildings/tents.txt +++ b/parts/buildings/tents.txt @@ -1,3 +1,6 @@ name: Tent type: housing amount: 1 +cost[] + wood: 6 + stone: 4 diff --git a/parts/buildings/waterprocessor.txt b/parts/buildings/waterprocessor.txt index 44b2ef3..57df246 100644 --- a/parts/buildings/waterprocessor.txt +++ b/parts/buildings/waterprocessor.txt @@ -1,2 +1,5 @@ name: Water Processor type: utility +cost[] + wood: 6 + stone: 10 diff --git a/parts/buildings/waterpump.txt b/parts/buildings/waterpump.txt index 0f82b95..19786f9 100644 --- a/parts/buildings/waterpump.txt +++ b/parts/buildings/waterpump.txt @@ -1,2 +1,4 @@ name: Water Pump type: utility +cost[] + stone: 3 diff --git a/parts/buildings/woodcutter.txt b/parts/buildings/woodcutter.txt index 5c8cf46..2e53ae9 100644 --- a/parts/buildings/woodcutter.txt +++ b/parts/buildings/woodcutter.txt @@ -4,3 +4,5 @@ resource: wood amount: 1 time: 10 max_workers: 6 +cost[] + stone: 3 diff --git a/tile_map.gd b/tile_map.gd index f9e7bd6..3fd250e 100644 --- a/tile_map.gd +++ b/tile_map.gd @@ -131,6 +131,7 @@ func place_building(): Building_Mode = false Dic[str(tile)]["Key"] = building_key Dic[str(tile)]["Placed"] = true + Drag_Mode = false diff --git a/ui/building_menu.gd b/ui/building_menu.gd index aa40510..bb67579 100644 --- a/ui/building_menu.gd +++ b/ui/building_menu.gd @@ -26,6 +26,8 @@ extends Control func _ready() -> void: swap_to_tab(0) + Triggerer.listen("stone", _trigger_check) + Triggerer.listen("wood", _trigger_check) func swap_to_tab(index): @@ -50,7 +52,21 @@ func swap_to_tab(index): if i > 0: spacers[i - 1].visible = false + + _update_icons() +func _trigger_check(_data): + _update_icons() + +func _update_icons(): + for i in range(0, icons.size()): + if icons[i].visible: + var key = icons[i].key + var build_data = Data.data.buildings[key] + if (build_data.cost.has("stone") and Persister.get_value("stone", PersisterEnums.Scope.UNKNOWN, 0) < int(build_data.cost.stone)) or (build_data.cost.has("wood") and Persister.get_value("wood", PersisterEnums.Scope.UNKNOWN, 0) < int(build_data.cost.wood)): + icons[i].modulate = Color(1, 0.5, 0.5, 0.5) + else: + icons[i].modulate = Color(1, 1, 1, 1) func _on_building_tab_clicked() -> void: swap_to_tab(0)