Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AddOnSkins/Core/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function AS:Desaturate(frame)
end

function AS:SkinTooltip(tooltip, scale)
return AS:SkinTooltip(tooltip, scale)
return S:HandleTooltip(tooltip, scale)
end

function AS:AdjustForTheme(number, offset)
Expand All @@ -128,4 +128,4 @@ end

function AS:EnumObjects(enumFuncs, yieldFunc)
return S:EnumObjects(enumFuncs, yieldFunc)
end
end
90 changes: 70 additions & 20 deletions AddOnSkins/Core/Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ local AddOnName = ...
local ES = AS.EmbedSystem

local _G = _G
local pairs, ipairs, type, pcall, tinsert = pairs, ipairs, type, pcall, tinsert
local floor, print, format, strlower, strmatch, strlen = floor, print, format, strlower, strmatch, strlen
local select, pairs, ipairs, type, pcall, tinsert = select, pairs, ipairs, type, pcall, tinsert
local floor, print, format, strlower, strfind, strmatch, strlen = floor, print, format, strlower, strfind, strmatch, strlen
local sort = sort

local geterrorhandler = geterrorhandler
local IsAddOnLoaded, C_Timer = C_AddOns.IsAddOnLoaded, C_Timer
local C_AddOns = C_AddOns
local IsAddOnLoaded = (C_AddOns and C_AddOns.IsAddOnLoaded) or _G.IsAddOnLoaded
if not IsAddOnLoaded then
IsAddOnLoaded = function() return false end
end
local C_Timer = C_Timer

AS.SkinErrors = {}

local Validator = CreateFrame('Frame')

function AS:CheckOption(optionName, ...)
for _, addon in next, {...} do
for i = 1, select('#', ...) do
local addon = select(i, ...)
if not addon then break end
if not AS:CheckAddOn(addon) then return false end
end
Expand Down Expand Up @@ -63,7 +70,22 @@ function AS:Delay(delay, func)
end

function AS:CheckAddOn(addon)
return AS.AddOns[strlower(addon)] or false
local key = strlower(addon or '')
-- Prefer runtime loaded state: enable-state APIs can be unreliable on Anniversary
-- (per-character enablement stored differently than on Retail).
local loaded = (C_AddOns and C_AddOns.IsAddOnLoaded and C_AddOns.IsAddOnLoaded(addon))
or (_G.IsAddOnLoaded and _G.IsAddOnLoaded(addon))
if loaded then return true end
-- ElvUI may not appear enabled in the addon list on Anniversary but its global is present.
if key == 'elvui' then return _G.ElvUI ~= nil end
if AS.AddOns[key] ~= nil then return AS.AddOns[key] end
local state
if C_AddOns and C_AddOns.GetAddOnEnableState then
state = C_AddOns.GetAddOnEnableState(addon, AS.MyName)
else
state = _G.GetAddOnEnableState and _G.GetAddOnEnableState(AS.MyName, addon)
end
return (state or 0) > 0
end

function AS:GetAddOnVersion(addon)
Expand All @@ -83,6 +105,24 @@ function AS:Round(num, idp)
return floor(num * mult + 0.5) / mult
end

function AS:Scale(Number)
return AS.Mult * floor(Number / AS.Mult + .5)
end

function AS:OrderedPairs(t, f)
local a = {}
for n in pairs(t) do tinsert(a, n) end
sort(a, f)
local i = 0
local iter = function()
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end

function AS:RegisterForPetBattleHide(frame)
RegisterStateDriver(frame, 'visibility', '[petbattle] hide; show')
end
Expand Down Expand Up @@ -159,9 +199,12 @@ local function errorhandler(err)
end

function AS:CallSkin(addonName, func, event, ...)
if AS.Debug then
if AS.Debug or AS:CheckOption('SkinDebug') then
local args = {...}
xpcall(function() func(self, event, unpack(args)) end, errorhandler)
local ok, err = xpcall(function() func(self, event, unpack(args)) end, function(e) return e..'\n'..debugstack() end)
if not ok then
AS:Print('SkinDebug ['..addonName..']: '..tostring(err))
end
else
local pass = pcall(func, self, event, ...)
if not pass then
Expand Down Expand Up @@ -196,7 +239,7 @@ function AS:UnregisterSkinEvent(addonName, event)
end

function AS:UpdateMedia()
AS.Blank = AS.Libs.LSM:Fetch('statusbar', 'Solid')
AS.Blank = AS.Libs.LSM:Fetch('background', 'Solid') or AS.Libs.LSM:Fetch('statusbar', 'Solid')
AS.Font = AS.Libs.LSM:Fetch('font', "Friz Quadrata TT")
AS.PixelFont = AS.Libs.LSM:Fetch('font', "Arial Narrow")
AS.NormTex = AS.Libs.LSM:Fetch('statusbar', "Blizzard")
Expand All @@ -218,7 +261,7 @@ function AS:StartUp(event, ...)
AS:SecureHook(_G.ElvUI[1], 'UpdateMedia')
end

if not AS.Debug then
if not AS.Debug and not AS:CheckOption('SkinDebug') then
for Version, SkinTable in pairs(_G.AddOnSkinsDS) do
if Version == AS.Version or Version < AS.Version then
if Version < AS.Version then
Expand All @@ -233,7 +276,7 @@ function AS:StartUp(event, ...)

-- Check Blizzard for already loaded
for addonName, funcs in next, AS.skins do
if strmatch(addonName, '^Blizzard_') and AS:CheckOption(addonName) then
if strfind(addonName, '^Blizzard_') and AS:CheckOption(addonName) then
for _, func in ipairs(funcs) do
if IsAddOnLoaded(addonName) then
AS:CallSkin(addonName, func, 'ADDON_LOADED', addonName)
Expand All @@ -254,30 +297,37 @@ function AS:StartUp(event, ...)
end

ES:Initialize()
ES:HookToggleButtonTooltip()

AS.RunOnce = true
end

function AS:Init(event, addon)
if event == 'ADDON_LOADED' and (AS.Initialized or IsAddOnLoaded(AddOnName)) then
if addon == AddOnName then
AS.Initialized = true
AS:BuildProfile()
AS:UpdateMedia()

for addonName, funcs in next, AS.preload do
if AS.AlreadyLoaded[addonName] then
AS:RunPreload(addonName)
end
-- IsAddOnLoaded can be nil on Anniversary; use the addon argument as the reliable signal.
if event == 'ADDON_LOADED' and addon == AddOnName then
AS.Initialized = true
AS:BuildProfile()
AS:UpdateMedia()

for addonName in next, AS.preload do
if AS.AlreadyLoaded[addonName] then
AS:RunPreload(addonName)
end
end
end

if event == 'ADDON_LOADED' and AS.Initialized then
AS:RunPreload(addon)
end

if event == 'PLAYER_LOGIN' then
AS:BuildOptions()

-- Resolve EP lazily: ElvUI_Libraries may load after AddOnSkins Init.lua runs.
if not AS.Libs.EP then
AS.Libs.EP = LibStub('LibElvUIPlugin-1.0', true)
end

for addOnEvent in pairs(AS.events) do
AS:RegisterEvent(addOnEvent, 'SkinEvent')
end
Expand Down
51 changes: 33 additions & 18 deletions AddOnSkins/Core/ElvUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ local ES = AS.EmbedSystem
local E, L = unpack(ElvUI)

function AS:UpdateMedia()
if not E then E = unpack(ElvUI) end

S.Media.Blank = AS.Libs.LSM:Fetch('background', 'ElvUI Blank')
S.Media.StatusBar = AS.Libs.LSM:Fetch('statusbar', E.private.general.normTex)

Expand All @@ -20,6 +22,11 @@ function AS:UpdateMedia()
S.Media.borderColor = E.media.bordercolor
S.Media.valueColor = E.media.rgbvaluecolor

-- Also update the AS-level fields used by skins that reference AS.BackdropColor etc.
AS.BackdropColor = E.media.backdropcolor
AS.BorderColor = E.media.bordercolor
AS.Color = E.media.rgbvaluecolor or AS.ClassColor

S.Media.TexCoords = { 0, 1, 0, 1 }
local modifier = 0.04 * E.db.general.cropIcon
for i, v in ipairs(S.Media.TexCoords) do
Expand All @@ -44,7 +51,6 @@ function ES:Hooks()
hooksecurefunc(E:GetModule('Layout'), 'ToggleChatPanels', function() ES:Check() end)

if RightChatToggleButton then
RightChatToggleButton:RegisterForClicks('AnyDown')
RightChatToggleButton:SetScript('OnClick', function(s, btn)
if btn == 'RightButton' then
if ES.Main:IsShown() then
Expand All @@ -70,26 +76,35 @@ function ES:Hooks()
end
end
end)
end
end

RightChatToggleButton:SetScript('OnEnter', function(s)
if E.db[s.parent:GetName()..'Faded'] then
s.parent:Show()
UIFrameFadeIn(s.parent, 0.2, s.parent:GetAlpha(), 1)
UIFrameFadeIn(s, 0.2, s:GetAlpha(), 1)
if not AS:CheckOption('EmbedIsHidden') then
ES.Main:Show()
end
-- Hook RightChatToggleButton tooltip unconditionally so the Right Click
-- line appears even when the embed system is disabled.
function ES:HookToggleButtonTooltip()
if not (E and RightChatToggleButton) then return end
if RightChatToggleButton._asTipHooked then return end
RightChatToggleButton._asTipHooked = true

RightChatToggleButton:RegisterForClicks('AnyDown')
RightChatToggleButton:HookScript('OnEnter', function(s)
if E.db[s.parent:GetName()..'Faded'] then
s.parent:Show()
UIFrameFadeIn(s.parent, 0.2, s.parent:GetAlpha(), 1)
UIFrameFadeIn(s, 0.2, s:GetAlpha(), 1)
if not AS:CheckOption('EmbedIsHidden') then
ES.Main:Show()
end
end

if not s.parent.editboxforced then
_G.GameTooltip:SetOwner(s, 'ANCHOR_TOPLEFT', 0, 4)
_G.GameTooltip:ClearLines()
_G.GameTooltip:AddDoubleLine(L["Left Click:"], L["Toggle Chat Frame"], 1, 1, 1)
_G.GameTooltip:AddDoubleLine(L["Right Click:"], L["Toggle Embedded Addon"], 1, 1, 1)
_G.GameTooltip:Show()
end
end)
end
if not s.parent.editboxforced then
_G.GameTooltip:SetOwner(s, 'ANCHOR_TOPLEFT', 0, 4)
_G.GameTooltip:ClearLines()
_G.GameTooltip:AddDoubleLine(L["Left Click:"], L["Toggle Chat Frame"], 1, 1, 1)
_G.GameTooltip:AddDoubleLine(L["Right Click:"], L["Toggle Embedded Addon"], 1, 1, 1)
_G.GameTooltip:Show()
end
end)
end

function ES:Resize()
Expand Down
14 changes: 8 additions & 6 deletions AddOnSkins/Core/EmbedSystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,20 @@ function ES:Check(Message)
if not (AS:CheckOption('EmbedSystem') or AS:CheckOption('EmbedSystemDual')) then return end

ES:Resize()
ES.Main:SetShown(not (AS:CheckOption('EmbedIsHidden') or AS:CheckOption('EmbedOoC')))
local shouldShow = not (AS:CheckOption('EmbedIsHidden') or AS:CheckOption('EmbedOoC'))
ES.Main:SetShown(shouldShow)
ES:ToggleChatFrame(shouldShow)

for _, Window in next, ES.Windows do
Window:SetFrameStrata(strsub(AS:CheckOption('EmbedFrameStrata'), 3))
Window:SetFrameLevel(AS:CheckOption('EmbedFrameLevel'))
end

if AS:CheckEmbed('Details') then ES:Details() end
if AS:CheckEmbed('Omen') then ES:Omen() end
if AS:CheckEmbed('Skada') then ES:Skada() end
if AS:CheckEmbed('TinyDPS') then ES:TinyDPS() end
if AS:CheckEmbed('Recount') then ES:Recount() end
if AS:CheckEmbed('Details') and ES.Details then ES:Details() end
if AS:CheckEmbed('Omen') and ES.Omen then ES:Omen() end
if AS:CheckEmbed('Skada') and ES.Skada then ES:Skada() end
if AS:CheckEmbed('TinyDPS') and ES.TinyDPS then ES:TinyDPS() end
if AS:CheckEmbed('Recount') and ES.Recount then ES:Recount() end

if Message and AS:CheckOption('EmbedSystemMessage') then
if AS:CheckOption('EmbedMain') then AS:Print(format(L["Embed System: Main: '%s'"], AS:CheckOption('EmbedMain'))) end
Expand Down
8 changes: 7 additions & 1 deletion AddOnSkins/Core/Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ local strlower = strlower
local strtrim = strtrim
local unpack = unpack

local GetAddOnMetadata = C_AddOns and C_AddOns.GetAddOnMetadata or GetAddOnMetadata
local C_AddOns = C_AddOns
local GetAddOnMetadata = (C_AddOns and C_AddOns.GetAddOnMetadata) or _G.GetAddOnMetadata
local GENERAL = GENERAL
local hooksecurefunc = hooksecurefunc
local tContains = tContains
Expand Down Expand Up @@ -109,6 +110,7 @@ AS.Options.args.general = ACH:Group(GENERAL, nil, 0, nil, function(info) return
AS.Options.args.general.args.general = ACH:Group(' ', nil, 1)
AS.Options.args.general.args.general.inline = true
AS.Options.args.general.args.general.args.LoginMsg = ACH:Toggle(L["Login Message"], nil, 1)
AS.Options.args.general.args.general.args.SkinDebug = ACH:Toggle('Enable Skin Debugging', nil, 2)

AS.Options.args.general.args.Theme = ACH:Select(L["Themes"], nil, 2, { PixelPerfect = L["Thin Border"], TwoPixel = L["Two Pixel"], ThickBorder = L["Thick Border"] })
AS.Options.args.general.args.SkinTemplate = ACH:Select(L["Template"], nil, 3, function() local tbl = CopyTable(DefaultTemplates) if AS:CheckOption('ElvUIStyle', 'ElvUI') then tbl.Custom = nil end return tbl end)
Expand Down Expand Up @@ -223,6 +225,7 @@ function AS:BuildProfile()
HideChatFrame = 'NONE',
HighlightColor = { 1, .8, .1 },
LoginMsg = false,
SkinDebug = false,
Parchment = false,
SelectedColor = { 0, 0.44, .87 },
Shadows = true,
Expand Down Expand Up @@ -288,6 +291,9 @@ function AS:BuildOptions()

if AS.Libs.EP and AS:CheckAddOn('ElvUI') then
AS.Libs.EP:RegisterPlugin('AddOnSkins', AS.GetOptions)
-- On Anniversary, LibElvUIPlugin may not fire the callback if ElvUI_Options
-- is already loaded by this point. Force one call to ensure hooks are set up.
C_Timer.After(0, function() pcall(AS.GetOptions, AS) end)
else
AS.Libs.AC:RegisterOptionsTable('AddOnSkins', AS.Options)
AS.Libs.ACD:AddToBlizOptions('AddOnSkins', 'AddOnSkins')
Expand Down
30 changes: 23 additions & 7 deletions AddOnSkins/Core/Skins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1488,14 +1488,19 @@ do
function S:HandleCloseButton(button, point, x, y)
S:StripTextures(button)

if not button.Texture then
button.Texture = button:CreateTexture(nil, 'OVERLAY')
-- button.Texture may exist as a parentKey from UIPanelCloseButton but still
-- hold a numeric fileID after StripTextures. Only skip if it's a string path
-- (i.e. was already set by a previous HandleCloseButton call).
if not button.Texture or type(button.Texture:GetTexture()) ~= 'string' then
if not button.Texture then
button.Texture = button:CreateTexture(nil, 'OVERLAY')
button:HookScript('OnEnter', closeOnEnter)
button:HookScript('OnLeave', closeOnLeave)
button:SetHitRectInsets(6, 6, 7, 7)
end
S:Point(button.Texture, 'CENTER')
button.Texture:SetTexture(Media.Close)
S:Size(button.Texture, 12, 12)
button:HookScript('OnEnter', closeOnEnter)
button:HookScript('OnLeave', closeOnLeave)
button:SetHitRectInsets(6, 6, 7, 7)
end

if point then
Expand Down Expand Up @@ -1670,8 +1675,19 @@ function S:HandleTooltip(tooltip, scale, showHook)
S:HandleBlizzardRegions(tooltip)
S:SetTemplate(tooltip, nil, nil, nil, nil, nil, nil, nil, true)

-- HandleBlizzardRegions hides .Center (it's in BlizzardRegions list),
-- but SetTemplate needs it as the backdrop fill texture. Re-show it.
if tooltip.Center and not tooltip.Center:IsShown() then
tooltip.Center:Show()
end

if showHook then
tooltip:HookScript('OnShow', function(tt) S:SetTemplate(tt) end)
tooltip:HookScript('OnShow', function(tt)
S:SetTemplate(tt)
if tt.Center and not tt.Center:IsShown() then
tt.Center:Show()
end
end)
end

if scale then
Expand Down Expand Up @@ -2295,4 +2311,4 @@ function S:PLAYER_LOGIN()
end
end

S:RegisterEvent('PLAYER_LOGIN')
S:RegisterEvent('PLAYER_LOGIN')
Loading