diff --git a/Main.gd b/Main.gd index a39023d..0e3eae1 100644 --- a/Main.gd +++ b/Main.gd @@ -1,5 +1,35 @@ extends Node +# The main scene manages the displayed screens +const BattleScreen = preload("res://screens/battle_screen.tscn") + +# Variables +# The stack of screens. All are displayed one above the others. +var screens: Array = [] +var current_screen: String + # Called when the node enters the scene tree for the first time. func _ready(): + go_to_battle_screen() + +# Function to change screen +func on_next_screen(screen: String): + match screen: + 'battle': + go_to_battle_screen() +# Function to leave current screen +func on_leave_screen(): pass + +# Common screen management +func go_to_screen(type, name): + current_screen = name + var scr = type.instance() + scr.connect("next_screen", self, "on_next_screen") + scr.connect("leave_screen", self, "on_leave_screen") + screens.push_back(scr) + $Screens.add_child(scr) + +# Screen transitions +func go_to_battle_screen(): + go_to_screen(BattleScreen, 'battle') diff --git a/Main.tscn b/Main.tscn index e31d31c..e539fcf 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] -[ext_resource path="res://screens/battle_screen.tscn" type="PackedScene" id=1] [ext_resource path="res://Main.gd" type="Script" id=3] [node name="Main" type="Node"] script = ExtResource( 3 ) -[node name="BattleScreen" parent="." instance=ExtResource( 1 )] +[node name="Screens" type="Control" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 diff --git a/project.godot b/project.godot index 3be8ba8..bc97555 100644 --- a/project.godot +++ b/project.godot @@ -10,6 +10,11 @@ config_version=4 _global_script_classes=[ { "base": "Control", +"class": "AbstractScreen", +"language": "GDScript", +"path": "res://screens/abstract_screen.gd" +}, { +"base": "Control", "class": "Gem", "language": "GDScript", "path": "res://entities/gem.gd" @@ -25,6 +30,7 @@ _global_script_classes=[ { "path": "res://tools/random.gd" } ] _global_script_class_icons={ +"AbstractScreen": "", "Gem": "", "LogicalGrid": "", "Random": "" diff --git a/screens/abstract_screen.gd b/screens/abstract_screen.gd new file mode 100644 index 0000000..12ab69b --- /dev/null +++ b/screens/abstract_screen.gd @@ -0,0 +1,8 @@ +class_name AbstractScreen +extends Control + +# Abstract screen, only for definition of signals +# Go to a given screen +signal next_screen(screen_name) +# Exit current screen +signal leave_screen() diff --git a/screens/battle_screen.gd b/screens/battle_screen.gd index 3f94aa0..74ebd1d 100644 --- a/screens/battle_screen.gd +++ b/screens/battle_screen.gd @@ -1,4 +1,4 @@ -extends Control +extends AbstractScreen # Called when the node enters the scene tree for the first time. func _ready(): diff --git a/screens/battle_screen.tscn b/screens/battle_screen.tscn index a444d7c..305bce6 100644 --- a/screens/battle_screen.tscn +++ b/screens/battle_screen.tscn @@ -4,10 +4,8 @@ [ext_resource path="res://screens/battle_screen.gd" type="Script" id=2] [node name="BattleScreen" type="Control"] -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 +anchor_right = 1.0 +anchor_bottom = 1.0 script = ExtResource( 2 ) [node name="GemGrid" parent="." instance=ExtResource( 1 )]