use native dialogs

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

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Tomás Espejo Gómez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,9 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/native_dialogs/bin/native_dialogs.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "native_dialog_message"
class_name = "NativeDialogMessage"
library = ExtResource( 1 )
script_class_icon_path = "res://addons/native_dialogs/icons/native_dialog_message.png"

View File

@ -0,0 +1,9 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/native_dialogs/bin/native_dialogs.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "native_dialog_notify"
class_name = "NativeDialogNotify"
library = ExtResource( 1 )
script_class_icon_path = "res://addons/native_dialogs/icons/native_dialog_notify.png"

View File

@ -0,0 +1,9 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/native_dialogs/bin/native_dialogs.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "native_dialog_open_file"
class_name = "NativeDialogOpenFile"
library = ExtResource( 1 )
script_class_icon_path = "res://addons/native_dialogs/icons/native_dialog_open_file.png"

View File

@ -0,0 +1,9 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/native_dialogs/bin/native_dialogs.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "native_dialog_save_file"
class_name = "NativeDialogSaveFile"
library = ExtResource( 1 )
script_class_icon_path = "res://addons/native_dialogs/icons/native_dialog_save_file.png"

View File

@ -0,0 +1,9 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/native_dialogs/bin/native_dialogs.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "native_dialog_select_folder"
class_name = "NativeDialogSelectFolder"
library = ExtResource( 1 )
script_class_icon_path = "res://addons/native_dialogs/icons/native_dialog_select_folder.png"

View File

@ -0,0 +1,18 @@
[general]
singleton=false
load_once=true
symbol_prefix="godot_"
reloadable=false
[entry]
X11.64="res://addons/native_dialogs/bin/x11/libnativedialogs.so"
Windows.64="res://addons/native_dialogs/bin/win64/libnativedialogs.dll"
OSX.64="res://addons/native_dialogs/bin/osx/libnativedialogs.dylib"
[dependencies]
X11.64=[ ]
Windows.64=[ ]
OSX.64=[ ]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/native_dialog_message.png-d3a3788b812cbdd538caffc1bd4f6303.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/native_dialogs/icons/native_dialog_message.png"
dest_files=[ "res://.import/native_dialog_message.png-d3a3788b812cbdd538caffc1bd4f6303.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/native_dialog_notify.png-5ccb03b82c726e402d1ee63705cdfce9.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/native_dialogs/icons/native_dialog_notify.png"
dest_files=[ "res://.import/native_dialog_notify.png-5ccb03b82c726e402d1ee63705cdfce9.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/native_dialog_open_file.png-94d31b95f481d556dcb2679a4986fc3e.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/native_dialogs/icons/native_dialog_open_file.png"
dest_files=[ "res://.import/native_dialog_open_file.png-94d31b95f481d556dcb2679a4986fc3e.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/native_dialog_save_file.png-488c5f5500af041c2ce0b2fc9836df36.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/native_dialogs/icons/native_dialog_save_file.png"
dest_files=[ "res://.import/native_dialog_save_file.png-488c5f5500af041c2ce0b2fc9836df36.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/native_dialog_select_folder.png-38710e428d30ce3e92fad43e6141022e.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/native_dialogs/icons/native_dialog_select_folder.png"
dest_files=[ "res://.import/native_dialog_select_folder.png-38710e428d30ce3e92fad43e6141022e.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -0,0 +1,11 @@
const Message = preload("./bin/native_dialog_message.gdns")
const Notify = preload("./bin/native_dialog_notify.gdns")
const OpenFile = preload("./bin/native_dialog_open_file.gdns")
const SaveFile = preload("./bin/native_dialog_save_file.gdns")
const SelectFolder = preload("./bin/native_dialog_select_folder.gdns")
enum MessageChoices { OK, OK_CANCEL, YES_NO, YES_NO_CANCEL }
enum MessageIcons { INFO, WARNING, ERROR, QUESTION }
enum MessageResults { OK, CANCEL, YES, NO }
enum NotifyIcons { INFO, WARNING, ERROR }

View File

@ -0,0 +1,7 @@
[plugin]
name="Native Dialogs"
description="Native Dialogs is a plugin for Godot that allows you to interact with OS-specific dialogs, such as notifications, messages and file dialogs. "
author="Teggy"
version="1.0.0"
script="plugin.gd"

View File

@ -0,0 +1,50 @@
tool
extends EditorPlugin
const NativeDialogs = preload("./native_dialogs.gd")
func _enter_tree():
add_custom_type(
"NativeDialogMessage",
"Node",
NativeDialogs.Message,
preload("./icons/native_dialog_message.png")
)
add_custom_type(
"NativeDialogNotify",
"Node",
NativeDialogs.Notify,
preload("./icons/native_dialog_notify.png")
)
add_custom_type(
"NativeDialogOpenFile",
"Node",
NativeDialogs.OpenFile,
preload("./icons/native_dialog_open_file.png")
)
add_custom_type(
"NativeDialogSaveFile",
"Node",
NativeDialogs.SaveFile,
preload("./icons/native_dialog_save_file.png")
)
add_custom_type(
"NativeDialogSelectFolder",
"Node",
NativeDialogs.SelectFolder,
preload("./icons/native_dialog_select_folder.png")
)
func _exit_tree():
remove_custom_type("NativeDialogMessage")
remove_custom_type("NativeDialogNotify")
remove_custom_type("NativeDialogOpenFile")
remove_custom_type("NativeDialogSaveFile")
remove_custom_type("NativeDialogSelectFolder")

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"
[editor_plugins]
enabled=PoolStringArray( "res://addons/native_dialogs/plugin.cfg" )
[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

@ -2,6 +2,8 @@ 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 := $"%FilePathLineEdit" as LineEdit onready var file_path_line_edit := $"%FilePathLineEdit" as LineEdit
onready var file_path_button := $"%FilePathButton" as Button onready var file_path_button := $"%FilePathButton" as Button
onready var theme_path_button := $"%ThemePathButton" 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 open_data_dir_button := $"%OpenDataDirButton" as Button
onready var file_path_open_button := $"%FilePathOpenButton" as Button onready var file_path_open_button := $"%FilePathOpenButton" as Button
onready var attributions_rich_text_label := $"%AttributionsRichTextLabel" as RichTextLabel onready var attributions_rich_text_label := $"%AttributionsRichTextLabel" as RichTextLabel
onready var file_path_file_dialog := $"%FilePathFileDialog" as FileDialog var file_path_file_dialog := NativeDialogs.SaveFile.new()
onready var theme_path_file_dialog := $"%ThemePathFileDialog" as FileDialog var theme_path_file_dialog := NativeDialogs.OpenFile.new()
func _ready() -> void: func _ready() -> void:
@ -24,16 +26,22 @@ 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"]
file_path_file_dialog.force_overwrite = true
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")
# 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")
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("file_selected", self, "_on_new_theme_selected") theme_path_file_dialog.connect("files_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()
@ -54,8 +62,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 +71,12 @@ 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() 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: 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 +84,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() 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: 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:

View File

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