forked from shrekin/DarkRuneOrder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimap.lua
More file actions
138 lines (120 loc) · 4.61 KB
/
Copy pathminimap.lua
File metadata and controls
138 lines (120 loc) · 4.61 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
-- minimap.lua
-- Lightweight minimap button without external library dependencies (C5)
CoxisDarkRuneOrder = CoxisDarkRuneOrder or {}
local BUTTON_SIZE = 32
local ICON_TEXTURE = "Interface\\AddOns\\CoxisDarkRuneOrder\\texture\\tank.tga"
local DEFAULT_ANGLE = 220 -- degrees, default position around minimap
-- Create the minimap button
local btn = CreateFrame("Button", "CoxisDarkRuneOrderMinimapButton", Minimap)
btn:SetSize(BUTTON_SIZE, BUTTON_SIZE)
btn:SetFrameStrata("MEDIUM")
btn:SetFrameLevel(8)
btn:SetMovable(true)
btn:SetClampedToScreen(true)
-- Circular overlay border (mimics standard minimap buttons)
local overlay = btn:CreateTexture(nil, "OVERLAY")
overlay:SetSize(53, 53)
overlay:SetPoint("TOPLEFT")
overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
-- Icon
local icon = btn:CreateTexture(nil, "BACKGROUND")
icon:SetSize(20, 20)
icon:SetPoint("CENTER", btn, "CENTER", 0, 1)
icon:SetTexture(ICON_TEXTURE)
-- Highlight on hover
local highlight = btn:CreateTexture(nil, "HIGHLIGHT")
highlight:SetSize(24, 24)
highlight:SetPoint("CENTER", btn, "CENTER", 0, 1)
highlight:SetTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
highlight:SetBlendMode("ADD")
-- Position the button around the minimap edge
local function UpdatePosition(angleDeg)
local angle = math.rad(angleDeg)
local x = math.cos(angle) * 80
local y = math.sin(angle) * 80
btn:ClearAllPoints()
btn:SetPoint("CENTER", Minimap, "CENTER", x, y)
end
-- Dragging logic: track angle around minimap center
local isDragging = false
btn:RegisterForDrag("LeftButton")
btn:SetScript("OnDragStart", function(self)
isDragging = true
self:SetScript("OnUpdate", function(self)
local mx, my = Minimap:GetCenter()
local cx, cy = GetCursorPosition()
local scale = UIParent:GetEffectiveScale()
cx, cy = cx / scale, cy / scale
local angle = math.deg(math.atan2(cy - my, cx - mx))
CoxisDarkRuneOrderDB = CoxisDarkRuneOrderDB or {}
CoxisDarkRuneOrderDB.minimapAngle = angle
UpdatePosition(angle)
end)
end)
btn:SetScript("OnDragStop", function(self)
isDragging = false
self:SetScript("OnUpdate", nil)
end)
-- Left click: toggle picker
-- Right click: toggle test mode picker
btn:SetScript("OnClick", function(self, button)
if button == "LeftButton" then
if CoxisDarkRuneOrder.testMode or CoxisDarkRuneOrder.forceMode then
CoxisDarkRuneOrder.ShowPicker()
elseif UnitIsGroupLeader("player") then
CoxisDarkRuneOrder.testMode = false
CoxisDarkRuneOrder.forceMode = false
CoxisDarkRuneOrder.ShowPicker()
else
print("|cff00ff00CoxisDarkRuneOrder|r: Only the raid leader can open the picker. Right-click for test mode.")
end
elseif button == "RightButton" then
CoxisDarkRuneOrder.testMode = true
CoxisDarkRuneOrder.forceMode = false
CoxisDarkRuneOrder.testDifficulty = CoxisDarkRuneOrder.testDifficulty or 3
CoxisDarkRuneOrder.ShowPicker()
end
end)
-- Tooltip
btn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:SetText("|cff6839a6CoxisDarkRuneOrder|r", 1, 1, 1)
GameTooltip:AddLine("|cffccccccLeft-click:|r Open picker", 1, 1, 1)
GameTooltip:AddLine("|cffccccccRight-click:|r Test mode", 1, 1, 1)
GameTooltip:AddLine("|cffccccccDrag:|r Move button", 1, 1, 1)
GameTooltip:Show()
end)
btn:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
-- Restore position from SavedVariables
local restoreFrame = CreateFrame("Frame")
restoreFrame:RegisterEvent("ADDON_LOADED")
restoreFrame:SetScript("OnEvent", function(self, event, name)
if name == "CoxisDarkRuneOrder" then
CoxisDarkRuneOrderDB = CoxisDarkRuneOrderDB or {}
local angle = CoxisDarkRuneOrderDB.minimapAngle or DEFAULT_ANGLE
UpdatePosition(angle)
-- Respect hide setting
if CoxisDarkRuneOrderDB.minimapHide then
btn:Hide()
end
self:UnregisterEvent("ADDON_LOADED")
end
end)
-- Default position
UpdatePosition(DEFAULT_ANGLE)
-- Public toggle for minimap button visibility
function CoxisDarkRuneOrder.ToggleMinimapButton()
CoxisDarkRuneOrderDB = CoxisDarkRuneOrderDB or {}
if btn:IsShown() then
btn:Hide()
CoxisDarkRuneOrderDB.minimapHide = true
print("|cff00ff00CoxisDarkRuneOrder|r: Minimap button hidden. /dr minimap to show again.")
else
btn:Show()
CoxisDarkRuneOrderDB.minimapHide = false
print("|cff00ff00CoxisDarkRuneOrder|r: Minimap button shown.")
end
end