2020-03-21 09:10:26 +00:00
|
|
|
extends Spatial
|
|
|
|
|
|
|
|
|
|
|
|
var loader
|
|
|
|
var wait_frames
|
|
|
|
var time_max = 100 # msec
|
2020-10-15 17:23:55 +00:00
|
|
|
var current_scene_path = null
|
2020-03-21 09:10:26 +00:00
|
|
|
var current_scene = null
|
2020-10-15 17:23:55 +00:00
|
|
|
var is_scene_loading = false
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
var creature_selected_slot = null
|
|
|
|
var creature_selected_filename = null
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
Connection.connect( "connection_ok", self, "_on_connexion_ok" )
|
|
|
|
Connection.connect( "connection_error", self, "_on_connection_error" )
|
|
|
|
|
2020-10-15 17:23:55 +00:00
|
|
|
Globals.ressource_queue.start()
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _process(_time):
|
2020-10-15 17:23:55 +00:00
|
|
|
|
|
|
|
if self.is_scene_loading:
|
|
|
|
if Globals.ressource_queue.is_ready( self.current_scene_path ):
|
|
|
|
print( "LOADING FINISHED")
|
|
|
|
self.set_new_scene( Globals.ressource_queue.get_resource( self.current_scene_path ) )
|
|
|
|
$loading_screen.hide()
|
|
|
|
else:
|
|
|
|
self.update_progress()
|
|
|
|
$loading_screen.show()
|
|
|
|
|
|
|
|
|
|
|
|
# if loader == null:
|
|
|
|
# # no need to process anymore
|
|
|
|
# set_process(false)
|
|
|
|
# return
|
|
|
|
#
|
|
|
|
# if wait_frames > 0: # wait for frames to let the "loading" animation 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 for how long we block this thread
|
|
|
|
#
|
|
|
|
# # poll your loader
|
|
|
|
# var err = loader.poll()
|
|
|
|
#
|
|
|
|
# if err == ERR_FILE_EOF: # Finished loading.
|
|
|
|
# var resource = loader.get_resource()
|
|
|
|
# loader = null
|
|
|
|
# set_new_scene(resource)
|
|
|
|
# break
|
|
|
|
# elif err == OK:
|
|
|
|
# update_progress()
|
|
|
|
# else: # error during loading
|
|
|
|
## show_error()
|
|
|
|
# printerr( "Loading errors." )
|
|
|
|
# loader = null
|
|
|
|
# break
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _input( event ):
|
|
|
|
|
|
|
|
if event.is_action_released( "music_manager" ):
|
|
|
|
MusicManager.toggle()
|
|
|
|
|
|
|
|
|
2020-10-15 17:23:55 +00:00
|
|
|
#func load_scene( path ):
|
|
|
|
# self.loader = ResourceLoader.load_interactive( path )
|
|
|
|
# if self.loader == null:
|
|
|
|
## show_error()
|
|
|
|
# printerr( "Loading errors." )
|
|
|
|
# return
|
|
|
|
# set_process(true)
|
|
|
|
# if self.current_scene:
|
|
|
|
# self.current_scene.queue_free() # get rid of the old scene
|
|
|
|
#
|
|
|
|
# # start your "loading..." animation
|
|
|
|
## get_node("animation").play("loading")
|
|
|
|
#
|
|
|
|
# $loading_screen.show()
|
|
|
|
#
|
|
|
|
# self.wait_frames = 1
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func set_new_scene( scene_resource ):
|
2020-10-15 17:23:55 +00:00
|
|
|
if scene_resource:
|
|
|
|
self.current_scene = scene_resource.instance()
|
|
|
|
self.get_node("scene").add_child(self.current_scene)
|
|
|
|
self.is_scene_loading = false
|
|
|
|
$loading_screen.hide()
|
|
|
|
$main_menu.hide()
|
|
|
|
|
|
|
|
if self.has_node( "scene/creatures_menu_ui" ):
|
|
|
|
self.get_node( "scene/creatures_menu_ui" ).connect( "new_pressed", self, "_on_creatures_menu_ui_new_pressed" )
|
|
|
|
self.get_node( "scene/creatures_menu_ui" ).connect( "cancel_pressed", self, "_on_creatures_menu_ui_cancel_pressed" )
|
|
|
|
self.get_node( "scene/creatures_menu_ui" ).connect( "select_pressed", self, "_on_creatures_menu_ui_select_pressed" )
|
|
|
|
elif self.has_node( "scene/creatures_editor_ui" ):
|
|
|
|
self.get_node( "scene/creatures_editor_ui" ).connect( "valid_pressed", self, "_on_creature_editor_ui_valid_pressed" )
|
|
|
|
self.get_node( "scene/creatures_editor_ui" ).connect( "cancel_pressed", self, "_on_creature_editor_ui_cencel_pressed" )
|
|
|
|
print( "slot: " + str( self.creature_selected_slot ) )
|
|
|
|
self.get_node( "scene/creatures_editor_ui" ).slot = self.creature_selected_slot
|
|
|
|
# elif self.has_node( "scene/game" ):
|
|
|
|
# self.get_node( "scene/game" ).load_player( self.creature_selected_filename )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func update_progress():
|
2020-10-15 17:23:55 +00:00
|
|
|
var progress = float(Globals.ressource_queue.get_progress( self.current_scene_path ))
|
2020-03-21 09:10:26 +00:00
|
|
|
|
2020-03-23 14:16:06 +00:00
|
|
|
self.get_node("loading_screen/background_player").play("loading")
|
|
|
|
self.get_node("loading_screen/background_player").stop()
|
|
|
|
self.get_node("loading_screen/background_player").seek( (progress*13.0)/100.0 )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
|
2020-10-15 17:23:55 +00:00
|
|
|
func goto_scene( p_path ):
|
|
|
|
|
|
|
|
# Clean old scene.
|
|
|
|
if self.current_scene:
|
|
|
|
Globals.ressource_queue.cancel_resource( self.current_scene_path )
|
|
|
|
self.current_scene.queue_free()
|
|
|
|
|
|
|
|
Globals.ressource_queue.queue_resource( p_path )
|
|
|
|
self.current_scene_path = p_path
|
|
|
|
self.is_scene_loading = true
|
|
|
|
|
|
|
|
|
|
|
|
#func set_new_scene( scene_resource ):
|
|
|
|
# if scene_resource:
|
|
|
|
# self.current_scene = scene_resource.instance()
|
|
|
|
# self.get_node("scene").add_child(self.current_scene)
|
|
|
|
# self.is_scene_loading = false
|
|
|
|
|
|
|
|
#func update_progress():
|
|
|
|
# self.get_node("loading_screen/progress_bar").value = Globals.ressource_queue.get_progress( self.current_scene_path )
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_main_menu_play_pressed():
|
|
|
|
|
|
|
|
var username = $main_menu/screen_box/login_box/username.text;
|
|
|
|
var password = $main_menu/screen_box/login_box/password.text;
|
|
|
|
if username != null and username != "" and password != null and password != "":
|
|
|
|
Connection.do_request(username, password)
|
2020-03-22 10:54:47 +00:00
|
|
|
else:
|
2020-10-15 17:23:55 +00:00
|
|
|
Globals.goto_scene( "res://scenes/interfaces/creatures_menu/creatures_menu_ui.tscn" )
|
2020-03-22 10:54:47 +00:00
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_creatures_menu_ui_new_pressed( slot ):
|
|
|
|
self.creature_selected_slot = slot
|
2020-10-15 17:23:55 +00:00
|
|
|
# Globals.goto_scene( "res://scenes/interfaces/creatures_editor/creatures_editor_ui.tscn" )
|
|
|
|
Globals.goto_scene( "res://scenes/creatures/creatures_creation.tscn" )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_creatures_menu_ui_cancel_pressed():
|
|
|
|
$main_menu.show()
|
|
|
|
|
|
|
|
func _on_creatures_menu_ui_select_pressed( filename ):
|
|
|
|
self.creature_selected_filename = filename
|
2020-10-15 17:23:55 +00:00
|
|
|
Globals.goto_scene( "res://scenes/game/game.tscn" )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_creature_editor_ui_valid_pressed():
|
2020-10-15 17:23:55 +00:00
|
|
|
Globals.goto_scene( "res://scenes/interfaces/creatures_menu/creatures_menu_ui.tscn" )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_creature_editor_ui_cencel_pressed():
|
2020-10-15 17:23:55 +00:00
|
|
|
Globals.goto_scene( "res://scenes/interfaces/creatures_menu/creatures_menu_ui.tscn" )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_main_menu_quit_pressed():
|
|
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
func _on_connexion_ok():
|
2020-10-15 17:23:55 +00:00
|
|
|
Globals.goto_scene( "res://scenes/interfaces/creatures_menu/creatures_menu_ui.tscn" )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_connection_error( message ):
|
|
|
|
$main_menu/screen_box/login_box/error.text = message
|