5 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
8888572829 ensure paths work on MacOS 2023-04-26 00:31:12 +02:00
f94a0e89d6 whiten tree font 2023-04-26 00:21:59 +02:00
8 changed files with 168 additions and 82 deletions

Binary file not shown.

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,6 +96,10 @@ window/handheld/orientation="portrait"
window/ios/hide_home_indicator=false window/ios/hide_home_indicator=false
window/stretch/aspect="keep" window/stretch/aspect="keep"
[global]
rced=false
[gui] [gui]
theme/use_hidpi=true 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: func set_current_timesheet_file_path(value: String) -> void:
if current_timesheet_file_path == value:
return
timesheet = _load_timesheet(value) timesheet = _load_timesheet(value)
if timesheet == null: if timesheet == null:
return return

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,15 +2,15 @@ extends Control
var config: ConfigManager = preload("res://config_manager.tres") var config: ConfigManager = preload("res://config_manager.tres")
onready var file_path_line_edit := $"%FilePathLineEdit" as LineEdit onready var file_path_line_edit: LineEdit = $"%FilePathLineEdit" as LineEdit
onready var file_path_button := $"%FilePathButton" as Button onready var file_path_button: Button = $"%FilePathButton" as Button
onready var theme_path_button := $"%ThemePathButton" as Button onready var theme_path_button: Button = $"%ThemePathButton" as Button
onready var sound_check_box := $"%SoundCheckBox" as CheckBox onready var sound_check_box: CheckBox = $"%SoundCheckBox" as CheckBox
onready var open_data_dir_button := $"%OpenDataDirButton" as Button onready var open_data_dir_button: Button = $"%OpenDataDirButton" as Button
onready var file_path_open_button := $"%FilePathOpenButton" as Button onready var file_path_open_button: Button = $"%FilePathOpenButton" as Button
onready var attributions_rich_text_label := $"%AttributionsRichTextLabel" as RichTextLabel onready var attributions_rich_text_label: RichTextLabel = $"%AttributionsRichTextLabel" as RichTextLabel
onready var file_path_file_dialog := $"%FilePathFileDialog" as FileDialog onready var file_path_file_dialog: FileDialog = $"%FilePathFileDialog" as FileDialog
onready var theme_path_file_dialog := $"%ThemePathFileDialog" as FileDialog onready var theme_path_file_dialog: FileDialog = $"%ThemePathFileDialog" as FileDialog
func _ready() -> void: func _ready() -> void:
@ -24,14 +24,19 @@ 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")
# 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 # 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")
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
file_path_line_edit.connect("text_entered", self, "_on_current_file_selected") file_path_line_edit.connect("text_entered", self, "_on_current_file_selected")
# 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")
# 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 # warning-ignore:return_value_discarded
theme_path_file_dialog.connect("file_selected", self, "_on_new_theme_selected") 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: func _on_current_file_changed() -> void:
file_path_file_dialog.current_path = config.current_timesheet_file_path #file_path_file_dialog.initial_path = config.current_timesheet_file_path.get_base_dir()
file_path_file_dialog.current_dir = config.current_timesheet_file_path.get_base_dir()
file_path_line_edit.text = config.current_timesheet_file_path 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: 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: 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: 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: 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: 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: func _on_attributions_rich_text_label_meta_clicked(meta) -> void:
@ -90,10 +95,30 @@ func _on_attributions_rich_text_label_meta_clicked(meta) -> void:
func _on_open_data_dir_button_pressed() -> void: func _on_open_data_dir_button_pressed() -> void:
# warning-ignore:return_value_discarded _open_path(OS.get_user_data_dir())
OS.shell_open(OS.get_user_data_dir())
func _on_file_path_open_button_pressed() -> void: func _on_file_path_open_button_pressed() -> void:
_open_path(config.current_timesheet_file_path.get_base_dir())
func _open_path(path: String):
var canonical_path := ProjectSettings.globalize_path(path).strip_edges()
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
OS.shell_open(config.current_timesheet_file_path.get_base_dir()) 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

@ -10,87 +10,87 @@ size_flags_vertical = 3
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="VBoxContainer" type="VBoxContainer" parent="."] [node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_right = 360.0 margin_right = 505.0
margin_bottom = 760.0 margin_bottom = 760.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_right = 360.0 margin_right = 505.0
margin_bottom = 24.0 margin_bottom = 45.0
size_flags_horizontal = 3 size_flags_horizontal = 3
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"] [node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
margin_top = 5.0 margin_top = 10.0
margin_right = 55.0 margin_right = 92.0
margin_bottom = 19.0 margin_bottom = 35.0
text = "File Path" text = "File Path"
[node name="FilePathLineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer"] [node name="FilePathLineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
margin_left = 59.0 margin_left = 100.0
margin_right = 223.0 margin_right = 264.0
margin_bottom = 24.0 margin_bottom = 45.0
size_flags_horizontal = 3 size_flags_horizontal = 3
caret_blink = true caret_blink = true
caret_blink_speed = 0.5 caret_blink_speed = 0.5
[node name="FilePathButton" type="Button" parent="VBoxContainer/HBoxContainer"] [node name="FilePathButton" type="Button" parent="VBoxContainer/HBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
margin_left = 227.0 margin_left = 272.0
margin_right = 251.0 margin_right = 314.0
margin_bottom = 24.0 margin_bottom = 45.0
text = "..." text = "..."
[node name="FilePathOpenButton" type="Button" parent="VBoxContainer/HBoxContainer"] [node name="FilePathOpenButton" type="Button" parent="VBoxContainer/HBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
margin_left = 255.0 margin_left = 322.0
margin_right = 360.0 margin_right = 505.0
margin_bottom = 24.0 margin_bottom = 45.0
text = "open directory" text = "open directory"
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 28.0 margin_top = 53.0
margin_right = 360.0 margin_right = 505.0
margin_bottom = 48.0 margin_bottom = 90.0
size_flags_horizontal = 3 size_flags_horizontal = 3
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer2"] [node name="Label" type="Label" parent="VBoxContainer/HBoxContainer2"]
margin_top = 3.0 margin_top = 6.0
margin_right = 118.0 margin_right = 199.0
margin_bottom = 17.0 margin_bottom = 31.0
text = "Alternative Theme" text = "Alternative Theme"
[node name="ThemePathButton" type="Button" parent="VBoxContainer/HBoxContainer2"] [node name="ThemePathButton" type="Button" parent="VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true unique_name_in_owner = true
margin_left = 122.0 margin_left = 207.0
margin_right = 161.0 margin_right = 278.0
margin_bottom = 20.0 margin_bottom = 37.0
text = "load" text = "load"
[node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 52.0 margin_top = 98.0
margin_right = 360.0 margin_right = 505.0
margin_bottom = 76.0 margin_bottom = 146.0
size_flags_horizontal = 3 size_flags_horizontal = 3
[node name="SoundCheckBox" type="CheckBox" parent="VBoxContainer/HBoxContainer3"] [node name="SoundCheckBox" type="CheckBox" parent="VBoxContainer/HBoxContainer3"]
unique_name_in_owner = true unique_name_in_owner = true
margin_right = 74.0 margin_right = 134.0
margin_bottom = 24.0 margin_bottom = 48.0
text = "sounds" text = "sounds"
[node name="OpenDataDirButton" type="Button" parent="VBoxContainer"] [node name="OpenDataDirButton" type="Button" parent="VBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
margin_top = 80.0 margin_top = 154.0
margin_right = 360.0 margin_right = 505.0
margin_bottom = 100.0 margin_bottom = 191.0
text = "Open data dir" text = "Open data dir"
[node name="AttributionsRichTextLabel" type="RichTextLabel" parent="VBoxContainer"] [node name="AttributionsRichTextLabel" type="RichTextLabel" parent="VBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
margin_top = 104.0 margin_top = 199.0
margin_right = 360.0 margin_right = 505.0
margin_bottom = 760.0 margin_bottom = 760.0
size_flags_vertical = 3 size_flags_vertical = 3
theme_type_variation = "small_text" theme_type_variation = "small_text"
@ -126,29 +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
anchor_right = 1.0 margin_bottom = 40.0
anchor_bottom = 1.0 mouse_filter = 2
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" )