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