Skip to content

Commit

Permalink
Properly interrupt animations to fix dialogic-godot#2163
Browse files Browse the repository at this point in the history
  • Loading branch information
Jowan-Spooner committed Jun 25, 2024
1 parent 830ff8d commit de2b918
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
18 changes: 15 additions & 3 deletions addons/dialogic/Modules/Core/subsystem_animation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,40 @@ extends DialogicSubsystem
## Subsystem that allows entering and leaving an animation state.

signal finished
signal animation_interrupted

var prev_state: int = 0
var prev_state: DialogicGameHandler.States = DialogicGameHandler.States.IDLE

var _is_animating := false

#region MAIN METHODS
####################################################################################################

func clear_game_state(_clear_flag := DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void:
animation_finished()
stop_animation()


func is_animating() -> bool:
return dialogic.current_state == dialogic.States.ANIMATING
return _is_animating


func start_animating() -> void:
prev_state = dialogic.current_state
dialogic.current_state = dialogic.States.ANIMATING
_is_animating = true


func animation_finished(_arg := "") -> void:
# It can happen that the animation state has already been stopped
if not is_animating():
return
_is_animating = false
dialogic.current_state = prev_state as DialogicGameHandler.States
finished.emit()


func stop_animation() -> void:
animation_finished()
animation_interrupted.emit()

#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ func get_dialog() -> DialogicNode_DialogText:


func _ready() -> void:
var text_system : Node = DialogicUtil.autoload().get(&'Text')
var text_system: Node = DialogicUtil.autoload().get(&'Text')
text_system.connect(&'animation_textbox_hide', _on_textbox_hide)
text_system.connect(&'animation_textbox_show', _on_textbox_show)
text_system.connect(&'animation_textbox_new_text', _on_textbox_new_text)
text_system.connect(&'about_to_show_text', _on_about_to_show_text)
var animation_system: Node = DialogicUtil.autoload().get(&'Animations')
animation_system.connect(&'animation_interrupted', _on_animation_interrupted)


func _on_textbox_show() -> void:
Expand All @@ -43,24 +45,24 @@ func _on_textbox_show() -> void:
play("textbox_pop")
AnimationsIn.FADE_UP:
play("textbox_fade_up")
if not is_connected(&'animation_finished', Callable(animation_system, &'animation_finished')):
var _error : int = connect(&'animation_finished', Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)
if not animation_finished.is_connected(Callable(animation_system, &'animation_finished')):
animation_finished.connect(Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)


func _on_textbox_hide() -> void:
if animation_out == AnimationsOut.NONE:
return
play('RESET')
var animation_system : Node = DialogicUtil.autoload().get(&'Animations')
var animation_system: Node = DialogicUtil.autoload().get(&'Animations')
animation_system.call(&'start_animating')
match animation_out:
AnimationsOut.POP_OUT:
play_backwards("textbox_pop")
AnimationsOut.FADE_DOWN:
play_backwards("textbox_fade_up")

if not is_connected(&'animation_finished', Callable(animation_system, &'animation_finished')):
var _error : int = connect(&'animation_finished', Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)
if not animation_finished.is_connected(Callable(animation_system, &'animation_finished')):
animation_finished.connect(Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)


func _on_about_to_show_text(info:Dictionary) -> void:
Expand All @@ -84,3 +86,8 @@ func _on_textbox_new_text() -> void:

if not animation_finished.is_connected(Callable(animation_system, &'animation_finished')):
animation_finished.connect(Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)


func _on_animation_interrupted() -> void:
if is_playing():
stop()
3 changes: 1 addition & 2 deletions addons/dialogic/Modules/Text/subsystem_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ func update_textbox(text: String, instant := false) -> void:
func update_dialog_text(text: String, instant := false, additional := false) -> String:
update_text_speed()


if !instant: dialogic.current_state = dialogic.States.REVEALING_TEXT

if additional:
Expand Down Expand Up @@ -195,7 +194,7 @@ func show_textbox(instant:=false) -> void:
for text_node in get_tree().get_nodes_in_group('dialogic_dialog_text'):
if not text_node.enabled:
continue
if !text_node.textbox_root.visible and !emitted:
if not text_node.textbox_root.visible and not emitted:
animation_textbox_show.emit()
text_node.textbox_root.show()
if dialogic.Animations.is_animating():
Expand Down
10 changes: 7 additions & 3 deletions addons/dialogic/Modules/Wait/event_wait.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ func _execute() -> void:
var time_per_event: float = dialogic.Inputs.auto_skip.time_per_event
final_wait_time = min(time, time_per_event)

dialogic.current_state = dialogic.States.WAITING

if hide_text and dialogic.has_subsystem("Text"):
dialogic.Text.update_dialog_text('')
dialogic.Text.update_dialog_text('', true)
dialogic.Text.hide_textbox()
dialogic.current_state = dialogic.States.WAITING
await dialogic.get_tree().create_timer(time, false, DialogicUtil.is_physics_timer()).timeout

await dialogic.get_tree().create_timer(final_wait_time, false, DialogicUtil.is_physics_timer()).timeout
if dialogic.Animations.is_animating():
dialogic.Animations.stop_animation()
dialogic.current_state = dialogic.States.IDLE

finish()
Expand Down

0 comments on commit de2b918

Please sign in to comment.