-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfUI-bettertotems.lua
175 lines (149 loc) · 6.58 KB
/
pfUI-bettertotems.lua
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
pfUI:RegisterModule("bettertotems", "vanilla:tbc", function ()
local _, class = UnitClass("player")
local slots = {
[FIRE_TOTEM_SLOT] = { r = .5, g = .2, b = .1 },
[EARTH_TOTEM_SLOT] = { r = .2, g = .4, b = .1 },
[WATER_TOTEM_SLOT] = { r = .1, g = .4, b = .6 },
[AIR_TOTEM_SLOT] = { r = .4, g = .1, b = .7 },
}
local totems = CreateFrame("Frame", "pfBetterTotems", UIParent)
totems:RegisterEvent("PLAYER_TOTEM_UPDATE")
totems:RegisterEvent("PLAYER_ENTERING_WORLD")
totems:SetScript("OnEvent", function(self)
totems:RefreshList()
end)
if pfUI.client <= 11200 and class == "SHAMAN" then
-- there's no totem event in vanilla using ticks instead
local eventemu = CreateFrame("Frame")
eventemu:SetScript("OnUpdate", function()
if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + .5 end
totems:RefreshList()
end)
end
totems.OnEnter = function(self)
if not this.id then return end
local active, name, start, duration, icon, unitId = GetBetterTotemInfo(this.id)
local color = slots[this.id]
GameTooltip:SetOwner(this, "ANCHOR_LEFT")
GameTooltip:SetText(name, color.r+.2, color.g+.2, color.b+.2)
GameTooltip:Show()
end
totems.OnLeave = function(self)
GameTooltip:Hide()
end
totems.OnClick = function(self)
if pfUI.client <= 11200 and this.id and arg1 and arg1 == "LeftButton" then
-- Try to recast totem on left click in vanilla
local active, name, start, duration, icon, unitId = GetBetterTotemInfo(this.id)
if name then CastSpellByName(name) end
elseif pfUI.client > 11200 and this.id and arg1 and arg1 == "RightButton" then
-- Try to cancel totem on right click in tbc+
DestroyTotem(this.id)
end
end
totems.RefreshList = function(self)
local count = 0
for i = 1, MAX_TOTEMS do
local active, name, start, duration, icon, unitId = GetBetterTotemInfo(i)
if active and icon and icon ~= "" then
count = count + 1
local color = slots[i]
self.bar[count]:Show()
self.bar[count]:SetBackdropBorderColor(color.r, color.g, color.b)
self.bar[count].icon:SetTexture(icon)
self.bar[count].id = i
local _,_,_,_,rank = GetTalentInfo(3,8)
local totemicMastery = rank == 1
local inRange = LibrangeCalc:InRange(unitId,totemicMastery and 30 or 20)
if not inRange and UnitExists(unitId) then
self.bar[count].icon:SetVertexColor(1,0,0,0.7)
local warnRange = pfUI_config.bettertotems.recallRange or 45
warnRange = tonumber(warnRange)
local toWarn = pfUI_config.bettertotems.recall or "1"
local notWarnRange = unitId and UnitExists(unitId) and LibrangeCalc:InRange(unitId,warnRange)
if not notWarnRange and toWarn == "1" then
UIErrorsFrame:AddMessage("Totems Out of Range. Recall?",1.0,0.0,0.0)
PlaySound("igPVPUpdate", "master")
end
else
self.bar[count].icon:SetVertexColor(1,1,1,1)
end
CooldownFrame_SetTimer(self.bar[count].cd, start, duration, 1)
end
end
self:UpdateSize(count)
end
totems.UpdateSize = function(self, count)
if not count or count == 0 then
-- hide entire panel
self:Hide()
else
-- hide remaining totems and show panel
for i = count + 1, MAX_TOTEMS do self.bar[i]:Hide() end
self:Show()
end
local count = count and count > 0 and count or MAX_TOTEMS
if pfUI_config.totems.direction == "HORIZONTAL" then
self:SetHeight(self.iconsize + self.spacing*2)
self:SetWidth(self.spacing*2 + self.iconsize + (count-1)*(self.iconsize + self.spacing*2))
else
self:SetWidth(self.iconsize + self.spacing*2)
self:SetHeight(self.spacing*2 + self.iconsize + (count-1)*(self.iconsize + self.spacing*2))
end
end
totems.UpdateConfig = function(self)
local rawborder, border = GetBorderSize()
self.iconsize = pfUI_config.totems.iconsize
self.direction = pfUI_config.totems.direction
self.spacing = tonumber(pfUI_config.totems.spacing) * GetPerfectPixel()
self.showbg = pfUI_config.totems.showbg == "1" and true or nil
for i = 1, MAX_TOTEMS do
self.bar = self.bar or {}
self.bar[i] = self.bar[i] or CreateFrame("Button", "pfBetterTotemsBar"..i, totems)
self.bar[i]:ClearAllPoints()
if pfUI_config.totems.direction == "HORIZONTAL" then
if self.bar[i-1] then
self.bar[i]:SetPoint("LEFT", self.bar[i-1], "RIGHT", self.spacing*2, 0)
else
self.bar[i]:SetPoint("TOPLEFT", self, "TOPLEFT", self.spacing, -self.spacing)
end
else
if self.bar[i-1] then
self.bar[i]:SetPoint("TOP", self.bar[i-1], "BOTTOM", 0, -self.spacing*2)
else
self.bar[i]:SetPoint("TOPLEFT", self, "TOPLEFT", self.spacing, -self.spacing)
end
end
self.bar[i]:SetHeight(self.iconsize)
self.bar[i]:SetWidth(self.iconsize)
CreateBackdrop(self.bar[i], nil, true)
self.bar[i].icon = self.bar[i].icon or self.bar[i]:CreateTexture(nil, "ARTWORK")
self.bar[i].icon:SetTexCoord(.08, .92, .08, .92)
SetAllPointsOffset(self.bar[i].icon, self.bar[i], 2,-2)
self.bar[i].cdbg = self.bar[i].cdbg or CreateFrame("Frame", nil, self.bar[i])
self.bar[i].cdbg:SetHeight(self.iconsize - 3)
self.bar[i].cdbg:SetWidth(self.iconsize - 3)
self.bar[i].cdbg:SetPoint("CENTER", self.bar[i], "CENTER", 0, 0)
self.bar[i].cd = self.bar[i].cd or CreateFrame(COOLDOWN_FRAME_TYPE, "pfBetterTotemsBar"..i.."Cooldown", self.bar[i].cdbg, "CooldownFrameTemplate")
self.bar[i].cd.pfCooldownStyleAnimation = 1
self.bar[i].cd.pfCooldownType = "ALL"
self.bar[i]:RegisterForClicks("LeftButtonUp", "RightButtonUp")
self.bar[i]:SetScript("OnClick", self.OnClick)
self.bar[i]:SetScript("OnEnter", self.OnEnter)
self.bar[i]:SetScript("OnLeave", self.OnLeave)
end
self:RefreshList()
self:ClearAllPoints()
self:SetPoint("BOTTOM", 0, 75)
UpdateMovable(self, true)
if self.showbg then
CreateBackdrop(self)
self.backdrop:Show()
elseif self.backdrop then
self.backdrop:Hide()
end
end
-- add totems to the pfUI global space
BetterTotems = totems
BetterTotems:UpdateConfig()
end)