aboutsummaryrefslogtreecommitdiff
path: root/scripts/gui_picker.gd
blob: 0dc4dcb56fda185f6fc4aa949d5fa66fcc2300b1 (plain)
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
extends Panel

var _hbox : HBoxContainer
var _gui_button : Resource = load("res://scenes/gui/gui_turret.tscn")
var _gui_detail : Resource = load("res://scenes/gui/gui_turret.tscn")

var _options = []

var gui : Control

var hovering = ""

func _fetch ():
	if gui == null: gui = get_parent().gui
	if _hbox == null: _hbox = $Hbox

func build (options : Array = []):
	_fetch()
	
	if options.size() > 0:
		for n in _hbox.get_children(): n.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)
		
	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])

func refresh (sel):
	_fetch()
	if sel.type == "idle":
		for child in _hbox.get_children(): child.picked = false
	if sel.type == name:
		for child in _hbox.get_children():
			child.picked = child.name == sel.name
	
func _on_gui_turret_mouse_entered(name : String):
	hovering = name;
	
func _on_gui_turret_mouse_exited(name : String):
	hovering = ""
	
func _on_gui_turret_pressed(name : String):
	print(self.name + ' ' + name)
	gui.player.selected_event(name, self.name)