aboutsummaryrefslogtreecommitdiff
path: root/scripts/gui.gd
blob: 65ff39b7eb1a8bb6a3a162102ef1448c9106b643 (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
extends Control

var player : Node
var control : Node
var wave : Node

var bottom_bar : Control
var top_bar : Control
var wave_ongoing : Panel
var load_map : PanelContainer
var save_as : AcceptDialog
var delete_confirm : AcceptDialog
var edit_palette : AcceptDialog
var saveload : Node
var saveload_map : Node

func _fetch ():
	var root = get_tree().root.get_node("world")
	player = root.get_node("player")
	control = player.get_node("control")
	wave = root.get_node("wave")
	saveload = root.get_node("saveload")
	saveload_map = saveload.get_node("saveload_map")
	
	if bottom_bar == null: bottom_bar = get_node("bottom_bar")
	if top_bar == null: top_bar = get_node("top_bar")
	if wave_ongoing == null: wave_ongoing = $wave_ongoing_indicator
	if load_map == null: load_map = $gui_load_map
	if save_as == null: 
		save_as = $save_as
		save_as.register_text_enter(save_as.get_node("line_edit"))
	if delete_confirm == null: 
		delete_confirm = $delete_confirm
	if edit_palette == null: 
		edit_palette = $edit_palette

func _ready():
	_fetch()

func refresh ():
	_fetch()
	
	bottom_bar.refresh(control.ineditor)
	top_bar.refresh(control.ineditor)
	
	if wave.ongoing: wave_ongoing.visible = true
	else: wave_ongoing.visible = false

func save_as_mapname():
	var mapname = save_as.get_node("line_edit").text
	if !mapname.ends_with(".json"): mapname += ".json"
	control.gui_save_as_map_event(mapname)
	save_as.visible = false
	load_map.build()

func _on_save_as_confirmed(): 
	save_as_mapname()

func _on_delete_confirmed():
	control.gui_delete_map_event(load_map.selected_delete)
	load_map.build()

func _on_close_load_map():
	load_map.visible = false

func _on_edit_palette_confirmed():
	control.gui_picked_color(edit_palette.get_node("ColorPicker").color)