class_name WorkerPrompt extends Control ## ## The work being performed by the prompt has ended. ## signal prompt_completed() ## ## The prompt has been started. ## signal prompted() var _worker_thread := Thread.new() ## ## Used to display a message from the prompt or [code]null[/code] to not display anything. ## @export var label: Label = null ## ## Used to display the progress of the prompt or [code]null[/code] to not display anything. ## @export var progress: Range = null ## ## Starts the prompt, emitting [signal prompted]. ## ## [signal prompt_completed] is emitted when the work being performed by the prompt has ended. ## func prompt(display_message: String, steps: Array) -> void: LocalPlayer.override_controls(hidden) show() prompted.emit() if label != null: label.text = display_message _worker_thread.start(func () -> void: var count := steps.size() var total := float(count) for i in count: steps[i].call() if progress != null: progress.value = i / total) while _worker_thread.is_alive(): await get_tree().process_frame _worker_thread.wait_to_finish() prompt_completed.emit() hide()