use native dialogs

This commit is contained in:
2023-04-26 01:10:17 +02:00
parent 8888572829
commit 467cec1c30
29 changed files with 355 additions and 11 deletions

View File

@ -2,6 +2,8 @@ extends Control
var config: ConfigManager = preload("res://config_manager.tres")
const NativeDialogs := preload("res://addons/native_dialogs/native_dialogs.gd")
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
@ -9,8 +11,8 @@ 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
var file_path_file_dialog := NativeDialogs.SaveFile.new()
var theme_path_file_dialog := NativeDialogs.OpenFile.new()
func _ready() -> void:
@ -24,16 +26,22 @@ func _ready() -> void:
# warning-ignore:return_value_discarded
file_path_button.connect("pressed", self, "_on_file_path_button_pressed")
file_path_file_dialog.filters = ["*.csv ; CSV Files"]
file_path_file_dialog.force_overwrite = true
add_child(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")
theme_path_file_dialog.filters = ["*.theme ; Theme Files"]
add_child(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.connect("files_selected", self, "_on_new_theme_selected")
theme_path_file_dialog.hide()
file_path_file_dialog.hide()
@ -54,8 +62,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 +71,12 @@ func _on_theme_changed() -> void:
func _on_file_path_button_pressed() -> void:
file_path_file_dialog.popup_centered()
file_path_file_dialog.initial_path = config.current_timesheet_file_path
file_path_file_dialog.show()
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 +84,12 @@ func _on_sound_toggle(is_on: bool) -> void:
func _on_theme_path_button_pressed() -> void:
theme_path_file_dialog.popup_centered()
theme_path_file_dialog.initial_path = 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:

View File

@ -128,8 +128,10 @@ This game uses Godot Engine, available under the following license:
[node name="FilePathFileDialog" type="FileDialog" parent="CanvasLayer"]
unique_name_in_owner = true
anchor_right = 1.0
anchor_bottom = 1.0
visible = true
margin_top = 39.0
margin_right = 875.0
margin_bottom = 765.0
size_flags_horizontal = 3
size_flags_vertical = 3
window_title = "Pick a file"