Mercurial > wow > buffalo2
comparison BuffFrame/RaidBuffTray.lua @ 47:1a322b92dbfa
file cleanup
| author | Nenue |
|---|---|
| date | Thu, 28 Apr 2016 05:54:21 -0400 |
| parents | RaidBuffTray.lua@3dbcad2b387d |
| children | 9837069e366a |
comparison
equal
deleted
inserted
replaced
| 46:aa693607b813 | 47:1a322b92dbfa |
|---|---|
| 1 --- ${PACKAGE_NAME} | |
| 2 -- @file-author@ | |
| 3 -- @project-revision@ @project-hash@ | |
| 4 -- @file-revision@ @file-hash@ | |
| 5 -- Created: 3/20/2016 10:00 PM | |
| 6 | |
| 7 local _, A = ... | |
| 8 local B = A.frame | |
| 9 local MODULE = 'BuffFrame' | |
| 10 local M = B:RegisterModule(MODULE) | |
| 11 local displays = B.displays | |
| 12 | |
| 13 local parentAnchor, parentFrame, raidbuffsFrame | |
| 14 local band, lshift, CreateFrame = bit.band, bit.lshift, CreateFrame | |
| 15 local raidBuffs = {} | |
| 16 local raidBuffSymbols = {'St', 'HP', 'AP', 'Ha', 'SP', 'Cr', 'Ma', 'MS', 'V' } | |
| 17 local missingBuffs = {} | |
| 18 local playerBuffing, playerCurrentBuff | |
| 19 local playerBuffs = {} | |
| 20 local c, ac, frameSize, frameSpacing, framePosition | |
| 21 local fprint = B.fprint | |
| 22 local NUM_LE_MISSING_RAID_BUFFS = 0 | |
| 23 local missingBuffsAnchor | |
| 24 | |
| 25 | |
| 26 --- Takes a given icon texture and calls the pre-defined function set | |
| 27 M.UpdateBuffStyle = function(buff, style, path) | |
| 28 local print = fprint() | |
| 29 local icon = buff.icon | |
| 30 local symbol = buff.symbol | |
| 31 path = path or icon.iconPath | |
| 32 --print(style, icon.iconStyle) | |
| 33 | |
| 34 if style ~= buff.iconStyle or path ~= buff.iconPath then | |
| 35 print('|cFF0088FFUpdateBuffStyle(|r', icon:GetName(), style, path) | |
| 36 icon.iconStyle = style | |
| 37 icon.iconPath = path | |
| 38 else | |
| 39 --print('|cFF00FF88UpdateBuffStyle(|r', icon:GetName(), style, path, ') same values, ignore') | |
| 40 return | |
| 41 end | |
| 42 local styleset = B.BuffStyles[style] | |
| 43 if not path or path == '' then | |
| 44 print('path is nil/empty') | |
| 45 icon:SetTexture(1, 1, 1, 1) | |
| 46 icon:SetVertexColor(unpack(styleset.Color)) | |
| 47 else | |
| 48 icon:SetTexture(path or icon:GetTexture()) | |
| 49 icon:SetVertexColor(unpack(styleset.Color)) | |
| 50 end | |
| 51 | |
| 52 if symbol and symbol.GetText then | |
| 53 symbol:SetTextColor(unpack(styleset.TextColor)) | |
| 54 symbol:SetText(buff.symbolName or 'NaW') | |
| 55 end | |
| 56 | |
| 57 icon:SetBlendMode(styleset.SetBlendMode) | |
| 58 icon:SetDesaturated(styleset.SetDesaturated) | |
| 59 end | |
| 60 | |
| 61 --- Populates a list of targets needing a buff, fired by a handler | |
| 62 local PlayerBuffTodo ={} | |
| 63 M.UpdateBuffStatus = function(aura, filters) | |
| 64 if not PlayerBuffStatus[aura] then | |
| 65 PlayerBuffStatus[aura] = {} | |
| 66 end | |
| 67 | |
| 68 | |
| 69 print(UnitClass('player')) | |
| 70 if IsInGroup() then | |
| 71 local numBuffed = 0 | |
| 72 local partySize = GetNumGroupMembers() | |
| 73 local missing = {} | |
| 74 for i = 1, partySize do | |
| 75 local unit = 'raid'..i | |
| 76 if UnitAura(unit, aura, nil, filters) then | |
| 77 numBuffed = numBuffed + 1 | |
| 78 else | |
| 79 tinsert(missing, unit) | |
| 80 end | |
| 81 end | |
| 82 | |
| 83 PlayerBuffTodo[aura] = missing | |
| 84 | |
| 85 end | |
| 86 end | |
| 87 | |
| 88 --- Evaluates buff availability criteria | |
| 89 -- Uses hard returns to avoid over-iterating conditionals, particularly pet family | |
| 90 local function IsBuffAvailable(criteria) | |
| 91 local available, active = false, false | |
| 92 local result | |
| 93 for _, test in ipairs(criteria) do | |
| 94 if test == true then | |
| 95 -- it's a passive effect that is always on | |
| 96 return true, true | |
| 97 else | |
| 98 if c.spec then | |
| 99 if not (result and c.spec == B.PlayerSpec) then | |
| 100 return false | |
| 101 end | |
| 102 end | |
| 103 | |
| 104 if c.talent then | |
| 105 local talentID, name, texture, selected, available = GetTalentInfoByID(c.talent, GetActiveSpecGroup()) | |
| 106 if not (result and selected) then | |
| 107 return false | |
| 108 end | |
| 109 end | |
| 110 | |
| 111 if c.petFamily then | |
| 112 local lim = min(5, NUM_PET_STABLE_SLOTS) -- to avoid volatile loop condition | |
| 113 for p = 1, lim do | |
| 114 local hasPet = false | |
| 115 local icon, name, level, family, talent = GetStablePetInfo(p) | |
| 116 if family == c.petFamily then | |
| 117 hasPet = true | |
| 118 end | |
| 119 if not (result and hasPet) then | |
| 120 return false | |
| 121 end | |
| 122 end | |
| 123 end | |
| 124 | |
| 125 end | |
| 126 end | |
| 127 return true, false | |
| 128 end | |
| 129 | |
| 130 --- events: PLAYER_SPECIALIZATION_CHANGED | |
| 131 function M:UpdateBuffsTodo (unit) | |
| 132 -- buffs vs. auras | |
| 133 if unit ~= 'player' then | |
| 134 -- look for changes in the GIST manifest and sort them out | |
| 135 return | |
| 136 end | |
| 137 | |
| 138 local class = UnitClass('player') | |
| 139 local spec = GetSpecialization() | |
| 140 if not class or | |
| 141 not spec or | |
| 142 not IsInGroup() or | |
| 143 not B.PlayerBuffStatus[class] then | |
| 144 -- if just logging in, info won't be available for several seconds | |
| 145 -- if not grouped, don't calc | |
| 146 -- hide frame | |
| 147 B.PlayerBuffsActive = function() return false end | |
| 148 return | |
| 149 end | |
| 150 | |
| 151 -- verify change | |
| 152 if B.PlayerCurrentSpec == spec or B.PlayerClass == class then | |
| 153 return | |
| 154 end | |
| 155 B.PlayerCurrentSpec = spec | |
| 156 B.PlayerClass = class | |
| 157 | |
| 158 local test = B.ClassRaidBuffs | |
| 159 local buffTypes = {} | |
| 160 local auraTypes = {} | |
| 161 for i = 1, NUM_LE_RAID_BUFF_TYPES do | |
| 162 local name, filters | |
| 163 if test[i] and test[i][class] then | |
| 164 playerBuffs[i], name, filters = IsBuffAvailable(test[i][class]) | |
| 165 else | |
| 166 playerBuffs[i] = nil | |
| 167 end | |
| 168 | |
| 169 if name then | |
| 170 B.UpdateBuffStatus(name, filters) | |
| 171 end | |
| 172 end | |
| 173 end | |
| 174 | |
| 175 -- Called once to setup the ConsolidatedBuffs stencil | |
| 176 local consolidatedBuffsLoaded | |
| 177 M.SetConsolidatedBuffs = function() | |
| 178 local print = fprint() | |
| 179 c = displays.ConsolidatedBuff.conf | |
| 180 parentFrame = B.guides[c.Parent][c.Position] | |
| 181 raidbuffsFrame = B.anchor.ConsolidatedBuff | |
| 182 | |
| 183 B.SetConfigLayers(raidbuffsFrame) | |
| 184 consolidatedBuffsLoaded = true | |
| 185 ConsolidatedBuffs:ClearAllPoints() | |
| 186 ConsolidatedBuffs:SetAllPoints(parentFrame.icon) | |
| 187 if c.Icon then | |
| 188 ConsolidatedBuffsIcon:SetAllPoints(parentFrame.icon) | |
| 189 ConsolidatedBuffsIcon:SetTexCoord(0.609,0.89,0.215,0.78) | |
| 190 else | |
| 191 ConsolidatedBuffsIcon:Hide() | |
| 192 end | |
| 193 | |
| 194 ConsolidatedBuffsCount:Hide() | |
| 195 end | |
| 196 | |
| 197 local missingTypes = {} | |
| 198 local raidBuffsInitialized | |
| 199 M.UpdateRaidBuffs = function() | |
| 200 local print = fprint() | |
| 201 if not consolidatedBuffsLoaded then | |
| 202 M.SetConsolidatedBuffs() | |
| 203 end | |
| 204 | |
| 205 if not M.ShowConsolidated or not parentFrame.contains then | |
| 206 print(' hiding raid buffs square') | |
| 207 if raidBuffsInitialized then | |
| 208 for i = 1, 9 do | |
| 209 if raidBuffs[i] then | |
| 210 raidBuffs[i]:Hide() | |
| 211 end | |
| 212 end | |
| 213 raidBuffsInitialized = nil | |
| 214 end | |
| 215 if parentFrame then | |
| 216 print(c.Parent, c.Position) | |
| 217 print('de-flagging parent') | |
| 218 parentFrame.contains = nil | |
| 219 end | |
| 220 raidbuffsFrame:Hide() | |
| 221 return | |
| 222 end | |
| 223 | |
| 224 local c = B.displays.ConsolidatedBuff.conf | |
| 225 if parentFrame and not parentFrame.contains then | |
| 226 raidBuffsInitialized = true | |
| 227 print('re-flagging parent', parentFrame:GetName()) | |
| 228 parentFrame.contains = parentFrame | |
| 229 B.decors[c.Parent][c.Position]:Hide() | |
| 230 raidbuffsFrame:Show() | |
| 231 | |
| 232 -- make sure parent icon is updated | |
| 233 local w = c.Size*c.PerRow+c.Spacing*(c.PerRow-1)+c.Border*2 | |
| 234 parentFrame:SetSize(w, w) | |
| 235 parentFrame.icon:SetSize(w - c.Border*2, w - c.Border*2) | |
| 236 parentFrame.contains = raidbuffsFrame | |
| 237 | |
| 238 M.UpdateBuffs(c.Parent) | |
| 239 end | |
| 240 | |
| 241 -- have to loop again due to tainting restrictions | |
| 242 -- could compare the tooltip font object pointers, but that may change | |
| 243 local buffStack = GetRaidBuffInfo() | |
| 244 print(GetRaidBuffInfo()) | |
| 245 local guides = B.guides.ConsolidatedBuff | |
| 246 local numBuffs = 0 | |
| 247 local numAvailable = 0 | |
| 248 local mask = 1 | |
| 249 if buffStack == nil then | |
| 250 return -- discard | |
| 251 end | |
| 252 | |
| 253 | |
| 254 for i = 1, NUM_LE_RAID_BUFF_TYPES do | |
| 255 local available = (band(buffStack, mask) > 0) | |
| 256 local name, _, icon, start, duration, spellID, slot = GetRaidBuffTrayAuraInfo(i) | |
| 257 print(i, name, icon, available) | |
| 258 | |
| 259 raidBuffs[i] = raidBuffs[i] or CreateFrame('Frame', 'VeneerRaidBuff' .. i, raidbuffsFrame, 'VeneerRaidBuffTemplate') | |
| 260 local buff = raidBuffs[i] | |
| 261 if not raidBuffs[i].stylized then | |
| 262 print(' setting style', i) | |
| 263 buff.stylized = true | |
| 264 buff.symbol:SetText(raidBuffSymbols[i]) | |
| 265 buff.symbol:SetFont("Fonts\\FRIZQT__.TTF", 10, 'OUTLINE') | |
| 266 buff:SetSize(parentFrame.icon:GetWidth()/c.PerRow,parentFrame.icon:GetWidth()/c.PerRow) | |
| 267 buff.symbolName = raidBuffSymbols[i] | |
| 268 | |
| 269 buff.icon:SetAllPoints(guides[i].icon) | |
| 270 buff:SetAllPoints(guides[i]) | |
| 271 raidbuffsFrame.Zoom(buff.icon) | |
| 272 end | |
| 273 | |
| 274 buff:Show() | |
| 275 local buffStyle = 'missing' | |
| 276 if name then | |
| 277 buff:Show() | |
| 278 buff.symbol:Hide() | |
| 279 missingTypes[i] = nil | |
| 280 numBuffs = numBuffs + 1 | |
| 281 numAvailable = numAvailable + 1 | |
| 282 buffStyle = 'active' | |
| 283 else | |
| 284 buff.symbol:Show() | |
| 285 if band(buffStack, mask) > 0 then | |
| 286 buffStyle = 'available' | |
| 287 numAvailable = numAvailable + 1 | |
| 288 else | |
| 289 buffStyle = 'missing' | |
| 290 icon = '' | |
| 291 end | |
| 292 end | |
| 293 mask = lshift(mask, 1) | |
| 294 | |
| 295 M.UpdateBuffStyle(buff, buffStyle, icon) | |
| 296 end | |
| 297 | |
| 298 -- todo: filter by castable and suppress for non-overlapping auras | |
| 299 | |
| 300 raidbuffsFrame.label:SetText(numBuffs..'/'..numAvailable) | |
| 301 print(parentFrame:GetName(), parentFrame:GetSize()) | |
| 302 | |
| 303 if B.ShowMissingBuffs then | |
| 304 B.UpdateMissingBuffs() | |
| 305 elseif missingBuffsAnchor and missingBuffsAnchor:IsVisible() then | |
| 306 for i = 1, NUM_LE_MISSING_RAID_BUFFS do | |
| 307 missingBuffs[i]:Hide() | |
| 308 end | |
| 309 end | |
| 310 end | |
| 311 | |
| 312 B.UpdateMissingBuffs = function() | |
| 313 local print = B.fprint() | |
| 314 local numMissing = 0 | |
| 315 | |
| 316 local firstMissing, lastMissing | |
| 317 for i = 1, NUM_LE_RAID_BUFF_TYPES do | |
| 318 local name, _, icon, start, duration, spellID, slot = GetRaidBuffTrayAuraInfo(i) | |
| 319 | |
| 320 if not name then | |
| 321 numMissing = numMissing + 1 | |
| 322 | |
| 323 print('missing buff', i, numMissing) | |
| 324 B.UpdateBuffStyle(raidBuffs[i].icon, 'missing', "") | |
| 325 | |
| 326 missingBuffs[numMissing] = missingBuffs[numMissing] or CreateFrame('Button', 'VeneerMissingBuff' .. numMissing, raidbuffsFrame, 'VeneerMissingBuffTemplate') | |
| 327 | |
| 328 local missing = missingBuffs[numMissing] | |
| 329 | |
| 330 missing:Show() | |
| 331 missing:SetSize(c.Size*c.PerRow, c.Size) | |
| 332 if numMissing == 1 then | |
| 333 firstMissing = missing | |
| 334 else | |
| 335 missing:SetPoint('TOP', lastMissing, 'BOTTOM', 0, -c.Spacing) | |
| 336 end | |
| 337 | |
| 338 missing.label:SetText(_G['RAID_BUFF_'.. i]) | |
| 339 lastMissing = missing | |
| 340 | |
| 341 end | |
| 342 end | |
| 343 | |
| 344 if firstMissing then | |
| 345 print(firstMissing:GetName(), raidbuffsFrame) | |
| 346 firstMissing:SetPoint('TOPRIGHT', raidbuffsFrame.label, 'BOTTOMRIGHT', 0, c.Spacing) | |
| 347 missingBuffsAnchor = firstMissing | |
| 348 end | |
| 349 | |
| 350 for i = numMissing +1, NUM_LE_MISSING_RAID_BUFFS do | |
| 351 missingBuffs[i]:Hide() | |
| 352 end | |
| 353 NUM_LE_MISSING_RAID_BUFFS = numMissing | |
| 354 end |
