-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Ping.lua
115 lines (103 loc) · 2.88 KB
/
Ping.lua
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
local _, sm = ...
sm.ping = {}
local mod = sm.ping
local L = sm.L
local pingFrame
local options = {
type = "group",
name = L["Ping"],
disabled = function() return not mod.db.showPing end,
args = {
show = {
type = "toggle",
order = 1,
name = L["Show who pinged"],
width = "full",
get = function()
return mod.db.showPing
end,
set = function(info, v)
mod.db.showPing = v
if v then
pingFrame:RegisterEvent("MINIMAP_PING")
else
pingFrame:UnregisterEvent("MINIMAP_PING")
end
end,
disabled = false,
},
fade = {
type = "multiselect",
name = "",
order = 2,
values = {
["chat"] = L["Show inside chat"],
["map"] = L["Show on minimap"],
},
get = function(info, v)
return mod.db.showAt == v
end,
set = function(info, v)
mod.db.showAt = v
end,
}
}
}
function mod:OnInitialize(profile)
if type(profile.ping) ~= "table" then
profile.ping = {
showPing = true,
showAt = "map"
}
end
self.db = profile.ping
end
function mod:OnEnable()
sm.core:RegisterModuleOptions("Ping", options, L["Ping"])
pingFrame = CreateFrame("Frame", "SexyMapPingFrame", Minimap, "BackdropTemplate")
pingFrame:SetBackdrop(sm.backdrop)
pingFrame:SetBackdropColor(0,0,0,0.8)
pingFrame:SetBackdropBorderColor(0,0,0,0.6)
pingFrame:SetHeight(20)
pingFrame:SetWidth(100)
pingFrame:SetPoint("TOP", Minimap, "TOP", 0, 15)
pingFrame:SetFrameStrata("HIGH")
pingFrame.name = pingFrame:CreateFontString(nil, nil, "GameFontNormalSmall")
pingFrame.name:SetAllPoints()
pingFrame:Hide()
local animGroup = pingFrame:CreateAnimationGroup()
local anim = animGroup:CreateAnimation("Alpha")
animGroup:SetScript("OnFinished", function() pingFrame:Hide() end)
anim:SetFromAlpha(0)
anim:SetToAlpha(1)
anim:SetOrder(1)
anim:SetDuration(3)
anim:SetStartDelay(3)
do
local prevUnit, prevX, prevY = "player", 0, 0
pingFrame:SetScript("OnEvent", function(_, _, unit, x, y)
if UnitIsUnit(unit, prevUnit) and x == prevX and y == prevY then return end
prevUnit, prevX, prevY = unit, x, y -- Throttle, it will fire for units like "target" also
local _, class = UnitClass(unit)
local color
if class then
color = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[class] or RAID_CLASS_COLORS[class] or GRAY_FONT_COLOR
else
color = GRAY_FONT_COLOR
end
if mod.db.showAt == "chat" then
DEFAULT_CHAT_FRAME:AddMessage(("%s: |cFF%02x%02x%02x%s|r"):format(L["Ping"], color.r * 255, color.g * 255, color.b * 255, UnitName(unit)))
else
pingFrame.name:SetFormattedText("|cFF%02x%02x%02x%s|r", color.r * 255, color.g * 255, color.b * 255, UnitName(unit))
pingFrame:SetWidth(pingFrame.name:GetUnboundedStringWidth() + 12)
pingFrame:SetHeight(pingFrame.name:GetStringHeight() + 10)
animGroup:Stop()
pingFrame:Show()
animGroup:Play()
end
end)
end
if mod.db.showPing then
pingFrame:RegisterEvent("MINIMAP_PING")
end
end