diff --git a/.luacheckrc b/.luacheckrc index 4c98522..c02a02f 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -239,6 +239,7 @@ globals = { "UnitChannelInfo", "GetRaidRosterInfo", "CreateFramePool", + "PowerBarColor", -- Wrath dual spec "GetActiveTalentGroup", diff --git a/Aptechka.lua b/Aptechka.lua index 963b376..a3569bf 100644 --- a/Aptechka.lua +++ b/Aptechka.lua @@ -921,7 +921,7 @@ function Aptechka.FrameUpdateUnitColor(frame, unit) Aptechka.FrameColorize(frame, unit) FrameSetJob(frame, config.UnitNameStatus, true, nil, makeUnique()) FrameSetJob(frame, config.HealthBarColor, true, nil, makeUnique()) - if not frame.power.disabled then FrameSetJob(frame, config.PowerBarColor, true, nil, makeUnique()) end + if not frame.power.disabled then FrameSetJob(frame, config.PowerBarColor, true, "POWERCOLOR", frame.state.powerType, makeUnique()) end end function Aptechka:RefreshAllUnitsColors() Aptechka:ForEachFrame(Aptechka.FrameUpdateName) @@ -1427,31 +1427,51 @@ function Aptechka.UNIT_CONNECTION(self, event, unit) Aptechka:ForEachUnitFrame(unit, Aptechka.FrameUpdateConnection) end -local Enum_RunicPower = Enum.PowerType.RunicPower -local Enum_Alternate = Enum.PowerType.Alternate -function Aptechka.FrameUpdatePower(frame, unit, ptype) - if ptype == "MANA" then-- not frame.power.disabled then - local powerMax = UnitPowerMax(unit, 0) - local power = UnitPower(unit, 0) +local function MakePowerHandlerForType(powerTypeIndex) + return function(frame, unit, ptype) + local powerMax = UnitPowerMax(unit, powerTypeIndex) + local power = UnitPower(unit, powerTypeIndex) if powerMax == 0 then power = 1 powerMax = 1 end local manaPercent = GetForegroundSeparation(power, powerMax, fgShowMissing) frame.power:SetValue(manaPercent*100) - elseif ptype == "RUNIC_POWER" then - if not Aptechka:UnitIsTank(unit) then - return FrameSetJob(frame, config.RunicPowerStatus, false) + end +end +local function MakeForcedPowerHandlerForType(powerTypeIndex) + return function(frame, unit, ptype) + local powerMax = UnitPowerMax(unit, powerTypeIndex) + local power = UnitPower(unit, powerTypeIndex) + if powerMax == 0 then + power = 1 + powerMax = 1 end + local manaPercent = GetForegroundSeparation(power, powerMax, false) + frame.power:SetValue(manaPercent*100) + end +end + + + +local Enum_RunicPower = Enum.PowerType.RunicPower +local Enum_Alternate = Enum.PowerType.Alternate + +local SpecialPowerTypeHandlers = { + RUNIC_POWER = function(frame, unit, ptype) local powerMax = UnitPowerMax(unit, Enum_RunicPower) local power = UnitPower(unit, Enum_RunicPower) + if not Aptechka:UnitIsTank(unit) then + return FrameSetJob(frame, config.RunicPowerStatus, false) + end if power > 40 then local p = power/powerMax FrameSetJob(frame, config.RunicPowerStatus, true, "PROGRESS", power, powerMax, p) else FrameSetJob(frame, config.RunicPowerStatus, false) end - elseif ptype == "ALTERNATE" then + end, + ALTERNATE = function(frame, unit, ptype) local powerMax = UnitPowerMax(unit, Enum_Alternate) local power = UnitPower(unit, Enum_Alternate) if power > 0 then @@ -1460,6 +1480,25 @@ function Aptechka.FrameUpdatePower(frame, unit, ptype) else FrameSetJob(frame, config.AltPowerStatus, false) end + end, +} +local PowerTypeHandlers = { + MANA = MakePowerHandlerForType(Enum.PowerType.Mana), + RAGE = MakeForcedPowerHandlerForType(Enum.PowerType.Rage), + FOCUS = MakePowerHandlerForType(Enum.PowerType.Focus), + ENERGY = MakePowerHandlerForType(Enum.PowerType.Energy), + RUNIC_POWER = MakeForcedPowerHandlerForType(Enum.PowerType.RunicPower), + FURY = MakeForcedPowerHandlerForType(Enum.PowerType.Fury), + PAIN = MakeForcedPowerHandlerForType(Enum.PowerType.Fury), -- Pain was merged with Fury in DF +} + +function Aptechka.FrameUpdatePower(frame, unit, ptype) + local special = SpecialPowerTypeHandlers[ptype] + if special then special(frame, unit, ptype) end + + if ptype == frame.state.powerType then + local handler = PowerTypeHandlers[ptype] + if handler then handler(frame, unit, ptype) end end end function Aptechka.UNIT_POWER_UPDATE(self, event, unit, ptype) @@ -1477,26 +1516,36 @@ do } local showHybridMana = false function Aptechka.FrameUpdateDisplayPower(frame, unit) - if frame.power and frame.power.OnPowerTypeChange then - local tnum, tname = UnitPowerType(unit) - local _, unitClass = UnitClass(unit) - if showHybridMana and healerClasses[unitClass] then - tnum, tname = 0, "MANA" - end - if isMainline and not healerClasses[unitClass] then - tnum, tname = 4, "HAPPINESS" - end - frame.power:OnPowerTypeChange(tname) + local pindex, pname = UnitPowerType(unit) + local _, unitClass = UnitClass(unit) + if showHybridMana and healerClasses[unitClass] then + pindex, pname = 0, "MANA" end - FrameSetJob(frame, config.PowerBarColor,true, nil, makeUnique()) + + local showPowerTypesTank = Aptechka.db.profile.showPowerTypesTank + local showPowerTypesDamage = Aptechka.db.profile.showPowerTypesDamage + + local showPowerBar = config.allowedPowerTypes[pname] + if showPowerTypesTank then + showPowerBar = showPowerBar or config.allowedPowerTypesTank[pname] + end + if showPowerTypesDamage then + showPowerBar = showPowerBar or config.allowedPowerTypesDamage[pname] + end + if isMainline then + if not healerClasses[unitClass] and pname == "MANA" then showPowerBar = false end + end + + frame.power:OnPowerTypeChange(pname, not showPowerBar) + frame.state.powerType = showPowerBar and pname or "NONE" + + FrameSetJob(frame, config.PowerBarColor, true, "POWERCOLOR", pname, makeUnique()) end end function Aptechka.UNIT_DISPLAYPOWER(self, event, unit) self:ForEachUnitFrame(unit, Aptechka.FrameUpdateDisplayPower) - if apiLevel <= 3 then - local pnum, ptype = UnitPowerType(unit) - self:ForEachUnitFrame(unit, Aptechka.FrameUpdatePower, ptype) - end + local pnum, ptype = UnitPowerType(unit) + self:ForEachUnitFrame(unit, Aptechka.FrameUpdatePower, ptype) end local vehicleHack = function (self, time) @@ -2114,10 +2163,9 @@ local function updateUnitButton(self, unit) if not config.disableManaBar then Aptechka.FrameUpdateDisplayPower(self, unit) local ptype = select(2,UnitPowerType(owner)) - Aptechka.FrameUpdatePower(self, unit, ptype) Aptechka.FrameUpdatePower(self, unit, "RUNIC_POWER") Aptechka.FrameUpdatePower(self, unit, "ALTERNATE") - FrameSetJob(self,config.PowerBarColor,true, nil, makeUnique()) + Aptechka.FrameUpdatePower(self, unit, ptype) end Aptechka.FrameUpdateThreat(self, unit) Aptechka.FrameUpdateMindControl(self, unit) @@ -2714,7 +2762,7 @@ function Aptechka.SetupFrame(header, frameName) Aptechka:UnregisterEvent("UNIT_POWER_UPDATE") Aptechka:UnregisterEvent("UNIT_MAXPOWER") Aptechka:UnregisterEvent("UNIT_DISPLAYPOWER") - if f.power and f.power.OnPowerTypeChange then f.power:OnPowerTypeChange("none") end + if f.power and f.power.OnPowerTypeChange then f.power:OnPowerTypeChange("MANA", true) end f.power = nil end diff --git a/config.lua b/config.lua index ba98ff6..cf6e706 100644 --- a/config.lua +++ b/config.lua @@ -63,7 +63,7 @@ config.IncomingHealStatus = { name = "IncHealText", assignto = set(), color = { config.HealthTextStatus = { name = "HealthText", assignto = set("text2"), color = { 54/255, 201/255, 99/256 }, priority = 10, formatType = "MISSING_VALUE_SHORT" } config.UnitNameStatus = { name = "UnitName", assignto = set("text1"), classcolor = true, priority = 5 } config.HealthBarColor = { name = "HealthBar", assignto = set("health"), color = {1, .3, .3}, classcolor = true, priority = 10 } -config.PowerBarColor = { name = "PowerBar", assignto = set("power"), color = {.5,.5,1}, priority = 20 } +config.PowerBarColor = { name = "PowerBarColor", assignto = set("power"), color = {.5,.5,1}, priority = 20 } config.InVehicleStatus = { name = "InVehicle", assignto = set("vehicle"), color = {0.3,1,0.3}, priority = 21 } config.LOSStatus = { name = "OutOfSight", assignto = set("healfeedback"), scale = 1.6, color = {1,0.1,0.1}, priority = 95, fade = 0.3 } config.DispelStatus = { name = "Dispel", assignto = set("debuffHighlight"), scale = 1, pulse = 2, spin = true, priority = 86 } @@ -133,6 +133,25 @@ config.templates = { HealTrace = { assignto = set("healfeedback"), color = { 1, 0.7, 0.35}, fade = 0.7, priority = 96 }, } +config.allowedPowerTypes = { + MANA = true, +} +config.allowedPowerTypesTank = { + RAGE = true, + PAIN = true, + RUNIC_POWER = true, +} +config.allowedPowerTypesDamage = { + INSANITY = true, + RAGE = true, + RUNIC_POWER = true, + FURY = true, + ENERGY = true, + FOCUS = true, + LUNAR_POWER = true, + MAELSTROM = true, +} + local isMainline = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE if not isMainline then return end diff --git a/frame.lua b/frame.lua index 1842233..e4890a2 100644 --- a/frame.lua +++ b/frame.lua @@ -348,6 +348,23 @@ function contentNormalizers.INCOMING_HEAL(job, state, contentType, ...) r,g,b, a, tr,tg,tb = GetTextColor(job) return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords end + +local PowerBarColor = PowerBarColor +function contentNormalizers.POWERCOLOR(job, state, contentType, pname, ...) + local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords + local db = Aptechka.db.profile + local showPowerTypeColors = true + if showPowerTypeColors and pname ~= "MANA" then + local c = PowerBarColor[pname] -- getting default color from a globalr2 + r,g,b = c.r, c.g, c.b + else + r,g,b = unpack(db.powerColor) + end + a = 1 + text = job.text + + return timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords +end function contentNormalizers.AURA(job, state, contentType, ...) local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords local duration, expirationTime, count1, icon1, spellID, caster = ... @@ -681,18 +698,11 @@ local SetJob_HealthBar = function(self, job, state, contentType, ...) end local SetJob_PowerBar = function(self, job, state, contentType, ...) local profile = Aptechka.db.profile - local r,g,b,a + local timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords, isReversed = NormalizeContent(job, state, contentType, ...) local r2,g2,b2 - if contentType == "PowerBar" then - r,g,b = unpack(profile.powerColor) - if profile.useCustomBackgroundColorPower then - r2,g2,b2 = unpack(profile.customBackgroundColorPower) - else - r2,g2,b2 = r,g,b - end + if profile.useCustomBackgroundColorPower then + r2,g2,b2 = unpack(profile.customBackgroundColorPower) else - local timerType, cur, max, count, icon, text, _,_,_, _, tr,tg,tb, texture, texCoords, isReversed - timerType, cur, max, count, icon, text, r,g,b, a, tr,tg,tb, texture, texCoords, isReversed = NormalizeContent(job, state, contentType, ...) r2,g2,b2 = r,g,b end if b then @@ -704,15 +714,35 @@ local SetJob_PowerBar = function(self, job, state, contentType, ...) end end -local PowerBar_OnPowerTypeChange = function(powerbar, powerType, isDead) +local forcedStandardFillPowerTypes = { + RAGE = true, + FURY = true, + RUNIC_POWER = true, +} + +local PowerBar_OnPowerTypeChange = function(powerbar, powerType, hidePower) local self = powerbar:GetParent() - powerType = powerType or self.power.powerType - self.power.powerType = powerType + + local isInverted = Aptechka.db.profile.fgShowMissing + if not isInverted then + self.power:SetFillStyleLock(false) + self.power:SetFillStyle("STANDARD") + else + if forcedStandardFillPowerTypes[powerType] then + self.power:SetFillStyle("STANDARD") + self.power:SetFillStyleLock(true) + else + self.power:SetFillStyleLock(false) + self.power:SetFillStyle("REVERSE") + end + end + local isVertical = Aptechka.db.profile.healthOrientation == "VERTICAL" - if powerType ~= "MANA" or isDead then + if hidePower then self.power.disabled = true self.power:Hide() + -- self.power.powerType = "NONE" if isVertical then -- self.health:SetPoint("TOPLEFT", self, "TOPLEFT",0,0) self.health:SetPoint("TOPRIGHT", self, "TOPRIGHT",0,0) @@ -723,6 +753,7 @@ local PowerBar_OnPowerTypeChange = function(powerbar, powerType, isDead) else self.power.disabled = nil self.power:Show() + -- self.power.powerType = powerType if isVertical then self.health:SetPoint("TOPLEFT", self, "TOPLEFT",0,0) self.health:SetPoint("TOPRIGHT", self.power, "TOPLEFT",0,0) @@ -3470,10 +3501,13 @@ function MaskStatusBar.SetMinMaxValues(self, min, max) end function MaskStatusBar.SetFillStyle(self, fillStyle) - if self._fillStyle == fillStyle then return end + if self._fillStyle == fillStyle or self._locked then return end self._fillStyle = fillStyle self:_Configure() end +function MaskStatusBar.SetFillStyleLock(self, state) + self._locked = state +end function MaskStatusBar.SetOrientation(self, orientation) if self._orientation == orientation then return end self._orientation = orientation @@ -3610,10 +3644,13 @@ function CoordStatusBar.GetSeparationRegionAttachmentPoints(self) return region end function CoordStatusBar.SetFillStyle(self, fillStyle) - if self._fillStyle == fillStyle then return end + if self._fillStyle == fillStyle or self._locked then return end self._fillStyle = fillStyle self:_Configure() end +function CoordStatusBar.SetFillStyleLock(self, state) + self._locked = state +end function CoordStatusBar.SetOrientation(self, orientation) if self._orientation == orientation then return end self._orientation = orientation