From 88acb31bd43f0e163522837bb1d0dd7da2977c4a Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 28 Aug 2024 18:46:30 +0100 Subject: Switch to using custom UI nodes --- game/src/Game/GameSession/Topbar.gd | 209 +++++++++++++++++------------------- 1 file changed, 99 insertions(+), 110 deletions(-) (limited to 'game/src/Game/GameSession/Topbar.gd') diff --git a/game/src/Game/GameSession/Topbar.gd b/game/src/Game/GameSession/Topbar.gd index d6cc358..62fa322 100644 --- a/game/src/Game/GameSession/Topbar.gd +++ b/game/src/Game/GameSession/Topbar.gd @@ -1,8 +1,8 @@ extends GUINode # Country info -var _country_flag_texture : GFXMaskedFlagTexture -var _country_flag_overlay_texture : GFXSpriteTexture +var _country_flag_button : GUIMaskedFlagButton +var _country_flag_overlay_icon : GUIIcon var _country_name_label : GUILabel var _country_rank_label : GUILabel var _country_prestige_label : GUILabel @@ -14,41 +14,39 @@ var _country_military_power_rank_label : GUILabel var _country_colonial_power_label : GUILabel # Time controls -var _speed_up_button : Button -var _speed_down_button : Button -var _speed_indicator_texture : GFXSpriteTexture +var _speed_up_button : GUIIconButton +var _speed_down_button : GUIIconButton +var _speed_indicator_button : GUIIconButton var _date_label : GUILabel -# NationManagement.Screen-Button +# NationManagement.Screen-GUIIconButton var _nation_management_buttons : Dictionary -# NationManagement.Screen-GFXSpriteTexture -var _nation_management_button_textures : Dictionary # Production -var _production_top_goods_textures : Array[GFXSpriteTexture] -var _production_alert_building_texture : GFXSpriteTexture -var _production_alert_closed_texture : GFXSpriteTexture -var _production_alert_unemployment_texture : GFXSpriteTexture +var _production_top_goods_icons : Array[GUIIcon] +var _production_alert_building_icon : GUIIcon +var _production_alert_closed_icon : GUIIcon +var _production_alert_unemployment_icon : GUIIcon # Budget # TODO - line chart var _budget_funds_label : GUILabel # Technology -var _technology_progress_bar : TextureProgressBar +var _technology_progress_bar : GUIProgressBar var _technology_current_research_label : GUILabel var _technology_literacy_label : GUILabel var _technology_research_points_label : GUILabel # Politics -var _politics_party_icon : TextureRect +var _politics_party_icon : GUIIcon var _politics_party_label : GUILabel var _politics_suppression_points_label : GUILabel var _politics_infamy_label : GUILabel -var _politics_reforms_texture : GFXSpriteTexture -var _politics_decisions_texture : GFXSpriteTexture -var _politics_election_texture : GFXSpriteTexture -var _politics_rebels_texture : GFXSpriteTexture +var _politics_reforms_button : GUIButton +var _politics_decisions_button : GUIIconButton +var _politics_election_icon : GUIIcon +var _politics_rebels_button : GUIIconButton # Population var _population_total_size_label : GUILabel @@ -57,17 +55,17 @@ var _population_militancy_label : GUILabel var _population_consciousness_label : GUILabel # Trade -var _trade_imported_textures : Array[GFXSpriteTexture] -var _trade_exported_textures : Array[GFXSpriteTexture] +var _trade_imported_icons : Array[GUIIcon] +var _trade_exported_icons : Array[GUIIcon] # Diplomacy var _diplomacy_peace_label : GUILabel var _diplomacy_war_enemies_overlapping_elements_box : GUIOverlappingElementsBox var _diplomacy_diplomatic_points_label : GUILabel -var _diplomacy_alert_colony_texture : GFXSpriteTexture -var _diplomacy_alert_crisis_texture : GFXSpriteTexture -var _diplomacy_alert_sphere_texture : GFXSpriteTexture -var _diplomacy_alert_great_power_texture : GFXSpriteTexture +var _diplomacy_alert_colony_button : GUIIconButton +var _diplomacy_alert_crisis_icon : GUIIcon +var _diplomacy_alert_sphere_icon : GUIIcon +var _diplomacy_alert_great_power_icon : GUIIcon # Military var _military_army_size_label : GUILabel @@ -87,21 +85,20 @@ func _ready() -> void: ]) # Disables all consuming invisible panel - var topbar := get_panel_from_nodepath(^"./topbar") + var topbar : Panel = get_panel_from_nodepath(^"./topbar") if topbar: topbar.mouse_filter = Control.MOUSE_FILTER_IGNORE set_click_mask_from_nodepaths([^"./topbar/topbar_bg", ^"./topbar/topbar_paper"]) # Country info - var country_flag_button = get_button_from_nodepath(^"./topbar/player_flag") - if country_flag_button: - country_flag_button.pressed.connect( + _country_flag_button = get_gui_masked_flag_button_from_nodepath(^"./topbar/player_flag") + if _country_flag_button: + _country_flag_button.pressed.connect( func() -> void: # TODO - open the diplomacy menu on the Wars tab Events.NationManagementScreens.open_nation_management_screen(NationManagement.Screen.DIPLOMACY) ) - _country_flag_texture = GUINode.get_gfx_masked_flag_texture_from_node(country_flag_button) - _country_flag_overlay_texture = get_gfx_sprite_texture_from_nodepath(^"./topbar/topbar_flag_overlay") + _country_flag_overlay_icon = get_gui_icon_from_nodepath(^"./topbar/topbar_flag_overlay") _country_name_label = get_gui_label_from_nodepath(^"./topbar/CountryName") _country_rank_label = get_gui_label_from_nodepath(^"./topbar/nation_totalrank") _country_prestige_label = get_gui_label_from_nodepath(^"./topbar/country_prestige") @@ -113,19 +110,18 @@ func _ready() -> void: _country_colonial_power_label = get_gui_label_from_nodepath(^"./topbar/country_colonial_power") # Time controls - _speed_up_button = get_button_from_nodepath(^"./topbar/button_speedup") + _speed_up_button = get_gui_icon_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_from_nodepath(^"./topbar/button_speeddown") + _speed_down_button = get_gui_icon_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_from_nodepath(^"./topbar/pause_bg") + var pause_bg_button : GUIIconButton = get_gui_icon_button_from_nodepath(^"./topbar/pause_bg") if pause_bg_button: pause_bg_button.pressed.connect(_on_play_pause_button_pressed) - var speed_indicator_button = get_button_from_nodepath(^"./topbar/speed_indicator") - if speed_indicator_button: - speed_indicator_button.pressed.connect(_on_play_pause_button_pressed) - _speed_indicator_texture = GUINode.get_gfx_sprite_texture_from_node(speed_indicator_button) + _speed_indicator_button = get_gui_icon_button_from_nodepath(^"./topbar/speed_indicator") + if _speed_indicator_button: + _speed_indicator_button.pressed.connect(_on_play_pause_button_pressed) _date_label = get_gui_label_from_nodepath(^"./topbar/DateText") # Nation management screens @@ -140,40 +136,37 @@ func _ready() -> void: NationManagement.Screen.MILITARY : ^"./topbar/topbarbutton_military" } for screen : NationManagement.Screen in screen_nodepaths: - var button : Button = get_button_from_nodepath(screen_nodepaths[screen]) + var button : GUIIconButton = get_gui_icon_button_from_nodepath(screen_nodepaths[screen]) if button: button.pressed.connect( Events.NationManagementScreens.toggle_nation_management_screen.bind(screen) ) - var icon : GFXSpriteTexture = GUINode.get_gfx_sprite_texture_from_node(button) - if icon: - _nation_management_buttons[screen] = button - _nation_management_button_textures[screen] = icon + _nation_management_buttons[screen] = button Events.NationManagementScreens.update_active_nation_management_screen.connect( _on_update_active_nation_management_screen ) # Production const PRODUCED_GOOD_COUNT : int = 5 - for idx in PRODUCED_GOOD_COUNT: - _production_top_goods_textures.push_back(get_gfx_sprite_texture_from_nodepath("./topbar/topbar_produced%d" % idx)) - _production_alert_building_texture = get_gfx_sprite_texture_from_nodepath(^"./topbar/alert_building_factories") - _production_alert_closed_texture = get_gfx_sprite_texture_from_nodepath(^"./topbar/alert_closed_factories") - _production_alert_unemployment_texture = get_gfx_sprite_texture_from_nodepath(^"./topbar/alert_unemployed_workers") + for idx : int in PRODUCED_GOOD_COUNT: + _production_top_goods_icons.push_back(get_gui_icon_from_nodepath("./topbar/topbar_produced%d" % idx)) + _production_alert_building_icon = get_gui_icon_from_nodepath(^"./topbar/alert_building_factories") + _production_alert_closed_icon = get_gui_icon_from_nodepath(^"./topbar/alert_closed_factories") + _production_alert_unemployment_icon = get_gui_icon_from_nodepath(^"./topbar/alert_unemployed_workers") # Budget _budget_funds_label = get_gui_label_from_nodepath(^"./topbar/budget_funds") # Technology - _technology_progress_bar = get_progress_bar_from_nodepath(^"./topbar/topbar_tech_progress") + _technology_progress_bar = get_gui_progress_bar_from_nodepath(^"./topbar/topbar_tech_progress") _technology_current_research_label = get_gui_label_from_nodepath(^"./topbar/tech_current_research") _technology_literacy_label = get_gui_label_from_nodepath(^"./topbar/tech_literacy_value") _technology_research_points_label = get_gui_label_from_nodepath(^"./topbar/topbar_researchpoints_value") # Politics - _politics_party_icon = get_texture_rect_from_nodepath(^"./topbar/politics_party_icon") + _politics_party_icon = get_gui_icon_from_nodepath(^"./topbar/politics_party_icon") _politics_party_label = get_gui_label_from_nodepath(^"./topbar/politics_ruling_party") - var politics_suppression_button : Button = get_button_from_nodepath(^"./topbar/topbar_supression_icon") + var politics_suppression_button : GUIIconButton = get_gui_icon_button_from_nodepath(^"./topbar/topbar_supression_icon") if politics_suppression_button: politics_suppression_button.pressed.connect( func() -> void: @@ -182,31 +175,28 @@ func _ready() -> void: ) _politics_suppression_points_label = get_gui_label_from_nodepath(^"./topbar/politics_supressionpoints_value") _politics_infamy_label = get_gui_label_from_nodepath(^"./topbar/politics_infamy_value") - var politics_reforms_button : Button = get_button_from_nodepath(^"./topbar/alert_can_do_reforms") - if politics_reforms_button: - politics_reforms_button.pressed.connect( + _politics_reforms_button = get_gui_icon_button_from_nodepath(^"./topbar/alert_can_do_reforms") + if _politics_reforms_button: + _politics_reforms_button.pressed.connect( func() -> void: # TODO - open the politics menu on the Reforms tab Events.NationManagementScreens.toggle_nation_management_screen(NationManagement.Screen.POLITICS) ) - _politics_reforms_texture = GUINode.get_gfx_sprite_texture_from_node(politics_reforms_button) - var politics_decisions_button : Button = get_button_from_nodepath(^"./topbar/alert_can_do_decisions") - if politics_decisions_button: - politics_decisions_button.pressed.connect( + _politics_decisions_button = get_gui_icon_button_from_nodepath(^"./topbar/alert_can_do_decisions") + if _politics_decisions_button: + _politics_decisions_button.pressed.connect( func() -> void: # TODO - open the politics menu on the Decisions tab Events.NationManagementScreens.toggle_nation_management_screen(NationManagement.Screen.POLITICS) ) - _politics_decisions_texture = GUINode.get_gfx_sprite_texture_from_node(politics_decisions_button) - _politics_election_texture = get_gfx_sprite_texture_from_nodepath(^"./topbar/alert_is_in_election") - var politics_rebels_button : Button = get_button_from_nodepath(^"./topbar/alert_have_rebels") - if politics_rebels_button: - politics_rebels_button.pressed.connect( + _politics_election_icon = get_gui_icon_from_nodepath(^"./topbar/alert_is_in_election") + _politics_rebels_button = get_gui_icon_button_from_nodepath(^"./topbar/alert_have_rebels") + if _politics_rebels_button: + _politics_rebels_button.pressed.connect( func() -> void: # TODO - open the politics menu on the Movements tab Events.NationManagementScreens.toggle_nation_management_screen(NationManagement.Screen.POLITICS) ) - _politics_rebels_texture = GUINode.get_gfx_sprite_texture_from_node(politics_rebels_button) # Population _population_total_size_label = get_gui_label_from_nodepath(^"./topbar/population_total_value") @@ -217,24 +207,23 @@ func _ready() -> void: # Trade const TRADE_GOOD_COUNT : int = 3 for idx in TRADE_GOOD_COUNT: - _trade_imported_textures.push_back(get_gfx_sprite_texture_from_nodepath("./topbar/topbar_import%d" % idx)) - _trade_exported_textures.push_back(get_gfx_sprite_texture_from_nodepath("./topbar/topbar_export%d" % idx)) + _trade_imported_icons.push_back(get_gui_icon_from_nodepath("./topbar/topbar_import%d" % idx)) + _trade_exported_icons.push_back(get_gui_icon_from_nodepath("./topbar/topbar_export%d" % idx)) # Diplomacy _diplomacy_peace_label = get_gui_label_from_nodepath(^"./topbar/diplomacy_status") _diplomacy_war_enemies_overlapping_elements_box = get_gui_overlapping_elements_box_from_nodepath(^"./topbar/diplomacy_at_war") _diplomacy_diplomatic_points_label = get_gui_label_from_nodepath(^"./topbar/diplomacy_diplopoints_value") - var diplomacy_alert_colony_button : Button = get_button_from_nodepath(^"./topbar/alert_colony") - if diplomacy_alert_colony_button: - diplomacy_alert_colony_button.pressed.connect( + _diplomacy_alert_colony_button = get_gui_icon_button_from_nodepath(^"./topbar/alert_colony") + if _diplomacy_alert_colony_button: + _diplomacy_alert_colony_button.pressed.connect( func() -> void: # TODO - move to and select province in upgradable colony if any exist Events.NationManagementScreens.open_nation_management_screen(NationManagement.Screen.DIPLOMACY) ) - _diplomacy_alert_colony_texture = GUINode.get_gfx_sprite_texture_from_node(diplomacy_alert_colony_button) - _diplomacy_alert_crisis_texture = get_gfx_sprite_texture_from_nodepath(^"./topbar/alert_crisis") - _diplomacy_alert_sphere_texture = get_gfx_sprite_texture_from_nodepath(^"./topbar/alert_can_increase_opinion") - _diplomacy_alert_great_power_texture = get_gfx_sprite_texture_from_nodepath(^"./topbar/alert_loosing_gp") + _diplomacy_alert_crisis_icon = get_gui_icon_from_nodepath(^"./topbar/alert_crisis") + _diplomacy_alert_sphere_icon = get_gui_icon_from_nodepath(^"./topbar/alert_can_increase_opinion") + _diplomacy_alert_great_power_icon = get_gui_icon_from_nodepath(^"./topbar/alert_loosing_gp") # Military _military_army_size_label = get_gui_label_from_nodepath(^"./topbar/military_army_value") @@ -255,15 +244,15 @@ func _update_info() -> void: const player_country : String = "ENG" ## Country info - if _country_flag_texture: - _country_flag_texture.set_flag_country_name(player_country) + if _country_flag_button: + _country_flag_button.set_flag_country_name(player_country) - if _country_flag_overlay_texture: + if _country_flag_overlay_icon: # 1 - Great Power # 2 - Secondary Power # 3 - Civilised # 4 - Uncivilised - _country_flag_overlay_texture.set_icon_index(1) + _country_flag_overlay_icon.set_icon_index(1) if _country_name_label: _country_name_label.set_text(player_country) @@ -301,18 +290,18 @@ func _update_info() -> void: _date_label.text = MenuSingleton.get_longform_date() ## Production - for idx : int in _production_top_goods_textures.size(): - if _production_top_goods_textures[idx]: - _production_top_goods_textures[idx].set_icon_index(idx + 2) + for idx : int in _production_top_goods_icons.size(): + if _production_top_goods_icons[idx]: + _production_top_goods_icons[idx].set_icon_index(idx + 2) - if _production_alert_building_texture: - _production_alert_building_texture.set_icon_index(2) + if _production_alert_building_icon: + _production_alert_building_icon.set_icon_index(2) - if _production_alert_closed_texture: - _production_alert_closed_texture.set_icon_index(2) + if _production_alert_closed_icon: + _production_alert_closed_icon.set_icon_index(2) - if _production_alert_unemployment_texture: - _production_alert_unemployment_texture.set_icon_index(2) + if _production_alert_unemployment_icon: + _production_alert_unemployment_icon.set_icon_index(2) ## Budget if _budget_funds_label: @@ -351,17 +340,17 @@ func _update_info() -> void: if _politics_infamy_label: _politics_infamy_label.set_text("§Y%s" % GUINode.float_to_string_dp(0.0, 2)) - if _politics_reforms_texture: - _politics_reforms_texture.set_icon_index(2) + if _politics_reforms_button: + _politics_reforms_button.set_icon_index(2) - if _politics_decisions_texture: - _politics_decisions_texture.set_icon_index(2) + if _politics_decisions_button: + _politics_decisions_button.set_icon_index(2) - if _politics_election_texture: - _politics_election_texture.set_icon_index(2) + if _politics_election_icon: + _politics_election_icon.set_icon_index(2) - if _politics_rebels_texture: - _politics_rebels_texture.set_icon_index(2) + if _politics_rebels_button: + _politics_rebels_button.set_icon_index(2) ## Population if _population_total_size_label: @@ -386,13 +375,13 @@ func _update_info() -> void: _population_consciousness_label.set_text("§Y%s" % GUINode.float_to_string_dp(0.05, 2)) ## Trade - for idx : int in _trade_imported_textures.size(): - if _trade_imported_textures[idx]: - _trade_imported_textures[idx].set_icon_index(idx + 2 + _production_top_goods_textures.size()) + for idx : int in _trade_imported_icons.size(): + if _trade_imported_icons[idx]: + _trade_imported_icons[idx].set_icon_index(idx + 2 + _production_top_goods_icons.size()) - for idx : int in _trade_exported_textures.size(): - if _trade_exported_textures[idx]: - _trade_exported_textures[idx].set_icon_index(idx + 2 + _production_top_goods_textures.size() + _trade_imported_textures.size()) + for idx : int in _trade_exported_icons.size(): + if _trade_exported_icons[idx]: + _trade_exported_icons[idx].set_icon_index(idx + 2 + _production_top_goods_icons.size() + _trade_imported_icons.size()) ## Diplomacy if _diplomacy_peace_label: @@ -403,17 +392,17 @@ func _update_info() -> void: if _diplomacy_diplomatic_points_label: _diplomacy_diplomatic_points_label.set_text("§Y%s" % GUINode.float_to_string_dp(7.4, 0)) - if _diplomacy_alert_colony_texture: - _diplomacy_alert_colony_texture.set_icon_index(3) + if _diplomacy_alert_colony_button: + _diplomacy_alert_colony_button.set_icon_index(3) - if _diplomacy_alert_crisis_texture: - _diplomacy_alert_crisis_texture.set_icon_index(3) + if _diplomacy_alert_crisis_icon: + _diplomacy_alert_crisis_icon.set_icon_index(3) - if _diplomacy_alert_sphere_texture: - _diplomacy_alert_sphere_texture.set_icon_index(2) + if _diplomacy_alert_sphere_icon: + _diplomacy_alert_sphere_icon.set_icon_index(2) - if _diplomacy_alert_great_power_texture: - _diplomacy_alert_great_power_texture.set_icon_index(2) + if _diplomacy_alert_great_power_icon: + _diplomacy_alert_great_power_icon.set_icon_index(2) ## Military if _military_army_size_label: @@ -437,11 +426,11 @@ func _update_speed_controls() -> void: #if _speed_down_button: # _speed_down_button.disabled = not MenuSingleton.can_decrease_speed() - if _speed_indicator_texture: + if _speed_indicator_button: var index : int = 1 if not MenuSingleton.is_paused(): index += MenuSingleton.get_speed() + 1 - _speed_indicator_texture.set_icon_index(index) + _speed_indicator_button.set_icon_index(index) # REQUIREMENTS: # * UIFUN-71 @@ -463,4 +452,4 @@ func _on_decrease_speed_button_pressed() -> void: func _on_update_active_nation_management_screen(active_screen : NationManagement.Screen) -> void: for screen : NationManagement.Screen in _nation_management_buttons: - _nation_management_button_textures[screen].set_icon_index(1 + int(screen == active_screen)) + _nation_management_buttons[screen].set_icon_index(1 + int(screen == active_screen)) -- cgit v1.2.3-56-ga3b1