remove native dialogs

This commit is contained in:
xananax prozaxx 2023-04-30 18:47:36 +02:00
parent 467cec1c30
commit 8fd89c3b4c
6 changed files with 119 additions and 54 deletions

View File

@ -50,7 +50,7 @@ script_encryption_key=""
custom_template/debug="" custom_template/debug=""
custom_template/release="" custom_template/release=""
application/name="mutnt" application/name="Rat Times"
application/info="Made with Godot Engine" application/info="Made with Godot Engine"
application/icon="res://assets/logo.icns" application/icon="res://assets/logo.icns"
application/identifier="io.mutnt.app.rattimes" application/identifier="io.mutnt.app.rattimes"

View File

@ -96,9 +96,9 @@ window/handheld/orientation="portrait"
window/ios/hide_home_indicator=false window/ios/hide_home_indicator=false
window/stretch/aspect="keep" window/stretch/aspect="keep"
[editor_plugins] [global]
enabled=PoolStringArray( "res://addons/native_dialogs/plugin.cfg" ) rced=false
[gui] [gui]

View File

@ -28,15 +28,9 @@ func load_file() -> bool:
entries.append(entry) entries.append(entry)
file.close() file.close()
entries.sort_custom(self, "_sort_entries")
return true return true
func _sort_entries(a: TimeEntry, b: TimeEntry) -> bool:
return a.name < b.name
func get_active_entry_from_name(task_name: String) -> TimeEntry: func get_active_entry_from_name(task_name: String) -> TimeEntry:
for _entry in entries: for _entry in entries:
var current_time_entry := _entry as TimeEntry var current_time_entry := _entry as TimeEntry
@ -103,9 +97,11 @@ func save() -> void:
func make_items_tree() -> TimeEntryTreeItem: func make_items_tree() -> TimeEntryTreeItem:
var sorted_entries := EntrySorter.new(entries).sort_by([["name"], ["start_date", true]]).entries
var tree := TimeEntryTreeItem.new() var tree := TimeEntryTreeItem.new()
for entry_index in entries.size(): for entry_index in sorted_entries.size():
var entry := entries[entry_index] as TimeEntry var entry := sorted_entries[entry_index] as TimeEntry
var parts := entry.name.split("/") var parts := entry.name.split("/")
var repo: TimeEntryTreeItem = tree.get_child(parts, true) var repo: TimeEntryTreeItem = tree.get_child(parts, true)
repo.append(entry) repo.append(entry)
@ -119,3 +115,56 @@ static func restore(file_path: String) -> TimeSheet:
if success: if success:
return timesheet return timesheet
return null return null
class EntrySorter:
var entries: Array
var _sorters := PoolStringArray()
func _init(initial_entries: Array) -> void:
entries = initial_entries.duplicate()
func by_name(reverse := false) -> EntrySorter:
return sort_by_one("name", reverse)
func by_date(reverse := false) -> EntrySorter:
return sort_by_one("date", reverse)
func sort_by_one(property: String, reverse := false) -> EntrySorter:
var method_name := "_by_%s"%[property]
assert(has_method(method_name), "%s is not a valid sorting property"%[property])
entries.sort_custom(self, method_name)
if reverse:
entries.invert()
return self
func sort_by(initial_sorters: Array) -> EntrySorter:
for item in initial_sorters:
var property = item[0]
var reversed = item[1] if item.size() > 1 else false
var method_name := "_by_%s"%[property]
assert(has_method(method_name), "%s is not a valid sorting property"%[property])
assert(reversed == null or reversed is bool, "The second item is not a boolean")
return self
_sorters = initial_sorters
entries.sort_custom(self, "__by_multiple")
_sorters = PoolStringArray()
return self
func __by_multiple(a: TimeEntry, b: TimeEntry) -> bool:
for item in _sorters:
var property = item[0]
var reversed = item[1]
var method_name := "_by_%s"%[property]
var result: bool = call(method_name, a, b)
if reversed:
result = not result
if result == false:
return false
return true
func _by_name(a: TimeEntry, b: TimeEntry) -> bool:
return a.name < b.name
func _by_date(a: TimeEntry, b: TimeEntry) -> bool:
return a.start_time < b.start_time

View File

@ -68,12 +68,21 @@ margin_right = 350.0
margin_bottom = 750.0 margin_bottom = 750.0
size_flags_vertical = 3 size_flags_vertical = 3
[node name="TasksList" parent="VBoxContainer/TabContainer" instance=ExtResource( 2 )] [node name="Task List" type="VBoxContainer" parent="VBoxContainer/TabContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 5.0 margin_left = 5.0
margin_top = 46.0 margin_top = 46.0
margin_right = -5.0 margin_right = -5.0
margin_bottom = -5.0 margin_bottom = -5.0
[node name="TasksList" parent="VBoxContainer/TabContainer/Task List" instance=ExtResource( 2 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 340.0
margin_bottom = 550.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3
[node name="Settings" type="ScrollContainer" parent="VBoxContainer/TabContainer"] [node name="Settings" type="ScrollContainer" parent="VBoxContainer/TabContainer"]
visible = false visible = false

View File

@ -2,17 +2,15 @@ extends Control
var config: ConfigManager = preload("res://config_manager.tres") var config: ConfigManager = preload("res://config_manager.tres")
const NativeDialogs := preload("res://addons/native_dialogs/native_dialogs.gd") onready var file_path_line_edit: LineEdit = $"%FilePathLineEdit" as LineEdit
onready var file_path_button: Button = $"%FilePathButton" as Button
onready var file_path_line_edit := $"%FilePathLineEdit" as LineEdit onready var theme_path_button: Button = $"%ThemePathButton" as Button
onready var file_path_button := $"%FilePathButton" as Button onready var sound_check_box: CheckBox = $"%SoundCheckBox" as CheckBox
onready var theme_path_button := $"%ThemePathButton" as Button onready var open_data_dir_button: Button = $"%OpenDataDirButton" as Button
onready var sound_check_box := $"%SoundCheckBox" as CheckBox onready var file_path_open_button: Button = $"%FilePathOpenButton" as Button
onready var open_data_dir_button := $"%OpenDataDirButton" as Button onready var attributions_rich_text_label: RichTextLabel = $"%AttributionsRichTextLabel" as RichTextLabel
onready var file_path_open_button := $"%FilePathOpenButton" as Button onready var file_path_file_dialog: FileDialog = $"%FilePathFileDialog" as FileDialog
onready var attributions_rich_text_label := $"%AttributionsRichTextLabel" as RichTextLabel onready var theme_path_file_dialog: FileDialog = $"%ThemePathFileDialog" as FileDialog
var file_path_file_dialog := NativeDialogs.SaveFile.new()
var theme_path_file_dialog := NativeDialogs.OpenFile.new()
func _ready() -> void: func _ready() -> void:
@ -26,9 +24,8 @@ func _ready() -> void:
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
file_path_button.connect("pressed", self, "_on_file_path_button_pressed") file_path_button.connect("pressed", self, "_on_file_path_button_pressed")
file_path_file_dialog.filters = ["*.csv ; CSV Files"] # warning-ignore:return_value_discarded
file_path_file_dialog.force_overwrite = true file_path_file_dialog.connect("visibility_changed", self, "_resize_on_dialog", [file_path_file_dialog])
add_child(file_path_file_dialog)
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
file_path_file_dialog.connect("file_selected", self, "_on_current_file_selected") file_path_file_dialog.connect("file_selected", self, "_on_current_file_selected")
@ -38,10 +35,10 @@ func _ready() -> void:
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
theme_path_button.connect("pressed", self, "_on_theme_path_button_pressed") theme_path_button.connect("pressed", self, "_on_theme_path_button_pressed")
theme_path_file_dialog.filters = ["*.theme ; Theme Files"]
add_child(theme_path_file_dialog)
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
theme_path_file_dialog.connect("files_selected", self, "_on_new_theme_selected") theme_path_file_dialog.connect("visibility_changed", self, "_resize_on_dialog", [theme_path_file_dialog])
# warning-ignore:return_value_discarded
theme_path_file_dialog.connect("file_selected", self, "_on_new_theme_selected")
theme_path_file_dialog.hide() theme_path_file_dialog.hide()
file_path_file_dialog.hide() file_path_file_dialog.hide()
@ -71,8 +68,7 @@ func _on_theme_changed() -> void:
func _on_file_path_button_pressed() -> void: func _on_file_path_button_pressed() -> void:
file_path_file_dialog.initial_path = config.current_timesheet_file_path _set_file_dialog_file_path(file_path_file_dialog, config.current_timesheet_file_path)
file_path_file_dialog.show()
func _on_current_file_selected(new_file: String) -> void: func _on_current_file_selected(new_file: String) -> void:
@ -84,7 +80,7 @@ func _on_sound_toggle(is_on: bool) -> void:
func _on_theme_path_button_pressed() -> void: func _on_theme_path_button_pressed() -> void:
theme_path_file_dialog.initial_path = config.theme_file_path _set_file_dialog_file_path(theme_path_file_dialog, config.theme_file_path)
theme_path_file_dialog.show() theme_path_file_dialog.show()
@ -110,3 +106,19 @@ func _open_path(path: String):
var canonical_path := ProjectSettings.globalize_path(path).strip_edges() var canonical_path := ProjectSettings.globalize_path(path).strip_edges()
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
OS.shell_open("file://"+canonical_path) OS.shell_open("file://"+canonical_path)
func _set_file_dialog_file_path(dialog: FileDialog, path: String) -> void:
#dialog.current_path = path
#dialog.current_file = path
dialog.current_dir = path.get_base_dir()
dialog.show()
dialog.invalidate()
var previous_window_size := OS.window_size
func _resize_on_dialog(dialog: Control) -> void:
if dialog.visible == true:
previous_window_size = OS.window_size
OS.window_size = file_path_file_dialog.rect_size
else:
OS.window_size = previous_window_size

View File

@ -126,31 +126,26 @@ This game uses Godot Engine, available under the following license:
[node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="FilePathFileDialog" type="FileDialog" parent="CanvasLayer"] [node name="Popups" type="Control" parent="CanvasLayer"]
unique_name_in_owner = true margin_right = 40.0
visible = true margin_bottom = 40.0
margin_top = 39.0 mouse_filter = 2
margin_right = 875.0
margin_bottom = 765.0
size_flags_horizontal = 3
size_flags_vertical = 3
window_title = "Pick a file"
resizable = true
dialog_hide_on_ok = true
mode_overrides_title = false
access = 2
filters = PoolStringArray( "*.csv ; Comma Separated Files" )
[node name="ThemePathFileDialog" type="FileDialog" parent="CanvasLayer"] [node name="FilePathFileDialog" type="FileDialog" parent="CanvasLayer/Popups"]
unique_name_in_owner = true unique_name_in_owner = true
anchor_right = 1.0 margin_right = 1092.0
anchor_bottom = 1.0 margin_bottom = 762.0
size_flags_horizontal = 3 window_title = "Select CSV"
size_flags_vertical = 3 dialog_hide_on_ok = true
window_title = "Open a File" access = 2
resizable = true filters = PoolStringArray( "*.csv ; CSV Files" )
[node name="ThemePathFileDialog" type="FileDialog" parent="CanvasLayer/Popups"]
unique_name_in_owner = true
margin_right = 1092.0
margin_bottom = 762.0
window_title = "Select a Theme File"
dialog_hide_on_ok = true dialog_hide_on_ok = true
mode_overrides_title = false
mode = 0 mode = 0
access = 2 access = 2
filters = PoolStringArray( "*.theme ; Theme Files" ) filters = PoolStringArray( "*.theme ; Theme Files" )