- item_tooltip_view.gd: 新增 avoid_rect 属性,tooltip 与装备窗口重叠时自动推到左侧 - inventory_ui.gd: 悬停装备时传入窗口矩形作为避让区域 - 包含其他累积的功能开发和测试文件
57 lines
1.9 KiB
GDScript
57 lines
1.9 KiB
GDScript
# ItemTooltipBridge —— all item-bearing windows share the 40250 ItemTooltipView.
|
|
#
|
|
# Native Control.tooltip_text is deliberately disabled for item slots. The
|
|
# reference client owns one custom ItemToolTip instance and switches its data
|
|
# as the pointer moves between inventory, storage, exchange and shop windows.
|
|
extends RefCounted
|
|
|
|
const ItemTooltipView = preload("res://ui/item_tooltip_view.gd")
|
|
|
|
var _ui: CanvasLayer
|
|
var _parent: Node
|
|
var _proto: Node
|
|
var _assets_root := ""
|
|
var _item_list: RefCounted
|
|
var _view: Control
|
|
|
|
func setup(parent: Node, proto: Node = null, assets_root := "", item_list: RefCounted = null) -> void:
|
|
_parent = parent
|
|
_ui = parent as CanvasLayer
|
|
_proto = proto
|
|
_assets_root = assets_root if assets_root != "" else AssetRoot.path()
|
|
_item_list = item_list
|
|
|
|
func bind(control: Control, item_getter: Callable) -> void:
|
|
if control == null:
|
|
return
|
|
control.tooltip_text = ""
|
|
control.mouse_entered.connect(func() -> void:
|
|
var item = item_getter.call()
|
|
show_item(item if item is Dictionary else {}))
|
|
control.mouse_exited.connect(hide)
|
|
|
|
func show_item(item: Dictionary) -> void:
|
|
var vnum := int(item.get("vnum", 0))
|
|
if vnum <= 0:
|
|
hide()
|
|
return
|
|
var count := maxi(1, int(item.get("count", 1)))
|
|
var proto_data: Dictionary = _proto.item(vnum) if _proto and _proto.has_method("item") else {}
|
|
if _ui and _ui.has_method("show_item_tooltip"):
|
|
_ui.show_item_tooltip(vnum, count, proto_data, item, {}, _assets_root, _proto, _item_list)
|
|
return
|
|
if _view == null or not is_instance_valid(_view):
|
|
_view = ItemTooltipView.new()
|
|
_view.setup(_assets_root, _proto, _item_list)
|
|
_view.visible = false
|
|
_view.z_index = 200
|
|
if _parent:
|
|
_parent.add_child(_view)
|
|
_view.show_item(vnum, count, proto_data, item, {})
|
|
|
|
func hide() -> void:
|
|
if _ui and _ui.has_method("hide_item_tooltip"):
|
|
_ui.hide_item_tooltip()
|
|
elif _view and is_instance_valid(_view):
|
|
_view.hide_tooltip()
|