Go to most recent revision | Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 2 | Blooblahguy-207965 | --[[ Element: Eclipse Bar |
2 | Blooblahguy-207965 | Handle updating and visibility of the Druid eclipse state status bars. |
|
3 | Blooblahguy-207965 | ||
4 | Blooblahguy-207965 | Widget |
|
5 | Blooblahguy-207965 | ||
6 | Blooblahguy-207965 | EclipseBar - A table to hold the sub-widgets. |
|
7 | Blooblahguy-207965 | ||
8 | Blooblahguy-207965 | Sub-Widgets |
|
9 | Blooblahguy-207965 | ||
10 | Blooblahguy-207965 | LunarBar - A StatusBar used to represent the lunar power state. |
|
11 | Blooblahguy-207965 | SolarBar - A StatusBar used to represent the solar power state. |
|
12 | Blooblahguy-207965 | ||
13 | Blooblahguy-207965 | Notes |
|
14 | Blooblahguy-207965 | ||
15 | Blooblahguy-207965 | The default StatusBar texture will be applied if the UI widget doesn't have a |
|
16 | Blooblahguy-207965 | status bar texture or color defined. |
|
17 | Blooblahguy-207965 | ||
18 | Blooblahguy-207965 | Examples |
|
19 | Blooblahguy-207965 | ||
20 | Blooblahguy-207965 | local EclipseBar = CreateFrame('Frame', nil, self) |
|
21 | Blooblahguy-207965 | EclipseBar:SetPoint('BOTTOM', self, 'TOP') |
|
22 | Blooblahguy-207965 | EclipseBar:SetSize(160, 20) |
|
23 | Blooblahguy-207965 | ||
24 | Blooblahguy-207965 | -- Position and size |
|
25 | Blooblahguy-207965 | local LunarBar = CreateFrame('StatusBar', nil, EclipseBar) |
|
26 | Blooblahguy-207965 | LunarBar:SetPoint('LEFT') |
|
27 | Blooblahguy-207965 | LunarBar:SetSize(160, 20) |
|
28 | Blooblahguy-207965 | ||
29 | Blooblahguy-207965 | local SolarBar = CreateFrame('StatusBar', nil, EclipseBar) |
|
30 | Blooblahguy-207965 | SolarBar:SetPoint('LEFT', LunarBar:GetStatusBarTexture(), 'RIGHT') |
|
31 | Blooblahguy-207965 | SolarBar:SetSize(160, 20) |
|
32 | Blooblahguy-207965 | ||
33 | Blooblahguy-207965 | -- Register with oUF |
|
34 | Blooblahguy-207965 | EclipseBar.LunarBar = LunarBar |
|
35 | Blooblahguy-207965 | EclipseBar.SolarBar = SolarBar |
|
36 | Blooblahguy-207965 | self.EclipseBar = EclipseBar |
|
37 | Blooblahguy-207965 | ||
38 | Blooblahguy-207965 | Hooks and Callbacks |
|
39 | Blooblahguy-207965 | ||
40 | Blooblahguy-207965 | Override(self) - Used to completely override the internal update function. |
|
41 | Blooblahguy-207965 | Removing the table key entry will make the element fall-back |
|
42 | Blooblahguy-207965 | to its internal function again. |
|
43 | Blooblahguy-207965 | ]] |
|
44 | Blooblahguy-207965 | ||
45 | Blooblahguy-207965 | if(select(2, UnitClass('player')) ~= 'DRUID') then return end |
|
46 | Blooblahguy-207965 | ||
47 | Blooblahguy-207965 | local parent, ns = ... |
|
48 | Blooblahguy-207965 | local oUF = ns.oUF |
|
49 | Blooblahguy-207965 | ||
50 | Blooblahguy-207965 | local ECLIPSE_BAR_SOLAR_BUFF = GetSpellInfo(171744) |
|
51 | Blooblahguy-207965 | local ECLIPSE_BAR_LUNAR_BUFF = GetSpellInfo(171743) |
|
52 | Blooblahguy-207965 | local SPELL_POWER_ECLIPSE = SPELL_POWER_ECLIPSE |
|
53 | Blooblahguy-207965 | local MOONKIN_FORM = MOONKIN_FORM |
|
54 | Blooblahguy-207965 | ||
55 | Blooblahguy-207965 | local UNIT_POWER = function(self, event, unit, powerType) |
|
56 | Blooblahguy-207965 | if(self.unit ~= unit or (event == 'UNIT_POWER_FREQUENT' and powerType ~= 'ECLIPSE')) then return end |
|
57 | Blooblahguy-207965 | ||
58 | Blooblahguy-207965 | local eb = self.EclipseBar |
|
59 | Blooblahguy-207965 | ||
60 | Blooblahguy-207965 | local power = UnitPower('player', SPELL_POWER_ECLIPSE) |
|
61 | Blooblahguy-207965 | local maxPower = UnitPowerMax('player', SPELL_POWER_ECLIPSE) |
|
62 | Blooblahguy-207965 | ||
63 | Blooblahguy-207965 | if(eb.LunarBar) then |
|
64 | Blooblahguy-207965 | eb.LunarBar:SetMinMaxValues(-maxPower, maxPower) |
|
65 | Blooblahguy-207965 | eb.LunarBar:SetValue(power) |
|
66 | Blooblahguy-207965 | end |
|
67 | Blooblahguy-207965 | ||
68 | Blooblahguy-207965 | if(eb.SolarBar) then |
|
69 | Blooblahguy-207965 | eb.SolarBar:SetMinMaxValues(-maxPower, maxPower) |
|
70 | Blooblahguy-207965 | eb.SolarBar:SetValue(power * -1) |
|
71 | Blooblahguy-207965 | end |
|
72 | Blooblahguy-207965 | ||
73 | Blooblahguy-207965 | if(eb.PostUpdatePower) then |
|
74 | Blooblahguy-207965 | --[[ :PostUpdatePower(unit) |
|
75 | Blooblahguy-207965 | ||
76 | Blooblahguy-207965 | Callback which is called after lunar and solar bar was updated. |
|
77 | Blooblahguy-207965 | ||
78 | Blooblahguy-207965 | Arguments |
|
79 | Blooblahguy-207965 | ||
80 | Blooblahguy-207965 | self - The widget that holds the eclipse frame. |
|
81 | Blooblahguy-207965 | unit - The unit that has the widget. |
|
82 | Blooblahguy-207965 | power - The unit's current power. |
|
83 | Blooblahguy-207965 | maxPower - The unit's maximum power. |
|
84 | Blooblahguy-207965 | ]] |
|
85 | Blooblahguy-207965 | return eb:PostUpdatePower(unit, power, maxPower) |
|
86 | Blooblahguy-207965 | end |
|
87 | Blooblahguy-207965 | end |
|
88 | Blooblahguy-207965 | ||
89 | Blooblahguy-207965 | local UPDATE_VISIBILITY = function(self, event) |
|
90 | Blooblahguy-207965 | local eb = self.EclipseBar |
|
91 | Blooblahguy-207965 | ||
92 | Blooblahguy-207965 | -- check form/mastery |
|
93 | Blooblahguy-207965 | local showBar |
|
94 | Blooblahguy-207965 | local form = GetShapeshiftFormID() |
|
95 | Blooblahguy-207965 | if(not form) then |
|
96 | Blooblahguy-207965 | local ptt = GetSpecialization() |
|
97 | Blooblahguy-207965 | if(ptt and ptt == 1) then -- player has balance spec |
|
98 | Blooblahguy-207965 | showBar = true |
|
99 | Blooblahguy-207965 | end |
|
100 | Blooblahguy-207965 | elseif(form == MOONKIN_FORM) then |
|
101 | Blooblahguy-207965 | showBar = true |
|
102 | Blooblahguy-207965 | end |
|
103 | Blooblahguy-207965 | ||
104 | Blooblahguy-207965 | if(UnitHasVehicleUI'player') then |
|
105 | Blooblahguy-207965 | showBar = false |
|
106 | Blooblahguy-207965 | end |
|
107 | Blooblahguy-207965 | ||
108 | Blooblahguy-207965 | if(showBar) then |
|
109 | Blooblahguy-207965 | eb:Show() |
|
110 | Blooblahguy-207965 | else |
|
111 | Blooblahguy-207965 | eb:Hide() |
|
112 | Blooblahguy-207965 | end |
|
113 | Blooblahguy-207965 | ||
114 | Blooblahguy-207965 | if(eb.PostUpdateVisibility) then |
|
115 | Blooblahguy-207965 | --[[ :PostUpdateVisibility(unit) |
|
116 | Blooblahguy-207965 | ||
117 | Blooblahguy-207965 | Callback which is called after the eclipse frame was shown or hidden. |
|
118 | Blooblahguy-207965 | ||
119 | Blooblahguy-207965 | Arguments |
|
120 | Blooblahguy-207965 | ||
121 | Blooblahguy-207965 | self - The widget that holds the eclipse frame. |
|
122 | Blooblahguy-207965 | unit - The unit that has the widget. |
|
123 | Blooblahguy-207965 | ]] |
|
124 | Blooblahguy-207965 | return eb:PostUpdateVisibility(self.unit) |
|
125 | Blooblahguy-207965 | end |
|
126 | Blooblahguy-207965 | end |
|
127 | Blooblahguy-207965 | ||
128 | Blooblahguy-207965 | local UNIT_AURA = function(self, event, unit) |
|
129 | Blooblahguy-207965 | if(self.unit ~= unit) then return end |
|
130 | Blooblahguy-207965 | local eb = self.EclipseBar |
|
131 | Blooblahguy-207965 | ||
132 | Blooblahguy-207965 | local hasSolarEclipse = not not UnitBuff(unit, ECLIPSE_BAR_SOLAR_BUFF) |
|
133 | Blooblahguy-207965 | local hasLunarEclipse = not not UnitBuff(unit, ECLIPSE_BAR_LUNAR_BUFF) |
|
134 | Blooblahguy-207965 | ||
135 | Blooblahguy-207965 | if(eb.hasSolarEclipse == hasSolarEclipse and eb.hasLunarEclipse == hasLunarEclipse) then return end |
|
136 | Blooblahguy-207965 | ||
137 | Blooblahguy-207965 | eb.hasSolarEclipse = hasSolarEclipse |
|
138 | Blooblahguy-207965 | eb.hasLunarEclipse = hasLunarEclipse |
|
139 | Blooblahguy-207965 | ||
140 | Blooblahguy-207965 | if(eb.PostUnitAura) then |
|
141 | Blooblahguy-207965 | --[[ :PostUnitAura(unit) |
|
142 | Blooblahguy-207965 | ||
143 | Blooblahguy-207965 | Callback which is called after the eclipse state was checked. |
|
144 | Blooblahguy-207965 | ||
145 | Blooblahguy-207965 | Arguments |
|
146 | Blooblahguy-207965 | ||
147 | Blooblahguy-207965 | self - The widget that holds the eclipse frame. |
|
148 | Blooblahguy-207965 | unit - The unit that has the widget. |
|
149 | Blooblahguy-207965 | ]] |
|
150 | Blooblahguy-207965 | return eb:PostUnitAura(unit) |
|
151 | Blooblahguy-207965 | end |
|
152 | Blooblahguy-207965 | end |
|
153 | Blooblahguy-207965 | ||
154 | Blooblahguy-207965 | local ECLIPSE_DIRECTION_CHANGE = function(self, event, direction) |
|
155 | Blooblahguy-207965 | local eb = self.EclipseBar |
|
156 | Blooblahguy-207965 | ||
157 | Blooblahguy-207965 | eb.directionIsLunar = direction == "moon" |
|
158 | Blooblahguy-207965 | eb.direction = direction |
|
159 | Blooblahguy-207965 | ||
160 | Blooblahguy-207965 | if(eb.PostDirectionChange) then |
|
161 | Blooblahguy-207965 | --[[ :PostDirectionChange(unit) |
|
162 | Blooblahguy-207965 | ||
163 | Blooblahguy-207965 | Callback which is called after eclipse direction was changed. |
|
164 | Blooblahguy-207965 | ||
165 | Blooblahguy-207965 | Arguments |
|
166 | Blooblahguy-207965 | ||
167 | Blooblahguy-207965 | self - The widget that holds the eclipse frame. |
|
168 | Blooblahguy-207965 | unit - The unit that has the widget. |
|
169 | Blooblahguy-207965 | ]] |
|
170 | Blooblahguy-207965 | return eb:PostDirectionChange(self.unit) |
|
171 | Blooblahguy-207965 | end |
|
172 | Blooblahguy-207965 | end |
|
173 | Blooblahguy-207965 | ||
174 | Blooblahguy-207965 | local Update = function(self, event, ...) |
|
175 | Blooblahguy-207965 | UNIT_POWER(self, event, ...) |
|
176 | Blooblahguy-207965 | UNIT_AURA(self, event, ...) |
|
177 | Blooblahguy-207965 | ECLIPSE_DIRECTION_CHANGE(self, event) |
|
178 | Blooblahguy-207965 | return UPDATE_VISIBILITY(self, event) |
|
179 | Blooblahguy-207965 | end |
|
180 | Blooblahguy-207965 | ||
181 | Blooblahguy-207965 | local ForceUpdate = function(element) |
|
182 | Blooblahguy-207965 | return Update(element.__owner, 'ForceUpdate', element.__owner.unit, 'ECLIPSE') |
|
183 | Blooblahguy-207965 | end |
|
184 | Blooblahguy-207965 | ||
185 | Blooblahguy-207965 | local function Enable(self) |
|
186 | Blooblahguy-207965 | local eb = self.EclipseBar |
|
187 | Blooblahguy-207965 | if(eb) then |
|
188 | Blooblahguy-207965 | eb.__owner = self |
|
189 | Blooblahguy-207965 | eb.ForceUpdate = ForceUpdate |
|
190 | Blooblahguy-207965 | ||
191 | Blooblahguy-207965 | if(eb.LunarBar and eb.LunarBar:IsObjectType'StatusBar' and not eb.LunarBar:GetStatusBarTexture()) then |
|
192 | Blooblahguy-207965 | eb.LunarBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]]) |
|
193 | Blooblahguy-207965 | end |
|
194 | Blooblahguy-207965 | if(eb.SolarBar and eb.SolarBar:IsObjectType'StatusBar' and not eb.SolarBar:GetStatusBarTexture()) then |
|
195 | Blooblahguy-207965 | eb.SolarBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]]) |
|
196 | Blooblahguy-207965 | end |
|
197 | Blooblahguy-207965 | ||
198 | Blooblahguy-207965 | self:RegisterEvent('ECLIPSE_DIRECTION_CHANGE', ECLIPSE_DIRECTION_CHANGE, true) |
|
199 | Blooblahguy-207965 | self:RegisterEvent('PLAYER_TALENT_UPDATE', UPDATE_VISIBILITY, true) |
|
200 | Blooblahguy-207965 | self:RegisterEvent('UNIT_AURA', UNIT_AURA) |
|
201 | Blooblahguy-207965 | self:RegisterEvent('UNIT_POWER_FREQUENT', UNIT_POWER) |
|
202 | Blooblahguy-207965 | self:RegisterEvent('UPDATE_SHAPESHIFT_FORM', UPDATE_VISIBILITY, true) |
|
203 | Blooblahguy-207965 | ||
204 | Blooblahguy-207965 | return true |
|
205 | Blooblahguy-207965 | end |
|
206 | Blooblahguy-207965 | end |
|
207 | Blooblahguy-207965 | ||
208 | Blooblahguy-207965 | local function Disable(self) |
|
209 | Blooblahguy-207965 | local eb = self.EclipseBar |
|
210 | Blooblahguy-207965 | if(eb) then |
|
211 | Blooblahguy-207965 | eb:Hide() |
|
212 | Blooblahguy-207965 | self:UnregisterEvent('ECLIPSE_DIRECTION_CHANGE', ECLIPSE_DIRECTION_CHANGE) |
|
213 | Blooblahguy-207965 | self:UnregisterEvent('PLAYER_TALENT_UPDATE', UPDATE_VISIBILITY) |
|
214 | Blooblahguy-207965 | self:UnregisterEvent('UNIT_AURA', UNIT_AURA) |
|
215 | Blooblahguy-207965 | self:UnregisterEvent('UNIT_POWER_FREQUENT', UNIT_POWER) |
|
216 | Blooblahguy-207965 | self:UnregisterEvent('UPDATE_SHAPESHIFT_FORM', UPDATE_VISIBILITY) |
|
217 | Blooblahguy-207965 | end |
|
218 | Blooblahguy-207965 | end |
|
219 | Blooblahguy-207965 | ||
220 | Blooblahguy-207965 | oUF:AddElement('EclipseBar', Update, Enable, Disable) |