diff --git a/godot_ship/project.godot b/godot_ship/project.godot index aa0c1d4..551e31a 100644 --- a/godot_ship/project.godot +++ b/godot_ship/project.godot @@ -14,6 +14,10 @@ config/name="godot_ship" run/main_scene="res://scenes/Main.tscn" config/icon="res://icon.png" +[autoload] + +MessageBus="*res://script/game/Message Bus.gd" + [display] window/size/width=640 diff --git a/godot_ship/scenes/Main.tscn b/godot_ship/scenes/Main.tscn index 3dd2b98..d8abbd4 100644 --- a/godot_ship/scenes/Main.tscn +++ b/godot_ship/scenes/Main.tscn @@ -1,21 +1,11 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=2 format=2] -[ext_resource path="res://scenes/Debug Menu.tscn" type="PackedScene" id=1] -[ext_resource path="res://scenes/Gameplay.tscn" type="PackedScene" id=2] -[ext_resource path="res://scenes/Title Screen.tscn" type="PackedScene" id=3] -[ext_resource path="res://scenes/Options.tscn" type="PackedScene" id=4] +[ext_resource path="res://script/game/Main.gd" type="Script" id=5] [node name="Root" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 +script = ExtResource( 5 ) __meta__ = { "_edit_use_anchors_": false } - -[node name="Title Screen" parent="." instance=ExtResource( 3 )] - -[node name="Game" parent="." instance=ExtResource( 2 )] - -[node name="Options" parent="." instance=ExtResource( 4 )] - -[node name="Debug Menu" parent="." instance=ExtResource( 1 )] diff --git a/godot_ship/script/debug/debug_menu.gd b/godot_ship/script/debug/debug_menu.gd index 926cc8d..502ab47 100644 --- a/godot_ship/script/debug/debug_menu.gd +++ b/godot_ship/script/debug/debug_menu.gd @@ -16,7 +16,6 @@ var menu_active = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0, 0)) func _ready(): debug_canvas = get_node("debug_canvas") debug_transform = debug_canvas.get_transform() - return # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): @@ -33,3 +32,9 @@ func _unhandled_input(event): if event.is_action_pressed("ui_debug"): # open debug menu debug_active = !debug_active; + + + +func _on_LineEdit_text_entered(new_text): + + pass # Replace with function body. diff --git a/godot_ship/script/game/Main.gd b/godot_ship/script/game/Main.gd new file mode 100644 index 0000000..86ee2c2 --- /dev/null +++ b/godot_ship/script/game/Main.gd @@ -0,0 +1,41 @@ +extends Control + +# Scenes +var title_screen +var gameplay +var options +var debug_menu + +var debug_enabled = true + +# Called when the node enters the scene tree for the first time. +func _ready(): + # Connect to signals + MessageBus.connect("change_scene", self, "_on_change_scene") + MessageBus.connect("quit", self, "_on_quit_request") + MessageBus.connect("return_to_title", self, "_on_title_request") + # Create the scenes + title_screen = preload("res://scenes/Title Screen.tscn") + gameplay = preload("res://scenes/Gameplay.tscn") + options = preload("res://scenes/Options.tscn") + debug_menu = preload("res://scenes/Debug Menu.tscn") + if (debug_enabled): + add_child(debug_menu.instance()) + _on_change_scene("Title") + +func _on_change_scene(scene): + match scene: + "Singleplayer": + add_child(gameplay.instance()) + "Multiplayer": + add_child(gameplay.instance()) + "Options": + add_child(options.instance()) + "Title": + add_child(title_screen.instance()) + +func _on_quit_request(): + get_tree().quit() + +func _on_title_request(): + get_tree().change_scene("res://scenes/Options.tscn") diff --git a/godot_ship/script/game/Message Bus.gd b/godot_ship/script/game/Message Bus.gd new file mode 100644 index 0000000..336cc10 --- /dev/null +++ b/godot_ship/script/game/Message Bus.gd @@ -0,0 +1,8 @@ +extends Node + +# Ask for a scene change +signal change_scene(scene_name) +# Ask to quit the game +signal quit +# Ask to return to title screen +signal return_to_title diff --git a/godot_ship/script/title screen/Title Screen.gd b/godot_ship/script/title screen/Title Screen.gd index 51d6f25..cc83a11 100644 --- a/godot_ship/script/title screen/Title Screen.gd +++ b/godot_ship/script/title screen/Title Screen.gd @@ -1,9 +1,7 @@ extends Control -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" +# Declare member variables here: # Called when the node enters the scene tree for the first time. @@ -17,13 +15,17 @@ func _ready(): func _on_Singleplayer_pressed(): - get_tree().change_scene("res://scenes/Gameplay.tscn") + #get_tree().change_scene("res://scenes/Gameplay.tscn") + MessageBus.emit_signal("change_scene", "Singleplayer") func _on_Multiplayer_pressed(): - get_tree().change_scene("res://scenes/Gameplay.tscn") + #get_tree().change_scene("res://scenes/Gameplay.tscn") + MessageBus.emit_signal("change_scene", "Multiplayer") func _on_Options_pressed(): - get_tree().change_scene("res://scenes/Options.tscn") + #get_tree().change_scene("res://scenes/Options.tscn") + MessageBus.emit_signal("change_scene", "Options") func _on_Quit_pressed(): - get_tree().quit() + #get_tree().quit() + MessageBus.emit_signal("quit")