view Turok/Modules/Utilities/Raid.lua @ 6:a9b8b0866ece

clear out log jam
author Nenue
date Sun, 21 Feb 2016 08:32:53 -0500
parents
children
line wrap: on
line source
--- Turok Raid/Raid.lua
-- @file-author@
-- @project-revision@ @project-hash@
-- @file-revision@ @file-hash@
--- Defines the interfaces for raid tools
local T = Turok
local mod = T:NewModule('RaidReady')
mod.OnInitialize = function(self)
  self.db = TurokData.Lost
  self.events = {
    PARTY_MEMBERS_CHANGED = self.MembersChangedEvent,
    PLAYER_SPECIALIZATION_CHANGED = self.SpecChangeEvent,
    ENCOUNTER_START = self.EncounterStart,
    UNIT_AURA = self.UnitAura
  }
end

T.defaults.Lost = {
  parent = 'UIParent',
  anchor = 'BOTTOMRIGHT', anchorTo = 'BOTTOMRIGHT',
  x = -300, y = 300,
  height = 24*9, width = 72,
  width = 72,
  height = 24,
  size = 11,
  font = "Interface\\Addons\\Turok\\Media\\font\\ArchivoNarrow-Bold.ttf",

  raidbuff = {
    icon = {},
    status = {},
  },

  durability = {

  },

  toast = {

  },
}
local _G = _G
local print = function(...) if Devian and DevianDB.workspace~= 1 then print('RaidInfo', ...) end end
local CreateFrame, floor, GetRaidBuffTrayAuraInfo, NUM_LE_RAID_BUFF_TYPES = CreateFrame, math.floor, GetRaidBuffTrayAuraInfo, NUM_LE_RAID_BUFF_TYPES
local GetSpecialization, GetSpecializationInfo, GetSpecializationInfoByID = GetSpecialization, GetSpecializationInfo, GetSpecializationInfoByID
local IsInRaid, IsInGroup, GetInspectSpecialization = IsInRaid, IsInGroup, GetInspectSpecialization
local find, match, sub = string.find, string.match, string.sub
local GetRealmName, GetRaidRosterInfo, UnitGUID = GetRealmName, GetRaidRosterInfo, UnitGUID
local db

function mod:OnEnable()
  db = self.db

  self.raidbuffs = {} -- active raid buffs
  self.buffinfo = {}   -- raid buff text
  self.available = {}  -- availability info
  self.units_raid = {}

  self.raidbuffs_tray = _G.TurokRaidbuffsTray

  -- seed raid buff analyzer assets
  self.num_raidbuff_columns = floor(db.raidbuff.width / db.raidbuff.icon.width)
  for i = 1, 9 do
    --print('TurokRaidbuffButton'..i, self.raidbuffs_tray, 'TurokRaidbuffButton')
    local buff = CreateFrame('Button', 'TurokRaidbuffButton'..i, self.raidbuffs_tray, 'TurokRaidbuffButton')

    -- T.SetFrameLayout(buff, db.raidbuff)
  end

  db.raidevent = {}




end

function mod:PLAYER_SPECIALIZATION_CHANGED(e, unit)
  local specID
  --print(e, unit)
  if unit == 'player' then
    specID = GetSpecializationInfo(GetSpecialization())
  else
    --NotifyInspect(unit)
    specID = GetInspectSpecialization()
  end
  if specID then
    --print(GetSpecializationInfoByID(specID))
  end
end

function mod:PARTY_MEMBERS_CHANGED(e, ...)
  if IsInRaid() or IsInGroup() then
    self.raidbuffs_frame:Show()
    self:RaidBuffScan()
  else
  end
end

function mod:ENCOUNTER_START(e,...)
  --print(e,...)
end

-- Updates available raid/party buffs
function mod:RaidbuffsUpdate(unit)
  if not (IsInGroup() or IsInRaid()) then
    self.raidbuffs_tray:Hide()
    return
  end

  local c = db.raidbuff
  local k = 0
  for i = 1, NUM_LE_RAID_BUFF_TYPES do

    local rb = self.raidbuffs[i]
    local buff = {GetRaidBuffTrayAuraInfo(i) }
    --name, rank, texture, duration, expiration, spellId, slot
    local isShown = false
    if buff[1] then
      isShown = true
      self.raidbuffs[i] = buff
    else
      self.raidbuffs[i] = nil
    end

    if isShown then
        rb:Show()
        rb.bufftype:SetText(sub(_G['RAID_BUFF_'..i],0,2))
        rb.spellname:SetText(self.buffinfo[i])

        local pn = k                                     -- need (n-1) for lua grid math
        local py = floor(pn / self.num_raidbuff_columns) * c.height
        local px = (pn * c.width) % db.width      -- x-offset
        --print('buff slot '..i..' (draw position '..k..')', pn, py, px)
        rb:SetPoint(c.anchor, self.raidbuffs_tray, c.anchor, px, py)

        k = k + 1
      end
  end
  if k == 0 and self.raidbuffs_tray:IsVisible() then
    self.raidbuffs_tray:Hide()
  elseif not self.raidbuffs_tray:IsVisible() then
    self.raidbuffs_tray:Show()
  end
end

function mod:RosterScan()
  local lim = 1
  if IsInRaid() then
    lim = 40
  elseif IsInGroup() then
    lim = 5
  end
end