feat(ui): 40250 item tooltip parity (thinboard, palette, sockets, stats)
This commit is contained in:
@@ -14,6 +14,7 @@ extends Node
|
||||
|
||||
const CursorManager = preload("res://ui/cursor_manager.gd")
|
||||
const ItemTooltip = preload("res://ui/item_tooltip.gd")
|
||||
const ItemTooltipView = preload("res://ui/item_tooltip_view.gd")
|
||||
const UiAssets = preload("res://ui/ui_assets.gd")
|
||||
const UiKit = preload("res://ui_kit.gd")
|
||||
const UiBuild = preload("res://ui/ui_build.gd")
|
||||
@@ -28,6 +29,7 @@ var proto: Node
|
||||
var item_list # ItemListDB (RefCounted)
|
||||
var _assets_root := ""
|
||||
var _tooltip_builder: RefCounted
|
||||
var _tooltip_view: Control = null
|
||||
var _root: Control
|
||||
var _tabbar: HBoxContainer
|
||||
var _grid: GridContainer
|
||||
@@ -134,6 +136,7 @@ func open() -> void:
|
||||
refresh()
|
||||
|
||||
func _close() -> void:
|
||||
_hide_slot_tooltip()
|
||||
_has_open_pos = false
|
||||
if item_mouse and item_mouse.has_method("unregister_owner"):
|
||||
item_mouse.unregister_owner(self)
|
||||
@@ -419,6 +422,9 @@ func _slot(it: Dictionary, pos: int) -> Button:
|
||||
slot.tooltip_text = _tooltip_builder.format(vnum, maxi(1, count), pd, it)
|
||||
slot.tooltip_text += "\n价格:%d" % int(it.get("price", 0))
|
||||
|
||||
slot.mouse_entered.connect(func(): _show_slot_tooltip(vnum, maxi(1, count), it))
|
||||
slot.mouse_exited.connect(func(): _hide_slot_tooltip())
|
||||
|
||||
slot.pressed.connect(func() -> void: _buy_slot(pos, it))
|
||||
slot.gui_input.connect(func(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
@@ -428,6 +434,31 @@ func _slot(it: Dictionary, pos: int) -> Button:
|
||||
slot.disabled = true
|
||||
return slot
|
||||
|
||||
func _get_tooltip_view() -> Control:
|
||||
if _root and _root.get_parent() and _root.get_parent().has_method("get_item_tooltip_view"):
|
||||
return _root.get_parent().get_item_tooltip_view(_assets_root, proto, item_list)
|
||||
if _tooltip_view == null or not is_instance_valid(_tooltip_view):
|
||||
_tooltip_view = ItemTooltipView.new()
|
||||
_tooltip_view.setup(_assets_root, proto, item_list, _tooltip_builder)
|
||||
_tooltip_view.visible = false
|
||||
_tooltip_view.z_index = 200
|
||||
if _root and is_instance_valid(_root):
|
||||
_root.add_child(_tooltip_view)
|
||||
return _tooltip_view
|
||||
|
||||
func _show_slot_tooltip(vnum: int, count: int, item_data: Dictionary) -> void:
|
||||
if vnum <= 0:
|
||||
return
|
||||
var pd: Dictionary = proto.item(vnum) if proto and proto.has_method("item") else {}
|
||||
var tv := _get_tooltip_view()
|
||||
if tv:
|
||||
tv.show_item(vnum, count, pd, item_data)
|
||||
|
||||
func _hide_slot_tooltip() -> void:
|
||||
var tv := _get_tooltip_view()
|
||||
if tv:
|
||||
tv.hide_tooltip()
|
||||
|
||||
func _direct_buy(pos: int, item: Dictionary) -> void:
|
||||
if _mode != 1 or item.is_empty() or pos < 0:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user