3 Commits

Author SHA1 Message Date
320d6ceb0b remove native dialogs 2023-04-30 18:48:31 +02:00
8fd89c3b4c remove native dialogs 2023-04-30 18:47:36 +02:00
467cec1c30 use native dialogs 2023-04-26 01:10:17 +02:00
7 changed files with 127 additions and 45 deletions

View File

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

View File

@ -96,6 +96,10 @@ window/handheld/orientation="portrait"
window/ios/hide_home_indicator=false
window/stretch/aspect="keep"
[global]
rced=false
[gui]
theme/use_hidpi=true

View File

@ -63,6 +63,8 @@ var current_timesheet_file_path: String = "" setget set_current_timesheet_file_p
func set_current_timesheet_file_path(value: String) -> void:
if current_timesheet_file_path == value:
return
timesheet = _load_timesheet(value)
if timesheet == null:
return

View File

@ -28,15 +28,9 @@ func load_file() -> bool:
entries.append(entry)
file.close()
entries.sort_custom(self, "_sort_entries")
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:
for _entry in entries:
var current_time_entry := _entry as TimeEntry
@ -103,9 +97,11 @@ func save() -> void:
func make_items_tree() -> TimeEntryTreeItem:
var sorted_entries := EntrySorter.new(entries).sort_by([["name"], ["start_date", true]]).entries
var tree := TimeEntryTreeItem.new()
for entry_index in entries.size():
var entry := entries[entry_index] as TimeEntry
for entry_index in sorted_entries.size():
var entry := sorted_entries[entry_index] as TimeEntry
var parts := entry.name.split("/")
var repo: TimeEntryTreeItem = tree.get_child(parts, true)
repo.append(entry)
@ -119,3 +115,56 @@ static func restore(file_path: String) -> TimeSheet:
if success:
return timesheet
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
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_top = 46.0
margin_right = -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_vertical = 3
[node name="Settings" type="ScrollContainer" parent="VBoxContainer/TabContainer"]
visible = false

View File

@ -2,15 +2,15 @@ extends Control
var config: ConfigManager = preload("res://config_manager.tres")
onready var file_path_line_edit := $"%FilePathLineEdit" as LineEdit
onready var file_path_button := $"%FilePathButton" as Button
onready var theme_path_button := $"%ThemePathButton" as Button
onready var sound_check_box := $"%SoundCheckBox" as CheckBox
onready var open_data_dir_button := $"%OpenDataDirButton" as Button
onready var file_path_open_button := $"%FilePathOpenButton" as Button
onready var attributions_rich_text_label := $"%AttributionsRichTextLabel" as RichTextLabel
onready var file_path_file_dialog := $"%FilePathFileDialog" as FileDialog
onready var theme_path_file_dialog := $"%ThemePathFileDialog" as FileDialog
onready var file_path_line_edit: LineEdit = $"%FilePathLineEdit" as LineEdit
onready var file_path_button: Button = $"%FilePathButton" as Button
onready var theme_path_button: Button = $"%ThemePathButton" as Button
onready var sound_check_box: CheckBox = $"%SoundCheckBox" as CheckBox
onready var open_data_dir_button: Button = $"%OpenDataDirButton" as Button
onready var file_path_open_button: Button = $"%FilePathOpenButton" as Button
onready var attributions_rich_text_label: RichTextLabel = $"%AttributionsRichTextLabel" as RichTextLabel
onready var file_path_file_dialog: FileDialog = $"%FilePathFileDialog" as FileDialog
onready var theme_path_file_dialog: FileDialog = $"%ThemePathFileDialog" as FileDialog
func _ready() -> void:
@ -24,14 +24,19 @@ func _ready() -> void:
# warning-ignore:return_value_discarded
file_path_button.connect("pressed", self, "_on_file_path_button_pressed")
# warning-ignore:return_value_discarded
file_path_file_dialog.connect("visibility_changed", self, "_resize_on_dialog", [file_path_file_dialog])
# warning-ignore:return_value_discarded
file_path_file_dialog.connect("file_selected", self, "_on_current_file_selected")
# warning-ignore:return_value_discarded
file_path_line_edit.connect("text_entered", self, "_on_current_file_selected")
# warning-ignore:return_value_discarded
theme_path_button.connect("pressed", self, "_on_theme_path_button_pressed")
# warning-ignore:return_value_discarded
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")
@ -54,8 +59,7 @@ func _ready() -> void:
func _on_current_file_changed() -> void:
file_path_file_dialog.current_path = config.current_timesheet_file_path
file_path_file_dialog.current_dir = config.current_timesheet_file_path.get_base_dir()
#file_path_file_dialog.initial_path = config.current_timesheet_file_path.get_base_dir()
file_path_line_edit.text = config.current_timesheet_file_path
@ -64,11 +68,11 @@ func _on_theme_changed() -> void:
func _on_file_path_button_pressed() -> void:
file_path_file_dialog.popup_centered()
_set_file_dialog_file_path(file_path_file_dialog, config.current_timesheet_file_path)
func _on_current_file_selected(new_file: String) -> void:
config.set_current_file = new_file
config.current_timesheet_file_path = new_file
func _on_sound_toggle(is_on: bool) -> void:
@ -76,11 +80,12 @@ func _on_sound_toggle(is_on: bool) -> void:
func _on_theme_path_button_pressed() -> void:
theme_path_file_dialog.popup_centered()
_set_file_dialog_file_path(theme_path_file_dialog, config.theme_file_path)
theme_path_file_dialog.show()
func _on_new_theme_selected(new_theme_path: String) -> void:
config.set_theme_path = new_theme_path
config.theme_file_path = new_theme_path
func _on_attributions_rich_text_label_meta_clicked(meta) -> void:
@ -101,3 +106,19 @@ func _open_path(path: String):
var canonical_path := ProjectSettings.globalize_path(path).strip_edges()
# warning-ignore:return_value_discarded
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,29 +126,26 @@ This game uses Godot Engine, available under the following license:
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="FilePathFileDialog" type="FileDialog" parent="CanvasLayer"]
unique_name_in_owner = true
anchor_right = 1.0
anchor_bottom = 1.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="Popups" type="Control" parent="CanvasLayer"]
margin_right = 40.0
margin_bottom = 40.0
mouse_filter = 2
[node name="ThemePathFileDialog" type="FileDialog" parent="CanvasLayer"]
[node name="FilePathFileDialog" type="FileDialog" parent="CanvasLayer/Popups"]
unique_name_in_owner = true
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
window_title = "Open a File"
resizable = true
margin_right = 1092.0
margin_bottom = 762.0
window_title = "Select CSV"
dialog_hide_on_ok = true
access = 2
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
mode_overrides_title = false
mode = 0
access = 2
filters = PoolStringArray( "*.theme ; Theme Files" )