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():
|
2021-01-21 21:03:44 +00:00
|
|
|
Connection.connect( "connection_ok", self, "_on_connexion_ok" )
|
|
|
|
Connection.connect( "connection_error", self, "_on_connection_error" )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
2021-01-21 21:03:44 +00:00
|
|
|
Globals.ressource_queue.start()
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _process(_time):
|
2021-01-21 21:03:44 +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()
|
|
|
|
self.stop_progress()
|
|
|
|
else:
|
|
|
|
self.update_progress()
|
|
|
|
$loading_screen.show()
|
|
|
|
|
|
|
|
|
2020-10-15 17:23:55 +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 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
|
2021-01-21 21:03:44 +00:00
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
func _input( event ):
|
2021-01-21 21:03:44 +00:00
|
|
|
|
|
|
|
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 ):
|
2021-01-21 21:03:44 +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
|
|
|
|
self.stop_progress()
|
|
|
|
# $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():
|
2021-01-21 21:03:44 +00:00
|
|
|
var progress = float(Globals.ressource_queue.get_progress( self.current_scene_path ))
|
|
|
|
#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 )
|
|
|
|
|
|
|
|
func start_progress():
|
|
|
|
var progress = float(Globals.ressource_queue.get_progress( self.current_scene_path ))
|
|
|
|
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( 0 )
|
|
|
|
self.is_scene_loading = true
|
|
|
|
$loading_screen.show()
|
|
|
|
|
|
|
|
func stop_progress():
|
|
|
|
self.get_node("loading_screen/background_player").stop()
|
|
|
|
self.is_scene_loading = false
|
|
|
|
$loading_screen.hide()
|
|
|
|
|
2020-10-15 17:23:55 +00:00
|
|
|
func goto_scene( p_path ):
|
2021-01-21 21:03:44 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
self.start_progress()
|
2020-10-15 17:23:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
#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
|
2021-01-21 21:03:44 +00:00
|
|
|
|
2020-10-15 17:23:55 +00:00
|
|
|
#func update_progress():
|
|
|
|
# self.get_node("loading_screen/progress_bar").value = Globals.ressource_queue.get_progress( self.current_scene_path )
|
|
|
|
#
|
2021-01-21 21:03:44 +00:00
|
|
|
|
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_main_menu_play_pressed():
|
|
|
|
|
2021-01-21 21:03:44 +00:00
|
|
|
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)
|
|
|
|
else:
|
|
|
|
Globals.goto_scene( "res://scenes/interfaces/creatures_menu/creatures_menu_ui.tscn" )
|
|
|
|
|
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_creatures_menu_ui_new_pressed( slot ):
|
2021-01-21 21:03:44 +00:00
|
|
|
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" )
|
2021-01-21 21:03:44 +00:00
|
|
|
Globals.goto_scene( "res://scenes/creatures/creatures_creation.tscn" )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_creatures_menu_ui_cancel_pressed():
|
2021-01-21 21:03:44 +00:00
|
|
|
$main_menu.show()
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_creatures_menu_ui_select_pressed( filename ):
|
2021-01-21 21:03:44 +00:00
|
|
|
self.creature_selected_filename = filename
|
2021-03-23 22:24:40 +00:00
|
|
|
#Globals.goto_scene( "res://scenes/game/game.tscn" )
|
|
|
|
Globals.goto_scene( "res://scenes/game/dispensaire/dispensaire.tscn" )
|
2021-01-21 21:03:44 +00:00
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
func _on_creature_editor_ui_valid_pressed():
|
2021-01-21 21:03:44 +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():
|
2021-01-21 21:03:44 +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():
|
2021-01-21 21:03:44 +00:00
|
|
|
get_tree().quit()
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
func _on_connexion_ok():
|
2021-01-21 21:03:44 +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 ):
|
2021-01-21 21:03:44 +00:00
|
|
|
$main_menu/screen_box/login_box/error.text = message
|