public
Description: WoW Addon - Durability display
Homepage: http://www.tekkub.net/
Clone URL: git://github.com/tekkub/tekability.git
Click here to lend your support to: tekability and make a donation at www.pledgie.com !
Add LDB feed
tekkub (author)
Sat Jul 12 14:24:58 -0700 2008
commit  3ff679fa3a40d7d3845bb662daecc90a2cc9eb2e
tree    ab82d1c97f2025176ff38e1686b51af64c4cbf26
parent  5ea927aa250b416efe03567a26dc915ed437cba7
...
3
4
5
 
6
7
8
...
30
31
32
33
34
 
 
35
36
37
...
42
43
44
 
45
46
47
48
 
49
50
51
...
54
55
56
 
 
 
 
 
57
58
59
60
61
62
63
64
65
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
69
70
 
 
 
 
 
 
 
 
 
 
...
3
4
5
6
7
8
9
...
31
32
33
 
 
34
35
36
37
38
...
43
44
45
46
47
48
49
50
51
52
53
54
...
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
0
@@ -3,6 +3,7 @@
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
 
0
 
0
 local function RYGColorGradient(perc)
0
@@ -30,8 +31,8 @@ local fontstrings = setmetatable({}, {
0
 })
0
 
0
 
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
 
0
   if not CharacterFrame:IsVisible() then return end
0
 
0
+ local s1, s2 = 0, 0
0
   for slot,id in pairs(SLOTIDS) do
0
     local v1, v2 = GetInventoryItemDurability(id)
0
 
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
     end
0
   end
0
+
0
+ if s2 > 0 then
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
 end
0
 
0
 
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
-end)
0
+frame:RegisterEvent("UNIT_INVENTORY_CHANGED")
0
+
0
+
0
+------------------------
0
+-- Tooltip! --
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
+end
0
+
0
+
0
+function dataobj.OnLeave() GameTooltip:Hide() end
0
+
0
+
0
+function dataobj.OnEnter(self)
0
+ GameTooltip:SetOwner(self, "ANCHOR_NONE")
0
+ GameTooltip:SetPoint(GetTipAnchor(self))
0
+ GameTooltip:ClearLines()
0
 
0
+ GameTooltip:AddLine("tekability")
0
 
0
--- Handle LoD
0
-if CharacterFrame:IsVisible() then frame:GetScript("OnShow")() end
0
+ for slot,id in pairs(SLOTIDS) do
0
+ local v1, v2 = GetInventoryItemDurability(id)
0
+
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))
0
+ end
0
+ end
0
+
0
+ GameTooltip:Show()
0
+end
...
4
5
6
7
8
 
9
10
 
11
12
13
14
15
 
 
 
 
16
...
4
5
6
 
 
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
@@ -4,13 +4,17 @@
0
 ## Notes: Simple item durability readout in the character frame.
0
 ## Author: Tekkub Stoutwrithe
0
 ## Version: Alpha
0
-## X-Credits: Fizzle by phyber
0
-## X-Website: http://code.google.com/p/tekkub-wow/
0
+## X-Website: http://www.tekkub.net/
0
 ## X-Email: tekkub-wow@googlegroups.com
0
 ## X-Category: Inventory
0
+## X-Credits: Fizzle by phyber
0
 
0
 ## LoadManagers: AddonLoader
0
 ## X-LoadOn-Hooks: CharacterFrame_OnShow
0
 ## X-LoadOn-CharacterFrame_OnShow: LoadAddOn('tekability')
0
 
0
+LibStub.lua
0
+CallbackHandler-1.0.lua
0
+LibDataBroker-1.1\LibDataBroker-1.1.lua
0
+
0
 tekability.lua

Comments

    No one has commented yet.