forked from vattenapa/TotemFrameRelocation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTotemFrameRelocation.lua
More file actions
106 lines (87 loc) · 3.46 KB
/
TotemFrameRelocation.lua
File metadata and controls
106 lines (87 loc) · 3.46 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
local ParentFrameName = "PlayerFrame" -- Frame for the TotemFrame to attach to.
local ParentAnchorPosition = "BOTTOMRIGHT" -- Attachment point on the parent frame.
local TotemFrameAnchorPosition = "TOPRIGHT" -- Attachment point on the TotemFrame.
local UseSquareMask = true -- Apply square mask to totem icons (true or false).
local XOffset = 0 -- Horizontal offset from the attachment point.
local YOffset = 0 -- Vertical offset from the attachment point.
local MaxParentAttempts = 10 -- Max number of parent attempts before giving up until reload
local ParentAttempt = 0 -- Current number of attempts
local Disabled = false -- Disable parenting
local Verbose = true -- Display debug messages
local AddonName = ...
--If the player is not a shaman, disable the addon
if(UnitClassBase("player") ~= "SHAMAN") then
C_AddOns.DisableAddOn(AddonName, UnitName("player"))
return
end
local function Printv(message)
if (Verbose) then
print( "[".. AddonName .."]: " .. message)
end
end
local function ResetParentAttempts()
Disabled = false
ParentAttempt = 0
end
local function ReparentFrame(self)
if (Disabled) then
return
end
local ParentFrame = _G[ParentFrameName]
-- Give up if it takes too long to parent
if (ParentAttempt >= MaxParentAttempts) then
Printv(ParentFrameName .. " frame does not exist, giving up.")
Disabled = true
return
end
-- If the frame to parent exists and we're not attached to it yet
if (ParentFrame and self:GetParent() ~= ParentFrame) then
Printv("Attached " .. self:GetName() .. " to " .. ParentFrame:GetName() .. ".")
self:ClearAllPoints()
self:SetParent(ParentFrame)
self:SetPoint(TotemFrameAnchorPosition, ParentFrame, ParentAnchorPosition, XOffset, YOffset)
ResetParentAttempts()
else
-- If we're still not attached, the frame doesn't exist
if (self:GetParent() ~= ParentFrame) then
Printv(ParentFrameName .. " frame not found, retrying.")
ParentAttempt = ParentAttempt + 1
C_Timer.After(1, function()
ReparentFrame(self)
end)
end
end
end
-- Function to modify the totem button on load
local function ModifyTotemButton(self)
-- Hide the border
self.Border:Hide()
-- Get atlas information for square mask
local squareMaskAtlas = C_Texture.GetAtlasInfo("SquareMask")
local left, right, top, bottom = squareMaskAtlas.leftTexCoord, squareMaskAtlas.rightTexCoord,
squareMaskAtlas.topTexCoord, squareMaskAtlas.bottomTexCoord
-- Set icon texture and coordinates
self.Icon.TextureMask:SetTexture(squareMaskAtlas.file or squareMaskAtlas.filename)
self.Icon.TextureMask:SetTexCoord(left, right, top, bottom)
-- Set swipe texture and coordinates
local lowTexCoords = { x = left, y = top }
local highTexCoords = { x = right, y = bottom }
self.Icon.Cooldown:SetSwipeTexture(squareMaskAtlas.file or squareMaskAtlas.filename)
self.Icon.Cooldown:SetTexCoordRange(lowTexCoords, highTexCoords)
end
if (UseSquareMask) then
-- Hook the OnLoad function to modify totem buttons
hooksecurefunc(TotemButtonMixin, "OnLoad", ModifyTotemButton)
-- Modify existing totem buttons
for button in TotemFrame.totemPool:EnumerateActive() do
ModifyTotemButton(button)
end
end
-- Register PLAYER_LOGIN event and set OnEvent script
TotemFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
TotemFrame:HookScript("OnShow", ReparentFrame)
TotemFrame:HookScript("OnEvent", function(self, event)
if (event == "PLAYER_ENTERING_WORLD") then
ReparentFrame(self)
end
end)