79 lines
2.1 KiB
GDScript
79 lines
2.1 KiB
GDScript
extends Control
|
|
|
|
signal os_finished
|
|
|
|
@onready var os_pausing_timer = %OSTimer as Timer
|
|
@onready var os_label = %OSLabel as DialogueLabel
|
|
@onready var os_contaner = %PanelContainer as PanelContainer
|
|
|
|
var os_tween: Tween
|
|
|
|
|
|
func _ready() -> void:
|
|
if Engine.is_editor_hint():
|
|
# 显示 os 效果
|
|
os_contaner.modulate.a = 1.0
|
|
os_label.text = "os 测试文本"
|
|
return
|
|
os_contaner.modulate.a = 0.0
|
|
os_label.text = ""
|
|
os_pausing_timer.timeout.connect(_on_os_pausing_timeout)
|
|
os_finished.connect(func(): locking = false)
|
|
|
|
|
|
var locking := false:
|
|
set(val):
|
|
if val != locking:
|
|
locking = val
|
|
if val:
|
|
SceneManager.lock_player()
|
|
else:
|
|
SceneManager.unlock_player()
|
|
|
|
|
|
func pop_os(lines := []) -> void:
|
|
if os_tween and os_tween.is_valid():
|
|
os_tween.kill()
|
|
os_finished.emit()
|
|
locking = true
|
|
os_tween = create_tween()
|
|
os_label.text = ""
|
|
os_tween.tween_property(os_contaner, "modulate:a", 1.0, 0.2)
|
|
for line in lines:
|
|
# os_pausing_timer 启动最小时长 0.01 秒
|
|
var duration = max(GlobalConfigManager.config.os_wait_time, 0.01)
|
|
os_tween.tween_callback(_os_load_line.bind(line, duration))
|
|
os_tween.tween_property(os_contaner, "modulate:a", 0.0, 0.2)
|
|
os_tween.tween_callback(os_finished.emit)
|
|
# os 结束
|
|
await os_finished
|
|
|
|
|
|
func _os_load_line(line: DialogueLine, duration: float):
|
|
os_label.dialogue_line = line
|
|
os_label.type_out()
|
|
if GlobalConfigManager.config.os_auto_end:
|
|
if os_label.finished_typing.is_connected(os_pausing_timer.start):
|
|
os_label.finished_typing.disconnect(os_pausing_timer.start)
|
|
os_label.finished_typing.connect(os_pausing_timer.start.bind(duration), CONNECT_ONE_SHOT)
|
|
os_tween.pause()
|
|
|
|
|
|
func _on_os_pausing_timeout():
|
|
if os_tween and os_tween.is_valid():
|
|
os_tween.play()
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("interact"):
|
|
if os_label.is_typing:
|
|
get_viewport().set_input_as_handled()
|
|
os_label.skip_typing()
|
|
elif (
|
|
not os_pausing_timer.is_stopped()
|
|
or (not GlobalConfigManager.config.os_auto_end and os_tween and os_tween.is_valid())
|
|
):
|
|
get_viewport().set_input_as_handled()
|
|
os_pausing_timer.stop()
|
|
_on_os_pausing_timeout()
|