2025-01-16 16:32:58 +00:00
@ tool
extends CenterContainer
2025-02-06 17:55:05 +00:00
signal text_finished
2025-01-16 16:32:58 +00:00
signal finished
signal intro
#TODO properly implement animation taking stage, as it should do, disabling processing when it does not have stage.
2025-02-06 17:55:05 +00:00
var max_lines : float = 0
2025-01-16 16:32:58 +00:00
@ export var story_array : Array [ String ] = [ ] :
set ( array ) :
story_array = array
if is_node_ready ( ) :
label . text = " "
substring_sizes = [ ]
if Engine . is_editor_hint ( ) :
TranslationServer . set_locale ( " en " )
for str in array :
label . text += TranslationServer . translate ( str ) . replace ( " [/p] " , " [/p][p][font_size=8] [/font_size][/p] " )
substring_sizes . append ( TranslationServer . translate ( str ) . replace ( " [/p] " , " . " ) . replace ( " [p] " , " " ) . length ( ) )
2025-02-06 17:55:05 +00:00
max_lines = float ( label . get_line_count ( ) )
2025-01-16 16:32:58 +00:00
@ export var progress : float = 0 :
set ( value ) :
progress = value
if is_node_ready ( ) :
var start_index = 0
if progress > = substring_sizes . size ( ) or progress < 0 :
label . visible_ratio = 1
2025-02-06 17:55:05 +00:00
elif progress > 0 :
2025-01-16 16:32:58 +00:00
for i in range ( min ( progress , substring_sizes . size ( ) - 1 ) as int ) if progress > 0 else range ( substring_sizes . size ( ) - 1 ) :
start_index += substring_sizes [ i ]
label . visible_characters = start_index + substring_sizes [ min ( progress as int , substring_sizes . size ( ) - 1 ) ] * fmod ( progress , 1 )
2025-02-06 17:55:05 +00:00
else :
label . visible_ratio = 0
@ export var test_scroll : bool :
set ( scroll ) :
try_scroll ( )
2025-01-16 16:32:58 +00:00
@ onready var label : RichTextLabel = % StoryLabel
@ onready var scroll_container : ScrollContainer = % StoryScroll
@ onready var animation_player : AnimationPlayer = % AnimationPlayer
2025-02-06 17:55:05 +00:00
@ onready var skip_control : SkipControl = % SkipControl
2025-01-16 16:32:58 +00:00
@ export var animation_complete : bool = false :
set ( value ) :
animation_complete = value
if value :
2025-02-06 17:55:05 +00:00
scroll_container . vertical_scroll_mode = ScrollContainer . ScrollMode . SCROLL_MODE_AUTO
2025-01-16 16:32:58 +00:00
progress = - 1
2025-02-06 17:55:05 +00:00
else :
scroll_container . scroll_vertical = ScrollContainer . ScrollMode . SCROLL_MODE_DISABLED
2025-01-16 16:32:58 +00:00
animation_complete = value
var substring_sizes : Array [ int ]
func _ready ( ) - > void :
2025-02-06 17:55:05 +00:00
skip_control = % SkipControl
if skip_control is SkipControl :
skip_control . skip . connect ( skip_text )
if get_tree ( ) . root . get_child ( - 1 ) == self :
2025-01-16 16:32:58 +00:00
play_scene ( )
story_array = story_array
progress = progress
func try_scroll ( ) :
var scroll_target : int
2025-02-06 17:55:05 +00:00
#print( "max lines: " + str(max_lines))
#print( "current lines: " + str(label.get_character_line(label.visible_characters)))
var visible_ratio : float = float ( label . get_character_line ( label . visible_characters ) ) / max_lines
#print("Tried scrolling with ratio of %f. Comparing %f against %f" % [visible_ratio, label.size.y * visible_ratio - scroll_container.scroll_vertical, scroll_container.size.y * 0.9])
if label . size . y * visible_ratio + scroll_container . scroll_vertical > scroll_container . size . y * 0.9 :
if scroll_container . scroll_vertical + scroll_container . size . y * 0.9 < label . size . y :
scroll_target = scroll_container . scroll_vertical + scroll_container . size . y * 0.8
2025-01-16 16:32:58 +00:00
else :
2025-02-06 17:55:05 +00:00
scroll_target = label . size . y - scroll_container . size . y
2025-01-16 16:32:58 +00:00
if scroll_target != null :
var tween : Tween = get_tree ( ) . create_tween ( )
##tween.set_trans()
tween . tween_property ( scroll_container , " scroll_vertical " , scroll_target , 0.5 )
func play_scene ( ) :
animation_complete = false
##FIXME match State.text_language:
match TranslationServer . get_locale ( ) :
" de " :
animation_player . queue ( " de " )
" en " :
animation_player . queue ( " en " )
2025-02-06 17:55:05 +00:00
await text_finished
2025-01-16 16:32:58 +00:00
if name == " draven " :
trigger_intro ( )
animation_complete = true
2025-02-06 17:55:05 +00:00
skip_control . start_proceed_countdown ( )
await skip_control . proceed
animation_player . play ( " vanish " )
await animation_player . animation_finished
2025-01-16 16:32:58 +00:00
finished . emit ( )
var intro_triggered : = false
func trigger_intro ( ) :
if not intro_triggered :
intro . emit ( )
2025-02-06 17:55:05 +00:00
intro_triggered = true
2025-01-16 16:32:58 +00:00
func skip_text ( ) :
2025-02-06 17:55:05 +00:00
if not animation_complete :
animation_player . stop ( true )
text_finished . emit ( )
func _on_text_finished ( ) :
if not animation_complete :
text_finished . emit ( )