aboutsummaryrefslogtreecommitdiff
path: root/logic
diff options
context:
space:
mode:
Diffstat (limited to 'logic')
-rw-r--r--logic/file_picker.gd18
-rw-r--r--logic/menu.gd121
-rw-r--r--logic/popup.gd76
3 files changed, 139 insertions, 76 deletions
diff --git a/logic/file_picker.gd b/logic/file_picker.gd
new file mode 100644
index 0000000..9715d0d
--- /dev/null
+++ b/logic/file_picker.gd
@@ -0,0 +1,18 @@
+extends FileDialog
+
+export var clear_signals_on_hide := true
+
+
+func _init():
+ self.connect("hide", self, "_clear_signals")
+
+
+func _clear_signals():
+ if clear_signals_on_hide == false:
+ return
+
+ for signal_name in ["file_selected"]:
+ for it in get_signal_connection_list(signal_name):
+ disconnect(it.signal, it.target, it.method)
+
+
diff --git a/logic/menu.gd b/logic/menu.gd
new file mode 100644
index 0000000..d6e1501
--- /dev/null
+++ b/logic/menu.gd
@@ -0,0 +1,121 @@
+extends MenuButton
+
+const menu_items: Array = [
+ { label = "Import Option Sets", action = "import_option_sets_action" },
+ { label = "Export Option Sets", action = "export_option_sets_action" },
+ { label = "Clear Option Sets", action = "clear_option_sets_action" },
+ { label = "Import Database", action = "import_database_action" },
+ { label = "Export Database", action = "export_database_action" },
+ { label = "Clear Database", action = "clear_database_action" },
+ { label = "About", action = "about_action" },
+]
+const license_font_b612: String = "res://licenses/font_b612.txt"
+const license_godot: String = "res://licenses/godot.txt"
+
+onready var menu := get_popup() as PopupMenu
+onready var popup := get_node("/root/main/popup") as ModalPopup
+onready var dialog := get_node("/root/main/dialog") as Dialog
+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()):
+ menu.add_item(menu_items[idx].label, idx)
+ menu.connect("id_pressed", self, "id_pressed")
+
+
+func id_pressed(id: int):
+ self.call_deferred(menu_items[id].action)
+
+
+func import_option_sets_action():
+ dialog.setup("All option sets from the dropdown menus will be replaced.", "Continue", "No")
+ dialog.connect("accepted", self, "import_option_sets_action_accepted")
+ popup.open_popup("Replace option sets?", dialog)
+
+
+func import_option_sets_action_accepted():
+ file_picker.mode = FileDialog.MODE_OPEN_FILE
+ file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
+ file_picker.filters = ["*.json", "*.csv"]
+ file_picker.current_file = ""
+ file_picker.connect("file_selected", self, "import_option_sets")
+ file_picker.show_modal(true)
+ file_picker.invalidate()
+
+
+func import_option_sets(file_path: String):
+ stage.load_option_sets(file_path)
+ stage.save_option_sets()
+
+
+func export_option_sets_action():
+ file_picker.mode = FileDialog.MODE_SAVE_FILE
+ file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
+ file_picker.filters = ["*.json"]
+ file_picker.current_file = ""
+ file_picker.connect("file_selected", stage, "save_option_sets")
+ file_picker.show_modal(true)
+ file_picker.invalidate()
+
+
+func clear_option_sets_action():
+ dialog.setup("All option sets from the dropdown menus will be deleted.", "Delete all", "No")
+ dialog.connect("accepted", self, "clear_option_sets")
+ popup.open_popup("Clear option sets?", dialog)
+
+
+func clear_option_sets():
+ stage.clear_option_sets()
+ stage.save_option_sets()
+
+
+func import_database_action():
+ dialog.setup("All entries from the database will be replaced.", "Continue", "No")
+ dialog.connect("accepted", self, "import_database_action_accepted")
+ popup.open_popup("Replace database?", dialog)
+
+
+func import_database_action_accepted():
+ file_picker.mode = FileDialog.MODE_OPEN_FILE
+ file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
+ file_picker.filters = ["*.json", "*.csv"]
+ file_picker.current_file = ""
+ file_picker.connect("file_selected", self, "import_database")
+ file_picker.show_modal(true)
+ file_picker.invalidate()
+
+
+func import_database(file_path: String):
+ database.load_database(file_path)
+ database.save_database()
+
+
+func export_database_action():
+ file_picker.mode = FileDialog.MODE_SAVE_FILE
+ file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
+ file_picker.filters = ["*.csv"]
+ file_picker.current_file = ""
+ file_picker.connect("file_selected", database, "save_database")
+ file_picker.show_modal(true)
+ file_picker.invalidate()
+
+
+func clear_database_action():
+ dialog.setup("All entries from the database will be deleted.", "Delete all", "No")
+ dialog.connect("accepted", self, "clear_database")
+ popup.open_popup("Clear database?", dialog)
+
+
+func clear_database():
+ database.clear_database()
+ database.save_database()
+
+
+func about_action():
+ dialog.setup("Surgery Log\nversion 0.1", "", "")
+ popup.open_popup("About", dialog)
+
+
diff --git a/logic/popup.gd b/logic/popup.gd
deleted file mode 100644
index 95fc2c3..0000000
--- a/logic/popup.gd
+++ /dev/null
@@ -1,76 +0,0 @@
-extends Control
-class_name ModalPopup
-
-signal dismissed # ()
-
-export var clear_signals_on_hide := true
-
-var control : Control
-var control_parent : Node
-
-onready var title := get_node("title") as Label
-onready var background := get_node("background") as Panel
-onready var dismiss_button := get_node("dismiss") as Button
-
-
-func _init():
- self.anchor_right = 1.0
- self.anchor_bottom = 1.0
- self.rect_clip_content = true
- self.connect("hide", self, "_clear_signals")
-
-
-func _ready():
- dismiss_button.connect("pressed", self, "dismiss")
-
-
-func _clear_signals():
- if clear_signals_on_hide == false:
- return
-
- for signal_name in ["dismissed"]:
- for it in get_signal_connection_list(signal_name):
- disconnect(it.signal, it.target, it.method)
-
-
-func dismiss():
- emit_signal("dismissed")
- close_popup()
-
-
-func open_popup(title: String, item: Control):
- if visible == true:
- return
-
- self.title.text = title
-
- control = item
- control.connect("hide", self, "close_popup")
- 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
-
- self.show()
- control.show()
-
-
-func close_popup():
- if visible == false:
- return
-
- control.disconnect("hide", self, "close_popup")
- control.hide()
- self.hide()
- remove_child(control)
- control_parent.add_child(control)
- control_parent = null
-