extends Control ## Provides methods and pre-instantiated prompts that can be easily arranged. class_name Prompter signal performed(action: String) var _prompts : Dictionary[StringName, Control] = {} static var _instance : Prompter = null func _ready() -> void: _register_prompts() clear() func _register_prompts() -> void: assert(not _instance, "Cannot have two prompters (are you trying to run the prompter itself?)") _instance = self for prompt in get_tree().get_nodes_in_group("prompts") as Array[PromptButton]: _prompts[prompt.name] = prompt prompt.get_parent().remove_child(prompt) prompt.performed.connect(_perform) prints("Prompter.gd:", "registered", prompt) func _perform(action : StringName): prints("Prompter.gd:", "PERFORMED", action) performed.emit(action) func _clear(container: Control) -> void: for child in container.get_children(): container.remove_child(child) func _clearInteraction() -> void: %Interaction.text = "" %Interaction.get_parent().hide() func _clearInstruction() -> void: %Instruction.text = "" %Instruction.get_parent().hide() func _show(container: Control, controls: Array[Control], overrides: Array[StringName] = []) -> void: for i in range(len(controls)): var control := controls[i] var override : StringName = overrides[i] if overrides else &"" container.add_child(control) control.appear(override) func test() -> void: await get_tree().create_timer(0.5).timeout var prompts := pick("ui_cancel", "ui_accept") show_left_bottom(prompts) interaction("Hello World.") instruction("lorem ipsum dolor sit amet") await get_tree().create_timer(2.5).timeout clear() func interaction(text: String) -> void: if not text: _clearInteraction() %Interaction.text = text %Interaction.get_parent().show() func instruction(text: String) -> void: if not text: _clearInstruction() %Instruction.text = text %Instruction.get_parent().show() func show_left_bottom(controls: Array[Control], overrides: Array[StringName] = []) -> void: _show(%LeftBottom, controls, overrides) func clear() -> void: _clear(%LeftBottom) _clear(%RightBottom) _clearInteraction() _clearInstruction() ## Selects a list of up to three prompts to be passed to the show_xxxxx() functions func pick(p0: StringName, p1: StringName = "", p2: StringName = "") -> Array[Control]: var result : Array[Control] = [] assert(p0 in _prompts, p0 + " is not a known prompt.") assert(not p1 or p1 in _prompts, p1 + " is not a known prompt.") assert(not p2 or p2 in _prompts, p2 + " is not a known prompt.") result.append(_prompts[p0]) if p1: result.append(_prompts[p1]) if p2: result.append(_prompts[p2]) return result