diff options
Diffstat (limited to 'scripts/gui_picker.gd')
-rw-r--r-- | scripts/gui_picker.gd | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/scripts/gui_picker.gd b/scripts/gui_picker.gd index 21f6b4c..7a20842 100644 --- a/scripts/gui_picker.gd +++ b/scripts/gui_picker.gd @@ -1,7 +1,8 @@ extends Panel var _hbox : HBoxContainer -var _gui_button : Resource = load("res://scenes/gui/gui_turret.tscn") +var _gui_button : Resource = load("res://scenes/gui/gui_button.tscn") +var _gui_turret_button : Resource = load("res://scenes/gui/gui_turret.tscn") var _options = [] @@ -15,37 +16,57 @@ func _fetch (): func build (options : Array = []): _fetch() + hovering = "" - if options.size() > 0: - for n in _hbox.get_children(): n.queue_free() + for child in _hbox.get_children(): + child.disconnect("mouse_entered", self, "_on_gui_turret_mouse_entered") + child.disconnect("mouse_exited", self, "_on_gui_turret_mouse_exited") + child.disconnect("pressed", self, "_on_gui_turret_pressed") + child.queue_free() - _options = options - for t in _options: - var gt : TextureButton = _gui_button.instance() - gt.name = t.name - _hbox.add_child(gt) - gt.init(t) + _options = options + for opt in _options: + var button = null + if opt.type == "turret buy": + button = _gui_turret_button.instance() + _hbox.add_child(button) + button.init(opt.name) + if opt.type == "turret upg": + button = _gui_turret_button.instance() + _hbox.add_child(button) + button.init(opt.name) + if opt.type == "text": + button = _gui_button.instance() + _hbox.add_child(button) + button.get_node("hbox").get_node("name_label").text = opt.name + if opt.type == "color": + button = _gui_button.instance() + _hbox.add_child(button) + button.get_node("hbox").get_node("name_label").text = "" + button.get_node("color").color = opt.color + + if button != null: + button.option = opt.name + else: print("no option for " + str(opt)) for child in _hbox.get_children(): - if child.get_signal_connection_list("pressed").size() == 0: - child.connect("mouse_entered", self, "_on_gui_turret_mouse_entered", [child.name]) - child.connect("mouse_exited", self, "_on_gui_turret_mouse_exited", [child.name]) - child.connect("pressed", self, "_on_gui_turret_pressed", [child.name]) + child.connect("mouse_entered", self, "_on_gui_turret_mouse_entered", [child.option]) + child.connect("mouse_exited", self, "_on_gui_turret_mouse_exited", [child.option]) + child.connect("pressed", self, "_on_gui_turret_pressed", [child.option]) -func refresh (sel): +func refresh (): _fetch() - if sel.type == "idle": + if gui.control.state == Globals.PlayerState.PICK: for child in _hbox.get_children(): child.picked = false - if sel.type == name: + if gui.control.selected == name: for child in _hbox.get_children(): - child.picked = child.name == sel.name + child.picked = child.name == gui.control.selected -func _on_gui_turret_mouse_entered(name : String): - hovering = name; +func _on_gui_turret_mouse_entered(option : String): + hovering = option; -func _on_gui_turret_mouse_exited(name : String): +func _on_gui_turret_mouse_exited(option : String): hovering = "" -func _on_gui_turret_pressed(name : String): - print(self.name + ' ' + name) - gui.player.selected_event(name, self.name) +func _on_gui_turret_pressed(option : String): + gui.control.do(Globals.PlayerActions.PICK, { "selected": option }) |