load scene by state
This commit is contained in:
parent
810a3aa9b5
commit
d1992c62d9
|
@ -23,13 +23,13 @@ func _ready():
|
|||
var db_path = config.get_value("general", "db_path")
|
||||
load_db(db_path)
|
||||
|
||||
|
||||
func switch_state(new: State):
|
||||
var old = current_state
|
||||
if old == new:
|
||||
return
|
||||
|
||||
current_state = new
|
||||
emit_signal("state_changed", old, new)
|
||||
#signal state_changed(old, new)
|
||||
|
||||
func load_db(path: String):
|
||||
|
@ -38,8 +38,10 @@ func load_db(path: String):
|
|||
if success:
|
||||
config.set_value("general", "db_path", path)
|
||||
config.save(config_path)
|
||||
switch_state(State.LOADED)
|
||||
else:
|
||||
db.path = ""
|
||||
switch_state(State.UNLOADED)
|
||||
|
||||
func goto_scene(path):
|
||||
call_deferred("_deferred_goto_scene", path)
|
||||
|
|
7
godot/loaded.tscn
Normal file
7
godot/loaded.tscn
Normal file
|
@ -0,0 +1,7 @@
|
|||
[gd_scene format=3 uid="uid://h1sdn3cjclqi"]
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer"]
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Loaded !"
|
|
@ -6,6 +6,16 @@ func _ready():
|
|||
$FileDialog.access = FileDialog.ACCESS_FILESYSTEM
|
||||
$FileDialog.use_native_dialog = true
|
||||
|
||||
Global.state_changed.connect(_update_state)
|
||||
if Global.current_state == Global.State.UNLOADED:
|
||||
pass
|
||||
elif Global.current_state == Global.State.LOADED:
|
||||
$MarginContainer.remove_child($MarginContainer/Unloaded)
|
||||
var s = ResourceLoader.load("res://loaded.tscn")
|
||||
var current_scene = s.instantiate()
|
||||
$MarginContainer.add_child(current_scene)
|
||||
pass
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
@ -16,3 +26,7 @@ func _on_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
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://y5v0kmse8n10"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://y5v0kmse8n10"]
|
||||
|
||||
[ext_resource type="Script" path="res://main.gd" id="1_2tuu3"]
|
||||
[ext_resource type="PackedScene" uid="uid://b71wpb1vts86r" path="res://unloaded.tscn" id="2_diny5"]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
layout_mode = 3
|
||||
|
@ -24,15 +25,9 @@ grow_horizontal = 2
|
|||
grow_vertical = 2
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="MarginContainer"]
|
||||
[node name="Unloaded" parent="MarginContainer" instance=ExtResource("2_diny5")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Button" type="Button" parent="MarginContainer/CenterContainer"]
|
||||
custom_minimum_size = Vector2(200, 200)
|
||||
layout_mode = 2
|
||||
text = "Load database"
|
||||
|
||||
[node name="FileDialog" type="FileDialog" parent="."]
|
||||
|
||||
[connection signal="pressed" from="MarginContainer/CenterContainer/Button" to="." method="_on_button_pressed"]
|
||||
[connection signal="file_selected" from="FileDialog" to="." method="_on_file_dialog_file_selected"]
|
||||
|
|
8
godot/unloaded.tscn
Normal file
8
godot/unloaded.tscn
Normal file
|
@ -0,0 +1,8 @@
|
|||
[gd_scene format=3 uid="uid://b71wpb1vts86r"]
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer"]
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
custom_minimum_size = Vector2(200, 200)
|
||||
layout_mode = 2
|
||||
text = "Load database"
|
Loading…
Reference in a new issue