Skip to content

Commit b21dce8

Browse files
authored
Character: Add Character Prefixes and Suffixes for Text Events (#2460)
This new Feature allows to set text segments before and after a text spoken by a character. For instance, you can set the “ or " for your quotation marks or use rich tags, such as colour.
1 parent 7e0f7c8 commit b21dce8

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

addons/dialogic/Editor/CharacterEditor/character_editor.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func _ready() -> void:
165165
## Add general tabs
166166
add_settings_section(load("res://addons/dialogic/Editor/CharacterEditor/char_edit_section_general.tscn").instantiate(), %MainSettingsSections)
167167
add_settings_section(load("res://addons/dialogic/Editor/CharacterEditor/char_edit_section_portraits.tscn").instantiate(), %MainSettingsSections)
168+
add_settings_section(load("res://addons/dialogic/Editor/CharacterEditor/character_prefix_suffix.tscn").instantiate(), %MainSettingsSections)
168169

169170

170171
add_settings_section(load("res://addons/dialogic/Editor/CharacterEditor/char_edit_p_section_main_exports.tscn").instantiate(), %PortraitSettingsSection)
@@ -188,10 +189,12 @@ func _ready() -> void:
188189
func add_settings_section(edit:Control, parent:Node) -> void:
189190
edit.changed.connect(something_changed)
190191
edit.character_editor = self
192+
191193
if edit.has_signal('update_preview'):
192194
edit.update_preview.connect(update_preview)
193195

194196
var button: Button
197+
195198
if edit._show_title():
196199
var hbox := HBoxContainer.new()
197200
hbox.name = edit._get_title()+"BOX"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
@tool
2+
class_name DialogicCharacterPrefixSuffixSection
3+
extends DialogicCharacterEditorMainSection
4+
## Character Editor Section for setting the prefix and suffix of a character.
5+
##
6+
## loads and sets the prefix and suffix of a character.
7+
## Provides [const PREFIX_CUSTOM_KEY] and [const SUFFIX_CUSTOM_KEY] to
8+
## access the `custom_info` dictionary of the [class DialogicCharacter].
9+
10+
@export var prefix_input: LineEdit
11+
@export var suffix_input: LineEdit
12+
13+
## We won't force any prefixes or suffixes onto the player,
14+
## to ensure their games are working as previously when updating.
15+
const DEFAULT_PREFIX = ""
16+
const DEFAULT_SUFFIX = ""
17+
18+
## `custom_info` dictionary keys for the prefix.
19+
const PREFIX_CUSTOM_KEY = "prefix"
20+
21+
## `custom_info` dictionary keys for the prefix.
22+
const SUFFIX_CUSTOM_KEY = "suffix"
23+
24+
var suffix := ""
25+
var prefix := ""
26+
27+
28+
func _ready() -> void:
29+
suffix_input.text_changed.connect(_suffix_changed)
30+
prefix_input.text_changed.connect(_prefix_changed)
31+
32+
33+
func _suffix_changed(text: String) -> void:
34+
suffix = text
35+
36+
37+
func _prefix_changed(text: String) -> void:
38+
prefix = text
39+
40+
41+
func _get_title() -> String:
42+
return "Character Prefix & Suffix"
43+
44+
45+
func _show_title() -> bool:
46+
return true
47+
48+
49+
func _start_opened() -> bool:
50+
return false
51+
52+
53+
func _load_portrait_data(portrait_data: Dictionary) -> void:
54+
_load_prefix_data(portrait_data)
55+
56+
57+
## We load the prefix and suffix from the character's `custom_info` dictionary.
58+
func _load_character(resource: DialogicCharacter) -> void:
59+
_load_prefix_data(resource.custom_info)
60+
61+
62+
func _load_prefix_data(data: Dictionary) -> void:
63+
suffix = data.get(SUFFIX_CUSTOM_KEY, DEFAULT_SUFFIX)
64+
prefix = data.get(PREFIX_CUSTOM_KEY, DEFAULT_PREFIX)
65+
66+
suffix_input.text = suffix
67+
prefix_input.text = prefix
68+
69+
70+
## Whenever the user makes a save to the character, we save the prefix and suffix.
71+
func _save_changes(character: DialogicCharacter) -> DialogicCharacter:
72+
if not character.custom_info:
73+
printerr("[Dialogic] Unable to save Prefix and Suffix, the character is missing.")
74+
return character
75+
76+
character.custom_info[PREFIX_CUSTOM_KEY] = prefix
77+
character.custom_info[SUFFIX_CUSTOM_KEY] = suffix
78+
79+
return character
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://1ctcs6ywjjtd"]
2+
3+
[ext_resource type="PackedScene" uid="uid://dbpkta2tjsqim" path="res://addons/dialogic/Editor/Common/hint_tooltip_icon.tscn" id="1_o3alv"]
4+
[ext_resource type="Script" path="res://addons/dialogic/Editor/CharacterEditor/character_prefix_suffix.gd" id="1_tkxff"]
5+
6+
[node name="CharacterPrefixSuffix" type="GridContainer" node_paths=PackedStringArray("prefix_input", "suffix_input")]
7+
offset_right = 121.0
8+
offset_bottom = 66.0
9+
columns = 2
10+
script = ExtResource("1_tkxff")
11+
prefix_input = NodePath("PrefixInput")
12+
suffix_input = NodePath("SuffixInput")
13+
14+
[node name="Prefix" type="HBoxContainer" parent="."]
15+
layout_mode = 2
16+
17+
[node name="Label" type="Label" parent="Prefix"]
18+
layout_mode = 2
19+
text = "Prefix"
20+
21+
[node name="HintTooltip" parent="Prefix" instance=ExtResource("1_o3alv")]
22+
layout_mode = 2
23+
texture = null
24+
hint_text = "If a character speaks, this appears before their text.
25+
Example: Color Tags or Quotation Marks."
26+
27+
[node name="PrefixInput" type="LineEdit" parent="."]
28+
layout_mode = 2
29+
size_flags_horizontal = 3
30+
caret_blink = true
31+
32+
[node name="Suffix" type="HBoxContainer" parent="."]
33+
layout_mode = 2
34+
35+
[node name="Label" type="Label" parent="Suffix"]
36+
layout_mode = 2
37+
text = "Suffix"
38+
39+
[node name="HintTooltip" parent="Suffix" instance=ExtResource("1_o3alv")]
40+
layout_mode = 2
41+
texture = null
42+
hint_text = "If a character speaks, this appears after their text.
43+
Example: Color Tags or Quotation Marks."
44+
45+
[node name="SuffixInput" type="LineEdit" parent="."]
46+
layout_mode = 2
47+
size_flags_horizontal = 3
48+
caret_blink = true

addons/dialogic/Modules/Text/subsystem_text.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ func update_dialog_text(text: String, instant := false, additional := false) ->
138138
text_node.text = text
139139

140140
else:
141+
var current_character := get_current_speaker()
142+
143+
if current_character:
144+
var character_prefix: String = current_character.custom_info.get(DialogicCharacterPrefixSuffixSection.PREFIX_CUSTOM_KEY, DialogicCharacterPrefixSuffixSection.DEFAULT_PREFIX)
145+
var character_suffix: String = current_character.custom_info.get(DialogicCharacterPrefixSuffixSection.SUFFIX_CUSTOM_KEY, DialogicCharacterPrefixSuffixSection.DEFAULT_SUFFIX)
146+
text = character_prefix + text + character_suffix
147+
141148
text_node.reveal_text(text, additional)
142149

143150
if !text_node.finished_revealing_text.is_connected(_on_dialog_text_finished):

0 commit comments

Comments
 (0)