-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCore.lua
More file actions
132 lines (118 loc) · 4.06 KB
/
Core.lua
File metadata and controls
132 lines (118 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
local addonName, addon = ...
local DEFAULTS = {
parentFrameName = nil,
parentAnchor = "BOTTOMRIGHT",
totemFrameAnchor = "TOPRIGHT",
useSquareMask = true,
xOffset = 0,
yOffset = 0,
}
local db
local function InitDB()
TotemFrameRelocationDB = TotemFrameRelocationDB or {}
db = TotemFrameRelocationDB
for key, value in pairs(DEFAULTS) do
if db[key] == nil then
db[key] = value
end
end
addon.db = db
end
local function ModifyTotemButton(button)
button.Border:Hide()
local atlas = C_Texture.GetAtlasInfo("SquareMask")
local left, right, top, bottom = atlas.leftTexCoord, atlas.rightTexCoord, atlas.topTexCoord, atlas.bottomTexCoord
local file = atlas.file or atlas.filename
button.Icon.TextureMask:SetTexture(file)
button.Icon.TextureMask:SetTexCoord(left, right, top, bottom)
button.Icon.Cooldown:SetSwipeTexture(file)
button.Icon.Cooldown:SetTexCoordRange({ x = left, y = top }, { x = right, y = bottom })
end
local function RestoreTotemButton(button)
button.Border:Show()
local atlas = C_Texture.GetAtlasInfo("CircleMask")
local left, right, top, bottom = atlas.leftTexCoord, atlas.rightTexCoord, atlas.topTexCoord, atlas.bottomTexCoord
local file = atlas.file or atlas.filename
button.Icon.TextureMask:SetTexture(file)
button.Icon.TextureMask:SetTexCoord(left, right, top, bottom)
button.Icon.Cooldown:SetSwipeTexture(file)
button.Icon.Cooldown:SetTexCoordRange({ x = left, y = top }, { x = right, y = bottom })
end
local squareMaskHooked = false
local function ApplySquareMask()
if db.useSquareMask then
if not squareMaskHooked then
hooksecurefunc(TotemButtonMixin, "OnLoad", function(button)
if db.useSquareMask then
ModifyTotemButton(button)
end
end)
squareMaskHooked = true
end
for button in TotemFrame.totemPool:EnumerateActive() do
ModifyTotemButton(button)
end
else
for button in TotemFrame.totemPool:EnumerateActive() do
RestoreTotemButton(button)
end
end
end
local MAX_RETRIES = 10
local onShowHooked = false
local function ReparentFrame()
if not db.parentFrameName then return end
local parentFrame = _G[db.parentFrameName]
if not parentFrame then return end
TotemFrame:SetParent(parentFrame)
TotemFrame:ClearAllPoints()
TotemFrame:SetPoint(db.totemFrameAnchor, parentFrame, db.parentAnchor, db.xOffset, db.yOffset)
if not onShowHooked then
TotemFrame:HookScript("OnShow", function() ReparentFrame() end)
onShowHooked = true
end
end
local function DetachFrame()
TotemFrame:SetParent(PlayerFrame)
TotemFrame:ClearAllPoints()
TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "BOTTOMLEFT", 0, 0)
end
-- I have no fucking clue how to know that the expected frame is loaded/active.
local function AttachWithRetry()
if not db.parentFrameName then return end
local retries = 0
local function tryAttach()
if _G[db.parentFrameName] then
ReparentFrame()
else
retries = retries + 1
if retries <= MAX_RETRIES then
C_Timer.After(1, tryAttach)
else
print("|cFFFF6600TotemFrameRelocation:|r Could not find frame '" .. db.parentFrameName .. "' after " .. MAX_RETRIES .. " seconds.")
end
end
end
tryAttach()
end
function addon:ApplySettings()
if db.parentFrameName then
ReparentFrame()
else
DetachFrame()
end
ApplySquareMask()
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:SetScript("OnEvent", function(_, event, arg1)
if event == "ADDON_LOADED" and arg1 == addonName then
InitDB()
eventFrame:UnregisterEvent("ADDON_LOADED")
elseif event == "PLAYER_LOGIN" then
AttachWithRetry()
ApplySquareMask()
eventFrame:UnregisterEvent("PLAYER_LOGIN")
end
end)