diff --git a/global.gd b/global.gd index f72b7e1..b0af53c 100644 --- a/global.gd +++ b/global.gd @@ -18,6 +18,8 @@ var old_scene = null var parent_scene = null var current_map = null +var current_state = "login" + func _ready(): var root = get_tree().get_root() # current_scene = root.get_child(root.get_child_count() -1) @@ -51,28 +53,26 @@ func change_title(): ######## #### change level func unload_scene( scene ): - print("unload_scene: "+str(scene.name)) scene.queue_free() func load_scene( scene_path ): - print("load_scene: "+str(scene_path)) loader = ResourceLoader.load_interactive( scene_path ) if loader == null: # check for errors return false 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() get_node("background_loader").show() - print() - print( "change_level: " ) - if p_old_scene: - print( "from "+p_old_scene.name ) - print( "to "+str(p_next_scene_path) ) - if p_parent_next_scene: - print( " on "+ str(p_parent_next_scene.name) ) - print() +# print() +# print( "change_level: " ) +# if p_old_scene: +# print( "from "+p_old_scene.name ) +# print( "to "+str(p_next_scene_path) ) +# if p_parent_next_scene: +# print( " on "+ str(p_parent_next_scene.name) ) +# print() if not load_scene( p_next_scene_path ): 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 ) wait_frames = 1 - + self.current_state = p_next_state ######## func _process( time ): - print("process1") ######## #### LOADER if loader == null: @@ -98,12 +97,10 @@ func _process( time ): set_process(false) return - print("process2") if wait_frames > 0: # wait for frames to let the "loading" animation to show up wait_frames -= 1 return - print("process3") 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 # poll your loader @@ -124,17 +121,17 @@ func _process( time ): loader = null break ######## - print("process4") 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"): - 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"): - 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"): - 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: 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(global.character_slot), "color", global.character_color) + config_file.set_value(str(self.character_slot), "name", self.character_name) + config_file.set_value(str(self.character_slot), "color", self.character_color) 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.get_node( "infos_spatial" ).show() 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 ######## diff --git a/global.tscn b/global.tscn index b855f3b..0fda1bc 100644 --- a/global.tscn +++ b/global.tscn @@ -3,7 +3,7 @@ [ext_resource path="res://global.gd" type="Script" id=1] [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 script = ExtResource( 1 ) diff --git a/scenes/GUI/GUI.tscn b/scenes/GUI/GUI.tscn index 9ad24a2..5d42853 100644 --- a/scenes/GUI/GUI.tscn +++ b/scenes/GUI/GUI.tscn @@ -19,7 +19,7 @@ _sections_unfolded = [ "Font", "Settings" ] default_font = SubResource( 1 ) -[node name="GUI" type="MarginContainer"] +[node name="GUI" type="MarginContainer" index="0"] pause_mode = 2 anchor_left = 0.0