aboutsummaryrefslogtreecommitdiff
path: root/game/src/GameSession/ProvinceOverviewPanel
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-05-12 02:21:09 +0200
committer GitHub <noreply@github.com>2023-05-12 02:21:09 +0200
commit398ba6f05ae1bb13e59790436bf0da299e5a399d (patch)
tree68cfc1f01f6a13067417e53d1ed8547cffbb969c /game/src/GameSession/ProvinceOverviewPanel
parentc784a95478ec369fe9255622d40ac498b7a23079 (diff)
parent9ed9ee209ef9accebb9ec0d81ec58b569d680b6a (diff)
Merge pull request #111 from OpenVic2Project/goods
Added Goods loading + mapmode
Diffstat (limited to 'game/src/GameSession/ProvinceOverviewPanel')
-rw-r--r--game/src/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd121
-rw-r--r--game/src/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.tscn86
2 files changed, 207 insertions, 0 deletions
diff --git a/game/src/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd b/game/src/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd
new file mode 100644
index 0000000..0d8d8b7
--- /dev/null
+++ b/game/src/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd
@@ -0,0 +1,121 @@
+extends PanelContainer
+
+@export var _province_name_label : Label
+@export var _region_name_label : Label
+@export var _life_rating_bar : ProgressBar
+@export var _rgo_icon_texture_rect : TextureRect
+@export var _rgo_name_label : Label
+@export var _buildings_container : Container
+
+const _missing_suffix : String = "_MISSING"
+
+var _selected_index : int:
+ get: return _selected_index
+ set(v):
+ _selected_index = v
+ update_info()
+var _province_info : Dictionary
+
+func _ready():
+ GameSingleton.province_selected.connect(_on_province_selected)
+ GameSingleton.state_updated.connect(update_info)
+ update_info()
+
+enum { CANNOT_EXPAND, CAN_EXPAND, PREPARING, EXPANDING }
+
+func _expand_building(building_identifier : String) -> void:
+ if GameSingleton.expand_building(_selected_index, building_identifier) != OK:
+ push_error("Failed to expand ", building_identifier, " in province #", _selected_index);
+
+# Each building row contains:
+# level - Level Label
+# name - Name Label
+# button - Expansion Button
+# progress_bar - Expansion ProgressBar
+var _building_rows : Array[Dictionary]
+
+# REQUIREMENTS:
+# * UI-183, UI-185, UI-186, UI-765, UI-187, UI-188, UI-189
+# * UI-191, UI-193, UI-194, UI-766, UI-195, UI-196, UI-197
+# * UI-199, UI-201, UI-202, UI-767, UI-203, UI-204, UI-205
+func _add_building_row() -> void:
+ var row : Dictionary
+
+ row.level = Label.new()
+ row.level.text = "X"
+ _buildings_container.add_child(row.level)
+
+ row.name = Label.new()
+ row.name.text = GameSingleton.get_building_info_building_key() + _missing_suffix
+ _buildings_container.add_child(row.name)
+
+ row.button = Button.new()
+ row.button.text = "EXPAND_PROVINCE_BUILDING"
+ row.button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
+ row.button.mouse_filter = Control.MOUSE_FILTER_PASS
+ row.button.pressed.connect(func(): _expand_building(row.name.text))
+ _buildings_container.add_child(row.button)
+
+ row.progress_bar = ProgressBar.new()
+ row.progress_bar.max_value = 1
+ row.progress_bar.size_flags_horizontal = Control.SIZE_EXPAND_FILL
+ row.progress_bar.mouse_filter = Control.MOUSE_FILTER_PASS
+ _buildings_container.add_child(row.progress_bar)
+
+ _building_rows.append(row)
+ _set_building_row(_building_rows.size() - 1, {})
+
+func _set_building_row(index : int, building : Dictionary) -> void:
+ if index < 0 or index > _building_rows.size():
+ push_error("Invalid building row index: ", index, " (max ", _building_rows.size(), ")")
+ return
+ if index == _building_rows.size(): _add_building_row()
+ var row := _building_rows[index]
+ if building.is_empty():
+ row.level.visible = false
+ row.name.visible = false
+ row.progress_bar.visible = false
+ row.button.visible = false
+ return
+ row.level.text = str(building.get(GameSingleton.get_building_info_level_key(), 0))
+ row.level.visible = true
+ row.name.text = building.get(GameSingleton.get_building_info_building_key(),
+ GameSingleton.get_building_info_building_key() + _missing_suffix)
+ row.name.visible = true
+
+ var expansion_state : int = building.get(GameSingleton.get_building_info_expansion_state_key(),
+ CANNOT_EXPAND)
+ var show_progress_bar := expansion_state == PREPARING or expansion_state == EXPANDING
+ row.progress_bar.value = building.get(GameSingleton.get_building_info_expansion_progress_key(), 0)
+ row.progress_bar.visible = show_progress_bar
+ row.button.disabled = expansion_state != CAN_EXPAND
+ row.button.visible = not show_progress_bar
+
+func update_info() -> void:
+ _province_info = GameSingleton.get_province_info_from_index(_selected_index)
+ if _province_info:
+ _province_name_label.text = _province_info.get(GameSingleton.get_province_info_province_key(),
+ GameSingleton.get_province_info_province_key() + _missing_suffix)
+ _region_name_label.text = _province_info.get(GameSingleton.get_province_info_region_key(),
+ GameSingleton.get_province_info_region_key() + _missing_suffix)
+
+ _life_rating_bar.value = _province_info.get(GameSingleton.get_province_info_life_rating_key(), 0)
+ _life_rating_bar.tooltip_text = tr("LIFE_RATING_TOOLTIP").format({ "life_rating": _life_rating_bar.value })
+
+ _rgo_name_label.text = _province_info.get(GameSingleton.get_province_info_rgo_key(),
+ GameSingleton.get_province_info_rgo_key() + _missing_suffix)
+ _rgo_icon_texture_rect.texture = GameSingleton.get_good_icon_texture(_rgo_name_label.text)
+
+ var buildings : Array = _province_info.get(GameSingleton.get_province_info_buildings_key(), [])
+ for i in max(buildings.size(), _building_rows.size()):
+ _set_building_row(i, buildings[i] if i < buildings.size() else {})
+
+ show()
+ else:
+ hide()
+
+func _on_province_selected(index : int) -> void:
+ _selected_index = index
+
+func _on_close_button_pressed() -> void:
+ GameSingleton.set_selected_province(0)
diff --git a/game/src/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.tscn b/game/src/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.tscn
new file mode 100644
index 0000000..a233db0
--- /dev/null
+++ b/game/src/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.tscn
@@ -0,0 +1,86 @@
+[gd_scene load_steps=2 format=3 uid="uid://byq323jbel48u"]
+
+[ext_resource type="Script" path="res://src/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd" id="1_3n8k5"]
+
+[node name="ProvinceOverviewPanel" type="PanelContainer" node_paths=PackedStringArray("_province_name_label", "_region_name_label", "_life_rating_bar", "_rgo_icon_texture_rect", "_rgo_name_label", "_buildings_container")]
+editor_description = "UI-56"
+anchors_preset = 2
+anchor_top = 1.0
+anchor_bottom = 1.0
+offset_top = -300.0
+offset_right = 200.0
+grow_vertical = 0
+mouse_filter = 1
+script = ExtResource("1_3n8k5")
+_province_name_label = NodePath("PanelList/TopBarList/NameList/ProvinceName")
+_region_name_label = NodePath("PanelList/TopBarList/NameList/RegionName")
+_life_rating_bar = NodePath("PanelList/TopBarList/NameList/LifeRatingBar")
+_rgo_icon_texture_rect = NodePath("PanelList/InteractList/RGOInfo/RGOIcon")
+_rgo_name_label = NodePath("PanelList/InteractList/RGOInfo/RGOName")
+_buildings_container = NodePath("PanelList/InteractList/BuildingsContainer")
+
+[node name="PanelList" type="VBoxContainer" parent="."]
+layout_mode = 2
+
+[node name="TopBarList" type="HBoxContainer" parent="PanelList"]
+layout_mode = 2
+
+[node name="NameList" type="VBoxContainer" parent="PanelList/TopBarList"]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 0
+
+[node name="ProvinceName" type="Label" parent="PanelList/TopBarList/NameList"]
+editor_description = "UI-57"
+layout_mode = 2
+text = "province_MISSING"
+vertical_alignment = 1
+
+[node name="RegionName" type="Label" parent="PanelList/TopBarList/NameList"]
+editor_description = "UI-58"
+layout_mode = 2
+text = "region_MISSING"
+vertical_alignment = 1
+
+[node name="LifeRatingBar" type="ProgressBar" parent="PanelList/TopBarList/NameList"]
+editor_description = "UI-62"
+layout_mode = 2
+mouse_filter = 1
+
+[node name="CloseButton" type="Button" parent="PanelList/TopBarList"]
+custom_minimum_size = Vector2(30, 30)
+layout_mode = 2
+size_flags_vertical = 0
+mouse_filter = 1
+text = "X"
+
+[node name="InteractList" type="VBoxContainer" parent="PanelList"]
+layout_mode = 2
+size_flags_vertical = 3
+
+[node name="HSeparator" type="HSeparator" parent="PanelList/InteractList"]
+layout_mode = 2
+mouse_filter = 1
+
+[node name="RGOInfo" type="HBoxContainer" parent="PanelList/InteractList"]
+editor_description = "UI-112"
+layout_mode = 2
+
+[node name="RGOIcon" type="TextureRect" parent="PanelList/InteractList/RGOInfo"]
+editor_description = "UI-100"
+layout_mode = 2
+
+[node name="RGOName" type="Label" parent="PanelList/InteractList/RGOInfo"]
+layout_mode = 2
+text = "rgo_MISSING"
+vertical_alignment = 1
+
+[node name="HSeparator2" type="HSeparator" parent="PanelList/InteractList"]
+layout_mode = 2
+mouse_filter = 1
+
+[node name="BuildingsContainer" type="GridContainer" parent="PanelList/InteractList"]
+layout_mode = 2
+columns = 3
+
+[connection signal="pressed" from="PanelList/TopBarList/CloseButton" to="." method="_on_close_button_pressed"]