0
local SLOTIDS, FONTSIZE = {}, 12
0
for _,slot in pairs({"Head", "Shoulder", "Chest", "Waist", "Legs", "Feet", "Wrist", "Hands", "MainHand", "SecondaryHand", "Ranged"}) do SLOTIDS[slot] = GetInventorySlotInfo(slot .. "Slot") end
0
local frame = CreateFrame("Frame", nil, CharacterFrame)
0
+local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("tekability", {text = "100%"})
0
local function RYGColorGradient(perc)
0
@@ -30,8 +31,8 @@ local fontstrings = setmetatable({}, {
0
-function frame:OnEvent(event)
0
- if event == "ADDON_LOADED" then
0
+function frame:OnEvent(event, addon)
0
+ if event == "ADDON_LOADED" and addon:lower() ~= "tekability" then
0
for i,fstr in pairs(fontstrings) do
0
-- Re-apply the font, so that we catch any changes to NumberFontNormal by addons like ClearFont
0
local font, _, flags = NumberFontNormal:GetFont()
0
@@ -42,10 +43,12 @@ function frame:OnEvent(event)
0
if not CharacterFrame:IsVisible() then return end
0
for slot,id in pairs(SLOTIDS) do
0
local v1, v2 = GetInventoryItemDurability(id)
0
if v1 and v2 and v2 ~= 0 then
0
+ s1, s2 = s1 + v1, s2 + v2
0
local str = fontstrings[slot]
0
str:SetTextColor(RYGColorGradient(v1/v2))
0
str:SetText(string.format("%d%%", v1/v2*100))
0
@@ -54,17 +57,49 @@ function frame:OnEvent(event)
0
if str then str:SetText(nil) end
0
+ local r,g,b = RYGColorGradient(s1/s2)
0
+ dataobj.text = string.format("|cff%02x%02x%02x%d%%", r*255, g*255, b*255, s1/s2*100)
0
+ else dataobj.text = "---" end
0
frame:SetScript("OnEvent", frame.OnEvent)
0
frame:RegisterEvent("ADDON_LOADED")
0
-frame:SetScript("OnHide", function() frame:UnregisterEvent("UNIT_INVENTORY_CHANGED") end)
0
-frame:SetScript("OnShow", function()
0
- frame:RegisterEvent("UNIT_INVENTORY_CHANGED")
0
- frame:GetScript("OnEvent")("UNIT_INVENTORY_CHANGED")
0
+frame:RegisterEvent("UNIT_INVENTORY_CHANGED")
0
+------------------------
0
+------------------------
0
+local function GetTipAnchor(frame)
0
+ local x,y = frame:GetCenter()
0
+ if not x or not y then return "TOPLEFT", "BOTTOMLEFT" end
0
+ local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or ""
0
+ local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM"
0
+ return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
0
+function dataobj.OnLeave() GameTooltip:Hide() end
0
+function dataobj.OnEnter(self)
0
+ GameTooltip:SetOwner(self, "ANCHOR_NONE")
0
+ GameTooltip:SetPoint(GetTipAnchor(self))
0
+ GameTooltip:ClearLines()
0
+ GameTooltip:AddLine("tekability")
0
-if CharacterFrame:IsVisible() then frame:GetScript("OnShow")() end
0
+ for slot,id in pairs(SLOTIDS) do
0
+ local v1, v2 = GetInventoryItemDurability(id)
0
+ if v1 and v2 and v2 ~= 0 then
0
+ GameTooltip:AddDoubleLine(slot, string.format("%d%%", v1/v2*100), 1, 1, 1, RYGColorGradient(v1/v2))
Comments
No one has commented yet.