-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Announce.lua
85 lines (73 loc) · 1.93 KB
/
Announce.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
local addonName, addon = ...
local L = addon.L
assert(addon.spellList, "Announce module requires spellList module.")
local lastTarget = ""
local announceFormat = format("%%s - %s: %%s %s: %%s", L["Normal"], L["Crit"])
local function announce(data, channel, target)
local normal = data.normal and addon:ShortenNumber(data.normal.amount)
local crit = data.crit and addon:ShortenNumber(data.crit.amount)
local text = format(announceFormat, addon:GetFullSpellName(data.name, data.periodic, true), (normal or "-"), (crit or "-"))
SendChatMessage(text, channel, nil, target)
end
local targetChannels = {
WHISPER = "CRITLINE_ANNOUNCE_WHISPER",
CHANNEL = "CRITLINE_ANNOUNCE_CHANNEL",
}
local function onClick(self, tree, channel)
local popup = targetChannels[channel]
if popup then
StaticPopup_Show(popup, nil, nil, self.value)
else
announce(self.value, channel)
end
CloseDropDownMenus()
end
local channels = {
"SAY",
"GUILD",
"PARTY",
"RAID",
"WHISPER",
"CHANNEL",
}
for i, v in ipairs(channels) do
channels[i] = {
text = _G[v],
func = onClick,
notCheckable = true,
arg2 = v,
}
end
addon.spellList:AddSpellOption({
text = L["Announce"],
hasArrow = true,
notCheckable = true,
menuList = channels,
})
local function onShow(self)
self.button1:Disable()
self.editBox:SetText(lastTarget)
self.editBox:HighlightText()
end
addon:CreatePopup("CRITLINE_ANNOUNCE_WHISPER", {
text = L["Enter whisper target"],
OnAccept = function(self, data)
lastTarget = self.editBox:GetText()
announce(data, "WHISPER", lastTarget:trim())
end,
OnShow = onShow,
}, true)
addon:CreatePopup("CRITLINE_ANNOUNCE_CHANNEL", {
text = ADD_CHANNEL,
OnAccept = function(self, data)
lastTarget = self.editBox:GetText()
local target = GetChannelName(lastTarget:trim())
if target == 0 then
addon:Message(L["Invalid channel. Please enter a valid channel name or ID."])
return
else
announce(data, "CHANNEL", target)
end
end,
OnShow = onShow,
}, true)