Skip to content

Commit

Permalink
Simplify and fix text speed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jowan-Spooner committed Jan 30, 2024
1 parent f1d4a70 commit f1a526f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
18 changes: 9 additions & 9 deletions addons/dialogic/Modules/Text/node_dialog_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ enum Alignment {LEFT, CENTER, RIGHT}
var revealing := false
var base_visible_characters := 0

# Letter speed used per revealed character.
var lspeed: float = 0.01
# The used speed per revealed character.
# May be overwritten when syncing reveal speed to voice.
var active_speed: float = lspeed
var active_speed: float = 0.01

var speed_counter: float = 0

func _set(property: StringName, what: Variant) -> bool:
Expand Down Expand Up @@ -80,19 +79,20 @@ func reveal_text(_text: String, keep_previous:=false) -> void:
visible_characters = 1
return

revealing = true
speed_counter = 0
started_revealing_text.emit()


func set_speed(delay_per_character:float) -> void:
if DialogicUtil.autoload().Text.is_text_voice_synced() and DialogicUtil.autoload().Voice.is_running():
var total_characters := get_total_character_count() as float
var remaining_time: float = DialogicUtil.autoload().Voice.get_remaining_time()
var synced_speed := remaining_time / total_characters
active_speed = synced_speed

else:
active_speed = lspeed


revealing = true
speed_counter = 0
started_revealing_text.emit()
active_speed = delay_per_character


## Reveals one additional character.
Expand Down
11 changes: 6 additions & 5 deletions addons/dialogic/Modules/Text/subsystem_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ func update_dialog_text(text: String, instant := false, additional := false) ->

dialogic.current_state_info['text_parsed'] = (text_node as RichTextLabel).get_parsed_text()

# Reset speed multiplier
update_text_speed(-1, false, 1)
# Reset Auto-Advance temporarily and the No-Skip setting:
update_text_speed(-1, false, 1, -1)
dialogic.Inputs.auto_advance.enabled_until_next_event = false
dialogic.Inputs.auto_advance.override_delay_for_current_event = -1
dialogic.Inputs.set_manualadvance(true, true)
Expand Down Expand Up @@ -278,9 +279,9 @@ func update_text_speed(letter_speed: float = -1,

for text_node in get_tree().get_nodes_in_group('dialogic_dialog_text'):
if absolute:
text_node.lspeed = letter_speed
text_node.set_speed(letter_speed)
else:
text_node.lspeed = letter_speed * _speed_multiplier * user_speed
text_node.set_speed(letter_speed * _speed_multiplier * user_speed)


func set_text_reveal_skippable(skippable:= true, temp:=false) -> void:
Expand Down Expand Up @@ -491,9 +492,9 @@ func effect_speed(text_node:Control, skipped:bool, argument:String) -> void:
if skipped:
return
if argument:
update_text_speed(-1, false, float(argument), -1)
update_text_speed(-1, false, float(argument))
else:
update_text_speed(-1, false, 1, -1)
update_text_speed(-1, false, 1)


func effect_lspeed(text_node:Control, skipped:bool, argument:String) -> void:
Expand Down

0 comments on commit f1a526f

Please sign in to comment.