view SkeletonUnit/UnitFrame.lua @ 0:69e828f4238a

Initial Commit
author Nenue
date Mon, 20 Jun 2016 06:35:11 -0400
parents
children cd7d06bcd98d
line wrap: on
line source
--------------------------------------------
-- KrakTool
-- Nick
-- @project - r e v i s i o n @ @project-hash@
-- @file - r e v i s i o n @ @file-hash@
-- Created: 6/16/2016 3:46 AM
--------------------------------------------

local KT = select(2,...)
local PLAYER_NAMEPLATE
local PLAYER_WIDTH = 220
local BUFF_SIZE = 24


KT.register(KTplayerFrame)
KTplayerFrame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", "player")
KTplayerFrame:RegisterUnitEvent("UNIT_POWER_FREQUENT", "player")
KTplayerFrame:RegisterUnitEvent("UNIT_AURA", 'player')
KTplayerFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
KTplayerFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
KTplayerFrame.event = function(self)
  --  print(C_NamePlate.GetNamePlateForUnit('player'))
end

local buttons = {}
local SetupButton = function(self, unit, index)
  if not buttons[index] then
    buttons[index] = CreateFrame('Frame', 'KT'..unit..'Buff'..index, self, 'KTAuraButton')
    buttons[index]:SetSize(BUFF_SIZE, BUFF_SIZE)
    buttons[index].cooldown:SetHideCountdownNumbers(true)

  end
  return buttons[index]
end

KTplayerFrame.UNIT_AURA = function(self, event, unit)
  local buffOffset = 0
  for i = 1, 16 do
    --UnitAura()
    local aura, _, texture, count, dispelType, duration, expires, caster = UnitAura(unit, i, nil, 'HELPFUL')
    if aura then
      local button = SetupButton(self, unit, i)

      button.icon:SetTexture(texture)
      button.cooldown:SetCooldown(expires - duration, duration)
      button.cooldown:Show()
      button.count:SetText(count > 0 and count or nil)
      button:SetPoint('BOTTOMLEFT', self, 'TOPLEFT', buffOffset* BUFF_SIZE, 2)
      button:Show()
      buffOffset = buffOffset + 1
    else
      if buttons[i] then
        buttons[i]:Hide()
      end
    end
  end
end

KTplayerFrame.NAME_PLATE_UNIT_ADDED = function(self, event, unit)
  print('|cFF008800'..unit)
  if UnitIsUnit('player', unit) then
    PLAYER_NAMEPLATE = unit
    self:ClearAllPoints()
    self:SetPoint('TOP', C_NamePlate.GetNamePlateForUnit(unit), 'BOTTOM', 0, 0)
  end
end
KTplayerFrame.NAME_PLATE_UNIT_REMOVED = function(self, event, unit)
  if unit == PLAYER_NAMEPLATE then
    PLAYER_NAMEPLATE = nil
    self:ClearAllPoints()
    self:SetPoint('LEFT', UIParent, 'LEFT', 25, 0)
  end
end

KTplayerFrame.UNIT_HEALTH_FREQUENT = function(self, ...)
  --print(UnitHealth('player') / UnitHealthMax('player'))
  self.healthbar:SetWidth(PLAYER_WIDTH * UnitHealth('player') / UnitHealthMax('player'))
  return true
end

KTplayerFrame.UNIT_POWER_FREQUENT = function(self)
  self.powerbar:SetWidth(PLAYER_WIDTH * UnitPower('player') / UnitPowerMax('player'))
  return true
end

KTplayerFrame:SetWidth(PLAYER_WIDTH)
KTplayerFrame.variables = function()
  KTplayerFrame:UNIT_HEALTH_FREQUENT()
  KTplayerFrame:UNIT_POWER_FREQUENT()
end