diff options
Diffstat (limited to 'game/src/GameSession')
-rw-r--r-- | game/src/GameSession/GameSession.gd | 5 | ||||
-rw-r--r-- | game/src/GameSession/GameSessionMenu.gd | 1 | ||||
-rw-r--r-- | game/src/GameSession/GameSpeedPanel.gd | 29 | ||||
-rw-r--r-- | game/src/GameSession/MapControlPanel.gd | 6 | ||||
-rw-r--r-- | game/src/GameSession/MapView.gd | 21 | ||||
-rw-r--r-- | game/src/GameSession/ProvinceOverviewPanel.gd | 82 | ||||
-rw-r--r-- | game/src/GameSession/ProvinceOverviewPanel.tscn | 14 |
7 files changed, 113 insertions, 45 deletions
diff --git a/game/src/GameSession/GameSession.gd b/game/src/GameSession/GameSession.gd index fe83a8a..2761815 100644 --- a/game/src/GameSession/GameSession.gd +++ b/game/src/GameSession/GameSession.gd @@ -5,7 +5,10 @@ extends Control func _ready(): Events.Options.load_settings_from_file() +func _process(delta : float): + GameSingleton.try_tick() + # REQUIREMENTS: # * SS-42 -func _on_game_session_menu_button_pressed(): +func _on_game_session_menu_button_pressed() -> void: _game_session_menu.visible = !_game_session_menu.visible diff --git a/game/src/GameSession/GameSessionMenu.gd b/game/src/GameSession/GameSessionMenu.gd index 8a76c0f..7d785ca 100644 --- a/game/src/GameSession/GameSessionMenu.gd +++ b/game/src/GameSession/GameSessionMenu.gd @@ -8,6 +8,7 @@ signal options_button_pressed # * SS-47 # * UIFUN-69 func _on_main_menu_confirmed() -> void: + # TODO - reset map when going back to main menu get_tree().change_scene_to_packed(_main_menu_scene) # REQUIREMENTS: diff --git a/game/src/GameSession/GameSpeedPanel.gd b/game/src/GameSession/GameSpeedPanel.gd index 8dc35d7..c203032 100644 --- a/game/src/GameSession/GameSpeedPanel.gd +++ b/game/src/GameSession/GameSpeedPanel.gd @@ -7,27 +7,32 @@ extends PanelContainer @export var _decrease_speed_button : Button @export var _increase_speed_button : Button -var is_game_paused : bool = true - # Called when the node enters the scene tree for the first time. func _ready(): - _update_playpause_button() + GameSingleton.state_updated.connect(_update_buttons) + _update_buttons() + +func _update_buttons(): + _play_pause_display_button.text = "⏸️" if GameSingleton.is_paused() else "▶" + + _increase_speed_button.disabled = not GameSingleton.can_increase_speed() + _decrease_speed_button.disabled = not GameSingleton.can_decrease_speed() -func _update_playpause_button(): - _play_pause_display_button.text = "⏸️" if is_game_paused else "▶" - print("Game is paused" if is_game_paused else "Game is advancing") + _longform_date_button.text = GameSingleton.get_longform_date() func _on_decrease_speed_button_pressed(): - print("Decrease speed") + GameSingleton.decrease_speed() + _update_buttons() func _on_increase_speed_button_pressed(): - print("Increase speed") + GameSingleton.increase_speed() + _update_buttons() func _on_play_pause_display_button_pressed(): - is_game_paused = !is_game_paused - _update_playpause_button() + GameSingleton.toggle_paused() + _update_buttons() func _on_longform_date_label_pressed(): - is_game_paused = !is_game_paused - _update_playpause_button() + GameSingleton.toggle_paused() + _update_buttons() diff --git a/game/src/GameSession/MapControlPanel.gd b/game/src/GameSession/MapControlPanel.gd index d5810c5..73d7e06 100644 --- a/game/src/GameSession/MapControlPanel.gd +++ b/game/src/GameSession/MapControlPanel.gd @@ -27,8 +27,8 @@ func _add_mapmode_button(identifier : String) -> void: func _ready(): _mapmode_button_group = ButtonGroup.new() _mapmode_button_group.pressed.connect(_mapmode_pressed) - for index in MapSingleton.get_mapmode_count(): - _add_mapmode_button(MapSingleton.get_mapmode_identifier(index)) + for index in GameSingleton.get_mapmode_count(): + _add_mapmode_button(GameSingleton.get_mapmode_identifier(index)) # REQUIREMENTS: # * UIFUN-10 @@ -39,7 +39,7 @@ func _on_game_session_menu_button_pressed() -> void: # * SS-76 # * UIFUN-129, UIFUN-133 func _mapmode_pressed(button : BaseButton) -> void: - MapSingleton.set_mapmode(button.tooltip_text) + GameSingleton.set_mapmode(button.tooltip_text) mapmode_changed.emit() func _on_map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) -> void: diff --git a/game/src/GameSession/MapView.gd b/game/src/GameSession/MapView.gd index ae49e82..ac060e1 100644 --- a/game/src/GameSession/MapView.gd +++ b/game/src/GameSession/MapView.gd @@ -1,6 +1,6 @@ extends Node3D -signal province_selected(identifier : String) +signal province_selected(index : int) signal map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) const _action_north : StringName = &"map_north" @@ -21,7 +21,7 @@ const _shader_param_terrain_tile_factor : StringName = &"terrain_tile_factor" @export var _camera : Camera3D @export var _cardinal_move_speed : float = 1.0 -@export var _edge_move_threshold: float = 0.02 +@export var _edge_move_threshold: float = 0.01 @export var _edge_move_speed: float = 2.5 var _drag_anchor : Vector2 var _drag_active : bool = false @@ -53,7 +53,7 @@ var _viewport_dims : Vector2 = Vector2(1, 1) # ??? Strange Godot/GDExtension Bug ??? # Upon first opening a clone of this repo with the Godot Editor, -# if MapSingleton.get_province_index_image is called before MapMesh +# if GameSingleton.get_province_index_image is called before MapMesh # is referenced in the script below, then the editor will crash due # to a failed HashMap lookup. I'm not sure if this is a bug in the # editor, GDExtension, my own extension, or a combination of them. @@ -78,7 +78,7 @@ func _ready(): _map_shader_material = map_material # Province index texture - _map_province_index_image = MapSingleton.get_province_index_image() + _map_province_index_image = GameSingleton.get_province_index_image() if _map_province_index_image == null: push_error("Failed to get province index image!") return @@ -86,7 +86,7 @@ func _ready(): _map_shader_material.set_shader_parameter(_shader_param_province_index, province_index_texture) # Province colour texture - _map_province_colour_image = MapSingleton.get_province_colour_image() + _map_province_colour_image = GameSingleton.get_province_colour_image() if _map_province_colour_image == null: push_error("Failed to get province colour image!") return @@ -99,7 +99,7 @@ func _ready(): _map_mesh = _map_mesh_instance.mesh # Set map mesh size and get bounds - _map_image_size = Vector2(Vector2i(MapSingleton.get_width(), MapSingleton.get_height())) + _map_image_size = Vector2(Vector2i(GameSingleton.get_width(), GameSingleton.get_height())) _map_mesh.aspect_ratio = _map_image_size.x / _map_image_size.y _map_shader_material.set_shader_parameter(_shader_param_terrain_tile_factor, _map_image_size.y / 64.0) var map_mesh_aabb := _map_mesh.get_core_aabb() * _map_mesh_instance.transform @@ -120,7 +120,7 @@ func _notification(what : int): _on_mouse_exited_viewport() func _update_colour_texture() -> void: - MapSingleton.update_colour_image() + GameSingleton.update_colour_image() _map_province_colour_texture.update(_map_province_colour_image) func _world_to_map_coords(pos : Vector3) -> Vector2: @@ -151,10 +151,9 @@ func _unhandled_input(event : InputEvent): if _mouse_over_viewport and event.is_action_pressed(_action_click): # Check if the mouse is outside of bounds if _map_mesh.is_valid_uv_coord(_mouse_pos_map): - var selected_index := MapSingleton.get_province_index_from_uv_coords(_mouse_pos_map) + var selected_index := GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map) _map_shader_material.set_shader_parameter(_shader_param_selected_index, selected_index) - var province_identifier := MapSingleton.get_province_identifier_from_uv_coords(_mouse_pos_map) - province_selected.emit(province_identifier) + province_selected.emit(selected_index) else: print("Clicked outside the map!") elif event.is_action_pressed(_action_drag): @@ -248,7 +247,7 @@ func _update_minimap_viewport() -> void: func _update_mouse_map_position() -> void: _mouse_pos_map = _viewport_to_map_coords(_mouse_pos_viewport) - var hover_index := MapSingleton.get_province_index_from_uv_coords(_mouse_pos_map) + var hover_index := GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map) if _mouse_over_viewport: _map_shader_material.set_shader_parameter(_shader_param_hover_index, hover_index) diff --git a/game/src/GameSession/ProvinceOverviewPanel.gd b/game/src/GameSession/ProvinceOverviewPanel.gd index 4615df9..832f21c 100644 --- a/game/src/GameSession/ProvinceOverviewPanel.gd +++ b/game/src/GameSession/ProvinceOverviewPanel.gd @@ -2,32 +2,84 @@ extends Panel @export var _province_name_label : Label @export var _region_name_label : Label +@export var _buildings_container : Container -var _province_identifier: String = "": - get: return _province_identifier +const _missing_suffix : String = "_MISSING" + +var _selected_index : int: + get: return _selected_index set(v): - _province_identifier = v + _selected_index = v update_info() - -const _name_suffix : String = "_NAME" +var _province_info : Dictionary func _ready(): + 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); + +func _add_building(building : Dictionary) -> void: + const _building_key : StringName = &"building" + const _level_key : StringName = &"level" + const _expansion_state_key : StringName = &"expansion_state" + const _start_key : StringName = &"start" + const _end_key : StringName = &"end" + const _expansion_progress_key : StringName = &"expansion_progress" + + const _expand_province_building : String = "EXPAND_PROVINCE_BUILDING" + + var level_label := Label.new() + level_label.text = str(building.get(_level_key, 0)) + _buildings_container.add_child(level_label) + + var building_label := Label.new() + building_label.text = building.get(_building_key, _building_key + _missing_suffix) + _buildings_container.add_child(building_label) + + var expansion_state : int = building.get(_expansion_state_key, CANNOT_EXPAND) + if expansion_state == PREPARING or expansion_state == EXPANDING: + var progress_bar := ProgressBar.new() + progress_bar.max_value = 1 + progress_bar.value = building.get(_expansion_progress_key, 0) + progress_bar.size_flags_horizontal = Control.SIZE_EXPAND_FILL + _buildings_container.add_child(progress_bar) + else: + var expand_button := Button.new() + expand_button.text = _expand_province_building + expand_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL + expand_button.disabled = expansion_state != CAN_EXPAND + expand_button.pressed.connect(func(): _expand_building(building_label.text)) + _buildings_container.add_child(expand_button) + func update_info() -> void: - if _province_identifier: - _province_name_label.text = _province_identifier + _name_suffix - var region_identifier := MapSingleton.get_region_identifier_from_province_identifier(_province_identifier) - if region_identifier: - _region_name_label.text = region_identifier + _name_suffix - else: - _region_name_label.text = "NO REGION" + const _province_key : StringName = &"province" + const _region_key : StringName = &"region" + const _life_rating_key : StringName = &"life_rating" + const _buildings_key : StringName = &"buildings" + + _province_info = GameSingleton.get_province_info_from_index(_selected_index) + if _province_info: + _province_name_label.text = _province_info.get(_province_key, _province_key + _missing_suffix) + _region_name_label.text = _province_info.get(_region_key, _region_key + _missing_suffix) + + for child in _buildings_container.get_children(): + _buildings_container.remove_child(child) + child.queue_free() + var buildings : Array = _province_info.get(_buildings_key, []) + for building in buildings: + _add_building(building) + show() else: hide() -func _on_province_selected(identifier : String) -> void: - _province_identifier = identifier +func _on_province_selected(index : int) -> void: + _selected_index = index func _on_close_button_pressed() -> void: - _province_identifier = "" + _selected_index = 0 diff --git a/game/src/GameSession/ProvinceOverviewPanel.tscn b/game/src/GameSession/ProvinceOverviewPanel.tscn index 7d21edc..dacdc4b 100644 --- a/game/src/GameSession/ProvinceOverviewPanel.tscn +++ b/game/src/GameSession/ProvinceOverviewPanel.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://src/GameSession/ProvinceOverviewPanel.gd" id="1_3n8k5"] -[node name="ProvinceOverviewPanel" type="Panel" node_paths=PackedStringArray("_province_name_label", "_region_name_label")] +[node name="ProvinceOverviewPanel" type="Panel" node_paths=PackedStringArray("_province_name_label", "_region_name_label", "_buildings_container")] editor_description = "UI-56" anchors_preset = 2 anchor_top = 1.0 @@ -13,6 +13,7 @@ grow_vertical = 0 script = ExtResource("1_3n8k5") _province_name_label = NodePath("VBoxContainer/ProvinceName") _region_name_label = NodePath("VBoxContainer/RegionName") +_buildings_container = NodePath("VBoxContainer/BuildingsContainer") [node name="VBoxContainer" type="VBoxContainer" parent="."] layout_mode = 1 @@ -27,15 +28,22 @@ offset_bottom = -5.0 [node name="ProvinceName" type="Label" parent="VBoxContainer"] editor_description = "UI-57" layout_mode = 2 -text = "PROVINCE_NAME" +text = "province_MISSING" vertical_alignment = 1 [node name="RegionName" type="Label" parent="VBoxContainer"] editor_description = "UI-58" layout_mode = 2 -text = "REGION_NAME" +text = "region_MISSING" vertical_alignment = 1 +[node name="HSeparator" type="HSeparator" parent="VBoxContainer"] +layout_mode = 2 + +[node name="BuildingsContainer" type="GridContainer" parent="VBoxContainer"] +layout_mode = 2 +columns = 3 + [node name="CloseButton" type="Button" parent="."] custom_minimum_size = Vector2(30, 30) layout_mode = 1 |