-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimapButton.lua
More file actions
140 lines (121 loc) · 4.37 KB
/
Copy pathMinimapButton.lua
File metadata and controls
140 lines (121 loc) · 4.37 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
133
134
135
136
137
138
139
140
local ADDON_NAME = ...
local L = HelloGuild_L
local button
local dragging = false
local function UpdatePosition()
if not button then return end
local angle = math.rad(HelloGuildDB.minimapAngle or 220)
local radiusX = (Minimap:GetWidth() / 2) + 4
local radiusY = (Minimap:GetHeight() / 2) + 4
button:ClearAllPoints()
button:SetPoint(
"CENTER",
Minimap,
"CENTER",
math.cos(angle) * radiusX,
math.sin(angle) * radiusY
)
end
local function UpdatePositionFromCursor()
local scale = Minimap:GetEffectiveScale()
local cursorX, cursorY = GetCursorPosition()
local centerX, centerY = Minimap:GetCenter()
cursorX, cursorY = cursorX / scale, cursorY / scale
HelloGuildDB.minimapAngle = math.deg(
math.atan2(cursorY - centerY, cursorX - centerX)
)
UpdatePosition()
end
function HelloGuild_SetMinimapButtonShown(shown)
if not button then return end
button:SetShown(shown and true or false)
end
function HelloGuild_ResetMinimapButtonPosition()
HelloGuildDB.minimapAngle = 220
UpdatePosition()
end
local function CreateMinimapButton()
button = CreateFrame("Button", "HelloGuildMinimapButton", Minimap)
button:SetSize(32, 32)
button:SetFrameStrata("MEDIUM")
button:SetFrameLevel(8)
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:RegisterForDrag("LeftButton")
local outerMask = button:CreateMaskTexture()
outerMask:SetTexture("Interface\\CharacterFrame\\TempPortraitAlphaMask")
outerMask:SetSize(30, 30)
outerMask:SetPoint("CENTER")
local rim = button:CreateTexture(nil, "BACKGROUND")
rim:SetSize(30, 30)
rim:SetPoint("CENTER")
rim:SetColorTexture(0.85, 0.68, 0.12, 1)
rim:AddMaskTexture(outerMask)
local innerMask = button:CreateMaskTexture()
innerMask:SetTexture("Interface\\CharacterFrame\\TempPortraitAlphaMask")
innerMask:SetSize(25, 25)
innerMask:SetPoint("CENTER")
local background = button:CreateTexture(nil, "BORDER")
background:SetSize(25, 25)
background:SetPoint("CENTER")
background:SetColorTexture(0.03, 0.03, 0.03, 1)
background:AddMaskTexture(innerMask)
local icon = button:CreateTexture(nil, "ARTWORK")
icon:SetSize(20, 20)
icon:SetPoint("CENTER")
icon:SetTexture("Interface\\Icons\\Achievement_GuildPerk_EverybodysFriend")
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
icon:AddMaskTexture(innerMask)
local highlight = button:CreateTexture(nil, "HIGHLIGHT")
highlight:SetSize(28, 28)
highlight:SetPoint("CENTER")
highlight:SetColorTexture(1, 0.82, 0.2, 0.25)
highlight:AddMaskTexture(outerMask)
button:SetScript("OnClick", function(_, mouseButton)
if dragging then
dragging = false
return
end
if mouseButton == "RightButton" then
local enabled = not HelloGuildDB.enabled
if HelloGuild_SetEnabledOption then
HelloGuild_SetEnabledOption("enabled", enabled)
else
HelloGuildDB.enabled = enabled
end
DEFAULT_CHAT_FRAME:AddMessage(
"|cff33ff99HelloGuild:|r "
.. L.MINIMAP_TOGGLE:format(HelloGuildDB.enabled and L.ENABLED or L.DISABLED)
)
elseif HelloGuild_OpenOptions then
HelloGuild_OpenOptions()
end
end)
button:SetScript("OnDragStart", function()
dragging = true
button:SetScript("OnUpdate", UpdatePositionFromCursor)
end)
button:SetScript("OnDragStop", function()
button:SetScript("OnUpdate", nil)
end)
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine("HelloGuild", 0.2, 1, 0.6)
GameTooltip:AddLine(L.MINIMAP_LEFT, 1, 1, 1)
GameTooltip:AddLine(L.MINIMAP_RIGHT, 1, 1, 1)
GameTooltip:AddLine(L.MINIMAP_DRAG, 0.7, 0.7, 0.7)
GameTooltip:Show()
end)
button:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
Minimap:HookScript("OnSizeChanged", UpdatePosition)
UpdatePosition()
HelloGuild_SetMinimapButtonShown(HelloGuildDB.minimapButton)
end
local loader = CreateFrame("Frame")
loader:RegisterEvent("ADDON_LOADED")
loader:SetScript("OnEvent", function(self, _, addon)
if addon ~= ADDON_NAME then return end
CreateMinimapButton()
self:UnregisterEvent("ADDON_LOADED")
end)