Nenue@0: -------------------------------------------- Nenue@0: -- KrakTool Nenue@0: -- Nick Nenue@0: -- @project - r e v i s i o n @ @project-hash@ Nenue@0: -- @file - r e v i s i o n @ @file-hash@ Nenue@0: -- Created: 6/16/2016 3:46 AM Nenue@0: -------------------------------------------- Nenue@0: Nenue@1: local KT = LibKT.register(SkeletonUnits) Nenue@0: local PLAYER_NAMEPLATE Nenue@0: local PLAYER_WIDTH = 220 Nenue@0: local BUFF_SIZE = 24 Nenue@1: local sk = SkeletonUnits Nenue@1: local player = KTPlayerFrame Nenue@1: local prototypes = { Nenue@1: player = {}, Nenue@1: target = {}, Nenue@1: pet = {}, Nenue@1: focus = {} Nenue@1: } Nenue@1: local units = {} Nenue@1: local buttons = {} Nenue@1: local params = { Nenue@1: player = {width = 220, height = 30}, Nenue@1: pet = {height = 25} Nenue@1: } Nenue@1: sk.handler = sk -- so sk.event can work Nenue@0: Nenue@0: Nenue@1: local UpdateUnitAnchor = function(self) Nenue@1: self.nameplate = C_NamePlate.GetNamePlateForUnit(self.unit) Nenue@1: if self.nameplate and self.nameplate.namePlateUnitToken then Nenue@1: self:ClearAllPoints() Nenue@1: self:SetPoint('TOP', self.nameplate, 'BOTTOM', 0, 0) Nenue@1: print('snapping', self.unit, 'to', self.nameplate.namePlateUnitToken) Nenue@1: else Nenue@1: self:ClearAllPoints() Nenue@1: self:SetPoint(unpack(self.anchorPoint)) Nenue@1: end Nenue@0: end Nenue@0: Nenue@0: local SetupButton = function(self, unit, index) Nenue@1: if not buttons[unit][index] then Nenue@1: buttons[unit][index] = CreateFrame('Frame', 'KT'..unit..'Buff'..index, self, 'KTAuraButton') Nenue@1: buttons[unit][index]:SetSize(BUFF_SIZE, BUFF_SIZE) Nenue@1: buttons[unit][index].cooldown:SetHideCountdownNumbers(true) Nenue@0: Nenue@0: end Nenue@1: return buttons[unit][index] Nenue@0: end Nenue@0: Nenue@1: sk.init = function() Nenue@1: for unit, handler in pairs(prototypes) do Nenue@1: if not _G['KT'..unit..'Frame'] then Nenue@1: CreateFrame('Frame', 'KT'.. unit .. 'Frame', sk) Nenue@1: end Nenue@1: local frame = _G['KT'..unit..'Frame'] Nenue@1: frame.unit = unit Nenue@1: frame.anchorPoint = {frame:GetPoint(1)} Nenue@1: frame.handler = handler Nenue@1: if handler.init then Nenue@1: handler.init(frame, unit) Nenue@1: end Nenue@1: buttons[unit] = {} Nenue@1: units[unit] = frame Nenue@1: end Nenue@1: Nenue@1: sk:RegisterEvent('PLAYER_TARGET_CHANGED') Nenue@1: sk:RegisterUnitEvent("UNIT_AURA") Nenue@1: end Nenue@1: sk.variables = function() Nenue@1: for unit, frame in pairs(units) do Nenue@1: if frame.handler.variables then Nenue@1: frame.handler.variables(frame, unit) Nenue@1: end Nenue@1: local width = params.player.width Nenue@1: local height = params.player.height Nenue@1: if params[unit] then Nenue@1: if params[unit].width then Nenue@1: width = params[unit].width Nenue@1: end Nenue@1: if params[unit].height then Nenue@1: height = params[unit].height Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: frame:SetWidth(width) Nenue@1: frame:SetHeight(height) Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: sk.event = function(self, event, ...) Nenue@1: if self.handler[event] then Nenue@1: self.handler[event](self, event, ...) Nenue@1: end Nenue@1: end Nenue@1: Nenue@1: sk.PLAYER_TARGET_CHANGED = function() Nenue@1: prototypes.player.refresh(units.target) Nenue@1: end Nenue@1: Nenue@1: prototypes.player.init = function(self) Nenue@1: self:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", self.unit) Nenue@1: self:RegisterUnitEvent("UNIT_POWER_FREQUENT", self.unit) Nenue@1: self:RegisterEvent("NAME_PLATE_UNIT_ADDED") Nenue@1: self:RegisterEvent("NAME_PLATE_UNIT_REMOVED") Nenue@1: self:RegisterEvent("UNIT_TARGET") Nenue@1: self:SetScript('OnEvent', sk.event) Nenue@1: end Nenue@1: Nenue@1: --- Runs once Nenue@1: prototypes.player.variables = function(self) Nenue@1: self.handler.refresh(self) Nenue@1: end Nenue@1: Nenue@1: --- Runs when event handler decides so Nenue@1: prototypes.player.refresh = function(self) Nenue@1: if not UnitExists(self.unit) then Nenue@1: self:Hide() Nenue@1: return Nenue@1: end Nenue@1: Nenue@1: local class, classFile = UnitClass(self.unit) Nenue@1: if classFile then Nenue@1: self.healthbar:SetColorTexture(RAID_CLASS_COLORS[classFile].r, RAID_CLASS_COLORS[classFile].g, RAID_CLASS_COLORS[classFile].b) Nenue@1: end Nenue@1: Nenue@1: self.handler.UNIT_HEALTH_FREQUENT(self) Nenue@1: self.handler.UNIT_POWER_FREQUENT(self) Nenue@1: end Nenue@1: Nenue@1: sk.UNIT_AURA = function(self, event, unit) Nenue@1: if not units[unit] then return end Nenue@1: Nenue@0: local buffOffset = 0 Nenue@1: local buttons = buttons[unit] Nenue@0: for i = 1, 16 do Nenue@1: Nenue@1: local aura, _, texture, count, dispelType, duration, expires, caster = UnitAura(unit, i, 'HARMFUL') Nenue@0: if aura then Nenue@1: local button = SetupButton(units[unit], unit, i) Nenue@0: Nenue@0: button.icon:SetTexture(texture) Nenue@0: button.cooldown:SetCooldown(expires - duration, duration) Nenue@0: button.cooldown:Show() Nenue@0: button.count:SetText(count > 0 and count or nil) Nenue@1: button:SetPoint('BOTTOMLEFT', units[unit], 'TOPLEFT', buffOffset* BUFF_SIZE, 2) Nenue@0: button:Show() Nenue@0: buffOffset = buffOffset + 1 Nenue@0: else Nenue@0: if buttons[i] then Nenue@0: buttons[i]:Hide() Nenue@0: end Nenue@0: end Nenue@0: end Nenue@0: end Nenue@0: Nenue@1: prototypes.player.NAME_PLATE_UNIT_ADDED = function(self, event, nameplate) Nenue@1: UpdateUnitAnchor(self) Nenue@1: end Nenue@1: prototypes.player.NAME_PLATE_UNIT_REMOVED = function(self, event, nameplate) Nenue@1: UpdateUnitAnchor(self) Nenue@1: end Nenue@1: Nenue@1: prototypes.player.UNIT_HEALTH_FREQUENT = function(self, ...) Nenue@1: if UnitHealthMax(self.unit) > 0 then Nenue@1: self.healthbar:SetWidth(PLAYER_WIDTH * UnitHealth(self.unit) / UnitHealthMax(self.unit)) Nenue@1: self.healthtext:SetText(UnitHealth(self.unit)) Nenue@1: else Nenue@1: self.healthbar:SetWidth(PLAYER_WIDTH) Nenue@1: self.healthtext:SetText(nil) Nenue@0: end Nenue@1: return true Nenue@0: end Nenue@1: Nenue@1: prototypes.player.UNIT_POWER_FREQUENT = function(self) Nenue@1: if UnitPowerMax(self.unit) > 0 then Nenue@1: self.powerbar:SetWidth(PLAYER_WIDTH * UnitPower(self.unit) / UnitPowerMax(self.unit)) Nenue@1: self.powertext:SetText(UnitPower(self.unit)) Nenue@1: else Nenue@1: self.powerbar:Hide() Nenue@1: self.powertext:SetText(nil) Nenue@1: end Nenue@1: return true Nenue@1: end Nenue@1: Nenue@1: Nenue@1: prototypes.player.UNIT_TARGET = function(self, ...) Nenue@1: if not UnitExists(self.unit) then Nenue@1: self:Hide() Nenue@1: else Nenue@1: self:Show() Nenue@1: self.handler.refresh(self) Nenue@1: UpdateUnitAnchor(self) Nenue@0: end Nenue@0: end Nenue@0: Nenue@1: prototypes.pet = prototypes.player Nenue@1: prototypes.target = prototypes.player