Refactor progress handling

probably some regressions
This commit is contained in:
NoM0Re
2025-01-22 03:37:10 +01:00
parent a643b275ba
commit 23c7da5ea6
29 changed files with 2037 additions and 1263 deletions
+45 -128
View File
@@ -9,6 +9,7 @@ local default = {
icon = false,
desaturate = false,
iconSource = -1,
progressSource = {-1, "" },
texture = "Blizzard",
width = 200,
height = 15,
@@ -38,7 +39,7 @@ local default = {
zoom = 0
};
Private.regionPrototype.AddAdjustedDurationToDefault(default);
Private.regionPrototype.AddProgressSourceToDefault(default)
Private.regionPrototype.AddAlphaToDefault(default);
local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20;
@@ -66,7 +67,7 @@ local properties = {
values = {}
},
displayIcon = {
display = {L["Icon"], L["Fallback"]},
display = {L["Icon"], L["Manual"]},
setter = "SetIcon",
type = "icon",
},
@@ -149,6 +150,7 @@ local function GetProperties(data)
end
auraProperties.iconSource.values = Private.IconSources(data)
auraProperties.progressSource.values = Private.GetProgressSourcesForUi(data)
return auraProperties;
end
@@ -725,6 +727,17 @@ local function GetTexCoordZoom(texWidth)
return unpack(texCoord)
end
local function FrameTick(self)
local expirationTime = self.expirationTime
local remaining = expirationTime - GetTime()
local duration = self.duration
local progress = duration ~= 0 and remaining / duration or 0;
if self.inverse then
progress = 1 - progress;
end
self:SetProgress(progress)
end
local funcs = {
AnchorSubRegion = function(self, subRegion, anchorType, selfPoint, anchorPoint, anchorXOffset, anchorYOffset)
if anchorType == "area" then
@@ -816,12 +829,7 @@ local funcs = {
self.height = height;
self:Scale(self.scalex, self.scaley);
end,
SetValue = function(self, value, total)
local progress = 0;
if (total ~= 0) then
progress = value / total;
end
SetProgress = function(self, progress)
if self.inverseDirection then
progress = 1 - progress;
end
@@ -833,22 +841,31 @@ local funcs = {
self.bar:SetValue(progress);
end
end,
SetTime = function(self, duration, expirationTime, inverse)
local remaining = expirationTime - GetTime();
local progress = duration ~= 0 and remaining / duration or 0;
-- Need to invert?
if (
(self.inverseDirection and not inverse)
or (inverse and not self.inverseDirection)
)
then
UpdateValue = function(self)
local progress = 0;
if (self.total ~= 0) then
progress = self.value / self.total;
end
self:SetProgress(progress)
if self.FrameTick then
self.FrameTick = nil
self.subRegionEvents:RemoveSubscriber("FrameTick", self)
end
end,
UpdateTime = function(self)
local remaining = self.expirationTime - GetTime();
local progress = self.duration ~= 0 and remaining / self.duration or 0;
if self.inverse then
progress = 1 - progress;
end
if (self.smoothProgress) then
self.bar.targetValue = progress
self.bar:SetSmoothedValue(progress);
else
self.bar:SetValue(progress);
self:SetProgress(progress)
if self.paused and self.FrameTick then
self.FrameTick = nil
self.subRegionEvents:RemoveSubscriber("FrameTick", self)
end
if not self.paused and not self.FrameTick then
self.FrameTick = FrameTick
self.subRegionEvents:AddSubscriber("FrameTick", self)
end
end,
SetInverse = function(self, inverse)
@@ -1061,14 +1078,6 @@ local function create(parent)
return region;
end
local function TimerTick(self)
local state = self.state
local duration = state.duration or 0
local adjustMin = self.adjustedMin or self.adjustedMinRel or 0;
local expirationTime = state.expirationTime and state.expirationTime > 0 and state.expirationTime or math.huge;
self:SetTime((duration ~= 0 and (self.adjustedMax or self.adjustedMaxRel) or duration) - adjustMin, expirationTime - adjustMin, state.inverse);
end
-- Modify a given region/display
local function modify(parent, region, data)
region.timer = nil
@@ -1201,107 +1210,15 @@ local function modify(parent, region, data)
region.tooltipFrame:EnableMouse(false);
end
function region:UpdateMinMax()
local state = region.state
local min
local max
if state.progressType == "timed" then
local duration = state.duration or 0
if region.adjustedMinRelPercent then
region.adjustedMinRel = region.adjustedMinRelPercent * duration
end
min = region.adjustedMin or region.adjustedMinRel or 0;
if duration == 0 then
max = 0
elseif region.adjustedMax then
max = region.adjustedMax
elseif region.adjustedMaxRelPercent then
region.adjustedMaxRel = region.adjustedMaxRelPercent * duration
max = region.adjustedMaxRel
else
max = duration
end
elseif state.progressType == "static" then
local total = state.total or 0;
if region.adjustedMinRelPercent then
region.adjustedMinRel = region.adjustedMinRelPercent * total
end
min = region.adjustedMin or region.adjustedMinRel or 0;
if region.adjustedMax then
max = region.adjustedMax
elseif region.adjustedMaxRelPercent then
region.adjustedMaxRel = region.adjustedMaxRelPercent * total
max = region.adjustedMaxRel
else
max = total
end
end
region.currentMin, region.currentMax = min, max
end
function region:GetMinMax()
return region.currentMin or 0, region.currentMax or 0
end
region.TimerTick = nil
region.FrameTick = nil
function region:Update()
local state = region.state
region:UpdateMinMax()
if state.progressType == "timed" then
local expirationTime
if state.paused == true then
if not region.paused then
region:Pause()
end
if region.TimerTick then
region.TimerTick = nil
region.subRegionEvents:RemoveSubscriber("TimerTick", self)
end
expirationTime = GetTime() + (state.remaining or 0)
else
if region.paused then
region:Resume()
end
if not region.TimerTick then
region.TimerTick = TimerTick
region.subRegionEvents:AddSubscriber("TimerTick", self, true)
end
expirationTime = state.expirationTime and state.expirationTime > 0 and state.expirationTime or math.huge;
end
local duration = state.duration or 0
region:SetTime(region.currentMax - region.currentMin, expirationTime - region.currentMin, state.inverse);
elseif state.progressType == "static" then
if region.paused then
region:Resume()
end
local value = state.value or 0;
local total = state.total or 0;
region:SetValue(value - region.currentMin, region.currentMax - region.currentMin);
if region.TimerTick then
region.TimerTick = nil
region.subRegionEvents:RemoveSubscriber("TimerTick", region)
end
else
if region.paused then
region:Resume()
end
region:SetTime(0, math.huge)
if region.TimerTick then
region.TimerTick = nil
region.subRegionEvents:RemoveSubscriber("TimerTick", region)
end
end
region:UpdateProgress()
region:UpdateIcon()
end
local duration = state.duration or 0
local effectiveInverse = (state.inverse and not region.inverseDirection) or (not state.inverse and region.inverseDirection);
region.bar:SetAdditionalBars(state.additionalProgress, region.overlays, region.overlaysTexture, region.currentMin, region.currentMax, effectiveInverse, region.overlayclip);
function region:SetAdditionalProgress(additionalProgress, currentMin, currentMax, inverse)
local effectiveInverse = (inverse and not region.inverseDirection) or (not inverse and region.inverseDirection);
region.bar:SetAdditionalBars(additionalProgress, region.overlays, region.overlaysTexture, currentMin, currentMax, effectiveInverse, region.overlayclip);
end
-- Scale update function
+52 -82
View File
@@ -19,6 +19,7 @@ local default = {
icon = true,
desaturate = false,
iconSource = -1,
progressSource = {-1, "" },
inverse = false,
width = 64,
height = 64,
@@ -35,6 +36,7 @@ local default = {
cooldownEdge = false
};
Private.regionPrototype.AddProgressSourceToDefault(default)
Private.regionPrototype.AddAlphaToDefault(default);
local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20;
@@ -95,7 +97,7 @@ local properties = {
values = {}
},
displayIcon = {
display = {L["Icon"], L["Fallback"]},
display = {L["Icon"], L["Manual"]},
setter = "SetIcon",
type = "icon",
}
@@ -106,12 +108,11 @@ Private.regionPrototype.AddProperties(properties, default);
local function GetProperties(data)
local result = CopyTable(properties)
result.iconSource.values = Private.IconSources(data)
result.progressSource.values = Private.GetProgressSourcesForUi(data)
return result
end
local function GetTexCoord(region, texWidth, aspectRatio, xOffset, yOffset)
xOffset = xOffset or 0
yOffset = yOffset or 0
region.currentCoord = region.currentCoord or {}
local usesMasque = false
if region.MSQGroup then
@@ -430,8 +431,8 @@ local function modify(parent, region, data)
region.scaley = 1;
region.keepAspectRatio = data.keepAspectRatio;
region.zoom = data.zoom;
region.texXOffset = data.texXOffset
region.texYOffset = data.texYOffset
region.texXOffset = data.texXOffset or 0
region.texYOffset = data.texYOffset or 0
region:UpdateSize()
icon:SetDesaturated(data.desaturate);
@@ -451,7 +452,27 @@ local function modify(parent, region, data)
region.tooltipFrame:EnableMouse(false);
end
cooldown:SetReverse(not data.inverse);
function region:SetInverse(inverse)
if region.inverse == inverse then
return
end
region.inverse = inverse
region:UpdateEffectiveInverse()
end
function region:UpdateEffectiveInverse()
-- If cooldown.inverse == false then effectiveReverse = not inverse
-- If cooldown.inverse == true then effectiveReverse = inverse
local effectiveReverse = not region.inverse == not cooldown.inverse
cooldown:SetReverse(effectiveReverse)
if (cooldown.expirationTime and cooldown.duration and cooldown:IsShown()) then
-- WORKAROUND SetReverse not applying until next frame
cooldown:SetCooldown(0, 0)
cooldown:SetCooldown(cooldown.expirationTime - cooldown.duration,
cooldown.duration,
cooldown.useCooldownModRate and cooldown.modRate or nil)
end
end
region:SetInverse(data.inverse)
function region:Color(r, g, b, a)
region.color_r = r;
@@ -545,15 +566,6 @@ local function modify(parent, region, data)
region:UpdateSize();
end
function region:SetInverse(inverse)
cooldown:SetReverse(not inverse);
if (cooldown.expirationTime and cooldown.duration and cooldown:IsShown()) then
-- WORKAROUND SetReverse not applying until next frame
cooldown:SetCooldown(0, 0);
cooldown:SetCooldown(cooldown.expirationTime - cooldown.duration, cooldown.duration);
end
end
function region:SetCooldownEdge(cooldownEdge)
region.cooldownEdge = cooldownEdge;
cooldown:SetDrawEdge(cooldownEdge);
@@ -570,32 +582,40 @@ local function modify(parent, region, data)
cooldown.duration = nil;
cooldown:Hide()
if(data.cooldown) then
function region:SetValue(value, total)
cooldown.value = value
cooldown.total = total
if (value >= 0 and value <= total) then
function region:UpdateValue()
cooldown.value = self.value
cooldown.total = self.total
if (self.value >= 0 and self.value <= self.total) then
cooldown:Show()
cooldown:SetCooldown(GetTime() - (total - value), total)
cooldown:SetCooldown(GetTime() - (self.total - self.value), self.total)
cooldown:Pause()
else
cooldown:Hide();
end
end
function region:SetTime(duration, expirationTime)
if (duration > 0 and expirationTime > GetTime()) then
cooldown:Show();
cooldown.expirationTime = expirationTime;
cooldown.duration = duration;
cooldown:SetCooldown(expirationTime - duration, duration);
function region:UpdateTime()
if self.paused then
cooldown:Pause()
else
cooldown.expirationTime = expirationTime;
cooldown.duration = duration;
cooldown:Resume()
end
if (self.duration > 0 and self.expirationTime > GetTime() and self.expirationTime ~= math.huge) then
cooldown:Show();
cooldown.expirationTime = self.expirationTime
cooldown.duration = self.duration
cooldown.inverse = self.inverse
region:UpdateEffectiveInverse()
cooldown:SetCooldown(self.expirationTime - self.duration, self.duration)
else
cooldown.expirationTime = self.expirationTime
cooldown.duration = self.duration
cooldown:Hide();
end
end
function region:PreShow()
if (cooldown.duration and cooldown.duration > 0.01) then
if (cooldown.duration and cooldown.duration > 0.01 and cooldown.duration ~= math.huge and cooldown.expirationTime ~= math.huge) then
cooldown:Show();
cooldown:SetCooldown(cooldown.expirationTime - cooldown.duration, cooldown.duration);
cooldown:Resume()
@@ -603,64 +623,14 @@ local function modify(parent, region, data)
end
function region:Update()
local state = region.state
if state.progressType == "timed" then
local expirationTime
if state.paused == true then
if not region.paused then
region:Pause()
end
cooldown:Pause()
expirationTime = GetTime() + (state.remaining or 0)
else
if region.paused then
region:Resume()
end
cooldown:Resume()
expirationTime = state.expirationTime and state.expirationTime > 0 and state.expirationTime or math.huge;
end
local duration = state.duration or 0
if region.adjustedMinRelPercent then
region.adjustedMinRel = region.adjustedMinRelPercent * duration
end
local adjustMin = region.adjustedMin or region.adjustedMinRel or 0;
local max
if duration == 0 then
max = 0
elseif region.adjustedMax then
max = region.adjustedMax
elseif region.adjustedMaxRelPercent then
region.adjustedMaxRel = region.adjustedMaxRelPercent * duration
max = region.adjustedMaxRel
else
max = duration
end
region:SetTime(max - adjustMin, expirationTime - adjustMin, state.inverse);
elseif state.progressType == "static" then
local value = state.value or 0;
local total = state.total or 0;
if region.adjustedMinRelPercent then
region.adjustedMinRel = region.adjustedMinRelPercent * total
end
local adjustMin = region.adjustedMin or region.adjustedMinRel or 0;
local max = region.adjustedMax or region.adjustedMaxRel or total;
region:SetValue(value - adjustMin, max - adjustMin);
cooldown:Pause()
else
region:SetTime(0, math.huge)
end
region:UpdateProgress()
region:UpdateIcon()
end
else
region.SetValue = nil
region.SetTime = nil
region.UpdateValue = nil
region.UpdateTime = nil
function region:Update()
local state = region.state
region:UpdateIcon()
end
end
+57 -100
View File
@@ -80,6 +80,7 @@ local function Transform(tx, x, y, angle, aspect) -- Translates texture to x, y
end
local default = {
progressSource = {-1, "" },
foregroundTexture = "Interface\\Addons\\WeakAuras\\PowerAurasMedia\\Auras\\Aura3",
backgroundTexture = "Interface\\Addons\\WeakAuras\\PowerAurasMedia\\Auras\\Aura3",
desaturateBackground = false,
@@ -115,7 +116,7 @@ local default = {
Private.regionPrototype.AddAlphaToDefault(default);
Private.regionPrototype.AddAdjustedDurationToDefault(default);
Private.regionPrototype.AddProgressSourceToDefault(default)
local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20;
@@ -180,9 +181,9 @@ Private.regionPrototype.AddProperties(properties, default);
local function GetProperties(data)
local overlayInfo = Private.GetOverlayInfo(data);
local auraProperties = CopyTable(properties)
auraProperties.progressSource.values = Private.GetProgressSourcesForUi(data)
if (overlayInfo and next(overlayInfo)) then
local auraProperties = CopyTable(properties);
for id, display in ipairs(overlayInfo) do
auraProperties["overlays." .. id] = {
display = string.format(L["%s Overlay Color"], display),
@@ -191,10 +192,9 @@ local function GetProperties(data)
type = "color",
}
end
return auraProperties;
return auraProperties
else
return CopyTable(properties);
return auraProperties
end
end
@@ -467,10 +467,27 @@ local function create(parent)
return region;
end
local function TimerTick(self)
local adjustMin = self.adjustedMin or self.adjustedMinRel or 0;
local duration = self.state.duration
self:SetTime( (duration ~= 0 and (self.adjustedMax or self.adjustedMaxRel) or duration) - adjustMin, self.state.expirationTime - adjustMin, self.state.inverse);
local function FrameTick(self)
local duration = self.duration
local expirationTime = self.expirationTime
local inverse = self.inverse
local progress = 1;
if (duration ~= 0) then
local remaining = expirationTime - GetTime();
progress = remaining / duration;
local inversed = (not inverse and self.inverseDirection) or (inverse and not self.inverseDirection);
if(inversed) then
progress = 1 - progress;
end
end
progress = progress > 0.0001 and progress or 0.0001;
if (self.useSmoothProgress) then
self.smoothProgress:SetSmoothedValue(progress);
else
self:SetValueOnTexture(progress);
end
end
local function modify(parent, region, data)
@@ -486,6 +503,7 @@ local function modify(parent, region, data)
region.scalex = 1;
region.scaley = 1;
region.aspect = data.width / data.height;
region.useSmoothProgress = data.smoothProgress
foreground:SetWidth(data.width);
foreground:SetHeight(data.height);
local scaleWedge = 1 / 1.4142 * (1 + (data.crop or 0.41));
@@ -843,123 +861,62 @@ local function modify(parent, region, data)
region:Color(data.foregroundColor[1], data.foregroundColor[2], data.foregroundColor[3], data.foregroundColor[4]);
function region:SetTime(duration, expirationTime, inverse)
function region:UpdateTime()
local progress = 1;
if (duration ~= 0) then
local remaining = expirationTime - GetTime();
progress = remaining / duration;
local inversed = (not inverse and region.inverseDirection) or (inverse and not region.inverseDirection);
if (self.duration ~= 0) then
local remaining = self.expirationTime - GetTime()
progress = remaining / self.duration
local inversed = self.inverse ~= region.inverseDirection
if(inversed) then
progress = 1 - progress;
end
end
progress = progress > 0.0001 and progress or 0.0001;
if (data.smoothProgress) then
if (region.useSmoothProgress) then
region.smoothProgress:SetSmoothedValue(progress);
else
region:SetValueOnTexture(progress);
end
if self.paused and self.FrameTick then
self.FrameTick = nil
self.subRegionEvents:RemoveSubscriber("FrameTick", region)
end
if not self.paused and not self.FrameTick then
self.FrameTick = FrameTick
self.subRegionEvents:AddSubscriber("FrameTick", region)
end
end
function region:SetValue(value, total)
function region:UpdateValue()
local progress = 1
if(total > 0) then
progress = value / total;
if(self.total > 0) then
progress = self.value / self.total;
if(region.inverseDirection) then
progress = 1 - progress;
end
end
progress = progress > 0.0001 and progress or 0.0001;
if (data.smoothProgress) then
if (region.useSmoothProgress) then
region.smoothProgress:SetSmoothedValue(progress);
else
region:SetValueOnTexture(progress);
end
end
region.TimerTick = nil
function region:Update()
local state = region.state
local max
if state.progressType == "timed" then
local expirationTime
if state.paused == true then
if not region.paused then
region:Pause()
end
if region.TimerTick then
region.TimerTick = nil
region.subRegionEvents:RemoveSubscriber("TimerTick", region)
end
expirationTime = GetTime() + (state.remaining or 0)
else
if region.paused then
region:Resume()
end
if not region.TimerTick then
region.TimerTick = TimerTick
region.subRegionEvents:AddSubscriber("TimerTick", region, true)
end
expirationTime = state.expirationTime and state.expirationTime > 0 and state.expirationTime or math.huge;
end
local duration = state.duration or 0
if region.adjustedMinRelPercent then
region.adjustedMinRel = region.adjustedMinRelPercent * duration
end
local adjustMin = region.adjustedMin or region.adjustedMinRel or 0;
if duration == 0 then
max = 0
elseif region.adjustedMax then
max = region.adjustedMax
elseif region.adjustedMaxRelPercent then
region.adjustedMaxRel = region.adjustedMaxRelPercent * duration
max = region.adjustedMaxRel
else
max = duration
end
region:SetTime(max - adjustMin, expirationTime - adjustMin, state.inverse);
elseif state.progressType == "static" then
if region.paused then
region:Resume()
end
local value = state.value or 0;
local total = state.total or 0;
if region.adjustedMinRelPercent then
region.adjustedMinRel = region.adjustedMinRelPercent * total
end
local adjustMin = region.adjustedMin or region.adjustedMinRel or 0;
if region.adjustedMax then
max = region.adjustedMax
elseif region.adjustedMaxRelPercent then
region.adjustedMaxRel = region.adjustedMaxRelPercent * total
max = region.adjustedMaxRel
else
max = total
end
region:SetValue(value - adjustMin, max - adjustMin);
if region.TimerTick then
region.TimerTick = nil
region.subRegionEvents:RemoveSubscriber("TimerTick", region)
end
else
if region.paused then
region:Resume()
end
region:SetTime(0, math.huge)
if region.TimerTick then
region.TimerTick = nil
region.subRegionEvents:RemoveSubscriber("TimerTick", region)
end
if region.useSmoothProgress then
region.PreShow = function()
region.smoothProgress:ResetSmoothedValue();
end
else
region.PreShow = nil
end
max = max or 0
region.FrameTick = nil
function region:Update()
region:UpdateProgress()
local state = region.state
if state.texture then
region:SetTexture(state.texture)
+301 -187
View File
@@ -11,67 +11,11 @@ function Private.regionPrototype.AddAlphaToDefault(default)
default.alpha = 1.0;
end
-- Adjusted Duration
function Private.regionPrototype.AddAdjustedDurationToDefault(default)
default.useAdjustededMax = false;
default.useAdjustededMin = false;
end
function Private.regionPrototype.AddAdjustedDurationOptions(options, data, order)
options.useAdjustededMin = {
type = "toggle",
width = WeakAuras.normalWidth,
name = L["Set Minimum Progress"],
desc = L["Values/Remaining Time below this value are displayed as no progress."],
order = order
};
options.adjustedMin = {
type = "input",
validate = WeakAuras.ValidateNumericOrPercent,
width = WeakAuras.normalWidth,
order = order + 0.01,
name = L["Minimum"],
hidden = function() return not data.useAdjustededMin end,
desc = L["Enter static or relative values with %"]
};
options.useAdjustedMinSpacer = {
type = "description",
width = WeakAuras.normalWidth,
name = "",
order = order + 0.02,
hidden = function() return not (not data.useAdjustededMin and data.useAdjustededMax) end,
};
options.useAdjustededMax = {
type = "toggle",
width = WeakAuras.normalWidth,
name = L["Set Maximum Progress"],
desc = L["Values/Remaining Time above this value are displayed as full progress."],
order = order + 0.03
};
options.adjustedMax = {
type = "input",
width = WeakAuras.normalWidth,
validate = WeakAuras.ValidateNumericOrPercent,
order = order + 0.04,
name = L["Maximum"],
hidden = function() return not data.useAdjustededMax end,
desc = L["Enter static or relative values with %"]
};
options.useAdjustedMaxSpacer = {
type = "description",
width = WeakAuras.normalWidth,
name = "",
order = order + 0.05,
hidden = function() return not (data.useAdjustededMin and not data.useAdjustededMax) end,
};
return options;
-- Progress Sources
function Private.regionPrototype.AddProgressSourceToDefault(default)
default.progressSource = {-1, ""}
default.useAdjustededMax = false
default.useAdjustededMin = false
end
local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20;
@@ -149,6 +93,28 @@ function Private.regionPrototype.AddProperties(properties, defaultsForRegion)
isPercent = true
}
end
if defaultsForRegion and defaultsForRegion.progressSource then
properties["progressSource"] = {
display = L["Progress Source"],
setter = "SetProgressSource",
type = "progressSource",
values = {},
}
properties["adjustedMin"] = {
display = L["Minimum Progress"],
setter = "SetAdjustedMin",
type = "string",
validate = WeakAuras.ValidateNumericOrPercent,
}
properties["adjustedMax"] = {
display = L["Maximum Progress"],
setter = "SetAdjustedMax",
type = "string",
validate = WeakAuras.ValidateNumericOrPercent,
}
end
end
local function SoundRepeatStop(self)
@@ -373,62 +339,253 @@ local function GetRegionAlpha(self)
return self.animAlpha or self.alpha or 1;
end
local function SetProgressSource(self, progressSource)
self.progressSource = progressSource
self:UpdateProgress()
end
local function SetAdjustedMin(self, adjustedMin)
local percent = string.match(adjustedMin, "(%d+)%%")
if percent then
self.adjustedMinRelPercent = tonumber(percent) / 100
self.adjustedMin = nil
else
self.adjustedMin = tonumber(adjustedMin)
self.adjustedMinRelPercent = nil
end
self:UpdateProgress()
end
local function SetAdjustedMax(self, adjustedMax)
local percent = string.match(adjustedMax, "(%d+)%%")
if percent then
self.adjustedMaxRelPercent = tonumber(percent) / 100
else
self.adjustedMax = tonumber(adjustedMax)
end
self:UpdateProgress()
end
local function GetProgressSource(self)
return self.progressSource
end
local function GetMinMaxProgress(self)
return self.minProgress or 0, self.maxProgress or 0
end
local function UpdateProgressFromState(self, minMaxConfig, state, progressSource)
local progressType = progressSource[2]
local property = progressSource[3]
local totalProperty = progressSource[4]
local inverseProperty = progressSource[5]
local pausedProperty = progressSource[6]
local remainingProperty = progressSource[7]
if progressType == "number" then
local value = state[property] or 0
local total = totalProperty and state[totalProperty] or 0
-- We don't care about inverse or paused
local adjustMin
if minMaxConfig.adjustedMin then
adjustMin = minMaxConfig.adjustedMin
elseif minMaxConfig.adjustedMinRelPercent then
adjustMin = minMaxConfig.adjustedMinRelPercent * total
else
adjustMin = 0
end
local max
if minMaxConfig.adjustedMax then
max = minMaxConfig.adjustedMax
elseif minMaxConfig.adjustedMaxRelPercent then
max = minMaxConfig.adjustedMaxRelPercent * total
else
max = total
end
-- The output of UpdateProgress is setting various values on self
-- and calling UpdateTime/UpdateValue. Not an ideal interface, but
-- the animation code/sub elements needs those values in some convenient place
self.minProgress, self.maxProgress = adjustMin, max
self.progressType = "static"
self.value = value - adjustMin
self.total = max - adjustMin
if self.UpdateValue then
self:UpdateValue()
end
elseif progressType == "timer" then
local expirationTime
local paused = pausedProperty and state[pausedProperty]
local inverse = inverseProperty and state[inverseProperty]
local remaining
if paused then
remaining = remainingProperty and state[remainingProperty]
expirationTime = GetTime() + (remaining or 0)
else
expirationTime = state[property] or math.huge
end
local duration = totalProperty and state[totalProperty] or 0
local adjustMin
if minMaxConfig.adjustedMin then
adjustMin = minMaxConfig.adjustedMin
elseif minMaxConfig.adjustedMinRelPercent then
adjustMin = minMaxConfig.adjustedMinRelPercent * duration
else
adjustMin = 0
end
local max
if minMaxConfig.adjustedMax then
max = minMaxConfig.adjustedMax
elseif minMaxConfig.adjustedMaxRelPercent then
max = minMaxConfig.adjustedMaxRelPercent * duration
else
max = duration
end
self.minProgress, self.maxProgress = adjustMin, max
self.progressType = "timed"
self.duration = max - adjustMin
self.expirationTime = expirationTime - adjustMin
self.remaining = remaining
self.inverse = inverse
self.paused = paused
if self.UpdateTime then
self:UpdateTime()
end
elseif progressType == "elapsedTimer" then
local startTime = state[property] or math.huge
local duration = totalProperty and state[totalProperty] or 0
local adjustMin
if minMaxConfig.adjustedMin then
adjustMin = minMaxConfig.adjustedMin
elseif minMaxConfig.adjustedMinRelPercent then
adjustMin = minMaxConfig.adjustedMinRelPercent * duration
else
adjustMin = 0
end
local max
if minMaxConfig.adjustedMax then
max = minMaxConfig.adjustedMax
elseif minMaxConfig.adjustedMaxRelPercent then
max = minMaxConfig.adjustedMaxRelPercent * duration
else
max = duration
end
self.minProgress, self.maxProgress = adjustMin, max
self.progressType = "timed"
self.duration = max - adjustMin
self.expirationTime = startTime + adjustMin + self.duration
self.inverse = true
self.paused = false
self.remaining = nil
if self.UpdateTime then
self:UpdateTime()
end
end
end
local autoTimedProgressSource = {-1, "timer", "expirationTime", "duration", "inverse", "paused", "remaining"}
local autoStaticProgressSource = {-1, "number", "value", "total", nil, nil, nil, nil}
local function UpdateProgressFromAuto(self, minMaxConfig, state)
if state.progressType == "timed" then
UpdateProgressFromState(self, minMaxConfig, state, autoTimedProgressSource)
elseif state.progressType == "static"then
UpdateProgressFromState(self, minMaxConfig, state, autoStaticProgressSource)
else
self.minProgress, self.maxProgress = nil, nil
self.progressType = "timed"
self.duration = 0
self.expirationTime = math.huge
self.inverse = false
self.paused = true
self.remaining = math.huge
if self.UpdateTime then
self:UpdateTime()
end
end
end
local function UpdateProgressFromManual(self, minMaxConfig, state, value, total)
value = type(value) == "number" and value or 0
total = type(total) == "number" and total or 0
local adjustMin
if minMaxConfig.adjustedMin then
adjustMin = minMaxConfig.adjustedMin
elseif minMaxConfig.adjustedMinRelPercent then
adjustMin = minMaxConfig.adjustedMinRelPercent * total
else
adjustMin = 0
end
local max
if minMaxConfig.adjustedMax then
max = minMaxConfig.adjustedMax
elseif minMaxConfig.adjustedMaxRelPercent then
max = minMaxConfig.adjustedMaxRelPercent * total
else
max = total
end
self.minProgress, self.maxProgress = adjustMin, max
self.progressType = "static"
self.value = value - adjustMin
self.total = max - adjustMin
if self.UpdateValue then
self:UpdateValue()
end
end
local function UpdateProgressFrom(self, progressSource, minMaxConfig, state, states, parent)
local trigger = progressSource and progressSource[1] or -1
if trigger == -2 then
-- sub element'a auto uses the whatever progress the main region has
UpdateProgressFromAuto(self, minMaxConfig, parent)
elseif trigger == -1 then
-- auto for regions uses the state
UpdateProgressFromAuto(self, minMaxConfig, state)
elseif trigger == 0 then
UpdateProgressFromManual(self, minMaxConfig, state, progressSource[3], progressSource[4])
else
UpdateProgressFromState(self, minMaxConfig, states[trigger] or {}, progressSource)
end
end
-- For regions
local function UpdateProgress(self)
UpdateProgressFrom(self, self.progressSource, self, self.state, self.states)
end
Private.UpdateProgressFrom = UpdateProgressFrom
local function SetAnimAlpha(self, alpha)
if alpha then
if alpha > 1 then
alpha = 1
elseif alpha < 0 then
alpha = 0
end
end
if (self.animAlpha == alpha) then
return;
end
self.animAlpha = alpha;
local errorHandler = Private.GetErrorHandlerId(self.id, L["Custom Fade Animation"])
if (WeakAuras.IsOptionsOpen()) then
local ok = pcall(self.SetAlpha, self, max(self.animAlpha or self.alpha or 1, 0.5))
if not ok then
Private.GetErrorHandlerId(self.id, L["Custom Fade Animation"])
errorHandler()
end
else
local ok = pcall(self.SetAlpha, self, self.animAlpha or self.alpha or 1)
if not ok then
Private.GetErrorHandlerId(self.id, L["Custom Fade Animation"])
errorHandler()
end
end
self.subRegionEvents:Notify("AlphaChanged")
end
local function SetTriggerProvidesTimer(self, timerTick)
self.triggerProvidesTimer = timerTick
self:UpdateTimerTick()
end
local function TimerTickForRegion(region)
Private.StartProfileSystem("timer tick")
Private.StartProfileAura(region.id);
region.subRegionEvents:Notify("TimerTick")
Private.StopProfileAura(region.id);
Private.StopProfileSystem("timer tick")
end
local function UpdateTimerTick(self)
if self.triggerProvidesTimer and self.subRegionEvents:HasSubscribers("TimerTick") and self.toShow then
if not self:GetScript("OnUpdate") then
self:SetScript("OnUpdate", function()
TimerTickForRegion(self)
end);
end
else
if self:GetScript("OnUpdate") then
self:SetScript("OnUpdate", nil);
end
end
end
local function UpdateFrameTick(self)
local function UpdateTick(self)
if self.subRegionEvents:HasSubscribers("FrameTick") and self.toShow then
Private.FrameTick:AddSubscriber("FrameTick", self)
Private.FrameTick:AddSubscriber("Tick", self)
else
Private.FrameTick:RemoveSubscriber("FrameTick", self)
Private.FrameTick:RemoveSubscriber("Tick", self)
end
end
local function FrameTick(self)
local function Tick(self)
Private.StartProfileAura(self.id)
self.values.lastCustomTextUpdate = nil
self.subRegionEvents:Notify("FrameTick")
@@ -484,12 +641,18 @@ function Private.regionPrototype.create(region)
region.SetRegionAlpha = SetRegionAlpha;
region.GetRegionAlpha = GetRegionAlpha;
end
if defaultsForRegion and defaultsForRegion.progressSource then
region.SetProgressSource = SetProgressSource
region.GetProgressSource = GetProgressSource
region.SetAdjustedMin = SetAdjustedMin
region.SetAdjustedMax = SetAdjustedMax
end
region.UpdateProgress = UpdateProgress
region.GetMinMaxProgress = GetMinMaxProgress
region.SetAnimAlpha = SetAnimAlpha;
region.SetTriggerProvidesTimer = SetTriggerProvidesTimer
region.UpdateTimerTick = UpdateTimerTick
region.UpdateFrameTick = UpdateFrameTick
region.FrameTick = FrameTick
region.UpdateTick = UpdateTick
region.Tick = Tick
region.subRegionEvents = Private.CreateSubscribableObject()
region.AnchorSubRegion = AnchorSubRegion
@@ -498,14 +661,12 @@ function Private.regionPrototype.create(region)
region:SetPoint("CENTER", UIParent, "CENTER")
end
-- SetDurationInfo
function Private.regionPrototype.modify(parent, region, data)
region.state = nil
region.states = nil
region.subRegionEvents:ClearSubscribers()
region.subRegionEvents:ClearCallbacks()
Private.FrameTick:RemoveSubscriber("FrameTick", region)
Private.FrameTick:RemoveSubscriber("Tick", region)
local defaultsForRegion = Private.regionTypes[data.regionType] and Private.regionTypes[data.regionType].default;
@@ -513,18 +674,20 @@ function Private.regionPrototype.modify(parent, region, data)
region:SetRegionAlpha(data.alpha)
end
local hasAdjustedMin = defaultsForRegion and defaultsForRegion.useAdjustededMin ~= nil and data.useAdjustededMin
and data.adjustedMin;
local hasAdjustedMax = defaultsForRegion and defaultsForRegion.useAdjustededMax ~= nil and data.useAdjustededMax
and data.adjustedMax;
local hasProgressSource = defaultsForRegion and defaultsForRegion.progressSource
local hasAdjustedMin = hasProgressSource and data.useAdjustededMin and data.adjustedMin
local hasAdjustedMax = hasProgressSource and data.useAdjustededMax and data.adjustedMax
region.progressSource = nil
region.adjustedMin = nil
region.adjustedMinRel = nil
region.adjustedMinRelPercent = nil
region.adjustedMax = nil
region.adjustedMaxRel = nil
region.adjustedMaxRelPercent = nil
if hasProgressSource then
region.progressSource = Private.AddProgressSourceMetaData(data, data.progressSource)
end
if (hasAdjustedMin) then
local percent = string.match(data.adjustedMin, "(%d+)%%")
if percent then
@@ -576,7 +739,7 @@ function Private.regionPrototype.modify(parent, region, data)
data.actions.start[fullKey] = default
end
return data.actions.start[fullKey]
end, true)
end, true, data)
region.finishFormatters = Private.CreateFormatters(data.actions.finish.message, function(key, default)
local fullKey = "message_format_" .. key
@@ -584,7 +747,7 @@ function Private.regionPrototype.modify(parent, region, data)
data.actions.finish[fullKey] = default
end
return data.actions.finish[fullKey]
end, true)
end, true, data)
end
function Private.regionPrototype.modifyFinish(parent, region, data)
@@ -615,91 +778,56 @@ function Private.regionPrototype.modifyFinish(parent, region, data)
end
end
region.subRegionEvents:SetOnSubscriptionStatusChanged("TimerTick", function()
region:UpdateTimerTick()
end)
region:UpdateTimerTick()
region.subRegionEvents:SetOnSubscriptionStatusChanged("FrameTick", function()
region:UpdateFrameTick()
region:UpdateTick()
end)
region:UpdateFrameTick()
region:UpdateTick()
Private.ApplyFrameLevel(region)
end
local function SetProgressValue(region, value, total)
local adjustMin = region.adjustedMin or 0;
local max = region.adjustedMax or total;
region:SetValue(value - adjustMin, max - adjustMin);
end
local regionsForFrameTick = {}
local frameForFrameTick = CreateFrame("Frame");
Private.frames["Frame Tick Frame"] = frameForFrameTick
Private.FrameTick = Private.CreateSubscribableObject()
Private.FrameTick.OnUpdateHandler = function()
if WeakAuras.IsOptionsOpen() then
return
end
Private.StartProfileSystem("frame tick")
Private.FrameTick:Notify("FrameTick")
Private.FrameTick:Notify("Tick")
Private.StopProfileSystem("frame tick")
end
Private.FrameTick:SetOnSubscriptionStatusChanged("FrameTick", function()
if Private.FrameTick:HasSubscribers("FrameTick") then
Private.FrameTick:SetOnSubscriptionStatusChanged("Tick", function()
if Private.FrameTick:HasSubscribers("Tick") then
frameForFrameTick:SetScript("OnUpdate", Private.FrameTick.OnUpdateHandler);
else
frameForFrameTick:SetScript("OnUpdate", nil)
end
end)
local function TimerTickForSetDuration(self)
local duration = self.duration
local adjustMin = self.adjustedMin or 0;
local max
if duration == 0 then
max = 0
elseif self.adjustedMax then
max = self.adjustedMax
else
max = duration
end
self:SetTime(max - adjustMin, self.expirationTime - adjustMin, self.inverse);
end
function Private.regionPrototype.AddSetDurationInfo(region)
if (region.SetValue and region.SetTime) then
region.generatedSetDurationInfo = true;
-- WeakAuras no longer calls SetDurationInfo, but some people do that,
-- In that case we also need to overwrite TimerTick
function Private.regionPrototype.AddSetDurationInfo(region, uid)
if (region.UpdateValue and region.UpdateTime) then
-- WeakAuras no longer calls SetDurationInfo, but some people do that
region.SetDurationInfo = function(self, duration, expirationTime, customValue, inverse)
self.duration = duration or 0
self.expirationTime = expirationTime;
self.inverse = inverse;
-- For now don't warn against SetDurationInfo
-- Private.AuraWarnings.UpdateWarning(uid, "SetDurationInfo", "warning", L["Aura is using deprecated SetDurationInfo"])
if customValue then
SetProgressValue(region, duration, expirationTime);
region.TimerTick = nil
region.subRegionEvents:RemoveSubscriber("TimerTick", self)
else
local adjustMin = region.adjustedMin or 0;
region:SetTime((duration ~= 0 and region.adjustedMax or duration) - adjustMin, expirationTime - adjustMin, inverse);
region.TimerTick = TimerTickForSetDuration
region.subRegionEvents:AddSubscriber("TimerTick", self, true)
local max = self.adjustedMax or expirationTime
region.progressType = "static"
region.value = duration - adjustMin
region.total = max - adjustMin
region:UpdateValue()
else
local adjustMin = self.adjustedMin or 0;
self.progressType = "timed"
self.duration = (duration ~= 0 and self.adjustedMax or duration) - adjustMin
self.expirationTime = expirationTime - adjustMin
self.inverse = inverse
self.paused = false
self.remaining = nil
self:UpdateTime()
end
end
elseif (region.generatedSetDurationInfo) then
region.generatedSetDurationInfo = nil;
region.SetDurationInfo = nil;
end
end
@@ -808,8 +936,7 @@ function Private.regionPrototype.AddExpandFunction(data, region, cloneId, parent
region:SoundRepeatStop();
end
region:UpdateFrameTick()
region:UpdateTimerTick()
region:UpdateTick()
end
function region:Expand()
if (region.toShow) then
@@ -844,8 +971,7 @@ function Private.regionPrototype.AddExpandFunction(data, region, cloneId, parent
end
parent:ActivateChild(data.id, cloneId);
region:UpdateFrameTick()
region:UpdateTimerTick()
region:UpdateTick()
end
elseif not(data.controlledChildren) then
function region:Collapse()
@@ -867,8 +993,7 @@ function Private.regionPrototype.AddExpandFunction(data, region, cloneId, parent
region:SoundRepeatStop();
end
region:UpdateFrameTick()
region:UpdateTimerTick()
region:UpdateTick()
end
function region:Expand()
if data.anchorFrameType == "SELECTFRAME"
@@ -915,8 +1040,7 @@ function Private.regionPrototype.AddExpandFunction(data, region, cloneId, parent
parent:UpdateBorder(region);
end
region:UpdateFrameTick()
region:UpdateTimerTick()
region:UpdateTick()
end
end
-- Stubs that allow for polymorphism
@@ -926,16 +1050,6 @@ function Private.regionPrototype.AddExpandFunction(data, region, cloneId, parent
if not region.Expand then
function region:Expand() end
end
if not region.Pause then
function region:Pause()
self.paused = true
end
end
if not region.Resume then
function region:Resume()
self.paused = nil
end
end
end
do
+155 -88
View File
@@ -5,6 +5,7 @@ local texture_data = WeakAuras.StopMotion.texture_data;
local L = WeakAuras.L;
local default = {
progressSource = {-1, "" },
foregroundTexture = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\StopMotion",
backgroundTexture = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\StopMotion",
desaturateBackground = false,
@@ -44,6 +45,8 @@ local default = {
hideBackground = true
};
Private.regionPrototype.AddProgressSourceToDefault(default)
local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20;
local properties = {
@@ -87,6 +90,12 @@ local properties = {
Private.regionPrototype.AddProperties(properties, default);
local function GetProperties(data)
local result = CopyTable(properties)
result.progressSource.values = Private.GetProgressSourcesForUi(data)
return result
end
local function create(parent)
local frame = CreateFrame("Frame", nil, UIParent);
frame.regionType = "stopmotion"
@@ -150,10 +159,117 @@ local function SetFrameViaFrames(self, texture, frame)
self:SetTexture(texture .. format("%03d", frame));
end
local function SetProgress(self, progress)
local frames
local startFrame = self.startFrame
local endFrame = self.endFrame
local inverse = self.inverseDirection
if (endFrame >= startFrame) then
frames = endFrame - startFrame + 1
else
frames = startFrame - endFrame + 1
startFrame, endFrame = endFrame, startFrame
inverse = not inverse
end
local frame = floor( (frames - 1) * progress) + startFrame
if (inverse) then
frame = endFrame - frame + startFrame;
end
if (frame > endFrame) then
frame = endFrame
end
if (frame < startFrame) then
frame = startFrame
end
self.foreground:SetFrame(self.foregroundTexture, frame);
end
local FrameTickFunctions = {
progressTimer = function(self)
Private.StartProfileSystem("stopmotion")
Private.StartProfileAura(self.id)
local remaining = self.expirationTime - GetTime()
local progress = 1 - (remaining / self.duration)
self:SetProgress(progress)
Private.StopProfileAura(self.id)
Private.StopProfileSystem("stopmotion")
end,
timed = function(self)
if (not self.startTime) then return end
Private.StartProfileSystem("stopmotion")
Private.StartProfileAura(self.id)
local timeSinceStart = (GetTime() - self.startTime)
local newCurrentFrame = floor(timeSinceStart * (self.frameRate or 15))
if (newCurrentFrame == self.currentFrame) then
Private.StopProfileAura(self.id)
Private.StopProfileSystem("stopmotion")
return
end
self.currentFrame = newCurrentFrame
local frames
local startFrame = self.startFrame
local endFrame = self.endFrame
local inverse = self.inverseDirection
if (endFrame >= startFrame) then
frames = endFrame - startFrame + 1
else
frames = startFrame - endFrame + 1
startFrame, endFrame = endFrame, startFrame
inverse = not inverse
end
local frame = 0
if (self.animationType == "loop") then
frame = (newCurrentFrame % frames) + startFrame
elseif (self.animationType == "bounce") then
local direction = floor(newCurrentFrame / frames) % 2
if (direction == 0) then
frame = (newCurrentFrame % frames) + startFrame
else
frame = endFrame - (newCurrentFrame % frames)
end
elseif (self.animationType == "once") then
frame = newCurrentFrame + startFrame
if (frame > endFrame) then
frame = endFrame
end
end
if (inverse) then
frame = endFrame - frame + startFrame
end
if (frame > endFrame) then
frame = endFrame
end
if (frame < startFrame) then
frame = startFrame
end
self.foreground:SetFrame(self.foregroundTexture, frame)
Private.StopProfileAura(self.id)
Private.StopProfileSystem("stopmotion")
end,
}
local function modify(parent, region, data)
Private.regionPrototype.modify(parent, region, data);
region.foreground = region.foreground or {}
region.background = region.background or {}
region.frameRate = data.frameRate
region.inverseDirection = data.inverse
region.animationType = data.animationType
region.foregroundTexture = data.foregroundTexture
region.FrameTick = nil
local pattern = "%.x(%d+)y(%d+)f(%d+)%.[tb][gl][ap]"
local pattern2 = "%.x(%d+)y(%d+)f(%d+)w(%d+)h(%d+)W(%d+)H(%d+)%.[tb][gl][ap]"
@@ -364,101 +480,52 @@ local function modify(parent, region, data)
function region:PreShow()
region.startTime = GetTime();
if region.FrameTick then
region:FrameTick()
end
end
local function onUpdate()
if (not region.startTime) then return end
region.SetProgress = SetProgress
Private.StartProfileAura(region.id);
Private.StartProfileSystem("stopmotion")
local timeSinceStart = (GetTime() - region.startTime);
local newCurrentFrame = floor(timeSinceStart * (data.frameRate or 15));
if (newCurrentFrame == region.currentFrame) then
Private.StopProfileAura(region.id);
Private.StopProfileSystem("stopmotion")
return;
end
region.currentFrame = newCurrentFrame;
local frames;
local startFrame = region.startFrame;
local endFrame = region.endFrame;
local inverse = data.inverse;
if (endFrame >= startFrame) then
frames = endFrame - startFrame + 1;
else
frames = startFrame - endFrame + 1;
startFrame, endFrame = endFrame, startFrame;
inverse = not inverse;
end
local frame = 0;
if (data.animationType == "loop") then
frame = (newCurrentFrame % frames) + startFrame;
elseif (data.animationType == "bounce") then
local direction = floor(newCurrentFrame / frames) % 2;
if (direction == 0) then
frame = (newCurrentFrame % frames) + startFrame;
else
frame = endFrame - (newCurrentFrame % frames);
end
elseif (data.animationType == "once") then
frame = newCurrentFrame + startFrame
if (frame > endFrame) then
frame = endFrame;
end
elseif (data.animationType == "progress") then
if (not region.state) then
-- Do nothing
elseif (region.state.progressType == "static") then
local value = region.state.value or 0
local total = region.state.total ~= 0 and region.state.total or 1
frame = floor((frames - 1) * value / total) + startFrame;
else
local remaining
if region.state.paused then
remaining = region.state.remaining or 0;
else
remaining = region.state.expirationTime and (region.state.expirationTime - GetTime()) or 0;
end
local progress = region.state.duration and region.state.duration > 0 and (1 - (remaining / region.state.duration)) or 0;
frame = floor( (frames - 1) * progress) + startFrame;
end
end
if (inverse) then
frame = endFrame - frame + startFrame;
end
if (frame > endFrame) then
frame = endFrame
end
if (frame < startFrame) then
frame = startFrame
end
region.foreground:SetFrame(data.foregroundTexture, frame);
Private.StopProfileAura(region.id);
Private.StopProfileSystem("stopmotion")
end;
region.FrameTick = onUpdate;
if region.FrameTick then
if data.animationType == "loop" or data.animationType == "bounce" or data.animationType == "once" then
region.FrameTick = FrameTickFunctions.timed
region.subRegionEvents:AddSubscriber("FrameTick", region, true)
end
function region:Update()
end
function region:Update()
if region.state.paused then
if not region.paused then
region:Pause()
elseif data.animationType == "progress" then
function region:Update()
region:UpdateProgress()
end
function region:UpdateValue()
local progress = 0;
if (self.total ~= 0) then
progress = self.value / self.total
end
else
if region.paused then
region:Resume()
self:SetProgress(progress)
if self.FrameTick then
self.FrameTick = nil
self.subRegionEvents:RemoveSubscriber("FrameTick", self)
end
end
onUpdate();
function region:UpdateTime()
if self.paused and self.FrameTick then
self.FrameTick = nil
self.subRegionEvents:RemoveSubscriber("FrameTick", self)
end
self.expirationTime = self.expirationTime
self.duration = self.duration
if not self.paused then
if not self.FrameTick then
self.FrameTick = FrameTickFunctions.progressTimer
self.subRegionEvents:AddSubscriber("FrameTick", self)
end
self:FrameTick()
end
end
end
function region:SetForegroundDesaturated(b)
@@ -488,4 +555,4 @@ local function validate(data)
Private.EnforceSubregionExists(data, "subbackground")
end
Private.RegisterRegionType("stopmotion", create, modify, default, properties, validate);
Private.RegisterRegionType("stopmotion", create, modify, default, GetProperties, validate);
+4 -18
View File
@@ -54,10 +54,6 @@ local properties = {
Private.regionPrototype.AddProperties(properties, default);
local function GetProperties(data)
return properties;
end
local function create(parent)
local region = CreateFrame("Frame", nil, parent);
region.regionType = "text"
@@ -68,9 +64,6 @@ local function create(parent)
text:SetWordWrap(true);
text:SetNonSpaceWrap(true);
region.duration = 0;
region.expirationTime = math.huge;
Private.regionPrototype.create(region);
return region;
@@ -220,7 +213,7 @@ local function modify(parent, region, data)
end
end
formatters = Private.CreateFormatters(texts, getter)
formatters = Private.CreateFormatters(texts, getter, false, data)
end
local customTextFunc = nil
@@ -252,12 +245,11 @@ local function modify(parent, region, data)
Update = UpdateText or function() end
end
local TimerTick
local FrameTick
if Private.ContainsPlaceHolders(self.displayText, "p") then
TimerTick = UpdateText
FrameTick = UpdateText
end
local FrameTick
if customTextFunc and data.customTextUpdate == "update" then
if Private.ContainsCustomPlaceHolder(self.displayText) then
FrameTick = function()
@@ -269,7 +261,6 @@ local function modify(parent, region, data)
self.Update = Update
self.FrameTick = FrameTick
self.TimerTick = TimerTick
if not UpdateText then
local textStr = self.displayText
@@ -285,11 +276,6 @@ local function modify(parent, region, data)
self.subRegionEvents:RemoveSubscriber("FrameTick", self)
end
if self.TimerTick then
self.subRegionEvents:AddSubscriber("TimerTick", self, true)
else
self.subRegionEvents:RemoveSubscriber("TimerTick", self)
end
if self.Update and self.state then
self:Update()
end
@@ -347,7 +333,7 @@ local function validate(data)
Private.EnforceSubregionExists(data, "subbackground")
end
Private.RegisterRegionType("text", create, modify, default, GetProperties, validate);
Private.RegisterRegionType("text", create, modify, default, properties, validate);
-- Fallback region type