refactor: unify interactable components

This commit is contained in:
ANG-Server
2026-07-21 23:23:26 +08:00
parent 9dee47492c
commit 74a0fb8309
17 changed files with 241 additions and 208 deletions

View File

@@ -23,7 +23,6 @@ const COMPANION_NAMEPLATE_VISUAL_MAX_WIDTH: int = 118
const COMPANION_NAMEPLATE_VISUAL_CHAR_WIDTH: int = 12
const NPC_NAMEPLATE_OFFSET_Y: float = -136.0
const HIRED_PLAYER_NAMEPLATE_OFFSET_Y: float = -96.0
const InteractionAnchorUtil = preload("res://_Core/utils/InteractionAnchor.gd")
@onready var player: PlayerController = $YSortWorld/Characters/Players/Player
@onready var playerCamera: Camera2D = $YSortWorld/Characters/Players/Player/Camera2D
@@ -39,7 +38,6 @@ var _isChangingScene: bool = false
var _lastRecruitmentClickMsec: int = 0
func _ready() -> void:
add_to_group("whaletown_interactable")
_align_service_occupants()
_configure_static_companion_nameplates()
_apply_spawn_point()
@@ -47,6 +45,7 @@ func _ready() -> void:
_connect_exit_area()
_connect_recruitment_area()
_connect_cafe_companion_events()
_register_interactables()
_discover_destination()
func _discover_destination() -> void:
@@ -103,29 +102,28 @@ func _connect_cafe_companion_events() -> void:
eventSystem.call("connect_event", EventNames.CAFE_COMPANION_AGENT_REGISTERED, _on_cafe_companion_agent_registered, self)
eventSystem.call("connect_event", EventNames.CAFE_COMPANION_EMPLOYMENT_RESIGNED, _on_cafe_companion_employment_resigned, self)
func _register_interactables() -> void:
var exit_interactable: InteractableComponent = InteractableComponent.new()
exit_interactable.interaction_id = "cafe_exit"
exit_interactable.interaction_title = "离开咖啡馆"
exit_interactable.interaction_priority = 20
exit_interactable.interaction_distance = 160.0
exit_interactable.activation_method = &"_leave_to_work_zone"
exit_interactable.anchor_path = NodePath("InteractionAreas/ExitToWorkZoneArea")
add_child(exit_interactable)
var recruitment_interactable: InteractableComponent = InteractableComponent.new()
recruitment_interactable.interaction_id = "cafe_recruitment"
recruitment_interactable.interaction_title = "登记咖啡店陪伴机器人"
recruitment_interactable.interaction_priority = 30
recruitment_interactable.interaction_distance = 150.0
recruitment_interactable.activation_method = &"_try_emit_recruitment_selected"
recruitment_interactable.anchor_path = NodePath("InteractionAreas/CafeRecruitmentLogoArea")
add_child(recruitment_interactable)
func _on_exit_area_body_entered(body: Node2D) -> void:
return
func get_interaction_actions(local_player: Node2D) -> Array[Dictionary]:
if _isChangingScene or exitToWorkZoneArea == null:
return []
var anchor_position: Vector2 = InteractionAnchorUtil.get_position(exitToWorkZoneArea)
var distance: float = anchor_position.distance_to(local_player.global_position)
if distance > 160.0:
return []
return [{
"id": "cafe_exit",
"title": "离开咖啡馆",
"distance": distance,
"priority": 20,
"callback": Callable(self, "_leave_to_work_zone"),
}]
func get_interaction_marker_positions() -> Array[Vector2]:
if exitToWorkZoneArea == null:
return []
return [InteractionAnchorUtil.get_position(exitToWorkZoneArea)]
func _leave_to_work_zone() -> void:
if _isChangingScene:
return