-
Notifications
You must be signed in to change notification settings - Fork 6
/
ConfirmPopup.gd
77 lines (59 loc) · 2.08 KB
/
ConfirmPopup.gd
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
extends ConfirmationDialog
signal action_chosen(result)
enum {
OKAY,
CANCEL,
OTHER,
}
onready var ok_button = get_ok()
onready var cancel_button = get_cancel()
onready var other_button = add_button("", true)
func _ready():
ok_button.connect("pressed", self, "_on_button_pressed", [OKAY])
cancel_button.connect("pressed", self, "_on_button_pressed", [CANCEL])
other_button.connect("pressed", self, "_on_button_pressed", [OTHER])
ok_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
cancel_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
other_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
var box = (ok_button.get_parent() as HBoxContainer)
box.add_constant_override("separation", 16)
box.alignment = BoxContainer.ALIGN_CENTER
for child in box.get_children():
if not child is Button:
child.queue_free()
get_close_button().connect("pressed", self, "_on_button_pressed", [CANCEL])
var label = get_label()
label.align = Label.ALIGN_CENTER
func _popup(text:String, title:String, size:Vector2 = Vector2.ZERO):
window_title = title
dialog_text = text
rect_size = rect_min_size if size == Vector2.ZERO else size
call_deferred("popup_centered_minsize", rect_min_size)
func popup_confirm(text:String, title:String = "", size:Vector2 = Vector2.ZERO):
if title.empty():
title = "Please confirm..."
ok_button.visible = true
cancel_button.visible = true
other_button.visible = false
ok_button.text = "OK"
_popup(text, title, size)
func popup_save(text:String, title:String = "", size:Vector2 = Vector2.ZERO):
if title.empty():
title = "Confirm save..."
ok_button.visible = true
cancel_button.visible = true
other_button.visible = true
ok_button.text = "Save"
other_button.text = "Don't save"
_popup(text, title, size)
func popup_accept(text:String, title:String = "", size:Vector2 = Vector2.ZERO):
if title.empty():
title = "Warning!"
ok_button.visible = true
cancel_button.visible = false
other_button.visible = false
ok_button.text = "OK"
_popup(text, title, size)
func _on_button_pressed(result):
emit_signal("action_chosen", result)
hide()