Skip to content

Commit

Permalink
[Feature] Add PostUpdate API fn to Auras & Glow Helpers (#91)
Browse files Browse the repository at this point in the history
* Add util functions for glows

* add PostUpdate fn call to auras

* mark global EventUtil

* create example snippet for applying glow
  • Loading branch information
Krealle authored Sep 28, 2024
1 parent af23df8 commit 2ac6b43
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"GAME_LOCALE",
"SetRaidTargetIconTexture",
"PlayerCastingBarFrame",
"CellLayoutsPreviewButton"
"CellLayoutsPreviewButton",
"EventUtil"
]
}
26 changes: 26 additions & 0 deletions Snippets/AuraGlow.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Run Snippet late to ensure addon is properly loaded
EventUtil.RegisterOnceFrameEventAndCallback("LOADING_SCREEN_DISABLED", function()
local Util = CUF.Util

local function PostUpdate(icon, auraData)
if auraData.spellId == 393438 then
Util.GlowStart_Normal(icon)
else
Util.GlowStop(icon)
end
end

-- Override PostUpdate for all auras
Util:IterateAllUnitButtons(function(button, unit)
-- Nil check
if not button:HasWidget("buffs") then return end

-- NOTE: Only apply to player
-- if unit ~= "player" then return end

-- can also iterate "button.widgets.debuffs"
for _, icon in ipairs(button.widgets.buffs) do
icon.PostUpdate = PostUpdate
end
end)
end)
89 changes: 89 additions & 0 deletions Util/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,95 @@ function Util.GetPositionRelativeToScreenCenter(frame)
return relativeX, relativeY
end

-------------------------------------------------
-- MARK: Glow
-------------------------------------------------

local LCG = LibStub("LibCustomGlow-1.0")
---@class GlowFrame: Frame
---@field __glowing string?

---@param frame GlowFrame|CellAuraIcon
---@param color RGBAOpt?
---@param N number?
---@param frequency number?
---@param length number?
---@param thickness number?
---@param xOffset number?
---@param yOffset number?
---@param border boolean?
---@param key string?
---@param frameLevel number?
function Util.GlowStart_Pixel(frame, color, N, frequency, length, thickness, xOffset, yOffset, border, key, frameLevel)
if frame.__glowing ~= "Pixel" then
Util.GlowStop(frame, key)
end

LCG.PixelGlow_Start(frame, color, N, frequency, length, thickness, xOffset, yOffset, border, key, frameLevel)
frame.__glowing = "Pixel"
end

---@param frame GlowFrame|CellAuraIcon
---@param color RGBAOpt?
---@param N number?
---@param frequency number?
---@param scale number?
---@param xOffset number?
---@param yOffset number?
---@param key string?
---@param frameLevel number?
function Util.GlowStart_Shine(frame, color, N, frequency, scale, xOffset, yOffset, key, frameLevel)
if frame.__glowing ~= "Shine" then
Util.GlowStop(frame, key)
end

LCG.AutoCastGlow_Start(frame, color, N, frequency, scale, xOffset, yOffset, key, frameLevel)
frame.__glowing = "Shine"
end

---@param frame GlowFrame|CellAuraIcon
---@param color RGBAOpt?
---@param duration number?
---@param startAnim boolean?
---@param xOffset number?
---@param yOffset number?
---@param key string?
---@param frameLevel number?
function Util.GlowStart_Proc(frame, color, duration, startAnim, xOffset, yOffset, key, frameLevel)
if frame.__glowing ~= "Proc" then
Util.GlowStop(frame, key)
end

LCG.ProcGlow_Start(frame, color, duration, startAnim, xOffset, yOffset, key, frameLevel)
frame.__glowing = "Proc"
end

---@param frame GlowFrame|CellAuraIcon
---@param color RGBAOpt?
---@param frequency number?
---@param frameLevel number?
function Util.GlowStart_Normal(frame, color, frequency, frameLevel)
if frame.__glowing ~= "Normal" then
Util.GlowStop(frame)
end

LCG.ButtonGlow_Start(frame, color, frequency, frameLevel)
frame.__glowing = "Normal"
end

---@param frame GlowFrame|CellAuraIcon
---@param key string?
function Util.GlowStop(frame, key)
if not frame.__glowing then return end

LCG.ButtonGlow_Stop(frame, key)
LCG.PixelGlow_Stop(frame, key)
LCG.AutoCastGlow_Stop(frame, key)
LCG.ProcGlow_Stop(frame, key)

frame.__glowing = nil
end

-------------------------------------------------
-- MARK: Formatting
-------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions Widgets/Auras/Auras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ local function Icons_HidePreview(icons)
end
end

-------------------------------------------------
-- MARK: API Functions
-------------------------------------------------

---@param icon CellAuraIcon
---@param auraDate AuraData
function Icon_PostUpdate(icon, auraDate)
end

-------------------------------------------------
-- MARK: Update
-------------------------------------------------
Expand Down Expand Up @@ -351,6 +360,12 @@ function W:CreateAuraIcons(button, type)
frame:SetScript("OnUpdate", Icon_OnUpdate)
end
end)

icon:HookScript("OnHide", function()
Util.GlowStop(icon)
end)

icon.PostUpdate = Icon_PostUpdate
end

auraIcons.SetEnabled = W.SetEnabled
Expand Down Expand Up @@ -429,6 +444,7 @@ W:RegisterCreateWidgetFunc(const.WIDGET_KIND.DEBUFFS, W.CreateDebuffs)
---@field ShowStack fun(frame, show) Shared_ShowStack
---@field ShowAnimation fun(frame, show) BarIcon_ShowAnimation
---@field UpdatePixelPerfect fun(frame) BarIcon_UpdatePixelPerfect
---@field PostUpdate fun(self: CellAuraIcon, auraDate: AuraData) Icon_PostUpdate
---@field cooldown StatusBar
---@field GetCooldownDuration function
---@field ShowCooldown function
Expand All @@ -437,6 +453,7 @@ W:RegisterCreateWidgetFunc(const.WIDGET_KIND.DEBUFFS, W.CreateDebuffs)
---@field preview CellAuraIcon.preview
---@field showDuration boolean
---@field _showDuration boolean
---@field __glowing string?

---@class CellAuraIcons: Frame
---@field indicatorType "icons"
Expand Down
2 changes: 2 additions & 0 deletions Widgets/Auras/Handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ local function UpdateAuraIcons(icons)
auraData.refreshing
)
icons[icons._auraCount].index = auraData.index -- Tooltip

icons[icons._auraCount]:PostUpdate(auraData)
end

-- Resize
Expand Down

0 comments on commit 2ac6b43

Please sign in to comment.