mirror of
https://port.numenaute.org/aleajactaest/khanat-client.git
synced 2024-12-30 13:00:54 +00:00
131 lines
4.6 KiB
GDScript
131 lines
4.6 KiB
GDScript
extends Spatial
|
|
|
|
|
|
var loader
|
|
var wait_frames
|
|
var time_max = 100 # msec
|
|
var current_scene = null
|
|
|
|
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" )
|
|
|
|
|
|
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 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
|
|
|
|
func _input( event ):
|
|
|
|
if event.is_action_released( "music_manager" ):
|
|
MusicManager.toggle()
|
|
|
|
|
|
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
|
|
|
|
func set_new_scene( scene_resource ):
|
|
self.current_scene = scene_resource.instance()
|
|
self.get_node("scene").add_child(current_scene)
|
|
$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 )
|
|
|
|
func update_progress():
|
|
var progress = float(self.loader.get_stage()) / self.loader.get_stage_count()
|
|
|
|
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 _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)
|
|
else:
|
|
self.load_scene( "res://scenes/interfaces/creatures_menu/creatures_menu_ui.tscn" )
|
|
|
|
|
|
|
|
func _on_creatures_menu_ui_new_pressed( slot ):
|
|
self.creature_selected_slot = slot
|
|
self.load_scene( "res://scenes/interfaces/creatures_editor/creatures_editor_ui.tscn" )
|
|
|
|
func _on_creatures_menu_ui_cancel_pressed():
|
|
$main_menu.show()
|
|
|
|
func _on_creatures_menu_ui_select_pressed( filename ):
|
|
self.creature_selected_filename = filename
|
|
self.load_scene( "res://scenes/game/game.tscn" )
|
|
|
|
func _on_creature_editor_ui_valid_pressed():
|
|
self.load_scene( "res://scenes/interfaces/creatures_menu/creatures_menu_ui.tscn" )
|
|
|
|
func _on_creature_editor_ui_cencel_pressed():
|
|
self.load_scene( "res://scenes/interfaces/creatures_menu/creatures_menu_ui.tscn" )
|
|
|
|
func _on_main_menu_quit_pressed():
|
|
get_tree().quit()
|
|
|
|
func _on_connexion_ok():
|
|
self.load_scene( "res://scenes/interfaces/creatures_menu/creatures_menu_ui.tscn" )
|
|
|
|
func _on_connection_error( message ):
|
|
$main_menu/screen_box/login_box/error.text = message
|