-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsave_check.gd
43 lines (36 loc) · 1.21 KB
/
save_check.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
class_name SaveCheck # asks user if unsaved changes need saving
extends ConfirmationDialog
enum {
RISKY_QUIT,
RISKY_NEW,
RISKY_LOAD,
}
static var risky_action := RISKY_QUIT
static var grammar : String
static var plural := "edits"
static var unsaved_changes : int:
set(value):
grammar = "ahead of" if value < 0 else "behind"
plural = "edit" if abs(value) == 1 else "edits"
unsaved_changes = value
get: # refresh on access!
unsaved_changes = Global.save_point - Global.revision
return unsaved_changes
signal confirm_new
signal confirm_load
func _ready() -> void:
cancel_button_text = "Wait, Go Back"
ok_button_text = "Continue"
about_to_popup.connect(_set_text)
confirmed.connect(_confirm)
func _set_text() -> void:
match risky_action:
RISKY_QUIT: dialog_text = "Really quit and discard unsaved changes?"
RISKY_NEW: dialog_text = "Really discard your chart and unsaved changes?"
RISKY_LOAD: dialog_text = "Really load a new chart and discard unsaved changes?"
dialog_text += "\n\nYou are %s %s %s your last save." % [abs(unsaved_changes),plural,grammar]
func _confirm() -> void:
match risky_action:
RISKY_QUIT: get_tree().quit()
RISKY_NEW: confirm_new.emit()
RISKY_LOAD: confirm_load.emit()