diff --git a/background_loader_scene/background_loader.tscn b/background_loader_scene/background_loader.tscn new file mode 100644 index 0000000..c146df8 --- /dev/null +++ b/background_loader_scene/background_loader.tscn @@ -0,0 +1,66 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://assets/GUI/loading_screens/new_loading_bg_0.tga" type="Texture" id=1] +[ext_resource path="res://assets/GUI/loading_screens/new_loading_bg_1.tga" type="Texture" id=2] + +[node name="background_loader" type="Panel"] + +visible = false +self_modulate = Color( 0, 0, 0, 1 ) +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 +_sections_unfolded = [ "Mouse", "Visibility", "custom_constants" ] + +[node name="center_container" type="MarginContainer" parent="." index="0"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 +_sections_unfolded = [ "Mouse" ] + +[node name="texture_progress" type="TextureProgress" parent="center_container" index="0"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 8.0 +margin_right = 1032.0 +margin_bottom = 600.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 +min_value = 0.0 +max_value = 100.0 +step = 1.0 +page = 0.0 +value = 0.0 +exp_edit = false +rounded = false +texture_under = ExtResource( 1 ) +texture_over = null +texture_progress = ExtResource( 2 ) +radial_fill_degrees = 360.0 +radial_center_offset = Vector2( 0, 0 ) +nine_patch_stretch = false +_sections_unfolded = [ "Mouse", "Textures" ] + + diff --git a/game_scene/game_scene.gd b/game_scene/game_scene.gd index 2e531b8..ed6ab77 100644 --- a/game_scene/game_scene.gd +++ b/game_scene/game_scene.gd @@ -14,8 +14,8 @@ func _ready(): $GUI.pause() - self.connect( "logout_button_pressed", self.get_parent(), "_on_logout_button_pressed" ) - + self.connect( "logout_button_pressed", global, "_on_logout_button_pressed" ) + func _process(delta): pass diff --git a/global.gd b/global.gd new file mode 100644 index 0000000..4ba9534 --- /dev/null +++ b/global.gd @@ -0,0 +1,173 @@ +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 +var character_slot = null + +# BG loader +var loader +var wait_frames +var time_max = 100 # msec +#var current_scene +var main_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") + +# 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 goto_scene_loading( path ): + get_node("background_loader").show() + loader = ResourceLoader.load_interactive( path ) + if loader == null: # check for errors +# show_error() + return + set_process(true) + + if current_scene: + current_scene.queue_free() # get rid of the old scene + + wait_frames = 1 + +func _process(time): + if loader == null: + # no need to process anymore + set_process(false) + return + + if wait_frames > 0: # wait for frames to let the "loading" animation to show up + wait_frames -= 1 + return + + 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 + var err = loader.poll() + 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() + pass + else: # error during loading + show_error() + loader = null + break + + +func update_progress(): + var progress_texture = get_node("background_loader/center_container/texture_progress") + var progress = (float(loader.get_stage()) / loader.get_stage_count()) * progress_texture.max_value + + progress_texture.value = progress + + +func set_new_scene( scene_resource ): + var progress_texture = get_node("background_loader/center_container/texture_progress") + + 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 ) + + + +######################################## +#### deffered 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. + # Deleting the current scene at this point might be + # a bad idea, because it may be inside of a callback or function of it. + # The worst case will be a crash or unexpected behavior. + + # 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) + + +func _deferred_goto_scene( path ): + # Immediately free the current scene, + # there is no risk here. + if current_scene: + current_scene.free() + + # Load new scene. + var s = ResourceLoader.load( path ) + + # Instance the new scene. + current_scene = s.instance() + + # Add it to the active scene, as child of root. + main_scene.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/global.tscn b/global.tscn new file mode 100644 index 0000000..31aad6e --- /dev/null +++ b/global.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=3 format=2] + +[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" index="0"] + +script = ExtResource( 1 ) + +[node name="background_loader" parent="." index="0" instance=ExtResource( 2 )] + + diff --git a/login_scene/login_scene.gd b/login_scene/login_scene.gd index 06d7f7b..5c16e4a 100644 --- a/login_scene/login_scene.gd +++ b/login_scene/login_scene.gd @@ -4,10 +4,8 @@ signal character_creation_finished func _ready(): - print("login_scene_ready") $login_menu.show() - - self.connect( "character_creation_finished", self.get_parent(), "_on_login_scene_character_creation_finished" ) + self.connect( "character_creation_finished", global, "_on_login_scene_character_creation_finished" ) func _on_login_menu_login_button_pressed(): diff --git a/project.godot b/project.godot index 1f50a41..10f4a87 100644 --- a/project.godot +++ b/project.godot @@ -17,7 +17,7 @@ config/icon="res://icon.png" [autoload] -global="*res://scenes/global.gd" +global="*res://global.tscn" [display] diff --git a/scenes/Main.gd b/scenes/Main.gd index ed735ec..1f4c535 100644 --- a/scenes/Main.gd +++ b/scenes/Main.gd @@ -1,46 +1,52 @@ 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_first_scene_loading( "res://login_scene/login_scene.tscn" ) -# if global.character_creation_camera: -# global.character_creation_camera.make_current() +#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" ) - -func _on_logout_button_pressed(): - global.goto_scene_loading( "res://login_scene/login_scene.tscn" ) \ No newline at end of file +# +#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 index 2e90a4e..24f791c 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -1,71 +1,10 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://scenes/Main.gd" type="Script" id=1] -[ext_resource path="res://assets/GUI/loading_screens/new_loading_bg_0.tga" type="Texture" id=2] -[ext_resource path="res://assets/GUI/loading_screens/new_loading_bg_1.tga" type="Texture" id=3] -[node name="Main" type="Node" index="0"] +[node name="Main" type="Node"] script = ExtResource( 1 ) _sections_unfolded = [ "Pause" ] -[node name="background_loader" type="Panel" parent="." index="0"] - -visible = false -self_modulate = Color( 0, 0, 0, 1 ) -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -_sections_unfolded = [ "Mouse", "Visibility", "custom_constants" ] - -[node name="center_container" type="MarginContainer" parent="background_loader" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 - -[node name="texture_progress" type="TextureProgress" parent="background_loader/center_container" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 8.0 -margin_right = 1032.0 -margin_bottom = 600.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 1 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 -max_value = 100.0 -step = 1.0 -page = 0.0 -value = 0.0 -exp_edit = false -rounded = false -texture_under = ExtResource( 2 ) -texture_over = null -texture_progress = ExtResource( 3 ) -radial_fill_degrees = 360.0 -radial_center_offset = Vector2( 0, 0 ) -nine_patch_stretch = false -_sections_unfolded = [ "Textures" ] - diff --git a/scenes/global.gd b/scenes/global.gd deleted file mode 100644 index c273459..0000000 --- a/scenes/global.gd +++ /dev/null @@ -1,123 +0,0 @@ -extends Node - -var current_scene = null - -var character_name = null -var character_color = null -var character_sex = null -var character_slot = null - -# BG loader -var loader -var wait_frames -var time_max = 100 # msec -#var current_scene -var main_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" ) - -func goto_first_scene_loading( path ): - get_tree().get_root().get_node("Main/background_loader").show() - loader = ResourceLoader.load_interactive( path ) - if loader == null: # check for errors -# show_error() - return - set_process(true) - - wait_frames = 1 - -func goto_scene_loading( path ): - get_tree().get_root().get_node("Main/background_loader").show() - loader = ResourceLoader.load_interactive( path ) - if loader == null: # check for errors -# show_error() - return - set_process(true) - - current_scene.queue_free() # get rid of the old scene - - wait_frames = 1 - -func _process(time): - if loader == null: - # no need to process anymore - set_process(false) - return - - if wait_frames > 0: # wait for frames to let the "loading" animation to show up - wait_frames -= 1 - return - - 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 - var err = loader.poll() - 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() - pass - else: # error during loading - show_error() - loader = null - break -func update_progress(): - var progress_texture = get_tree().get_root().get_node("Main/background_loader/center_container/texture_progress") - var progress = (float(loader.get_stage()) / loader.get_stage_count()) * progress_texture.max_value - progress_texture.value = progress - - - # or update a progress animation? -# var len = get_node("animation").get_current_animation_length() - # call this on a paused animation. use "true" as the second parameter to force the animation to update -# get_node("animation").seek(progress * len, true) - - -func set_new_scene( scene_resource ): - var progress_texture = get_tree().get_root().get_node("Main/background_loader/center_container/texture_progress") - progress_texture.value = 0 - get_tree().get_root().get_node("Main/background_loader").hide() - - current_scene = scene_resource.instance() - main_scene.add_child(current_scene) -# get_tree().set_current_scene( current_scene ) - -func goto_scene( path ): - # 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 - # a bad idea, because it may be inside of a callback or function of it. - # The worst case will be a crash or unexpected behavior. - - # 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) - - -func _deferred_goto_scene( path ): - # Immediately free the current scene, - # there is no risk here. - current_scene.free() - - # Load new scene. - var s = ResourceLoader.load( path ) - - # Instance the new scene. - current_scene = s.instance() - - # Add it to the active scene, as child of root. - path.add_child( current_scene ) - - # Optional, to make it compatible with the SceneTree.change_scene() API. - get_tree().set_current_scene( current_scene ) \ No newline at end of file