-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
271 lines (235 loc) · 8.71 KB
/
Copy pathcore.lua
File metadata and controls
271 lines (235 loc) · 8.71 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
local ADDON_NAME = ...;
local Addon = LibStub("AceAddon-3.0"):NewAddon(select(2, ...), ADDON_NAME, "AceConsole-3.0", "AceEvent-3.0", "LibSink-2.0");
local LibToast = LibStub("LibToast-1.0")
local LSM = LibStub("LibSharedMedia-3.0")
local Debug = Addon.DEBUG
local Const = Addon.CONST
local Options
local AddonDB_Defaults = {
profile = {
Enabled = true,
Sound = {
Enabled = true,
Alert = "AA - Default",
},
Toast = {
Enabled = false,
LST = true,
},
Sink = {
Enabled = false,
},
Debug = false,
}
}
local playerName = UnitName("player") .. "-" .. GetRealmName()
local private = {}
local addonName, KT = ...
local media = {
-- Sounds (Blizzard)
{ type = "SOUND", name = "Default", filePath = 569593 }, -- sound/spells/levelup.ogg
}
function Addon:Test()
local currentTime = time()
local dateTable = date("*t", currentTime)
local day = dateTable.day
local month = dateTable.month
local year = dateTable.year % 100
local achievement = "|cffffff00|Hachievement:411:"..UnitGUID('player')..":1:"..month..":"..day..":"..year..":4294967295:4294967295:4294967295:4294967295|h[Murky]|h|r"
private.Alert("%s will never ever get " .. achievement .. " achievement!", playerName)
end
function private.defineMedia()
for _, item in ipairs(media) do
LSM:Register(LSM.MediaType[item.type], "AA - "..item.name, item.filePath)
end
end
function private.defineLibToast()
LibToast:Register("AchievementAlert", function(toast, achievement, ...)
toast:SetTitle("AchievementAlert")
toast:SetFormattedText(achievement)
toast:SetUrgencyLevel(...)
end)
end
function private.Toast_Setup()
local E, C, L = unpack(ls_Toasts)
E:RegisterOptions("achievementalert", {
enabled = true,
anchor = 1,
dnd = false,
}, {
name = "Achievement Alert",
args = {
enabled = {
order = 1,
type = "toggle",
name = L["ENABLE"],
get = function(info) return Options.Toast.LST end,
set = function(info, value)
Options.Toast.LST = value
end,
},
test = {
type = "execute",
order = 99,
width = "full",
name = L["TEST"],
func = private.Toast_Test,
},
},
})
E:RegisterSystem("achievementalert", private.Toast_OnEnable, private.Toast_OnDisable, private.Toast_Test)
end
function private.Toast_Test()
Addon:Test()
end
function private.Toast_OnEnable()
end
function private.Toast_OnDisable()
end
function private.Toast_OnClick(self)
if self._data.ach_id and not InCombatLockdown() then
if not AchievementFrame then
AchievementFrame_LoadUI()
end
if AchievementFrame then
ShowUIPanel(AchievementFrame)
AchievementFrame_SelectAchievement(self._data.ach_id)
end
end
end
function private.Toast_OnEnter(self)
if self._data.ach_id then
local _, name, _, _, month, day, year, description = GetAchievementInfo(self._data.ach_id)
if name then
if day and day > 0 then
GameTooltip:AddDoubleLine(name, FormatShortDate(day, month, year), nil, nil, nil, 0.5, 0.5, 0.5)
else
GameTooltip:AddLine(name)
end
if description then
GameTooltip:AddLine(description, 1, 1, 1, true)
end
end
GameTooltip:Show()
end
end
function private.showToast(name, text)
if ls_Toasts and Addon.db.profile.Toast.LST then
local E, C, L = unpack(ls_Toasts)
local toast = E:GetToast()
local achievementName = string.match(text, "|.-|r")
local achievementID = string.match(text, "|Hachievement:(%d+):")
Debug:Info("Achievement", achievementName)
Debug:Info("ID", achievementID)
toast.Title:SetText(name)
toast.Text:SetText(achievementName)
toast.IconText1:SetText("")
if achievementID then
local _, _, points, _, _, _, _, _, _, icon, _, _ = GetAchievementInfo(achievementID)
if not toast:ShouldHideLeaves() then
toast:ShowLeaves()
end
if C.db.profile.colors.border then
toast.Border:SetVertexColor(1, 0.675, 0.125) -- ACHIEVEMENT_GOLD_BORDER_COLOR
toast:SetLeavesVertexColor(1, 0.675, 0.125)
end
if C.db.profile.colors.icon_border then
toast.IconBorder:SetVertexColor(1, 0.675, 0.125)
end
toast.IconText1:SetText(points == 0 and "" or points)
toast.Icon:SetTexture(icon)
toast.IconBorder:Show()
toast._data.ach_id = achievementID
toast:HookScript("OnClick", private.Toast_OnClick)
toast:HookScript("OnEnter", private.Toast_OnEnter)
end
toast:Spawn(C.db.profile.types.achievement.anchor, C.db.profile.types.achievement.dnd)
return
end
local achievementText = string.format(text, name)
Debug:Info("AchievementText", achievementText)
LibToast:Spawn("AchievementAlert", achievementText, "normal")
end
function private.Alert(text, name)
local guild
C_GuildInfo.GuildRoster()
local numMembers = GetNumGuildMembers()
for i=1, numMembers do
local fullName, rankName, rankIndex, level, classDisplayName, zone, publicNote, officerNote, isOnline, status, class, achievementPoints, achievementRank, isMobile, canSoR, repStanding, guid = GetGuildRosterInfo(i)
if fullName == name then
name = string.format("[|c%s%s|r:%d]", RAID_CLASS_COLORS[class].colorStr, Ambiguate(name, "guild"), level)
guild = true
break
end
end
if not guild then
local playerGUID = string.match(text, "|Hachievement:%d+:(%S+)|")
local _, class = GetPlayerInfoByGUID(playerGUID)
if not class then return end
name = string.format("[|c%s%s|r]", RAID_CLASS_COLORS[class].colorStr, Ambiguate(name, "none"))
end
local alertText = string.format(text, name)
if Options.Sound.Enabled then
PlaySoundFile(LSM:Fetch("sound", Options.Sound.Alert))
end
if Options.Toast.Enabled then
private.showToast(name, text)
end
if Options.Sink.Enabled then
Addon:Pour(alertText, 1, 1, 1)
end
end
function private.AchievementGained(event, text, name)
if not Options.Enabled then return end
if type(name) ~= "string" then return end
if playerName == name then return end
private.Alert(text, name)
end
function private.chatCmdShowConfig(input)
local cmd = Addon:GetArgs(input)
if not cmd or cmd == "" or cmd == "help" or cmd == "?" then
local argStr = " |cff00ff00/aa %s|r - %s"
local arg2Str = " |cff00ff00/aa %s|r or |cff00ff00%s|r - %s"
Addon:Print("Available Chat Command Arguments")
print(format(argStr, "config", "Opens configuration window."))
print(format(argStr, "toggle", "Toggles watching for achievements."))
print(format(argStr, "test", "Fire test achievement."))
print(format(arg2Str, "help", "?", "Print this again."))
print(format(argStr, "ver", "Print Addon Version"))
elseif cmd == "config" then
-- happens twice because there is a bug in the blizz implementation and the first call doesn't work. subsequent calls do.
InterfaceOptionsFrame_OpenToCategory(Const.METADATA.NAME)
InterfaceOptionsFrame_OpenToCategory(Const.METADATA.NAME)
elseif cmd == "ver" then
Addon:Print(("You are running version |cff1784d1%s|r."):format(Const.METADATA.VERSION))
elseif cmd == "toggle" then
Addon.db.profile.Enabled = not Addon.db.profile.Enabled
if Addon.db.profile.Enabled then
Addon:Print("Alerts are |cff00ff00Enabled|r")
else
Addon:Print("Alerts are |cffff0000Disabled|r")
end
elseif cmd == "test" then
Addon:Test()
end
end
function Addon:RefreshConfig()
Options = self.db.profile
end
function Addon:OnEnable()
Addon.db = LibStub("AceDB-3.0"):New(ADDON_NAME .. "DB", AddonDB_Defaults, true) -- set true to prefer 'Default' profile as default
Options = Addon.db.profile
private.defineLibToast()
private.defineMedia()
Addon:RegisterChatCommand("aa", private.chatCmdShowConfig)
Addon:RegisterEvent("CHAT_MSG_GUILD_ACHIEVEMENT", private.AchievementGained)
if ls_Toasts then
private.Toast_Setup()
end
self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
end
function Addon:OnDisable()
Addon:UnregisterEvent("CHAT_MSG_GUILD_ACHIEVEMENT")
end