blob: e660c6ada156cfeb0ed23a1dfb0931e8aabc88ea (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
extends GUINode
@export var _outliner_guinode : GUINode
var _speed_up_button : Button
var _speed_down_button : Button
var _speed_indicator_button : Button
var _speed_indicator_texture : GFXSpriteTexture
var _date_label : Label
var _country_name_label : Label
# NationManagement.Screen-Button
var _nation_management_buttons : Dictionary
# NationManagement.Screen-GFXSpriteTexture
var _nation_management_button_textures : Dictionary
func _ready() -> void:
GameSingleton.gamestate_updated.connect(_update_info)
GameSingleton.clock_state_changed.connect(_update_speed_controls)
add_gui_element("topbar", "topbar")
hide_nodes([
^"./topbar/topbar_outlinerbutton_bg",
^"./topbar/topbar_outlinerbutton"
])
const player_country : String = "SLV"
# Player country info
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(player_country)
# Time controls
_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_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")
if pause_bg_button:
pause_bg_button.pressed.connect(_on_play_pause_button_pressed)
_date_label = get_label_from_nodepath(^"./topbar/DateText")
_country_name_label = get_label_from_nodepath(^"./topbar/CountryName")
if _country_name_label:
_country_name_label.text = player_country
_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)
# Nation management screens
const screen_nodepaths : Dictionary = {
NationManagement.Screen.PRODUCTION : ^"./topbar/topbarbutton_production",
NationManagement.Screen.BUDGET : ^"./topbar/topbarbutton_budget",
NationManagement.Screen.TECHNOLOGY : ^"./topbar/topbarbutton_tech",
NationManagement.Screen.POLITICS : ^"./topbar/topbarbutton_politics",
NationManagement.Screen.POPULATION : ^"./topbar/topbarbutton_pops",
NationManagement.Screen.TRADE : ^"./topbar/topbarbutton_trade",
NationManagement.Screen.DIPLOMACY : ^"./topbar/topbarbutton_diplomacy",
NationManagement.Screen.MILITARY : ^"./topbar/topbarbutton_military"
}
for screen in screen_nodepaths:
var button : Button = get_button_from_nodepath(screen_nodepaths[screen])
if button:
button.pressed.connect(
Events.NationManagementScreens.toggle_nation_management_screen.bind(screen)
)
var icon : GFXSpriteTexture = get_gfx_sprite_texture_from_node(button)
if icon:
_nation_management_buttons[screen] = button
_nation_management_button_textures[screen] = icon
Events.NationManagementScreens.update_active_nation_management_screen.connect(
_on_update_active_nation_management_screen
)
_update_info()
_update_speed_controls()
func _notification(what : int) -> void:
match what:
NOTIFICATION_TRANSLATION_CHANGED:
_update_info()
func _update_info() -> void:
if _date_label:
_date_label.text = GameSingleton.get_longform_date()
func _update_speed_controls() -> void:
# TODO - decide whether to disable these or not
# (they don't appear to get disabled in the base game)
#if _speed_up_button:
# _speed_up_button.disabled = not GameSingleton.can_increase_speed()
#if _speed_down_button:
# _speed_down_button.disabled = not GameSingleton.can_decrease_speed()
if _speed_indicator_button and _speed_indicator_texture:
var index : int = 1
if not GameSingleton.is_paused():
index += GameSingleton.get_speed() + 1
_speed_indicator_texture.set_icon_index(index)
_speed_indicator_button.queue_redraw()
# REQUIREMENTS:
# * UIFUN-71
func _on_play_pause_button_pressed() -> void:
print("Toggling pause!")
GameSingleton.toggle_paused()
# REQUIREMENTS:
# * UIFUN-72
func _on_increase_speed_button_pressed() -> void:
print("Speed up!")
GameSingleton.increase_speed()
# REQUIREMENTS:
# * UIFUN-73
func _on_decrease_speed_button_pressed() -> void:
print("Speed down!")
GameSingleton.decrease_speed()
func _on_update_active_nation_management_screen(active_screen : NationManagement.Screen) -> void:
for screen in _nation_management_buttons:
_nation_management_button_textures[screen].set_icon_index(1 + int(screen == active_screen))
_nation_management_buttons[screen].queue_redraw()
|