@@ -6,7 +6,6 @@ onready var oStatsOptionButton = Nodelist.list["oStatsOptionButton"]
6
6
7
7
var all_creature_data = {}
8
8
9
- var list_data = []
10
9
var selected_labels = []
11
10
12
11
func _ready ():
@@ -18,7 +17,6 @@ func _ready():
18
17
for path in listOfCfgs :
19
18
var aaa = Utils .read_dkcfg_file (path )
20
19
all_creature_data [path .get_file ()] = aaa
21
- # print(creature_data)
22
20
23
21
print ('Codetime: ' + str (OS .get_ticks_msec () - CODETIME_START ) + 'ms' )
24
22
@@ -31,30 +29,61 @@ func _ready():
31
29
32
30
Utils .popup_centered (self )
33
31
34
- func _on_StatsOptionButton_item_selected (index ):
35
- update_list ()
32
+ func _on_StatsOptionButton_item_selected (optionButtonIndex ):
33
+ update_list (optionButtonIndex )
36
34
37
- func update_list ():
35
+ func update_list (optionButtonIndex ):
36
+
37
+ var list_data = []
38
+ for i in oSortCreaStatsGrid .get_children ():
39
+ i .free ()
40
+
41
+ var optionButtonMeta = oStatsOptionButton .get_item_metadata (optionButtonIndex )
42
+
38
43
for file in all_creature_data :
44
+ var getName = all_creature_data [file ].get ("attributes" ).get ("Name" )
39
45
for section in all_creature_data [file ]:
40
- if section == "attributes" :
41
- var getName = all_creature_data [file ][section ].get ("Name" )
42
- var getHealth = all_creature_data [file ][section ].get ("Health" )
46
+ if section == optionButtonMeta [0 ]:
43
47
44
- list_data .append ([getName , getHealth ])
48
+ var getValue = all_creature_data [file ][section ].get (optionButtonMeta [1 ])
49
+ list_data .append ([getName , getValue ])
45
50
46
51
list_data .sort_custom (self , "sort_list" )
47
-
48
52
for i in list_data :
49
- add_entry (i [0 ], i [1 ], Color (0.5 ,0.5 ,0.5 ))
53
+ var col = Color (0.5 ,0.5 ,0.5 )
54
+ var label_text = str (i [0 ]) # Create a single string with a separator
55
+ if label_text in selected_labels :
56
+ col = Color (1.0 ,1.0 ,1.0 )
57
+ add_entry (i [0 ], i [1 ], col )
50
58
51
59
52
60
func sort_list (a , b ):
53
- return int (a [1 ]) < int (b [1 ])
61
+
62
+ var compareA
63
+ var compareB
64
+
65
+ if a [1 ] is int :
66
+ compareA = a [1 ]
67
+ elif a [1 ] is String :
68
+ compareA = a [1 ].length ()
69
+ elif a [1 ] is Array :
70
+ compareA = int (a [1 ][0 ])
71
+ else :
72
+ compareA = 0
73
+
74
+ if b [1 ] is int :
75
+ compareB = b [1 ]
76
+ elif b [1 ] is String :
77
+ compareB = b [1 ].length ()
78
+ elif b [1 ] is Array :
79
+ compareB = int (b [1 ][0 ])
80
+ else :
81
+ compareB = 0
82
+ return compareA < compareB
54
83
55
84
func add_entry (string1 , value , fontColor ):
56
85
var addLabel1 = Label .new ()
57
- addLabel1 .text = string1
86
+ addLabel1 .text = str ( string1 )
58
87
oSortCreaStatsGrid .add_child (addLabel1 )
59
88
addLabel1 .set ("custom_colors/font_color" , fontColor )
60
89
addLabel1 .mouse_filter = Control .MOUSE_FILTER_PASS
@@ -78,33 +107,35 @@ func add_entry(string1, value, fontColor):
78
107
addLabel2 .connect ("gui_input" , self , "_on_label_gui_input" , [addLabel1 , addLabel2 ])
79
108
80
109
func _on_label_mouse_entered (l1 ,l2 ):
81
- if [ l1 , l2 ] in selected_labels :
110
+ if l1 . text in selected_labels :
82
111
pass
83
112
else :
84
113
l1 .set ("custom_colors/font_color" , Color (1 ,1 ,1 ))
85
114
l2 .set ("custom_colors/font_color" , Color (1 ,1 ,1 ))
86
115
87
116
func _on_label_mouse_exited (l1 ,l2 ):
88
- if [ l1 , l2 ] in selected_labels :
117
+ if l1 . text in selected_labels :
89
118
pass
90
119
else :
91
120
l1 .set ("custom_colors/font_color" , Color (0.5 ,0.5 ,0.5 ))
92
121
l2 .set ("custom_colors/font_color" , Color (0.5 ,0.5 ,0.5 ))
93
122
94
123
func _on_label_gui_input (event , l1 , l2 ):
95
124
if event is InputEventMouseButton and event .pressed and event .button_index == BUTTON_LEFT :
96
- if [l1 , l2 ] in selected_labels :
97
- selected_labels .erase ([l1 , l2 ])
98
- l1 .set ("custom_colors/font_color" , Color (0.5 , 0.5 , 0.5 ))
99
- l2 .set ("custom_colors/font_color" , Color (0.5 , 0.5 , 0.5 ))
125
+ var label_text = l1 .text
126
+ if label_text in selected_labels :
127
+ selected_labels .erase (label_text )
128
+ l1 .set ("custom_colors/font_color" , Color (0.5 ,0.5 ,0.5 ))
129
+ l2 .set ("custom_colors/font_color" , Color (0.5 ,0.5 ,0.5 ))
100
130
else :
101
- selected_labels .append ([ l1 , l2 ] )
131
+ selected_labels .append (label_text )
102
132
l1 .set ("custom_colors/font_color" , Color (1 , 1 , 1 ))
103
133
l2 .set ("custom_colors/font_color" , Color (1 , 1 , 1 ))
104
134
105
135
func _on_NameStatsButton_pressed ():
106
- pass # Replace with function body.
107
-
136
+ selected_labels .clear ()
137
+
138
+
108
139
109
140
110
141
@@ -118,6 +149,7 @@ func _on_RightStatsButton_pressed():
118
149
while next_index < oStatsOptionButton .selected and oStatsOptionButton .get_item_text (next_index ) == "" :
119
150
next_index += 1
120
151
oStatsOptionButton .selected = next_index
152
+ _on_StatsOptionButton_item_selected (next_index )
121
153
122
154
func _on_LeftStatsButton_pressed ():
123
155
var prev_index = oStatsOptionButton .selected - 1
@@ -128,14 +160,17 @@ func _on_LeftStatsButton_pressed():
128
160
while prev_index > oStatsOptionButton .selected and oStatsOptionButton .get_item_text (prev_index ) == "" :
129
161
prev_index -= 1
130
162
oStatsOptionButton .selected = prev_index
163
+ _on_StatsOptionButton_item_selected (prev_index )
131
164
132
165
133
166
func populate_optionbutton ():
134
167
var items_checked = 0
135
168
for file in all_creature_data :
136
- items_checked += 1
169
+ items_checked += 1
137
170
for section in all_creature_data [file ]:
138
171
if items_checked == 1 :
139
- for blah in all_creature_data [file ][section ].keys ():
140
- oStatsOptionButton .add_item (blah )
172
+ for key in all_creature_data [file ][section ].keys ():
173
+ var idx = oStatsOptionButton .get_item_count ()
174
+ oStatsOptionButton .add_item (key )
175
+ oStatsOptionButton .set_item_metadata (idx , [section , key ])
141
176
oStatsOptionButton .add_separator ()
0 commit comments