93 lines
2.8 KiB
GDScript3
93 lines
2.8 KiB
GDScript3
|
|
@tool
|
||
|
|
extends CenterContainer
|
||
|
|
|
||
|
|
signal finished
|
||
|
|
signal intro
|
||
|
|
|
||
|
|
#TODO properly implement animation taking stage, as it should do, disabling processing when it does not have stage.
|
||
|
|
|
||
|
|
@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())
|
||
|
|
|
||
|
|
@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 >= 1:
|
||
|
|
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)
|
||
|
|
|
||
|
|
@onready var story_label: Label
|
||
|
|
@onready var label:RichTextLabel = %StoryLabel
|
||
|
|
@onready var scroll_container:ScrollContainer = %StoryScroll
|
||
|
|
@onready var animation_player: AnimationPlayer = %AnimationPlayer
|
||
|
|
@export var animation_complete:bool = false:
|
||
|
|
set(value):
|
||
|
|
animation_complete = value
|
||
|
|
if value:
|
||
|
|
scroll_container.scroll_vertical = ScrollContainer.ScrollMode.SCROLL_MODE_AUTO
|
||
|
|
progress = -1
|
||
|
|
animation_complete = value
|
||
|
|
|
||
|
|
var substring_sizes: Array[int]
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
if get_tree().root == self:
|
||
|
|
play_scene()
|
||
|
|
story_array = story_array
|
||
|
|
progress = progress
|
||
|
|
|
||
|
|
func try_scroll():
|
||
|
|
var scroll_target: int
|
||
|
|
if get_minimum_size().y * label.visible_ratio + scroll_container.scroll_vertical > scroll_container.get_minimum_size().y * 0.9:
|
||
|
|
if get_minimum_size().y * label.visible_ratio + scroll_container.scroll_vertical + scroll_container.get_minimum_size().y * 0.9 > label.get_minimum_size().y:
|
||
|
|
scroll_target = scroll_container.scroll_vertical + scroll_container.get_minimum_size().y * 0.8
|
||
|
|
else:
|
||
|
|
scroll_target = label.get_minimum_size().y - scroll_container.get_minimum_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 animation_player.animation_finished
|
||
|
|
|
||
|
|
if name == "draven":
|
||
|
|
trigger_intro()
|
||
|
|
|
||
|
|
animation_complete = true
|
||
|
|
|
||
|
|
finished.emit()
|
||
|
|
|
||
|
|
var intro_triggered:= false
|
||
|
|
func trigger_intro():
|
||
|
|
if not intro_triggered:
|
||
|
|
intro.emit()
|
||
|
|
|
||
|
|
func skip_text():
|
||
|
|
animation_complete = true
|
||
|
|
|
||
|
|
|