forked from Nekojimi/JackIt
71 lines
2.0 KiB
GDScript
71 lines
2.0 KiB
GDScript
extends Control
|
|
class_name PromptManager
|
|
|
|
@export var multi_choice_button_scene: PackedScene = preload("res://objects/multi_choice_button.tscn")
|
|
@export var prompt_text_format: String = "[center]%s[/center]"
|
|
|
|
enum PromptType {TEXT, LONG_TEXT, NUMBER, MULTIPLE_CHOICE, COLOUR, PLAYER}
|
|
|
|
var current_prompt: Dictionary
|
|
|
|
var player: Player:
|
|
set(value):
|
|
if player != null:
|
|
player.disconnect("prompt_changed", display_prompt)
|
|
player = value
|
|
player.connect("prompt_changed", display_prompt)
|
|
display_prompt(player.current_prompt)
|
|
|
|
func display_prompt(prompt: Dictionary):
|
|
if prompt.is_empty():
|
|
visible = false
|
|
return
|
|
|
|
print("Displaying prompt \"%s\"" % prompt["text"])
|
|
current_prompt = prompt
|
|
|
|
visible = true
|
|
|
|
# hide all children
|
|
for child in get_children():
|
|
child.visible = false
|
|
|
|
$PromptLabel.text = prompt_text_format % prompt["text"]
|
|
$PromptLabel.visible = true
|
|
|
|
# clear all prompt buttons
|
|
for button in $MultichoiceButtons.get_children():
|
|
$MultichoiceButtons.remove_child(button)
|
|
button.queue_free()
|
|
|
|
if prompt["type"] == PromptType.LONG_TEXT:
|
|
$LongTextEdit.visible = true
|
|
$LongTextEdit.text = ""
|
|
$SubmitButton.visible = true
|
|
elif prompt["type"] == PromptType.TEXT:
|
|
$LineEdit.visible = true
|
|
$LineEdit.text = ""
|
|
$SubmitButton.visible = true
|
|
#$LongTextEdit.placeholder_text = prompt.options
|
|
elif prompt["type"] == PromptType.MULTIPLE_CHOICE:
|
|
$MultichoiceButtons.visible = true
|
|
for option in prompt.options:
|
|
var button: Button = multi_choice_button_scene.instantiate() as Button
|
|
button.text = option
|
|
$MultichoiceButtons.add_child(button)
|
|
button.connect("pressed", submit_result.bind(option))
|
|
|
|
func submit_button_pressed() -> void:
|
|
if current_prompt.is_empty():
|
|
return
|
|
match current_prompt["type"] as PromptType:
|
|
PromptType.TEXT:
|
|
submit_result($LineEdit.text)
|
|
PromptType.LONG_TEXT:
|
|
submit_result($LongTextEdit.text)
|
|
|
|
func submit_result(result: String):
|
|
player.submit_prompt_answer.rpc_id(1, result)
|
|
visible = false
|
|
current_prompt.clear()
|