131 lines
3.8 KiB
GDScript
131 lines
3.8 KiB
GDScript
@tool
|
|
extends CenterContainer
|
|
|
|
signal text_finished
|
|
signal finished
|
|
signal intro
|
|
|
|
#TODO properly implement animation taking stage, as it should do, disabling processing when it does not have stage.
|
|
|
|
var max_lines: float = 0
|
|
@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())
|
|
max_lines = float(label.get_line_count())
|
|
|
|
@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
|
|
elif progress > 0:
|
|
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)
|
|
else:
|
|
label.visible_ratio = 0
|
|
|
|
@export var test_scroll: bool:
|
|
set(scroll):
|
|
try_scroll()
|
|
|
|
@onready var label:RichTextLabel = %StoryLabel
|
|
@onready var scroll_container:ScrollContainer = %StoryScroll
|
|
@onready var animation_player: AnimationPlayer = %AnimationPlayer
|
|
@onready var skip_control: SkipControl = %SkipControl
|
|
|
|
@export var animation_complete:bool = false:
|
|
set(value):
|
|
animation_complete = value
|
|
if value:
|
|
scroll_container.vertical_scroll_mode = ScrollContainer.ScrollMode.SCROLL_MODE_AUTO
|
|
progress = -1
|
|
else:
|
|
scroll_container.scroll_vertical = ScrollContainer.ScrollMode.SCROLL_MODE_DISABLED
|
|
animation_complete = value
|
|
|
|
var substring_sizes: Array[int]
|
|
|
|
func _ready() -> void:
|
|
|
|
skip_control = %SkipControl
|
|
if skip_control is SkipControl:
|
|
skip_control.skip.connect(skip_text)
|
|
|
|
if get_tree().root.get_child(-1) == self:
|
|
play_scene()
|
|
story_array = story_array
|
|
progress = progress
|
|
|
|
func try_scroll():
|
|
var scroll_target: int
|
|
|
|
#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
|
|
else:
|
|
scroll_target = label.size.y - scroll_container.size.y
|
|
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")
|
|
|
|
await text_finished
|
|
|
|
if name == "draven":
|
|
trigger_intro()
|
|
|
|
animation_complete = true
|
|
|
|
skip_control.start_proceed_countdown()
|
|
|
|
await skip_control.proceed
|
|
|
|
animation_player.play("vanish")
|
|
|
|
await animation_player.animation_finished
|
|
|
|
finished.emit()
|
|
|
|
var intro_triggered:= false
|
|
func trigger_intro():
|
|
if not intro_triggered:
|
|
intro.emit()
|
|
intro_triggered = true
|
|
|
|
func skip_text():
|
|
if not animation_complete:
|
|
animation_player.stop(true)
|
|
text_finished.emit()
|
|
|
|
func _on_text_finished():
|
|
if not animation_complete:
|
|
text_finished.emit()
|