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
+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)