-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibQTipHelper.lua
More file actions
133 lines (110 loc) · 3.98 KB
/
LibQTipHelper.lua
File metadata and controls
133 lines (110 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
--- LibQTipHelper: Helper module for LibQTip-2.0 integration in SimpleUnitFrames
--- Provides common patterns and utilities for multi-column tooltips
---
local AceAddon = LibStub("AceAddon-3.0")
local addon = AceAddon and AceAddon:GetAddon("SimpleUnitFrames", true)
if not addon then
-- Store globally for access after addon initialization
_G["SimpleUnitFrames_LibQTipHelper"] = {}
return _G["SimpleUnitFrames_LibQTipHelper"]
end
-- Public module
local LibQTipHelper = {}
-- Attach to addon for easy access
addon.LibQTipHelper = LibQTipHelper
--- Get the LibQTip-2.0 library
--- @return LibQTip-2.0|nil
local function GetQTip()
return LibStub:GetLibrary("LibQTip-2.0")
end
--- Create a frame stats tooltip showing health, power, and performance data
--- @param frames table Array of unit frames to display
--- @return LibQTip-2.0.Tooltip|nil The created tooltip, or nil if LibQTip unavailable
function LibQTipHelper:CreateFrameStatsTooltip(frames)
local QTip = GetQTip()
if not QTip then
return nil
end
-- Create tooltip with 4 columns: Frame name, Health %, Power, Update Time
local tooltip = QTip:AcquireTooltip("SUF_FrameStats", 4, "LEFT", "CENTER", "CENTER", "CENTER")
if not tooltip then
return nil
end
-- Configure appearance (use string font names to avoid nil references)
tooltip:SetDefaultFont("GameFontNormalSmall")
tooltip:SetDefaultHeadingFont("GameFontNormalSmall")
tooltip:SetCellMarginH(3)
tooltip:SetCellMarginV(2)
-- Add header row
tooltip:AddHeadingRow("Frame Name", "Health", "Power", "Status")
-- Validate frames table
if not frames or type(frames) ~= "table" then
tooltip:AddRow("No frames", "—", "—", "Invalid")
return tooltip
end
-- Add frame data rows
local frameCount = 0
for i, frame in ipairs(frames) do
if frame then
frameCount = frameCount + 1
-- Get unit frame type name
local frameName = frame.sufUnitType or frame:GetName() or ("Frame " .. i)
-- Get health info
local healthPercent = "—"
if frame.Health and frame.Health.Value then
local val = tonumber(frame.Health.Value)
if val and val >= 0 then
healthPercent = format("%.0f%%", val * 100)
end
end
-- Get power info
local powerValue = "—"
if frame.Power and frame.Power.Value then
local val = tonumber(frame.Power.Value)
if val and val >= 0 then
powerValue = format("%.0f", val)
end
end
-- Get visibility status
local status = frame:IsVisible() and "Visible" or "Hidden"
-- Add row to tooltip
tooltip:AddRow(frameName, healthPercent, powerValue, status)
end
end
-- If no frames, add placeholder row
if frameCount == 0 then
tooltip:AddRow("No frames loaded", "—", "—", "Waiting")
end
-- Add summary separator and count
tooltip:AddSeparator()
tooltip:AddRow("Total", frameCount .. " frames", "—", "Active")
return tooltip
end
--- Release all active frame stat tooltips
--- @return nil
function LibQTipHelper:ReleaseFrameStatsTooltip()
local QTip = GetQTip()
if not QTip then
return
end
local key = "SUF_FrameStats"
if QTip:IsAcquiredTooltip(key) then
QTip:ReleaseTooltip(string.format("SUF_FrameStats"))
end
end
--- Release all tooltips owned by LibQTipHelper
--- @return nil
function LibQTipHelper:ReleaseAllTooltips()
local QTip = GetQTip()
if not QTip then
return
end
-- Iterate and release known tooltips
for key, tooltip in QTip:TooltipPairs() do
if key and key:match("^SUF_") then
QTip:ReleaseTooltip(tooltip)
end
end
end
return LibQTipHelper