2018-08-09 07:36:14 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
const WINDOW_TITLE_INPUT = "GUI/Settings/Menus/TabContainer/Test/ScrollContainer/VBoxContainer/TitleBox/Title"
|
|
|
|
|
|
|
|
var character_name = null
|
|
|
|
var character_color = null
|
|
|
|
var character_sex = null
|
|
|
|
var character_slot = null
|
|
|
|
|
|
|
|
# BG loader
|
|
|
|
var loader
|
|
|
|
var wait_frames
|
2018-08-09 08:08:33 +00:00
|
|
|
var time_max = 10 # msec
|
|
|
|
var current_scene = null
|
|
|
|
|
2018-08-09 07:36:14 +00:00
|
|
|
func _ready():
|
|
|
|
var root = get_tree().get_root()
|
|
|
|
current_scene = root.get_child(root.get_child_count() -1)
|
2018-08-09 08:08:33 +00:00
|
|
|
|
2018-08-09 07:36:14 +00:00
|
|
|
change_title()
|
|
|
|
get_tree().get_root().connect("size_changed", self, "on_window_size_changed")
|
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
########
|
|
|
|
#### change title ####
|
|
|
|
func on_window_size_changed():
|
|
|
|
change_title()
|
|
|
|
|
|
|
|
func change_title():
|
|
|
|
var title = "Khanat"
|
2018-08-09 07:36:14 +00:00
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
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 )
|
|
|
|
########
|
2018-08-09 07:36:14 +00:00
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
|
|
|
|
########
|
|
|
|
#### scene loading
|
2018-08-09 07:36:14 +00:00
|
|
|
func goto_scene_loading( path ):
|
2018-08-09 08:08:33 +00:00
|
|
|
print( "goto: "+str(path) )
|
|
|
|
|
2018-08-09 07:36:14 +00:00
|
|
|
get_node("background_loader").show()
|
|
|
|
loader = ResourceLoader.load_interactive( path )
|
|
|
|
if loader == null: # check for errors
|
2018-08-09 08:08:33 +00:00
|
|
|
show_error()
|
2018-08-09 07:36:14 +00:00
|
|
|
return
|
2018-08-09 08:08:33 +00:00
|
|
|
|
2018-08-09 07:36:14 +00:00
|
|
|
set_process(true)
|
2018-08-09 08:08:33 +00:00
|
|
|
|
2018-08-09 07:36:14 +00:00
|
|
|
if current_scene:
|
2018-08-09 08:08:33 +00:00
|
|
|
print( "queue_free: "+str(current_scene.name) )
|
2018-08-09 07:36:14 +00:00
|
|
|
current_scene.queue_free() # get rid of the old scene
|
|
|
|
|
|
|
|
wait_frames = 1
|
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
func _process( time ):
|
|
|
|
print( "process" )
|
2018-08-09 07:36:14 +00:00
|
|
|
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
|
2018-08-09 08:08:33 +00:00
|
|
|
|
|
|
|
print( "poll: "+str((float(loader.get_stage()) / loader.get_stage_count())*100)+"%" )
|
|
|
|
|
2018-08-09 07:36:14 +00:00
|
|
|
# poll your loader
|
|
|
|
var err = loader.poll()
|
2018-08-09 08:08:33 +00:00
|
|
|
# update_progress()
|
2018-08-09 07:36:14 +00:00
|
|
|
|
|
|
|
if err == ERR_FILE_EOF: # load finished
|
|
|
|
# update_progress()
|
|
|
|
var resource = loader.get_resource()
|
|
|
|
loader = null
|
|
|
|
set_new_scene( resource )
|
|
|
|
break
|
|
|
|
elif err == OK:
|
2018-08-09 08:08:33 +00:00
|
|
|
update_progress()
|
2018-08-09 07:36:14 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
current_scene = scene_resource.instance()
|
|
|
|
get_tree().get_root().add_child(current_scene)
|
|
|
|
# get_tree().set_current_scene( current_scene )
|
2018-08-09 08:08:33 +00:00
|
|
|
|
|
|
|
get_node("background_loader").hide()
|
2018-08-09 07:36:14 +00:00
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
|
|
|
|
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)
|
2018-08-09 07:36:14 +00:00
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
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" )
|
2018-08-09 07:36:14 +00:00
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
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
|
2018-08-09 07:36:14 +00:00
|
|
|
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.
|
2018-08-09 08:08:33 +00:00
|
|
|
get_tree().get_root().add_child( current_scene )
|
2018-08-09 07:36:14 +00:00
|
|
|
|
|
|
|
# Optional, to make it compatible with the SceneTree.change_scene() API.
|
|
|
|
get_tree().set_current_scene( current_scene )
|
2018-08-09 08:08:33 +00:00
|
|
|
########
|
2018-08-09 07:36:14 +00:00
|
|
|
|