Zariel / bollo2

WoW Addon - Customizable buff/debuff display

This URL has Read+Write access

bollo2 / weapon.lua
100644 102 lines (86 sloc) 2.558 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
local Bollo = LibStub("AceAddon-3.0"):GetAddon("Bollo2")
local w = Bollo:NewModule("Weapons", "AceConsole-3.0", "AceEvent-3.0")
 
local GetWeaponEnchantInfo = GetWeaponEnchantInfo
local GetInventoryItemTexture = GetInventoryItemTexture
 
function w:OnEnable()
local defaults = {
profile = {
max = 2,
perRow = 2,
size = 32,
spacing = 20,
rowSpacing = 25,
growthX = "LEFT",
growthY = "DOWN",
scale = 1,
x = 0,
y = 0,
color = {
r = 1,
g = 0,
b = 1,
a = 0
}
}
}
 
TemporaryEnchantFrame:SetScript("OnUpdate", nil)
TemporaryEnchantFrame:Hide()
 
local weapon = Bollo:NewDisplay("Weapon", "TEMP", defaults)
Bollo.RegisterCallback(weapon, "OnUpdate", "Update")
weapon:Update()
 
 
local hasMainHandEnchant, mainHandExpiration, mainHandCharges, hasOffHandEnchant, offHandExpiration, offHandCharges
 
local NewIcon
do
local GetTimeleft = function(self)
--hasMainHandEnchant, mainHandExpiration, mainHandCharges, hasOffHandEnchant, offHandExpiration, offHandCharges = GetWeaponEnchantInfo()
 
local id = self.id
if id == 16 then
return hasMainHandEnchant and mainHandExpiration / 1000 or 0
else
return hasOffHandEnchant and offHandExpiration / 1000 or 0
end
end
 
local OnEnter = function(self)
if self:IsShown() then
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT")
GameTooltip:SetInventoryItem("player", self.id)
end
end
 
local OnMouseUp = function(self, button)
if button == "RightButton" then
CancelItemTempEnchantment(self.id - 15)
end
end
 
NewIcon = function()
local icon = Bollo:NewIcon()
icon:Hide()
icon.modules = {}
icon.base = "TEMP"
icon:SetScript("OnEnter", OnEnter)
icon:SetScript("OnMouseUp", OnMouseUp)
icon.GetTimeleft = GetTimeleft
 
return icon
end
end
 
-- Fucking OnUpdate gief events and UnitTempBuff
function weapon:Update()
if self.config then return end
 
hasMainHandEnchant, mainHandExpiration, mainHandCharges, hasOffHandEnchant, offHandExpiration, offHandCharges = GetWeaponEnchantInfo()
 
for i = 1, 2 do
local index = i + 15
if i == 1 and hasMainHandEnchant or i == 2 and hasOffHandEnchant then
local icon = self.icons[i] or NewIcon()
icon.id = index
icon:SetNormalTexture(GetInventoryItemTexture("player", icon.id))
icon.base = "TEMP"
icon:Setup(self.db.profile)
icon:Show()
self.icons[i] = icon
elseif self.icons[i] and self.icons[i]:IsShown() then
Bollo:DelIcon(self.icons[i])
self.icons[i] = nil
end
end
self:UpdatePosition()
end
end