ajout d'un systeme de chargement de scene via un script autoload.

This commit is contained in:
osquallo 2018-08-07 10:18:26 +02:00
parent 927753f6d1
commit 19c605ab0c
8 changed files with 157 additions and 82 deletions

42
game_scene/game_scene.gd Normal file
View file

@ -0,0 +1,42 @@
extends Node
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
const WINDOW_TITLE_INPUT = "GUI/Settings/Menus/TabContainer/Test/ScrollContainer/VBoxContainer/TitleBox/Title"
func _ready():
change_title()
get_tree().get_root().connect("size_changed", self, "on_window_size_changed")
global.character = get_node( "Game/Character" )
global.character_camera = get_node( "Game/Character/Camera_rotation_helper/Camera" )
$GUI.pause()
global.character_camera.make_current()
# $Game.hide()
#
# # BugGodot?: Meme si tous les nodes parent sont caché les gridmaps s'affichent quand meme :/
# # ce qui les rends quelque peu inutilisables.
# $Game/World/GridMaps/Ground.hide()
# $Game/World/GridMaps/wall.hide()
# $Game/World/GridMaps/ceilling.hide()
get_tree().get_root().print_tree_pretty()
func _process(delta):
pass
func on_window_size_changed():
change_title()
func change_title():
var title_node = get_node( WINDOW_TITLE_INPUT )
var title = "Khanat"
if title_node and not title_node.text.strip_edges() == "":
title = title_node.text.strip_edges()
title += " (" + String(OS.get_window_size().x) + "x" + String(OS.get_window_size().y) + ")"
OS.set_window_title( title )

View file

@ -0,0 +1,19 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://game_scene/game_scene.gd" type="Script" id=1]
[ext_resource path="res://scenes/Game/Game.tscn" type="PackedScene" id=2]
[ext_resource path="res://scenes/GUI/GUI.tscn" type="PackedScene" id=3]
[node name="game_scene" type="Node"]
script = ExtResource( 1 )
_sections_unfolded = [ "Pause" ]
[node name="Game" parent="." index="0" instance=ExtResource( 2 )]
[node name="GUI" parent="." index="1" instance=ExtResource( 3 )]
pause_mode = 2
_sections_unfolded = [ "Margin", "Mouse", "Pause", "Size Flags", "Theme", "custom_constants" ]

View file

@ -0,0 +1,33 @@
extends Node
signal character_creation_finished
func _ready():
global.character_creation_camera = get_node( "character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/camera" )
get_tree().get_root().print_tree_pretty()
func _on_login_menu_login_button_pressed():
$login_menu.hide()
$character_selection_menu.show()
func _on_character_creation_menu_valid_button_pressed():
$character_creation_menu.hide()
emit_signal( "character_creation_finished" )
func _on_character_selection_menu_character_selected(slot):
print( "selected character slot "+str( slot )+"." )
$character_selection_menu.hide()
$character_creation_menu.show()
func _on_character_creation_menu_return_button_pressed():
$character_creation_menu.hide()
$character_selection_menu.show()
func _on_character_selection_menu_return_button_pressed():
$login_menu.show()
$character_selection_menu.hide()

View file

@ -0,0 +1,32 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://login_scene/login_scene.gd" type="Script" id=1]
[ext_resource path="res://scenes/GUI/character_creation/character_creation_menu.tscn" type="PackedScene" id=2]
[ext_resource path="res://scenes/GUI/character_selection/character_selection_menu.tscn" type="PackedScene" id=3]
[ext_resource path="res://scenes/GUI/login/login_menu.tscn" type="PackedScene" id=4]
[node name="login_scene" type="Node" index="0"]
script = ExtResource( 1 )
[node name="character_creation_menu" parent="." index="0" instance=ExtResource( 2 )]
visible = false
[node name="character_selection_menu" parent="." index="1" instance=ExtResource( 3 )]
visible = false
[node name="login_menu" parent="." index="2" instance=ExtResource( 4 )]
[connection signal="return_button_pressed" from="character_creation_menu" to="." method="_on_character_creation_menu_return_button_pressed"]
[connection signal="valid_button_pressed" from="character_creation_menu" to="." method="_on_character_creation_menu_valid_button_pressed"]
[connection signal="character_selected" from="character_selection_menu" to="." method="_on_character_selection_menu_character_selected"]
[connection signal="return_button_pressed" from="character_selection_menu" to="." method="_on_character_selection_menu_return_button_pressed"]
[connection signal="login_button_pressed" from="login_menu" to="." method="_on_login_menu_login_button_pressed"]

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://scenes/GUI/GUI.gd" type="Script" id=1]
[ext_resource path="res://scenes/GUI/HUD/HUD.tscn" type="PackedScene" id=2]
@ -6,9 +6,6 @@
[ext_resource path="res://scenes/GUI/Home/Home.tscn" type="PackedScene" id=4]
[ext_resource path="res://scenes/GUI/Settings/Settings.tscn" type="PackedScene" id=5]
[ext_resource path="res://scenes/GUI/Help/Help.tscn" type="PackedScene" id=6]
[ext_resource path="res://scenes/GUI/character_creation/character_creation_menu.tscn" type="PackedScene" id=7]
[ext_resource path="res://scenes/GUI/character_selection/character_selection_menu.tscn" type="PackedScene" id=8]
[ext_resource path="res://scenes/GUI/login/login_menu.tscn" type="PackedScene" id=9]
[sub_resource type="DynamicFont" id=1]
@ -22,7 +19,7 @@ _sections_unfolded = [ "Font", "Settings" ]
default_font = SubResource( 1 )
[node name="GUI" type="MarginContainer" index="0"]
[node name="GUI" type="MarginContainer"]
anchor_left = 0.0
anchor_top = 0.0
@ -43,7 +40,6 @@ _sections_unfolded = [ "Margin", "Mouse", "Size Flags", "Theme", "custom_constan
[node name="HUD" parent="." index="0" instance=ExtResource( 2 )]
visible = false
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1024.0
@ -52,7 +48,6 @@ theme = SubResource( 2 )
[node name="Home" parent="." index="1" instance=ExtResource( 4 )]
visible = false
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1024.0
@ -77,29 +72,6 @@ margin_right = 256.0
margin_bottom = 256.0
_sections_unfolded = [ "Margin", "Mouse", "Size Flags", "custom_constants" ]
[node name="character_creation_menu" parent="." index="4" instance=ExtResource( 7 )]
visible = false
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1024.0
margin_bottom = 600.0
[node name="character_selection_menu" parent="." index="5" instance=ExtResource( 8 )]
visible = false
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1024.0
margin_bottom = 600.0
[node name="login_menu" parent="." index="6" instance=ExtResource( 9 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1024.0
margin_bottom = 600.0
[connection signal="play_pressed" from="Home" to="." method="_on_Home_play_pressed"]
[connection signal="setting_pressed" from="Home" to="." method="_on_Home_setting_pressed"]
@ -108,14 +80,4 @@ margin_bottom = 600.0
[connection signal="return_pressed" from="Settings" to="." method="_on_Settings_return_pressed"]
[connection signal="return_button_pressed" from="character_creation_menu" to="." method="_on_character_creation_menu_return_button_pressed"]
[connection signal="valid_button_pressed" from="character_creation_menu" to="." method="_on_character_creation_menu_valid_button_pressed"]
[connection signal="character_selected" from="character_selection_menu" to="." method="_on_character_selection_menu_character_selected"]
[connection signal="return_button_pressed" from="character_selection_menu" to="." method="_on_character_selection_menu_return_button_pressed"]
[connection signal="login_button_pressed" from="login_menu" to="." method="_on_login_menu_login_button_pressed"]

View file

@ -10,15 +10,8 @@ func _ready():
change_title()
get_tree().get_root().connect("size_changed", self, "on_window_size_changed")
# $GUI.pause()
global.character_creation_camera.make_current()
$Game.hide()
# BugGodot?: Meme si tous les nodes parent sont caché les gridmaps s'affichent quand meme :/
# ce qui les rends quelque peu inutilisables.
$Game/World/GridMaps/Ground.hide()
$Game/World/GridMaps/wall.hide()
$Game/World/GridMaps/ceilling.hide()
func _process(delta):
@ -35,11 +28,15 @@ func change_title():
title += " (" + String(OS.get_window_size().x) + "x" + String(OS.get_window_size().y) + ")"
OS.set_window_title( title )
func _on_GUI_character_creation_finished():
$Game.show()
$Game/World/GridMaps/Ground.show()
$Game/World/GridMaps/wall.show()
$Game/World/GridMaps/ceilling.show()
global.character_camera.make_current()
$GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene.hide()
$Game/Character/MeshInstance.get_surface_material(0).albedo_color = $GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/mesh_instance.get_surface_material(0).albedo_color
#func _on_GUI_character_creation_finished():
# $Game.show()
# $Game/World/GridMaps/Ground.show()
# $Game/World/GridMaps/wall.show()
# $Game/World/GridMaps/ceilling.show()
# global.character_camera.make_current()
# $GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene.hide()
# $Game/Character/MeshInstance.get_surface_material(0).albedo_color = $GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/mesh_instance.get_surface_material(0).albedo_color
func _on_login_scene_character_creation_finished():
global.goto_scene( "res://game_scene/game_scene.tscn", "Main" )

View file

@ -1,25 +1,15 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://scenes/Main.gd" type="Script" id=1]
[ext_resource path="res://scenes/Game/Game.tscn" type="PackedScene" id=2]
[ext_resource path="res://scenes/GUI/GUI.tscn" type="PackedScene" id=3]
[ext_resource path="res://login_scene/login_scene.tscn" type="PackedScene" id=2]
[node name="Main" type="Node" index="0"]
[node name="Main" type="Node"]
script = ExtResource( 1 )
_sections_unfolded = [ "Pause" ]
[node name="Game" parent="." index="0" instance=ExtResource( 2 )]
[node name="login_scene" parent="." index="0" instance=ExtResource( 2 )]
visible = false
[node name="GUI" parent="." index="1" instance=ExtResource( 3 )]
pause_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
_sections_unfolded = [ "Margin", "Mouse", "Pause", "Size Flags", "Theme", "custom_constants" ]
[connection signal="character_creation_finished" from="GUI" to="." method="_on_GUI_character_creation_finished"]
[connection signal="character_creation_finished" from="login_scene" to="." method="_on_login_scene_character_creation_finished"]

View file

@ -7,13 +7,13 @@ var character_creation_camera = null
func _ready():
var root = get_tree().get_root()
current_scene = root.get_child(root.get_child_count() -1)
character = get_tree().get_root().get_node( "Main/Game/Character" )
character_camera = get_tree().get_root().get_node( "Main/Game/Character/Camera_rotation_helper/Camera" )
character_creation_camera = get_tree().get_root().get_node( "Main/GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/camera" )
# current_scene = root.get_child(root.get_child_count() -1)
current_scene = root.get_node( "Main/login_scene" )
# character = get_tree().get_root().get_node( "Main/Game/Character" )
# character_camera = get_tree().get_root().get_node( "Main/Game/Character/Camera_rotation_helper/Camera" )
# character_creation_camera = get_tree().get_root().get_node( "Main/login_scene/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/camera" )
func goto_scene(path):
func goto_scene(path, parent):
# This function will usually be called from a signal callback,
# or some other function from the running scene.
# Deleting the current scene at this point might be
@ -23,22 +23,22 @@ func goto_scene(path):
# The way around this is deferring the load to a later time, when
# it is ensured that no code from the current scene is running:
call_deferred("_deferred_goto_scene", path)
call_deferred("_deferred_goto_scene", path, parent)
func _deferred_goto_scene(path):
func _deferred_goto_scene(path, parent):
# Immediately free the current scene,
# there is no risk here.
current_scene.free()
# Load new scene.
var s = ResourceLoader.load(path)
var s = ResourceLoader.load( path )
# Instance the new scene.
current_scene = s.instance()
# Add it to the active scene, as child of root.
get_tree().get_root().add_child(current_scene)
get_tree().get_root().get_node( parent ).add_child( current_scene )
# Optional, to make it compatible with the SceneTree.change_scene() API.
get_tree().set_current_scene(current_scene)
get_tree().set_current_scene( current_scene )