Skip to content

Commit 223fe96

Browse files
committed
wip cr stats window
1 parent 5714cd1 commit 223fe96

File tree

2 files changed

+69
-34
lines changed

2 files changed

+69
-34
lines changed

Scenes/CompareCreatureStats.gd

+60-25
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ onready var oStatsOptionButton = Nodelist.list["oStatsOptionButton"]
66

77
var all_creature_data = {}
88

9-
var list_data = []
109
var selected_labels = []
1110

1211
func _ready():
@@ -18,7 +17,6 @@ func _ready():
1817
for path in listOfCfgs:
1918
var aaa = Utils.read_dkcfg_file(path)
2019
all_creature_data[path.get_file()] = aaa
21-
#print(creature_data)
2220

2321
print('Codetime: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')
2422

@@ -31,30 +29,61 @@ func _ready():
3129

3230
Utils.popup_centered(self)
3331

34-
func _on_StatsOptionButton_item_selected(index):
35-
update_list()
32+
func _on_StatsOptionButton_item_selected(optionButtonIndex):
33+
update_list(optionButtonIndex)
3634

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+
3843
for file in all_creature_data:
44+
var getName = all_creature_data[file].get("attributes").get("Name")
3945
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]:
4347

44-
list_data.append([getName, getHealth])
48+
var getValue = all_creature_data[file][section].get(optionButtonMeta[1])
49+
list_data.append([getName, getValue])
4550

4651
list_data.sort_custom(self, "sort_list")
47-
4852
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)
5058

5159

5260
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
5483

5584
func add_entry(string1, value, fontColor):
5685
var addLabel1 = Label.new()
57-
addLabel1.text = string1
86+
addLabel1.text = str(string1)
5887
oSortCreaStatsGrid.add_child(addLabel1)
5988
addLabel1.set("custom_colors/font_color", fontColor)
6089
addLabel1.mouse_filter = Control.MOUSE_FILTER_PASS
@@ -78,33 +107,35 @@ func add_entry(string1, value, fontColor):
78107
addLabel2.connect("gui_input", self, "_on_label_gui_input", [addLabel1, addLabel2])
79108

80109
func _on_label_mouse_entered(l1,l2):
81-
if [l1, l2] in selected_labels:
110+
if l1.text in selected_labels:
82111
pass
83112
else:
84113
l1.set("custom_colors/font_color", Color(1,1,1))
85114
l2.set("custom_colors/font_color", Color(1,1,1))
86115

87116
func _on_label_mouse_exited(l1,l2):
88-
if [l1, l2] in selected_labels:
117+
if l1.text in selected_labels:
89118
pass
90119
else:
91120
l1.set("custom_colors/font_color", Color(0.5,0.5,0.5))
92121
l2.set("custom_colors/font_color", Color(0.5,0.5,0.5))
93122

94123
func _on_label_gui_input(event, l1, l2):
95124
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))
100130
else:
101-
selected_labels.append([l1, l2])
131+
selected_labels.append(label_text)
102132
l1.set("custom_colors/font_color", Color(1, 1, 1))
103133
l2.set("custom_colors/font_color", Color(1, 1, 1))
104134

105135
func _on_NameStatsButton_pressed():
106-
pass # Replace with function body.
107-
136+
selected_labels.clear()
137+
138+
108139

109140

110141

@@ -118,6 +149,7 @@ func _on_RightStatsButton_pressed():
118149
while next_index < oStatsOptionButton.selected and oStatsOptionButton.get_item_text(next_index) == "":
119150
next_index += 1
120151
oStatsOptionButton.selected = next_index
152+
_on_StatsOptionButton_item_selected(next_index)
121153

122154
func _on_LeftStatsButton_pressed():
123155
var prev_index = oStatsOptionButton.selected - 1
@@ -128,14 +160,17 @@ func _on_LeftStatsButton_pressed():
128160
while prev_index > oStatsOptionButton.selected and oStatsOptionButton.get_item_text(prev_index) == "":
129161
prev_index -= 1
130162
oStatsOptionButton.selected = prev_index
163+
_on_StatsOptionButton_item_selected(prev_index)
131164

132165

133166
func populate_optionbutton():
134167
var items_checked = 0
135168
for file in all_creature_data:
136-
items_checked+=1
169+
items_checked += 1
137170
for section in all_creature_data[file]:
138171
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])
141176
oStatsOptionButton.add_separator()

Scenes/Main.tscn

+9-9
Original file line numberDiff line numberDiff line change
@@ -6836,20 +6836,20 @@ size_flags_vertical = 3
68366836
margin_right = 309.0
68376837
margin_bottom = 27.0
68386838

6839+
[node name="StatsOptionButton" type="OptionButton" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer"]
6840+
margin_right = 247.0
6841+
margin_bottom = 27.0
6842+
size_flags_horizontal = 3
6843+
text = "Sections"
6844+
68396845
[node name="LeftStatsButton" type="Button" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer"]
6840-
margin_right = 27.0
6846+
margin_left = 251.0
6847+
margin_right = 278.0
68416848
margin_bottom = 27.0
68426849
rect_min_size = Vector2( 27, 27 )
68436850
size_flags_horizontal = 0
68446851
text = "<"
68456852

6846-
[node name="StatsOptionButton" type="OptionButton" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer"]
6847-
margin_left = 31.0
6848-
margin_right = 278.0
6849-
margin_bottom = 27.0
6850-
size_flags_horizontal = 3
6851-
text = "Sections"
6852-
68536853
[node name="RightStatsButton" type="Button" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer"]
68546854
margin_left = 282.0
68556855
margin_right = 309.0
@@ -7640,8 +7640,8 @@ script = SubResource( 20 )
76407640
[connection signal="pressed" from="Ui/UiSystem/ResizeCurrentMapSize/MarginContainer/VBoxContainer/ResizeApplyButton" to="Ui/UiSystem/ResizeCurrentMapSize" method="_on_ResizeApplyButton_pressed"]
76417641
[connection signal="visibility_changed" from="Ui/UiSystem/GridDataWindow" to="Game2D/AnalyzeGrids" method="_on_GridDataWindow_visibility_changed"]
76427642
[connection signal="visibility_changed" from="Ui/UiSystem/ActionPointListWindow" to="Ui/UiSystem/ActionPointListWindow/MarginContainer/VBoxContainer/ScrollContainer/ActionPointList" method="_on_ActionPointListWindow_visibility_changed"]
7643-
[connection signal="pressed" from="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer/LeftStatsButton" to="Ui/UiSystem/SortCreatureStats" method="_on_LeftStatsButton_pressed"]
76447643
[connection signal="item_selected" from="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer/StatsOptionButton" to="Ui/UiSystem/SortCreatureStats" method="_on_StatsOptionButton_item_selected"]
7644+
[connection signal="pressed" from="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer/LeftStatsButton" to="Ui/UiSystem/SortCreatureStats" method="_on_LeftStatsButton_pressed"]
76457645
[connection signal="pressed" from="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer/RightStatsButton" to="Ui/UiSystem/SortCreatureStats" method="_on_RightStatsButton_pressed"]
76467646
[connection signal="pressed" from="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer2/NameStatsButton" to="Ui/UiSystem/SortCreatureStats" method="_on_NameStatsButton_pressed"]
76477647
[connection signal="visibility_changed" from="Ui/UiSystem/MapCoordinatesWindow" to="Ui/UiSystem/MapCoordinatesWindow" method="_on_MapCoordinatesWindow_visibility_changed"]

0 commit comments

Comments
 (0)