(feature/LibGlow) add Proc Glow (#35)
This commit is contained in:
@@ -135,7 +135,7 @@ local function formatValueForAssignment(vType, value, pathToCustomFunction, path
|
||||
if (value and type(value) == "table") then
|
||||
return ([[{ glow_action = %q, glow_frame_type = %q, glow_type = %q,
|
||||
glow_frame = %q, use_glow_color = %s, glow_color = {%s, %s, %s, %s},
|
||||
glow_lines = %d, glow_frequency = %f, glow_length = %f, glow_thickness = %f, glow_XOffset = %f, glow_YOffset = %f,
|
||||
glow_startAnim = %s, glow_duration = %f, glow_lines = %d, glow_frequency = %f, glow_length = %f, glow_thickness = %f, glow_XOffset = %f, glow_YOffset = %f,
|
||||
glow_scale = %f, glow_border = %s }]]):format(
|
||||
value.glow_action or "",
|
||||
value.glow_frame_type or "",
|
||||
@@ -146,6 +146,8 @@ local function formatValueForAssignment(vType, value, pathToCustomFunction, path
|
||||
type(value.glow_color) == "table" and tostring(value.glow_color[2]) or "1",
|
||||
type(value.glow_color) == "table" and tostring(value.glow_color[3]) or "1",
|
||||
type(value.glow_color) == "table" and tostring(value.glow_color[4]) or "1",
|
||||
value.glow_startAnim and "true" or "false",
|
||||
value.glow_duration or 1,
|
||||
value.glow_lines or 8,
|
||||
value.glow_frequency or 0.25,
|
||||
value.glow_length or 10,
|
||||
|
||||
@@ -811,4 +811,208 @@ end
|
||||
|
||||
tinsert(lib.glowList, "Action Button Glow")
|
||||
lib.startList["Action Button Glow"] = lib.ButtonGlow_Start
|
||||
lib.stopList["Action Button Glow"] = lib.ButtonGlow_Stop
|
||||
lib.stopList["Action Button Glow"] = lib.ButtonGlow_Stop
|
||||
|
||||
|
||||
-- ProcGlow
|
||||
|
||||
local ProcGlowBaseTexCoords = {
|
||||
["Loop"] = {0.412598, 0.575195, 0.000976562, 0.391602},
|
||||
["Start"] = {0.000488281, 0.411621, 0.000976562, 0.987305},
|
||||
}
|
||||
|
||||
local function SetTile(texture, frame, rows, columns, frameScaleW, frameScaleH, key)
|
||||
frame = frame - 1
|
||||
local row = math.floor(frame / columns)
|
||||
local column = frame % columns
|
||||
|
||||
local BaseTexCoord = ProcGlowBaseTexCoords[key]
|
||||
|
||||
local leftStart, rightEnd, topStart, bottomEnd = BaseTexCoord[1], BaseTexCoord[2], BaseTexCoord[3], BaseTexCoord[4]
|
||||
|
||||
local fullWidth = rightEnd - leftStart
|
||||
local fullHeight = bottomEnd - topStart
|
||||
|
||||
local baseDeltaX = fullWidth / columns
|
||||
local baseDeltaY = fullHeight / rows
|
||||
|
||||
local deltaX = baseDeltaX * frameScaleW
|
||||
local deltaY = baseDeltaY * frameScaleH
|
||||
|
||||
local left = leftStart + baseDeltaX * column + (baseDeltaX - deltaX) / 2
|
||||
local right = left + deltaX
|
||||
|
||||
local top = topStart + baseDeltaY * row + (baseDeltaY - deltaY) / 2
|
||||
local bottom = top + deltaY
|
||||
|
||||
pcall(function()
|
||||
texture:SetTexCoord(left, right, top, bottom)
|
||||
end)
|
||||
end
|
||||
|
||||
local StartFlipbook
|
||||
local FlipbookAnimation_OnUpdate
|
||||
|
||||
FlipbookAnimation_OnUpdate = function(self, elapsed)
|
||||
local data = self.flipbookData
|
||||
if not data then return end
|
||||
|
||||
if data.animElapsed then
|
||||
data.animElapsed = data.animElapsed + elapsed
|
||||
if data.animElapsed >= 0.7 then
|
||||
if self:IsShown() then
|
||||
StartFlipbook(self, self.ProcLoop, 6, 5, 30, ((data.animOptions and (30 / data.animOptions)) or 30), nil, nil, "Loop")
|
||||
end
|
||||
data.animElapsed = nil
|
||||
data.animOptions = nil
|
||||
end
|
||||
end
|
||||
data.elapsedTime = data.elapsedTime + elapsed
|
||||
local frameDuration = 1 / data.frameRate
|
||||
|
||||
if data.elapsedTime >= frameDuration then
|
||||
data.elapsedTime = data.elapsedTime - frameDuration
|
||||
data.currentFrame = data.currentFrame + 1
|
||||
if data.currentFrame > data.totalFrames then
|
||||
data.currentFrame = 1
|
||||
end
|
||||
SetTile(data.texture, data.currentFrame, data.rows, data.columns, 1, 1, data.key)
|
||||
end
|
||||
end
|
||||
|
||||
local function StopFlipbook(f)
|
||||
f:SetScript("OnUpdate", nil)
|
||||
if f.flipbookData and f.flipbookData.texture then
|
||||
f.flipbookData.texture:Hide()
|
||||
end
|
||||
f.flipbookData = nil
|
||||
end
|
||||
|
||||
StartFlipbook = function(f, texture, rows, columns, totalFrames, frameRate, startAnim, startOptionsDur, key)
|
||||
StopFlipbook(f)
|
||||
f.flipbookData = {
|
||||
key = key,
|
||||
texture = texture,
|
||||
rows = rows,
|
||||
columns = columns,
|
||||
totalFrames = totalFrames,
|
||||
frameRate = frameRate,
|
||||
currentFrame = 1,
|
||||
elapsedTime = 0,
|
||||
animElapsed = startAnim,
|
||||
animOptions = startOptionsDur,
|
||||
}
|
||||
texture:Show()
|
||||
f:SetScript("OnUpdate", FlipbookAnimation_OnUpdate)
|
||||
end
|
||||
|
||||
local function ProcGlowResetter(framePool, frame)
|
||||
frame:Hide()
|
||||
frame:ClearAllPoints()
|
||||
frame:SetScript("OnShow", nil)
|
||||
frame:SetScript("OnHide", nil)
|
||||
frame:SetScript("OnUpdate", nil)
|
||||
local parent = frame:GetParent()
|
||||
if frame.name and parent[frame.name] then
|
||||
parent[frame.name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
local ProcGlowPool = CreateFramePool("Frame", GlowParent, nil, ProcGlowResetter)
|
||||
lib.ProcGlowPool = ProcGlowPool
|
||||
|
||||
local function InitProcGlow(f)
|
||||
-- Start-Flipbook
|
||||
f.ProcStart = f:CreateTexture(nil, "ARTWORK")
|
||||
f.ProcStart:SetBlendMode("ADD")
|
||||
f.ProcStart:SetTexture([[Interface\AddOns\WeakAuras\Libs\LibCustomGlow-1.0\UIActionBarFX]])
|
||||
f.ProcStart:SetTexCoord(0.0827148248, 0.1649413686, 0.000976562, 0.165364635) -- First Frame
|
||||
f.ProcStart:SetAlpha(1)
|
||||
f.ProcStart:SetSize(150, 150)
|
||||
f.ProcStart:SetPoint("CENTER")
|
||||
f.ProcStart:Hide()
|
||||
|
||||
-- Loop-Flipbook
|
||||
f.ProcLoop = f:CreateTexture(nil, "ARTWORK")
|
||||
f.ProcLoop:SetTexture([[Interface\AddOns\WeakAuras\Libs\LibCustomGlow-1.0\UIActionBarFX]])
|
||||
f.ProcLoop:SetTexCoord(0.412598, 0.4451174, 0.000976562, 0.066080801666667) -- First Frame
|
||||
f.ProcLoop:SetAlpha(1)
|
||||
f.ProcLoop:SetAllPoints()
|
||||
f.ProcLoop:Hide()
|
||||
end
|
||||
|
||||
local function SetupProcGlow(f, options)
|
||||
f.name = "_ProcGlow" .. options.key
|
||||
|
||||
f:SetScript("OnHide", function(self)
|
||||
StopFlipbook(self)
|
||||
end)
|
||||
|
||||
f:SetScript("OnShow", function(self)
|
||||
StopFlipbook(self)
|
||||
if self.startAnim then
|
||||
local width, height = self:GetSize()
|
||||
self.ProcStart:SetSize((width / 42 * 150) / 1.4, (height / 42 * 150) / 1.4)
|
||||
StartFlipbook(self, self.ProcStart, 6, 5, 30, 30, 0, options.duration, "Start")
|
||||
else
|
||||
StartFlipbook(self, self.ProcLoop , 6, 5, 30, (30 / options.duration), nil, nil, "Loop")
|
||||
end
|
||||
end)
|
||||
|
||||
local color = options.color or {1, 1, 1, 1}
|
||||
f.ProcStart:SetVertexColor(unpack(color))
|
||||
f.ProcLoop:SetVertexColor(unpack(color))
|
||||
|
||||
f.startAnim = options.startAnim
|
||||
end
|
||||
|
||||
local ProcGlowDefaults = {
|
||||
frameLevel = 8,
|
||||
color = nil,
|
||||
startAnim = true,
|
||||
xOffset = 0,
|
||||
yOffset = 0,
|
||||
duration = 1,
|
||||
key = ""
|
||||
}
|
||||
|
||||
function lib.ProcGlow_Start(r, options)
|
||||
if not r then return end
|
||||
options = options or {}
|
||||
setmetatable(options, { __index = ProcGlowDefaults })
|
||||
local key = "_ProcGlow" .. options.key
|
||||
local f, new
|
||||
if r[key] then
|
||||
f = r[key]
|
||||
else
|
||||
f, new = ProcGlowPool:Acquire()
|
||||
if new then
|
||||
InitProcGlow(f)
|
||||
end
|
||||
r[key] = f
|
||||
end
|
||||
|
||||
f:SetParent(r)
|
||||
f:SetFrameLevel(r:GetFrameLevel() + options.frameLevel)
|
||||
|
||||
local width, height = r:GetSize()
|
||||
local xOffset = options.xOffset + width * 0.2
|
||||
local yOffset = options.yOffset + height * 0.2
|
||||
f:SetPoint("TOPLEFT", r, "TOPLEFT", -xOffset, yOffset)
|
||||
f:SetPoint("BOTTOMRIGHT", r, "BOTTOMRIGHT", xOffset, -yOffset)
|
||||
|
||||
SetupProcGlow(f, options)
|
||||
f:Show()
|
||||
end
|
||||
|
||||
function lib.ProcGlow_Stop(r, key)
|
||||
key = key or ""
|
||||
local f = r["_ProcGlow" .. key]
|
||||
if f then
|
||||
ProcGlowPool:Release(f)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(lib.glowList, "Proc Glow")
|
||||
lib.startList["Proc Glow"] = lib.ProcGlow_Start
|
||||
lib.stopList["Proc Glow"] = lib.ProcGlow_Stop
|
||||
|
||||
Binary file not shown.
@@ -15,6 +15,7 @@ local default = function(parentType)
|
||||
glowType = "buttonOverlay",
|
||||
glowLines = 8,
|
||||
glowFrequency = 0.25,
|
||||
glowDuration = 1,
|
||||
glowLength = 10,
|
||||
glowThickness = 1,
|
||||
glowScale = 1,
|
||||
@@ -70,6 +71,15 @@ local properties = {
|
||||
bigStep = 0.1,
|
||||
default = 0.25
|
||||
},
|
||||
glowDuration = {
|
||||
display = L["Duration"],
|
||||
setter = "SetGlowDuration",
|
||||
type = "number",
|
||||
softMin = 0.01,
|
||||
softMax = 3,
|
||||
bigStep = 0.1,
|
||||
default = 1
|
||||
},
|
||||
glowLength = {
|
||||
display = L["Length"],
|
||||
setter = "SetGlowLength",
|
||||
@@ -121,6 +131,11 @@ local properties = {
|
||||
bigStep = 1,
|
||||
default = 0
|
||||
},
|
||||
glowStartAnim = {
|
||||
display = L["Start Animation"],
|
||||
setter = "SetGlowStartAnim",
|
||||
type = "bool",
|
||||
},
|
||||
}
|
||||
|
||||
local function glowStart(self, frame, color)
|
||||
@@ -158,6 +173,15 @@ local function glowStart(self, frame, color)
|
||||
nil,
|
||||
0
|
||||
)
|
||||
elseif self.glowType == "Proc" then
|
||||
self.glowStart(frame, {
|
||||
color = color,
|
||||
startAnim = self.glowStartAnim and true or false,
|
||||
duration = self.glowDuration,
|
||||
xOffset = self.glowXOffset,
|
||||
yOffset = self.glowYOffset,
|
||||
frameLevel = 0
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -216,6 +240,15 @@ local funcs = {
|
||||
if self.parentRegionType ~= "aurabar" then
|
||||
self.parent:AnchorSubRegion(self, "area")
|
||||
end
|
||||
elseif newType == "Proc" then
|
||||
self.glowStart = LCG.ProcGlow_Start
|
||||
self.glowStop = LCG.ProcGlow_Stop
|
||||
if self.parentRegionType ~= "aurabar" then
|
||||
self.parent:AnchorSubRegion(self, "area", "region")
|
||||
end
|
||||
else -- noop function in case of unsupported glow
|
||||
self.glowStart = function() end
|
||||
self.glowStop = function() end
|
||||
end
|
||||
self.glowType = newType
|
||||
if isGlowing then
|
||||
@@ -249,6 +282,12 @@ local funcs = {
|
||||
self:SetVisible(true)
|
||||
end
|
||||
end,
|
||||
SetGlowDuration = function(self, duration)
|
||||
self.glowDuration = duration
|
||||
if self.glow then
|
||||
self:SetVisible(true)
|
||||
end
|
||||
end,
|
||||
SetGlowLength = function(self, length)
|
||||
self.glowLength = length
|
||||
if self.glow then
|
||||
@@ -273,6 +312,12 @@ local funcs = {
|
||||
self:SetVisible(true)
|
||||
end
|
||||
end,
|
||||
SetGlowStartAnim = function(self, enable)
|
||||
self.glowStartAnim = enable
|
||||
if self.glow then
|
||||
self:SetVisible(true)
|
||||
end
|
||||
end,
|
||||
SetGlowXOffset = function(self, xoffset)
|
||||
self.glowXOffset = xoffset
|
||||
if self.glow then
|
||||
@@ -308,6 +353,9 @@ end
|
||||
|
||||
local function onRelease(subRegion)
|
||||
subRegion.glowType = nil
|
||||
if subRegion.glow then
|
||||
subRegion:SetVisible(false)
|
||||
end
|
||||
subRegion:Hide()
|
||||
subRegion:ClearAllPoints()
|
||||
subRegion:SetParent(UIParent)
|
||||
@@ -329,6 +377,8 @@ local function modify(parent, region, parentData, data, first)
|
||||
region.glowBorder = data.glowBorder
|
||||
region.glowXOffset = data.glowXOffset
|
||||
region.glowYOffset = data.glowYOffset
|
||||
region.glowStartAnim = data.glowStartAnim
|
||||
region.glowDuration = data.glowDuration
|
||||
|
||||
region:SetGlowType(data.glowType)
|
||||
region:SetVisible(data.glow)
|
||||
@@ -355,6 +405,7 @@ function Private.getDefaultGlow(regionType)
|
||||
glowType = "Pixel",
|
||||
glowLines = 8,
|
||||
glowFrequency = 0.25,
|
||||
glowDuration = 1,
|
||||
glowLength = 10,
|
||||
glowThickness = 1,
|
||||
glowScale = 1,
|
||||
@@ -372,6 +423,7 @@ function Private.getDefaultGlow(regionType)
|
||||
glowType = "buttonOverlay",
|
||||
glowLines = 8,
|
||||
glowFrequency = 0.25,
|
||||
glowDuration = 1,
|
||||
glowLength = 10,
|
||||
glowThickness = 1,
|
||||
glowScale = 1,
|
||||
|
||||
@@ -3520,6 +3520,7 @@ Private.glow_types = {
|
||||
ACShine = L["Autocast Shine"],
|
||||
Pixel = L["Pixel Glow"],
|
||||
buttonOverlay = L["Action Button Glow"],
|
||||
Proc = L["Proc Glow"]
|
||||
}
|
||||
|
||||
Private.font_sizes = {
|
||||
|
||||
@@ -3143,6 +3143,8 @@ local function actionGlowStop(actions, frame, id)
|
||||
LCG.PixelGlow_Stop(frame.__WAGlowFrame, id)
|
||||
elseif actions.glow_type == "ACShine" then
|
||||
LCG.AutoCastGlow_Stop(frame.__WAGlowFrame, id)
|
||||
elseif actions.glow_type == "Proc" then
|
||||
LCG.ProcGlow_Stop(frame.__WAGlowFrame, id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3184,6 +3186,15 @@ local function actionGlowStart(actions, frame, id)
|
||||
actions.glow_YOffset,
|
||||
id
|
||||
)
|
||||
elseif actions.glow_type == "Proc" then
|
||||
LCG.ProcGlow_Start(glow_frame, {
|
||||
color = color,
|
||||
startAnim = actions.glow_startAnim and true or false,
|
||||
xOffset = actions.glow_XOffset,
|
||||
yOffset = actions.glow_YOffset,
|
||||
duration = actions.glow_duration or 1,
|
||||
key = id
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user