diff --git a/IceBarElement.lua b/IceBarElement.lua index 5b37e32..40314fc 100644 --- a/IceBarElement.lua +++ b/IceBarElement.lua @@ -15,6 +15,7 @@ IceBarElement.prototype.DesiredScale = 1 IceBarElement.prototype.CurrScale = 1 IceBarElement.prototype.Markers = {} IceBarElement.prototype.IsBarElement = true -- cheating to avoid crawling up the 'super' references looking for this class. see IceCore.lua +IceBarElement.prototype.bTreatEmptyAsFull = false local lastMarkerPosConfig = 50 local lastMarkerColorConfig = {r=1, b=0, g=0, a=1} @@ -34,6 +35,10 @@ end function IceBarElement.prototype:Enable() IceBarElement.super.prototype.Enable(self) + -- never register the OnUpdate for the mirror bar since it's handled internally + -- in addition, do not register OnUpdate if predictedPower is set and this is the player mana or target mana bar + self:ConditionalSetupUpdate() + if IceHUD.IceCore:ShouldUseDogTags() then DogTag = LibStub("LibDogTag-3.0", true) if DogTag then @@ -71,6 +76,7 @@ function IceBarElement.prototype:Enable() if self.moduleSettings.textVisible["lower"] then self.frame.bottomLowerText:Hide() end + self:OnHide() end) self.frame:SetScript("OnShow", function() if self.moduleSettings.textVisible["upper"] then @@ -79,13 +85,21 @@ function IceBarElement.prototype:Enable() if self.moduleSettings.textVisible["lower"] then self.frame.bottomLowerText:Show() end + self:OnShow() end) end +function IceBarElement.prototype:OnHide() + IceHUD.IceCore:RequestUpdates(self, nil) +end + +function IceBarElement.prototype:OnShow() +end + function IceBarElement.prototype:Disable(core) IceBarElement.super.prototype.Disable(self, core) - self.frame:SetScript("OnUpdate", nil) + IceHUD.IceCore:RequestUpdates(self, nil) self.frame:SetScript("OnHide", nil) self.frame:SetScript("OnShow", nil) end @@ -823,20 +837,29 @@ function IceBarElement.prototype:CreateFrame() end self.masterFrame:SetScale(self.moduleSettings.scale) - -- never register the OnUpdate for the mirror bar since it's handled internally - -- in addition, do not register OnUpdate if predictedPower is set and this is the player mana or target mana bar - if not string.find(self.elementName, "MirrorBar") - and ((IceHUD.WowVer < 30000 or not GetCVarBool("predictedPower")) or (not string.find(self.elementName, "PlayerMana"))) - and not self.moduleSettings.isCustomBar and self:RegisterOnUpdate() then - self.frame:SetScript("OnUpdate", function() self:MyOnUpdate() end) - end if self.moduleSettings.rotateBar then self:RotateHorizontal() end end -function IceBarElement.prototype:RegisterOnUpdate() +function IceBarElement.prototype:ConditionalSetupUpdate() + if not self.MyOnUpdateFunc then + self.MyOnUpdateFunc = function() self:MyOnUpdate() end + end + + if IceHUD.IceCore:IsUpdateSubscribed(self) then + return + end + + if not string.find(self.elementName, "MirrorBar") + and ((IceHUD.WowVer < 30000 or not GetCVarBool("predictedPower")) or (not string.find(self.elementName, "PlayerMana"))) + and self:ShouldRegisterOnUpdate() then + IceHUD.IceCore:RequestUpdates(self, self.MyOnUpdateFunc) + end +end + +function IceBarElement.prototype:ShouldRegisterOnUpdate() return true end @@ -1038,6 +1061,14 @@ function IceBarElement.prototype:SetScale(inScale, force) self.barFrame.bar:Show() end end + + if not self:IsFull(self.CurrScale) or not self:IsFull(inScale) then + self:ConditionalSetupUpdate() + else + if self.CurrScale == self.DesiredScale then + IceHUD.IceCore:RequestUpdates(self, nil) + end + end end @@ -1046,19 +1077,21 @@ function IceBarElement.prototype:LerpScale(scale) return scale end + local now = GetTime() + if self.CurrLerpTime < self.moduleSettings.desiredLerpTime then - self.CurrLerpTime = self.CurrLerpTime + (1 / GetFramerate()); + self.CurrLerpTime = self.CurrLerpTime + (now - (self.lastLerpTime or now)) end + self.lastLerpTime = GetTime() + if self.CurrLerpTime > self.moduleSettings.desiredLerpTime then self.CurrLerpTime = self.moduleSettings.desiredLerpTime + elseif self.CurrLerpTime < self.moduleSettings.desiredLerpTime then + return self.LastScale + ((self.DesiredScale - self.LastScale) * (self.CurrLerpTime / self.moduleSettings.desiredLerpTime)) end - if self.CurrLerpTime < self.moduleSettings.desiredLerpTime then - return self.LastScale + ((self.DesiredScale - self.LastScale) * (self.CurrLerpTime / self.moduleSettings.desiredLerpTime)) - else - return scale - end + return scale end @@ -1102,6 +1135,7 @@ function IceBarElement.prototype:UpdateBar(scale, color, alpha) if self.DesiredScale ~= scale then self.DesiredScale = scale self.CurrLerpTime = 0 + self.lastLerpTime = GetTime() self.LastScale = self.CurrScale end @@ -1124,7 +1158,19 @@ end function IceBarElement.prototype:UseTargetAlpha(scale) - return (scale and (scale < 1)) + return not self:IsFull(scale) +end + +function IceBarElement.prototype:IsFull(scale) + if self.reverse then + scale = 1 - scale + end + + if not self.bTreatEmptyAsFull then + return scale and scale == 1 + else + return scale and scale == 0 + end end @@ -1228,9 +1274,6 @@ function IceBarElement.prototype:Update() end function IceBarElement.prototype:MyOnUpdate() - if not self:IsVisible() then - return - end self:SetScale(self.DesiredScale) end @@ -1386,3 +1429,13 @@ function IceBarElement.prototype:LoadMarkers() self:CreateMarker(i) end end + +function IceBarElement.prototype:Show(bShouldShow) + if IceBarElement.super.prototype.Show(self, bShouldShow) then + if self.bIsVisible then + self:ConditionalSetupUpdate() + else + IceHUD.IceCore:RequestUpdates(self, nil) + end + end +end diff --git a/IceCastBar.lua b/IceCastBar.lua index 99eb000..8782140 100644 --- a/IceCastBar.lua +++ b/IceCastBar.lua @@ -245,7 +245,7 @@ end -- OnUpdate handler -function IceCastBar.prototype:OnUpdate() +function IceCastBar.prototype:MyOnUpdate() -- safety catch if (self.action == IceCastBar.Actions.None) then IceHUD:Debug("Stopping action ", self.action) @@ -370,7 +370,7 @@ function IceCastBar.prototype:StartBar(action, message) end self:Show(true) - self.frame:SetScript("OnUpdate", function() self:OnUpdate() end) + self:ConditionalSetupUpdate() end @@ -380,16 +380,6 @@ function IceCastBar.prototype:StopBar() self.actionDuration = nil self:Show(false) - self.frame:SetScript("OnUpdate", nil) -end - --- make sure that our custom OnUpdate is restored whenever a Redraw happens -function IceCastBar.prototype:Redraw() - IceCastBar.super.prototype.Redraw(self) - - if self.action ~= IceCastBar.Actions.None then - self.frame:SetScript("OnUpdate", function() self:OnUpdate() end) - end end function IceCastBar.prototype:GetShortRank(rank) diff --git a/IceCore.lua b/IceCore.lua index bad2491..57a951f 100644 --- a/IceCore.lua +++ b/IceCore.lua @@ -17,6 +17,8 @@ function IceCore_CreateClass(parent) return class end +local DogTag = LibStub("LibDogTag-3.0", true) + IceCore = IceCore_CreateClass() IceCore.Side = { Left = "LEFT", Right = "RIGHT" } @@ -73,7 +75,7 @@ function IceCore.prototype:SetupDefaults() bShouldUseDogTags = true, - updatePeriod = 0.1, + updatePeriod = 0.033, minimap = {}, }, global = { @@ -108,6 +110,15 @@ StaticPopupDialogs["ICEHUD_CONVERTED_TO_ACE3"] = hideOnEscape = 0, } +StaticPopupDialogs["ICEHUD_UPDATE_PERIOD_MATTERS"] = +{ + text = L["Since the last time you updated IceHUD, many significant CPU and memory optimizations have been made. If bar animation looks jumpy to you, open the /icehud configuration page and lower the 'Update Period' slider. This will cause higher CPU usage but will look nicer. Enjoy IceHUD!"], + button1 = OKAY, + timeout = 0, + whileDead = 1, + hideOnEscape = 0, +} + function IceCore.prototype:CheckDisplayUpdateMessage() local thisVersion --[===[@non-debug@ @@ -120,6 +131,14 @@ function IceCore.prototype:CheckDisplayUpdateMessage() if self.accountSettings.lastRunVersion < 549 then StaticPopup_Show("ICEHUD_CONVERTED_TO_ACE3") end + if self.accountSettings.lastRunVersion < 707 and self.accountSettings.lastRunVersion > 0 then + -- update from the old default that may have been saved with the user's settings + if self.settings.updatePeriod == 0.1 then + self.settings.updatePeriod = 0.033 + end + + StaticPopup_Show("ICEHUD_UPDATE_PERIOD_MATTERS") + end self.accountSettings.lastRunVersion = thisVersion end end @@ -185,7 +204,7 @@ function IceCore.prototype:Enable(userToggle) end if self.settings.updatePeriod == nil then - self.settings.updatePeriod = 0.1 + self.settings.updatePeriod = 0.033 end -- make sure the module options are re-generated. if we switched profiles, we don't want the old elements hanging around @@ -359,24 +378,23 @@ end function IceCore.prototype:GetColorOptions() - assert(table.getn(IceHUD.IceCore.elements) > 0, "Unable to get color options, no elements found!") - local options = {} - for k, v in pairs(self.elements[1]:GetColors()) do - local kk, vv = k, v - options[k] = { - type = 'color', - desc = k, - name = k, - get = function() - return IceHUD.IceCore:GetColor(kk) - end, - set = function(info, r, g, b) - local color = k - IceHUD.IceCore:SetColor(kk, r, g, b) - end - } + if #self.elements > 0 then + for k, v in pairs(self.elements[1]:GetColors()) do + options[k] = { + type = 'color', + desc = k, + name = k, + get = function() + return IceHUD.IceCore:GetColor(k) + end, + set = function(info, r, g, b) + local color = k + IceHUD.IceCore:SetColor(k, r, g, b) + end + } + end end return options @@ -658,7 +676,7 @@ function IceCore.prototype:ConfigModeToggle(bWantConfig) end function IceCore.prototype:ShouldUseDogTags() - return LibStub("LibDogTag-3.0", true) and self.settings.bShouldUseDogTags + return DogTag and self.settings.bShouldUseDogTags end function IceCore.prototype:SetShouldUseDogTags(should) @@ -678,22 +696,18 @@ function IceCore.prototype:HandleUpdates() local update_period = self:UpdatePeriod() local elapsed = 1 / GetFramerate() self.update_elapsed = self.update_elapsed + elapsed - if (self.update_elapsed > update_period) then - for frame, func in pairs(self.updatees) - do + if (self.update_elapsed >= update_period) then + for module, func in pairs(self.updatees) do func() end - if (elapsed > update_period) then - self.update_elapsed = 0 - else - self.update_elapsed = self.update_elapsed - update_period - end + + self.update_elapsed = self.update_elapsed - update_period end end -function IceCore.prototype:RequestUpdates(frame, func) - if self.updatees[frame] ~= func then - self.updatees[frame] = func +function IceCore.prototype:RequestUpdates(module, func) + if self.updatees[module] ~= func then + self.updatees[module] = func end local count = 0 @@ -704,12 +718,18 @@ function IceCore.prototype:RequestUpdates(frame, func) if (count == 0) then self.IceHUDFrame:SetScript("OnUpdate", nil) else - self.IceHUDFrame:SetScript("OnUpdate", function() self:HandleUpdates() end) + if not self.UpdateFunc then + self.UpdateFunc = function() self:HandleUpdates() end + end + + if self.IceHUDFrame:GetScript("OnUpdate") ~= self.UpdateFunc then + self.IceHUDFrame:SetScript("OnUpdate", self.UpdateFunc) + end end end -function IceCore.prototype:IsUpdateSubscribed(frame) - return self.updatees[frame] ~= nil +function IceCore.prototype:IsUpdateSubscribed(module) + return self.updatees[module] ~= nil end function IceCore.prototype:EmptyUpdates() diff --git a/IceElement.lua b/IceElement.lua index 462d266..51533b7 100644 --- a/IceElement.lua +++ b/IceElement.lua @@ -407,7 +407,7 @@ end function IceElement.prototype:Show(bShouldShow) if self.bIsVisible == bShouldShow then - return + return nil end self.bIsVisible = bShouldShow @@ -419,6 +419,8 @@ function IceElement.prototype:Show(bShouldShow) self.masterFrame:Show() self.frame:Show() end + + return true end diff --git a/IceHUD.lua b/IceHUD.lua index 6f0091e..3f4837f 100644 --- a/IceHUD.lua +++ b/IceHUD.lua @@ -651,9 +651,9 @@ Expand "|cffffdc42Module Settings|r", expand PlayerInfo (or TargetInfo for targe set = function(info, v) IceHUD.IceCore:SetUpdatePeriod(v) end, - min = 0.01, - max = 1.0, - step = 0.01, + min = 0, + max = 1, + step = 0.001, order = 97 }, diff --git a/IceUnitBar.lua b/IceUnitBar.lua index 6aae65e..c9d5405 100644 --- a/IceUnitBar.lua +++ b/IceUnitBar.lua @@ -285,31 +285,39 @@ function IceUnitBar.prototype:UpdateBar(scale, color, alpha) return end - self.flashFrame.flash:SetVertexColor(self:GetColor(color)) - if (self.moduleSettings.lowThreshold > 0 and self.moduleSettings.lowThresholdFlash and self.moduleSettings.lowThreshold >= scale and self.alive and not self.noFlash) then - self.flashFrame:SetScript("OnUpdate", function() self:OnFlashUpdate() end) + self.bUpdateFlash = true + self.flashFrame.flash:SetVertexColor(self:GetColor(color)) else - self.flashFrame:SetScript("OnUpdate", nil) + self.bUpdateFlash = nil self.flashFrame:SetAlpha(0) end end -function IceUnitBar.prototype:OnFlashUpdate() - local time = GetTime() - local decimals = time - math.floor(time) +function IceUnitBar.prototype:MyOnUpdate() + IceUnitBar.super.prototype.MyOnUpdate(self) - if (decimals > 0.5) then - decimals = 1 - decimals + self:ConditionalUpdateFlash() +end + + +function IceUnitBar.prototype:ConditionalUpdateFlash() + if self.bUpdateFlash then + local time = GetTime() + local decimals = time - math.floor(time) + + if (decimals > 0.5) then + decimals = 1 - decimals + end + + decimals = decimals*1.1 -- add more dynamic to the color change + + self.flashFrame:SetAlpha(decimals) end - - decimals = decimals*1.1 -- add more dynamic to the color change - - self.flashFrame:SetAlpha(decimals) end diff --git a/modules/ComboPointsBar.lua b/modules/ComboPointsBar.lua index ebab473..c41d0d6 100644 --- a/modules/ComboPointsBar.lua +++ b/modules/ComboPointsBar.lua @@ -6,6 +6,8 @@ function ComboPointsBar.prototype:init() self:SetDefaultColor("ComboPointsBarMin", 1, 1, 0) self:SetDefaultColor("ComboPointsBarMax", 0, 1, 0) + + self.bTreatEmptyAsFull = true end function ComboPointsBar.prototype:GetOptions() @@ -37,6 +39,7 @@ function ComboPointsBar.prototype:GetDefaultSettings() defaults.offset = 8 defaults.enabled = false defaults.alwaysDisplay = false + defaults.desiredLerpTime = 0.05 return defaults end diff --git a/modules/CustomBar.lua b/modules/CustomBar.lua index f42d2aa..a3fa2db 100644 --- a/modules/CustomBar.lua +++ b/modules/CustomBar.lua @@ -50,11 +50,15 @@ end function IceCustomBar.prototype:ConditionalSubscribe() if self:ShouldAlwaysSubscribe() then - if not IceHUD.IceCore:IsUpdateSubscribed(self.frame) then - IceHUD.IceCore:RequestUpdates(self.frame, function() self:UpdateCustomBar() end) + if not IceHUD.IceCore:IsUpdateSubscribed(self) then + if not self.CustomBarUpdateFunc then + self.CustomBarUpdateFunc = function() self:UpdateCustomBar() end + end + + IceHUD.IceCore:RequestUpdates(self, self.CustomBarUpdateFunc) end else - IceHUD.IceCore:RequestUpdates(self.frame, nil) + IceHUD.IceCore:RequestUpdates(self, nil) end end @@ -69,7 +73,7 @@ function IceCustomBar.prototype:TargetChanged() end function IceCustomBar.prototype:Disable(core) - IceHUD.IceCore:RequestUpdates(self.frame, nil) + IceHUD.IceCore:RequestUpdates(self, nil) IceCustomBar.super.prototype.Disable(self, core) end @@ -571,8 +575,12 @@ function IceCustomBar.prototype:UpdateCustomBar(unit, fromUpdate) end if self.auraEndTime ~= nil and (self.auraEndTime == 0 or self.auraEndTime >= now) then - if not self:ShouldAlwaysSubscribe() and not fromUpdate and not IceHUD.IceCore:IsUpdateSubscribed(self.frame) then - IceHUD.IceCore:RequestUpdates(self.frame, function() self:UpdateCustomBar(self.unit, true) end) + if not self:ShouldAlwaysSubscribe() and not fromUpdate and not IceHUD.IceCore:IsUpdateSubscribed(self) then + if not self.UpdateCustomBarFunc then + self.UpdateCustomBarFunc = function() self:UpdateCustomBar(self.unit, true) end + end + + IceHUD.IceCore:RequestUpdates(self, self.UpdateCustomBarFunc) end self:Show(true) @@ -590,7 +598,7 @@ function IceCustomBar.prototype:UpdateCustomBar(unit, fromUpdate) self:UpdateBar(0, "undef") self:Show(false) if not self:ShouldAlwaysSubscribe() then - IceHUD.IceCore:RequestUpdates(self.frame, nil) + IceHUD.IceCore:RequestUpdates(self, nil) end end diff --git a/modules/CustomCDBar.lua b/modules/CustomCDBar.lua index 4509535..35d639b 100644 --- a/modules/CustomCDBar.lua +++ b/modules/CustomCDBar.lua @@ -1,5 +1,5 @@ local L = LibStub("AceLocale-3.0"):GetLocale("IceHUD", false) -IceCustomCDBar = IceCore_CreateClass(IceUnitBar) +IceCustomCDBar = IceCore_CreateClass(IceBarElement) local IceHUD = _G.IceHUD @@ -18,7 +18,7 @@ table.insert(brokenSpellsNameToId, {"Holy Word: Aspire",88682}) -- Constructor -- function IceCustomCDBar.prototype:init() - IceCustomCDBar.super.prototype.init(self, "MyCustomCDBar", "player") + IceCustomCDBar.super.prototype.init(self, "MyCustomCDBar") end -- 'Public' methods ----------------------------------------------------------- @@ -59,7 +59,7 @@ end function IceCustomCDBar.prototype:Disable(core) - IceHUD.IceCore:RequestUpdates(self.frame, nil) + IceHUD.IceCore:RequestUpdates(self, nil) IceCustomCDBar.super.prototype.Disable(self, core) end @@ -79,7 +79,6 @@ function IceCustomCDBar.prototype:GetDefaultSettings() settings["lockLowerFontAlpha"] = false settings["lowerText"] = "" settings["lowerTextVisible"] = false - settings["isCustomBar"] = false settings["cooldownToTrack"] = "" settings["barColor"] = {r=1, g=0, b=0, a=1} settings["displayMode"] = "When cooling down" @@ -447,11 +446,15 @@ function IceCustomCDBar.prototype:EnableUpdates(enable_update) end if enable_update then - if not IceHUD.IceCore:IsUpdateSubscribed(self.frame) then - IceHUD.IceCore:RequestUpdates(self.frame, function() self:UpdateCustomBar(true) end) + if not IceHUD.IceCore:IsUpdateSubscribed(self) then + if not self.CustomUpdateFunc then + self.CustomUpdateFunc = function() self:UpdateCustomBar(true) end + end + + IceHUD.IceCore:RequestUpdates(self, self.CustomUpdateFunc) end else - IceHUD.IceCore:RequestUpdates(self.frame, nil) + IceHUD.IceCore:RequestUpdates(self, nil) end end @@ -533,6 +536,8 @@ function IceCustomCDBar.prototype:UpdateCustomBar(fromUpdate) self:SetBottomText1(self.moduleSettings.upperText) end + self:UpdateAlpha() + self.barFrame.bar:SetVertexColor(self:GetBarColor()) self.coolingDown = remaining ~= nil and remaining > 0 @@ -548,7 +553,7 @@ function IceCustomCDBar.prototype:TargetChanged() IceCustomCDBar.super.prototype.TargetChanged(self) -- Target changing only affects us if we want to show the bar as soon as it is ready. - if (self.moduleSettings.displayMode == "When ready") then + if (self.moduleSettings.displayMode == "When ready" or self.moduleSettings.displayMode == "Always") then self:UpdateCustomBar() end end @@ -584,11 +589,13 @@ end function IceCustomCDBar.prototype:Show(bShouldShow, bForceHide) if self.moduleSettings.enabled and not bForceHide then - if (self.moduleSettings.displayMode == "Always") then - if not self.bIsVisible then + if self.moduleSettings.displayMode == "Always" then + if self.target then IceCustomCDBar.super.prototype.Show(self, true) + else + IceCustomCDBar.super.prototype.Show(self, bShouldShow) end - elseif (self.moduleSettings.displayMode == "When ready") then + elseif self.moduleSettings.displayMode == "When ready" then if not self.coolingDown and self:IsReady() then IceCustomCDBar.super.prototype.Show(self, true) else @@ -603,9 +610,10 @@ function IceCustomCDBar.prototype:Show(bShouldShow, bForceHide) end function IceCustomCDBar.prototype:UseTargetAlpha(scale) - if self.moduleSettings.displayMode == "When ready" and scale == 0 then + if (self.moduleSettings.displayMode == "When ready" or self.moduleSettings.displayMode == "Always") + and scale == 0 then return false end - return true + return IceCustomCDBar.super.prototype:UseTargetAlpha(self, scale) end diff --git a/modules/CustomHealth.lua b/modules/CustomHealth.lua index e52aa02..40cf340 100644 --- a/modules/CustomHealth.lua +++ b/modules/CustomHealth.lua @@ -1,6 +1,5 @@ local L = LibStub("AceLocale-3.0"):GetLocale("IceHUD", false) IceCustomHealth = IceCore_CreateClass(IceTargetHealth) -IceCustomHealth.prototype.scheduledEvent = nil -- Constructor -- function IceCustomHealth.prototype:init() @@ -113,21 +112,19 @@ end function IceCustomHealth.prototype:Enable(core) - self.registerEvents = false + --self.registerEvents = false IceCustomHealth.super.prototype.Enable(self, core) self:SetUnit(self.moduleSettings.unitToTrack) self:CreateFrame() - - self.scheduledEvent = self:ScheduleRepeatingTimer("Update", IceHUD.IceCore:UpdatePeriod()) end -function IceCustomHealth.prototype:Disable(core) - IceCustomHealth.super.prototype.Disable(self, core) +function IceCustomHealth.prototype:MyOnUpdate() + IceCustomHealth.super.prototype.MyOnUpdate(self) - UnregisterUnitWatch(self.frame) - - self:CancelTimer(self.scheduledEvent, true) + if UnitExists(self.unit) then + self:Update() + end end function IceCustomHealth.prototype:Update(unit) @@ -153,12 +150,8 @@ function IceCustomHealth.prototype:Update(unit) self.color = "Tapped" end - if not self:IsVisible() then - RegisterUnitWatch(self.frame) - end - --self.determineColor = false - IceCustomHealth.super.prototype.Update(self, unit) + IceCustomHealth.super.prototype.Update(self, self.unit) end function IceCustomHealth.prototype:SetUnit(unit) @@ -168,3 +161,7 @@ function IceCustomHealth.prototype:SetUnit(unit) end self:RegisterFontStrings() end + +function IceCustomHealth.prototype:OnShow() + self:Update(self.unit) +end diff --git a/modules/EclipseBar.lua b/modules/EclipseBar.lua index 1c1abc2..0e3b718 100644 --- a/modules/EclipseBar.lua +++ b/modules/EclipseBar.lua @@ -58,8 +58,6 @@ function EclipseBar.prototype:Enable(core) self:RegisterEvent("UNIT_AURA", "UpdateEclipseBuffs") self:RegisterEvent("ECLIPSE_DIRECTION_CHANGE", "UpdateEclipseDirection") - self.frame:SetScript("OnUpdate", function() self:Update() end) - self:UpdateEclipseDirection(nil, GetEclipseDirection() == "sun", GetEclipseDirection() == "none") self:UpdateEclipseBuffs() self:UpdateShown() @@ -97,7 +95,7 @@ function EclipseBar.prototype:CreateFrame() self:UpdateAlpha() end -function EclipseBar.prototype:RegisterOnUpdate() +function EclipseBar.prototype:ShouldRegisterOnUpdate() return false end @@ -146,7 +144,7 @@ function EclipseBar.prototype:CreateSolarBar() end function EclipseBar.prototype:UpdateShown() - local form = GetShapeshiftFormID(); + local form = GetShapeshiftFormID() if form == MOONKIN_FORM or not form then if GetPrimaryTalentTree() == 1 then @@ -206,8 +204,8 @@ function EclipseBar.prototype:UpdateEclipsePower() self:PositionMarker(1, pos) end -function EclipseBar.prototype:Update() - EclipseBar.super.prototype.Update(self) +function EclipseBar.prototype:MyOnUpdate() + self:Update() self:UpdateEclipsePower() self:UpdateBar(0.5, self.barUpdateColor, 1) diff --git a/modules/PetMana.lua b/modules/PetMana.lua index f5ec678..ef8229c 100644 --- a/modules/PetMana.lua +++ b/modules/PetMana.lua @@ -102,13 +102,17 @@ end function PetMana.prototype:SetupOnUpdate(enable) if enable then - self.frame:SetScript("OnUpdate", function() self:Update(self.unit) end) + if not self.CustomOnUpdate then + self.CustomOnUpdate = function() self:Update(self.unit) end + end + + IceHUD.IceCore:RequestUpdates(self, self.CustomOnUpdate) else -- make sure the animation has a chance to finish filling up the bar before we cut it off completely if self.CurrScale ~= self.DesiredScale then - self.frame:SetScript("OnUpdate", function() self:MyOnUpdate() end) + IceHUD.IceCore:RequestUpdates(self, self.MyOnUpdateFunc) else - self.frame:SetScript("OnUpdate", nil) + IceHUD.IceCore:RequestUpdates(self, nil) end end end diff --git a/modules/PlayerInfo.lua b/modules/PlayerInfo.lua index e3c27f6..7b31233 100644 --- a/modules/PlayerInfo.lua +++ b/modules/PlayerInfo.lua @@ -54,8 +54,10 @@ end function PlayerInfo.prototype:CreateFrame(redraw) PlayerInfo.super.prototype.CreateFrame(self, redraw) - self.frame.menu = function() - ToggleDropDownMenu(1, nil, PlayerFrameDropDown, "cursor") + if not self.frame.menu then + self.frame.menu = function() + ToggleDropDownMenu(1, nil, PlayerFrameDropDown, "cursor") + end end end @@ -68,26 +70,28 @@ StaticPopupDialogs["ICEHUD_BUFF_DISMISS_UNAVAILABLE"] = hideOnEscape = 0, } +local function OnBuffMouseUp(frame, button) + if IceHUD.WowVer >= 40000 then + StaticPopup_Show("ICEHUD_BUFF_DISMISS_UNAVAILABLE") + else +--[[ if( button == "RightButton" ) then + if buffs[i].type == "mh" then + CancelItemTempEnchantment(1) + elseif buffs[i].type == "oh" then + CancelItemTempEnchantment(2) + else + CancelUnitBuff("player", i) + end + end]] + end +end + function PlayerInfo.prototype:CreateIconFrames(parent, direction, buffs, type) local buffs = PlayerInfo.super.prototype.CreateIconFrames(self, parent, direction, buffs, type) for i = 1, IceCore.BuffLimit do if (self.moduleSettings.mouseBuff) then - buffs[i]:SetScript("OnMouseUp", function( self, button) - if IceHUD.WowVer >= 40000 then - StaticPopup_Show("ICEHUD_BUFF_DISMISS_UNAVAILABLE") - else - if( button == "RightButton" ) then - if buffs[i].type == "mh" then - CancelItemTempEnchantment(1) - elseif buffs[i].type == "oh" then - CancelItemTempEnchantment(2) - else - CancelUnitBuff("player", i) - end - end - end - end) + buffs[i]:SetScript("OnMouseUp", OnBuffMouseUp) else buffs[i]:SetScript("OnMouseUp", nil) end diff --git a/modules/PlayerMana.lua b/modules/PlayerMana.lua index c0fc6fd..37c1f18 100644 --- a/modules/PlayerMana.lua +++ b/modules/PlayerMana.lua @@ -121,6 +121,10 @@ function PlayerMana.prototype:Enable(core) self:RegisterEvent("UNIT_ENTERED_VEHICLE", "EnteringVehicle") self:RegisterEvent("UNIT_EXITED_VEHICLE", "ExitingVehicle") + if not self.CustomOnUpdate then + self.CustomOnUpdate = function() self:Update(self.unit) end + end + -- allow new 'predicted power' stuff to show the power updates constantly instead of ticking if GetCVarBool("predictedPower") then self:SetupOnUpdate(true) @@ -137,13 +141,13 @@ end function PlayerMana.prototype:SetupOnUpdate(enable) if enable then - self.frame:SetScript("OnUpdate", function() self:Update(self.unit) end) + IceHUD.IceCore:RequestUpdates(self, self.CustomOnUpdate) else -- make sure the animation has a chance to finish filling up the bar before we cut it off completely if self.CurrScale ~= self.DesiredScale then - self.frame:SetScript("OnUpdate", function() self:MyOnUpdate() end) + IceHUD.IceCore:RequestUpdates(self, self.MyOnUpdateFunc) else - self.frame:SetScript("OnUpdate", nil) + IceHUD.IceCore:RequestUpdates(self, nil) end end end @@ -186,16 +190,6 @@ function PlayerMana.prototype:Redraw() end --- OVERRIDE -function PlayerMana.prototype:UseTargetAlpha(scale) - if (self.manaType == SPELL_POWER_RAGE or self.manaType == SPELL_POWER_RUNIC_POWER) then - return (scale and (scale > 0)) - else - return PlayerMana.super.prototype.UseTargetAlpha(self, scale) - end -end - - function PlayerMana.prototype:ManaType(event, unit) if (unit ~= self.unit) then return @@ -214,6 +208,12 @@ function PlayerMana.prototype:ManaType(event, unit) end end + if self.manaType == SPELL_POWER_RAGE or self.manaType == SPELL_POWER_RUNIC_POWER then + self.bTreatEmptyAsFull = true + else + self.bTreatEmptyAsFull = false + end + self:Update(self.unit) end @@ -239,12 +239,13 @@ function PlayerMana.prototype:Update(unit, powertype) self:Show(true) end + local useTicker = self:ShouldUseTicker() -- the user can toggle the predictedPower cvar at any time and the addon will not get notified. handle it. - if not self.tickerFrame and self:ShouldUseTicker() then + if not self.tickerFrame and useTicker then self:CreateTickerFrame() end - if (self.manaType ~= SPELL_POWER_ENERGY and self:ShouldUseTicker()) then + if (self.manaType ~= SPELL_POWER_ENERGY and useTicker) then self.tickerFrame:Hide() end @@ -268,15 +269,16 @@ function PlayerMana.prototype:Update(unit, powertype) self:UpdateBar(self.manaPercentage, color) - local powerType = UnitPowerType(self.unit) - if (self.manaPercentage == 1 and powerType ~= 1 and powerType ~= 6) - or (self.manaPercentage == 0 and (powerType == 1 or powerType == 6)) then + self:ConditionalUpdateFlash() + + if (self.manaPercentage == 1 and self.manaType ~= SPELL_POWER_RAGE and self.manaType ~= SPELL_POWER_RUNIC_POWER) + or (self.manaPercentage == 0 and (self.manaType == SPELL_POWER_RAGE or self.manaType == SPELL_POWER_RUNIC_POWER)) then self:SetupOnUpdate(false) elseif GetCVarBool("predictedPower") then self:SetupOnUpdate(true) end - if self:ShouldUseTicker() then + if useTicker then -- hide ticker if rest of the bar is not visible if (self.alpha == 0) then self.tickerFrame.spark:SetVertexColor(self:GetColor("PlayerEnergy", 0)) @@ -315,7 +317,6 @@ function PlayerMana.prototype:UpdateBar(scale, color, alpha) end - function PlayerMana.prototype:UpdateEnergy(event, unit) if (unit and (unit ~= self.unit)) then return diff --git a/modules/SliceAndDice.lua b/modules/SliceAndDice.lua index ae19c74..c73504c 100644 --- a/modules/SliceAndDice.lua +++ b/modules/SliceAndDice.lua @@ -33,6 +33,8 @@ function SliceAndDice.prototype:init() self:SetDefaultColor("SliceAndDice", 0.75, 1, 0.2) self:SetDefaultColor("SliceAndDicePotential", 1, 1, 1) + + self.bTreatEmptyAsFull = true end -- 'Public' methods ----------------------------------------------------------- @@ -208,6 +210,13 @@ function SliceAndDice.prototype:GetBuffDuration(unitName, buffName) return nil, nil end +function SliceAndDice.prototype:MyOnUpdate() + SliceAndDice.super.prototype.MyOnUpdate(self) + if self.bUpdateSnd then + self:UpdateSliceAndDice(nil, self.unit, true) + end +end + function SliceAndDice.prototype:UpdateSliceAndDice(event, unit, fromUpdate) if unit and unit ~= self.unit then return @@ -228,7 +237,7 @@ function SliceAndDice.prototype:UpdateSliceAndDice(event, unit, fromUpdate) if sndEndTime and sndEndTime >= now then if not fromUpdate then - self.frame:SetScript("OnUpdate", function() self:UpdateSliceAndDice(nil, self.unit, true) end) + self.bUpdateSnd = true end self:Show(true) @@ -244,7 +253,7 @@ function SliceAndDice.prototype:UpdateSliceAndDice(event, unit, fromUpdate) if ((IceHUD.WowVer >= 30000 and GetComboPoints(self.unit, "target") == 0) or (IceHUD.WowVer < 30000 and GetComboPoints() == 0)) or not UnitExists("target") then if self.bIsVisible then - self.frame:SetScript("OnUpdate", nil) + self.bUpdateSnd = nil end if not self.moduleSettings.alwaysFullAlpha then diff --git a/modules/TargetCC.lua b/modules/TargetCC.lua index aae5f5c..6ea4486 100644 --- a/modules/TargetCC.lua +++ b/modules/TargetCC.lua @@ -316,18 +316,23 @@ function TargetCC.prototype:GetMaxDebuffDuration(unitName, debuffNames) return unpack(result) end +function TargetCC.prototype:MyOnUpdate() + TargetCC.super.prototype.MyOnUpdate(self) + self:UpdateTargetDebuffs(nil, self.unit, true) +end + function TargetCC.prototype:UpdateTargetDebuffs(event, unit, isUpdate) local name, duration, remaining + if not isUpdate then - self.frame:SetScript("OnUpdate", function() self:UpdateTargetDebuffs(nil, self.unit, true) end) self.debuffName, self.debuffDuration, self.debuffRemaining = self:GetMaxDebuffDuration(self.unit, self.debuffList) else - self.debuffRemaining = math.max(0, self.debuffRemaining - (1.0 / GetFramerate())) + self.debuffRemaining = math.max(0, self.debuffRemaining - (GetTime() - self.lastUpdateTime)) if self.debuffRemaining <= 0 then self.debuffName = nil - self.frame:SetScript("OnUpdate", nil) end end + self.lastUpdateTime = GetTime() name = self.debuffName duration = self.debuffDuration diff --git a/modules/TargetInfo.lua b/modules/TargetInfo.lua index 0ad8770..e3dadcb 100644 --- a/modules/TargetInfo.lua +++ b/modules/TargetInfo.lua @@ -899,8 +899,10 @@ function IceTargetInfo.prototype:CreateFrame(redraw) self.frame:SetAttribute("unit", self.unit) - self.frame.menu = function() - ToggleDropDownMenu(1, nil, TargetFrameDropDown, "cursor") + if not self.frame.menu then + self.frame.menu = function() + ToggleDropDownMenu(1, nil, TargetFrameDropDown, "cursor") + end end @@ -1058,6 +1060,13 @@ function IceTargetInfo.prototype:CreateIconFrames(parent, direction, buffs, type local lastX = 0 local lastBuffSize = 0 + if not self.MyOnEnterBuffFunc then + self.MyOnEnterBuffFunc = function(this) self:BuffOnEnter(this) end + end + if not self.MyOnLeaveBuffFunc then + self.MyOnLeaveBuffFunc = function() GameTooltip:Hide() end + end + for i = 1, IceCore.BuffLimit do if (not buffs[i]) then buffs[i] = CreateFrame("Frame", nil, parent) @@ -1149,8 +1158,8 @@ function IceTargetInfo.prototype:CreateIconFrames(parent, direction, buffs, type buffs[i].id = i if (self.moduleSettings.mouseBuff) then buffs[i]:EnableMouse(true) - buffs[i]:SetScript("OnEnter", function(this, ...) self:BuffOnEnter(this, buffs[i].type or type) end) - buffs[i]:SetScript("OnLeave", function() GameTooltip:Hide() end) + buffs[i]:SetScript("OnEnter", self.MyOnEnterBuffFunc) + buffs[i]:SetScript("OnLeave", self.MyOnLeaveBuffFunc) else buffs[i]:EnableMouse(false) buffs[i]:SetScript("OnEnter", nil) @@ -1532,11 +1541,32 @@ function IceTargetInfo.prototype:OnLeave(frame) end -function IceTargetInfo.prototype:BuffOnEnter(this, type) +function IceTargetInfo.prototype:BuffOnEnter(this) if (not self:IsVisible()) then return end + local type = nil + for i = 1, IceCore.BuffLimit do + if self.frame.buffFrame.buffs[i] and self.frame.buffFrame.buffs[i] == this then + type = self.frame.buffFrame.buffs[i].type + break + end + end + + if not type then + for i = 1, IceCore.BuffLimit do + if self.frame.debuffFrame.buffs[i] and self.frame.debuffFrame.buffs[i] == this then + type = self.frame.debuffFrame.buffs[i].type + break + end + end + end + + if not type then + return + end + GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT") if (type == "buff") then GameTooltip:SetUnitBuff(self.unit, this.id) diff --git a/modules/TargetInvuln.lua b/modules/TargetInvuln.lua index 9a99113..4c05b32 100644 --- a/modules/TargetInvuln.lua +++ b/modules/TargetInvuln.lua @@ -174,20 +174,24 @@ function TargetInvuln.prototype:GetMaxbuffDuration(unitName, buffNames) return unpack(result) end +function TargetInvuln.prototype:MyOnUpdate() + TargetInvuln.super.prototype.MyOnUpdate(self) + self:UpdateTargetBuffs(nil, self.unit, true) +end + function TargetInvuln.prototype:UpdateTargetBuffs(event, unit, isUpdate) local name, duration, remaining - if not isUpdate then - self.frame:SetScript("OnUpdate", function() self:UpdateTargetBuffs(nil, self.unit, true) end) - self.buffName, self.buffDuration, self.buffRemaining = self:GetMaxbuffDuration(self.unit, self.buffList) + if not isUpdate then + self.buffName, self.buffDuration, self.buffRemaining = self:GetMaxbuffDuration(self.unit, self.buffList) else - self.buffRemaining = math.max(0, self.buffRemaining - (1.0 / GetFramerate())) + self.buffRemaining = math.max(0, self.buffRemaining - (GetTime() - self.lastUpdateTime)) if self.buffRemaining <= 0 then self.buffName = nil - self.frame:SetScript("OnUpdate", nil) end end + self.lastUpdateTime = GetTime() name = self.buffName duration = self.buffDuration diff --git a/modules/Threat.lua b/modules/Threat.lua index 850bb43..d369749 100644 --- a/modules/Threat.lua +++ b/modules/Threat.lua @@ -32,6 +32,8 @@ function IceThreat.prototype:init(name, unit) self:SetDefaultColor("ThreatCustom", 255, 255, 0) self:SetDefaultColor("ThreatPullAggro", 255, 0, 0) self:SetDefaultColor("ThreatSecondPlace", 255, 255, 0) + + self.bTreatEmptyAsFull = true end -- default settings @@ -191,11 +193,6 @@ function IceThreat.prototype:CreateFrame() self:CreateSecondThreatBar() end --- needs to be inverted for threat bar -function IceThreat.prototype:UseTargetAlpha(scale) - return (scale and (scale > 0)) -end - -- create the aggro range indicator bar function IceThreat.prototype:CreateAggroBar() if not (self.aggroBar) then diff --git a/modules/Vengeance.lua b/modules/Vengeance.lua index 8695573..e62a878 100644 --- a/modules/Vengeance.lua +++ b/modules/Vengeance.lua @@ -12,11 +12,12 @@ function Vengeance.prototype:init() Vengeance.super.prototype.init(self, "Vengeance", "player") self.current = 0 - self.max = floor(0.1*UnitHealthMax(self.unit)) self.tooltipBuffer = CreateFrame("GameTooltip","tooltipBuffer",nil,"GameTooltipTemplate") self.tooltipBuffer:SetOwner(WorldFrame, "ANCHOR_NONE") self:SetDefaultColor("Vengeance", 200, 45, 45) + + self.bTreatEmptyAsFull = true end -- default settings @@ -50,11 +51,6 @@ function Vengeance.prototype:Disable(core) self:UnregisterAllEvents() end --- OVERRIDE -function Vengeance.prototype:UseTargetAlpha(scale) - return (scale and (scale > 0)) -end - function Vengeance.prototype:UpdateCurrent(event, unit) if (unit and (unit ~= self.unit)) then return