2025-01-12 11:36:41 +00:00
|
|
|
|
# @tool
|
2025-01-20 13:45:47 +00:00
|
|
|
|
class_name Portal2D extends Sprite2D
|
2024-12-26 13:58:37 +00:00
|
|
|
|
|
2025-01-20 13:45:47 +00:00
|
|
|
|
@export var enabled := true:
|
|
|
|
|
set(val):
|
|
|
|
|
enabled = val
|
|
|
|
|
if is_node_ready():
|
|
|
|
|
_check_sign_mark()
|
2025-01-12 11:36:41 +00:00
|
|
|
|
@export var immediately := true
|
2024-12-27 13:32:12 +00:00
|
|
|
|
@export_enum("left", "right", "1", "2", "3", "4", "5", "6", "7", "8", "9") var portal_name := "left":
|
2024-12-26 13:58:37 +00:00
|
|
|
|
set(value):
|
2024-12-27 13:32:12 +00:00
|
|
|
|
#if portal_name:
|
|
|
|
|
#remove_from_group("portal_"+portal_name)
|
2024-12-26 13:58:37 +00:00
|
|
|
|
portal_name = value
|
2024-12-27 13:32:12 +00:00
|
|
|
|
#add_to_group("portal_"+value)
|
|
|
|
|
name = "portal_" + value
|
|
|
|
|
@export var target_scene := "c02_s00"
|
|
|
|
|
@export_enum("none", "left", "right", "1", "2", "3", "4", "5", "6", "7", "8", "9")
|
2025-01-20 13:45:47 +00:00
|
|
|
|
var target_portal := "none":
|
|
|
|
|
set(value):
|
|
|
|
|
target_portal = value
|
|
|
|
|
if is_node_ready():
|
|
|
|
|
_check_sign_mark()
|
2025-01-12 11:36:41 +00:00
|
|
|
|
@export var default_texture: Texture2D
|
|
|
|
|
@export var opened_texture: Texture2D
|
|
|
|
|
@export var opened := false:
|
|
|
|
|
set(new_val):
|
|
|
|
|
opened = new_val
|
|
|
|
|
if is_node_ready():
|
|
|
|
|
_checkout_texture()
|
2024-12-26 13:58:37 +00:00
|
|
|
|
|
2025-01-14 00:56:51 +00:00
|
|
|
|
@onready var sfx = %Sfx as Sfx
|
2025-01-08 00:51:09 +00:00
|
|
|
|
@onready var sign_mark = %Sign as Sign
|
2024-12-26 13:58:37 +00:00
|
|
|
|
@onready var area2d = %Area2D as Area2D
|
|
|
|
|
|
2024-12-27 13:32:12 +00:00
|
|
|
|
var activated := false
|
|
|
|
|
var action_times := 0
|
|
|
|
|
|
2024-12-26 13:58:37 +00:00
|
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
2024-12-27 13:32:12 +00:00
|
|
|
|
name = "portal_" + portal_name
|
2025-01-12 11:36:41 +00:00
|
|
|
|
_checkout_texture()
|
2025-01-20 13:45:47 +00:00
|
|
|
|
_check_sign_mark()
|
2025-01-12 11:36:41 +00:00
|
|
|
|
if Engine.is_editor_hint():
|
|
|
|
|
return
|
2024-12-26 13:58:37 +00:00
|
|
|
|
area2d.body_entered.connect(_reset)
|
|
|
|
|
area2d.body_exited.connect(_on_cancel)
|
|
|
|
|
sign_mark.interacted.connect(_on_interacted)
|
|
|
|
|
sign_mark.cancel.connect(_on_cancel)
|
2024-12-27 07:56:45 +00:00
|
|
|
|
# if GlobalConfig.DEBUG:
|
|
|
|
|
# var label = Label.new()
|
|
|
|
|
# label.text = portal_name
|
|
|
|
|
# label.name = "Label"
|
|
|
|
|
# add_child(label)
|
2024-12-26 13:58:37 +00:00
|
|
|
|
|
2025-01-12 11:36:41 +00:00
|
|
|
|
func _checkout_texture():
|
2025-01-20 13:45:47 +00:00
|
|
|
|
if opened and opened_texture:
|
2025-01-12 11:36:41 +00:00
|
|
|
|
texture = opened_texture
|
|
|
|
|
else:
|
|
|
|
|
texture = default_texture
|
2024-12-27 13:32:12 +00:00
|
|
|
|
|
2025-01-20 13:45:47 +00:00
|
|
|
|
func _check_sign_mark():
|
|
|
|
|
if target_portal == "none" or not enabled:
|
|
|
|
|
sign_mark.enabled = false
|
|
|
|
|
else:
|
|
|
|
|
sign_mark.enabled = true
|
|
|
|
|
|
2024-12-26 13:58:37 +00:00
|
|
|
|
func _on_interacted() -> void:
|
2024-12-27 13:32:12 +00:00
|
|
|
|
if target_portal == "none":
|
|
|
|
|
return
|
2025-01-14 00:56:51 +00:00
|
|
|
|
# 传送,queue free 导致 sfx 无法播放,使用全局声源
|
|
|
|
|
sfx.global_play()
|
2024-12-27 13:32:12 +00:00
|
|
|
|
if GlobalConfig.DEBUG:
|
2025-01-21 07:58:21 +00:00
|
|
|
|
print("传送前往", target_scene, target_portal, " immediately=", immediately)
|
2024-12-27 13:32:12 +00:00
|
|
|
|
var ground_loader = SceneManager.get_ground_loader() as GroundLoader
|
|
|
|
|
if ground_loader:
|
2025-01-12 11:36:41 +00:00
|
|
|
|
ground_loader.transition_to_scene(target_scene, target_portal, immediately)
|
2024-12-27 13:32:12 +00:00
|
|
|
|
|
2024-12-26 13:58:37 +00:00
|
|
|
|
|
2024-12-27 07:56:45 +00:00
|
|
|
|
func _on_cancel(_body = null):
|
2024-12-27 13:32:12 +00:00
|
|
|
|
activated = false
|
|
|
|
|
|
2024-12-26 13:58:37 +00:00
|
|
|
|
|
2024-12-27 07:56:45 +00:00
|
|
|
|
func _reset(_body):
|
2024-12-27 13:32:12 +00:00
|
|
|
|
activated = true
|
|
|
|
|
|
2025-01-12 06:02:00 +00:00
|
|
|
|
# 暂时不启用自动传送
|
|
|
|
|
# func _input(event: InputEvent) -> void:
|
|
|
|
|
# # 长按自动传送
|
|
|
|
|
# if activated:
|
|
|
|
|
# if portal_name == "left" and target_portal == "right":
|
|
|
|
|
# if event.is_action("left"):
|
|
|
|
|
# action_times += 1
|
|
|
|
|
# elif event.is_action("right"):
|
|
|
|
|
# action_times = 0
|
|
|
|
|
# if action_times >= 7:
|
|
|
|
|
# activated = false
|
|
|
|
|
# action_times = 0
|
|
|
|
|
# %Sfx.play()
|
|
|
|
|
# _on_interacted()
|
|
|
|
|
# if portal_name == "right" and target_portal == "left":
|
|
|
|
|
# if event.is_action("right"):
|
|
|
|
|
# action_times += 1
|
|
|
|
|
# elif event.is_action("left"):
|
|
|
|
|
# action_times = 0
|
|
|
|
|
# if action_times >= 7:
|
|
|
|
|
# activated = false
|
|
|
|
|
# action_times = 0
|
|
|
|
|
# %Sfx.play()
|
|
|
|
|
# _on_interacted()
|