Skip to content

Commit

Permalink
Allow custom text nodes via text_node property.
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeVR committed Mar 12, 2024
1 parent 64ca5cf commit 3d52f8f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 16 additions & 3 deletions addons/dialogic/Modules/Choice/node_choice_button.gd
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
## 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
## Can be set to play this sound when hovered. Requires a sibling DialogicNode_ButtonSound node.
@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()
10 changes: 6 additions & 4 deletions addons/dialogic/Modules/Choice/subsystem_choices.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3d52f8f

Please sign in to comment.