aboutsummaryrefslogtreecommitdiff
path: root/menu/menu.gd
blob: 5847d5b3bd704b6a1d918d9e5599f0a77b2db8b4 (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
extends MenuButton

const menu_items: Array = [
	{ label = "IMPORT OPTION SETS",	action = "_menu_import_option_sets_action" },
	{ label = "EXPORT OPTION SETS",	action = "_menu_export_option_sets_action" },
	{ label = "CLEAR OPTION SETS",	action = "_menu_clear_option_sets_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")


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


func _menu_import_option_sets_action():
	file_picker.window_title = "IMPORT OPTION SETS"
	file_picker.mode = FileDialog.MODE_OPEN_FILE
	file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
	file_picker.filters[0] = "*.json"
	file_picker.current_file = ""
	file_picker.connect("file_selected", stage, "import_option_sets", [true], CONNECT_ONESHOT)
	file_picker.show_modal(true)
	file_picker.invalidate()


func _menu_export_option_sets_action():
	file_picker.window_title = "EXPORT OPTION SETS"
	file_picker.mode = FileDialog.MODE_SAVE_FILE
	file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
	file_picker.filters[0] = "*.json"
	file_picker.current_file = ""
	file_picker.connect("file_selected", stage, "store_option_sets", [], CONNECT_ONESHOT)
	file_picker.show_modal(true)
	file_picker.invalidate()


func _menu_clear_option_sets_action():
	confirm_action.window_title = "CLEAR OPTION SETS"
	confirm_action.dialog_text = "Do you want to delete all option sets?"
	confirm_action.connect("confirmed", stage, "clear_option_sets", [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.filters[0] = "*.csv"
	file_picker.current_file = ""
	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 = "ABOUT"
	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)