Skip to content
Newer
Older
100644 184 lines (133 sloc) 4.26 KB
8b97a8a @haste totems: Initial documentation.
authored Apr 1, 2012
1 --[[ Element: Totem Indicator
2
3 Handles updating and visibility of Shaman totems, Druid mushrooms and Death
4 Knight ghouls.
5
6 Widget
7
8 Totems - A table to hold sub-widgets.
9
10 Sub-Widgets
11
12 Totem - Any UI widget.
13 .Icon - A Texture representing the totem icon.
14 .Cooldown - A Cooldown representing the duration of the totem.
15
16 Notes
17
18 A OnClick handler, which calls DestroyTotem() when clicked, will be applied to
19 the `Totem` widget, if it supports OnClick.
20
21 It will also set OnEnter and OnLeave, to display the default Tooltip, if the
22 `Totem` widget is mouse enabled.
23
24 Options
25
26 :UpdateTooltip - The function that should populate the tooltip, when the
27 `Totem` widget is hovered. A default function, which calls
28 `:SetTotem(id)`, will be used if none is defined.
29
30 Examples
31
32 local Totems = {}
33 for index = 1, MAX_TOTEMS do
34 -- Position and size of the totem indicator
35 local Totem = CreateFrame('Button', nil, self)
36 Totem:SetSize(40, 40)
37 Totem:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', index * Totem:GetWidth(), 0)
38
39 local Icon = Totem:CreateTexture(nil, "OVERLAY")
40 Icon:SetAllPoints()
41
42 local Cooldown = CreateFrame("Cooldown", nil, Totem)
43 Cooldown:SetAllPoints()
44
45 Totem.Icon = Icon
46 Totem.Cooldown = Cooldown
47
48 Totems[index] = Totem
49 end
50
51 -- Register with oUF
52 self.Totems = Totems
53
54 Hooks
55
56 Override(self) - Used to completely override the internal update function.
57 Removing the table key entry will make the element fall-back
58 to its internal function again.
59 ]]
60
8f52b53 @haste Add a totems element.
authored Apr 12, 2011
61 local parent, ns = ...
62 local oUF = ns.oUF
63
38d6e86 @haste totems: Use the default UIs priority lists.
authored Apr 1, 2012
64 -- Order the list based upon the default UIs priorities.
65 local priorities = STANDARD_TOTEM_PRIORITIES
66 if(select(2, UnitClass'player') == 'SHAMAN') then
67 priorities = SHAMAN_TOTEM_PRIORITIES
68 end
7745234 update totems display order: earth - fire - water - air
budha authored May 27, 2011
69
8f52b53 @haste Add a totems element.
authored Apr 12, 2011
70 local OnClick = function(self)
71 DestroyTotem(self:GetID())
72 end
73
74 local UpdateTooltip = function(self)
75 GameTooltip:SetTotem(self:GetID())
76 end
77
78 local OnEnter = function(self)
79 if(not self:IsVisible()) then return end
80
81 GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT')
82 self:UpdateTooltip()
83 end
84
85 local OnLeave = function()
86 GameTooltip:Hide()
87 end
88
89 local UpdateTotem = function(self, event, slot)
90 local totems = self.Totems
91
38d6e86 @haste totems: Use the default UIs priority lists.
authored Apr 1, 2012
92 if(totems.PreUpdate) then totems:PreUpdate(priorities[slot]) end
8f52b53 @haste Add a totems element.
authored Apr 12, 2011
93
38d6e86 @haste totems: Use the default UIs priority lists.
authored Apr 1, 2012
94 local totem = totems[priorities[slot]]
8f52b53 @haste Add a totems element.
authored Apr 12, 2011
95 local haveTotem, name, start, duration, icon = GetTotemInfo(slot)
96 if(duration > 0) then
97 if(totem.Icon) then
98 totem.Icon:SetTexture(icon)
99 end
100
101 if(totem.Cooldown) then
102 totem.Cooldown:SetCooldown(start, duration)
103 end
104
105 totem:Show()
106 else
107 totem:Hide()
108 end
109
110 if(totems.PostUpdate) then
38d6e86 @haste totems: Use the default UIs priority lists.
authored Apr 1, 2012
111 return totems:PostUpdate(priorities[slot], haveTotem, name, start, duration, icon)
8f52b53 @haste Add a totems element.
authored Apr 12, 2011
112 end
113 end
114
115 local Path = function(self, ...)
116 return (self.Totems.Override or UpdateTotem) (self, ...)
117 end
118
119 local Update = function(self, event)
120 for i = 1, MAX_TOTEMS do
121 Path(self, event, i)
122 end
123 end
124
125 local ForceUpdate = function(element)
126 return Update(element.__owner, 'ForceUpdate')
127 end
128
129 local Enable = function(self)
130 local totems = self.Totems
131
132 if(totems) then
133 totems.__owner = self
134 totems.ForceUpdate = ForceUpdate
135
136 for i = 1, MAX_TOTEMS do
137 local totem = totems[i]
138
38d6e86 @haste totems: Use the default UIs priority lists.
authored Apr 1, 2012
139 totem:SetID(priorities[i])
8f52b53 @haste Add a totems element.
authored Apr 12, 2011
140
141 if(totem:HasScript'OnClick') then
142 totem:SetScript('OnClick', OnClick)
143 end
144
145 if(totem:IsMouseEnabled()) then
146 totem:SetScript('OnEnter', OnEnter)
147 totem:SetScript('OnLeave', OnLeave)
148
149 if(not totem.UpdateTooltip) then
150 totem.UpdateTooltip = UpdateTooltip
151 end
152 end
153 end
154
37b1063 @haste totems: Tag PLAYER_TOTEM_UPDATE as shared.
authored Oct 2, 2011
155 self:RegisterEvent('PLAYER_TOTEM_UPDATE', Path, true)
8f52b53 @haste Add a totems element.
authored Apr 12, 2011
156
157 TotemFrame.Show = TotemFrame.Hide
158 TotemFrame:Hide()
159
160 TotemFrame:UnregisterEvent"PLAYER_TOTEM_UPDATE"
161 TotemFrame:UnregisterEvent"PLAYER_ENTERING_WORLD"
162 TotemFrame:UnregisterEvent"UPDATE_SHAPESHIFT_FORM"
163 TotemFrame:UnregisterEvent"PLAYER_TALENT_UPDATE"
164
165 return true
166 end
167 end
168
169 local Disable = function(self)
170 if(self.Totems) then
171 TotemFrame.Show = nil
172 TotemFrame:Show()
173
174 TotemFrame:RegisterEvent"PLAYER_TOTEM_UPDATE"
175 TotemFrame:RegisterEvent"PLAYER_ENTERING_WORLD"
176 TotemFrame:RegisterEvent"UPDATE_SHAPESHIFT_FORM"
177 TotemFrame:RegisterEvent"PLAYER_TALENT_UPDATE"
178
179 self:UnregisterEvent('PLAYER_TOTEM_UPDATE', Path)
180 end
181 end
182
183 oUF:AddElement("Totems", Update, Enable, Disable)
Something went wrong with that request. Please try again.