move file dialog to unloaded scene

This commit is contained in:
Fabien Freling 2023-12-20 22:41:41 +01:00
parent 8b1fe0a9be
commit b2c9bbf9a2
4 changed files with 22 additions and 23 deletions

View file

@ -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

View file

@ -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"]

12
godot/unloaded.gd Normal file
View file

@ -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)

View file

@ -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"]