Skip to content

Commit

Permalink
Character: Add Character Prefixes and Suffixes for Text Events (#2460)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CakeVR authored Nov 11, 2024
1 parent 7e0f7c8 commit b21dce8
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addons/dialogic/Editor/CharacterEditor/character_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func _ready() -> void:
## Add general tabs
add_settings_section(load("res://addons/dialogic/Editor/CharacterEditor/char_edit_section_general.tscn").instantiate(), %MainSettingsSections)
add_settings_section(load("res://addons/dialogic/Editor/CharacterEditor/char_edit_section_portraits.tscn").instantiate(), %MainSettingsSections)
add_settings_section(load("res://addons/dialogic/Editor/CharacterEditor/character_prefix_suffix.tscn").instantiate(), %MainSettingsSections)


add_settings_section(load("res://addons/dialogic/Editor/CharacterEditor/char_edit_p_section_main_exports.tscn").instantiate(), %PortraitSettingsSection)
Expand All @@ -188,10 +189,12 @@ func _ready() -> void:
func add_settings_section(edit:Control, parent:Node) -> void:
edit.changed.connect(something_changed)
edit.character_editor = self

if edit.has_signal('update_preview'):
edit.update_preview.connect(update_preview)

var button: Button

if edit._show_title():
var hbox := HBoxContainer.new()
hbox.name = edit._get_title()+"BOX"
Expand Down
79 changes: 79 additions & 0 deletions addons/dialogic/Editor/CharacterEditor/character_prefix_suffix.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@tool
class_name DialogicCharacterPrefixSuffixSection
extends DialogicCharacterEditorMainSection
## Character Editor Section for setting the prefix and suffix of a character.
##
## loads and sets the prefix and suffix of a character.
## Provides [const PREFIX_CUSTOM_KEY] and [const SUFFIX_CUSTOM_KEY] to
## access the `custom_info` dictionary of the [class DialogicCharacter].

@export var prefix_input: LineEdit
@export var suffix_input: LineEdit

## We won't force any prefixes or suffixes onto the player,
## to ensure their games are working as previously when updating.
const DEFAULT_PREFIX = ""
const DEFAULT_SUFFIX = ""

## `custom_info` dictionary keys for the prefix.
const PREFIX_CUSTOM_KEY = "prefix"

## `custom_info` dictionary keys for the prefix.
const SUFFIX_CUSTOM_KEY = "suffix"

var suffix := ""
var prefix := ""


func _ready() -> void:
suffix_input.text_changed.connect(_suffix_changed)
prefix_input.text_changed.connect(_prefix_changed)


func _suffix_changed(text: String) -> void:
suffix = text


func _prefix_changed(text: String) -> void:
prefix = text


func _get_title() -> String:
return "Character Prefix & Suffix"


func _show_title() -> bool:
return true


func _start_opened() -> bool:
return false


func _load_portrait_data(portrait_data: Dictionary) -> void:
_load_prefix_data(portrait_data)


## We load the prefix and suffix from the character's `custom_info` dictionary.
func _load_character(resource: DialogicCharacter) -> void:
_load_prefix_data(resource.custom_info)


func _load_prefix_data(data: Dictionary) -> void:
suffix = data.get(SUFFIX_CUSTOM_KEY, DEFAULT_SUFFIX)
prefix = data.get(PREFIX_CUSTOM_KEY, DEFAULT_PREFIX)

suffix_input.text = suffix
prefix_input.text = prefix


## Whenever the user makes a save to the character, we save the prefix and suffix.
func _save_changes(character: DialogicCharacter) -> DialogicCharacter:
if not character.custom_info:
printerr("[Dialogic] Unable to save Prefix and Suffix, the character is missing.")
return character

character.custom_info[PREFIX_CUSTOM_KEY] = prefix
character.custom_info[SUFFIX_CUSTOM_KEY] = suffix

return character
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[gd_scene load_steps=3 format=3 uid="uid://1ctcs6ywjjtd"]

[ext_resource type="PackedScene" uid="uid://dbpkta2tjsqim" path="res://addons/dialogic/Editor/Common/hint_tooltip_icon.tscn" id="1_o3alv"]
[ext_resource type="Script" path="res://addons/dialogic/Editor/CharacterEditor/character_prefix_suffix.gd" id="1_tkxff"]

[node name="CharacterPrefixSuffix" type="GridContainer" node_paths=PackedStringArray("prefix_input", "suffix_input")]
offset_right = 121.0
offset_bottom = 66.0
columns = 2
script = ExtResource("1_tkxff")
prefix_input = NodePath("PrefixInput")
suffix_input = NodePath("SuffixInput")

[node name="Prefix" type="HBoxContainer" parent="."]
layout_mode = 2

[node name="Label" type="Label" parent="Prefix"]
layout_mode = 2
text = "Prefix"

[node name="HintTooltip" parent="Prefix" instance=ExtResource("1_o3alv")]
layout_mode = 2
texture = null
hint_text = "If a character speaks, this appears before their text.
Example: Color Tags or Quotation Marks."

[node name="PrefixInput" type="LineEdit" parent="."]
layout_mode = 2
size_flags_horizontal = 3
caret_blink = true

[node name="Suffix" type="HBoxContainer" parent="."]
layout_mode = 2

[node name="Label" type="Label" parent="Suffix"]
layout_mode = 2
text = "Suffix"

[node name="HintTooltip" parent="Suffix" instance=ExtResource("1_o3alv")]
layout_mode = 2
texture = null
hint_text = "If a character speaks, this appears after their text.
Example: Color Tags or Quotation Marks."

[node name="SuffixInput" type="LineEdit" parent="."]
layout_mode = 2
size_flags_horizontal = 3
caret_blink = true
7 changes: 7 additions & 0 deletions addons/dialogic/Modules/Text/subsystem_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ func update_dialog_text(text: String, instant := false, additional := false) ->
text_node.text = text

else:
var current_character := get_current_speaker()

if current_character:
var character_prefix: String = current_character.custom_info.get(DialogicCharacterPrefixSuffixSection.PREFIX_CUSTOM_KEY, DialogicCharacterPrefixSuffixSection.DEFAULT_PREFIX)
var character_suffix: String = current_character.custom_info.get(DialogicCharacterPrefixSuffixSection.SUFFIX_CUSTOM_KEY, DialogicCharacterPrefixSuffixSection.DEFAULT_SUFFIX)
text = character_prefix + text + character_suffix

text_node.reveal_text(text, additional)

if !text_node.finished_revealing_text.is_connected(_on_dialog_text_finished):
Expand Down

0 comments on commit b21dce8

Please sign in to comment.