From 0c5d43e98522c780c1564bd12af7677a87055120 Mon Sep 17 00:00:00 2001 From: osquallo Date: Thu, 9 Aug 2018 10:08:33 +0200 Subject: [PATCH] nettoyage --- global.gd | 125 +++++++++++++++++++++++------------------------ project.godot | 2 +- scenes/Main.gd | 52 -------------------- scenes/Main.tscn | 10 ---- 4 files changed, 61 insertions(+), 128 deletions(-) delete mode 100644 scenes/Main.gd delete mode 100644 scenes/Main.tscn diff --git a/global.gd b/global.gd index 4ba9534..3571d5f 100644 --- a/global.gd +++ b/global.gd @@ -2,8 +2,6 @@ extends Node const WINDOW_TITLE_INPUT = "GUI/Settings/Menus/TabContainer/Test/ScrollContainer/VBoxContainer/TitleBox/Title" -var current_scene = null - var character_name = null var character_color = null var character_sex = null @@ -12,43 +10,55 @@ var character_slot = null # BG loader var loader var wait_frames -var time_max = 100 # msec -#var current_scene -var main_scene = null +var time_max = 10 # msec +var current_scene = null + func _ready(): var root = get_tree().get_root() current_scene = root.get_child(root.get_child_count() -1) - -# current_scene = root.get_node( "Main/login_scene" ) -# main_scene = root.get_node( "Main" ) - - + change_title() get_tree().get_root().connect("size_changed", self, "on_window_size_changed") + +######## +#### change title #### +func on_window_size_changed(): + change_title() -# global.goto_scene_loading( "res://login_scene/login_scene.tscn" ) -# if global.character_creation_camera: -# global.character_creation_camera.make_current() - - global.goto_scene_loading( "res://login_scene/login_scene.tscn" ) -# get_tree().change_scene( "res://login_scene/login_scene.tscn" ) +func change_title(): + var title = "Khanat" + if has_node( WINDOW_TITLE_INPUT ): + var title_node = get_node( WINDOW_TITLE_INPUT ) + 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 ) +######## - + +######## +#### scene loading func goto_scene_loading( path ): + print( "goto: "+str(path) ) + get_node("background_loader").show() loader = ResourceLoader.load_interactive( path ) if loader == null: # check for errors -# show_error() + show_error() return + set_process(true) - + if current_scene: + print( "queue_free: "+str(current_scene.name) ) current_scene.queue_free() # get rid of the old scene wait_frames = 1 -func _process(time): +func _process( time ): + print( "process" ) if loader == null: # no need to process anymore set_process(false) @@ -60,19 +70,21 @@ func _process(time): 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 + + print( "poll: "+str((float(loader.get_stage()) / loader.get_stage_count())*100)+"%" ) + # poll your loader var err = loader.poll() - update_progress() +# update_progress() if err == ERR_FILE_EOF: # load finished # update_progress() - var resource = loader.get_resource() loader = null set_new_scene( resource ) break elif err == OK: -# update_progress() + update_progress() pass else: # error during loading show_error() @@ -92,16 +104,36 @@ func set_new_scene( scene_resource ): progress_texture.value = 0 - get_node("background_loader").hide() current_scene = scene_resource.instance() get_tree().get_root().add_child(current_scene) # get_tree().set_current_scene( current_scene ) + + get_node("background_loader").hide() + +func _on_login_scene_character_creation_finished(): + var config_file = ConfigFile.new() + var err = config_file.load( "user://player.cfg" ) + 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.save( "user://player.cfg" ) + print("test") +# global.goto_scene_loading( "res://login_scene/login_scene.tscn" ) + global.goto_scene_loading( "res://game_scene/game_scene.tscn" ) +# get_tree().change_scene( "res://game_scene/game_scene.tscn" ) -######################################## -#### deffered goto without loading ##### +func _on_logout_button_pressed(): + global.goto_scene_loading( "res://login_scene/login_scene.tscn" ) +# get_tree().change_scene( "res://login_scene/login_scene.tscn" ) +######## + +######## +#### defered goto without loading func goto_scene( path ): # This function will usually be called from a signal callback, # or some other function from the running scene. @@ -128,46 +160,9 @@ func _deferred_goto_scene( path ): current_scene = s.instance() # Add it to the active scene, as child of root. - main_scene.add_child( current_scene ) + get_tree().get_root().add_child( current_scene ) # Optional, to make it compatible with the SceneTree.change_scene() API. get_tree().set_current_scene( current_scene ) - -######################################## -######################################## +######## - - -######################################## -############### Main ################### -func on_window_size_changed(): - change_title() - -func change_title(): - var title = "Khanat" - - if has_node( WINDOW_TITLE_INPUT ): - var title_node = get_node( WINDOW_TITLE_INPUT ) - 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 ) - -func _on_login_scene_character_creation_finished(): - var config_file = ConfigFile.new() - var err = config_file.load( "user://player.cfg" ) - 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.save( "user://player.cfg" ) - print("test") - global.goto_scene_loading( "res://game_scene/game_scene.tscn" ) -# get_tree().change_scene( "res://game_scene/game_scene.tscn" ) - -func _on_logout_button_pressed(): - global.goto_scene_loading( "res://login_scene/login_scene.tscn" ) -# get_tree().change_scene( "res://login_scene/login_scene.tscn" ) diff --git a/project.godot b/project.godot index 10f4a87..a4d2cdc 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=3 [application] config/name="Khanat" -run/main_scene="res://scenes/Main.tscn" +run/main_scene="res://login_scene/login_scene.tscn" boot_splash/image="res://assets/GUI/images/new_launcher_bg_0-1.png" config/icon="res://icon.png" diff --git a/scenes/Main.gd b/scenes/Main.gd deleted file mode 100644 index 1f4c535..0000000 --- a/scenes/Main.gd +++ /dev/null @@ -1,52 +0,0 @@ -extends Node - -#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.goto_scene_loading( "res://login_scene/login_scene.tscn" ) -## if global.character_creation_camera: -## global.character_creation_camera.make_current() -# -# get_tree().change_scene( "res://login_scene/login_scene.tscn" ) -# - - -# -#func _process(delta): -# pass -# -#func on_window_size_changed(): -# change_title() -# -#func change_title(): -# var title = "Khanat" -# -# if has_node( WINDOW_TITLE_INPUT ): -# var title_node = get_node( WINDOW_TITLE_INPUT ) -# 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 ) -# -#func _on_login_scene_character_creation_finished(): -# var config_file = ConfigFile.new() -# var err = config_file.load( "user://player.cfg" ) -# 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.save( "user://player.cfg" ) -# print("test") -## global.goto_scene_loading( "res://game_scene/game_scene.tscn" ) -# get_tree().change_scene( "res://game_scene/game_scene.tscn" ) -# -#func _on_logout_button_pressed(): -## global.goto_scene_loading( "res://login_scene/login_scene.tscn" ) -# get_tree().change_scene( "res://login_scene/login_scene.tscn" ) -## pass \ No newline at end of file diff --git a/scenes/Main.tscn b/scenes/Main.tscn deleted file mode 100644 index 24f791c..0000000 --- a/scenes/Main.tscn +++ /dev/null @@ -1,10 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://scenes/Main.gd" type="Script" id=1] - -[node name="Main" type="Node"] - -script = ExtResource( 1 ) -_sections_unfolded = [ "Pause" ] - -