From ff80233cbe62614af4ccd6a268f5a1b4b54e5c50 Mon Sep 17 00:00:00 2001 From: d87 Date: Mon, 31 May 2021 09:48:29 +0700 Subject: [PATCH] FSR & Mana configs --- NugEnergy.lua | 36 ++------- config.lua | 215 ++++++++++++++++++++++++++++++++++++++++++++++++-- ticker.lua | 69 +++++++++++++++- 3 files changed, 281 insertions(+), 39 deletions(-) diff --git a/NugEnergy.lua b/NugEnergy.lua index cbfef37..11086c3 100644 --- a/NugEnergy.lua +++ b/NugEnergy.lua @@ -46,7 +46,6 @@ NugEnergy.L = L NugEnergy:RegisterEvent("PLAYER_LOGIN") -NugEnergy:RegisterEvent("PLAYER_LOGOUT") local UnitPower = UnitPower local math_modf = math.modf local math_abs = math.abs @@ -74,8 +73,8 @@ local ColorArray = function(color) return {color.r, color.g, color.b} end local defaults = { global = { classConfig = { - ROGUE = { "EnergyRogueTicker", "EnergyRogueTicker", "EnergyRogueTicker" }, - DRUID = { "Disabled", "Disabled", "Disabled", "Disabled" }, + ROGUE = { "EnergyRogue", "EnergyRogue", "EnergyRogue" }, + DRUID = { "ShapeshiftDruidClassic", "ShapeshiftDruidClassic", "ShapeshiftDruidClassic", "ShapeshiftDruidClassic" }, PALADIN = { "Disabled", "Disabled", "Disabled" }, MONK = { "Disabled", "Disabled", "Disabled" }, WARLOCK = { "Disabled", "Disabled", "Disabled" }, @@ -179,11 +178,6 @@ function NugEnergy.PLAYER_LOGIN(self,event) pmult = (768/h) / UIParent:GetScale() end - - if APILevel >= 3 then - self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") -- for mark swaps - end - NugEnergy:UpdateUpvalues() NugEnergy:Initialize() @@ -202,10 +196,6 @@ function NugEnergy.PLAYER_LOGIN(self,event) end) end --- function NugEnergy.PLAYER_LOGOUT(self, event) --- RemoveDefaults( NugEnergyDB, defaults) --- end - function NugEnergy:UpdateUpvalues() isVertical = NugEnergy.db.profile.isVertical onlyText = NugEnergy.db.profile.hideBar @@ -718,7 +708,7 @@ function NugEnergy.UpdateEnergy(self, elapsed) -- self.spentBar:SetColor(unpack(c)) self:SetColor(unpack(c)) - if APILevel <= 2 then + if APILevel <= 2 and PowerTypeIndex == Enum_PowerType_Energy then self:ColorTickWindow(capped, c) end @@ -727,6 +717,7 @@ function NugEnergy.UpdateEnergy(self, elapsed) if self.marks[p] then self.marks[p].shine:Play() end end end +NugEnergy.Update = NugEnergy.UpdateEnergy NugEnergy.__UpdateEnergy = NugEnergy.UpdateEnergy -- local idleSince = nil @@ -759,16 +750,6 @@ NugEnergy.__UpdateEnergy = NugEnergy.UpdateEnergy -- end -- end -function NugEnergy:PlaySound() - local sound - if NugEnergy.db.profile.soundName == "Heartbeat" then - sound = "Interface\\AddOns\\NugEnergy\\heartbeat.mp3" - elseif NugEnergy.db.profile.soundName then - sound = NugEnergy.db.profile.soundNameCustom - end - PlaySoundFile(sound, NugEnergy.db.profile.soundChannel) -end - function NugEnergy:Disable() PowerFilter = nil PowerTypeIndex = nil @@ -872,12 +853,6 @@ function NugEnergy:UpdateVisibility() end end -function NugEnergy.ACTIVE_TALENT_GROUP_CHANGED() - NugEnergy:ReconfigureMarks() - if NugEnergy.UNIT_DISPLAYPOWER then - NugEnergy:UNIT_DISPLAYPOWER() - end -end function NugEnergy.ReconfigureMarks(self) -- local spec_marks = NugEnergy.db.profile_Character.marks[GetSpecialization() or 0] -- for at, frame in pairs(NugEnergy.marks) do @@ -2416,6 +2391,9 @@ function NugEnergy:ResetConfig() self.eventProxy:SetScript("OnUpdate", nil) self:UpdateBarEffects() self.ticker:Disable() + if self.fsrwatch then + self.fsrwatch:Disable() + end end function NugEnergy:SelectConfig(name) diff --git a/config.lua b/config.lua index a6b978d..80255cf 100644 --- a/config.lua +++ b/config.lua @@ -6,6 +6,13 @@ local math_modf = math.modf local math_abs = math.abs local GetSpecialization = APILevel <= 2 and function() return 1 end or _G.GetSpecialization +local IsAnySpellKnown = function (...) + for i=1, select("#", ...) do + local spellID = select(i, ...) + if not spellID then break end + if IsPlayerSpell(spellID) then return spellID end + end +end local GetSpell = function(spellId) return function() @@ -20,6 +27,26 @@ local GetPowerBy5 = function(unit) return p, math_modf(p/5)*5, nil, nil, p == pmax, nil end +local execute = false +local function UNIT_HEALTH_EXECUTE(execute_range) + return function(self, event, unit) + if unit ~= "target" then return end + local uhm = UnitHealthMax(unit) + if uhm == 0 then uhm = 1 end + if execute_range then + execute = UnitHealth(unit)/uhm < execute_range + else + execute = false + end + self:UpdateEnergy() + end +end +local function UNIT_HEALTH_EXECUTE_PLAYER_TARGET_CHANGED(self,event) + if UnitExists('target') then + self.eventProxy:UNIT_HEALTH(self, event, "target") + end +end + local MakeGeneralGetPower = function(PowerTypeIndex, shineZone, cappedZone, minLimit, throttleText) return function(unit) local p = UnitPower(unit, PowerTypeIndex) @@ -30,7 +57,7 @@ local MakeGeneralGetPower = function(PowerTypeIndex, shineZone, cappedZone, minL -- if GetSpecialization() == 3 p < 60 pmax-10 local capped = p >= pmax-cappedZone local p2 = throttleText and math_modf(p/5)*5 - return p, p2, nil, shine, capped, (minLimit and p < minLimit) + return p, p2, execute, shine, capped, (minLimit and p < minLimit) end end @@ -55,8 +82,6 @@ local function GENERAL_UPDATE_STEALTH(self) end -local lastEnergyTickTime = GetTime() -local lastEnergyValue = 0 local GetPower_ClassicRogueTicker = function(PowerTypeIndex, shineZone, cappedZone, minLimit, throttleText) local ticker = NugEnergy.ticker return function(unit) @@ -69,10 +94,6 @@ local GetPower_ClassicRogueTicker = function(PowerTypeIndex, shineZone, cappedZo return p, p2, nil, shine, capped, (minLimit and p2 < minLimit) end end -local UNIT_MAXPOWER_ClassicTicker = function(self) - self:SetMinMaxValues(0, 2) -end - @@ -89,6 +110,7 @@ NugEnergy:RegisterConfig("EnergyRogue", { self.eventProxy:RegisterUnitEvent("UNIT_MAXPOWER", "player") self.eventProxy.UNIT_MAXPOWER = GENERAL_UNIT_MAXPOWER + GENERAL_UNIT_MAXPOWER(self) self.eventProxy:RegisterUnitEvent("UNIT_POWER_UPDATE", "player") self.eventProxy.UNIT_POWER_UPDATE = FILTERED_UNIT_POWER_UPDATE("ENERGY") @@ -112,4 +134,181 @@ NugEnergy:RegisterConfig("EnergyRogueTicker", { self.ticker:Enable() self:UpdateBarEffects("DISABLE_SMOOTHING") end, -}, "ROGUE") \ No newline at end of file +}, "ROGUE") + +NugEnergy:RegisterConfig("GeneralRage", { + triggers = { GetSpecialization }, + setup = function(self, spec) + self:SetPowerFilter("RAGE", Enum.PowerType.Rage) + self:SetNormalColor() + self.flags.shouldBeFull = true + + self.eventProxy:RegisterUnitEvent("UNIT_MAXPOWER", "player") + self.eventProxy.UNIT_MAXPOWER = GENERAL_UNIT_MAXPOWER + GENERAL_UNIT_MAXPOWER(self) + + self.eventProxy:RegisterUnitEvent("UNIT_POWER_UPDATE", "player") + self.eventProxy.UNIT_POWER_UPDATE = FILTERED_UNIT_POWER_UPDATE("RAGE") + + -- self.eventProxy:RegisterUnitEvent("UNIT_HEALTH", "target") + -- self.eventProxy.UNIT_HEALTH = UNIT_HEALTH_EXECUTE(0.2) + + -- self:SetPowerGetter(MakeGeneralGetPower(Enum.PowerType.Rage, 30, 10, nil, nil)) + end, +}, "GENERAL") + + +local GetPower_ClassicMana = function(unit) + local p = GetTime() - NugEnergy.ticker:GetLastTickTime() + local _, PowerTypeIndex = NugEnergy:GetPowerFilter() + local mana = UnitPower(unit, PowerTypeIndex) + local pmax = UnitPowerMax(unit, PowerTypeIndex) + local p2 + if pmax > 0 then + p2 = string.format("%d", mana/pmax*100) + end + local shine = nil + local capped = mana == pmax + local insufficient = nil + return p, p2, execute, shine, capped, insufficient +end + +NugEnergy:RegisterConfig("GeneralMana", { + triggers = { GetSpecialization }, + setup = function(self, spec) + self:SetPowerFilter("MANA", Enum.PowerType.Mana) + self:SetNormalColor() + self.flags.shouldBeFull = true + + -- self.eventProxy:RegisterUnitEvent("UNIT_MAXPOWER", "player") + -- self.eventProxy.UNIT_MAXPOWER = GENERAL_UNIT_MAXPOWER + -- GENERAL_UNIT_MAXPOWER(self) + self.eventProxy:UnregisterEvent("UNIT_MAXPOWER") + self:SetMinMaxValues(0, 2) + + self.eventProxy:RegisterUnitEvent("UNIT_POWER_UPDATE", "player") + self.eventProxy.UNIT_POWER_UPDATE = FILTERED_UNIT_POWER_UPDATE("MANA") + + self.ticker:Enable() + self.eventProxy:SetScript("OnUpdate", function() NugEnergy:UpdateEnergy() end) + + self:SetPowerGetter(GetPower_ClassicMana) + end, +}, "GENERAL") + + +local GetPower_ClassicMana5SR = function(unit) + local p = GetTime() - NugEnergy.fsrwatch:GetLastManaSpentTime() + local _, PowerTypeIndex = NugEnergy:GetPowerFilter() + local mana = UnitPower(unit, PowerTypeIndex) + local pmax = UnitPowerMax(unit, PowerTypeIndex) + local p2 + if pmax > 0 then + p2 = string.format("%d", mana/pmax*100) + end + local shine = nil + local capped = nil + local insufficient = nil + -- if p >= 5 and callback then + -- callback() + -- end + -- local p2 = throttleText and math_modf(p2/5)*5 or p2 + return p, p2, execute, shine, capped, true +end + + + +NugEnergy:RegisterConfig("GeneralFSRMana", { + triggers = { GetSpecialization }, + setup = function(self, spec) + -- local powerFilter = self:GetPowerFilter() + -- if powerFilter ~= "MANA" then + self:ApplyConfig("GeneralMana") + -- end + + self.fsrwatch = self.fsrwatch or self:Make5SRWatcher(function(self) + local powerFilter = self:GetPowerFilter() + if powerFilter == "MANA" then + self:ApplyConfig("GeneralFSRMana") + end + end) + self.fsrwatch:Enable() + + self.ticker:Enable("FSR", function(self) + self:ResetConfig() + self:ApplyConfig("GeneralMana") + self.fsrwatch:Enable() + self:Update() + end) + + self.eventProxy:UnregisterEvent("UNIT_MAXPOWER") + self:SetMinMaxValues(0, 5) + + self:SetPowerGetter(GetPower_ClassicMana5SR) + self.eventProxy:SetScript("OnUpdate", function() NugEnergy:UpdateEnergy() end) + end, +}, "GENERAL") + +NugEnergy:RegisterConfig("RageWarriorClassic", { + triggers = { GetSpecialization }, + setup = function(self, spec) + self:ApplyConfig("GeneralRage") + + if IsAnySpellKnown(20662, 20661, 20660, 20658, 5308) then + self.eventProxy:RegisterUnitEvent("UNIT_HEALTH", "target") + self.eventProxy.UNIT_HEALTH = UNIT_HEALTH_EXECUTE(0.2) + + self.eventProxy:RegisterEvent("PLAYER_TARGET_CHANGED") + self.eventProxy.PLAYER_TARGET_CHANGED = UNIT_HEALTH_EXECUTE_PLAYER_TARGET_CHANGED + end + + self:SetPowerGetter(MakeGeneralGetPower(Enum.PowerType.Rage, 30, 10, nil, nil)) + end, +}, "WARRIOR") + + + + + + + + + +NugEnergy:RegisterConfig("RageDruidClassic", { + triggers = { GetSpecialization }, + setup = function(self, spec) + self:ApplyConfig("GeneralRage") + + self:SetPowerGetter(MakeGeneralGetPower(Enum.PowerType.Rage, 30, 10, nil, nil)) + end, +}, "DRUID") + + +NugEnergy:RegisterConfig("ShapeshiftDruidClassic", { + triggers = { GetSpecialization }, + + setup = function(self, spec) + self:RegisterEvent("UNIT_DISPLAYPOWER") -- Registering on main addon, not event proxy + self.UNIT_DISPLAYPOWER = function(self) + local newPowerType = select(2,UnitPowerType("player")) + self:ResetConfig() + + if newPowerType == "ENERGY" then + self:ApplyConfig("EnergyRogueTicker") + if APILevel == 2 then + self.ticker:Reset() + end + self:Update() + elseif newPowerType == "RAGE" then + self:ApplyConfig("RageDruidClassic") + self:Update() + elseif newPowerType == "MANA" then + self:ApplyConfig("GeneralFSRMana") + self:Update() + else + self:Disable() + end + end + self.UNIT_DISPLAYPOWER(self) + end +}, "DRUID") \ No newline at end of file diff --git a/ticker.lua b/ticker.lua index 0adcb03..dc46f0a 100644 --- a/ticker.lua +++ b/ticker.lua @@ -47,14 +47,30 @@ local ClassicTickerOnUpdate = function(self) end lastEnergyValue = currentEnergy end + +local fsrCallback +local ClassicTickerOnUpdateFSR = function(self) + local now = GetTime() + if now >= lastEnergyTickTime + 5 then + self:Disable() + fsrCallback(NugEnergy) + end +end + function ClassicTickerFrame:GetLastTickTime() return lastEnergyTickTime end function ClassicTickerFrame:Reset() lastEnergyTickTime = GetTime() end -function ClassicTickerFrame:Enable() - self:SetScript("OnUpdate", ClassicTickerOnUpdate) +function ClassicTickerFrame:Enable(mode, callback) + if mode == "FSR" then + self:SetScript("OnUpdate", ClassicTickerOnUpdateFSR) + fsrCallback = callback + self:Reset() + else + self:SetScript("OnUpdate", ClassicTickerOnUpdate) + end self.isEnabled = true end function ClassicTickerFrame:Disable() @@ -161,4 +177,53 @@ do end PlaySoundFile(sound, NugEnergy.db.profile.soundChannel) end +end + +function NugEnergy:Make5SRWatcher(default_callback) + local f = CreateFrame("Frame", nil, UIParent) + f:SetScript("OnEvent", function(self, event, ...) + return self[event](self, event, ...) + end) + + local callback = default_callback + + local lastManaDropTime = 0 + local prevMana = UnitPower("player", 0) + f.UNIT_SPELLCAST_SUCCEEDED = function(self, event, unit) + if unit == "player" then + local now = GetTime() + if now - lastManaDropTime < 0.01 then + callback(NugEnergy) + end + end + end + f.UNIT_POWER_UPDATE = function(self, event, unit, ptype) + if ptype == "MANA" then + local mana = UnitPower("player", 0) + if mana < prevMana then + lastManaDropTime = GetTime() + end + prevMana = mana + end + end + + f.Enable = function(self, new_callback) + self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") + self:RegisterUnitEvent("UNIT_POWER_UPDATE", "player") + if new_callback then + callback = new_callback + end + end + f.Disable = function(self) + self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED") + self:UnregisterEvent("UNIT_POWER_UPDATE") + end + + f.GetLastManaSpentTime = function(self) + return lastManaDropTime + end + + f:Enable() + + return f end \ No newline at end of file