Update user interface to work with presenloader.gd
This commit is contained in:
parent
47f0e3ef53
commit
439ffba196
2 changed files with 103 additions and 10 deletions
|
@ -91,13 +91,13 @@ anchor_top = 0.5
|
|||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -179.0
|
||||
offset_top = -88.5
|
||||
offset_top = -113.5
|
||||
offset_right = 179.0
|
||||
offset_bottom = 88.5
|
||||
offset_bottom = 113.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Present" parent="Buttons" instance=ExtResource("6_xj8q1")]
|
||||
[node name="PresentZip" parent="Buttons" instance=ExtResource("6_xj8q1")]
|
||||
layout_mode = 1
|
||||
anchors_preset = 5
|
||||
anchor_left = 0.5
|
||||
|
@ -107,7 +107,20 @@ offset_left = -175.0
|
|||
offset_right = 175.0
|
||||
offset_bottom = 53.0
|
||||
grow_vertical = 1
|
||||
text = "[center]Open presentation[/center]"
|
||||
text = "[center]Open archive[/center]"
|
||||
|
||||
[node name="PresentDir" parent="Buttons" instance=ExtResource("6_xj8q1")]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -175.0
|
||||
offset_top = -55.5
|
||||
offset_right = 175.0
|
||||
offset_bottom = -2.5
|
||||
text = "[center]Open directory[/center]"
|
||||
|
||||
[node name="Docs" parent="Buttons" instance=ExtResource("6_xj8q1")]
|
||||
layout_mode = 1
|
||||
|
@ -117,9 +130,9 @@ anchor_top = 0.5
|
|||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -175.0
|
||||
offset_top = -26.5
|
||||
offset_top = 2.5
|
||||
offset_right = 175.0
|
||||
offset_bottom = 26.5
|
||||
offset_bottom = 55.5
|
||||
text = "[center]View documentation[/center]"
|
||||
|
||||
[node name="ClosePresencode" parent="Buttons" instance=ExtResource("6_xj8q1")]
|
||||
|
|
|
@ -5,6 +5,9 @@ var core_config: CoreConfiguration
|
|||
@onready var core: Core = get_node("/root/CORE")
|
||||
@onready var logger: CoreLoggerInstance = core.logger.get_instance("src/userinterface.gd", self)
|
||||
|
||||
# Internal infrastructure
|
||||
var presenloader: Node
|
||||
|
||||
# Variables
|
||||
var shutdown: bool = false
|
||||
var cleanup_hook: int
|
||||
|
@ -32,7 +35,8 @@ var splashes: Array[String] = [
|
|||
"xD",
|
||||
"Now in 2D!",
|
||||
"very bad",
|
||||
"beta and alpha males are overrated, i'm a release male"
|
||||
"beta and alpha males are overrated, i'm a release male",
|
||||
"uses .pcar files!"
|
||||
]
|
||||
|
||||
# Threads
|
||||
|
@ -99,12 +103,88 @@ func add_connections() -> void:
|
|||
$Splash/Switcher.connect("pressed", func() -> void: update_splash())
|
||||
|
||||
# Buttons
|
||||
$Buttons/Present.connect("pressed", func() -> void:
|
||||
logger.error("Not implemented.")
|
||||
)
|
||||
$Buttons/PresentZip.connect("pressed", Callable(self, "display_open_dialog").bind(false))
|
||||
$Buttons/PresentDir.connect("pressed", Callable(self, "display_open_dialog").bind(true))
|
||||
$Buttons/Docs.connect("pressed", func() -> void: OS.shell_open("https://presencode.jstm.staropensource.de"))
|
||||
$Buttons/ClosePresencode.connect("pressed", func() -> void: core.quit_safely(0))
|
||||
|
||||
func display_open_dialog(directory: bool) -> void:
|
||||
var file_dialog: FileDialog = FileDialog.new()
|
||||
|
||||
# AcceptDialog settings
|
||||
file_dialog.title = "Open a Presencode-compatible presentation"
|
||||
file_dialog.ok_button_text = "Load"
|
||||
file_dialog.visible = true
|
||||
|
||||
# ConfirmationDialog settings
|
||||
file_dialog.size = Vector2i(500, 500)
|
||||
file_dialog.min_size = Vector2i(250, 250)
|
||||
|
||||
# FileDialog settings
|
||||
file_dialog.access = FileDialog.Access.ACCESS_FILESYSTEM
|
||||
if directory: file_dialog.file_mode = FileDialog.FileMode.FILE_MODE_OPEN_DIR
|
||||
else: file_dialog.file_mode = FileDialog.FileMode.FILE_MODE_OPEN_FILE
|
||||
if !directory: file_dialog.filters = PackedStringArray([ "*.pcar ; Presencode Archives" ])
|
||||
file_dialog.mode_overrides_title = false
|
||||
file_dialog.show_hidden_files = false
|
||||
|
||||
# Add connections
|
||||
file_dialog.connect("file_selected", Callable(self, "handle_open_dialog_logic").bind(file_dialog))
|
||||
file_dialog.connect("dir_selected", Callable(self, "handle_open_dialog_logic").bind(file_dialog))
|
||||
file_dialog.connect("canceled", func() -> void:
|
||||
get_tree().root.remove_child(file_dialog)
|
||||
file_dialog.queue_free()
|
||||
)
|
||||
|
||||
# Display dialog
|
||||
get_tree().root.add_child(file_dialog)
|
||||
|
||||
# Center dialog
|
||||
# (we do this after add_child because FileDialog seems
|
||||
# to run some logic related to 'size' during _ready())
|
||||
file_dialog.position = core.misc.get_center(get_tree().root.size, file_dialog.size)
|
||||
|
||||
func handle_open_dialog_logic(path: String, file_dialog: FileDialog) -> void:
|
||||
# Remove dialog
|
||||
get_tree().root.remove_child(file_dialog)
|
||||
file_dialog.queue_free()
|
||||
|
||||
# Check if presentation is valid
|
||||
var error: String = presenloader.load_presentation(path)
|
||||
if error != "":
|
||||
# Display errors in dialog
|
||||
var error_dialog: AcceptDialog = AcceptDialog.new()
|
||||
|
||||
# Configure dialog
|
||||
error_dialog.title = "Can't load presentation"
|
||||
error_dialog.dialog_text = "Presencode is unable to load the presentation you tried to open.\nError thrown by presenloader.gd:\n" + error
|
||||
error_dialog.ok_button_text = "ACK"
|
||||
error_dialog.visible = true
|
||||
|
||||
# Add connections
|
||||
error_dialog.connect("confirmed", func() -> void:
|
||||
get_tree().root.remove_child(error_dialog)
|
||||
error_dialog.queue_free()
|
||||
)
|
||||
error_dialog.connect("canceled", func() -> void:
|
||||
get_tree().root.remove_child(error_dialog)
|
||||
error_dialog.queue_free()
|
||||
)
|
||||
|
||||
# Display dialog
|
||||
get_tree().root.add_child(error_dialog)
|
||||
|
||||
# Center dialog
|
||||
# (we do this after add_child because AcceptDialog seems
|
||||
# to run some logic related to 'size' during _ready())
|
||||
error_dialog.position = core.misc.get_center(get_tree().root.size, error_dialog.size)
|
||||
|
||||
# Don't unload the user interface, just exit
|
||||
return
|
||||
|
||||
# Unload user interface
|
||||
unload()
|
||||
|
||||
# Updates the splash text
|
||||
func update_splash() -> void:
|
||||
var new_splash: String = splashes.pick_random()
|
||||
|
|
Loading…
Reference in a new issue