Skip to content

Commit

Permalink
feat: adds option to sync talking animation finishing with either aud…
Browse files Browse the repository at this point in the history
…io or text; if with text, now finishes when text is done rendering.
  • Loading branch information
BHSDuncan authored and StraToN committed Dec 4, 2022
1 parent f64b596 commit 13a6005
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
5 changes: 5 additions & 0 deletions addons/escoria-core/game/scenes/dialogs/esc_dialog_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ func finish():
# The say command has been interrupted, cancel the dialog display
func interrupt():
pass


# To be called if voice audio has finished.
func voice_audio_finished():
pass
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var _keytext_regex: RegEx = RegEx.new()

var _ready_to_say: bool

var _stop_talking_animation_on_option: String


# Constructor
func _init() -> void:
Expand All @@ -36,6 +38,8 @@ func initialize(character: String, type: String, text: String) -> void:
_character = character
_type = type
_text = text
_stop_talking_animation_on_option = \
ESCProjectSettingsManager.get_setting(SimpleDialogPlugin.STOP_TALKING_ANIMATION_ON)


func handle_input(_event):
Expand Down Expand Up @@ -125,6 +129,12 @@ func enter():
as ESCSpeechPlayer
).set_state(_speech_resource)

if _stop_talking_animation_on_option == SimpleDialogPlugin.STOP_TALKING_ANIMATION_ON_END_OF_AUDIO:
(
escoria.object_manager.get_object(escoria.object_manager.SPEECH).node\
as ESCSpeechPlayer
).stream.connect("finished", self, "_on_audio_finished", [], CONNECT_ONESHOT)

var translated_text: String = tr(matches.get_string("key"))

# Only update the text if the translated text was found; otherwise, raise
Expand Down Expand Up @@ -189,3 +199,7 @@ func _get_voice_file(key: String, start: String = "") -> String:
func _on_say_visible() -> void:
escoria.logger.trace(self, "Dialog State Machine: 'say' -> 'visible'")
emit_signal("finished", "visible")


func _on_audio_finished() -> void:
_dialog_manager.voice_audio_finished()
6 changes: 6 additions & 0 deletions addons/escoria-dialog-simple/esc_dialog_simple.gd
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ func interrupt():

_dialog_player.remove_child(_type_player)
emit_signal("say_finished")


# To be called if voice audio has finished.
func voice_audio_finished():
if _type_player != null:
_type_player.voice_audio_finished()
27 changes: 26 additions & 1 deletion addons/escoria-dialog-simple/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ const TEXT_TIME_PER_LETTER_MS_FAST = "%s/text_time_per_fast_letter_ms" % SETTING
const READING_SPEED_IN_WPM = "%s/reading_speed_in_wpm" % SETTINGS_ROOT
const CLEAR_TEXT_BY_CLICK_ONLY = "%s/clear_text_by_click_only" % SETTINGS_ROOT
const LEFT_CLICK_ACTION = "%s/left_click_action" % SETTINGS_ROOT
const STOP_TALKING_ANIMATION_ON = "%s/stop_talking_animation_on" % SETTINGS_ROOT

const LEFT_CLICK_ACTION_SPEED_UP = "Speed up"
const LEFT_CLICK_ACTION_INSTANT_FINISH = "Instant finish"
const LEFT_CLICK_ACTION_NOTHING = "None"

const STOP_TALKING_ANIMATION_ON_END_OF_TEXT = "End of text"
const STOP_TALKING_ANIMATION_ON_END_OF_AUDIO = "End of audio"

const READING_SPEED_IN_WPM_DEFAULT_VALUE = 200
const TEXT_TIME_PER_LETTER_MS_DEFAULT_VALUE = 100
const TEXT_TIME_PER_LETTER_MS_FAST_DEFAULT_VALUE = 25
Expand All @@ -29,6 +33,11 @@ var leftClickActions: Array = [
LEFT_CLICK_ACTION_NOTHING
]

var stopTalkingAnimationOnOptions: Array = [
STOP_TALKING_ANIMATION_ON_END_OF_TEXT,
STOP_TALKING_ANIMATION_ON_END_OF_AUDIO
]


# Override function to return the plugin name.
func get_plugin_name():
Expand Down Expand Up @@ -65,6 +74,10 @@ func disable_plugin():
ESCProjectSettingsManager.remove_setting(
LEFT_CLICK_ACTION
)

ESCProjectSettingsManager.remove_setting(
STOP_TALKING_ANIMATION_ON
)

EscoriaPlugin.deregister_dialog_manager(MANAGER_CLASS)

Expand Down Expand Up @@ -127,14 +140,26 @@ func enable_plugin():

ESCProjectSettingsManager.register_setting(
LEFT_CLICK_ACTION,
"Speed up",
LEFT_CLICK_ACTION_SPEED_UP,
{
"type": TYPE_STRING,
"hint": PROPERTY_HINT_ENUM,
"hint_string": leftClickActionsString
}
)

var stopTalkingAnimationOnOptionsString: String = ",".join(stopTalkingAnimationOnOptions)

ESCProjectSettingsManager.register_setting(
STOP_TALKING_ANIMATION_ON,
STOP_TALKING_ANIMATION_ON_END_OF_AUDIO,
{
"type": TYPE_STRING,
"hint": PROPERTY_HINT_ENUM,
"hint_string": stopTalkingAnimationOnOptionsString
}
)

else:
get_editor_interface().set_plugin_enabled(
get_plugin_name(),
Expand Down
17 changes: 13 additions & 4 deletions addons/escoria-dialog-simple/types/avatar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,20 @@ func finish():
tween.start()


# To be called if voice audio has finished.
func voice_audio_finished():
if avatar_node and avatar_node.texture:
avatar_node.texture.current_frame = 0
avatar_node.texture.pause = true


# The dialog line was printed, start the waiting time and then finish
# the dialog
func _on_dialog_line_typed(object, key):
if avatar_node.texture is AnimatedTexture:
avatar_node.texture.current_frame = 0
avatar_node.texture.pause = true

text_node.visible_characters = -1

var time_to_disappear: float = _calculate_time_to_disappear()
Expand All @@ -196,10 +207,6 @@ func _get_number_of_words() -> int:

# Ending the dialog
func _on_dialog_finished():
if avatar_node.texture is AnimatedTexture:
avatar_node.texture.current_frame = 0
avatar_node.texture.pause = true

# Only trigger to clear the text if we aren't limiting the clearing trigger to a click.
if not ESCProjectSettingsManager.get_setting(SimpleDialogPlugin.CLEAR_TEXT_BY_CLICK_ONLY):
emit_signal("say_finished")
Expand All @@ -218,3 +225,5 @@ func _on_resumed():
if not tween.is_active():
is_paused = false
tween.resume_all()


8 changes: 6 additions & 2 deletions addons/escoria-dialog-simple/types/floating.gd
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,15 @@ func finish():
tween.start()


# To be called if voice audio has finished.
func voice_audio_finished():
_stop_character_talking()


# The dialog line was printed, start the waiting time and then finish
# the dialog
func _on_dialog_line_typed(object, key):
_stop_character_talking()
text_node.visible_characters = -1

var time_to_disappear: float = _calculate_time_to_disappear()
Expand All @@ -220,8 +226,6 @@ func _get_number_of_words() -> int:

# Ending the dialog
func _on_dialog_finished():
_stop_character_talking()

# Only trigger to clear the text if we aren't limiting the clearing trigger to a click.
if not ESCProjectSettingsManager.get_setting(SimpleDialogPlugin.CLEAR_TEXT_BY_CLICK_ONLY):
emit_signal("say_finished")
Expand Down

0 comments on commit 13a6005

Please sign in to comment.