Introduce the abstract screen
This commit is contained in:
parent
64c6732a75
commit
ea40692f9a
30
Main.gd
30
Main.gd
|
@ -1,5 +1,35 @@
|
||||||
extends Node
|
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.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
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
|
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')
|
||||||
|
|
|
@ -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]
|
[ext_resource path="res://Main.gd" type="Script" id=3]
|
||||||
|
|
||||||
[node name="Main" type="Node"]
|
[node name="Main" type="Node"]
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="BattleScreen" parent="." instance=ExtResource( 1 )]
|
[node name="Screens" type="Control" parent="."]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
|
|
@ -10,6 +10,11 @@ config_version=4
|
||||||
|
|
||||||
_global_script_classes=[ {
|
_global_script_classes=[ {
|
||||||
"base": "Control",
|
"base": "Control",
|
||||||
|
"class": "AbstractScreen",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://screens/abstract_screen.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Control",
|
||||||
"class": "Gem",
|
"class": "Gem",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://entities/gem.gd"
|
"path": "res://entities/gem.gd"
|
||||||
|
@ -25,6 +30,7 @@ _global_script_classes=[ {
|
||||||
"path": "res://tools/random.gd"
|
"path": "res://tools/random.gd"
|
||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
|
"AbstractScreen": "",
|
||||||
"Gem": "",
|
"Gem": "",
|
||||||
"LogicalGrid": "",
|
"LogicalGrid": "",
|
||||||
"Random": ""
|
"Random": ""
|
||||||
|
|
|
@ -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()
|
|
@ -1,4 +1,4 @@
|
||||||
extends Control
|
extends AbstractScreen
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
|
@ -4,10 +4,8 @@
|
||||||
[ext_resource path="res://screens/battle_screen.gd" type="Script" id=2]
|
[ext_resource path="res://screens/battle_screen.gd" type="Script" id=2]
|
||||||
|
|
||||||
[node name="BattleScreen" type="Control"]
|
[node name="BattleScreen" type="Control"]
|
||||||
anchor_left = 0.5
|
anchor_right = 1.0
|
||||||
anchor_top = 0.5
|
anchor_bottom = 1.0
|
||||||
anchor_right = 0.5
|
|
||||||
anchor_bottom = 0.5
|
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="GemGrid" parent="." instance=ExtResource( 1 )]
|
[node name="GemGrid" parent="." instance=ExtResource( 1 )]
|
||||||
|
|
Loading…
Reference in New Issue