From 3d52f8f631e0a33d77999f78b4d59caf721671ae Mon Sep 17 00:00:00 2001 From: Cake Date: Tue, 12 Mar 2024 09:07:47 +0100 Subject: [PATCH] Allow custom text nodes via `text_node` property. --- .../Modules/Choice/node_choice_button.gd | 19 ++++++++++++++++--- .../Modules/Choice/subsystem_choices.gd | 10 ++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/addons/dialogic/Modules/Choice/node_choice_button.gd b/addons/dialogic/Modules/Choice/node_choice_button.gd index ae5de2a99..62aca1cba 100644 --- a/addons/dialogic/Modules/Choice/node_choice_button.gd +++ b/addons/dialogic/Modules/Choice/node_choice_button.gd @@ -1,10 +1,12 @@ +## Dialogic Node that displays choices. + class_name DialogicNode_ChoiceButton extends Button -## Dialogic Node that displays choices. + ## Used to identify what choices to put on. If you leave it at -1, choices will be distributed automatically. -@export var choice_index:int = -1 +@export var choice_index: int = -1 ## Can be set to play this sound when pressed. Requires a sibling DialogicNode_ButtonSound node. @export var sound_pressed: AudioStream @@ -12,9 +14,20 @@ extends Button @export var sound_hover: AudioStream ## Can be set to play this sound when focused. Requires a sibling DialogicNode_ButtonSound node. @export var sound_focus: AudioStream +## If set, the text will be set on this node's `text` property instead. +@export var text_node: Node + + +## Called when the text changes. +func _set_text_changed(new_text: String) -> void: + if text_node == null: + text = new_text + + else: + text_node.text = new_text -func _ready(): +func _ready() -> void: add_to_group('dialogic_choice_button') shortcut_in_tooltip = false hide() diff --git a/addons/dialogic/Modules/Choice/subsystem_choices.gd b/addons/dialogic/Modules/Choice/subsystem_choices.gd index 73ebf39f1..3ee43f831 100644 --- a/addons/dialogic/Modules/Choice/subsystem_choices.gd +++ b/addons/dialogic/Modules/Choice/subsystem_choices.gd @@ -117,15 +117,17 @@ func show_current_choices(instant:=true) -> void: func show_choice(button_index:int, text:String, enabled:bool, event_index:int) -> void: var idx := 1 var shown_at_all := false - for node:DialogicNode_ChoiceButton in get_tree().get_nodes_in_group('dialogic_choice_button'): + for node: DialogicNode_ChoiceButton in get_tree().get_nodes_in_group('dialogic_choice_button'): if !node.get_parent().is_visible_in_tree(): continue if (node.choice_index == button_index) or (idx == button_index and node.choice_index == -1): node.show() + + if dialogic.has_subsystem('Text'): - node.text = dialogic.Text.parse_text(text, true, true, false, true, false, false) - else: - node.text = text + text = dialogic.Text.parse_text(text, true, true, false, true, false, false) + + node._set_text_changed(text) if idx == 1 and autofocus_first_choice: node.grab_focus()