| 
									
										
										
										
											2023-01-24 23:26:17 +00:00
										 |  |  | class_name WorkerPrompt extends Control | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-25 23:55:18 +00:00
										 |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | signal prompt_completed() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-24 23:26:17 +00:00
										 |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | signal prompted() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var _worker_thread := Thread.new() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | @export | 
					
						
							|  |  |  | var label: Label = null | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | @export | 
					
						
							|  |  |  | var progress: Range = null | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | func prompt(display_message: String, steps: Array) -> void: | 
					
						
							| 
									
										
										
										
											2023-01-25 23:39:10 +00:00
										 |  |  | 	LocalPlayer.override_controls(hidden) | 
					
						
							| 
									
										
										
										
											2023-01-24 23:26:17 +00:00
										 |  |  | 	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() | 
					
						
							| 
									
										
										
										
											2023-01-25 23:55:18 +00:00
										 |  |  | 	prompt_completed.emit() | 
					
						
							| 
									
										
										
										
											2023-01-24 23:26:17 +00:00
										 |  |  | 	hide() | 
					
						
							| 
									
										
										
										
											2023-01-25 23:55:18 +00:00
										 |  |  | 	 |