diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index 3f239ed..9e6f476 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -4106,7 +4106,7 @@ Private.event_prototypes = { { name = "count", display = L["Count"], - desc = L["Occurence of the event, reset when aura is unloaded\nCan be a range of values\nCan have multiple values separated by a comma or a space\n\nExamples:\n2nd 5th and 6th events: 2, 5, 6\n2nd to 6th: 2-6\nevery 2 events: /2\nevery 3 events starting from 2nd: 2/3\nevery 3 events starting from 2nd and ending at 11th: 2-11/3\n\nOnly if DBM shows it on it's bar"], + desc = L["Occurrence of the event, reset when aura is unloaded\nCan be a range of values\nCan have multiple values separated by a comma or a space\n\nExamples:\n2nd 5th and 6th events: 2, 5, 6\n2nd to 6th: 2-6\nevery 2 events: /2\nevery 3 events starting from 2nd: 2/3\nevery 3 events starting from 2nd and ending at 11th: 2-11/3\n\nOnly if DBM shows it on it's bar"], type = "string", conditionType = "string", }, @@ -4341,7 +4341,7 @@ Private.event_prototypes = { { name = "count", display = L["Count"], - desc = L["Occurence of the event, reset when aura is unloaded\nCan be a range of values\nCan have multiple values separated by a comma or a space\n\nExamples:\n2nd 5th and 6th events: 2, 5, 6\n2nd to 6th: 2-6\nevery 2 events: /2\nevery 3 events starting from 2nd: 2/3\nevery 3 events starting from 2nd and ending at 11th: 2-11/3\n\nOnly if BigWigs shows it on it's bar"], + desc = L["Occurrence of the event, reset when aura is unloaded\nCan be a range of values\nCan have multiple values separated by a comma or a space\n\nExamples:\n2nd 5th and 6th events: 2, 5, 6\n2nd to 6th: 2-6\nevery 2 events: /2\nevery 3 events starting from 2nd: 2/3\nevery 3 events starting from 2nd and ending at 11th: 2-11/3\n\nOnly if BigWigs shows it on it's bar"], type = "string", conditionType = "string", }, diff --git a/WeakAuras/RegionTypes/AuraBar.lua b/WeakAuras/RegionTypes/AuraBar.lua index bb785c8..1e10b83 100644 --- a/WeakAuras/RegionTypes/AuraBar.lua +++ b/WeakAuras/RegionTypes/AuraBar.lua @@ -1012,7 +1012,7 @@ local function create(parent) -- Create statusbar (inherit prototype) local bar = CreateFrame("Frame", nil, region); - WeakAuras.Mixin(bar, SmoothStatusBarMixin); + WeakAuras.Mixin(bar, Private.SmoothStatusBarMixin); local fg = bar:CreateTexture(nil, "BORDER"); local bg = region:CreateTexture(nil, "BACKGROUND"); bg:SetAllPoints(bar); diff --git a/WeakAuras/RegionTypes/ProgressTexture.lua b/WeakAuras/RegionTypes/ProgressTexture.lua index 436e494..060de36 100644 --- a/WeakAuras/RegionTypes/ProgressTexture.lua +++ b/WeakAuras/RegionTypes/ProgressTexture.lua @@ -446,7 +446,7 @@ local function create(parent) -- Use a dummy object for the SmoothStatusBarMixin, because our SetValue -- is used for a different purpose region.smoothProgress = {}; - WeakAuras.Mixin(region.smoothProgress, SmoothStatusBarMixin); + WeakAuras.Mixin(region.smoothProgress, Private.SmoothStatusBarMixin); region.smoothProgress.SetValue = function(self, progress) region:SetValueOnTexture(progress); end diff --git a/WeakAuras/RegionTypes/SmoothStatusBarMixin.lua b/WeakAuras/RegionTypes/SmoothStatusBarMixin.lua new file mode 100644 index 0000000..2c60bcd --- /dev/null +++ b/WeakAuras/RegionTypes/SmoothStatusBarMixin.lua @@ -0,0 +1,65 @@ +if not WeakAuras.IsLibsOK() then return end + +local AddonName, Private = ... + +-- This is a more or less 1:1 copy of SmoothStatusBarMixin except that it +-- doesn't clamp the targetValue in ProcesSmoothStatusBars, because that's incorrect for us +local g_updatingBars = {}; + +local function IsCloseEnough(bar, newValue, targetValue) + local min, max = bar:GetMinMaxValues(); + local range = max - min; + if range > 0.0 then + return math.abs((newValue - targetValue) / range) < 0.00001; + end + + return true; +end + +local function ProcessSmoothStatusBars(self, elapsed) + for bar, targetValue in pairs(g_updatingBars) do + local newValue = FrameDeltaLerp(bar:GetValue(), targetValue, 0.25, elapsed); + + if IsCloseEnough(bar, newValue, targetValue) then + g_updatingBars[bar] = nil; + bar:SetValue(targetValue); + else + bar:SetValue(newValue); + end + end +end + +CreateFrame("Frame"):SetScript("OnUpdate", ProcessSmoothStatusBars); + +Private.SmoothStatusBarMixin = {}; + +function Private.SmoothStatusBarMixin:ResetSmoothedValue(value) --If nil, tries to set to the last target value + local targetValue = g_updatingBars[self]; + if targetValue then + g_updatingBars[self] = nil; + self:SetValue(value or targetValue); + elseif value then + self:SetValue(value); + end +end + +function Private.SmoothStatusBarMixin:SetSmoothedValue(value) + g_updatingBars[self] = value; +end + +function Private.SmoothStatusBarMixin:SetMinMaxSmoothedValue(min, max) + self:SetMinMaxValues(min, max); + + local targetValue = g_updatingBars[self]; + if targetValue then + local ratio = 1; + if max ~= 0 and self.lastSmoothedMax and self.lastSmoothedMax ~= 0 then + ratio = max / self.lastSmoothedMax; + end + + g_updatingBars[self] = targetValue * ratio; + end + + self.lastSmoothedMin = min; + self.lastSmoothedMax = max; +end diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index 10d60e3..e9d54d8 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -3561,7 +3561,6 @@ function WeakAuras.GetAuraTooltipInfo(unit, index, filter) local tooltipText = tooltipTextLine and tooltipTextLine:GetObjectType() == "FontString" and tooltipTextLine:GetText() or ""; local debuffType = "none"; - local found = false; local tooltipSize = {}; if(tooltipText) then for t in tooltipText:gmatch("(%d[%d%.,]*)") do @@ -5013,11 +5012,11 @@ local function GetAnchorFrame(data, region, parent) if unit then local frame = unit and WeakAuras.GetNamePlateForUnit(unit) if frame then return frame end - end - if WeakAuras.IsOptionsOpen() then - Private.ensurePRDFrame() - personalRessourceDisplayFrame:anchorFrame(id, anchorFrameType) - return personalRessourceDisplayFrame + if WeakAuras.IsOptionsOpen() then + Private.ensurePRDFrame() + personalRessourceDisplayFrame:anchorFrame(id, anchorFrameType) + return personalRessourceDisplayFrame + end end end diff --git a/WeakAuras/WeakAuras.toc b/WeakAuras/WeakAuras.toc index 5f0602f..05dd046 100644 --- a/WeakAuras/WeakAuras.toc +++ b/WeakAuras/WeakAuras.toc @@ -52,6 +52,7 @@ DebugLog.lua SubscribableObject.lua # Region support +RegionTypes\SmoothStatusBarMixin.lua RegionTypes\RegionPrototype.lua RegionTypes\ProgressTexture.lua RegionTypes\Texture.lua diff --git a/WeakAuras/compat.lua b/WeakAuras/compat.lua index 1172119..f6f24d7 100644 --- a/WeakAuras/compat.lua +++ b/WeakAuras/compat.lua @@ -80,91 +80,29 @@ RAID_CLASS_COLORS.SHAMAN.colorStr = "ff0070de" RAID_CLASS_COLORS.WARRIOR.colorStr = "ffc79c6e" RAID_CLASS_COLORS.DEATHKNIGHT.colorStr = "ffc41f3b" -if not SmoothStatusBarMixin then - function Lerp(startValue, endValue, amount) - return (1 - amount) * startValue + amount * endValue; +function Clamp(value, min, max) + if value > max then + return max; + elseif value < min then + return min; end + return value; +end - function Clamp(value, min, max) - if value > max then - return max; - elseif value < min then - return min; - end - return value; - end +-- This section is mostly used by Private.SmoothStatusBarMixin +function Lerp(startValue, endValue, amount) + return (1 - amount) * startValue + amount * endValue; +end - function Saturate(value) - return Clamp(value, 0, 1); - end +function Saturate(value) + return Clamp(value, 0, 1); +end - local TARGET_FRAME_PER_SEC = 60; - function DeltaLerp(startValue, endValue, amount, timeSec) - return Lerp(startValue, endValue, Saturate(amount * timeSec * TARGET_FRAME_PER_SEC)); - end +local TARGET_FRAME_PER_SEC = 60.0; +function DeltaLerp(startValue, endValue, amount, timeSec) + return Lerp(startValue, endValue, Saturate(amount * timeSec * TARGET_FRAME_PER_SEC)); +end - function FrameDeltaLerp(startValue, endValue, amount, elapsed) - return DeltaLerp(startValue, endValue, amount, elapsed); - end - - local g_updatingBars = {}; - - local function IsCloseEnough(bar, newValue, targetValue) - local min, max = bar:GetMinMaxValues(); - local range = max - min; - if range > 0 then - return abs((newValue - targetValue) / range) < .00001; - end - - return true; - end - - local function ProcessSmoothStatusBars(self, elapsed) - for bar, targetValue in pairs(g_updatingBars) do - local effectiveTargetValue = Clamp(targetValue, bar:GetMinMaxValues()); - local newValue = FrameDeltaLerp(bar:GetValue(), effectiveTargetValue, .25, elapsed); - - if IsCloseEnough(bar, newValue, effectiveTargetValue) then - g_updatingBars[bar] = nil; - bar:SetValue(effectiveTargetValue); - else - bar:SetValue(newValue); - end - end - end - - CreateFrame("Frame"):SetScript("OnUpdate", ProcessSmoothStatusBars) - - SmoothStatusBarMixin = {}; - - function SmoothStatusBarMixin:ResetSmoothedValue(value) --If nil, tries to set to the last target value - local targetValue = g_updatingBars[self]; - if targetValue then - g_updatingBars[self] = nil; - self:SetValue(value or targetValue); - elseif value then - self:SetValue(value); - end - end - - function SmoothStatusBarMixin:SetSmoothedValue(value) - g_updatingBars[self] = value; - end - - function SmoothStatusBarMixin:SetMinMaxSmoothedValue(min, max) - self:SetMinMaxValues(min, max); - - local targetValue = g_updatingBars[self]; - if targetValue then - local ratio = 1; - if max ~= 0 and self.lastSmoothedMax and self.lastSmoothedMax ~= 0 then - ratio = max / self.lastSmoothedMax; - end - - g_updatingBars[self] = targetValue * ratio; - end - - self.lastSmoothedMin = min; - self.lastSmoothedMax = max; - end -end \ No newline at end of file +function FrameDeltaLerp(startValue, endValue, amount, elapsed) + return DeltaLerp(startValue, endValue, amount, elapsed); +end