Skip to content

Commit

Permalink
StopMotion: Introduce a StopMotion sub element
Browse files Browse the repository at this point in the history
Refactor the existing StopMotion region into something that can be
reused by an sub element.

Additionally add a way for sub elements to provided anchors to other sub
elements and implement Ticks as anchor providers.

Cycles in Stop Motion anchoring is prevented by Ticks being not
anchoreable to other sub elements. Eventually a more robust solution for
preventing anchoring cycles between sub elements will be needed.

Also argueably the regions should provide "progress relative" anchoring
and this shouldn't be Ticks responsibility, but we'll need sub elements
providing anchors anyway.
  • Loading branch information
InfusOnWoW committed Nov 30, 2024
1 parent c475408 commit 7f857ba
Show file tree
Hide file tree
Showing 27 changed files with 1,561 additions and 509 deletions.
440 changes: 440 additions & 0 deletions WeakAuras/BaseRegions/StopMotion.lua

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions WeakAuras/Init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Private.frames = {}
---@field state state
---@field states state[]
---@field regionType string
---@field FrameTick fun(self: WARegion)?
---@field UpdateValue fun(self: WARegion)?
---@field UpdateTime fun(self: WARegion)?
---@field Update fun(self: WARegion)?

--- @class Private
--- @field ActivateAuraEnvironment fun(id: auraId?, cloneId: string?, state: state?, states: state[]?, config: boolean?)
Expand Down
28 changes: 28 additions & 0 deletions WeakAuras/Modernize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,34 @@ function Private.Modernize(data, oldSnapshot)
end
end

if data.internalVersion < 79 then
-- Use common names for anchor areas/points so
-- that up/down of sub regions can adapt that

local conversions = {
subborder = {
border_anchor = "anchor_area",
},
subglow = {
glow_anchor = "anchor_area"
},
subtext = {
text_anchorPoint = "anchor_point"
}
}

if data.subRegions then
for index, subRegionData in ipairs(data.subRegions) do
if conversions[subRegionData.type] then
for oldKey, newKey in pairs(conversions[subRegionData.type]) do
subRegionData[newKey] = subRegionData[oldKey]
subRegionData[oldKey] = nil
end
end
end
end
end

data.internalVersion = max(data.internalVersion or 0, WeakAuras.InternalVersion())
end

Expand Down
15 changes: 10 additions & 5 deletions WeakAuras/RegionTypes/AuraBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -787,16 +787,21 @@ local function FrameTick(self)
end

local funcs = {
AnchorSubRegion = function(self, subRegion, anchorType, selfPoint, anchorPoint, anchorXOffset, anchorYOffset)
AnchorSubRegion = function(self, subRegion, anchorType, anchorPoint, selfPoint, anchorXOffset, anchorYOffset)
if anchorPoint:sub(1, 4) == "sub." then
Private.regionPrototype.AnchorSubRegion(self, subRegion, anchorType, anchorPoint, selfPoint, anchorXOffset, anchorYOffset)
return
end
if anchorType == "area" then
local anchor = self
if selfPoint == "bar" then

if anchorPoint == "bar" then
anchor = self
elseif selfPoint == "icon" then
elseif anchorPoint == "icon" then
anchor = self.icon
elseif selfPoint == "fg" then
elseif anchorPoint == "fg" then
anchor = self.bar.fgMask
elseif selfPoint == "bg" then
elseif anchorPoint == "bg" then
anchor = self.bar.bg
end

Expand Down
9 changes: 7 additions & 2 deletions WeakAuras/RegionTypes/Icon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,15 @@ local function GetTexCoord(region, texWidth, aspectRatio, xOffset, yOffset)
return unpack(region.currentCoord)
end

local function AnchorSubRegion(self, subRegion, anchorType, selfPoint, anchorPoint, anchorXOffset, anchorYOffset)
local function AnchorSubRegion(self, subRegion, anchorType, anchorPoint, selfPoint, anchorXOffset, anchorYOffset)
if type(anchorPoint) == "string" and anchorPoint:sub(1, 4) == "sub." then
Private.regionPrototype.AnchorSubRegion(self, subRegion, anchorType, anchorPoint, selfPoint, anchorXOffset, anchorYOffset)
return
end

if anchorType == "area" then
Private.regionPrototype.AnchorSubRegion(selfPoint == "region" and self or self.icon,
subRegion, anchorType, selfPoint, anchorPoint, anchorXOffset, anchorYOffset)
subRegion, anchorType, anchorPoint, selfPoint, anchorXOffset, anchorYOffset)
else
subRegion:ClearAllPoints()
anchorPoint = anchorPoint or "CENTER"
Expand Down
2 changes: 0 additions & 2 deletions WeakAuras/RegionTypes/Model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ local function create(parent)
region[k] = v
end

region.AnchorSubRegion = Private.regionPrototype.AnchorSubRegion

-- Return complete region
return region;
end
Expand Down
64 changes: 54 additions & 10 deletions WeakAuras/RegionTypes/RegionPrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,44 @@ end

local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20;

function Private.GetAnchorsForData(parentData, type)
local result
if not parentData.controlledChildren then
if not Private.regionOptions[parentData.regionType] then
function Private.GetAnchorsForData(data, filter)
local result = {}
if not data.controlledChildren then
if not Private.regionOptions[data.regionType] then
return
end

local anchors
if Private.regionOptions[parentData.regionType].getAnchors then
anchors = Private.regionOptions[parentData.regionType].getAnchors(parentData)
if Private.regionOptions[data.regionType].getAnchors then
anchors = Private.regionOptions[data.regionType].getAnchors(data)
else
anchors = Private.default_types_for_anchor
end

for anchorId, anchorData in pairs(anchors) do
if anchorData.type == type then
result = result or {}
if anchorData.type == filter then
result[anchorId] = anchorData.display
end
end

local subElementTypeCounter = {}
for i, subRegion in ipairs(data.subRegions) do
subElementTypeCounter[subRegion.type] = (subElementTypeCounter[subRegion.type] or 0) + 1
local getAnchors = Private.subRegionOptions[subRegion.type].getAnchors
if getAnchors then
local subRegionTypeData = Private.subRegionTypes[subRegion.type]

local anchors = getAnchors(subRegion)
for key, anchorData in pairs(anchors) do
if anchorData.type == filter then
local subElementName = subRegionTypeData.displayName .. " " .. subElementTypeCounter[subRegion.type]
local anchorId = "sub." .. i .. "." .. key
result[anchorId] = {subElementName, anchorData.display}
end
end
end
end

end
return result
end
Expand Down Expand Up @@ -638,16 +657,32 @@ local function Tick(self)
Private.StopProfileAura(self.id)
end

local function AnchorSubRegion(self, subRegion, anchorType, selfPoint, anchorPoint, anchorXOffset, anchorYOffset)
subRegion:ClearAllPoints()
local function ForwardAnchorToSubRegion(self, subRegion, anchorType, anchorPoint, selfPoint, anchorXOffset, anchorYOffset)
local nextdot = anchorPoint:find(".", 5, true)
local index = tonumber(anchorPoint:sub(5, nextdot - 1))
local subElement = index and self.subRegions[index] or nil
if subElement then
local key = anchorPoint:sub(nextdot + 1)
if subElement.AnchorSubRegion then
subElement:AnchorSubRegion(subRegion, anchorType, key, selfPoint, anchorXOffset, anchorYOffset)
end
end
end

local function AnchorSubRegion(self, subRegion, anchorType, anchorPoint, selfPoint, anchorXOffset, anchorYOffset)
if anchorPoint and anchorPoint:sub(1, 4) == "sub." then
self:ForwardAnchorToSubRegion(subRegion, anchorType, anchorPoint, selfPoint, anchorXOffset, anchorYOffset)
return
end
if anchorType == "point" then
subRegion:ClearAllPoints()
local xOffset = anchorXOffset or 0
local yOffset = anchorYOffset or 0
subRegion:SetPoint(Private.point_types[selfPoint] and selfPoint or "CENTER",
self, Private.point_types[anchorPoint] and anchorPoint or "CENTER",
xOffset, yOffset)
else
subRegion:ClearAllPoints()
anchorXOffset = anchorXOffset or 0
anchorYOffset = anchorYOffset or 0
subRegion:SetPoint("bottomleft", self, "bottomleft", -anchorXOffset, -anchorYOffset)
Expand Down Expand Up @@ -702,8 +737,10 @@ function Private.regionPrototype.create(region)
region.UpdateTick = UpdateTick
region.Tick = Tick


region.subRegionEvents = Private.CreateSubscribableObject()
region.AnchorSubRegion = AnchorSubRegion
region.ForwardAnchorToSubRegion = ForwardAnchorToSubRegion
region.values = {} -- For SubText

region:SetPoint("CENTER", UIParent, "CENTER")
Expand Down Expand Up @@ -824,6 +861,13 @@ function Private.regionPrototype.modifyFinish(parent, region, data)
tinsert(region.subRegions, subRegion)
end
end

for index, subRegion in pairs(region.subRegions) do
if subRegion.Anchor then
subRegion:Anchor()
end
end

end

region.subRegionEvents:SetOnSubscriptionStatusChanged("FrameTick", function()
Expand Down
Loading

0 comments on commit 7f857ba

Please sign in to comment.