This commit is contained in:
2024-09-07 15:01:45 -07:00
parent fbaf698852
commit b470a9d2fe
116 changed files with 15968 additions and 24 deletions

View File

@@ -0,0 +1,31 @@
extends DialogueEngine
enum {
DEFAULT_TOPIC = 0, # this is the branch used by default unless set_branch_id() is used
GO_BACK_TO_SLEEP = 1,
KEEP_WORKING = 2
}
func _setup() -> void:
var entry : DialogueEntry = add_text_entry("The storm rages right outside the window. I should...")
var option_id_1 : int = entry.add_option("Go back to sleep.")
var option_id_2 : int = entry.add_option("Get back to work.")
var option_id_1_entry : DialogueEntry = add_text_entry("That's right, sleep is for the strong 💪.", GO_BACK_TO_SLEEP)
entry.set_option_goto_id(option_id_1, option_id_1_entry.get_id())
var option_id_2_entry : DialogueEntry = add_text_entry("That's right, let's get back to work 🫡", KEEP_WORKING)
entry.set_option_goto_id(option_id_2, option_id_2_entry.get_id())
# Join branches into the default topic (i.e. branch id 0)
var default_topic : DialogueEntry = add_text_entry("Some time passes...")
option_id_1_entry.set_goto_id(default_topic.get_id())
option_id_2_entry.set_goto_id(default_topic.get_id())
# None of the following entries will be connected on the graph and won't be shown when advancing the dialogue
add_text_entry("A sleep entry skipped due to missing goto against this entry.", GO_BACK_TO_SLEEP)
add_text_entry("A working entry due to missing goto against this entry.", KEEP_WORKING)
add_text_entry("<Press 'Space' or 'Enter' to quit>")

View File

@@ -0,0 +1,65 @@
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() # to avoid hidding an button due to the input event travelling through the children
func __on_dialogue_started() -> void:
print("Dialogue Started!")
var enabled_buttons : Array[Button] = []
func __on_dialogue_continued(p_dialogue_entry : DialogueEntry) -> void:
var label : RichTextLabel = RichTextLabel.new()
label.set_use_bbcode(true)
label.set_fit_content(true)
label.set_text(" > " + p_dialogue_entry.get_text())
add_child(label)
if p_dialogue_entry.has_options():
for option_id : int in range(0, p_dialogue_entry.get_option_count()):
var option_text : String = p_dialogue_entry.get_option_text(option_id)
var button : Button = Button.new()
button.set_text(option_text)
add_child(button)
if option_id == 0:
button.grab_focus()
button.pressed.connect(__advance_dialogue_with_chosen_option.bind(option_id))
enabled_buttons.push_back(button)
set_process_input(false)
func __advance_dialogue_with_chosen_option(p_option_id : int) -> void:
for button : Button in enabled_buttons:
button.set_disabled(true)
enabled_buttons.clear()
var current_entry : DialogueEntry = dialogue_engine.get_current_entry()
current_entry.choose_option(p_option_id)
dialogue_engine.advance()
set_process_input(true)
func __on_dialogue_finished() -> void:
print("Dialogue Finished! Exiting...")
get_tree().quit()
func __on_dialogue_cancelled() -> void:
print("Dialogue Cancelled! Exiting...")
get_tree().quit()

View File

@@ -0,0 +1,26 @@
[gd_scene load_steps=3 format=3 uid="uid://c1803quu2vtn"]
[ext_resource type="Script" path="res://demos/5. branching options dialogue/branching_options_dialogue_log.gd" id="1_0yldt"]
[ext_resource type="Script" path="res://demos/5. branching options dialogue/branching_options_dialogue.gd" id="2_h7u25"]
[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_0yldt")
dialogue_gdscript = ExtResource("2_h7u25")
[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