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

View File

@@ -0,0 +1,3 @@
:use
say player "This is a very long text: it will most likely span over the border of the screen if not handled well. Let's see" floating

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_terrain.gd" type="Script" id=1]
[ext_resource path="res://game/rooms/room15/background.tscn" type="PackedScene" id=2]
@@ -8,6 +8,7 @@
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_room.gd" type="Script" id=6]
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_item.gd" type="Script" id=7]
[ext_resource path="res://game/rooms/room15/r_door.tscn" type="PackedScene" id=8]
[ext_resource path="res://game/items/escitems/button.tscn" type="PackedScene" id=9]
[sub_resource type="NavigationPolygon" id=1]
vertices = PoolVector2Array( 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, 864.626, 613.518, 1143.08, 613.35, -9.16094, 803.802, 386.666, 618.012, 129.634, 615.792, 84.5821, 654.06, -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698 )
@@ -94,3 +95,21 @@ script = ExtResource( 5 )
global_id = "start"
is_start_location = true
interaction_direction = 180
[node name="say_long" parent="Hotspots" instance=ExtResource( 9 )]
position = Vector2( 675.509, 0.950089 )
global_id = "say_long"
esc_script = "res://game/rooms/room15/esc/say_long.esc"
tooltip_name = "Say long test right"
[node name="Position2D" type="Position2D" parent="Hotspots/say_long"]
position = Vector2( 362.457, 358.656 )
[node name="say_long_left" parent="Hotspots" instance=ExtResource( 9 )]
position = Vector2( -205.218, 2.85024 )
global_id = "say_long_left"
esc_script = "res://game/rooms/room15/esc/say_long.esc"
tooltip_name = "Say long test left"
[node name="Position2D" type="Position2D" parent="Hotspots/say_long_left"]
position = Vector2( 362.457, 358.656 )

View File

@@ -714,6 +714,10 @@ dialog_simple/avatars_path="res://game/dialog_avatars"
dialog_simple/text_speed_per_character=0.1
dialog_simple/fast_text_speed_per_character=0.25
dialog_simple/max_time_to_disappear=1.0
debug/log_file_path="user://"
debug/crash_message="We're sorry, but the game crashed. Please send us the following files:
%s"
[input]