Update
This commit is contained in:
21
demos/4. branching condition/branching_condition_dialogue.gd
Normal file
21
demos/4. branching condition/branching_condition_dialogue.gd
Normal file
@@ -0,0 +1,21 @@
|
||||
extends DialogueEngine
|
||||
|
||||
var have_we_talked_before : bool = false
|
||||
|
||||
enum branch {
|
||||
STRANGERS,
|
||||
ACQUAINTANCES,
|
||||
}
|
||||
|
||||
func __have_we_talked_before() -> bool:
|
||||
return have_we_talked_before
|
||||
|
||||
func _setup() -> void:
|
||||
add_text_entry("Hello!")
|
||||
var condition_entry : DialogueEntry = add_conditional_entry(__have_we_talked_before)
|
||||
var if_true : DialogueEntry = add_text_entry("Hey! We meet again!", branch.STRANGERS)
|
||||
var if_false : DialogueEntry = add_text_entry("It's nice to meet you!", branch.ACQUAINTANCES)
|
||||
condition_entry.set_condition_goto_ids(if_true.get_id(), if_false.get_id())
|
||||
add_text_entry("<Press 'Enter' or 'Space' to exit>")
|
||||
|
||||
dialogue_finished.connect(func() -> void: have_we_talked_before = true)
|
||||
38
demos/4. branching condition/branching_condition_log.gd
Normal file
38
demos/4. branching condition/branching_condition_log.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
extends VBoxContainer
|
||||
|
||||
@export var dialogue_gdscript : GDScript = null
|
||||
var dialogue_engine : DialogueEngine = null
|
||||
|
||||
var dialogue_finished_count : int = 0
|
||||
|
||||
func _ready() -> void:
|
||||
dialogue_engine = dialogue_gdscript.new()
|
||||
dialogue_engine.dialogue_continued.connect(__on_dialogue_continued)
|
||||
dialogue_engine.dialogue_finished.connect(__on_dialogue_finished)
|
||||
|
||||
|
||||
func _input(p_input_event : InputEvent) -> void:
|
||||
if p_input_event.is_action_pressed(&"ui_accept"):
|
||||
dialogue_engine.advance()
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
func __on_dialogue_finished() -> void:
|
||||
if dialogue_finished_count > 0:
|
||||
get_tree().quit()
|
||||
return
|
||||
dialogue_finished_count += 1
|
||||
var label : RichTextLabel = RichTextLabel.new()
|
||||
label.set_fit_content(true)
|
||||
label.set_text("<Some time passes>")
|
||||
add_child(label)
|
||||
|
||||
|
||||
26
demos/4. branching condition/branching_condition_log.tscn
Normal file
26
demos/4. branching condition/branching_condition_log.tscn
Normal file
@@ -0,0 +1,26 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://bl1d3ktmm0s7f"]
|
||||
|
||||
[ext_resource type="Script" path="res://demos/4. branching condition/branching_condition_log.gd" id="1_7x7u2"]
|
||||
[ext_resource type="Script" path="res://demos/4. branching condition/branching_condition_dialogue.gd" id="2_yhcl2"]
|
||||
|
||||
[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_7x7u2")
|
||||
dialogue_gdscript = ExtResource("2_yhcl2")
|
||||
|
||||
[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