-
Notifications
You must be signed in to change notification settings - Fork 2
/
Multishot.lua
474 lines (431 loc) · 17.1 KB
/
Multishot.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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
Multishot = LibStub("AceAddon-3.0"):NewAddon("Multishot", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("Multishot")
local isEnabled, isDelayed
local strMatch = string.gsub(FACTION_STANDING_CHANGED, "%%%d?%$?s", "(.+)")
local prefix = "WoWScrnShot_"
local player = (UnitName("player"))
local class = (UnitClass("player"))
local realm = GetRealmName()
local extension, intAlpha, minimapStatus
local timeLineStart, timeLineElapsed
function Multishot:OnEnable()
self:RegisterEvent("PLAYER_LEVEL_UP")
-- self:RegisterEvent("UNIT_GUILD_LEVEL")
self:RegisterEvent("ACHIEVEMENT_EARNED")
self:RegisterEvent("CHALLENGE_MODE_COMPLETED")
self:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
self:RegisterEvent("TRADE_ACCEPT_UPDATE")
self:RegisterEvent("CHAT_MSG_SYSTEM")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
-- self:RegisterEvent("GARISSON_BUILDING_ACTIVATED")
self:RegisterEvent("ADDON_LOADED")
self:RegisterEvent("SHOW_LOOT_TOAST_LEGENDARY_LOOTED")
self:RegisterEvent("ENCOUNTER_END")
self:RegisterEvent("SCREENSHOT_FAILED", "Debug")
-- self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
if Multishot.configDB.global.timeLineEnable then
self.timeLineTimer = self:ScheduleRepeatingTimer("TimeLineProgress", 5)
timeLineStart, timeLineElapsed = GetTime(), 0
end
local ssformat = GetCVar("screenshotFormat")
extension = (ssformat == "tga") and ".tga" or (ssformat == "png") and ".png" or ".jpg"
Multishot.watermarkFrame = Multishot.watermarkFrame or Multishot:CreateWatermark()
self:RefreshWatermark(false)
end
function Multishot:PLAYER_LEVEL_UP(strEvent)
if Multishot.configDB.global.levelup then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent)
end
end
--[[
function Multishot:UNIT_GUILD_LEVEL(strEvent, strUnit)
if Multishot.configDB.global.guildlevelup and strUnit == "player" then self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent) end
end
--]]
function Multishot:ACHIEVEMENT_EARNED(strEvent, intId)
if Multishot.configDB.global.guildachievement and select(12, GetAchievementInfo(intId)) then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent)
end
if Multishot.configDB.global.achievement and not select(12, GetAchievementInfo(intId)) then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent)
end
end
function Multishot:TRADE_ACCEPT_UPDATE(strEvent, strPlayer, strTarget)
if ((strPlayer == 1 and strTarget == 0) or (strPlayer == 0 and strTarget == 1)) and Multishot.configDB.global.trade then
self:CustomScreenshot(strEvent)
end
end
function Multishot:CHALLENGE_MODE_COMPLETED(strEvent)
if not Multishot.configDB.global.challengemode then
return
end
-- hooksecurefunc(ChallengeModeCompleteBanner,"PlayBanner",function()
-- self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent)
-- end)
end
function Multishot:ADDON_LOADED(strEvent, subev)
if not Multishot.configDB.global.mythicpluscompletion then
return
end
if subev == "Blizzard_ChallengesUI" then
hooksecurefunc(ChallengeModeCompleteBanner, "PlayBanner", function()
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, subev)
end)
else
return
end
end
function Multishot:SHOW_LOOT_TOAST_LEGENDARY_LOOTED(strEvent)
if Multishot.configDB.global.legendaryloot then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent)
end
end
function Multishot:UPDATE_BATTLEFIELD_STATUS(strEvent)
if not Multishot.configDB.global.arena or Multishot.configDB.global.battleground then
return
end
local winner = GetBattlefieldWinner()
if not winner then
return
end
local isArena, registered = IsActiveBattlefieldArena()
if (isArena) and not Multishot.configDB.global.arena then
return
end
if isArena then
if IsInArenaTeam() then
if not PLAYER_FACTION_GROUP[winner] then -- draw, get our screenshot and bail
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent)
return
end
local playerTeamId
for i = 1, GetNumBattlefieldScores() do
local name, _, _, _, _, teamId = GetBattlefieldScore(i)
if name == player then
playerTeamId = teamId
break
end
end
if playerTeamId and playerTeamId == winner then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent)
end
end
else
if PLAYER_FACTION_GROUP[winner] == GetPlayerFactionGroup() then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent)
end
end
end
function Multishot:CHAT_MSG_SYSTEM(strEvent, strMessage)
if Multishot.configDB.global.repchange then
if string.match(strMessage, strMatch) then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay1, strEvent)
end
end
end
function Multishot:CHAT_MSG_MONSTER_SAY(strEvent, strBuilding, arg2, arg3, arg4, strPlayer)
if Multishot.configDB.global.timeLineEnable then
timeLineStart, timeLineElapsed = GetTime(), 0
end
Screenshot()
self:UnregisterEvent("CHAT_MSG_MONSTER_SAY")
end
function Multishot:TIME_PLAYED_MSG(strEvent, total, thislevel)
if Multishot.configDB.global.timeLineEnable then
timeLineStart, timeLineElapsed = GetTime(), 0
end
Screenshot()
self:UnregisterEvent("TIME_PLAYED_MSG")
end
--[[
function Multishot:GARISSON_BUILDING_ACTIVATED(strEvent, arg1, arg2)
if Multishot.configDB.global.garissonbuild then
self:RegisterEvent("CHAT_MSG_MONSTER_SAY")
end
end
--]]
--[[
function Multishot:COMBAT_LOG_EVENT_UNFILTERED(strEvent, ...)
local strType, _, sourceGuid, _, _, _, destGuid = select(2, ...) -- 4.1 compat, 4.2 compat
--local currentId = destGuid and tonumber(destGuid:sub(-16, -12)) -- 6.x
local currentId = tonumber((select(6, strsplit("-", destGuid)))) -- 7.x
if strType == "UNIT_DIED" or strType == "PARTY_KILL" then
local solo, inParty, inRaid
if IsInRaid() then inRaid = true elseif IsInGroup() then inParty = true else solo = true end
local _,_,difficultyID = GetInstanceInfo()
if not (sourceGuid == UnitGUID("player") and Multishot.configDB.global.rares and Multishot.RareID[currentId]) and strType == "PARTY_KILL" then return end
if not ((solo and Multishot.configDB.global.groupstatus["1solo"]) or (inParty and Multishot.configDB.global.groupstatus["2party"]) or (inRaid and Multishot.configDB.global.groupstatus["3raid"])) then return end
if difficultyID and not Multishot.configDB.global.difficulty[difficultyID] then return end
if not (Multishot_dbWhitelist[currentId] or Multishot.BossID[currentId] or Multishot.RareID[currentId]) or Multishot_dbBlacklist[currentId] then return end
if Multishot.configDB.global.firstkill and Multishot.historyDB.char.history[UnitName("player") .. currentId] then return end
Multishot.historyDB.char.history[player .. currentId] = true
isDelayed = currentId --FLAG
if UnitIsDead("player") then
self:PLAYER_REGEN_ENABLED(strType)
end
end
end
--]]
-- Debug event created for watermark issues by Nukme@20220504
--[[
function Multishot:COMBAT_LOG_EVENT_UNFILTERED(strEvent)
if not Multishot.configDB.global.debug then
return
else
local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName,
destFlags, destRaidFlags, spellID, _, _, auraType = CombatLogGetCurrentEventInfo()
if subevent == "SPELL_CAST_SUCCESS" and spellID == 50842 then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay2, subevent .. spellID)
end
end
end
]]
function Multishot:PLAYER_REGEN_ENABLED(strEvent)
if isDelayed then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay2, strEvent .. isDelayed)
isDelayed = nil
end
end
function Multishot:ENCOUNTER_END(strEvent, ...)
if not Multishot.configDB.global.encounter_success then
return
else
local encoutnerID, encounterName, difficultyID, raidsize, endstatus = ...
if endstatus == 1 then
local solo, inParty, inRaid
if IsInRaid() then
inRaid = true
elseif IsInGroup() then
inParty = true
else
solo = true
end
if not ((solo and Multishot.configDB.global.groupstatus["1solo"]) or
(inParty and Multishot.configDB.global.groupstatus["2party"]) or
(inRaid and Multishot.configDB.global.groupstatus["3raid"])) then
return
end
if difficultyID and not Multishot.configDB.global.difficulty[difficultyID] then
return
end
if Multishot_dbBlacklist[encoutnerID] then
return
end
if Multishot.configDB.global.firstkill and Multishot.historyDB.char.history[player .. encoutnerID] then
return
end
Multishot.historyDB.char.history[player .. encoutnerID] = true
isDelayed = encoutnerID -- FLAG
if isDelayed then
self:ScheduleTimer("CustomScreenshot", Multishot.configDB.global.delay2, strEvent .. isDelayed)
isDelayed = nil
end
end
end
end
function Multishot:SCREENSHOT_SUCCEEDED(strEvent)
if Multishot.configDB.global.debug then
self:Print(strEvent)
end
local minus1, now, plus1 = date(nil, time() - 1), date(), date(nil, time() + 1)
local filea = prefix .. minus1:gsub("[/:]", ""):gsub(" ", "_") .. extension
local fileb = prefix .. now:gsub("[/:]", ""):gsub(" ", "_") .. extension
local filec = prefix .. plus1:gsub("[/:]", ""):gsub(" ", "_") .. extension
if not MultishotPlayerScreens then
MultishotPlayerScreens = {}
end
if not MultishotPlayerScreens[player] then
MultishotPlayerScreens[player] = {}
end
tinsert(MultishotPlayerScreens[player], filea)
tinsert(MultishotPlayerScreens[player], fileb)
tinsert(MultishotPlayerScreens[player], filec)
self:UIToggle(true)
self:RefreshWatermark(false)
self:UnregisterEvent("SCREENSHOT_SUCCEEDED")
end
-- not sure whether the persistent watermark is caused by this event. put here as a fail-safe.
--[[
function Multishot:SCREENSHOT_FAILED(strEvent)
if Multishot.configDB.global.debug then
self:Print(strEvent)
end
local minus1, now, plus1 = date(nil, time() - 1), date(), date(nil, time() + 1)
local filea = prefix .. minus1:gsub("[/:]", ""):gsub(" ", "_") .. extension
local fileb = prefix .. now:gsub("[/:]", ""):gsub(" ", "_") .. extension
local filec = prefix .. plus1:gsub("[/:]", ""):gsub(" ", "_") .. extension
if not MultishotPlayerScreens then
MultishotPlayerScreens = {}
end
if not MultishotPlayerScreens[player] then
MultishotPlayerScreens[player] = {}
end
tinsert(MultishotPlayerScreens[player], filea)
tinsert(MultishotPlayerScreens[player], fileb)
tinsert(MultishotPlayerScreens[player], filec)
self:UIToggle(true)
self:RefreshWatermark(false)
self:UnregisterEvent("SCREENSHOT_SUCCEEDED")
self:UnregisterEvent("SCREENSHOT_FAILED")
end
]]
function Multishot:CreateWatermark()
local f = CreateFrame("Frame", "MultishotWatermark", UIParent) -- changed from WorldFrame to UIParent
f:SetFrameStrata("TOOLTIP")
f:SetFrameLevel(0)
f:SetWidth(350)
f:SetHeight(100)
f.Text = f:CreateFontString(nil, "OVERLAY")
f.Text:SetShadowOffset(1, -1)
return f
end
function Multishot:RefreshWatermark(show)
-- Set Watermark Position
local anchor = Multishot.configDB.global.watermarkanchor
Multishot.watermarkFrame:ClearAllPoints()
Multishot.watermarkFrame:SetPoint(anchor)
-- Set Watermark Text Position
Multishot.watermarkFrame.Text:ClearAllPoints()
Multishot.watermarkFrame.Text:SetPoint("CENTER", Multishot.watermarkFrame, "CENTER")
Multishot.watermarkFrame.Text:SetJustifyH("CENTER")
-- Set Watermark Text Font
Multishot.watermarkFrame.Text:SetFont(Multishot.configDB.global.watermarkfont,
Multishot.configDB.global.watermarkfontsize, "OUTLINE")
if show then
Multishot:ShowWatermark()
else
Multishot:HideWatermark()
end
end
--[[
Wraps API f:Show() and f:Hide()
]]
function Multishot:ShowWatermark()
-- Set Text
local text = Multishot.configDB.global.watermarkformat
local level = UnitLevel("player")
local tdate = date()
-- 20231117 fix for nil zone string
local zone = " "
local zone1 = GetRealZoneText()
local map_id = C_Map.GetBestMapForUnit("player")
if map_id then
zone = C_Map.GetMapInfo(map_id).name
end
if zone1 then
zone = zone1
end
text = text:gsub("$n", player)
text = text:gsub("$l", level)
text = text:gsub("$c", class)
text = text:gsub("$z", zone)
text = text:gsub("$r", realm)
text = text:gsub("$d", tdate)
text = text:gsub("$b", "\n")
Multishot.watermarkFrame.Text:SetFormattedText("%s%s%s", YELLOW_FONT_COLOR_CODE, text, FONT_COLOR_CODE_CLOSE)
-- Brutal Force Show
local attempt = 0
while Multishot.watermarkFrame and not Multishot.watermarkFrame:IsShown() and attempt < 100 do
Multishot.watermarkFrame:Show()
attempt = attempt + 1
end
-- Debug Info
if Multishot.configDB.global.debug then
self:Print("WATERMARK_SHOW " .. attempt .. " attempt(s)")
end
end
function Multishot:HideWatermark()
-- Set Text to nil
Multishot.watermarkFrame.Text:SetText("")
-- Brutal Force Hide
local attempt = 0
while Multishot.watermarkFrame and Multishot.watermarkFrame:IsShown() and attempt < 100 do
Multishot.watermarkFrame:Hide()
attempt = attempt + 1
end
-- Debug Info
if Multishot.configDB.global.debug then
self:Print("WATERMARK_HIDE " .. attempt .. " attempt(s)")
end
end
function Multishot:TimeLineProgress()
local now = GetTime()
timeLineStart = timeLineStart or now
timeLineElapsed = timeLineElapsed or 0
if UnitIsAFK("player") then
timeLineStart = now - timeLineElapsed
else
timeLineElapsed = now - timeLineStart
end
if timeLineElapsed >= (Multishot.configDB.global.delay3 * 60) then
self:ScheduleTimer("CustomScreenshot", 0.2, L["timeline"])
end
end
function Multishot:CustomScreenshot(strDebug)
self:Debug(strDebug)
self:RegisterEvent("SCREENSHOT_SUCCEEDED")
if Multishot.configDB.global.charpane and not PaperDollFrame:IsVisible() then
ToggleCharacter("PaperDollFrame")
if not PaperDollFrame:IsVisible() then
self:ScheduleTimer("CustomScreenshot", 0.2, "RETRY")
end
end
if Multishot.configDB.global.close and strDebug ~= "TRADE_ACCEPT_UPDATE" then
CloseAllWindows()
end
if Multishot.configDB.global.uihide and
(string.find(strDebug, "PLAYER_REGEN_ENABLED") or string.find(strDebug, "UNIT_DIED") or
string.find(strDebug, "PARTY_KILL") or string.find(strDebug, "CHALLENGE_MODE_COMPLETED") or
string.find(strDebug, "PLAYER_LEVEL_UP") or string.find(strDebug, L["timeline"]) or
string.find(strDebug, KEY_BINDING)) then
self:UIToggle()
end
if Multishot.configDB.global.watermark then
self:RefreshWatermark(true)
end
if Multishot.configDB.global.played and
(
strDebug == "PLAYER_LEVEL_UP" or strDebug == "ACHIEVEMENT_EARNED" or strDebug == "CHAT_MSG_SYSTEM" or
strDebug ==
"CHAT_MSG_MONSTER_SAY" or strDebug == KEY_BINDING) and strDebug ~= "TIME_PLAYED_MSG" then
self:RegisterEvent("TIME_PLAYED_MSG")
RequestTimePlayed()
return
end
if Multishot.configDB.global.timeLineEnable then
timeLineStart, timeLineElapsed = GetTime(), 0
end
Screenshot()
-- if bug still exists, force a delayed watermark hiding here
end
function Multishot:UIToggle(show)
if not show then
intAlpha = UIParent:GetAlpha()
minimapStatus = Minimap:IsShown()
-- if minimapStatus then Minimap:Hide() end -- taints if called in combat
UIParent:SetAlpha(0)
else
-- if minimapStatus then Minimap:Show() end
if intAlpha and intAlpha > 0 then
UIParent:SetAlpha(intAlpha)
intAlpha = nil
else
UIParent:SetAlpha(1)
end
end
end
function Multishot:Debug(strMessage)
if strMessage == "SCREENSHOT_FAILED" then
self:UIToggle(true)
self:RefreshWatermark(false)
end
if Multishot.configDB.global.debug then
self:Print(strMessage)
end
end
BINDING_HEADER_MULTISHOT = "Multishot"
BINDING_NAME_MULTISHOTSCREENSHOT = L["Custom screenshot"]
--[[
Notes
SetUIVisibility(visible)
]]