-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimapButton.lua
More file actions
146 lines (124 loc) · 4.87 KB
/
MinimapButton.lua
File metadata and controls
146 lines (124 loc) · 4.87 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
local _, ns = ...
local MinimapButton = {
radius = 80,
}
local ICON_TEXTURE = "Interface\\Icons\\INV_Misc_Note_05"
local function updatePosition(button)
local angle = ns.Addon:GetSetting("minimapAngle") or 225
local radians = math.rad(angle)
local x = math.cos(radians) * MinimapButton.radius
local y = math.sin(radians) * MinimapButton.radius
button:ClearAllPoints()
button:SetPoint("CENTER", Minimap, "CENTER", x, y)
end
function MinimapButton:Initialize()
if self.initialized then
self:RefreshVisibility()
return
end
self.initialized = true
self:RefreshVisibility()
end
function MinimapButton:EnsureButton()
if self.button then
return self.button
end
local button = CreateFrame("Button", nil, Minimap)
button:SetSize(32, 32)
button:SetFrameStrata("MEDIUM")
button:SetMovable(true)
button:EnableMouse(true)
button:RegisterForDrag("LeftButton")
button.border = button:CreateTexture(nil, "OVERLAY")
button.border:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
button.border:SetSize(54, 54)
button.border:SetPoint("TOPLEFT")
button.background = button:CreateTexture(nil, "BACKGROUND")
button.background:SetTexture("Interface\\Minimap\\UI-Minimap-Background")
button.background:SetSize(20, 20)
button.background:SetPoint("CENTER", button, "CENTER", 0, 0)
button.icon = button:CreateTexture(nil, "ARTWORK")
button.icon:SetTexture(ICON_TEXTURE)
button.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
button.icon:SetSize(18, 18)
button.icon:SetPoint("CENTER", button, "CENTER", 0, 0)
button.highlight = button:CreateTexture(nil, "HIGHLIGHT")
button.highlight:SetTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
button.highlight:SetBlendMode("ADD")
button.highlight:SetAllPoints(button)
button:SetScript("OnClick", function(_, mouseButton)
if mouseButton == "RightButton" then
ns.Addon:Print("Use |cff35c7e5/ca minimap|r to hide or show the minimap button.")
return
end
ns.Addon:OpenView("summary")
end)
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:SetText("CombatAnalytics", 0.90, 0.94, 0.98)
GameTooltip:AddLine("Left-click: Open addon UI", 0.60, 0.69, 0.78)
GameTooltip:AddLine("Right-click: Command hint", 0.60, 0.69, 0.78)
local store = ns.Addon:GetModule("CombatStore")
if store then
local characterKey = store:GetCurrentCharacterKey()
local session = store:GetLatestSession(characterKey)
if session and session.timestamp and (GetTime() - (session.timestamp or 0) < 1800) then
local result = session.result and string.lower(tostring(session.result)) or "unknown"
local opponentName = session.primaryOpponent and session.primaryOpponent.name or "Unknown"
local duration = ns.Helpers.FormatDuration(session.duration or 0)
local damage = ns.Helpers.FormatNumber(session.totals and session.totals.damageDone or 0)
local r, g, b = 0.60, 0.69, 0.78
if result == "won" then
r, g, b = 0.44, 0.82, 0.60
elseif result == "lost" then
r, g, b = 0.90, 0.30, 0.25
end
local resultLabel = result == "won" and "Won" or result == "lost" and "Lost" or "Draw"
GameTooltip:AddLine(" ")
GameTooltip:AddLine(
string.format("Last: %s vs %s — %s — %s dmg", resultLabel, opponentName, duration, damage),
r, g, b
)
end
end
GameTooltip:Show()
end)
button:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
button:SetScript("OnDragStart", function(self)
self.dragging = true
end)
button:SetScript("OnDragStop", function(self)
self.dragging = false
end)
button:SetScript("OnUpdate", function(self)
if not self.dragging then
return
end
local mx, my = Minimap:GetCenter()
local cx, cy = GetCursorPosition()
local scale = UIParent:GetScale()
cx = cx / scale
cy = cy / scale
local angle = math.deg(math.atan2(cy - my, cx - mx))
ns.Addon:SetSetting("minimapAngle", angle)
updatePosition(self)
end)
self.button = button
updatePosition(button)
return button
end
function MinimapButton:RefreshVisibility()
if ns.Addon:GetSetting("showMinimapButton") then
local button = self:EnsureButton()
if not button then
return
end
self.button:Show()
updatePosition(self.button)
elseif self.button then
self.button:Hide()
end
end
ns.Addon:RegisterModule("MinimapButton", MinimapButton)