Skip to content

Commit

Permalink
feat: adds additional options to dialog manager, including a left-cli…
Browse files Browse the repository at this point in the history
…ck action option and a text skipping option
  • Loading branch information
BHSDuncan authored and StraToN committed Dec 4, 2022
1 parent d955e2e commit d676e50
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ func choose(dialog_player: Node, dialog: ESCDialog):
pass


# Trigger running the dialog faster
# Trigger running the dialogue faster
func speedup():
pass


# Trigger an instant finish of the current dialog
func finish():
pass


# The say command has been interrupted, cancel the dialog display
func interrupt():
pass
9 changes: 8 additions & 1 deletion addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func _create_states() -> void:
"idle": DialogIdle.new(),
"say": DialogSay.new(),
"say_fast": DialogSayFast.new(),
"say_finish": DialogSayFinish.new(),
"visible": DialogVisible.new(),
"finish": DialogFinish.new(),
"interrupt": DialogInterrupt.new(),
Expand Down Expand Up @@ -70,11 +71,16 @@ func say(character: String, type: String, text: String) -> void:
_change_state("say")


# Called when a dialog line is to be sped up.
# Called when a dialogue line is to be sped up.
func speedup() -> void:
_change_state("say_fast")


# Called when a dialogue line is to be finished immediately.
func finish() -> void:
_change_state("say_finish")


# Display a list of choices
#
# #### Parameters
Expand All @@ -96,5 +102,6 @@ func interrupt() -> void:
func _on_dialog_manager_set(dialog_manager: ESCDialogManager) -> void:
_dialog_manager = dialog_manager
states_map["say_fast"].initialize(dialog_manager)
states_map["say_finish"].initialize(dialog_manager)
states_map["visible"].initialize(dialog_manager)
states_map["interrupt"].initialize(dialog_manager)
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func initialize(dialog_manager: ESCDialogManager) -> void:
func enter():
escoria.logger.trace(self, "Dialog State Machine: Entered 'interrupt'.")

if not _dialog_manager.is_connected("say_finished", self, "_on_say_finished"):
_dialog_manager.connect("say_finished", self, "_on_say_finished", [], CONNECT_ONESHOT)

if _dialog_manager != null:
if not _dialog_manager.is_connected("say_finished", self, "_on_say_finished"):
_dialog_manager.connect("say_finished", self, "_on_say_finished", [], CONNECT_ONESHOT)

_dialog_manager.interrupt()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@ func handle_input(_event):
escoria.inputs_manager.INPUT_NONE and \
_dialog_manager != null:

var left_click_action = ESCProjectSettingsManager.get_setting(SimpleDialogPlugin.LEFT_CLICK_ACTION)

_handle_left_click_action(left_click_action)


func _handle_left_click_action(left_click_action: String) -> void:
match left_click_action:
SimpleDialogPlugin.LEFT_CLICK_ACTION_SPEED_UP:
if _dialog_manager.is_connected("say_visible", self, "_on_say_visible"):
_dialog_manager.disconnect("say_visible", self, "_on_say_visible")

escoria.logger.trace(self, "Dialog State Machine: 'say' -> 'say_fast'")

emit_signal("finished", "say_fast")
get_tree().set_input_as_handled()
SimpleDialogPlugin.LEFT_CLICK_ACTION_INSTANT_FINISH:
if _dialog_manager.is_connected("say_visible", self, "_on_say_visible"):
_dialog_manager.disconnect("say_visible", self, "_on_say_visible")

escoria.logger.trace(self, "Dialog State Machine: 'say' -> 'say_finish'")
emit_signal("finished", "say_finish")

get_tree().set_input_as_handled()


func enter():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extends State
class_name DialogSayFinish


# Reference to the currently playing dialog manager
var _dialog_manager: ESCDialogManager = null


func initialize(dialog_manager: ESCDialogManager) -> void:
_dialog_manager = dialog_manager


func enter():
escoria.logger.trace(self, "Dialog State Machine: Entered 'say_finish'.")

if escoria.inputs_manager.input_mode != \
escoria.inputs_manager.INPUT_NONE and \
_dialog_manager != null:

if not _dialog_manager.is_connected("say_visible", self, "_on_say_visible"):
_dialog_manager.connect("say_visible", self, "_on_say_visible", [], CONNECT_ONESHOT)

_dialog_manager.finish()
else:
escoria.logger.error(self, "Illegal state.")


func _on_say_visible() -> void:
escoria.logger.trace(self, "Dialog State Machine: 'say_finish' -> 'visible'")
emit_signal("finished", "visible")
8 changes: 7 additions & 1 deletion addons/escoria-dialog-simple/esc_dialog_simple.gd
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,18 @@ func choose(dialog_player: Node, dialog: ESCDialog):
emit_signal("option_chosen", option)


# Trigger running the dialog faster
# Trigger running the dialogue faster
func speedup():
if _type_player != null:
_type_player.speedup()


# Trigger an instant finish of the current dialog
func finish():
if _type_player != null:
_type_player.finish()


# The say command has been interrupted, cancel the dialog display
func interrupt():
if _dialog_player.get_children().has(_type_player):
Expand Down
46 changes: 34 additions & 12 deletions addons/escoria-dialog-simple/plugin.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
# A simple dialog manager for Escoria
tool
extends EditorPlugin
class_name SimpleDialogPlugin


const MANAGER_CLASS="res://addons/escoria-dialog-simple/esc_dialog_simple.gd"
const SETTINGS_ROOT="escoria/dialog_simple"

const AVATARS_PATH = "%s/avatars_path" % SETTINGS_ROOT
const TEXT_SPEED_PER_CHARACTER = "%s/text_speed_per_character" % SETTINGS_ROOT
const FAST_TEXT_SPEED_PER_CHARACTER = "%s/fast_text_speed_per_character" % SETTINGS_ROOT
const MAX_TIME_TO_DISAPPEAR = "%s/max_time_to_disappear" % SETTINGS_ROOT
const SKIP_DIALOGS = "%s/skip_dialogs" % 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 LEFT_CLICK_ACTION = "%s/left_click_action" % SETTINGS_ROOT

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


var leftClickActions: Array = [
LEFT_CLICK_ACTION_SPEED_UP,
LEFT_CLICK_ACTION_INSTANT_FINISH,
LEFT_CLICK_ACTION_NOTHING
]


# Override function to return the plugin name.
func get_plugin_name():
Expand All @@ -36,12 +50,16 @@ func disable_plugin():
FAST_TEXT_SPEED_PER_CHARACTER
)

ESCProjectSettingsManager.remove_setting(
CLEAR_TEXT_BY_CLICK_ONLY
)

ESCProjectSettingsManager.remove_setting(
READING_SPEED_IN_WPM
)

ESCProjectSettingsManager.remove_setting(
MAX_TIME_TO_DISAPPEAR
LEFT_CLICK_ACTION
)

EscoriaPlugin.deregister_dialog_manager(MANAGER_CLASS)
Expand Down Expand Up @@ -86,29 +104,33 @@ func enable_plugin():
)

ESCProjectSettingsManager.register_setting(
READING_SPEED_IN_WPM,
200,
CLEAR_TEXT_BY_CLICK_ONLY,
false,
{
"type": TYPE_INT
"type": TYPE_BOOL
}
)

ESCProjectSettingsManager.register_setting(
MAX_TIME_TO_DISAPPEAR,
1.0,
READING_SPEED_IN_WPM,
200,
{
"type": TYPE_INT
}
)

var leftClickActionsString: String = ",".join(leftClickActions)

ESCProjectSettingsManager.register_setting(
SKIP_DIALOGS,
true,
LEFT_CLICK_ACTION,
"Speed up",
{
"type": TYPE_BOOL
"type": TYPE_STRING,
"hint": PROPERTY_HINT_ENUM,
"hint_string": leftClickActionsString
}
)
#escoria.settings_manager.custom_settings[SKIP_DIALOGS] = true

else:
get_editor_interface().set_plugin_enabled(
get_plugin_name(),
Expand Down
23 changes: 17 additions & 6 deletions addons/escoria-dialog-simple/types/avatar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ onready var is_paused: bool = true
# Build up the UI
func _ready():
_text_speed_per_character = ProjectSettings.get_setting(
"escoria/dialog_simple/text_speed_per_character"
SimpleDialogPlugin.TEXT_SPEED_PER_CHARACTER
)
_fast_text_speed_per_character = ProjectSettings.get_setting(
"escoria/dialog_simple/fast_text_speed_per_character"
SimpleDialogPlugin.FAST_TEXT_SPEED_PER_CHARACTER
)
_reading_speed_in_wpm = ProjectSettings.get_setting(
"escoria/dialog_simple/reading_speed_in_wpm"
SimpleDialogPlugin.READING_SPEED_IN_WPM
)

_word_regex.compile("\\S+")
Expand Down Expand Up @@ -118,13 +118,24 @@ func speedup():
tween.start()


# Called by the dialog player when user wants to finish dialogue immediately.
func finish():
tween.remove_all()
tween.interpolate_property(text_node, "percent_visible",
text_node.percent_visible, 1.0, 0.0)
tween.start()


# The dialog line was printed, start the waiting time and then finish
# the dialog
func _on_dialog_line_typed(object, key):
var time_to_disappear: float = _calculate_time_to_disappear()
text_node.visible_characters = -1
$Timer.start(time_to_disappear)
$Timer.connect("timeout", self, "_on_dialog_finished")

if not ESCProjectSettingsManager.get_setting(SimpleDialogPlugin.CLEAR_TEXT_BY_CLICK_ONLY):
var time_to_disappear: float = _calculate_time_to_disappear()
$Timer.start(time_to_disappear)
$Timer.connect("timeout", self, "_on_dialog_finished")

emit_signal("say_visible")


Expand Down
25 changes: 18 additions & 7 deletions addons/escoria-dialog-simple/types/floating.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ onready var is_paused: bool = true
# Enable bbcode and catch the signal when a tween completed
func _ready():
_text_speed_per_character = ProjectSettings.get_setting(
"escoria/dialog_simple/text_speed_per_character"
SimpleDialogPlugin.TEXT_SPEED_PER_CHARACTER
)
_fast_text_speed_per_character = ProjectSettings.get_setting(
"escoria/dialog_simple/fast_text_speed_per_character"
SimpleDialogPlugin.FAST_TEXT_SPEED_PER_CHARACTER
)
_reading_speed_in_wpm = ProjectSettings.get_setting(
"escoria/dialog_simple/reading_speed_in_wpm"
SimpleDialogPlugin.READING_SPEED_IN_WPM
)

_word_regex.compile("\\S+")
Expand Down Expand Up @@ -132,7 +132,7 @@ func say(character: String, line: String) :
set_process(true)


# Called by the dialog player when user wants to finish dialog fast.
# Called by the dialog player when user wants to finish dialogue fast.
func speedup():
if not _is_speeding_up:
_is_speeding_up = true
Expand All @@ -143,13 +143,24 @@ func speedup():
tween.start()


# Called by the dialog player when user wants to finish dialogue immediately.
func finish():
tween.remove_all()
tween.interpolate_property(text_node, "percent_visible",
text_node.percent_visible, 1.0, 0.0)
tween.start()


# The dialog line was printed, start the waiting time and then finish
# the dialog
func _on_dialog_line_typed(object, key):
var time_to_disappear: float = _calculate_time_to_disappear()
text_node.visible_characters = -1
$Timer.start(time_to_disappear)
$Timer.connect("timeout", self, "_on_dialog_finished")

if not ESCProjectSettingsManager.get_setting(SimpleDialogPlugin.CLEAR_TEXT_BY_CLICK_ONLY):
var time_to_disappear: float = _calculate_time_to_disappear()
$Timer.start(time_to_disappear)
$Timer.connect("timeout", self, "_on_dialog_finished")

emit_signal("say_visible")


Expand Down

0 comments on commit d676e50

Please sign in to comment.