aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GameSession/NationManagementScreen/TechnologyMenu.gd
blob: 496f7642976a83d09b0dbbd7fd19ede98723e354 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
extends GUINode

var _active : bool = false

const _screen : NationManagement.Screen = NationManagement.Screen.TECHNOLOGY
#generates the necessary base elements
var country_technology : Control = generate_gui_element("country_technology", "country_technology")
var folder_window : Control = generate_gui_element("country_technology", "folder_window")
var folder_windows = []
var tech_group : Control = generate_gui_element("country_technology", "tech_group")
var tech_groups = []
var tech_window : Control = generate_gui_element("country_technology", "tech_window")
var tech_windows = generate_tech_windows()

#populate godot dictionaries from the simulation backend
var tech_folder_dict : Dictionary = GameSingleton.get_tech_folders()
var tech_area_dict : Dictionary = GameSingleton.get_tech_areas()
var tech_dict : Dictionary = GameSingleton.get_technologies()

#defines the selected tech UI so we arent running expensive get_node repeatedly
var selected_tech_ui : Control

func _ready() -> void:
   GameSingleton.gamestate_updated.connect(_update_info)
   add_child(country_technology)
   Events.NationManagementScreens.update_active_nation_management_screen.connect(_on_update_active_nation_management_screen)

   
   generate_interface()
   #setup the window since the gui file doesnt store positions, can probably be optimised
   for folder_item in folder_windows:
      country_technology.add_child(folder_item)
   folder_windows.clear()
   for tech_group_item in tech_groups:
      country_technology.add_child(tech_group_item)
   tech_groups.clear()
   for research_item_column in tech_windows:
      for research_item_row in research_item_column:
         country_technology.add_child(research_item_row)
   tech_windows.clear()
   
   selected_tech_ui = get_node("/root/GameSession/Topbar/TechnologyMenu/country_technology/selected_tech_window")
   populate_areas("army_tech")
   

   var close_button : Button = get_button_from_nodepath(^"./country_technology/close_button")
   if close_button:
      close_button.pressed.connect(Events.NationManagementScreens.close_nation_management_screen.bind(_screen))

   _update_info()

func _notification(what : int) -> void:
   match what:
      NOTIFICATION_TRANSLATION_CHANGED:
         _update_info()

func _on_update_active_nation_management_screen(active_screen : NationManagement.Screen) -> void:
   _active = active_screen == _screen
   _update_info()

func _update_info() -> void:
   if _active:
      
      show()
   else:
      hide()
      
func generate_interface():
   #generate the initial UI elements
   for i in 5:
      var temp = folder_window.duplicate()
      temp.name = tech_folder_dict[i].identifier
      temp.get_child(0).connect("pressed",Callable(self,"_folder_button_pressed").bind(temp.name))
      temp.get_child(2).text = tech_folder_dict[i].identifier
      temp.position.x = 28+(194*i)
      temp.position.y = 55
      folder_windows.append(temp)
   for i in 5:
      var temp = tech_group.duplicate()
      temp.name = temp.name+str(i)
      temp.position.x = 28+(194*i)
      temp.position.y = 107
      tech_groups.append(temp)
      
func populate_areas(identifier):
   var offset
   match identifier:
      "army_tech":
         offset = 0
      "navy_tech":
         offset = 5
      "commerce_tech":
         offset = 10
      "culture_tech":
         offset = 15
      "industry_tech":
         offset = 20
   for i in 5:
      var node = get_node("/root/GameSession/Topbar/TechnologyMenu/country_technology/tech_group"+str(i))
      node.get_child(0).text = tech_area_dict[offset+i].identifier
   populate_techs(identifier)

func populate_techs(identifier):
   var offset
   match identifier:
      "army_tech":
         offset = 0
      "navy_tech":
         offset = 120
      "commerce_tech":
         offset = 30
      "culture_tech":
         offset = 60
      "industry_tech":
         offset = 90
   var shift = 0
   for x in 5:
      for y in 6:
         var node = get_node("/root/GameSession/Topbar/TechnologyMenu/country_technology/tech_window"+str(x)+"_"+str(y))
         node.get_child(1).text = tech_dict[offset+(shift+y)].identifier
         if(node.get_child(0).is_connected("pressed",Callable(self,"_tech_button_pressed").bind(tech_dict[offset+(shift+y)])) == false):
            node.get_child(0).connect("pressed",Callable(self,"_tech_button_pressed").bind(tech_dict[offset+(shift+y)]))
      shift = shift + 6

func generate_tech_windows():
   var matrix = []
   for xi in range(5):
      var row = []
      for yi in range(6):
         var temp = tech_window.duplicate()
         temp.name = temp.name+str(xi)+"_"+str(yi)
         temp.position.x = 28+(194*xi)
         temp.position.y = 122+(40*yi)
         row.append(temp)
      matrix.append(row)
   return matrix
   
func _folder_button_pressed(selected_folder):
   populate_areas(selected_folder)
   #selected_tech_ui.get_child(1).text = "NO_TECH_SELECTED"
   
func _tech_button_pressed(item):
   selected_tech_ui.get_child(1).text = item.identifier
   selected_tech_ui.get_child(6).text = str(item.cost)
   selected_tech_ui.get_child(8).text = str(item.year)