checheche/Robo-Bus-A31-HMI/common/load/loading.gd
2024-12-06 21:22:11 +08:00

53 lines
1.4 KiB
GDScript

extends CanvasLayer
#var BaseRouter = self
signal complete(node)
var path = "" :
set(value):
path = value
set_process(false)
%ProgressBar.max_value = 100
%ProgressBar.value = 0
var state = ResourceLoader.load_threaded_request(path, "", true)
if state == OK: set_process(true)
var is_add_child = false
func load_path(value,my_time_value = 0,my_is_add_child = false):
self.path = value
time = my_time_value
is_add_child = my_is_add_child
$Control.visible = true
return self
func _ready():
$Control.visible = false
set_process(false)
var time = 0
var progress: Array = []
func _process(_delta):
var load_status = ResourceLoader.load_threaded_get_status(path, progress)
match load_status:
ResourceLoader.THREAD_LOAD_INVALID_RESOURCE, ResourceLoader.THREAD_LOAD_FAILED :
set_process(false)
return
ResourceLoader.THREAD_LOAD_IN_PROGRESS :
%ProgressBar.value = clamp(progress[0]*100,0,70)
ResourceLoader.THREAD_LOAD_LOADED :
set_process(false)
var node = ResourceLoader.load_threaded_get(path).instantiate()
node.visible = false
if is_add_child:
complete.emit(node)
else:
get_tree().get_root().add_child(node)
complete.emit(node)
%ProgressBar.value = clamp(progress[0]*100,0,80)
var tween = get_tree().create_tween()
tween.tween_property(%ProgressBar,"value",100,time)
await get_tree().create_timer(time).timeout
node.visible = true
$Control.visible = false