diff options
author | hop311 <hop3114@gmail.com> | 2023-12-19 00:38:54 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2023-12-25 19:06:13 +0100 |
commit | 4e9764ee29fb7b453862835d5aa3a081b0f9a269 (patch) | |
tree | a59c5b960a706a383b8ebd1dbcfb704067a5b51b /game/src/Game | |
parent | d26c990d9a5596a3ef3b32ba1cb0f99950cd6d34 (diff) |
Back to UI Work
- UIAdapter -> UITools with cleaner API
- GUIOverlappingElementsBox (for core and modifier icons)
- Improved GUINode API
- Province building slots
- TypeHints for files in the GameSession folder
- Incorporate SIM strong colour types
Diffstat (limited to 'game/src/Game')
-rw-r--r-- | game/src/Game/GameSession/GameSession.gd | 4 | ||||
-rw-r--r-- | game/src/Game/GameSession/GameSession.tscn | 10 | ||||
-rw-r--r-- | game/src/Game/GameSession/GameSessionMenu.gd | 6 | ||||
-rw-r--r-- | game/src/Game/GameSession/MapControlPanel/MapControlPanel.gd | 4 | ||||
-rw-r--r-- | game/src/Game/GameSession/MapControlPanel/Minimap.gd | 6 | ||||
-rw-r--r-- | game/src/Game/GameSession/MapView.gd | 30 | ||||
-rw-r--r-- | game/src/Game/GameSession/MapView.tscn | 1 | ||||
-rw-r--r-- | game/src/Game/GameSession/ProvinceOverviewPanel.gd | 365 | ||||
-rw-r--r-- | game/src/Game/GameSession/Topbar.gd | 26 |
9 files changed, 254 insertions, 198 deletions
diff --git a/game/src/Game/GameSession/GameSession.gd b/game/src/Game/GameSession/GameSession.gd index 305709c..f085073 100644 --- a/game/src/Game/GameSession/GameSession.gd +++ b/game/src/Game/GameSession/GameSession.gd @@ -2,12 +2,12 @@ extends Control @export var _game_session_menu : Control -func _ready(): +func _ready() -> void: Events.Options.load_settings_from_file() if GameSingleton.setup_game(0) != OK: push_error("Failed to setup game") -func _process(_delta : float): +func _process(_delta : float) -> void: GameSingleton.try_tick() # REQUIREMENTS: diff --git a/game/src/Game/GameSession/GameSession.tscn b/game/src/Game/GameSession/GameSession.tscn index 2dd0e16..a3a5f38 100644 --- a/game/src/Game/GameSession/GameSession.tscn +++ b/game/src/Game/GameSession/GameSession.tscn @@ -31,13 +31,15 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -mouse_filter = 1 script = ExtResource("5_lfv8l") [node name="Topbar" type="GUINode" parent="."] -layout_mode = 0 -offset_right = 40.0 -offset_bottom = 40.0 +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 script = ExtResource("4_2kbih") [node name="MapControlPanel" parent="." instance=ExtResource("3_afh6d")] diff --git a/game/src/Game/GameSession/GameSessionMenu.gd b/game/src/Game/GameSession/GameSessionMenu.gd index 23ef2ef..7db0572 100644 --- a/game/src/Game/GameSession/GameSessionMenu.gd +++ b/game/src/Game/GameSession/GameSessionMenu.gd @@ -63,7 +63,7 @@ func _on_quit_confirmed() -> void: func _on_options_button_pressed() -> void: options_button_pressed.emit() -func _on_main_menu_dialog_custom_action(action) -> void: +func _on_main_menu_dialog_custom_action(action : StringName) -> void: match action: &"save_and_main_menu": _on_main_menu_confirmed() @@ -73,8 +73,8 @@ func _on_quit_dialog_custom_action(action : StringName) -> void: &"save_and_quit": _on_quit_confirmed() -func _on_save_button_pressed(): +func _on_save_button_pressed() -> void: save_button_pressed.emit() -func _on_load_button_pressed(): +func _on_load_button_pressed() -> void: load_button_pressed.emit() diff --git a/game/src/Game/GameSession/MapControlPanel/MapControlPanel.gd b/game/src/Game/GameSession/MapControlPanel/MapControlPanel.gd index 6cdbf28..eb4dd9f 100644 --- a/game/src/Game/GameSession/MapControlPanel/MapControlPanel.gd +++ b/game/src/Game/GameSession/MapControlPanel/MapControlPanel.gd @@ -24,10 +24,10 @@ func _add_mapmode_button(identifier : String) -> void: if _mapmode_button_group.get_pressed_button() == null: button.button_pressed = true -func _ready(): +func _ready() -> void: _mapmode_button_group = ButtonGroup.new() _mapmode_button_group.pressed.connect(_mapmode_pressed) - for index in GameSingleton.get_mapmode_count(): + for index : int in GameSingleton.get_mapmode_count(): _add_mapmode_button(GameSingleton.get_mapmode_identifier(index)) # REQUIREMENTS: diff --git a/game/src/Game/GameSession/MapControlPanel/Minimap.gd b/game/src/Game/GameSession/MapControlPanel/Minimap.gd index 5564821..ce27302 100644 --- a/game/src/Game/GameSession/MapControlPanel/Minimap.gd +++ b/game/src/Game/GameSession/MapControlPanel/Minimap.gd @@ -9,7 +9,7 @@ var _minimap_shader : ShaderMaterial var _viewport_points : PackedVector2Array -func _ready(): +func _ready() -> void: _minimap_texture.custom_minimum_size = Vector2(GameSingleton.get_map_aspect_ratio(), 1.0) * 150 var minimap_material := _minimap_texture.get_material() if GameLoader.ShaderManager.set_up_shader(minimap_material, false) != OK: @@ -32,7 +32,7 @@ func _draw() -> void: # REQUIREMENTS # * SS-81 # * UIFUN-127 -func _unhandled_input(event : InputEvent): +func _unhandled_input(event : InputEvent) -> void: if event is InputEventMouse and Input.is_action_pressed(_action_click): var pos_clicked := get_local_mouse_position() / size - Vector2(0.5, 0.5) if abs(pos_clicked.x) < 0.5 and abs(pos_clicked.y) < 0.5: @@ -100,6 +100,6 @@ func _on_map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_ri _add_line_looped_over_x(far_left, near_left) _add_line_looped_over_x(near_right, far_right) - for i in _viewport_points.size(): + for i : int in _viewport_points.size(): _viewport_points[i] *= size queue_redraw() diff --git a/game/src/Game/GameSession/MapView.gd b/game/src/Game/GameSession/MapView.gd index 01e5844..499f745 100644 --- a/game/src/Game/GameSession/MapView.gd +++ b/game/src/Game/GameSession/MapView.gd @@ -50,7 +50,7 @@ var _viewport_dims : Vector2 = Vector2(1, 1) # 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. # This was an absolute pain to track down. --- hop311 -func _ready(): +func _ready() -> void: if _camera == null: push_error("MapView's _camera variable hasn't been set!") return @@ -71,14 +71,16 @@ func _ready(): return _map_mesh = _map_mesh_instance.mesh - # Set map mesh size and get bounds - const pixels_per_terrain_tile : float = 32.0 + const pixels_per_terrain_tile : float = 20.0 _map_shader_material.set_shader_parameter(GameLoader.ShaderManager.param_terrain_tile_factor, float(GameSingleton.get_map_height()) / pixels_per_terrain_tile) + const pixels_per_stripe_tile : float = 16.0 _map_shader_material.set_shader_parameter(GameLoader.ShaderManager.param_stripe_tile_factor, float(GameSingleton.get_map_height()) / pixels_per_stripe_tile) - var map_mesh_aabb := _map_mesh.get_core_aabb() * _map_mesh_instance.transform + + # Get map mesh bounds + var map_mesh_aabb : AABB = _map_mesh.get_core_aabb() * _map_mesh_instance.transform _map_mesh_corner = Vector2( min(map_mesh_aabb.position.x, map_mesh_aabb.end.x), min(map_mesh_aabb.position.z, map_mesh_aabb.end.z) @@ -90,7 +92,7 @@ func _ready(): GameSingleton.province_selected.connect(_on_province_selected) -func _notification(what : int): +func _notification(what : int) -> void: match what: NOTIFICATION_WM_MOUSE_ENTER: # Mouse inside window _on_mouse_entered_viewport() @@ -108,7 +110,7 @@ func _viewport_to_map_coords(pos_viewport : Vector2) -> Vector2: var ray_origin := _camera.project_ray_origin(pos_viewport) var ray_normal := _camera.project_ray_normal(pos_viewport) # Plane with normal (0,1,0) facing upwards, at a distance 0 from the origin - var intersection = Plane(0, 1, 0, 0).intersects_ray(ray_origin, ray_normal) + var intersection : Variant = Plane(0, 1, 0, 0).intersects_ray(ray_origin, ray_normal) if typeof(intersection) == TYPE_VECTOR3: return _world_to_map_coords(intersection as Vector3) else: @@ -133,7 +135,7 @@ func _on_province_selected(index : int) -> void: # REQUIREMENTS # * SS-31 -func _unhandled_input(event : InputEvent): +func _unhandled_input(event : InputEvent) -> void: 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): @@ -154,7 +156,7 @@ func _unhandled_input(event : InputEvent): elif event.is_action_pressed(_action_zoom_out, true): zoom_out() -func _physics_process(delta : float): +func _physics_process(delta : float) -> void: _mouse_pos_viewport = get_viewport().get_mouse_position() _viewport_dims = Vector2(Resolution.get_current_resolution()) # Process movement @@ -212,7 +214,7 @@ func _clamp_over_map() -> void: func _zoom_process(delta : float) -> void: var height := _camera.position.y var zoom := _zoom_target - height - var zoom_delta = zoom * _zoom_speed * delta + var zoom_delta := zoom * _zoom_speed * delta # Set to target if height is within _zoom_epsilon of it or has overshot past it if abs(zoom - zoom_delta) < _zoom_epsilon or sign(zoom) != sign(zoom - zoom_delta): zoom_delta = zoom @@ -235,20 +237,20 @@ func _update_mouse_map_position() -> void: if _mouse_over_viewport: _map_shader_material.set_shader_parameter(GameLoader.ShaderManager.param_hover_index, hover_index) -func _on_mouse_entered_viewport(): +func _on_mouse_entered_viewport() -> void: _mouse_over_viewport = true -func _on_mouse_exited_viewport(): +func _on_mouse_exited_viewport() -> void: _mouse_over_viewport = false _map_shader_material.set_shader_parameter(GameLoader.ShaderManager.param_hover_index, 0) -func _on_window_entered_focus(): +func _on_window_entered_focus() -> void: _window_in_focus = true -func _on_window_exited_focus(): +func _on_window_exited_focus() -> void: _window_in_focus = false -func _on_minimap_clicked(pos_clicked : Vector2): +func _on_minimap_clicked(pos_clicked : Vector2) -> void: pos_clicked *= _map_mesh_dims _camera.position.x = pos_clicked.x _camera.position.z = pos_clicked.y diff --git a/game/src/Game/GameSession/MapView.tscn b/game/src/Game/GameSession/MapView.tscn index fb4ac07..43ff120 100644 --- a/game/src/Game/GameSession/MapView.tscn +++ b/game/src/Game/GameSession/MapView.tscn @@ -10,6 +10,7 @@ shader_parameter/province_shape_subdivisions = null shader_parameter/hover_index = null shader_parameter/selected_index = null shader_parameter/terrain_tile_factor = null +shader_parameter/stripe_tile_factor = null [sub_resource type="MapMesh" id="MapMesh_3gtsd"] diff --git a/game/src/Game/GameSession/ProvinceOverviewPanel.gd b/game/src/Game/GameSession/ProvinceOverviewPanel.gd index 6c183fb..6ffc906 100644 --- a/game/src/Game/GameSession/ProvinceOverviewPanel.gd +++ b/game/src/Game/GameSession/ProvinceOverviewPanel.gd @@ -8,58 +8,107 @@ var _colony_status_button : Button var _colony_status_button_texture : GFXIconTexture var _administrative_percentage_label : Label var _owner_percentage_label : Label +var _province_modifiers_overlapping_elements_box : GUIOverlappingElementsBox var _terrain_type_texture : GFXIconTexture var _life_rating_bar : TextureProgressBar var _controller_flag_texture : GFXMaskedFlagTexture -# state and province modifiers # Statistics var _rgo_icon_texture : GFXIconTexture var _rgo_produced_label : Label var _rgo_income_label : Label -# rgo employment progress bar (execpt it isn't a progress bar?) +var _rgo_employment_percentage_texture : GFXIconTexture var _rgo_employment_population_label : Label var _rgo_employment_percentage_label : Label var _crime_name_label : Label var _crime_icon_texture : GFXIconTexture -# crime fighting +var _crime_fighting_label : Label var _total_population_label : Label var _migration_label : Label var _population_growth_label : Label var _pop_types_piechart : GFXPieChartTexture var _pop_ideologies_piechart : GFXPieChartTexture var _pop_cultures_piechart : GFXPieChartTexture -# supply_limit_label -# cores - -const _missing_suffix : String = "_MISSING" - -const _province_info_province_key : StringName = &"province" -const _province_info_region_key : StringName = &"region" -const _province_info_controller_key : StringName = &"controller" -const _province_info_life_rating_key : StringName = &"life_rating" -const _province_info_terrain_type_key : StringName = &"terrain_type" -const _province_info_crime_name_key : StringName = &"crime_name" -const _province_info_crime_icon_key : StringName = &"crime_icon" -const _province_info_total_population_key : StringName = &"total_population" -const _province_info_pop_types_key : StringName = &"pop_types" -const _province_info_pop_ideologies_key : StringName = &"pop_ideologies" -const _province_info_pop_cultures_key : StringName = &"pop_cultures" -const _province_info_rgo_name_key : StringName = &"rgo_name" -const _province_info_rgo_icon_key : StringName = &"rgo_icon" -const _province_info_colony_status_key : StringName = &"colony_status" -const _province_info_slave_status_key : StringName = &"slave_status" -const _province_info_buildings_key : StringName = &"buildings" - -const _building_info_building_key : StringName = &"building" -const _building_info_level_key : StringName = &"level" -const _building_info_expansion_state_key : StringName = &"expansion_state" -const _building_info_start_date_key : StringName = &"start_date" -const _building_info_end_date_key : StringName = &"end_date" -const _building_info_expansion_progress_key : StringName = &"expansion_progress" - -const _piechart_info_size_key : StringName = &"size" -const _piechart_info_colour_key : StringName = &"colour" +var _supply_limit_label : Label +var _cores_overlapping_elements_box : GUIOverlappingElementsBox + +# Buildings +var _buildings_panel : Panel +var _building_slots : Array[BuildingSlot] + +# 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 +class BuildingSlot: + var _slot_index : int + var _slot_node : Control + + var _building_icon : GFXIconTexture + var _expand_button : Button + var _expanding_icon : TextureRect + var _expanding_progress_bar : TextureProgressBar + var _expanding_label : Label + + func _init(new_slot_index : int, new_slot_node : Control) -> void: + if new_slot_index < 0: + push_error("Invalid building slot index: ", new_slot_index) + return + _slot_index = new_slot_index + if not new_slot_node: + push_error("Invalid building slot node: null!") + return + _slot_node = new_slot_node + + for icon_index : int in GameSingleton.get_province_building_count(): + var icon := _slot_node.get_node("build_icon%d" % icon_index) + if icon: + if icon_index == _slot_index: + _building_icon = GUINode.get_gfx_icon_texture_from_node(icon) + else: + icon.hide() + + var building_name := GUINode.get_label_from_node(_slot_node.get_node(^"./description")) + if building_name: + building_name.text = GameSingleton.get_province_building_identifier(_slot_index) + _expand_button = GUINode.get_button_from_node(_slot_node.get_node(^"./expand")) + if _expand_button: + _expand_button.pressed.connect(func() -> void: GameSingleton.expand_selected_province_building(_slot_index)) + _expanding_icon = GUINode.get_texture_rect_from_node(_slot_node.get_node(^"./underconstruction_icon")) + _expanding_progress_bar = GUINode.get_progress_bar_from_node(_slot_node.get_node(^"./building_progress")) + if _expanding_progress_bar: + _expanding_progress_bar.max_value = 1.0 + _expanding_progress_bar.step = _expanding_progress_bar.max_value / 100 + _expanding_label = GUINode.get_label_from_node(_slot_node.get_node(^"./expand_text")) + + enum ExpansionState { CannotExpand, CanExpand, Preparing, Expanding } + + func update_info(info : Dictionary) -> void: + const building_info_level_key : StringName = &"level" + const building_info_expansion_state_key : StringName = &"expansion_state" + const building_info_start_date_key : StringName = &"start_date" + const building_info_end_date_key : StringName = &"end_date" + const building_info_expansion_progress_key : StringName = &"expansion_progress" + + if _building_icon: + _building_icon.set_icon_index(info.get(building_info_level_key, 0) + 1) + + var expansion_state : int = info.get(building_info_expansion_state_key, ExpansionState.CannotExpand) + var expansion_in_progress : bool = expansion_state == ExpansionState.Preparing or expansion_state == ExpansionState.Expanding + + if _expand_button: + _expand_button.visible = not expansion_in_progress + _expand_button.disabled = expansion_state != ExpansionState.CanExpand + + if _expanding_icon: + _expanding_icon.visible = expansion_in_progress + + if _expanding_progress_bar: + _expanding_progress_bar.visible = expansion_in_progress + _expanding_progress_bar.value = info.get(building_info_expansion_progress_key, 0) + + if _expanding_label: + _expanding_label.visible = expansion_in_progress var _selected_index : int: get: return _selected_index @@ -68,69 +117,87 @@ var _selected_index : int: _update_info() var _province_info : Dictionary -func _ready(): +func _ready() -> void: GameSingleton.province_selected.connect(_on_province_selected) GameSingleton.state_updated.connect(_update_info) - add_gui_element("province_interface.gui", "province_view") + if add_gui_element("province_interface.gui", "province_view") != OK: + push_error("Failed to generate province overview panel!") + return - var close_button : Button = get_button_node(^"./province_view/close_button") + var close_button : Button = get_button_from_nodepath(^"./province_view/close_button") if close_button: close_button.pressed.connect(_on_close_button_pressed) # Header - _province_name_label = get_label_node(^"./province_view/province_view_header/province_name") - _region_name_label = get_label_node(^"./province_view/province_view_header/state_name") - _slave_status_icon = get_texture_rect_node(^"./province_view/province_view_header/slave_state_icon") - var slave_status_icon_texture : GFXIconTexture = get_gfx_icon_texture_from_node(^"./province_view/province_view_header/slave_state_icon") + _province_name_label = get_label_from_nodepath(^"./province_view/province_view_header/province_name") + _region_name_label = get_label_from_nodepath(^"./province_view/province_view_header/state_name") + _slave_status_icon = get_texture_rect_from_nodepath(^"./province_view/province_view_header/slave_state_icon") + var slave_status_icon_texture : GFXIconTexture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_view_header/slave_state_icon") if slave_status_icon_texture: slave_status_icon_texture.set_icon_index(GameSingleton.get_slave_pop_icon_index()) - _colony_status_button = get_button_node(^"./province_view/province_view_header/colony_button") - _colony_status_button_texture = get_gfx_icon_texture_from_node(^"./province_view/province_view_header/colony_button") - var admin_icon_texture : GFXIconTexture = get_gfx_icon_texture_from_node(^"./province_view/province_view_header/admin_icon") + _colony_status_button = get_button_from_nodepath(^"./province_view/province_view_header/colony_button") + _colony_status_button_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_view_header/colony_button") + var admin_icon_texture : GFXIconTexture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_view_header/admin_icon") if admin_icon_texture: admin_icon_texture.set_icon_index(GameSingleton.get_administrative_pop_icon_index()) - _administrative_percentage_label = get_label_node(^"./province_view/province_view_header/admin_efficiency") - _owner_percentage_label = get_label_node(^"./province_view/province_view_header/owner_presence") - _terrain_type_texture = get_gfx_icon_texture_from_node(^"./province_view/province_view_header/prov_terrain") - _life_rating_bar = get_progress_bar_node(^"./province_view/province_view_header/liferating") - _controller_flag_texture = get_gfx_masked_flag_texture_from_node(^"./province_view/province_view_header/controller_flag") + _administrative_percentage_label = get_label_from_nodepath(^"./province_view/province_view_header/admin_efficiency") + _owner_percentage_label = get_label_from_nodepath(^"./province_view/province_view_header/owner_presence") + _province_modifiers_overlapping_elements_box = get_gui_overlapping_elements_box_from_nodepath(^"./province_view/province_view_header/province_modifiers") + if _province_modifiers_overlapping_elements_box and _province_modifiers_overlapping_elements_box.set_gui_child_element_name("province_interface.gui", "prov_state_modifier") != OK: + _province_modifiers_overlapping_elements_box = null # hide province modifiers box since we can't do anything with it + _terrain_type_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_view_header/prov_terrain") + _life_rating_bar = get_progress_bar_from_nodepath(^"./province_view/province_view_header/liferating") + _controller_flag_texture = get_gfx_masked_flag_texture_from_nodepath(^"./province_view/province_view_header/controller_flag") # Statistics - _rgo_icon_texture = get_gfx_icon_texture_from_node(^"./province_view/province_statistics/goods_type") - _rgo_produced_label = get_label_node(^"./province_view/province_statistics/produced") - _rgo_income_label = get_label_node(^"./province_view/province_statistics/income") - _rgo_employment_population_label = get_label_node(^"./province_view/province_statistics/rgo_population") - _rgo_employment_percentage_label = get_label_node(^"./province_view/province_statistics/rgo_percent") - _crime_name_label = get_label_node(^"./province_view/province_statistics/crime_name") - _crime_icon_texture = get_gfx_icon_texture_from_node(^"./province_view/province_statistics/crime_icon") - _total_population_label = get_label_node(^"./province_view/province_statistics/total_population") - _migration_label = get_label_node(^"./province_view/province_statistics/migration") - _population_growth_label = get_label_node(^"./province_view/province_statistics/growth") - _pop_types_piechart = get_gfx_pie_chart_texture_from_node(^"./province_view/province_statistics/workforce_chart") - _pop_ideologies_piechart = get_gfx_pie_chart_texture_from_node(^"./province_view/province_statistics/ideology_chart") - _pop_cultures_piechart = get_gfx_pie_chart_texture_from_node(^"./province_view/province_statistics/culture_chart") - - #^"./province_view/building" - #^"./province_view/province_core" - #^"./province_view/prov_state_modifier" - - #add_gui_element("province_interface.gui", "building", "building0") - #var building0 : Panel = get_panel_node(^"./building0") - #building0.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_LEFT) - #building0.set_position(pop_cultures_piechart_icon.get_position()) + _rgo_icon_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_statistics/goods_type") + _rgo_produced_label = get_label_from_nodepath(^"./province_view/province_statistics/produced") + _rgo_income_label = get_label_from_nodepath(^"./province_view/province_statistics/income") + _rgo_employment_percentage_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_statistics/employment_ratio") + _rgo_employment_population_label = get_label_from_nodepath(^"./province_view/province_statistics/rgo_population") + _rgo_employment_percentage_label = get_label_from_nodepath(^"./province_view/province_statistics/rgo_percent") + _crime_name_label = get_label_from_nodepath(^"./province_view/province_statistics/crime_name") + _crime_icon_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_statistics/crime_icon") + _crime_fighting_label = get_label_from_nodepath(^"./province_view/province_statistics/crimefight_percent") + _total_population_label = get_label_from_nodepath(^"./province_view/province_statistics/total_population") + _migration_label = get_label_from_nodepath(^"./province_view/province_statistics/migration") + _population_growth_label = get_label_from_nodepath(^"./province_view/province_statistics/growth") + _pop_types_piechart = get_gfx_pie_chart_texture_from_nodepath(^"./province_view/province_statistics/workforce_chart") + _pop_ideologies_piechart = get_gfx_pie_chart_texture_from_nodepath(^"./province_view/province_statistics/ideology_chart") + _pop_cultures_piechart = get_gfx_pie_chart_texture_from_nodepath(^"./province_view/province_statistics/culture_chart") + _supply_limit_label = get_label_from_nodepath(^"./province_view/province_statistics/supply_limit_label") + _cores_overlapping_elements_box = get_gui_overlapping_elements_box_from_nodepath(^"./province_view/province_statistics/core_icons") + if _cores_overlapping_elements_box and _cores_overlapping_elements_box.set_gui_child_element_name("province_interface.gui", "province_core") != OK: + _cores_overlapping_elements_box = null # hide cores box since we can't do anything with it + + _buildings_panel = get_panel_from_nodepath(^"./province_view/province_buildings") + if _buildings_panel: + var target_slot_count : int = GameSingleton.get_province_building_count() + var slot_y : float = 0.0 + for current_slot_count : int in target_slot_count: + var slot := generate_gui_element("province_interface.gui", "building", "building_slot_%d" % current_slot_count) + if slot: + _buildings_panel.add_child(slot) + slot.set_position(Vector2(0.0, slot_y)) + slot_y += slot.get_size().y + _building_slots.push_back(BuildingSlot.new(current_slot_count, slot)) + else: + push_error("Failed to generate building slot ", current_slot_count, " / ", target_slot_count) + break # TODO - fix checkbox positions - for path in [ + for path : NodePath in [ ^"./province_view/province_buildings/rallypoint_checkbox", ^"./province_view/province_buildings/rallypoint_merge_checkbox", ^"./province_view/province_buildings/rallypoint_checkbox_naval", ^"./province_view/province_buildings/rallypoint_merge_checkbox_naval" ]: - var rally_checkbox : CheckBox = get_check_box_node(path) + var rally_checkbox : CheckBox = get_check_box_from_nodepath(path) rally_checkbox.set_position(rally_checkbox.get_position() - Vector2(3, 3)) hide_nodes([ + ^"./province_view/province_view_header/state_modifiers", ^"./province_view/province_view_header/occupation_progress", ^"./province_view/province_view_header/occupation_icon", ^"./province_view/province_view_header/occupation_flag", @@ -144,86 +211,40 @@ func _ready(): _update_info() -func _notification(what : int): +func _notification(what : int) -> void: match what: NOTIFICATION_TRANSLATION_CHANGED: _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] +enum ColonyStatus { STATE, PROTECTORATE, COLONY } +# This assumes _cores_overlapping_elements_box is non-null +func _set_core_flag(core_index : int, country : String) -> void: + var core_flag_texture : GFXMaskedFlagTexture = get_gfx_masked_flag_texture_from_node(_cores_overlapping_elements_box.get_child(core_index).get_node(^"./country_flag")) + if core_flag_texture: + core_flag_texture.set_flag_country_name(country) -# 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 = _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.focus_mode = FOCUS_NONE - 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(_building_info_level_key, 0)) - row.level.visible = true - row.name.text = building.get(_building_info_building_key, - _building_info_building_key + _missing_suffix) - row.name.visible = true - - var expansion_state : int = building.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(_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 -""" - -enum { STATE, PROTECTORATE, COLONY } func _update_info() -> void: + const _province_info_province_key : StringName = &"province" + const _province_info_region_key : StringName = &"region" + const _province_info_slave_status_key : StringName = &"slave_status" + const _province_info_colony_status_key : StringName = &"colony_status" + const _province_info_terrain_type_key : StringName = &"terrain_type" + const _province_info_life_rating_key : StringName = &"life_rating" + const _province_info_controller_key : StringName = &"controller" + const _province_info_rgo_name_key : StringName = &"rgo_name" + const _province_info_rgo_icon_key : StringName = &"rgo_icon" + const _province_info_crime_name_key : StringName = &"crime_name" + const _province_info_crime_icon_key : StringName = &"crime_icon" + const _province_info_total_population_key : StringName = &"total_population" + const _province_info_pop_types_key : StringName = &"pop_types" + const _province_info_pop_ideologies_key : StringName = &"pop_ideologies" + const _province_info_pop_cultures_key : StringName = &"pop_cultures" + const _province_info_cores_key : StringName = &"cores" + const _province_info_buildings_key : StringName = &"buildings" + + const _missing_suffix : String = "_MISSING" + _province_info = GameSingleton.get_province_info_from_index(_selected_index) if _province_info: # Header @@ -238,9 +259,9 @@ func _update_info() -> void: if _slave_status_icon: _slave_status_icon.visible = _province_info.get(_province_info_slave_status_key, false) - var colony_status : int = _province_info.get(_province_info_colony_status_key, 0) + var colony_status : ColonyStatus = _province_info.get(_province_info_colony_status_key, 0) if _colony_status_button: - if colony_status == STATE: + if colony_status == ColonyStatus.STATE: _colony_status_button.hide() else: if _colony_status_button_texture: @@ -253,6 +274,14 @@ func _update_info() -> void: if _owner_percentage_label: pass + if _province_modifiers_overlapping_elements_box: + # TODO - replace example icons with those from the province's list of modifier instances + _province_modifiers_overlapping_elements_box.set_child_count(8) + for i : int in _province_modifiers_overlapping_elements_box.get_child_count(): + var icon : GFXIconTexture = get_gfx_icon_texture_from_node(_province_modifiers_overlapping_elements_box.get_child(i).get_node(^"./modifier")) + if icon: + icon.set_icon_index(2 * i + (i & 1) + 1) + if _terrain_type_texture: var terrain_type : String = _province_info.get(_province_info_terrain_type_key, "") if terrain_type: @@ -264,21 +293,25 @@ func _update_info() -> void: _life_rating_bar.value = _province_info.get(_province_info_life_rating_key, 0) if _controller_flag_texture: - var controller : String = _province_info.get(_province_info_controller_key, "REB") - _controller_flag_texture.set_flag_country_name_and_type(controller, &"") + _controller_flag_texture.set_flag_country_name(_province_info.get(_province_info_controller_key, "")) # Statistics if _rgo_icon_texture: _rgo_icon_texture.set_icon_index(_province_info.get(_province_info_rgo_icon_key, -1) + 2) if _rgo_produced_label: + # TODO - replace name with amount produced _rgo_produced_label.text = _province_info.get(_province_info_rgo_name_key, _province_info_rgo_name_key + _missing_suffix) if _rgo_income_label: + # TODO - add £ sign and replace placeholder with actual value _rgo_income_label.text = GameSingleton.float_to_formatted_string(12.34567) - # TODO - add £ sign + + if _rgo_employment_percentage_texture: + pass if _rgo_employment_population_label: + # TODO - replace placeholder with actual value _rgo_employment_population_label.text = GameSingleton.int_to_formatted_string(_province_info.get(_province_info_total_population_key, 0) / 10) if _rgo_employment_percentage_label: @@ -290,6 +323,9 @@ func _update_info() -> void: if _crime_icon_texture: _crime_icon_texture.set_icon_index(_province_info.get(_province_info_crime_icon_key, 0) + 1) + if _crime_fighting_label: + pass + if _total_population_label: _total_population_label.text = GameSingleton.int_to_formatted_string(_province_info.get(_province_info_total_population_key, 0)) @@ -300,17 +336,32 @@ func _update_info() -> void: pass if _pop_types_piechart: - _pop_types_piechart.set_slices(_province_info.get(_province_info_pop_types_key, [])) + _pop_types_piechart.set_slices_array(_province_info.get(_province_info_pop_types_key, [])) if _pop_ideologies_piechart: - _pop_ideologies_piechart.set_slices(_province_info.get(_province_info_pop_ideologies_key, [])) + _pop_ideologies_piechart.set_slices_array(_province_info.get(_province_info_pop_ideologies_key, [])) if _pop_cultures_piechart: - _pop_cultures_piechart.set_slices(_province_info.get(_province_info_pop_cultures_key, [])) + _pop_cultures_piechart.set_slices_array(_province_info.get(_province_info_pop_cultures_key, [])) + + if _supply_limit_label: + pass - #var buildings : Array = _province_info.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 {}) + if _cores_overlapping_elements_box: + var cores : PackedStringArray = _province_info.get(_province_info_cores_key, []) + _cores_overlapping_elements_box.set_child_count(cores.size()) + for core_index : int in min(cores.size(), _cores_overlapping_elements_box.get_child_count()): + _set_core_flag(core_index, cores[core_index]) + for core_index : int in range(cores.size(), _cores_overlapping_elements_box.get_child_count()): + _set_core_flag(core_index, "") + + # Buildings + if _buildings_panel: + var buildings : Array[Dictionary] = _province_info.get(_province_info_buildings_key, [] as Array[Dictionary]) + for slot_index : int in min(buildings.size(), _building_slots.size()): + _building_slots[slot_index].update_info(buildings[slot_index]) + for slot_index : int in range(buildings.size(), _building_slots.size()): + _building_slots[slot_index].update_info({}) show() else: diff --git a/game/src/Game/GameSession/Topbar.gd b/game/src/Game/GameSession/Topbar.gd index 6cc710f..4de9474 100644 --- a/game/src/Game/GameSession/Topbar.gd +++ b/game/src/Game/GameSession/Topbar.gd @@ -7,7 +7,7 @@ var _speed_indicator_texture : GFXIconTexture var _date_label : Label var _country_name_label : Label -func _ready(): +func _ready() -> void: GameSingleton.state_updated.connect(_update_info) add_gui_element("topbar.gui", "topbar") @@ -19,30 +19,30 @@ func _ready(): const player_country : String = "SLV" - var player_flag_texture : GFXMaskedFlagTexture = get_gfx_masked_flag_texture_from_node(^"./topbar/player_flag") + var player_flag_texture : GFXMaskedFlagTexture = get_gfx_masked_flag_texture_from_nodepath(^"./topbar/player_flag") if player_flag_texture: - player_flag_texture.set_flag_country_name_and_type(player_country, &"") + player_flag_texture.set_flag_country_name(player_country) - _speed_up_button = get_button_node(^"./topbar/button_speedup") + _speed_up_button = get_button_from_nodepath(^"./topbar/button_speedup") if _speed_up_button: _speed_up_button.pressed.connect(_on_increase_speed_button_pressed) - _speed_down_button = get_button_node(^"./topbar/button_speeddown") + _speed_down_button = get_button_from_nodepath(^"./topbar/button_speeddown") if _speed_down_button: _speed_down_button.pressed.connect(_on_decrease_speed_button_pressed) - var pause_bg_button : Button = get_button_node(^"./topbar/pause_bg") + var pause_bg_button : Button = get_button_from_nodepath(^"./topbar/pause_bg") if pause_bg_button: pause_bg_button.pressed.connect(_on_play_pause_button_pressed) - _date_label = get_label_node(^"./topbar/DateText") + _date_label = get_label_from_nodepath(^"./topbar/DateText") - _country_name_label = get_label_node(^"./topbar/CountryName") + _country_name_label = get_label_from_nodepath(^"./topbar/CountryName") if _country_name_label: _country_name_label.text = player_country - _speed_indicator_button = get_button_node(^"./topbar/speed_indicator") - _speed_indicator_texture = get_gfx_icon_texture_from_node(^"./topbar/speed_indicator") + _speed_indicator_button = get_button_from_nodepath(^"./topbar/speed_indicator") + _speed_indicator_texture = get_gfx_icon_texture_from_nodepath(^"./topbar/speed_indicator") func _update_info() -> void: if _date_label: @@ -64,21 +64,21 @@ func _update_info() -> void: # REQUIREMENTS: # * UIFUN-71 -func _on_play_pause_button_pressed(): +func _on_play_pause_button_pressed() -> void: print("Toggling pause!") GameSingleton.toggle_paused() _update_info() # REQUIREMENTS: # * UIFUN-72 -func _on_increase_speed_button_pressed(): +func _on_increase_speed_button_pressed() -> void: print("Speed up!") GameSingleton.increase_speed() _update_info() # REQUIREMENTS: # * UIFUN-73 -func _on_decrease_speed_button_pressed(): +func _on_decrease_speed_button_pressed() -> void: print("Speed down!") GameSingleton.decrease_speed() _update_info() |