|
| 1 | +extends WindowDialog |
| 2 | +onready var oGame = Nodelist.list["oGame"] |
| 3 | +onready var oSortCreaStatsGrid = Nodelist.list["oSortCreaStatsGrid"] |
| 4 | +onready var oStatsOptionButton = Nodelist.list["oStatsOptionButton"] |
| 5 | + |
| 6 | + |
| 7 | +var all_creature_data = {} |
| 8 | + |
| 9 | +var list_data = [] |
| 10 | +var selected_labels = [] |
| 11 | + |
| 12 | +func _ready(): |
| 13 | + for i in 10: |
| 14 | + yield(get_tree(),'idle_frame') |
| 15 | + |
| 16 | + var CODETIME_START = OS.get_ticks_msec() |
| 17 | + var listOfCfgs = Utils.get_filetype_in_directory(oGame.GAME_DIRECTORY.plus_file("creatrs"), "CFG") |
| 18 | + for path in listOfCfgs: |
| 19 | + var aaa = Utils.read_dkcfg_file(path) |
| 20 | + all_creature_data[path.get_file()] = aaa |
| 21 | + #print(creature_data) |
| 22 | + |
| 23 | + print('Codetime: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms') |
| 24 | + |
| 25 | + populate_optionbutton() |
| 26 | + |
| 27 | + |
| 28 | + # Default selection |
| 29 | + oStatsOptionButton.select(2) |
| 30 | + _on_StatsOptionButton_item_selected(2) |
| 31 | + |
| 32 | + Utils.popup_centered(self) |
| 33 | + |
| 34 | +func _on_StatsOptionButton_item_selected(index): |
| 35 | + update_list() |
| 36 | + |
| 37 | +func update_list(): |
| 38 | + for file in all_creature_data: |
| 39 | + 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") |
| 43 | + |
| 44 | + list_data.append([getName, getHealth]) |
| 45 | + |
| 46 | + list_data.sort_custom(self, "sort_list") |
| 47 | + |
| 48 | + for i in list_data: |
| 49 | + add_entry(i[0], i[1], Color(0.5,0.5,0.5)) |
| 50 | + |
| 51 | + |
| 52 | +func sort_list(a, b): |
| 53 | + return int(a[1]) < int(b[1]) |
| 54 | + |
| 55 | +func add_entry(string1, value, fontColor): |
| 56 | + var addLabel1 = Label.new() |
| 57 | + addLabel1.text = string1 |
| 58 | + oSortCreaStatsGrid.add_child(addLabel1) |
| 59 | + addLabel1.set("custom_colors/font_color", fontColor) |
| 60 | + addLabel1.mouse_filter = Control.MOUSE_FILTER_PASS |
| 61 | + |
| 62 | + var addLabel2 = Label.new() |
| 63 | + addLabel2.text = str(value) |
| 64 | + oSortCreaStatsGrid.add_child(addLabel2) |
| 65 | + addLabel2.set("custom_colors/font_color", fontColor) |
| 66 | + addLabel2.mouse_filter = Control.MOUSE_FILTER_PASS |
| 67 | + |
| 68 | + addLabel1.size_flags_horizontal = Control.SIZE_EXPAND_FILL |
| 69 | + addLabel2.size_flags_horizontal = Control.SIZE_EXPAND_FILL |
| 70 | + |
| 71 | + addLabel1.connect("mouse_entered", self, "_on_label_mouse_entered", [addLabel1, addLabel2]) |
| 72 | + addLabel2.connect("mouse_entered", self, "_on_label_mouse_entered", [addLabel1, addLabel2]) |
| 73 | + |
| 74 | + addLabel1.connect("mouse_exited", self, "_on_label_mouse_exited", [addLabel1, addLabel2]) |
| 75 | + addLabel2.connect("mouse_exited", self, "_on_label_mouse_exited", [addLabel1, addLabel2]) |
| 76 | + |
| 77 | + addLabel1.connect("gui_input", self, "_on_label_gui_input", [addLabel1, addLabel2]) |
| 78 | + addLabel2.connect("gui_input", self, "_on_label_gui_input", [addLabel1, addLabel2]) |
| 79 | + |
| 80 | +func _on_label_mouse_entered(l1,l2): |
| 81 | + if [l1, l2] in selected_labels: |
| 82 | + pass |
| 83 | + else: |
| 84 | + l1.set("custom_colors/font_color", Color(1,1,1)) |
| 85 | + l2.set("custom_colors/font_color", Color(1,1,1)) |
| 86 | + |
| 87 | +func _on_label_mouse_exited(l1,l2): |
| 88 | + if [l1, l2] in selected_labels: |
| 89 | + pass |
| 90 | + else: |
| 91 | + l1.set("custom_colors/font_color", Color(0.5,0.5,0.5)) |
| 92 | + l2.set("custom_colors/font_color", Color(0.5,0.5,0.5)) |
| 93 | + |
| 94 | +func _on_label_gui_input(event, l1, l2): |
| 95 | + 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)) |
| 100 | + else: |
| 101 | + selected_labels.append([l1, l2]) |
| 102 | + l1.set("custom_colors/font_color", Color(1, 1, 1)) |
| 103 | + l2.set("custom_colors/font_color", Color(1, 1, 1)) |
| 104 | + |
| 105 | +func _on_NameStatsButton_pressed(): |
| 106 | + pass # Replace with function body. |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +func _on_RightStatsButton_pressed(): |
| 113 | + var next_index = oStatsOptionButton.selected + 1 |
| 114 | + while next_index < oStatsOptionButton.get_item_count() and oStatsOptionButton.get_item_text(next_index) == "": |
| 115 | + next_index += 1 |
| 116 | + if next_index >= oStatsOptionButton.get_item_count(): |
| 117 | + next_index = 0 |
| 118 | + while next_index < oStatsOptionButton.selected and oStatsOptionButton.get_item_text(next_index) == "": |
| 119 | + next_index += 1 |
| 120 | + oStatsOptionButton.selected = next_index |
| 121 | + |
| 122 | +func _on_LeftStatsButton_pressed(): |
| 123 | + var prev_index = oStatsOptionButton.selected - 1 |
| 124 | + while prev_index >= 0 and oStatsOptionButton.get_item_text(prev_index) == "": |
| 125 | + prev_index -= 1 |
| 126 | + if prev_index < 0: |
| 127 | + prev_index = oStatsOptionButton.get_item_count() - 1 |
| 128 | + while prev_index > oStatsOptionButton.selected and oStatsOptionButton.get_item_text(prev_index) == "": |
| 129 | + prev_index -= 1 |
| 130 | + oStatsOptionButton.selected = prev_index |
| 131 | + |
| 132 | + |
| 133 | +func populate_optionbutton(): |
| 134 | + var items_checked = 0 |
| 135 | + for file in all_creature_data: |
| 136 | + items_checked+=1 |
| 137 | + for section in all_creature_data[file]: |
| 138 | + if items_checked == 1: |
| 139 | + for blah in all_creature_data[file][section].keys(): |
| 140 | + oStatsOptionButton.add_item(blah) |
| 141 | + oStatsOptionButton.add_separator() |
0 commit comments