vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | local gratuity = AceLibrary("Gratuity-2.0") |
||
3 | local findstr = string.gsub(DURABILITY_TEMPLATE, "%%[^%s]+", "(.+)") |
||
4 | local abacus = AceLibrary("Abacus-2.0") |
||
5 | local dewdrop = AceLibrary("Dewdrop-2.0") |
||
6 | local tablet = AceLibrary("Tablet-2.0") |
||
7 | local crayon = AceLibrary("Crayon-2.0") |
||
8 | |||
9 | local items = { |
||
10 | {name = INVTYPE_HEAD, slot = "Head"}, |
||
11 | {name = INVTYPE_SHOULDER, slot = "Shoulder"}, |
||
12 | {name = INVTYPE_CHEST, slot = "Chest"}, |
||
13 | {name = INVTYPE_WAIST, slot = "Waist"}, |
||
14 | {name = INVTYPE_LEGS, slot = "Legs"}, |
||
15 | {name = INVTYPE_FEET, slot = "Feet"}, |
||
16 | {name = INVTYPE_WRIST, slot = "Wrist"}, |
||
17 | {name = INVTYPE_HAND, slot = "Hands"}, |
||
18 | {name = INVTYPE_WEAPONMAINHAND, slot = "MainHand"}, |
||
19 | {name = INVTYPE_WEAPONOFFHAND, slot = "SecondaryHand"}, |
||
20 | {name = INVTYPE_RANGED, slot = "Ranged"}, |
||
21 | } |
||
22 | |||
23 | |||
24 | FuBar_DuraTek = AceLibrary("AceAddon-2.0"):new("FuBarPlugin-2.0", "AceEvent-2.0", "AceDB-2.0") |
||
25 | FuBar_DuraTek:RegisterDB("DuraTek") |
||
26 | FuBar_DuraTek.hasIcon = true |
||
27 | FuBar_DuraTek.cannotHideText = false |
||
28 | |||
29 | |||
30 | function FuBar_DuraTek:OnEnable() |
||
31 | self:RegisterBucketEvent({ |
||
32 | "PLAYER_UNGHOST", |
||
33 | "PLAYER_DEAD", |
||
34 | "PLAYER_REGEN_ENABLED", |
||
35 | "UPDATE_INVENTORY_ALERTS", |
||
36 | "MERCHANT_SHOW", |
||
37 | "MERCHANT_CLOSED", |
||
38 | }, 1, "Update") |
||
39 | end |
||
40 | |||
41 | |||
42 | function FuBar_DuraTek:OnDataUpdate() |
||
43 | local t1, t2, tcost = 0, 0, 0 |
||
44 | for i in ipairs(items) do |
||
45 | local v1, v2, cost = self:UpdateItem(i) |
||
46 | t1, t2, tcost = t1 + v1, t2 + v2, tcost + cost |
||
47 | end |
||
48 | |||
49 | self.perc, self.totalcost = (t2 == 0) and 1 or t1/t2, tcost |
||
50 | end |
||
51 | |||
52 | |||
53 | function FuBar_DuraTek:OnTextUpdate() |
||
54 | self:SetText(string.format("|cff%s%d%%", crayon:GetThresholdHexColor(self.perc), self.perc * 100)) |
||
55 | end |
||
56 | |||
57 | |||
58 | function FuBar_DuraTek:OnTooltipUpdate() |
||
59 | local cat = tablet:AddCategory("columns", 3, "child_justify2", "RIGHT") |
||
60 | for _,item in ipairs(items) do |
||
61 | if item.hasItem and item.percent and item.percent > 0 then |
||
62 | cat:AddLine("text", item.name, "text2", (item.cost > 0) and abacus:FormatMoneyCondensed(item.cost, true) or "", |
||
63 | "text3", crayon:Colorize(crayon:GetThresholdHexColor(item.percent), string.format("%d%%", item.percent*100))) |
||
64 | end |
||
65 | end |
||
66 | cat:AddLine() |
||
67 | |||
68 | cat:AddLine("text", "Total", "text2", (self.totalcost > 0) and abacus:FormatMoneyFull(self.totalcost, true) or "", |
||
69 | "text3", string.format("%d%%", self.perc * 100)) |
||
70 | end |
||
71 | |||
72 | |||
73 | function FuBar_DuraTek:UpdateItem(index) |
||
74 | local item = items[index] |
||
75 | local id = GetInventorySlotInfo(item.slot .. "Slot") |
||
76 | local hasItem, _, cost = gratuity:SetInventoryItem("player", id) |
||
77 | |||
78 | local v1, v2 |
||
79 | if hasItem then _, _, v1, v2 = gratuity:Find(findstr) end |
||
80 | v1, v2, cost = tonumber(v1) or 0, tonumber(v2) or 0, tonumber(cost) or 0 |
||
81 | item.percent, item.cost = (v2 == 0) and 1 or v1/v2, cost |
||
82 | item.hasItem = hasItem |
||
83 | return v1, v2, cost |
||
84 | end |