From b2c9bbf9a27095cd15d117cadfc772a59473a437 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 20 Dec 2023 22:41:41 +0100 Subject: [PATCH] move file dialog to unloaded scene --- godot/main.gd | 19 +------------------ godot/main.tscn | 4 ---- godot/unloaded.gd | 12 ++++++++++++ godot/unloaded.tscn | 10 +++++++++- 4 files changed, 22 insertions(+), 23 deletions(-) create mode 100644 godot/unloaded.gd diff --git a/godot/main.gd b/godot/main.gd index fcd7cba..159bd4a 100644 --- a/godot/main.gd +++ b/godot/main.gd @@ -2,12 +2,6 @@ extends Control # Called when the node enters the scene tree for the first time. func _ready(): - $FileDialog.mode = FileDialog.FILE_MODE_OPEN_FILE - $FileDialog.access = FileDialog.ACCESS_FILESYSTEM - $FileDialog.use_native_dialog = true - - $MarginContainer/Unloaded/Button.pressed.connect(_on_button_pressed) - Global.state_changed.connect(_update_state) if Global.current_state == Global.State.UNLOADED: pass @@ -17,17 +11,6 @@ func _ready(): var current_scene = s.instantiate() $MarginContainer.add_child(current_scene) -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - pass - -func _on_button_pressed(): - $FileDialog.show() - print("button pressed") - -func _on_file_dialog_file_selected(path): - Global.load_db(path) - func _update_state(old: Global.State, new: Global.State): print("updated state") - pass + diff --git a/godot/main.tscn b/godot/main.tscn index fb18b4a..791e64e 100644 --- a/godot/main.tscn +++ b/godot/main.tscn @@ -27,7 +27,3 @@ metadata/_edit_use_anchors_ = true [node name="Unloaded" parent="MarginContainer" instance=ExtResource("2_diny5")] layout_mode = 2 - -[node name="FileDialog" type="FileDialog" parent="."] - -[connection signal="file_selected" from="FileDialog" to="." method="_on_file_dialog_file_selected"] diff --git a/godot/unloaded.gd b/godot/unloaded.gd new file mode 100644 index 0000000..1930725 --- /dev/null +++ b/godot/unloaded.gd @@ -0,0 +1,12 @@ +extends CenterContainer + +func _ready(): + $FileDialog.mode = FileDialog.FILE_MODE_OPEN_FILE + $FileDialog.access = FileDialog.ACCESS_FILESYSTEM + $FileDialog.use_native_dialog = true + +func _on_button_pressed(): + $FileDialog.show() + +func _on_file_dialog_file_selected(path): + Global.load_db(path) diff --git a/godot/unloaded.tscn b/godot/unloaded.tscn index 62acad0..87f4a0c 100644 --- a/godot/unloaded.tscn +++ b/godot/unloaded.tscn @@ -1,8 +1,16 @@ -[gd_scene format=3 uid="uid://b71wpb1vts86r"] +[gd_scene load_steps=2 format=3 uid="uid://b71wpb1vts86r"] + +[ext_resource type="Script" path="res://unloaded.gd" id="1_ibvef"] [node name="CenterContainer" type="CenterContainer"] +script = ExtResource("1_ibvef") [node name="Button" type="Button" parent="."] custom_minimum_size = Vector2(200, 200) layout_mode = 2 text = "Load database" + +[node name="FileDialog" type="FileDialog" parent="."] + +[connection signal="pressed" from="Button" to="." method="_on_button_pressed"] +[connection signal="file_selected" from="FileDialog" to="." method="_on_file_dialog_file_selected"]