-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimapButton.lua
More file actions
230 lines (199 loc) · 7.81 KB
/
MinimapButton.lua
File metadata and controls
230 lines (199 loc) · 7.81 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
-- Valuate Minimap Button
-- Adds a draggable minimap button for quick access to Valuate UI
local Valuate = Valuate
if not Valuate then return end
-- Minimap button state
local minimapButton = nil
local DEFAULT_POSITION = 200 -- Default angle in degrees
-- Color constants matching Valuate UI styling
local BUTTON_COLORS = {
bg = { 0.15, 0.15, 0.15, 0.9 },
border = { 0.35, 0.35, 0.35, 1 },
borderLight = { 0.45, 0.45, 0.45, 1 },
text = { 0.85, 0.85, 0.85, 1 },
vText = { 0.75, 0.75, 0.75, 1 }, -- Grey stylized V
accent = { 0.4, 0.7, 0.9, 1 }, -- Soft blue accent
}
-- Update button position based on angle (in degrees)
local function UpdateButtonPosition(angle)
if not minimapButton then return end
local rad = math.rad(angle or DEFAULT_POSITION)
local radius = 80 -- Distance from minimap center
local x = math.cos(rad) * radius
local y = math.sin(rad) * radius
minimapButton:ClearAllPoints()
minimapButton:SetPoint("CENTER", Minimap, "CENTER", x, y)
end
-- Create the minimap button
local function CreateMinimapButton()
if minimapButton then return minimapButton end
-- Initialize saved variables if needed
local options = Valuate:GetOptions()
if not options.minimapButtonAngle then
options.minimapButtonAngle = DEFAULT_POSITION
end
if options.minimapButtonHidden == nil then
options.minimapButtonHidden = false
end
-- Create the button frame
minimapButton = CreateFrame("Button", "ValuateMinimapButton", Minimap)
minimapButton:SetFrameStrata("MEDIUM")
minimapButton:SetFrameLevel(8)
minimapButton:SetWidth(31)
minimapButton:SetHeight(31)
minimapButton:SetMovable(true)
-- Create background texture for the button
local background = minimapButton:CreateTexture(nil, "BACKGROUND")
background:SetWidth(20)
background:SetHeight(20)
background:SetPoint("CENTER", minimapButton, "CENTER", 0, 1)
background:SetTexture("Interface\\Buttons\\WHITE8X8")
background:SetVertexColor(unpack(BUTTON_COLORS.bg))
minimapButton.background = background
-- Highlight texture
minimapButton:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
-- Create the "V" text - stylized grey letter (on ARTWORK layer, above background)
local vText = minimapButton:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
vText:SetFont("Fonts\\FRIZQT__.TTF", 14, "THICKOUTLINE")
vText:SetText("V")
vText:SetTextColor(1, 1, 1, 1) -- White text for better visibility
-- Position using TOPLEFT anchor like other minimap buttons (VuhDo uses 7,-5 for 20x20 icons)
-- Adjusting slightly for text vs texture positioning
vText:SetPoint("TOPLEFT", minimapButton, "TOPLEFT", 9, -6)
minimapButton.vText = vText
-- Create overlay border (minimap button style) - should be on top
local overlay = minimapButton:CreateTexture(nil, "OVERLAY")
overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
overlay:SetWidth(53)
overlay:SetHeight(53)
overlay:SetPoint("TOPLEFT", minimapButton, "TOPLEFT", 0, 0)
minimapButton.overlay = overlay
-- Click handler
minimapButton:RegisterForClicks("LeftButtonUp", "RightButtonUp")
minimapButton:SetScript("OnClick", function(self, btn)
if btn == "LeftButton" or btn == "RightButton" then
-- Toggle Valuate UI
if Valuate and Valuate.ToggleUI then
Valuate:ToggleUI()
else
print("|cFFFF0000Valuate|r: UI not available. Please reload UI with /reload")
end
end
end)
-- Drag handler
minimapButton:RegisterForDrag("LeftButton")
minimapButton:SetScript("OnDragStart", function(self)
self:LockHighlight()
self.vText:SetTextColor(unpack(BUTTON_COLORS.accent)) -- Highlight text when dragging
self:SetScript("OnUpdate", function(self)
local mx, my = Minimap:GetCenter()
local px, py = GetCursorPosition()
local scale = Minimap:GetEffectiveScale()
px, py = px / scale, py / scale
local angle = math.deg(math.atan2(py - my, px - mx))
if angle < 0 then
angle = angle + 360
end
UpdateButtonPosition(angle)
-- Save position
local options = Valuate:GetOptions()
if options then
options.minimapButtonAngle = angle
end
end)
end)
minimapButton:SetScript("OnDragStop", function(self)
self:UnlockHighlight()
self.vText:SetTextColor(1, 1, 1, 1) -- Restore white color
self:SetScript("OnUpdate", nil)
end)
-- Hover effects
minimapButton:SetScript("OnEnter", function(self)
self.vText:SetTextColor(unpack(BUTTON_COLORS.accent)) -- Blue accent on hover
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:SetText("|cFF00FF00Valuate|r", 1, 1, 1)
GameTooltip:AddLine("Left-click to open Valuate UI", 0.85, 0.85, 0.85)
GameTooltip:AddLine("Right-click for options", 0.85, 0.85, 0.85)
GameTooltip:AddLine("Drag to move", 0.5, 0.5, 0.5)
GameTooltip:Show()
end)
minimapButton:SetScript("OnLeave", function(self)
self.vText:SetTextColor(1, 1, 1, 1) -- Back to white
GameTooltip:Hide()
end)
-- Set initial position
local options = Valuate:GetOptions()
local savedAngle = options.minimapButtonAngle or DEFAULT_POSITION
UpdateButtonPosition(savedAngle)
-- Show or hide based on saved state
if not options.minimapButtonHidden then
minimapButton:Show()
else
minimapButton:Hide()
end
return minimapButton
end
-- Public API for showing/hiding the button
function Valuate:ShowMinimapButton()
if not minimapButton then
CreateMinimapButton()
else
minimapButton:Show()
end
local options = Valuate:GetOptions()
if options then
options.minimapButtonHidden = false
end
end
function Valuate:HideMinimapButton()
if minimapButton then
minimapButton:Hide()
end
local options = Valuate:GetOptions()
if options then
options.minimapButtonHidden = true
end
end
function Valuate:ToggleMinimapButton()
if not minimapButton then
CreateMinimapButton()
end
if minimapButton:IsShown() then
Valuate:HideMinimapButton()
else
Valuate:ShowMinimapButton()
end
end
-- Initialize the button when the addon loads
local initFrame = CreateFrame("Frame")
local function InitializeMinimapButton()
-- Options should already be initialized by Valuate:Initialize()
-- Just check that it exists before trying to use it
local options = Valuate.GetOptions and Valuate:GetOptions()
if options and not options.minimapButtonHidden then
CreateMinimapButton()
end
end
-- Try to initialize immediately if addon is already loaded
if IsAddOnLoaded("Valuate") then
-- Addon is already loaded, wait for PLAYER_ENTERING_WORLD
initFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
initFrame:SetScript("OnEvent", function(self, event)
if event == "PLAYER_ENTERING_WORLD" then
InitializeMinimapButton()
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
end
end)
else
-- Wait for addon to load
initFrame:RegisterEvent("ADDON_LOADED")
initFrame:SetScript("OnEvent", function(self, event, addonName)
if event == "ADDON_LOADED" and addonName == "Valuate" then
-- Wait for player to enter world before creating minimap button
self:RegisterEvent("PLAYER_ENTERING_WORLD")
elseif event == "PLAYER_ENTERING_WORLD" then
InitializeMinimapButton()
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
end
end)
end