feat: adds warnings w/ defaults when using settings; uses same calculation basis for text speeds/times; changes time units to ms
This commit is contained in:
committed by
Julian Murgia
parent
e4414141cb
commit
f64b59621d
@@ -8,8 +8,8 @@ const MANAGER_CLASS="res://addons/escoria-dialog-simple/esc_dialog_simple.gd"
|
|||||||
const SETTINGS_ROOT="escoria/dialog_simple"
|
const SETTINGS_ROOT="escoria/dialog_simple"
|
||||||
|
|
||||||
const AVATARS_PATH = "%s/avatars_path" % SETTINGS_ROOT
|
const AVATARS_PATH = "%s/avatars_path" % SETTINGS_ROOT
|
||||||
const TEXT_SPEED_PER_CHARACTER = "%s/text_speed_per_character" % SETTINGS_ROOT
|
const TEXT_TIME_PER_LETTER_MS = "%s/text_time_per_letter_ms" % SETTINGS_ROOT
|
||||||
const FAST_TEXT_SPEED_PER_CHARACTER = "%s/fast_text_speed_per_character" % SETTINGS_ROOT
|
const TEXT_TIME_PER_LETTER_MS_FAST = "%s/text_time_per_fast_letter_ms" % SETTINGS_ROOT
|
||||||
const READING_SPEED_IN_WPM = "%s/reading_speed_in_wpm" % SETTINGS_ROOT
|
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 CLEAR_TEXT_BY_CLICK_ONLY = "%s/clear_text_by_click_only" % SETTINGS_ROOT
|
||||||
const LEFT_CLICK_ACTION = "%s/left_click_action" % SETTINGS_ROOT
|
const LEFT_CLICK_ACTION = "%s/left_click_action" % SETTINGS_ROOT
|
||||||
@@ -19,6 +19,8 @@ const LEFT_CLICK_ACTION_INSTANT_FINISH = "Instant finish"
|
|||||||
const LEFT_CLICK_ACTION_NOTHING = "None"
|
const LEFT_CLICK_ACTION_NOTHING = "None"
|
||||||
|
|
||||||
const READING_SPEED_IN_WPM_DEFAULT_VALUE = 200
|
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
|
||||||
|
|
||||||
|
|
||||||
var leftClickActions: Array = [
|
var leftClickActions: Array = [
|
||||||
@@ -45,11 +47,11 @@ func disable_plugin():
|
|||||||
)
|
)
|
||||||
|
|
||||||
ESCProjectSettingsManager.remove_setting(
|
ESCProjectSettingsManager.remove_setting(
|
||||||
TEXT_SPEED_PER_CHARACTER
|
TEXT_TIME_PER_LETTER_MS
|
||||||
)
|
)
|
||||||
|
|
||||||
ESCProjectSettingsManager.remove_setting(
|
ESCProjectSettingsManager.remove_setting(
|
||||||
FAST_TEXT_SPEED_PER_CHARACTER
|
TEXT_TIME_PER_LETTER_MS_FAST
|
||||||
)
|
)
|
||||||
|
|
||||||
ESCProjectSettingsManager.remove_setting(
|
ESCProjectSettingsManager.remove_setting(
|
||||||
@@ -90,16 +92,16 @@ func enable_plugin():
|
|||||||
)
|
)
|
||||||
|
|
||||||
ESCProjectSettingsManager.register_setting(
|
ESCProjectSettingsManager.register_setting(
|
||||||
TEXT_SPEED_PER_CHARACTER,
|
TEXT_TIME_PER_LETTER_MS,
|
||||||
0.1,
|
TEXT_TIME_PER_LETTER_MS_DEFAULT_VALUE,
|
||||||
{
|
{
|
||||||
"type": TYPE_REAL
|
"type": TYPE_REAL
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
ESCProjectSettingsManager.register_setting(
|
ESCProjectSettingsManager.register_setting(
|
||||||
FAST_TEXT_SPEED_PER_CHARACTER,
|
TEXT_TIME_PER_LETTER_MS_FAST,
|
||||||
0.25,
|
TEXT_TIME_PER_LETTER_MS_FAST_DEFAULT_VALUE,
|
||||||
{
|
{
|
||||||
"type": TYPE_REAL
|
"type": TYPE_REAL
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ signal say_visible
|
|||||||
|
|
||||||
|
|
||||||
# The text speed per character for normal display
|
# The text speed per character for normal display
|
||||||
var _text_speed_per_character
|
var _text_time_per_character: float
|
||||||
|
|
||||||
# The text speed per character if the dialog line is skipped
|
# The text speed per character if the dialog line is skipped
|
||||||
var _fast_text_speed_per_character
|
var _fast_text_time_per_character: float
|
||||||
|
|
||||||
# The reading speed to be used in determining the length of time text remains
|
# The reading speed to be used in determining the length of time text remains
|
||||||
# on the screen.
|
# on the screen.
|
||||||
@@ -25,6 +25,9 @@ var _word_regex: RegEx = RegEx.new()
|
|||||||
# Whether the current dialog is speeding up
|
# Whether the current dialog is speeding up
|
||||||
var _is_speeding_up: bool = false
|
var _is_speeding_up: bool = false
|
||||||
|
|
||||||
|
# The current line of text being displayed.
|
||||||
|
var _current_line: String
|
||||||
|
|
||||||
|
|
||||||
# The node holding the avatar
|
# The node holding the avatar
|
||||||
onready var avatar_node = $Panel/MarginContainer/HSplitContainer/VBoxContainer\
|
onready var avatar_node = $Panel/MarginContainer/HSplitContainer/VBoxContainer\
|
||||||
@@ -43,12 +46,38 @@ onready var is_paused: bool = true
|
|||||||
|
|
||||||
# Build up the UI
|
# Build up the UI
|
||||||
func _ready():
|
func _ready():
|
||||||
_text_speed_per_character = ProjectSettings.get_setting(
|
_text_time_per_character = ProjectSettings.get_setting(
|
||||||
SimpleDialogPlugin.TEXT_SPEED_PER_CHARACTER
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS
|
||||||
)
|
)
|
||||||
_fast_text_speed_per_character = ProjectSettings.get_setting(
|
|
||||||
SimpleDialogPlugin.FAST_TEXT_SPEED_PER_CHARACTER
|
if _text_time_per_character < 0:
|
||||||
|
escoria.logger.warn(
|
||||||
|
self,
|
||||||
|
"%s setting must be a non-negative number. Will use default value of %s." %
|
||||||
|
[
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS,
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_DEFAULT_VALUE
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
_text_time_per_character = SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_DEFAULT_VALUE
|
||||||
|
|
||||||
|
_fast_text_time_per_character = ProjectSettings.get_setting(
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_FAST
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if _fast_text_time_per_character < 0:
|
||||||
|
escoria.logger.warn(
|
||||||
|
self,
|
||||||
|
"%s setting must be a non-negative number. Will use default value of %s." %
|
||||||
|
[
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_FAST,
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_FAST_DEFAULT_VALUE
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
_fast_text_time_per_character = SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_FAST_DEFAULT_VALUE
|
||||||
|
|
||||||
_reading_speed_in_wpm = ProjectSettings.get_setting(
|
_reading_speed_in_wpm = ProjectSettings.get_setting(
|
||||||
SimpleDialogPlugin.READING_SPEED_IN_WPM
|
SimpleDialogPlugin.READING_SPEED_IN_WPM
|
||||||
)
|
)
|
||||||
@@ -93,6 +122,10 @@ func set_current_character(name: String):
|
|||||||
]
|
]
|
||||||
if ResourceLoader.exists(avatar):
|
if ResourceLoader.exists(avatar):
|
||||||
avatar_node.texture = ResourceLoader.load(avatar)
|
avatar_node.texture = ResourceLoader.load(avatar)
|
||||||
|
|
||||||
|
if avatar_node.texture is AnimatedTexture:
|
||||||
|
avatar_node.texture.current_frame = 0
|
||||||
|
avatar_node.texture.pause = false
|
||||||
else:
|
else:
|
||||||
escoria.logger.warn(self, "Unable to load avatar '%s': Resource not found in path '%s'" %
|
escoria.logger.warn(self, "Unable to load avatar '%s': Resource not found in path '%s'" %
|
||||||
[name, ProjectSettings.get_setting("escoria/dialog_simple/avatars_path")])
|
[name, ProjectSettings.get_setting("escoria/dialog_simple/avatars_path")])
|
||||||
@@ -104,6 +137,8 @@ func set_current_character(name: String):
|
|||||||
# - character: The global id of the character speaking
|
# - character: The global id of the character speaking
|
||||||
# - line: Line to say
|
# - line: Line to say
|
||||||
func say(character: String, line: String):
|
func say(character: String, line: String):
|
||||||
|
_current_line = line
|
||||||
|
|
||||||
_is_speeding_up = false
|
_is_speeding_up = false
|
||||||
popup_centered()
|
popup_centered()
|
||||||
set_current_character(character)
|
set_current_character(character)
|
||||||
@@ -111,7 +146,7 @@ func say(character: String, line: String):
|
|||||||
text_node.bbcode_text = tr(line)
|
text_node.bbcode_text = tr(line)
|
||||||
|
|
||||||
text_node.percent_visible = 0.0
|
text_node.percent_visible = 0.0
|
||||||
var time_show_full_text = _text_speed_per_character * len(line)
|
var time_show_full_text = _text_time_per_character / 1000 * len(line)
|
||||||
|
|
||||||
tween.interpolate_property(text_node, "percent_visible",
|
tween.interpolate_property(text_node, "percent_visible",
|
||||||
0.0, 1.0, time_show_full_text,
|
0.0, 1.0, time_show_full_text,
|
||||||
@@ -123,9 +158,10 @@ func say(character: String, line: String):
|
|||||||
func speedup():
|
func speedup():
|
||||||
if not _is_speeding_up:
|
if not _is_speeding_up:
|
||||||
_is_speeding_up = true
|
_is_speeding_up = true
|
||||||
|
var time_show_full_text = _fast_text_time_per_character / 1000 * len(_current_line)
|
||||||
tween.remove_all()
|
tween.remove_all()
|
||||||
tween.interpolate_property(text_node, "percent_visible",
|
tween.interpolate_property(text_node, "percent_visible",
|
||||||
text_node.percent_visible, 1.0, _fast_text_speed_per_character,
|
text_node.percent_visible, 1.0, time_show_full_text,
|
||||||
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||||
tween.start()
|
tween.start()
|
||||||
|
|
||||||
@@ -143,10 +179,9 @@ func finish():
|
|||||||
func _on_dialog_line_typed(object, key):
|
func _on_dialog_line_typed(object, key):
|
||||||
text_node.visible_characters = -1
|
text_node.visible_characters = -1
|
||||||
|
|
||||||
if not ESCProjectSettingsManager.get_setting(SimpleDialogPlugin.CLEAR_TEXT_BY_CLICK_ONLY):
|
var time_to_disappear: float = _calculate_time_to_disappear()
|
||||||
var time_to_disappear: float = _calculate_time_to_disappear()
|
$Timer.start(time_to_disappear)
|
||||||
$Timer.start(time_to_disappear)
|
$Timer.connect("timeout", self, "_on_dialog_finished")
|
||||||
$Timer.connect("timeout", self, "_on_dialog_finished")
|
|
||||||
|
|
||||||
emit_signal("say_visible")
|
emit_signal("say_visible")
|
||||||
|
|
||||||
@@ -161,8 +196,14 @@ func _get_number_of_words() -> int:
|
|||||||
|
|
||||||
# Ending the dialog
|
# Ending the dialog
|
||||||
func _on_dialog_finished():
|
func _on_dialog_finished():
|
||||||
emit_signal("say_finished")
|
if avatar_node.texture is AnimatedTexture:
|
||||||
queue_free()
|
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")
|
||||||
|
queue_free()
|
||||||
|
|
||||||
|
|
||||||
# Handler managing pause notification from Escoria
|
# Handler managing pause notification from Escoria
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ signal say_visible
|
|||||||
|
|
||||||
|
|
||||||
# The text speed per character for normal display
|
# The text speed per character for normal display
|
||||||
var _text_speed_per_character
|
var _text_time_per_character: float
|
||||||
|
|
||||||
# The text speed per character if the dialog line is skipped
|
# The text speed per character if the dialog line is skipped
|
||||||
var _fast_text_speed_per_character
|
var _fast_text_time_per_character: float
|
||||||
|
|
||||||
# The reading speed to be used in determining the length of time text remains
|
# The reading speed to be used in determining the length of time text remains
|
||||||
# on the screen.
|
# on the screen.
|
||||||
@@ -29,6 +29,9 @@ var _current_character
|
|||||||
# Whether the current dialog is speeding up
|
# Whether the current dialog is speeding up
|
||||||
var _is_speeding_up: bool = false
|
var _is_speeding_up: bool = false
|
||||||
|
|
||||||
|
# The current line of text being displayed.
|
||||||
|
var _current_line: String
|
||||||
|
|
||||||
|
|
||||||
# Tween node for text animation
|
# Tween node for text animation
|
||||||
onready var tween: Tween = $Tween
|
onready var tween: Tween = $Tween
|
||||||
@@ -42,12 +45,38 @@ onready var is_paused: bool = true
|
|||||||
|
|
||||||
# Enable bbcode and catch the signal when a tween completed
|
# Enable bbcode and catch the signal when a tween completed
|
||||||
func _ready():
|
func _ready():
|
||||||
_text_speed_per_character = ProjectSettings.get_setting(
|
_text_time_per_character = ProjectSettings.get_setting(
|
||||||
SimpleDialogPlugin.TEXT_SPEED_PER_CHARACTER
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS
|
||||||
)
|
)
|
||||||
_fast_text_speed_per_character = ProjectSettings.get_setting(
|
|
||||||
SimpleDialogPlugin.FAST_TEXT_SPEED_PER_CHARACTER
|
if _text_time_per_character < 0:
|
||||||
|
escoria.logger.warn(
|
||||||
|
self,
|
||||||
|
"%s setting must be a non-negative number. Will use default value of %s." %
|
||||||
|
[
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS,
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_DEFAULT_VALUE
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
_text_time_per_character = SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_DEFAULT_VALUE
|
||||||
|
|
||||||
|
_fast_text_time_per_character = ProjectSettings.get_setting(
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_FAST
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if _fast_text_time_per_character < 0:
|
||||||
|
escoria.logger.warn(
|
||||||
|
self,
|
||||||
|
"%s setting must be a non-negative number. Will use default value of %s." %
|
||||||
|
[
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_FAST,
|
||||||
|
SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_FAST_DEFAULT_VALUE
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
_fast_text_time_per_character = SimpleDialogPlugin.TEXT_TIME_PER_LETTER_MS_FAST_DEFAULT_VALUE
|
||||||
|
|
||||||
_reading_speed_in_wpm = ProjectSettings.get_setting(
|
_reading_speed_in_wpm = ProjectSettings.get_setting(
|
||||||
SimpleDialogPlugin.READING_SPEED_IN_WPM
|
SimpleDialogPlugin.READING_SPEED_IN_WPM
|
||||||
)
|
)
|
||||||
@@ -74,6 +103,8 @@ func _ready():
|
|||||||
escoria.connect("paused", self, "_on_paused")
|
escoria.connect("paused", self, "_on_paused")
|
||||||
escoria.connect("resumed", self, "_on_resumed")
|
escoria.connect("resumed", self, "_on_resumed")
|
||||||
|
|
||||||
|
_current_line = ""
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if _current_character.is_inside_tree() and \
|
if _current_character.is_inside_tree() and \
|
||||||
@@ -99,6 +130,8 @@ func _process(delta):
|
|||||||
# - character: The global id of the character speaking
|
# - character: The global id of the character speaking
|
||||||
# - line: Line to say
|
# - line: Line to say
|
||||||
func say(character: String, line: String) :
|
func say(character: String, line: String) :
|
||||||
|
_current_line = line
|
||||||
|
|
||||||
show()
|
show()
|
||||||
|
|
||||||
_is_speeding_up = false
|
_is_speeding_up = false
|
||||||
@@ -135,7 +168,7 @@ func say(character: String, line: String) :
|
|||||||
_current_character.start_talking()
|
_current_character.start_talking()
|
||||||
|
|
||||||
text_node.percent_visible = 0.0
|
text_node.percent_visible = 0.0
|
||||||
var time_show_full_text = _text_speed_per_character * len(line)
|
var time_show_full_text = _text_time_per_character / 1000 * len(_current_line)
|
||||||
|
|
||||||
tween.interpolate_property(text_node, "percent_visible",
|
tween.interpolate_property(text_node, "percent_visible",
|
||||||
0.0, 1.0, time_show_full_text,
|
0.0, 1.0, time_show_full_text,
|
||||||
@@ -148,9 +181,11 @@ func say(character: String, line: String) :
|
|||||||
func speedup():
|
func speedup():
|
||||||
if not _is_speeding_up:
|
if not _is_speeding_up:
|
||||||
_is_speeding_up = true
|
_is_speeding_up = true
|
||||||
|
var time_show_full_text = _fast_text_time_per_character / 1000 * len(_current_line)
|
||||||
|
|
||||||
tween.remove_all()
|
tween.remove_all()
|
||||||
tween.interpolate_property(text_node, "percent_visible",
|
tween.interpolate_property(text_node, "percent_visible",
|
||||||
text_node.percent_visible, 1.0, _fast_text_speed_per_character,
|
text_node.percent_visible, 1.0, time_show_full_text,
|
||||||
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||||
tween.start()
|
tween.start()
|
||||||
|
|
||||||
@@ -168,10 +203,9 @@ func finish():
|
|||||||
func _on_dialog_line_typed(object, key):
|
func _on_dialog_line_typed(object, key):
|
||||||
text_node.visible_characters = -1
|
text_node.visible_characters = -1
|
||||||
|
|
||||||
if not ESCProjectSettingsManager.get_setting(SimpleDialogPlugin.CLEAR_TEXT_BY_CLICK_ONLY):
|
var time_to_disappear: float = _calculate_time_to_disappear()
|
||||||
var time_to_disappear: float = _calculate_time_to_disappear()
|
$Timer.start(time_to_disappear)
|
||||||
$Timer.start(time_to_disappear)
|
$Timer.connect("timeout", self, "_on_dialog_finished")
|
||||||
$Timer.connect("timeout", self, "_on_dialog_finished")
|
|
||||||
|
|
||||||
emit_signal("say_visible")
|
emit_signal("say_visible")
|
||||||
|
|
||||||
@@ -187,7 +221,10 @@ func _get_number_of_words() -> int:
|
|||||||
# Ending the dialog
|
# Ending the dialog
|
||||||
func _on_dialog_finished():
|
func _on_dialog_finished():
|
||||||
_stop_character_talking()
|
_stop_character_talking()
|
||||||
emit_signal("say_finished")
|
|
||||||
|
# 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")
|
||||||
|
|
||||||
|
|
||||||
# Handler managing pause notification from Escoria
|
# Handler managing pause notification from Escoria
|
||||||
|
|||||||
Reference in New Issue
Block a user