aboutsummaryrefslogtreecommitdiff
path: root/logic/popup.gd
blob: 2ff91fea06094d3c9569b4da5eae7a049a1c9aad (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
extends Control
class_name ModalPopup

signal dismissed		# ()

var control				: Control
var control_parent		: Node

onready var title		:= get_node("title") as Label
onready var background	:= get_node("background") as Panel


func _init():
	anchor_right = 1.0
	anchor_bottom = 1.0


func _ready():
	get_node("dismiss").connect("pressed", self, "dismiss")


func open_popup(title: String, item: Control):
	if visible == true:
		return
	
	self.title.text = title
	
	control = item
	control_parent = control.get_parent()
	control_parent.remove_child(control)
	self.add_child(control)
	
	control.anchor_left = background.anchor_left
	control.anchor_top = background.anchor_top
	control.anchor_right = background.anchor_right
	control.anchor_bottom = background.anchor_bottom
	control.margin_left = 20
	control.margin_top = 20
	control.margin_right = -20
	control.margin_bottom = -20
	add_child(control)
	
	self.show()
	control.show()


func dismiss():
	emit_signal("dismissed")


func close_popup():
	if visible == false:
		return
	self.hide()
	control.hide()
	remove_child(control)
	control_parent.add_child(control)
	control_parent = null