From 802285a613b8126bfe0b1ad186d7c8229233bed0 Mon Sep 17 00:00:00 2001 From: rawoil Date: Tue, 28 Sep 2021 11:23:16 +0800 Subject: [PATCH] skin wa --- rSkin/modules/WeakAuras.lua | 101 +++++++++++++++++++++++++++++++++++++++++++ rSkin/rSkin.toc | 3 +- 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 rSkin/modules/WeakAuras.lua diff --git a/rSkin/modules/WeakAuras.lua b/rSkin/modules/WeakAuras.lua new file mode 100644 index 0000000..7657243 --- /dev/null +++ b/rSkin/modules/WeakAuras.lua @@ -0,0 +1,101 @@ +local A, L = ... + +-- credit: ndui +local pairs, unpack = pairs, unpack +local buttonConfig = rLib.CopyTable(rButtonTemplate_Zork_ActionButtonConfig) +buttonConfig.backdrop.bgColor = buttonConfig.backdrop.backgroundColor +buttonConfig.backdrop.edgeColor = buttonConfig.backdrop.borderColor +buttonConfig.backdrop.inset = 3 + +local function IconBgOnUpdate(self) + self:SetAlpha(self.__icon:GetAlpha()) + if self.__shadow then + self.__shadow:SetAlpha(self.__icon:GetAlpha()) + end +end + +local function UpdateIconTexCoord(icon) + if icon.isCutting then return end + icon.isCutting = true + + local width, height = icon:GetSize() + if width ~= 0 and height ~= 0 then + local left, right, top, bottom = unpack(buttonConfig.icon.texCoord) -- normal icon + local ratio = width/height + if ratio > 1 then -- fat icon + local offset = (1 - 1/ratio) / 2 + top = top + offset + bottom = bottom - offset + elseif ratio < 1 then -- thin icon + local offset = (1 - ratio) / 2 + left = left + offset + bottom = bottom - offset + end + icon:SetTexCoord(left, right, top, bottom) + end + + icon.isCutting = nil +end + +local function SkinWeakAuras(f, fType) + if fType == "icon" then + if not f.styled then + UpdateIconTexCoord(f.icon) + hooksecurefunc(f.icon, "SetTexCoord", UpdateIconTexCoord) + f.bg = L.CreateBackdrop(f, nil, buttonConfig.backdrop) + f.bg:SetFrameLevel(0) + f.bg.__icon = f.icon + f.bg:HookScript("OnUpdate", IconBgOnUpdate) + + f.styled = true + end + elseif fType == "aurabar" then + if not f.styled then + f.bg = L.CreateBackdrop(f.bar) + f.bg:SetFrameLevel(0) + UpdateIconTexCoord(f.icon) + hooksecurefunc(f.icon, "SetTexCoord", UpdateIconTexCoord) + f.iconFrame:SetAllPoints(f.icon) -- needs review + + f.styled = true + end + end +end + +local function ReskinWA() + if not IsAddOnLoaded("WeakAuras") then return end + + local regionTypes = WeakAuras.regionTypes + local CreateIcon, ModifyIcon = regionTypes.icon.create, regionTypes.icon.modify + local CreateAuraBar, ModifyAuraBar = regionTypes.aurabar.create, regionTypes.aurabar.modify + + regionTypes.icon.create = function(parent, data) + local region = CreateIcon(parent, data) + SkinWeakAuras(region, "icon") + return region + end + + regionTypes.aurabar.create = function(parent) + local region = CreateAuraBar(parent) + SkinWeakAuras(region, "aurabar") + return region + end + + regionTypes.icon.modify = function(parent, region, data) + ModifyIcon(parent, region, data) + SkinWeakAuras(region, "icon") + end + + regionTypes.aurabar.modify = function(parent, region, data) + ModifyAuraBar(parent, region, data) + SkinWeakAuras(region, "aurabar") + end + + for _, regions in pairs(WeakAuras.regions) do + if regions.regionType == "icon" or regions.regionType == "aurabar" then + SkinWeakAuras(regions.region, regions.regionType) + end + end +end + +rSkin:RegisterSkin("WeakAuras", ReskinWA) \ No newline at end of file diff --git a/rSkin/rSkin.toc b/rSkin/rSkin.toc index a18827f..a6978a6 100644 --- a/rSkin/rSkin.toc +++ b/rSkin/rSkin.toc @@ -9,4 +9,5 @@ init.lua modules\ls_Toasts.lua modules\Details.lua modules\BigWigs.lua -modules\DBM.lua \ No newline at end of file +modules\DBM.lua +modules\WeakAuras.lua \ No newline at end of file -- 1.7.9.5