xiandie/scene/entity/closeup.gd
2025-05-15 04:43:55 +08:00

55 lines
1.3 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@tool
extends Interactable2D
class_name Closeup2D
# 退出信号,默认 arg 为 null可能是一个 bool 值,从 packed_scene 的 exit 信号中传递过来
signal exit(arg)
@export var packed_scene: PackedScene
@onready var sign = $Sign as Sign
var current_child: Node
func _ready() -> void:
super._ready()
if Engine.is_editor_hint():
return
interacted.connect(display)
# 可以直接调用
func display() -> void:
if current_child:
# 先退出
_exit()
if packed_scene:
SceneManager.freeze_player(0)
# 展示时,禁用 sign 的输入
sign.pass_unhandled_input = true
current_child = packed_scene.instantiate()
add_child(current_child)
if current_child.has_signal("exit"):
current_child.connect("exit", _exit)
else:
printerr("[特写界面] Scene does not have exit signal, packed_scene:", packed_scene)
func _exit(arg = null):
if current_child:
SceneManager.release_player()
current_child.queue_free()
exit.emit(arg)
# 退出时,恢复 sign 的输入
sign.pass_unhandled_input = false
func _unhandled_input(event: InputEvent) -> void:
if not current_child:
return
# 在有特写界面时,阻塞输入
get_viewport().set_input_as_handled()
if event.is_action_pressed("cancel") or event.is_action_pressed("escape"):
_exit()