Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 126 lines (96 sloc) 2.757 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
local parent, ns = ...
local oUF = ns.oUF

-- colors
-- from Interface/BUTTONS/UI-TotemBar.blp
oUF.colors.totems = {
[FIRE_TOTEM_SLOT] = { 181/255, 073/255, 033/255 },
[EARTH_TOTEM_SLOT] = { 074/255, 142/255, 041/255 },
[WATER_TOTEM_SLOT] = { 057/255, 146/255, 181/255 },
[AIR_TOTEM_SLOT] = { 132/255, 056/255, 231/255 }
}

local OnClick = function(self)
DestroyTotem(self:GetID())
end

local UpdateTooltip = function(self)
GameTooltip:SetTotem(self:GetID())
end

local OnEnter = function(self)
if(not self:IsVisible()) then return end

GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT')
self:UpdateTooltip()
end

local OnLeave = function()
GameTooltip:Hide()
end

local UpdateTotem = function(self, event, slot)
local totems = self.Totems

if(totems.PreUpdate) then totems:PreUpdate(slot) end

local totem = totems[slot]
local haveTotem, name, start, duration, icon = GetTotemInfo(slot)
if(duration > 0) then
if(totem.Icon) then
totem.Icon:SetTexture(icon)
end

if(totem.Cooldown) then
totem.Cooldown:SetCooldown(start, duration)
end

totem:Show()
else
totem:Hide()
end

if(totems.PostUpdate) then
return totems:PostUpdate(slot, haveTotem, name, start, duration, icon)
end
end

local Path = function(self, ...)
return (self.Totems.Override or UpdateTotem) (self, ...)
end

local Update = function(self, event)
for i = 1, MAX_TOTEMS do
Path(self, event, i)
end
end

local ForceUpdate = function(element)
return Update(element.__owner, 'ForceUpdate')
end

local Enable = function(self)
local totems = self.Totems

if(totems) then
totems.__owner = self
totems.ForceUpdate = ForceUpdate

for i = 1, MAX_TOTEMS do
local totem = totems[i]

totem:SetID(i)

if(totem:HasScript'OnClick') then
totem:SetScript('OnClick', OnClick)
end

if(totem:IsMouseEnabled()) then
totem:SetScript('OnEnter', OnEnter)
totem:SetScript('OnLeave', OnLeave)

if(not totem.UpdateTooltip) then
totem.UpdateTooltip = UpdateTooltip
end
end
end

self:RegisterEvent('PLAYER_TOTEM_UPDATE', Path)

TotemFrame.Show = TotemFrame.Hide
TotemFrame:Hide()

TotemFrame:UnregisterEvent"PLAYER_TOTEM_UPDATE"
TotemFrame:UnregisterEvent"PLAYER_ENTERING_WORLD"
TotemFrame:UnregisterEvent"UPDATE_SHAPESHIFT_FORM"
TotemFrame:UnregisterEvent"PLAYER_TALENT_UPDATE"

return true
end
end

local Disable = function(self)
if(self.Totems) then
TotemFrame.Show = nil
TotemFrame:Show()

TotemFrame:RegisterEvent"PLAYER_TOTEM_UPDATE"
TotemFrame:RegisterEvent"PLAYER_ENTERING_WORLD"
TotemFrame:RegisterEvent"UPDATE_SHAPESHIFT_FORM"
TotemFrame:RegisterEvent"PLAYER_TALENT_UPDATE"

self:UnregisterEvent('PLAYER_TOTEM_UPDATE', Path)
end
end

oUF:AddElement("Totems", Update, Enable, Disable)
Something went wrong with that request. Please try again.