aboutsummaryrefslogtreecommitdiff
path: root/menu/menu.gd
diff options
context:
space:
mode:
Diffstat (limited to 'menu/menu.gd')
-rw-r--r--menu/menu.gd112
1 files changed, 112 insertions, 0 deletions
diff --git a/menu/menu.gd b/menu/menu.gd
new file mode 100644
index 0000000..55c74fa
--- /dev/null
+++ b/menu/menu.gd
@@ -0,0 +1,112 @@
+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 = "ABOUT", action = "_menu_about_action" },
+]
+const license_font_b612: String = "res://licenses/font_b612.txt"
+const license_godot: String = "res://licenses/godot.txt"
+
+onready var popup: PopupMenu = get_popup()
+onready var debug: Label = get_node("/root/main/debug") as Label
+
+func _ready():
+
+ for idx in range(menu_items.size()):
+ popup.add_item(menu_items[idx].label, idx)
+ popup.connect("id_pressed", self, "id_pressed")
+
+# load_file(file)
+
+
+
+func id_pressed(id: int):
+ debug.text += "'%d':'%s'" % [id, menu_items[id].action]
+ self.call_deferred(menu_items[id].action)
+ debug.text += "!\n"
+
+
+var csv_file: Array
+var has_permissions := false
+func _menu_import_filters_action():
+
+# printerr("pressed: %s" % get_stack()[0]);
+ debug.text += "> import: "
+
+ if OS.get_name() == "Android":
+ while not has_permissions:
+ var permissions := Array(OS.get_granted_permissions())
+ if not permissions.has("android.permission.READ_EXTERNAL_STORAGE") \
+ or not permissions.has("android.permission.WRITE_EXTERNAL_STORAGE"):
+ OS.request_permissions()
+ # await get_tree().create_timer(1).timeout
+ yield(get_tree().create_timer(1), "timeout") # - for Godot 3 branch
+ else:
+ has_permissions = true
+
+
+
+ var file_dialog := get_node("/root/main/import_filters") as FileDialog
+ file_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
+ file_dialog.connect("file_selected", self, "file_selected", [], CONNECT_ONESHOT)
+ file_dialog.show_modal(true)
+ file_dialog.invalidate()
+# printerr("download: '%s'" % OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS))
+
+func file_selected(path: String):
+ debug.text += "'%s'\n" % path
+
+ var file = File.new()
+ file.open(path, File.READ)
+ while file.eof_reached() == false:
+ var line = file.get_line()
+ csv_file.append(line)
+ printerr("%s" % line)
+ file.close()
+
+func _menu_export_filters_action():
+ debug.text += "> export: \n"
+# printerr("pressed: %s" % get_stack()[0]);
+ var file_dialog := get_node("/root/main/export_filters") as FileDialog
+ file_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)
+ file_dialog.connect("file_selected", self, "file_selected_export", [], CONNECT_ONESHOT)
+ file_dialog.show_modal(true)
+ file_dialog.invalidate()
+
+func file_selected_export(path: String):
+ debug.text += "'%s'\n" % path
+ var file = File.new()
+ file.open(path, File.WRITE)
+ for ln in csv_file:
+ file.store_line(ln)
+ file.close()
+
+
+func _menu_clear_filters_action():
+ debug.text += "> clear\n"
+# printerr("pressed: %s" % get_stack()[0]);
+ (get_node("/root/main/delete_filters") as ConfirmationDialog).show_modal(true)
+
+
+func _menu_about_action():
+# printerr("pressed: %s" % get_stack()[0]);
+ debug.text += "> about\n"
+ (get_node("/root/main/about") as AcceptDialog).show_modal()
+
+
+#func load_file(file: String):
+# var f = File.new()
+# f.open(file, File.READ)
+# var index = 1
+# while not f.eof_reached(): # iterate through all lines until the end of file is reached
+# var line = f.get_line()
+# line += " "
+# print(line + str(index))
+#
+# index += 1
+# f.close()
+# return
+
+