2018-08-09 07:36:14 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
const WINDOW_TITLE_INPUT = "GUI/Settings/Menus/TabContainer/Test/ScrollContainer/VBoxContainer/TitleBox/Title"
|
|
|
|
|
2018-08-20 09:10:33 +00:00
|
|
|
#### Environment
|
|
|
|
var time_scale = 0.1
|
|
|
|
|
|
|
|
|
2018-08-13 14:48:22 +00:00
|
|
|
#### Character
|
2018-08-12 16:49:50 +00:00
|
|
|
var character_name = "player"
|
2018-08-09 07:36:14 +00:00
|
|
|
var character_color = null
|
2018-08-09 14:09:55 +00:00
|
|
|
var character_gender = null
|
2018-08-09 07:36:14 +00:00
|
|
|
var character_slot = null
|
|
|
|
|
2018-08-13 14:48:22 +00:00
|
|
|
#### BG loader
|
2018-08-12 16:49:50 +00:00
|
|
|
onready var progress_texture = $background_loader/center_container/texture_progress
|
2018-08-09 07:36:14 +00:00
|
|
|
var loader
|
|
|
|
var wait_frames
|
2018-08-09 08:08:33 +00:00
|
|
|
var time_max = 10 # msec
|
|
|
|
var current_scene = null
|
2018-08-12 16:49:50 +00:00
|
|
|
var old_scene = null
|
|
|
|
var parent_scene = null
|
2018-08-13 14:48:22 +00:00
|
|
|
var current_map = null
|
2018-08-09 08:08:33 +00:00
|
|
|
|
2018-08-15 07:29:34 +00:00
|
|
|
var current_state = "login"
|
|
|
|
|
2018-08-18 08:22:19 +00:00
|
|
|
var font_size= 14
|
|
|
|
|
2018-08-09 07:36:14 +00:00
|
|
|
func _ready():
|
|
|
|
var root = get_tree().get_root()
|
2018-08-12 16:49:50 +00:00
|
|
|
# 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-12 16:49:50 +00:00
|
|
|
# change_level( "res://login_scene/login_scene.tscn", get_tree().get_root() )
|
2018-08-13 14:48:22 +00:00
|
|
|
|
|
|
|
character.get_node( "infos_spatial" ).hide()
|
|
|
|
|
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-12 16:49:50 +00:00
|
|
|
|
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
########
|
2018-08-12 16:49:50 +00:00
|
|
|
#### change level
|
|
|
|
func unload_scene( scene ):
|
|
|
|
scene.queue_free()
|
|
|
|
|
|
|
|
func load_scene( scene_path ):
|
|
|
|
loader = ResourceLoader.load_interactive( scene_path )
|
2018-08-09 07:36:14 +00:00
|
|
|
if loader == null: # check for errors
|
2018-08-12 16:49:50 +00:00
|
|
|
return false
|
|
|
|
return true
|
|
|
|
|
2018-08-15 07:29:34 +00:00
|
|
|
func change_level( p_next_state, p_next_scene_path, p_parent_next_scene = null, p_old_scene = null ):
|
2018-08-12 16:49:50 +00:00
|
|
|
character.hide()
|
|
|
|
get_node("background_loader").show()
|
2018-08-14 07:40:10 +00:00
|
|
|
|
2018-08-15 07:29:34 +00:00
|
|
|
# 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()
|
2018-08-12 16:49:50 +00:00
|
|
|
|
|
|
|
if not load_scene( p_next_scene_path ):
|
2018-08-09 08:08:33 +00:00
|
|
|
show_error()
|
2018-08-09 07:36:14 +00:00
|
|
|
return
|
2018-08-12 16:49:50 +00:00
|
|
|
parent_scene = p_parent_next_scene
|
|
|
|
old_scene = p_old_scene
|
2018-08-09 07:36:14 +00:00
|
|
|
set_process(true)
|
2018-08-09 08:08:33 +00:00
|
|
|
|
2018-08-12 16:49:50 +00:00
|
|
|
if old_scene:
|
|
|
|
unload_scene( old_scene )
|
2018-08-14 07:40:10 +00:00
|
|
|
|
|
|
|
wait_frames = 1
|
2018-08-15 07:29:34 +00:00
|
|
|
self.current_state = p_next_state
|
2018-08-12 16:49:50 +00:00
|
|
|
########
|
|
|
|
|
2018-08-09 07:36:14 +00:00
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
func _process( time ):
|
2018-08-13 14:48:22 +00:00
|
|
|
########
|
|
|
|
#### LOADER
|
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()
|
2018-08-09 14:14:11 +00:00
|
|
|
while OS.get_ticks_msec() < t + time_max: # use "time_max" to control how much time we block this thread
|
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
|
2018-08-13 14:48:22 +00:00
|
|
|
########
|
|
|
|
|
|
|
|
func _input( event ):
|
|
|
|
|
2018-08-15 07:29:34 +00:00
|
|
|
if current_state == "game" and event is InputEventKey and not event.is_echo():
|
2018-08-13 14:48:22 +00:00
|
|
|
if event.is_action_pressed("test_change_map_1"):
|
2018-08-15 07:29:34 +00:00
|
|
|
global.change_level( "game", "res://test_scene/test_scene.tscn", null, current_map )
|
2018-08-13 14:48:22 +00:00
|
|
|
elif event.is_action_pressed("test_change_map_2"):
|
2018-08-15 07:29:34 +00:00
|
|
|
global.change_level( "game", "res://test_grid_map/test_grid_map.tscn", null, current_map )
|
2018-08-13 14:48:22 +00:00
|
|
|
elif event.is_action_pressed("test_change_map_3"):
|
2018-08-15 07:29:34 +00:00
|
|
|
global.change_level( "game", "res://game_scene/game_scene.tscn", null, current_map )
|
|
|
|
|
2018-08-13 14:48:22 +00:00
|
|
|
|
|
|
|
|
2018-08-09 07:36:14 +00:00
|
|
|
|
|
|
|
func update_progress():
|
|
|
|
var progress = (float(loader.get_stage()) / loader.get_stage_count()) * progress_texture.max_value
|
|
|
|
|
|
|
|
progress_texture.value = progress
|
|
|
|
|
|
|
|
|
2018-08-13 14:48:22 +00:00
|
|
|
func set_new_scene( scene_resource ):
|
2018-08-09 07:36:14 +00:00
|
|
|
progress_texture.value = 0
|
|
|
|
|
2018-08-12 16:49:50 +00:00
|
|
|
var scene = scene_resource.instance()
|
|
|
|
# current_scene = scene_resource.instance()
|
|
|
|
if parent_scene:
|
|
|
|
parent_scene.add_child(scene)
|
|
|
|
else:
|
|
|
|
get_tree().get_root().add_child(scene)
|
|
|
|
|
|
|
|
if scene.has_node("start_position"):
|
|
|
|
character.update( scene.get_node("start_position") )
|
2018-08-13 14:48:22 +00:00
|
|
|
current_map = scene
|
2018-08-09 07:36:14 +00:00
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
get_node("background_loader").hide()
|
2018-08-12 16:49:50 +00:00
|
|
|
character.show()
|
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)
|
|
|
|
|
2018-08-15 07:29:34 +00:00
|
|
|
config_file.set_value(str(self.character_slot), "name", self.character_name)
|
|
|
|
config_file.set_value(str(self.character_slot), "color", self.character_color)
|
2018-08-09 07:36:14 +00:00
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
config_file.save( "user://player.cfg" )
|
2018-08-15 07:29:34 +00:00
|
|
|
self.change_level( "game", "res://game_scene/game_scene.tscn", null, get_tree().get_root().get_node("login_scene") )
|
2018-08-13 14:48:22 +00:00
|
|
|
character.show_third_person_camera()
|
|
|
|
# character.get_node( "infos_spatial" ).show()
|
2018-08-09 07:36:14 +00:00
|
|
|
|
2018-08-09 08:08:33 +00:00
|
|
|
func _on_logout_button_pressed():
|
2018-08-15 07:29:34 +00:00
|
|
|
self.change_level( "login", "res://login_scene/login_scene.tscn", null, current_map )
|
2018-08-09 08:16:41 +00:00
|
|
|
get_tree().paused = false
|
2018-08-09 08:08:33 +00:00
|
|
|
########
|