khanat-client/scenes/main/main.gd

180 lines
5.8 KiB
GDScript3
Raw Normal View History

2020-03-21 09:10:26 +00:00
extends Spatial
var loader
var wait_frames
var time_max = 100 # msec
var current_scene_path = null
2020-03-21 09:10:26 +00:00
var current_scene = null
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-03-21 09:10:26 +00:00
Globals.ressource_queue.start()
2020-03-21 09:10:26 +00:00
func _process(_time):
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()
#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 ):
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():
var progress = float(Globals.ressource_queue.get_progress( self.current_scene_path ))
2020-03-21 09:10:26 +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 )
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)
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 ):
self.creature_selected_slot = slot
# 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()
2020-03-21 09:10:26 +00:00
func _on_creatures_menu_ui_select_pressed( filename ):
self.creature_selected_filename = filename
Globals.goto_scene( "res://scenes/game/game.tscn" )
2020-03-21 09:10:26 +00:00
func _on_creature_editor_ui_valid_pressed():
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():
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()
2020-03-21 09:10:26 +00:00
func _on_connexion_ok():
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
func _on_mute_pressed():
pass
# $main_menu/control/option_settings.update_sound_button()
func _on_main_menu_mute_pressed():
Config.msg_debug("_on_main_menu_mute_pressed")
$main_menu/control/option_settings.update_sound_button()