forked from xiangwang25/whale-town-front-v2
refactor: unify interactable components
This commit is contained in:
@@ -18,7 +18,6 @@ class_name NPCController
|
||||
signal interaction_happened(text: String)
|
||||
|
||||
const CHAT_BUBBLE_SCENE: PackedScene = preload("res://scenes/ui/ChatBubble.tscn")
|
||||
const InteractionAnchorUtil = preload("res://_Core/utils/InteractionAnchor.gd")
|
||||
const CHAT_BUBBLE_LAYER_NAME: String = "WorldChatBubbleLayer"
|
||||
const CHAT_BUBBLE_TARGET_OFFSET: Vector2 = Vector2(0, -84)
|
||||
const NPC_TALKED_EVENT: String = "npc_talked"
|
||||
@@ -42,7 +41,14 @@ const NAMEPLATE_VISUAL_CHAR_WIDTH: int = 12
|
||||
var _nameplate: Label
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("whaletown_interactable")
|
||||
if get_node_or_null("CafeCompanionTarget") == null:
|
||||
var interactable: InteractableComponent = InteractableComponent.new()
|
||||
interactable.interaction_id = "npc:%s" % str(get_path())
|
||||
interactable.interaction_title = "与 %s 交谈" % npcName
|
||||
interactable.interaction_priority = 40
|
||||
interactable.interaction_distance = interactionDistance
|
||||
interactable.activation_method = &"interact"
|
||||
add_child(interactable)
|
||||
# 播放场景里配置好的待机动画,让不同 NPC 可以复用同一个控制器。
|
||||
if animation_player.has_animation("idle"):
|
||||
animation_player.play("idle")
|
||||
@@ -68,19 +74,6 @@ func interact() -> void:
|
||||
})
|
||||
interaction_happened.emit(dialogue)
|
||||
|
||||
func get_interaction_actions(player: Node2D) -> Array[Dictionary]:
|
||||
var anchor_position: Vector2 = InteractionAnchorUtil.get_position(self)
|
||||
var distance: float = anchor_position.distance_to(player.global_position)
|
||||
if distance > interactionDistance:
|
||||
return []
|
||||
return [{
|
||||
"id": "npc:%s" % get_instance_id(),
|
||||
"title": "与 %s 交谈" % npcName,
|
||||
"distance": distance,
|
||||
"priority": 40,
|
||||
"callback": Callable(self, "interact"),
|
||||
}]
|
||||
|
||||
# 在 NPC 头顶生成一次性聊天气泡。
|
||||
#
|
||||
# 参数:
|
||||
|
||||
Reference in New Issue
Block a user