feat: add nearby social interactions
This commit is contained in:
@@ -26,6 +26,7 @@ const CAFE_NAME_LABEL_VISUAL_MAX_WIDTH: int = 118
|
||||
const CAFE_NAME_LABEL_VISUAL_CHAR_WIDTH: int = 12
|
||||
const CAFE_NAME_LABEL_OFFSET_Y: float = -96.0
|
||||
const WORLD_TEXT_THEME = preload("res://assets/ui/world_text_theme.tres")
|
||||
const InteractionAnchorUtil = preload("res://_Core/utils/InteractionAnchor.gd")
|
||||
const DIRECTION_ROWS: Dictionary = {
|
||||
"down": 0,
|
||||
"up": 1,
|
||||
@@ -38,6 +39,7 @@ var _nameLabel: Label
|
||||
var _cafeCompanionTarget: CafeCompanionTarget
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("whaletown_interactable")
|
||||
# 初始化时确保无物理处理
|
||||
set_physics_process(false)
|
||||
# 初始位置设为当前位置
|
||||
@@ -52,6 +54,53 @@ func _ready() -> void:
|
||||
if has_node("CollisionShape2D"):
|
||||
$CollisionShape2D.disabled = true
|
||||
|
||||
func get_interaction_actions(player: Node2D) -> Array[Dictionary]:
|
||||
if userId.strip_edges().is_empty() or player == null:
|
||||
return []
|
||||
var anchor_position: Vector2 = InteractionAnchorUtil.get_position(self)
|
||||
var distance: float = anchor_position.distance_to(player.global_position)
|
||||
if distance > 160.0:
|
||||
return []
|
||||
var display_name := username if not username.strip_edges().is_empty() else "玩家"
|
||||
return [
|
||||
{
|
||||
"id": "player_card:%s" % userId,
|
||||
"title": "查看 %s 的社区名片" % display_name,
|
||||
"distance": distance,
|
||||
"priority": 60,
|
||||
"callback": Callable(self, "_show_community_profile"),
|
||||
},
|
||||
{
|
||||
"id": "player_dm:%s" % userId,
|
||||
"title": "私聊 %s" % display_name,
|
||||
"distance": distance,
|
||||
"priority": 61,
|
||||
"callback": Callable(self, "_open_private_chat"),
|
||||
},
|
||||
{
|
||||
"id": "player_friend:%s" % userId,
|
||||
"title": "申请添加 %s 为好友" % display_name,
|
||||
"distance": distance,
|
||||
"priority": 62,
|
||||
"callback": Callable(self, "_request_friend"),
|
||||
},
|
||||
]
|
||||
|
||||
func _show_community_profile() -> void:
|
||||
var socialManager := get_node_or_null("/root/SocialManager")
|
||||
if socialManager != null and socialManager.has_method("show_profile"):
|
||||
socialManager.call("show_profile", userId)
|
||||
|
||||
func _open_private_chat() -> void:
|
||||
var socialManager := get_node_or_null("/root/SocialManager")
|
||||
if socialManager != null and socialManager.has_method("open_private_chat"):
|
||||
socialManager.call("open_private_chat", userId, username)
|
||||
|
||||
func _request_friend() -> void:
|
||||
var socialManager := get_node_or_null("/root/SocialManager")
|
||||
if socialManager != null and socialManager.has_method("request_friend"):
|
||||
socialManager.call("request_friend", userId, username)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
var eventSystem := get_node_or_null("/root/EventSystem")
|
||||
if eventSystem != null:
|
||||
|
||||
Reference in New Issue
Block a user