aboutsummaryrefslogtreecommitdiff
path: root/scripts/gui_turret_detail.gd
blob: 74e382e26a3144eb5abfe4b0bd3071cd9f999d22 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
extends Panel

var hbox_labels 
var hbox_global
var _turret_holder : Node
var _turret_values : Resource = load("res://scenes/gui/gui_turret_values.tscn")
var load_turrets : Node
var resources : Node

var gui : Control

func _fetch ():
	if gui == null: gui = get_parent()
	if load_turrets != null: return;
	
	var root = get_tree().root.get_node("world")
	_turret_holder = root.get_node("turrets")
	
	hbox_labels = $"hbox_global/hbox_labels"
	hbox_global = $"hbox_global"
	
	resources = root.get_node("player").get_node("resources")
	
	load_turrets = root.get_node("saveload").get_node("load_turrets")
	if !load_turrets.loaded: yield(load_turrets, "done_loading")
	
	
func refresh (turret : Dictionary, upgraded : Dictionary = {}):
	_fetch()
	if upgraded == null: rect_min_size.x = 200
	else: rect_min_size.x = 230
	
	get_node("name_label").text = "name: " + turret.name
	
	var dict = {
		"damage": turret.get("damage", "-"),
		"range": turret.get("range", "-"),
		"turn speed": turret.get("turn_speed", "-"),
		"cooldown": turret.get("cooldown", "-"),
		"projectile": turret.get("projectile", {}).get("type", "-"),
		"spread": turret.get("projectile", {}).get("spread", "-"),
		"projectile speed": turret.get("projectile", {}).get("speed", "-"),
		"projectiles per shot": turret.get("projectile", {}).get("amount", "-"),
		"modules": turret.get("modules_max", "-"),
	}

	var base_values = hbox_global.get_node("hbox_values")
	for k in dict:
		base_values.get_node(k).text = str(dict[k]);

func _process(delta):
	_fetch()
	
	var info = null;
	
	var hovering = null
	if gui.control.state == Globals.PlayerState.PICK and \
			gui.control.statetype == Globals.StateType.TURRET and \
			gui.bottom_bar.picker.hovering != "":
		hovering = gui.bottom_bar.picker.hovering
		
	var highlight = null
	if gui.control.state == Globals.PlayerState.EDIT and \
			gui.control.statetype == Globals.StateType.TURRET:
		var turret_name = gui.control.editing_turret
		highlight = _turret_holder.get_node(turret_name)
		
	var placing = null
	if gui.control.state == Globals.PlayerState.PLACE and \
			gui.control.statetype == Globals.StateType.TURRET and \
			gui.control.selected != "":
		placing = gui.control.selected
		
	if highlight != null:
		info = highlight.info
	elif placing != null:
		info = load_turrets.info[placing]
	elif hovering != null:
		info = load_turrets.info[hovering]
	elif gui.player.placer.colliding \
			and "turrets" in gui.player.placer.colliding_group:
		info = gui.player.placer.colliding_node.info
		
	if info != null: 
		refresh(info)
		self.visible = true
	else: self.visible = false