Introduce the abstract screen

This commit is contained in:
Feufochmar 2022-05-25 17:26:43 +02:00
parent 64c6732a75
commit ea40692f9a
6 changed files with 51 additions and 8 deletions

30
Main.gd
View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
extends Control
extends AbstractScreen
# Called when the node enters the scene tree for the first time.
func _ready():

View File

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