2025-05-13 11:45:33 +00:00
|
|
|
|
@tool
|
|
|
|
|
|
|
|
|
|
extends Interactable2D
|
|
|
|
|
class_name Closeup2D
|
|
|
|
|
|
|
|
|
|
# 退出信号,默认 arg 为 null,可能是一个 bool 值,从 packed_scene 的 exit 信号中传递过来
|
|
|
|
|
signal exit(arg)
|
|
|
|
|
|
|
|
|
|
@export var packed_scene: PackedScene
|
2025-06-24 17:52:30 +00:00
|
|
|
|
@export var quit_closeup_on_escape := true
|
2025-05-13 11:45:33 +00:00
|
|
|
|
var current_child: Node
|
|
|
|
|
|
2025-06-24 20:12:24 +00:00
|
|
|
|
|
2025-05-13 11:45:33 +00:00
|
|
|
|
func _ready() -> void:
|
|
|
|
|
super._ready()
|
|
|
|
|
if Engine.is_editor_hint():
|
|
|
|
|
return
|
2025-06-25 17:53:16 +00:00
|
|
|
|
interacted.connect(display)
|
2025-06-11 05:43:36 +00:00
|
|
|
|
|
2025-05-13 11:45:33 +00:00
|
|
|
|
|
2025-05-14 20:43:55 +00:00
|
|
|
|
# 可以直接调用
|
|
|
|
|
func display() -> void:
|
2025-05-13 11:45:33 +00:00
|
|
|
|
if current_child:
|
|
|
|
|
# 先退出
|
|
|
|
|
_exit()
|
|
|
|
|
if packed_scene:
|
2025-06-24 20:12:24 +00:00
|
|
|
|
SceneManager.freeze_player(0, action_key)
|
2025-06-13 08:03:19 +00:00
|
|
|
|
# 展示时,禁用 sign_mark 的输入
|
|
|
|
|
sign_mark.pass_unhandled_input = true
|
2025-05-13 11:45:33 +00:00
|
|
|
|
current_child = packed_scene.instantiate()
|
|
|
|
|
add_child(current_child)
|
|
|
|
|
if current_child.has_signal("exit"):
|
|
|
|
|
current_child.connect("exit", _exit)
|
2025-06-21 05:10:55 +00:00
|
|
|
|
elif GlobalConfig.DEBUG:
|
|
|
|
|
print("[特写界面] no exit signal, packed_scene:", packed_scene)
|
2025-05-13 11:45:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _exit(arg = null):
|
|
|
|
|
if current_child:
|
|
|
|
|
SceneManager.release_player()
|
|
|
|
|
current_child.queue_free()
|
|
|
|
|
exit.emit(arg)
|
2025-06-13 08:03:19 +00:00
|
|
|
|
# 退出时,恢复 sign_mark 的输入
|
|
|
|
|
sign_mark.pass_unhandled_input = false
|
2025-05-13 11:45:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
|
|
|
if not current_child:
|
|
|
|
|
return
|
2025-06-21 08:22:31 +00:00
|
|
|
|
if (
|
2025-06-24 17:52:30 +00:00
|
|
|
|
quit_closeup_on_escape
|
2025-06-21 08:22:31 +00:00
|
|
|
|
and (event.is_action_pressed("cancel") or event.is_action_pressed("escape"))
|
|
|
|
|
):
|
2025-05-13 11:45:33 +00:00
|
|
|
|
_exit()
|
2025-06-21 08:22:31 +00:00
|
|
|
|
get_viewport().set_input_as_handled()
|
|
|
|
|
# 在有特写界面时,阻塞 interact 输入
|
|
|
|
|
elif event.is_action_pressed("interact"):
|
|
|
|
|
get_viewport().set_input_as_handled()
|