Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _,ns = ...
- EHVitals = ns
- ns.config = {}
- ns.backdrop = {}
- local EventsToRegister = {}
- local ModuleEventsToRegister = {}
- local class = select(2,UnitClass('player'))
- local frame = CreateFrame('Frame','EventHorizon_VitalsFrame',UIParent)
- local slave = CreateFrame('Frame',nil,frame)
- local left = frame:CreateFontString(nil,'OVERLAY')
- local center = frame:CreateFontString(nil,'OVERLAY')
- local right = {}
- local rune = {}
- local centerexclusive, rightexclusive
- local function printhelp(...)
- if select('#',...)>0 then
- return tostring((...)), printhelp(select(2,...))
- end
- end
- local function print(...)
- ChatFrame1:AddMessage('EventHorizon_Vitals: '..strjoin(',',printhelp(...)))
- end
- local time = GetTime()
- local TTL, tTTL, hTTL = 0.05, 0.10, 1
- local TSLU, tTSLU, hTSLU = 0, 0, 0
- local powerunit
- local runeCD
- local rounding = 60000
- ns.powerTypePrimary = {
- DEATHKNIGHT = 6,
- HUNTER = 2,
- ROGUE = 3,
- WARRIOR = 1,
- }
- ns.powerTypeSecondary = {
- DRUID = 'COMBO_POINTS',
- PALADIN = 'HOLY_POWER',
- WARLOCK = 'SOUL_SHARDS',
- ROGUE = "COMBO_POINTS"
- }
- ns.secondaryPowerTypes = {
- SOUL_SHARDS = 7,
- -- ECLIPSE = 8,
- HOLY_POWER = 9,
- }
- ns.auras = {
- PRIEST = {
- armor = {588,73413},
- orb = 77487,
- fort = {21562,469,90364},
- ve = 15286,
- },
- SHAMAN = {
- shield = {52127,974,324},
- },
- WARRIOR = {
- battle = {19740,6673},
- commanding = {21562,469,90364},
- },
- DRUID = {
- solar = 48517,
- lunar = 48518,
- },
- }
- for i=1,6 do
- rune[i] = CreateFrame('Frame',nil,frame)
- rune[i].TTL = tTTL
- rune[i].TSLU = 0
- rune[i].id = i
- rune[i].text = frame:CreateFontString(nil,'OVERLAY')
- if i <= 3 then
- right[i] = frame:CreateFontString(nil,'OVERLAY')
- end
- end
- local function EventHandler(self, event, ...)
- local f = self[event]
- if f then
- f(self,...)
- end
- end
- local function Clone(t)
- local new = {}
- local i, v = next(t, nil) -- i is an index of t, v = t[i]
- while i do
- new[i] = v
- i, v = next(t, i)
- end
- return new
- end
- local function Round(num,idp)
- if idp and idp>0 then
- local mult = 10^idp
- return math.floor(num * mult + 0.5) / mult
- end
- return math.floor(num + 0.5)
- end
- local UpdateCP = function (self)
- if centerexclusive and powerunit == 'player' then return end
- local c = UnitPower(powerunit, 4)
- if (c > 0) then
- center:SetText(c)
- center:SetVertexColor(unpack(ns.color["combo"..c]))
- else
- center:SetText("")
- center:SetVertexColor(unpack(ns.color["combo"..c]))
- end
- end
- local SpawnStyleFrame = function ()
- local sf = CreateFrame('Frame','EventHorizon_VitalsBG',EventHorizon_VitalsFrame)
- sf:SetFrameStrata('BACKGROUND')
- local eh = EventHorizon.config
- if eh.backdrop == true then
- sf:SetPoint('TOPRIGHT', EventHorizon_VitalsFrame, 'TOPRIGHT', eh.padding, eh.padding)
- sf:SetPoint('BOTTOMLEFT', EventHorizon_VitalsFrame, 'BOTTOMLEFT', -eh.padding, -eh.padding)
- sf:SetBackdrop({
- bgFile = eh.bg,
- edgeFile = eh.border, tileSize = 0, edgeSize = eh.edgesize,
- insets = eh.inset,
- })
- sf:SetBackdropColor(unpack(EventHorizon.colors.bgcolor))
- sf:SetBackdropBorderColor(unpack(EventHorizon.colors.bordercolor))
- else return end
- end
- local ApplyFonts = function (fs,j,flag) -- Ex: ApplyFonts(fontstring1,"LEFT")
- if flag == 'rune' then
- fs:SetFont(ns.config.runeFont,ns.config.fontSizeRune)
- elseif flag == 'right' then
- fs:SetFont(ns.config.font,ns.config.fontSizeRight)
- elseif flag == 'center' then
- fs:SetFont(ns.config.font,ns.config.fontSizeCenter)
- else
- fs:SetFont(ns.config.font,ns.config.fontSizeLeft)
- end
- fs:SetJustifyH(j)
- fs:SetHeight(ns.config.height)
- local sfs = ns.config.FontShadow and (type(ns.config.FontShadow) == 'table' and ns.config.FontShadow or {0,0,0,0.5}) or nil
- local sfso = (ns.config.FontShadowOffset and type(ns.config.FontShadowOffset) == 'table') and ns.config.FontShadowOffset or {1,-1}
- if sfs then
- fs:SetShadowColor(unpack(sfs))
- fs:SetShadowOffset(unpack(sfso))
- end
- fs:Show()
- end
- local ApplyConfig = function ()
- end
- local CheckPower = function ()
- powerunit = (UnitPower('vehicle') > 0 and UnitHasVehicleUI('player')) and 'vehicle' or 'player'
- local c = {}
- local p = UnitPower(powerunit)
- local pm = UnitPowerMax(powerunit)
- local pt, pts = UnitPowerType(powerunit)
- if ns.color.useClassColor and type(ns.color.useClassColor) == "table" then
- c = {r = ns.color.useClassColor[1], g = ns.color.useClassColor[2], b = ns.color.useClassColor[3]}
- elseif ns.color.useClassColor and (powerunit == 'player' and ((ns.powerTypePrimary[class] and pt == ns.powerTypePrimary[class]) or pt == 0)) then
- c = {r = ns.classcolor[1], g = ns.classcolor[2], b = ns.classcolor[3]}
- elseif PowerBarColor[pt] then
- c = PowerBarColor[pt]
- else
- c = {r = 1, g = 1, b = 1}
- end
- if p and pt then
- left:SetVertexColor(c.r,c.g,c.b)
- else
- left:SetVertexColor(1,1,1)
- end
- if ns.powerTypeSecondary[class] then
- frame:UNIT_POWER('player',ns.secondaryPowerTypes[ns.powerTypeSecondary[class]])
- end
- UpdateCP()
- end
- local OnUpdate_Enchant = function (self,elapsed)
- self.TSLU = self.TSLU + elapsed
- while (self.TSLU >= self.TTL) do
- local mh,mhEx,_,oh,ohEx,_ = GetWeaponEnchantInfo()
- --print(mh,mhEx,oh,ohEx)
- if mh then
- --print(r)
- local mt = Round(mhEx/rounding)
- right[3]:SetText(mt)
- if mt <= 5 then
- right[3]:SetVertexColor(unpack(ns.color.enchantExpiring))
- else
- right[3]:SetVertexColor(unpack(ns.color.useClassColor and ns.color.enchantFresh or ns.color.default))
- end
- else
- right[3]:SetText('')
- end
- if oh then
- local ot = Round(ohEx/rounding)
- right[1]:SetText(ot)
- if ot <= 5 then
- right[1]:SetVertexColor(unpack(ns.color.enchantExpiring))
- else
- right[1]:SetVertexColor(unpack(ns.color.useClassColor and ns.color.enchantFresh or ns.color.default))
- end
- else
- right[1]:SetText('')
- end
- self.TSLU = self.TSLU - self.TTL
- end
- end
- local OnUpdate_Rune = function (self,elapsed)
- self.TSLU = self.TSLU + elapsed
- -- Highly throttled updates for DK runes
- while (self.TSLU >= self.TTL) do
- local start,duration,ready = GetRuneCooldown(self.id)
- if (ready == true) then
- self.text:SetText(ns.config.runeReady)
- self.text:SetAlpha(1)
- self.TSLU = 0
- self:SetScript("OnUpdate",nil)
- return
- else
- local cd = Round(start + duration - GetTime())
- if cd < 0 then
- cd = 0
- end
- --[[if cd >= 10 then
- self.text:SetText(ns.config.runeReady)
- self.text:SetAlpha(1)
- self.TSLU = 0
- self:SetScript("OnUpdate",nil)
- return
- end]]-- Why is this here???
- self.text:SetText((cd <= runeCD) and cd or ns.config.runeCooling)
- self.text:SetAlpha(math.min(1, 1-(cd*ns.config.runeAlphaStep)))
- --print(1-(cd*ns.config.runeAlphaStep))
- end
- self.TSLU = self.TSLU - self.TTL
- end
- end
- local OnUpdate_Power = function (self,elapsed)
- self.TSLU = self.TSLU + elapsed
- while (self.TSLU >= self.TTL) do
- local p = UnitPower(powerunit)
- local pm = UnitPowerMax(powerunit)
- local pt, pts = UnitPowerType(powerunit)
- if PowerBarColor[pt] or PowerBarColor[pts] then
- left:SetText(p)
- else
- left:SetText("")
- end
- if p == 0 and ((pt == 1) or (pt == 6)) then
- left:SetAlpha(ns.color.fade)
- elseif p == pm then
- left:SetAlpha(ns.color.fade)
- else
- left:SetAlpha(ns.color.normal)
- end
- self.TSLU = self.TSLU - TTL
- end
- end
- local UpdateRune = function (self,runeid,usable)
- if runeid ~= self.id then return end
- local start,duration,ready = GetRuneCooldown(runeid)
- local rC = ns.config.runeCooldown or 0
- --print(runeid,usable)
- if ready == true then
- self.text:SetText(ns.config.runeReady)
- else
- self.TSLU = 0
- self:SetScript('OnUpdate',OnUpdate_Rune)
- local cd = start + duration - GetTime()
- cd = Round(cd)
- if ((rC > 0) and (cd <= rC)) then
- self.text:SetText(cd)
- else
- self.text:SetText(ns.config.runeCooling)
- end
- end
- end
- local UpdateRuneType = function (self,runeid)
- if runeid ~= self.id then return end
- local rt = GetRuneType(runeid)
- self.text:SetVertexColor(unpack(ns.color["rune"..rt]))
- UpdateRune(self,runeid)
- end
- local UpdateSecondaryPower = function (self,unit,powertype)
- if unit ~= 'player' then return end
- if ((class == "ROGUE") or (class == "DRUID")) then
- UpdateCP()
- return
- end
- local cpt
- if powertype then
- cpt = powertype and (powertype == ns.powerTypeSecondary[class]) and ns.secondaryPowerTypes[powertype]
- else
- cpt = ns.secondaryPowerTypes[ns.powerTypeSecondary[class]]
- end
- local p = UnitPower('player',ns.secondaryPowerTypes[ns.powerTypeSecondary[class]])
- center:SetText(p)
- center:SetVertexColor(unpack(ns.color.useClassColor and ns.color.enchantFresh or ns.color.default))
- end
- local Init = function ()
- local cc = ns.config
- local eh = EventHorizon.config
- local offset = cc.offset
- local classcolors = CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS
- local classcolor = Clone(classcolors[select(2,UnitClass('player'))])
- ns.classcolor = {classcolor.r,classcolor.g,classcolor.b}
- for colorid,color in pairs(ns.color) do
- if type(color) == 'table' and color[1] == true then
- if color[2] then
- ns.color[colorid] = {classcolor.r * color[2], classcolor.g * color[2], classcolor.b * color[2], color[3] or 1}
- else
- ns.color[colorid] = {classcolor.r, classcolor.g, classcolor.b, 1}
- end
- end
- end
- frame:SetHeight(cc.height)
- if type(cc.position) == 'table' then
- frame:SetPoint(unpack(cc.position))
- elseif cc.position == 'bottom' then
- frame:SetPoint("TOPLEFT", EventHorizon.mainframe, "BOTTOMLEFT", 0, -offset)
- frame:SetPoint("TOPRIGHT", EventHorizon.mainframe, "BOTTOMRIGHT", 0, -offset)
- else
- frame:SetPoint("BOTTOMLEFT", EventHorizon.mainframe, "TOPLEFT", 0, offset)
- frame:SetPoint("BOTTOMRIGHT", EventHorizon.mainframe, "TOPRIGHT", 0, offset)
- end
- ApplyFonts(left,"LEFT")
- ApplyFonts(center,"LEFT",'center')
- ApplyFonts(right[1],'RIGHT','right')
- ApplyFonts(right[2],'RIGHT','right')
- ApplyFonts(right[3],'RIGHT','right')
- for i=1,6 do
- ApplyFonts(rune[i].text,"LEFT",'rune')
- end
- local toffx = cc.textOffset[1]
- local toffy = cc.textOffset[2]
- left:SetPoint("LEFT", EventHorizon_VitalsFrame, "LEFT", toffx, toffy)
- center:SetPoint("CENTER", EventHorizon_VitalsFrame, "CENTER", 0, toffy)
- right[1]:SetPoint("RIGHT",frame,"RIGHT",-toffx,toffy)
- right[2]:SetPoint("RIGHT",right[1],"LEFT",-toffx,0)
- right[3]:SetPoint("RIGHT",right[2],"LEFT",-toffx,0)
- if class == "DEATHKNIGHT" then
- runeCD = cc.runeCooldown
- for i=1,6 do
- if i == 1 then
- rune[6].text:SetPoint("RIGHT", EventHorizon_VitalsFrame, "RIGHT", -toffx, cc.runeOffset + toffy)
- else
- rune[7-i].text:SetPoint("RIGHT", rune[8-i].text, "LEFT", -cc.runeSpacing, 0)
- end
- rune[i]:SetScript("OnEvent",EventHandler)
- UpdateRuneType(rune[i],i)
- end
- else
- for i=1,6 do
- rune[i].text:Hide()
- end
- end
- SpawnStyleFrame()
- CheckPower()
- frame:Show()
- frame:SetScript("OnUpdate", OnUpdate_Power)
- frame:SetScript("OnEvent", EventHandler)
- for k,v in pairs(EventsToRegister) do
- frame:RegisterEvent(k)
- end
- if ModuleEventsToRegister['UNIT_AURA'] then
- for k,v in pairs(ns.auras[class]) do
- if type(v) == 'table' then
- for i,aura in pairs(v) do
- local spellname = GetSpellInfo(aura)
- ns.auras[class][k][i] = spellname
- end
- else
- local spellname = GetSpellInfo(v)
- ns.auras[class][k] = {spellname}
- end
- -- print(ns.auras[class][k])
- end
- end
- if EventsToRegister['UNIT_POWER'] then frame:UNIT_POWER('player',ns.secondaryPowerTypes[ns.powerTypeSecondary[class]]) end
- if EventsToRegister['UNIT_INVENTORY_CHANGED'] then frame:UNIT_INVENTORY_CHANGED('player') end
- ns.isReady = true
- end
- local UpdateInventory = function (self,u)
- if u ~= 'player' then return end
- local mh,mhEx,_,oh,ohEx,_ = GetWeaponEnchantInfo()
- if (mh and mhEx) or (oh and ohEx) then
- slave.TTL = hTTL
- slave.TSLU = 0
- slave:SetScript('OnUpdate',OnUpdate_Enchant)
- else
- slave:SetScript('OnUpdate',nil)
- end
- if not mh then
- right[3]:SetText('')
- end
- if not oh then
- right[1]:SetText('')
- end
- end
- local GetAuraInfo = function (auras)
- local name, text, icon, count, dispelType, duration, expires, caster
- for i,aura in pairs(auras) do
- name, text, icon, count, dispelType, duration, expires, caster = UnitBuff('player',aura)
- if name then
- return name, text, icon, count, dispelType, duration, expires, caster
- end
- end
- end
- local UnitAuraCS = {
- ["PRIEST"] = function (self,u)
- if u ~= 'player' then return end
- centerexclusive = true
- local lvl = EventHorizon.vars.currentLevel
- local armor = GetAuraInfo(ns.auras[class].armor)
- local ve = GetAuraInfo(ns.auras[class].ve) or (EventHorizon.vars.activeTree ~= 3) or lvl < 39
- if armor then
- right[1]:SetText('')
- else
- right[1]:SetText('IF')
- right[1]:SetVertexColor(unpack(ns.color.enchantExpiring))
- end
- if ve then
- right[3]:SetText('')
- else
- right[3]:SetText('VE')
- right[3]:SetVertexColor(unpack(ns.color.enchantExpiring))
- end
- end,
- ["WARRIOR"] = function (self,u)
- if u ~= 'player' then return end
- right[1]:SetVertexColor(unpack(ns.color.enchantExpiring))
- local _,_,_,_,_,_,_,hp = GetAuraInfo(ns.auras[class].commanding)
- local _,_,_,_,_,_,_,ap = GetAuraInfo(ns.auras[class].battle)
- local lvl = EventHorizon.vars.currentLevel
- local mine = (hp == 'player') or (ap == 'player')
- local txt
- if mine or (hp and ap) then
- txt = ''
- else
- txt = (lvl >= 20 and hp and 'BS') or (lvl >= 68 and ap and 'CS') or lvl >= 20 and 'shout'
- end
- --print(hp,ap,mine)
- right[1]:SetText(txt)
- end,
- ["SHAMAN"] = function (self,u)
- if u ~= 'player' then return end
- local shielded
- centerexclusive = true
- local _,_,_,count,_,_,_,source = GetAuraInfo(ns.auras[class].shield)
- if source == 'player' and count > 0 then
- center:SetText(count)
- else
- center:SetText('shield')
- end
- if not(count) or count == 1 then
- center:SetVertexColor(unpack(ns.color.enchantExpiring))
- else
- center:SetVertexColor(unpack(ns.color.useClassColor and ns.color.enchantFresh or ns.color.default))
- end
- end,
- }
- EventsToRegister['UNIT_ENTERED_VEHICLE'] = true
- EventsToRegister['UNIT_EXITED_VEHICLE'] = true
- EventsToRegister['UPDATE_SHAPESHIFT_FORM'] = true
- frame.UPDATE_SHAPESHIFT_FORM = CheckPower
- frame.TSLU = 0
- frame.TTL = TTL
- if UnitAuraCS[class] then
- ModuleEventsToRegister['UNIT_AURA'] = true
- ns.UNIT_AURA = UnitAuraCS[class]
- ns.CheckTalents = function ()
- --print('CheckTalents')
- return EventHorizon.mainframe:UNIT_AURA('player') end
- end
- function frame:UNIT_ENTERED_VEHICLE(unit)
- if unit ~= 'player' then return end
- return CheckPower()
- end
- function frame:UNIT_EXITED_VEHICLE(unit)
- if unit ~= 'player' then return end
- return CheckPower()
- end
- if class == "DEATHKNIGHT" then
- for i=1,6 do
- rune[i]:RegisterEvent('RUNE_POWER_UPDATE')
- rune[i]:RegisterEvent('RUNE_TYPE_UPDATE')
- rune[i].RUNE_POWER_UPDATE = UpdateRune
- rune[i].RUNE_TYPE_UPDATE = UpdateRuneType
- end
- end
- if (class == "WARLOCK" or class == "ROGUE" or class == "SHAMAN") then
- EventsToRegister['UNIT_INVENTORY_CHANGED'] = true
- frame.UNIT_INVENTORY_CHANGED = UpdateInventory
- end
- if ns.powerTypeSecondary[class] then
- EventsToRegister['UNIT_POWER'] = true
- frame.UNIT_POWER = UpdateSecondaryPower
- end
- local Enable = function (slash)
- if slash and ns.config.slashDisable ~= true then return end
- CheckPower() -- Get everything set up properly before reenabling everything.
- frame:Show()
- frame:SetScript("OnEvent", EventHandler)
- frame:SetScript("OnUpdate", OnUpdate_Power)
- if ModuleEventsToRegister['UNIT_AURA'] then EventHorizon.mainframe:UNIT_AURA('player') end
- if EventsToRegister['UNIT_POWER'] then frame:UNIT_POWER('player',ns.secondaryPowerTypes[ns.powerTypeSecondary[class]]) end
- if EventsToRegister['UNIT_INVENTORY_CHANGED'] then frame:UNIT_INVENTORY_CHANGED('player') end
- if class == "DEATHKNIGHT" then
- for i=1,6 do
- rune[i]:SetScript("OnEvent",EventHandler)
- UpdateRuneType(rune[i],i)
- end
- end
- ns.isActive = true
- end
- local Disable = function (slash)
- if slash and ns.config.slashDisable ~= true then return end
- frame:Hide()
- frame:SetScript('OnEvent',nil)
- frame:SetScript('OnUpdate',nil)
- if EventsToRegister['UNIT_INVENTORY_CHANGED'] then slave:SetScript('OnUpdate',nil) end
- if class == "DEATHKNIGHT" then
- for i=1,6 do
- rune[i]:SetScript('OnEvent',nil)
- rune[i]:SetScript('OnUpdate',nil)
- end
- end
- ns.isActive = false
- end
- ns.Init = Init
- ns.Enable = Enable
- ns.Disable = Disable
- EventHorizon:RegisterModule('vitals',ns)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement