diverses bidouilles.
This commit is contained in:
parent
16b93154c2
commit
a51a504575
3 changed files with 23 additions and 26 deletions
45
global.gd
45
global.gd
|
@ -18,6 +18,8 @@ var old_scene = null
|
||||||
var parent_scene = null
|
var parent_scene = null
|
||||||
var current_map = null
|
var current_map = null
|
||||||
|
|
||||||
|
var current_state = "login"
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var root = get_tree().get_root()
|
var root = get_tree().get_root()
|
||||||
# current_scene = root.get_child(root.get_child_count() -1)
|
# current_scene = root.get_child(root.get_child_count() -1)
|
||||||
|
@ -51,28 +53,26 @@ func change_title():
|
||||||
########
|
########
|
||||||
#### change level
|
#### change level
|
||||||
func unload_scene( scene ):
|
func unload_scene( scene ):
|
||||||
print("unload_scene: "+str(scene.name))
|
|
||||||
scene.queue_free()
|
scene.queue_free()
|
||||||
|
|
||||||
func load_scene( scene_path ):
|
func load_scene( scene_path ):
|
||||||
print("load_scene: "+str(scene_path))
|
|
||||||
loader = ResourceLoader.load_interactive( scene_path )
|
loader = ResourceLoader.load_interactive( scene_path )
|
||||||
if loader == null: # check for errors
|
if loader == null: # check for errors
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func change_level( p_next_scene_path, p_parent_next_scene = null, p_old_scene = null ):
|
func change_level( p_next_state, p_next_scene_path, p_parent_next_scene = null, p_old_scene = null ):
|
||||||
character.hide()
|
character.hide()
|
||||||
get_node("background_loader").show()
|
get_node("background_loader").show()
|
||||||
|
|
||||||
print()
|
# print()
|
||||||
print( "change_level: " )
|
# print( "change_level: " )
|
||||||
if p_old_scene:
|
# if p_old_scene:
|
||||||
print( "from "+p_old_scene.name )
|
# print( "from "+p_old_scene.name )
|
||||||
print( "to "+str(p_next_scene_path) )
|
# print( "to "+str(p_next_scene_path) )
|
||||||
if p_parent_next_scene:
|
# if p_parent_next_scene:
|
||||||
print( " on "+ str(p_parent_next_scene.name) )
|
# print( " on "+ str(p_parent_next_scene.name) )
|
||||||
print()
|
# print()
|
||||||
|
|
||||||
if not load_scene( p_next_scene_path ):
|
if not load_scene( p_next_scene_path ):
|
||||||
show_error()
|
show_error()
|
||||||
|
@ -85,12 +85,11 @@ func change_level( p_next_scene_path, p_parent_next_scene = null, p_old_scene =
|
||||||
unload_scene( old_scene )
|
unload_scene( old_scene )
|
||||||
|
|
||||||
wait_frames = 1
|
wait_frames = 1
|
||||||
|
self.current_state = p_next_state
|
||||||
########
|
########
|
||||||
|
|
||||||
|
|
||||||
func _process( time ):
|
func _process( time ):
|
||||||
print("process1")
|
|
||||||
########
|
########
|
||||||
#### LOADER
|
#### LOADER
|
||||||
if loader == null:
|
if loader == null:
|
||||||
|
@ -98,12 +97,10 @@ func _process( time ):
|
||||||
set_process(false)
|
set_process(false)
|
||||||
return
|
return
|
||||||
|
|
||||||
print("process2")
|
|
||||||
if wait_frames > 0: # wait for frames to let the "loading" animation to show up
|
if wait_frames > 0: # wait for frames to let the "loading" animation to show up
|
||||||
wait_frames -= 1
|
wait_frames -= 1
|
||||||
return
|
return
|
||||||
|
|
||||||
print("process3")
|
|
||||||
var t = OS.get_ticks_msec()
|
var t = OS.get_ticks_msec()
|
||||||
while OS.get_ticks_msec() < t + time_max: # use "time_max" to control how much time we block this thread
|
while OS.get_ticks_msec() < t + time_max: # use "time_max" to control how much time we block this thread
|
||||||
# poll your loader
|
# poll your loader
|
||||||
|
@ -124,17 +121,17 @@ func _process( time ):
|
||||||
loader = null
|
loader = null
|
||||||
break
|
break
|
||||||
########
|
########
|
||||||
print("process4")
|
|
||||||
|
|
||||||
func _input( event ):
|
func _input( event ):
|
||||||
|
|
||||||
if event is InputEventKey and not event.is_echo():
|
if current_state == "game" and event is InputEventKey and not event.is_echo():
|
||||||
if event.is_action_pressed("test_change_map_1"):
|
if event.is_action_pressed("test_change_map_1"):
|
||||||
global.change_level( "res://test_scene/test_scene.tscn", null, current_map )
|
global.change_level( "game", "res://test_scene/test_scene.tscn", null, current_map )
|
||||||
elif event.is_action_pressed("test_change_map_2"):
|
elif event.is_action_pressed("test_change_map_2"):
|
||||||
global.change_level( "res://test_grid_map/test_grid_map.tscn", null, current_map )
|
global.change_level( "game", "res://test_grid_map/test_grid_map.tscn", null, current_map )
|
||||||
elif event.is_action_pressed("test_change_map_3"):
|
elif event.is_action_pressed("test_change_map_3"):
|
||||||
global.change_level( "res://game_scene/game_scene.tscn", null, current_map )
|
global.change_level( "game", "res://game_scene/game_scene.tscn", null, current_map )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,15 +165,15 @@ func _on_login_scene_character_creation_finished():
|
||||||
if err:
|
if err:
|
||||||
print("Error code when loading config file: ", err)
|
print("Error code when loading config file: ", err)
|
||||||
|
|
||||||
config_file.set_value(str(global.character_slot), "name", global.character_name)
|
config_file.set_value(str(self.character_slot), "name", self.character_name)
|
||||||
config_file.set_value(str(global.character_slot), "color", global.character_color)
|
config_file.set_value(str(self.character_slot), "color", self.character_color)
|
||||||
|
|
||||||
config_file.save( "user://player.cfg" )
|
config_file.save( "user://player.cfg" )
|
||||||
global.change_level( "res://game_scene/game_scene.tscn", null, get_tree().get_root().get_node("login_scene") )
|
self.change_level( "game", "res://game_scene/game_scene.tscn", null, get_tree().get_root().get_node("login_scene") )
|
||||||
character.show_third_person_camera()
|
character.show_third_person_camera()
|
||||||
# character.get_node( "infos_spatial" ).show()
|
# character.get_node( "infos_spatial" ).show()
|
||||||
|
|
||||||
func _on_logout_button_pressed():
|
func _on_logout_button_pressed():
|
||||||
global.change_level( "res://login_scene/login_scene.tscn", null, current_map )
|
self.change_level( "login", "res://login_scene/login_scene.tscn", null, current_map )
|
||||||
get_tree().paused = false
|
get_tree().paused = false
|
||||||
########
|
########
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
[ext_resource path="res://global.gd" type="Script" id=1]
|
[ext_resource path="res://global.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://background_loader_scene/background_loader.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://background_loader_scene/background_loader.tscn" type="PackedScene" id=2]
|
||||||
|
|
||||||
[node name="global" type="Node"]
|
[node name="global" type="Node" index="0"]
|
||||||
|
|
||||||
pause_mode = 2
|
pause_mode = 2
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
|
@ -19,7 +19,7 @@ _sections_unfolded = [ "Font", "Settings" ]
|
||||||
|
|
||||||
default_font = SubResource( 1 )
|
default_font = SubResource( 1 )
|
||||||
|
|
||||||
[node name="GUI" type="MarginContainer"]
|
[node name="GUI" type="MarginContainer" index="0"]
|
||||||
|
|
||||||
pause_mode = 2
|
pause_mode = 2
|
||||||
anchor_left = 0.0
|
anchor_left = 0.0
|
||||||
|
|
Loading…
Reference in a new issue