Nenue@6
|
1 -- User: Krakyn
|
Nenue@6
|
2 -- Created: 12/15/2015 7:31 PM
|
Nenue@6
|
3 --[[
|
Nenue@6
|
4 -- Turok by @project-author@
|
Nenue@6
|
5 -- @file-author@
|
Nenue@6
|
6 -- @file-revision@:@project-revision@
|
Nenue@6
|
7 -- @file-date-iso@
|
Nenue@6
|
8 --
|
Nenue@6
|
9 -- Visible element operations begin here
|
Nenue@6
|
10 --]]
|
Nenue@6
|
11 local _G = _G
|
Nenue@6
|
12 local T, pairs, select, setmetatable, type, tinsert = _G.Turok, pairs, select, setmetatable, type, tinsert
|
Nenue@6
|
13 local mod = T:NewModule("PowerBar")
|
Nenue@6
|
14 local UnitPower, UnitPowerMax, GetTalentInfoByID, GetTalentInfo, CreateFrame = UnitPower, UnitPowerMax, GetTalentInfoByID, GetTalentInfo, CreateFrame
|
Nenue@6
|
15 local bar, db, prototype -- convenience upvalues
|
Nenue@6
|
16 local cType, cText, cNum, cWord, cKey, cPink, cBool = cText, cNum, cWord, cKey, cPink, cBool
|
Nenue@6
|
17 --@debug
|
Nenue@6
|
18 local cType, cText, cNum, cWord, cKey, cPink, cBool = cText, cNum, cWord, cKey, cPink, cBool
|
Nenue@6
|
19 local print = function(...)
|
Nenue@6
|
20 if _G.Devian and _G.DevianDB.workspace ~= 1 then
|
Nenue@6
|
21 _G.print('PowerBar', ...)
|
Nenue@6
|
22 end
|
Nenue@6
|
23 end
|
Nenue@9
|
24 local uprint = function(...)
|
Nenue@9
|
25 if _G.Devian and _G.DevianDB.workspace ~= 1 then
|
Nenue@9
|
26 _G.print('Update', ...)
|
Nenue@9
|
27 end
|
Nenue@9
|
28 end
|
Nenue@6
|
29 local addon, tg = ...
|
Nenue@6
|
30 tg.what = tostring(tg.what)..'more'
|
Nenue@6
|
31 print(tg.what)
|
Nenue@6
|
32 --@end-debug@
|
Nenue@6
|
33 mod.OnInitialize = function(self)
|
Nenue@6
|
34 self.UNIT_SPELLCAST_START = self.SpellCastEvent
|
Nenue@6
|
35 self.UNIT_SPELLCAST_STOP = self.SpellCastEvent
|
Nenue@6
|
36 self.UNIT_SPELLCAST_SUCCEEDED = self.SpellCastEvent
|
Nenue@6
|
37 self.UNIT_SPELLCAST_CHANNEL_START = self.SpellCastEvent
|
Nenue@6
|
38 self.UNIT_SPELLCAST_CHANNEL_STOP = self.SpellCastEvent
|
Nenue@6
|
39 self.SPELL_UPDATE_COOLDOWN = self.SpellCooldownEvent
|
Nenue@6
|
40 self.PLAYER_REGEN_DISABLED = self.CombatStart
|
Nenue@6
|
41 self.PLAYER_REGEN_ENABLED = self.CombatEnd
|
Nenue@6
|
42 self.focusbar = {}
|
Nenue@6
|
43 self.parserLog = {}
|
Nenue@6
|
44 self.currentParse = {}
|
Nenue@6
|
45 end
|
Nenue@6
|
46 local SPELL_POWER_MANA, SPELL_POWER_ENERGY, SPELL_POWER_RAGE, SPELL_POWER_FOCUS = SPELL_POWER_MANA, SPELL_POWER_ENERGY, SPELL_POWER_RAGE, SPELL_POWER_FOCUS
|
Nenue@6
|
47 local SPELL_POWER_SHADOW_ORBS = SPELL_POWER_SHADOW_ORBS
|
Nenue@6
|
48 local SPELL_POWER_SOUL_SHARDS, SPELL_POWER_BURNING_EMBERS, SPELL_POWER_DEMONIC_FURY = SPELL_POWER_SOUL_SHARDS, SPELL_POWER_BURNING_EMBERS, SPELL_POWER_DEMONIC_FURY
|
Nenue@6
|
49 local SPELL_POWER_HOLY_POWER = SPELL_POWER_HOLY_POWER
|
Nenue@6
|
50 local SPELL_POWER_CHI = SPELL_POWER_CHI
|
Nenue@6
|
51 local SPELL_POWER_COMBO_POINTS = SPELL_POWER_COMBO_POINTS
|
Nenue@6
|
52
|
Nenue@6
|
53 -- indexes for talent_update cleanup
|
Nenue@6
|
54 mod.secondary_rows = {}
|
Nenue@6
|
55 mod.disabled_frames = {}
|
Nenue@6
|
56
|
Nenue@6
|
57 --[[
|
Nenue@6
|
58 -- Prototype list naming all the data sources and events that need to be handled for the logged in character
|
Nenue@6
|
59 -- .power_type {[bliz const] = event token} list of resources represented by global SPELL_POWER_* constants in the blizzard ui and the UNIT_POWER* token argument representing it
|
Nenue@6
|
60 -- .frame string frameXML template
|
Nenue@6
|
61 -- .spells {[spell name/id] = {events}} list of spells tracked by the updater
|
Nenue@6
|
62 -- .secondary {[aura name] = {}} list of auras tracked as secondary resources such as Thrill of Hunt, Anticipatin, Evangelism, etc.
|
Nenue@6
|
63 --]]
|
Nenue@6
|
64 mod.prototype = {
|
Nenue@6
|
65 ['HUNTER'] = {
|
Nenue@6
|
66 primary = {
|
Nenue@6
|
67 [1] = {"FOCUS", SPELL_POWER_FOCUS}, -- array of power type constants associated to event strings
|
Nenue@6
|
68 },
|
Nenue@6
|
69 frame = 'TkThinComboTemplate', ---------------------- desired frame template
|
Nenue@6
|
70 spells = {
|
Nenue@6
|
71 ["Steady Shot"] = {'UNIT_SPELL_CAST_SUCCEEDED', 'UNIT_SPELLCAST_STOP', 'UNIT_SPELLCAST_START'} -- spell events that this frame should listen to
|
Nenue@6
|
72 },
|
Nenue@6
|
73 secondary = {},
|
Nenue@6
|
74 spec = {
|
Nenue@6
|
75 [1] = {
|
Nenue@6
|
76 secondary = {
|
Nenue@6
|
77 ['Frenzy'] = {
|
Nenue@6
|
78 type = 'aura',
|
Nenue@6
|
79 order = 1,
|
Nenue@6
|
80 scale = 5,
|
Nenue@6
|
81 filters = 'HELPFUL',
|
Nenue@6
|
82 max = 5,
|
Nenue@6
|
83 specPage = 1,
|
Nenue@6
|
84 unit = 'player',
|
Nenue@6
|
85 spellID = 19623,
|
Nenue@6
|
86 },
|
Nenue@6
|
87 ['Focus Fire'] = {
|
Nenue@6
|
88 type = 'aura',
|
Nenue@6
|
89 max = 40,
|
Nenue@6
|
90 order = 2,
|
Nenue@6
|
91 scale = 5,
|
Nenue@6
|
92 line = 3, --------------- use this subtext value instead of count field
|
Nenue@6
|
93 filters = 'HELPFUL',
|
Nenue@6
|
94 specPage = 1,
|
Nenue@6
|
95 unit = 'player',
|
Nenue@6
|
96 spellID = 19623,
|
Nenue@6
|
97 }
|
Nenue@6
|
98 }
|
Nenue@6
|
99 },
|
Nenue@6
|
100 [2] = {
|
Nenue@6
|
101 secondary = { ------------------------ list of buffs that act as a secondary resource
|
Nenue@6
|
102 ['Thrill of the Hunt'] = {
|
Nenue@6
|
103 order = 1,
|
Nenue@6
|
104 unit = 'player',
|
Nenue@6
|
105 type = 'aura',
|
Nenue@6
|
106 max = 3,
|
Nenue@6
|
107 scale = 5,
|
Nenue@6
|
108 filters = 'HELPFUL',
|
Nenue@6
|
109 talent = {4,3},
|
Nenue@6
|
110 display = 'progressbar'
|
Nenue@6
|
111 },
|
Nenue@6
|
112 },
|
Nenue@6
|
113 },
|
Nenue@6
|
114 },
|
Nenue@6
|
115 },
|
Nenue@6
|
116 ['PRIEST'] = {
|
Nenue@6
|
117 primary = {
|
Nenue@6
|
118 [1] = {'MANA', SPELL_POWER_MANA}
|
Nenue@6
|
119 },
|
Nenue@6
|
120 frame = 'TkThinComboTemplate',
|
Nenue@6
|
121 secondary = {},
|
Nenue@6
|
122 spec = {
|
Nenue@6
|
123 [1] = {
|
Nenue@6
|
124 secondary = {
|
Nenue@6
|
125 ['Evangelism'] = {
|
Nenue@6
|
126 order = 1,
|
Nenue@6
|
127 max = 5,
|
Nenue@6
|
128 scale = 5,
|
Nenue@6
|
129 type='aura',
|
Nenue@6
|
130 unit = 'player',
|
Nenue@6
|
131 filters = 'HELPFUL|PLAYER',
|
Nenue@6
|
132 spellID = 81662,
|
Nenue@6
|
133 }
|
Nenue@6
|
134 }
|
Nenue@6
|
135 },
|
Nenue@6
|
136 [3] = {
|
Nenue@6
|
137 primary = {
|
Nenue@6
|
138 [1] = {'SHADOW_ORBS', SPELL_POWER_SHADOW_ORBS},
|
Nenue@6
|
139 },
|
Nenue@6
|
140 secondary = {
|
Nenue@6
|
141 ["Surge of Darkness"] = {
|
Nenue@6
|
142 order = 2,
|
Nenue@6
|
143 type = 'aura',
|
Nenue@6
|
144 filters = 'HELPFUL|PLAYER',
|
Nenue@6
|
145 spellID = 87160,
|
Nenue@6
|
146 talentID = 21751,
|
Nenue@6
|
147 max = 3,
|
Nenue@6
|
148 scale = 5,
|
Nenue@6
|
149 unit = 'player',
|
Nenue@6
|
150 },
|
Nenue@6
|
151 ["Insanity"] = {
|
Nenue@6
|
152 order = 2,
|
Nenue@6
|
153 type = 'aura',
|
Nenue@6
|
154 binary = true,
|
Nenue@6
|
155 regress = true,
|
Nenue@6
|
156 size = 1, scale = 1, max = 1,
|
Nenue@6
|
157 filters = 'HELPFUL|PLAYER',
|
Nenue@6
|
158 spellID = 132573,
|
Nenue@6
|
159 unit = 'player',
|
Nenue@6
|
160 talentID = 21753},
|
Nenue@6
|
161 }
|
Nenue@6
|
162 },
|
Nenue@6
|
163 },
|
Nenue@6
|
164 },
|
Nenue@6
|
165 ['ROGUE'] = {
|
Nenue@6
|
166 primary = {
|
Nenue@6
|
167 [1] = {'ENERGY', SPELL_POWER_ENERGY},
|
Nenue@6
|
168 [2] = {'COMBO_POINTS', SPELL_POWER_COMBO_POINTS}
|
Nenue@6
|
169 },
|
Nenue@6
|
170 frame = 'TkThinComboTemplate',
|
Nenue@6
|
171 secondary = {
|
Nenue@6
|
172 ['Anticipation'] = {
|
Nenue@6
|
173 type = 'aura',
|
Nenue@6
|
174 order = 1,
|
Nenue@6
|
175 max = 5,
|
Nenue@6
|
176 scale = 5,
|
Nenue@6
|
177 unit = 'player',
|
Nenue@6
|
178 talentID = 19250,
|
Nenue@6
|
179 },
|
Nenue@6
|
180 },
|
Nenue@6
|
181 spec = {},
|
Nenue@6
|
182 },
|
Nenue@6
|
183 ['MAGE'] = {
|
Nenue@6
|
184 primary = {
|
Nenue@6
|
185 [1] = {'MANA', SPELL_POWER_MANA},
|
Nenue@6
|
186 },
|
Nenue@6
|
187 frame = 'TkThinComboTemplate',
|
Nenue@6
|
188 secondary = {
|
Nenue@6
|
189
|
Nenue@6
|
190 ["Incanter's Flow"] = {
|
Nenue@6
|
191 type = 'aura',
|
Nenue@6
|
192 unit = 'player',
|
Nenue@6
|
193 filters = 'HELPFUL|PLAYER',
|
Nenue@6
|
194 spellID = 1463,
|
Nenue@6
|
195 max = 5,
|
Nenue@6
|
196 scale = 5,
|
Nenue@6
|
197 order = 2,
|
Nenue@6
|
198 talentID = 16033,
|
Nenue@6
|
199 },
|
Nenue@6
|
200 ["Rune of Power"] = {
|
Nenue@6
|
201 type = 'aura',
|
Nenue@6
|
202 unit = 'player',
|
Nenue@6
|
203 filters = 'HELPFUL|PLAYER',
|
Nenue@6
|
204 binary = true,
|
Nenue@6
|
205 max = 1,
|
Nenue@6
|
206 scale = 1,
|
Nenue@6
|
207 order = 2,
|
Nenue@6
|
208 talentID = 16032,
|
Nenue@6
|
209 }
|
Nenue@6
|
210 },
|
Nenue@6
|
211 spec = {
|
Nenue@6
|
212 [1] = {
|
Nenue@6
|
213 secondary = {
|
Nenue@6
|
214 ['Arcane Charge'] = {
|
Nenue@6
|
215 type ='aura',
|
Nenue@6
|
216 unit = 'player',
|
Nenue@6
|
217 filters = 'HARMFUL|PLAYER',
|
Nenue@6
|
218 spellID = 114664,
|
Nenue@6
|
219 scale = 4,
|
Nenue@6
|
220 max = 4,
|
Nenue@6
|
221 order = 1,
|
Nenue@6
|
222 },
|
Nenue@6
|
223 }
|
Nenue@6
|
224 },
|
Nenue@6
|
225 [3] = {
|
Nenue@6
|
226 secondary = {
|
Nenue@6
|
227 ['Fingers of Frost'] = {
|
Nenue@6
|
228 type = 'aura',
|
Nenue@6
|
229 unit = 'player',
|
Nenue@6
|
230 filters = '',
|
Nenue@6
|
231 spellID = 112965,
|
Nenue@6
|
232 max = 2,
|
Nenue@6
|
233 scale = 4,
|
Nenue@6
|
234 order = 1,
|
Nenue@6
|
235 },
|
Nenue@6
|
236 ['Brain Freeze'] = {
|
Nenue@6
|
237 type = 'aura',
|
Nenue@6
|
238 unit = 'player',
|
Nenue@6
|
239 filters = '',
|
Nenue@6
|
240 spellID = 44549,
|
Nenue@6
|
241 scale = 4,
|
Nenue@6
|
242 max = 2,
|
Nenue@6
|
243 order = 1,
|
Nenue@6
|
244 mirror = true,
|
Nenue@6
|
245 }
|
Nenue@6
|
246 }
|
Nenue@6
|
247 },
|
Nenue@6
|
248 }
|
Nenue@6
|
249 }
|
Nenue@6
|
250 }
|
Nenue@6
|
251 local P = mod.prototype
|
Nenue@6
|
252
|
Nenue@6
|
253 function mod:OnEnable()
|
Nenue@6
|
254 self.disabled_freams = {
|
Nenue@6
|
255 [T.playerClass] = {
|
Nenue@6
|
256 [T.specPage] = {}
|
Nenue@6
|
257 }
|
Nenue@6
|
258 }
|
Nenue@6
|
259 self.watched_units = {}
|
Nenue@6
|
260 self.watched_auras = {}
|
Nenue@6
|
261 self.watched_spells = {}
|
Nenue@6
|
262 self.db = TurokData.powerbar
|
Nenue@6
|
263 db = self.db
|
Nenue@6
|
264
|
Nenue@6
|
265 self:Prototype_Init()
|
Nenue@6
|
266 end
|
Nenue@6
|
267 function mod:Prototype_Init()
|
Nenue@6
|
268 -- consult prototype vars
|
Nenue@6
|
269 prototype = {}
|
Nenue@6
|
270 mod.dcopy = function(t1, t2, d)
|
Nenue@6
|
271 d = d or ''
|
Nenue@6
|
272 for k,v in pairs(t2) do
|
Nenue@6
|
273 if type(v) == 'table' then
|
Nenue@6
|
274 if type(t1[k]) ~= 'table' then
|
Nenue@6
|
275 t1[k] = {}
|
Nenue@6
|
276 print(d, 'adding table', cKey(k))
|
Nenue@6
|
277 else
|
Nenue@6
|
278 print(d, 'merging tables', cKey(k))
|
Nenue@6
|
279 end
|
Nenue@6
|
280 mod.dcopy(t1[k], v, d..' ')
|
Nenue@6
|
281 else
|
Nenue@6
|
282 if t1[k] then
|
Nenue@6
|
283 print(d, 'clobbered', k)
|
Nenue@6
|
284 else
|
Nenue@6
|
285 print(d, k, '=', cType(v))
|
Nenue@6
|
286 end
|
Nenue@6
|
287 t1[k] = v
|
Nenue@6
|
288 end
|
Nenue@6
|
289 end
|
Nenue@6
|
290 end
|
Nenue@6
|
291 mod.dcopy(prototype, mod.prototype[T.playerClass])
|
Nenue@6
|
292 if mod.prototype[T.playerClass].spec[T.specPage] then
|
Nenue@6
|
293 mod.dcopy(prototype, mod.prototype[T.playerClass].spec[T.specPage])
|
Nenue@6
|
294 end
|
Nenue@6
|
295
|
Nenue@6
|
296 mod.thisproto = prototype
|
Nenue@6
|
297
|
Nenue@6
|
298 print('|cFFFF0088Template:|r', 'Frame', 'TkPowerBarFrame', UIParent, prototype.frame)
|
Nenue@6
|
299 db = self.db
|
Nenue@6
|
300
|
Nenue@6
|
301 if bar and bar.GetObjectType then
|
Nenue@6
|
302 bar:Hide()
|
Nenue@6
|
303 mod.disabled_frames[bar.specPage] = bar
|
Nenue@6
|
304 print('putting away old frame')
|
Nenue@6
|
305 end
|
Nenue@6
|
306
|
Nenue@6
|
307 if not bar then
|
Nenue@6
|
308 bar = CreateFrame('Frame', 'TkPowerBar', UIParent, prototype.frame)
|
Nenue@6
|
309 end
|
Nenue@6
|
310 bar.specPage = T.specPage
|
Nenue@6
|
311 bar.specID = T.specID
|
Nenue@6
|
312 bar.primary = {} -- {current, max, token}
|
Nenue@6
|
313 bar.secondary = {} -- {current, max, token}
|
Nenue@6
|
314 bar.aura = {} -- {name, duration, expires, unit, flags}
|
Nenue@6
|
315 bar.spell = {} -- copy of the last T.spellevent match
|
Nenue@6
|
316 print(' setting layout', db)
|
Nenue@6
|
317 print(bar:GetName())
|
Nenue@6
|
318 T.SetFrameLayout(bar, prototype.cvars and db[prototype.cvars] or db)
|
Nenue@6
|
319 T.SetStatusTextures(bar, db)
|
Nenue@6
|
320
|
Nenue@6
|
321 print(' setting methods')
|
Nenue@6
|
322 bar.Init = mod.Bar_Init
|
Nenue@6
|
323 bar.Event = mod.Bar_Event
|
Nenue@6
|
324 bar.Update = mod.Bar_Update
|
Nenue@6
|
325
|
Nenue@6
|
326
|
Nenue@6
|
327 --- loop through aura definitions and flag accordingly
|
Nenue@6
|
328 print('Primary power types:')
|
Nenue@6
|
329 for order, power_data in pairs(prototype.primary) do
|
Nenue@6
|
330 print( order, unpack(power_data))
|
Nenue@6
|
331 local token, power_type = unpack(power_data)
|
Nenue@6
|
332 local power, max = UnitPower('player', power_type), UnitPowerMax('player', power_type)
|
Nenue@6
|
333 bar.primary[token] = {power, max, power_type, order}
|
Nenue@6
|
334 print(' ', cKey(token), '= {', power, max, power_type, order, '}')
|
Nenue@6
|
335 end
|
Nenue@6
|
336
|
Nenue@6
|
337 --- go through secondary data args and assign the appropriate source functions
|
Nenue@6
|
338 local useAura, useCooldown
|
Nenue@6
|
339 local used_rows = {}
|
Nenue@6
|
340 if prototype.secondary then
|
Nenue@6
|
341 mod.secondary = {}
|
Nenue@6
|
342 for name, c in pairs(prototype.secondary) do
|
Nenue@6
|
343 local isActive = true
|
Nenue@6
|
344 print('parsing extra handler', name)
|
Nenue@6
|
345 if c.talentID then
|
Nenue@6
|
346 print(c.talentID, T.specPage)
|
Nenue@6
|
347 isActive = (type(c.talentID) == 'table') and select(4, GetTalentInfo(unpack(c.talentID), T.specGroup)) or
|
Nenue@6
|
348 select(4, GetTalentInfoByID(c.talentID, T.specGroup))
|
Nenue@6
|
349 print(' talentID:', cNum(isActive))
|
Nenue@6
|
350 end
|
Nenue@6
|
351 if isActive then
|
Nenue@6
|
352 local sc = {}
|
Nenue@6
|
353
|
Nenue@6
|
354 sc = c
|
Nenue@6
|
355 print(' enable:', cNum(isActive), cWord(c.type))
|
Nenue@6
|
356 if c.type == 'aura' then
|
Nenue@6
|
357 sc.spellName = name
|
Nenue@6
|
358 if c.binary then
|
Nenue@6
|
359 sc.Get = function(self)
|
Nenue@6
|
360 print('get: UnitAura', self.unit, self.spellName, c.filters)
|
Nenue@6
|
361 local exists = UnitAura(self.unit, self.spellName, nil, self.filters)
|
Nenue@6
|
362 return (exists) and 1 or 0
|
Nenue@6
|
363 end
|
Nenue@6
|
364 else
|
Nenue@6
|
365 sc.Get = function(self)
|
Nenue@6
|
366 print('get: UnitAura', self.unit, self.spellName, c.filters)
|
Nenue@6
|
367 local _,_,_, count = UnitAura(self.unit, self.spellName, nil, self.filters)
|
Nenue@6
|
368 return count or 0
|
Nenue@6
|
369 end
|
Nenue@6
|
370 end
|
Nenue@6
|
371
|
Nenue@6
|
372 useAura = true
|
Nenue@6
|
373 elseif c.type == 'cooldown' then
|
Nenue@6
|
374 if c.inverse then
|
Nenue@6
|
375 sc.Get = function(self)
|
Nenue@6
|
376 local start, duration, enabled = GetSpellCooldown(c.spellID)
|
Nenue@6
|
377 sc[1] = (duration > 0) and (GetTime() - start) or c.max
|
Nenue@6
|
378 print('get: GetSpellCooldown (inverse)', c.spellID, '=', sc[1])
|
Nenue@6
|
379 end
|
Nenue@6
|
380 else
|
Nenue@6
|
381 sc.Get = function(self)
|
Nenue@6
|
382 local start, duration, enabled = GetSpellCooldown(c.spellID)
|
Nenue@6
|
383 sc[1] = (duration > 0) and (start + duration - GetTime()) or 0
|
Nenue@6
|
384 print('get: GetSpellCooldown', c.spellID, '=', sc[1])
|
Nenue@6
|
385 end
|
Nenue@6
|
386 end
|
Nenue@6
|
387 useCooldown = true
|
Nenue@6
|
388 end
|
Nenue@6
|
389 print(' committing', name, 'to row', sc.order)
|
Nenue@6
|
390 bar.secondary[name] = sc
|
Nenue@6
|
391 used_rows[sc.order] = true -- index the drawn rows for talent_update
|
Nenue@6
|
392 end
|
Nenue@6
|
393 end
|
Nenue@6
|
394 end
|
Nenue@6
|
395
|
Nenue@6
|
396
|
Nenue@6
|
397 if useAura then bar:RegisterEvent('UNIT_AURA') end
|
Nenue@6
|
398 if useCooldown then bar:RegisterEvent('UNIT_SPELLCAST_SUCCEEDED') end
|
Nenue@6
|
399
|
Nenue@6
|
400 bar:SetScript('OnUpdate', nil) -- make sure any xml embeds are cleaned out
|
Nenue@6
|
401 bar:SetScript('OnEvent', mod.Bar_Event)
|
Nenue@6
|
402 bar:RegisterEvent('UNIT_POWER_FREQUENT')
|
Nenue@6
|
403
|
Nenue@6
|
404 bar:Init()
|
Nenue@6
|
405 bar:Show()
|
Nenue@6
|
406
|
Nenue@6
|
407 -- metrics used by data plots
|
Nenue@6
|
408 bar.width = db.width
|
Nenue@6
|
409 bar.foreground_inset = db.foreground_inset
|
Nenue@6
|
410 bar.right_edge = bar:GetRight()
|
Nenue@6
|
411 bar.fill_limit = bar.right_edge
|
Nenue@6
|
412 bar.foreground.width = bar.width + (bar.foreground_inset)
|
Nenue@6
|
413 bar.spacing = 1
|
Nenue@6
|
414
|
Nenue@6
|
415 mod.powerbar = bar
|
Nenue@6
|
416 end
|
Nenue@6
|
417
|
Nenue@6
|
418 mod.Bar_Init = function(self)
|
Nenue@6
|
419 local mainPower, comboPower
|
Nenue@6
|
420 for token, power in pairs(self.primary) do
|
Nenue@6
|
421 if power[4] == 1 then
|
Nenue@6
|
422 mainPower = power
|
Nenue@6
|
423 elseif power[4] == 2 then
|
Nenue@6
|
424 comboPower = power
|
Nenue@6
|
425 end
|
Nenue@6
|
426 end
|
Nenue@6
|
427
|
Nenue@6
|
428 if mainPower then
|
Nenue@6
|
429 local power, max, type, token = unpack(mainPower)
|
Nenue@6
|
430 if power and max then
|
Nenue@6
|
431 self.powerText:SetText(power)
|
Nenue@6
|
432 self:SetProgress(power/max)
|
Nenue@6
|
433 end
|
Nenue@6
|
434 end
|
Nenue@6
|
435
|
Nenue@6
|
436 if comboPower then
|
Nenue@6
|
437 local power, max, type, token = unpack(comboPower)
|
Nenue@6
|
438 local px = (self.width-db.secondary.spacing* (max -1)-db.secondary.padding*2) / max
|
Nenue@6
|
439 self.combo = {}
|
Nenue@6
|
440 for i = 1, max do
|
Nenue@6
|
441 if not self.combo[i] then
|
Nenue@6
|
442 self.combo[i] = self:CreateTexture('TkPrimaryResourcePellet'..i, 'OVERLAY')
|
Nenue@6
|
443 end
|
Nenue@6
|
444
|
Nenue@6
|
445 local k = i - 1
|
Nenue@6
|
446 local cx = db.secondary.padding + px * k + db.secondary.spacing * k
|
Nenue@6
|
447 local cy = db.secondary.padding
|
Nenue@6
|
448 self.combo[i]:ClearAllPoints()
|
Nenue@6
|
449 self.combo[i]:SetSize(px, db.secondary.height)
|
Nenue@6
|
450 self.combo[i]:SetPoint(db.secondary.anchor, self, db.secondary.anchorTo, cx, cy)
|
Nenue@6
|
451 --print(' ', self.combo[i]:GetName(), self.pointsize1, cx, cy, self.combo[i]:GetDrawLayer())
|
Nenue@6
|
452
|
Nenue@6
|
453 self.combo[i]:Show()
|
Nenue@6
|
454 end
|
Nenue@6
|
455 end
|
Nenue@6
|
456
|
Nenue@6
|
457
|
Nenue@6
|
458 if self.secondary then
|
Nenue@6
|
459 if not self.resources then
|
Nenue@6
|
460 print('|cFFFF0000creating resources block')
|
Nenue@6
|
461 self.resources = {}
|
Nenue@6
|
462 else
|
Nenue@6
|
463 local hidecount = 0
|
Nenue@6
|
464 for i, row in pairs(self.resources) do
|
Nenue@6
|
465 for j, col in pairs(row) do
|
Nenue@6
|
466 col:Hide()
|
Nenue@6
|
467 hidecount = hidecount + 1
|
Nenue@6
|
468 end
|
Nenue@6
|
469 end
|
Nenue@6
|
470 print('hiding', hidecount, 'regions')
|
Nenue@6
|
471 end
|
Nenue@6
|
472 for name, secondary in pairs(self.secondary) do
|
Nenue@6
|
473 local n = secondary.order
|
Nenue@6
|
474 local sid = 'secondary'..n
|
Nenue@6
|
475 local c = db[sid] or db
|
Nenue@6
|
476 if not self.resources[n] then
|
Nenue@6
|
477 print(' |cFFFF8800creating resource row')
|
Nenue@6
|
478 self.resources[n] = {}
|
Nenue@6
|
479 end
|
Nenue@6
|
480 local row = self.resources[n]
|
Nenue@6
|
481
|
Nenue@6
|
482 print('secondary resource', cText(name), 'max= '..cNum(secondary.max), 'scale= '..cNum(secondary.scale))
|
Nenue@6
|
483 local px = c.padding
|
Nenue@6
|
484 local pw = (self.width - c.padding*2 - c.spacing * (secondary.scale - 1)) / secondary.scale
|
Nenue@6
|
485 for i = 1, (secondary.max or 1) do
|
Nenue@6
|
486 if not row[i] then
|
Nenue@6
|
487 row[i] = bar:CreateTexture('TkResourcePellet.'..tostring(secondary.order)..'.'..tostring(i))
|
Nenue@6
|
488 end
|
Nenue@6
|
489 row[i]:Show()
|
Nenue@6
|
490 row[i]:SetDrawLayer('OVERLAY', sid)
|
Nenue@6
|
491 row[i]:SetPoint('BOTTOMLEFT', self, 'TOPLEFT', px, c.y)
|
Nenue@6
|
492 row[i]:SetSize(pw, db[sid].height or db.height)
|
Nenue@6
|
493
|
Nenue@6
|
494 print(' *', cNum(i), cKey(sid), cNum(px), cNum(c.padding))
|
Nenue@6
|
495 px = px + pw + c.spacing
|
Nenue@6
|
496 end
|
Nenue@6
|
497 end
|
Nenue@6
|
498 end
|
Nenue@6
|
499
|
Nenue@6
|
500 mod.Bar_Event(self, nil, 'player')
|
Nenue@6
|
501 end
|
Nenue@6
|
502
|
Nenue@6
|
503 -- we only want to update at specific points
|
Nenue@6
|
504 mod.Bar_Event = function(self, event, ...)
|
Nenue@6
|
505 local unit, token = ...
|
Nenue@9
|
506 uprint( event, unit, token)
|
Nenue@6
|
507 if token and unit == 'player' then
|
Nenue@6
|
508 mod.Bar_Power(self, token)
|
Nenue@6
|
509 end
|
Nenue@6
|
510 --print(unit, token, ...)
|
Nenue@6
|
511 mod.Bar_Aura(bar, event, unit, token, ...)
|
Nenue@6
|
512 end
|
Nenue@6
|
513
|
Nenue@6
|
514 mod.Bar_Aura = function (self, event, unit)
|
Nenue@9
|
515 uprint('bar updating function called', event, unit)
|
Nenue@6
|
516
|
Nenue@6
|
517
|
Nenue@6
|
518 if event == 'UNIT_AURA' or event == nil then
|
Nenue@6
|
519 for token, info in pairs(self.secondary) do
|
Nenue@6
|
520 local row = self.resources[info.order]
|
Nenue@6
|
521 if info.unit == unit then
|
Nenue@6
|
522 local count = info.Get(info)
|
Nenue@6
|
523 local db = db['secondary'..info.order] or db
|
Nenue@6
|
524 for i = 1, info.max do
|
Nenue@6
|
525 local palette = (i > count) and ('background_color') or ('foreground_color')
|
Nenue@6
|
526
|
Nenue@6
|
527 print(token, i, count, (i > count), palette, unpack(db[palette]))
|
Nenue@6
|
528 row[i]:SetTexture(unpack(db[palette]))
|
Nenue@6
|
529 end
|
Nenue@6
|
530 end
|
Nenue@6
|
531 end
|
Nenue@6
|
532 end
|
Nenue@6
|
533 end
|
Nenue@6
|
534
|
Nenue@6
|
535 function mod:Bar_Power(token)
|
Nenue@6
|
536 if not self.primary[token] then
|
Nenue@6
|
537 return
|
Nenue@6
|
538 end
|
Nenue@6
|
539
|
Nenue@6
|
540 local p = self.primary[token]
|
Nenue@6
|
541 -- 1=cur, 2=max, 3=type, 4=token
|
Nenue@6
|
542 p[1] = UnitPower('player', p[3])
|
Nenue@6
|
543 p[2] = UnitPowerMax('player', p[3])
|
Nenue@9
|
544 uprint(' ', table.concat(self.primary[token],', '))
|
Nenue@6
|
545
|
Nenue@6
|
546 if p[4] == 1 then
|
Nenue@9
|
547 uprint( 'progress:', p[1]/p[2])
|
Nenue@6
|
548 --print(unpack(p))
|
Nenue@6
|
549 self.powerText:SetText(p[1])
|
Nenue@6
|
550 self:SetProgress(p[1]/p[2])
|
Nenue@6
|
551 elseif p[4] == 2 then
|
Nenue@6
|
552 --print('update on', token, 'c:', p[1], 'm:', p[2])
|
Nenue@6
|
553 self.secondaryText:SetText(p[1])
|
Nenue@6
|
554 for i = 1, p[2] do
|
Nenue@6
|
555 local palette = (i > p[1]) and 'background_color' or 'foreground_color'
|
Nenue@6
|
556 self.combo[i]:SetTexture(unpack(db.secondary[palette]))
|
Nenue@6
|
557
|
Nenue@6
|
558 end
|
Nenue@6
|
559 end
|
Nenue@6
|
560 end
|
Nenue@6
|
561
|
Nenue@6
|
562 --- Spell parsing
|
Nenue@6
|
563 function mod:SpellCastEvent(e, u, spellName, rank, castID, spellID)
|
Nenue@6
|
564 if u ~= 'player' then
|
Nenue@6
|
565 return true
|
Nenue@6
|
566 end
|
Nenue@6
|
567 if e == 'UNIT_SPELLCAST_DELAYED' then
|
Nenue@6
|
568 elseif e == 'UNIT_SPELLCAST_START' then
|
Nenue@6
|
569 bar.casting = true
|
Nenue@6
|
570 bar.spellevent = T.spellevent[u]
|
Nenue@6
|
571 bar.spell = T.casting[u]
|
Nenue@6
|
572 elseif e == 'UNIT_SPELLCAST_CHANNEL_START' then
|
Nenue@6
|
573 bar.channeling = true
|
Nenue@6
|
574 bar.spellevent = T.spellevent[u]
|
Nenue@6
|
575 bar.spell = T.channeling[u]
|
Nenue@6
|
576 elseif e == 'UNIT_SPELLCAST_SUCCEEDED' then
|
Nenue@6
|
577 elseif e == 'UNIT_SPELLCAST_STOP' then
|
Nenue@6
|
578 bar.casting = nil
|
Nenue@6
|
579 bar.casting = nil
|
Nenue@6
|
580 elseif e == 'UNIT_SPELLCAST_CHANNEL_STOP' then
|
Nenue@6
|
581 bar.channeling = nil
|
Nenue@6
|
582 bar.channeling = nil
|
Nenue@6
|
583 end
|
Nenue@6
|
584 end
|
Nenue@6
|
585
|
Nenue@6
|
586 function mod:PLAYER_TALENT_UPDATE(event, unit)
|
Nenue@6
|
587 print(cText('*** Talent Update'), cKey('Spec:'), cWord(T.specName), cNum(T.specPage))
|
Nenue@6
|
588 mod:Prototype_Init()
|
Nenue@6
|
589 end
|