fix: Say command fixes (#452)

Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
Dennis Ploeger
2021-11-21 21:10:22 +01:00
committed by GitHub
parent e2f68fb0bf
commit dbc7415aaf
6 changed files with 82 additions and 15 deletions

View File

@@ -25,7 +25,7 @@ func configure() -> ESCCommandArgumentDescriptor:
[
null,
null,
ProjectSettings.get_setting("escoria/ui/default_dialog_type")
""
]
)

View File

@@ -3,6 +3,10 @@ extends Node
class_name ESCDialogPlayer
# A regular expression that separates the translation key from the text
const KEYTEXT_REGEX = "^((?<key>[^:]+):)?(?<text>.+)"
# Emitted when an answer as chosem
#
# ##### Parameters
@@ -22,8 +26,13 @@ var is_speaking: bool = false
var _dialog_manager: ESCDialogManager = null
# Regular expression object for the separation of key and text
var _keytext_regex: RegEx = RegEx.new()
# Register the dialog player and load the dialog resources
func _ready():
_keytext_regex.compile(KEYTEXT_REGEX)
if !Engine.is_editor_hint():
escoria.dialog_player = self
@@ -81,6 +90,8 @@ func _get_voice_file(key: String, start: String = "") -> String:
# - type: UI to use for the dialog
# - text: Text to say
func say(character: String, type: String, text: String) -> void:
if type == "":
type = ProjectSettings.get_setting("escoria/ui/default_dialog_type")
is_speaking = true
for _manager_class in ProjectSettings.get_setting(
"escoria/ui/dialog_managers"
@@ -92,22 +103,32 @@ func say(character: String, type: String, text: String) -> void:
if _dialog_manager == null:
escoria.logger.report_errors(
"esc_dialog_player.gd: Unknown type",
"esc_dialog_player.gd:say",
[
"No dialog manager supports the type %s" % type
]
)
var _key_text = text.split(":")
if _key_text.size() == 1:
text = _key_text[0]
elif _key_text.size() >= 2:
var _speech_resource = _get_voice_file(_key_text[0])
var matches = _keytext_regex.search(text)
if not matches:
escoria.logger.report_errors(
"esc_dialog_player.gd:say",
[
"Unexpected text encountered %s" % text
]
)
var key = matches.get_string("key")
if matches.get_string("key") != "":
var _speech_resource = _get_voice_file(
matches.get_string("key")
)
if _speech_resource != "":
(
escoria.object_manager.get_object("_speech").node\
as ESCSpeechPlayer
).set_state(_speech_resource)
text = tr(_key_text[0])
text = tr(matches.get_string("key"))
else:
text = matches.get_string("text")
_dialog_manager.say(self, character, text, type)
yield(_dialog_manager, "say_finished")

View File

@@ -46,11 +46,22 @@ func _ready():
func _process(delta):
# Position the RichTextLabel on the character's dialog position, if any.
rect_position = _current_character.get_node("dialog_position") \
.get_global_transform_with_canvas().origin
rect_position.x -= rect_size.x / 2
if _current_character.is_inside_tree() and \
_current_character.has_node("dialog_position"):
# Position the RichTextLabel on the character's dialog position, if any.
rect_position = _current_character.get_node("dialog_position") \
.get_global_transform_with_canvas().origin
rect_position.x -= rect_size.x / 2
if rect_position.x < 0:
rect_position.x = 0
var screen_margin = rect_position.x + rect_size.x - \
ProjectSettings.get("display/window/size/width")
if screen_margin > 0:
rect_position.x -= screen_margin
# Make a character say something
#
@@ -81,7 +92,16 @@ func say(character: String, line: String) :
else:
rect_position.x = 0
rect_size.x = ProjectSettings.get_setting("display/window/size/width")
if rect_position.x < 0:
rect_position.x = 0
var screen_margin = rect_position.x + rect_size.x - \
ProjectSettings.get("display/window/size/width")
if screen_margin > 0:
rect_position.x -= screen_margin
_current_character.start_talking()
text_node.percent_visible = 0.0