aboutsummaryrefslogtreecommitdiff
path: root/menu/menu.gd
blob: b5e1ef2b4bda5cbfddf55e076da5b94b33ba8c92 (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
88
89
90
91
92
93
94
extends MenuButton

const menu_items: Array = [
	{ label = "IMPORT FILTERS",		action = "_menu_import_filters_action" },
	{ label = "EXPORT FILTERS",		action = "_menu_export_filters_action" },
	{ label = "CLEAR FILTERS",		action = "_menu_clear_filters_action" },
	{ label = "EXPORT DATA",		action = "_menu_export_data_action" },
	{ label = "CLEAR DATA",			action = "_menu_clear_data_action" },
	{ label = "ABOUT",				action = "_menu_about_action" },
	{ label = "FAKE_DB",			action = "_menu_fake_db_action" },
]
const license_font_b612: String		= "res://licenses/font_b612.txt"
const license_godot: String			= "res://licenses/godot.txt"

onready var popup					:= get_popup() as PopupMenu
onready var confirm_action			:= get_node("/root/main/confirm_action") as ConfirmationDialog
onready var file_picker				:= get_node("/root/main/file_picker") as FileDialog
onready var database				:= get_node("/root/main/database") as Database
onready var stage					:= get_node("/root/main/stage") as Stage


func _ready():
	for idx in range(menu_items.size()):
		popup.add_item(menu_items[idx].label, idx)
	popup.connect("id_pressed", self, "id_pressed")
	file_picker.get_cancel().connect("pressed", self, "dialog_cancelled", ["file_selected"])
	confirm_action.get_cancel().connect("pressed", self, "dialog_cancelled", ["confirmed"])


func id_pressed(id: int):
	self.call_deferred(menu_items[id].action)


func dialog_cancelled(confirmation_signal_name: String):
	var confirmation_handlers = confirm_action.get_signal_connection_list(confirmation_signal_name)
	for it in confirmation_handlers:
		confirm_action.disconnect(it.signal, it.target, it.method)


func _menu_import_filters_action():
	file_picker.window_title = "IMPORT FILTERS"
	file_picker.mode = FileDialog.MODE_OPEN_FILE
	file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
	file_picker.connect("file_selected", stage, "load_filters", [], CONNECT_ONESHOT)
	file_picker.show_modal(true)
	file_picker.invalidate()


func _menu_export_filters_action():
	file_picker.window_title = "EXPORT FILTERS"
	file_picker.mode = FileDialog.MODE_SAVE_FILE
	file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
	file_picker.connect("file_selected", stage, "store_filters", [], CONNECT_ONESHOT)
	file_picker.show_modal(true)
	file_picker.invalidate()


func _menu_clear_filters_action():
	confirm_action.window_title = "CLEAR FILTERS"
	confirm_action.dialog_text = "Do you want to delete all filters?"
	confirm_action.connect("confirmed", stage, "clear_filters", [true], CONNECT_ONESHOT)
	confirm_action.show_modal(true)


func _menu_export_data_action():
	file_picker.window_title = "EXPORT DATA"
	file_picker.mode = FileDialog.MODE_SAVE_FILE
	file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
	file_picker.connect("file_selected", database, "store_database", [], CONNECT_ONESHOT)
	file_picker.show_modal(true)
	file_picker.invalidate()


func _menu_clear_data_action():
	confirm_action.window_title = "CLEAR DATA"
	confirm_action.dialog_text = "Do you want to delete all entries from the database?"
	confirm_action.connect("confirmed", database, "clear_database", [true], CONNECT_ONESHOT)
	confirm_action.show_modal(true)


func _menu_about_action():
	confirm_action.window_title = "FAKE DB"
	confirm_action.dialog_text = "About text here!"
	confirm_action.show_modal(true)


# @DAM Hide this debug method before release.
func _menu_fake_db_action():
	confirm_action.window_title = "FAKE DB"
	confirm_action.dialog_text = "Do you want to delete all entries from the database and replace by fake entries?"
	confirm_action.connect("confirmed", database, "fake_database", [true], CONNECT_ONESHOT)
	confirm_action.show_modal(true)