Update
This commit is contained in:
8
demos/7. handling input/handling_input_dialogue.gd
Normal file
8
demos/7. handling input/handling_input_dialogue.gd
Normal file
@@ -0,0 +1,8 @@
|
||||
extends DialogueEngine
|
||||
|
||||
var player_name : String # will be set by the UI code
|
||||
|
||||
func _setup() -> void:
|
||||
add_text_entry("Welcome adventurer. May I know you name?").set_metadata(&"get_player_name", "The UI code will act accordingly and inject player_name into DialogueEngine.")
|
||||
add_text_entry("The legendary {player_name}!? Please, follow me this way. I will personally show you our guild.").set_format({"player_name" : get.bind("player_name")}, DialogueEntry.FORMAT_FUNCTION)
|
||||
add_text_entry("Press <Enter> or <Space> to exit.")
|
||||
64
demos/7. handling input/handling_input_log.gd
Normal file
64
demos/7. handling input/handling_input_log.gd
Normal file
@@ -0,0 +1,64 @@
|
||||
extends VBoxContainer
|
||||
|
||||
@export var dialogue_gdscript : GDScript = null
|
||||
var dialogue_engine : DialogueEngine = null
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
dialogue_engine = dialogue_gdscript.new()
|
||||
dialogue_engine.dialogue_started.connect(__on_dialogue_started)
|
||||
dialogue_engine.dialogue_continued.connect(__on_dialogue_continued)
|
||||
dialogue_engine.dialogue_finished.connect(__on_dialogue_finished)
|
||||
dialogue_engine.dialogue_cancelled.connect(__on_dialogue_cancelled)
|
||||
|
||||
func _input(p_input_event : InputEvent) -> void:
|
||||
if p_input_event.is_action_pressed(&"ui_accept"):
|
||||
dialogue_engine.advance()
|
||||
accept_event()
|
||||
|
||||
|
||||
func __on_dialogue_started() -> void:
|
||||
print("Dialogue Started!")
|
||||
|
||||
|
||||
func __on_dialogue_continued(p_dialogue_entry : DialogueEntry) -> void:
|
||||
var label : RichTextLabel = RichTextLabel.new()
|
||||
label.set_use_bbcode(true)
|
||||
label.set_fit_content(true)
|
||||
if p_dialogue_entry.has_metadata("author"):
|
||||
var author : String = p_dialogue_entry.get_metadata("author")
|
||||
label.set_text(" > " + author + ": " + p_dialogue_entry.get_formatted_text())
|
||||
else:
|
||||
label.set_text(" > " + p_dialogue_entry.get_formatted_text())
|
||||
add_child(label)
|
||||
|
||||
if p_dialogue_entry.has_metadata(&"get_player_name"):
|
||||
__get_player_name()
|
||||
|
||||
|
||||
func __on_dialogue_finished() -> void:
|
||||
print("Dialogue Finished! Exiting...")
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func __on_dialogue_cancelled() -> void:
|
||||
print("Dialogue Cancelled! Exiting...")
|
||||
get_tree().quit()
|
||||
|
||||
# Must return player name to update the variable within DialogueEngine
|
||||
func __get_player_name() -> void:
|
||||
var line_edit : LineEdit = LineEdit.new()
|
||||
add_child(line_edit)
|
||||
var p_data : Array = []
|
||||
line_edit.text_submitted.connect(func(text : String) -> void:
|
||||
p_data.push_back(text)
|
||||
)
|
||||
line_edit.grab_focus()
|
||||
line_edit.set_placeholder("Enter your name.")
|
||||
set_process_input(false)
|
||||
await line_edit.text_submitted
|
||||
line_edit.set_editable(false)
|
||||
@warning_ignore("unsafe_property_access")
|
||||
dialogue_engine.player_name = p_data[0]
|
||||
set_process_input(true)
|
||||
dialogue_engine.advance()
|
||||
26
demos/7. handling input/handling_input_log.tscn
Normal file
26
demos/7. handling input/handling_input_log.tscn
Normal file
@@ -0,0 +1,26 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cc22y2sa14se6"]
|
||||
|
||||
[ext_resource type="Script" path="res://demos/7. handling input/handling_input_log.gd" id="1_4r4r1"]
|
||||
[ext_resource type="Script" path="res://demos/7. handling input/handling_input_dialogue.gd" id="2_ti25x"]
|
||||
|
||||
[node name="DialogueEngineDemoVBoxContainer" type="VBoxContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_4r4r1")
|
||||
dialogue_gdscript = ExtResource("2_ti25x")
|
||||
|
||||
[node name="DialogueEngineDemoQuickStartPanelContainer" type="PanelContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="DialogueEngineDemoQuickStartLabel" type="Label" parent="DialogueEngineDemoQuickStartPanelContainer"]
|
||||
layout_mode = 2
|
||||
text = "Press <Enter> or <Space> to progress the dialogue."
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="LogRichTextLabel" type="RichTextLabel" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Log:"
|
||||
fit_content = true
|
||||
Reference in New Issue
Block a user