-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathTips.lua
547 lines (450 loc) · 18.5 KB
/
Tips.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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
local _, addon = ...
if addon.gameVersion > 40000 then return end
local GetItemInfo = C_Item and C_Item.GetItemInfo or _G.GetItemInfo
local GetSpellInfo = C_Spell and C_Spell.GetSpellInfo and addon.GetSpellInfo or _G.GetSpellInfo
local GetSpellTexture = C_Spell and C_Spell.GetSpellTexture or _G.GetSpellTexture
local GetSpellSubtext = C_Spell and C_Spell.GetSpellSubtext or _G.GetSpellSubtext
local IsCurrentSpell = C_Spell and C_Spell.IsCurrentSpell or _G.IsCurrentSpell
local IsSpellKnown = C_Spell and C_Spell.IsSpellKnown or _G.IsSpellKnown
local IsPlayerSpell = C_Spell and C_Spell.IsPlayerSpell or _G.IsPlayerSpell
local GetTime, GetMirrorTimerProgress = _G.GetTime, _G.GetMirrorTimerProgress
local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax
local GetInventoryItemID, IsPlayerSpell =
GetInventoryItemID,
IsPlayerSpell
local HasAction, GetActionInfo, GetMacroSpell = HasAction,
GetActionInfo,
GetMacroSpell
local IsOnBarOrSpecialBar = C_ActionBar.IsOnBarOrSpecialBar
local GetContainerNumSlots = C_Container and C_Container.GetContainerNumSlots or
_G.GetContainerNumSlots
local GetContainerItemID = C_Container and C_Container.GetContainerItemID or
_G.GetContainerItemID
local tinsert, fmt = tinsert, string.format
local GetRealZoneText = GetRealZoneText
local UIErrorsFrame = _G.UIErrorsFrame
local STRING_ENVIRONMENTAL_DAMAGE_DROWNING =
_G.STRING_ENVIRONMENTAL_DAMAGE_DROWNING
local L = addon.locale.Get
addon.tips = addon:NewModule("Tips", "AceEvent-3.0")
local session = {
checkFrequency = 0.5,
checkLast = GetTime(),
lastAlert = 0,
alertFrequency = 1,
emergencyItems = {},
emergencySpells = {},
highlights = {},
actionBarMap = {},
dangerousMobs = {}
}
function addon.tips:Setup()
if not addon.settings.profile.enableTips then return end
self:CreateTipsFrame()
self:CreateDangerWarning()
self:RegisterEvent("MIRROR_TIMER_START")
self:RegisterEvent("MIRROR_TIMER_STOP")
self:CatalogInventory()
self:RegisterEvent("PLAYER_STARTED_MOVING")
self:UpdateEmergencySpells()
self:CatalogActionBars()
self:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
WorldFrame:HookScript("OnUpdate", self.CheckEvents)
if addon.dangerousMobs then
self:LoadDangerousMobs()
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
end
end
function addon.tips:PLAYER_STARTED_MOVING()
-- Spams at login, so delay until after player moves
self:RegisterEvent("UNIT_INVENTORY_CHANGED")
self:UnregisterEvent("PLAYER_STARTED_MOVING")
end
function addon.tips:CreateTipsFrame()
if not addon.settings.profile.enableTipsFrame then return end
-- TODO
end
function addon.tips:MIRROR_TIMER_START(_, timerName, value, maxValue, rate)
if timerName ~= "BREATH" or not addon.settings.profile.enableDrowningWarning then
return
end
-- Recovering breath
if rate > 0 then
session.breath = nil
return
end
-- Draining down, event fires with 30 when regaining breath
session.breath = {value = value, maxValue = maxValue}
end
function addon.tips:MIRROR_TIMER_STOP(_, timerName)
if timerName ~= "BREATH" or not addon.settings.profile.enableDrowningWarning then
return
end
session.breath = nil
end
function addon.tips.CheckEvents()
if not addon.settings.profile.enableTips then return end
if GetTime() - session.checkLast <= session.checkFrequency then return end
if session.breath then
session.breath.value = GetMirrorTimerProgress("BREATH")
if session.breath.value == 0 or
(session.breath.value / session.breath.maxValue) <
addon.settings.profile.drowningThreshold then
if GetTime() - session.lastAlert > session.alertFrequency then
if addon.settings.profile.enableDrowningScreenFlash then
addon.tips:EnableDangerWarning(2)
end
FlashClientIcon()
UIErrorsFrame:AddMessage(STRING_ENVIRONMENTAL_DAMAGE_DROWNING,
1.0, 0.1, 0.1, session.alertFrequency);
if addon.settings.profile.enableDrowningWarningSound then
PlaySound(_G.SOUNDKIT.RAID_WARNING, "Master")
end
session.lastAlert = GetTime()
end
end
end
addon.tips:CheckEmergencyActions()
session.checkLast = GetTime()
end
function addon.tips:CheckEmergencyActions()
if not addon.settings.profile.enableEmergencyActions then return end
local maxHP = UnitHealthMax("player")
if maxHP > 0 and UnitHealth("player") / maxHP <
addon.settings.profile.emergencyThreshold then
addon.tips:HighlightEmergencyItem()
addon.tips:HighlightEmergencySpell()
if addon.settings.profile.enableEmergencyScreenFlash then
addon.tips:EnableDangerWarning(1)
end
return
end
for _, border in pairs(session.highlights) do
if border:IsShown() then border:Hide() end
end
end
function addon.tips:CatalogInventory()
if not addon.emergencyItems or
not addon.settings.profile.enableEmergencyActions then return end
local itemList = {}
local itemName, itemTexture, id
for i = 1, _G.INVSLOT_LAST_EQUIPPED do
id = GetInventoryItemID("player", i)
if id and addon.emergencyItems[id] then
itemName, _, _, _, _, _, _, _, _, itemTexture, _, _ =
GetItemInfo(id)
tinsert(itemList, {
name = itemName,
texture = itemTexture,
invSlot = i,
id = id
})
end
end
local bagSlots
for bag = _G.BACKPACK_CONTAINER, _G.NUM_BAG_FRAMES do
bagSlots = GetContainerNumSlots(bag)
for slot = 1, bagSlots do
id = GetContainerItemID(bag, slot)
if id and addon.emergencyItems[id] then
itemName, _, _, _, _, _, _, _, _, itemTexture, _, _ =
GetItemInfo(id)
tinsert(itemList, {
name = itemName,
texture = itemTexture,
bag = bag,
slot = slot,
id = id,
bagSlotFrameId = bagSlots + 1 - slot
})
end
end
end
session.emergencyItems = itemList
end
function addon.tips:UpdateEmergencySpells()
if not addon.emergencySpells or
not addon.settings.profile.enableEmergencyActions then return end
local spellList = {}
local name, icon
for spellId in pairs(addon.emergencySpells.professions or {}) do
-- Only add spells on action bars
if IsPlayerSpell(spellId) and IsOnBarOrSpecialBar(spellId) then
name, _, icon = GetSpellInfo(spellId)
tinsert(spellList,
{name = name, texture = icon, spell = true, id = spellId})
end
end
if addon.emergencySpells[addon.player.race] then
for spellId in pairs(addon.emergencySpells[addon.player.race]) do
-- Only add spells on action bars
if IsPlayerSpell(spellId) and IsOnBarOrSpecialBar(spellId) then
name, _, icon = GetSpellInfo(spellId)
tinsert(spellList, {
name = name,
texture = icon,
spell = true,
id = spellId
})
end
end
end
if addon.emergencySpells[addon.player.class] then
for spellId in pairs(addon.emergencySpells[addon.player.class]) do
-- Only add spells on action bars
if IsPlayerSpell(spellId) and IsOnBarOrSpecialBar(spellId) then
name, _, icon = GetSpellInfo(spellId)
tinsert(spellList, {
name = name,
texture = icon,
spell = true,
id = spellId
})
end
end
end
session.emergencySpells = spellList
end
function addon.tips:GetHighlight(name)
if not name then return end
if session.highlights[name] then return session.highlights[name] end
local parent = _G[name]
local border = parent:CreateTexture(name .. 'Emergency', 'ARTWORK')
border.animation = border:CreateAnimationGroup()
local animOut = border.animation:CreateAnimation("Alpha")
animOut:SetOrder(1)
animOut:SetDuration(0.2)
animOut:SetFromAlpha(1)
animOut:SetToAlpha(1)
animOut:SetStartDelay(0.2)
-- local animOut = border.animation:CreateAnimation("Rotation")
-- animOut:SetDegrees(-360)
-- animOut:SetDuration(1)
-- animOut:SetSmoothing("OUT")
border:SetTexture("Interface/Buttons/UI-ActionButton-Border")
border:SetBlendMode('ADD')
border:SetAlpha(0.5)
border:SetSize(68, 68)
border:SetPoint('CENTER', parent, 'CENTER', 0, 1)
border:Hide()
session.highlights[name] = border
return border
end
function addon.tips:HighlightEmergencyItem()
local bagBorder, actionBarLookup, actionBarBorder
for _, item in ipairs(session.emergencyItems) do
bagBorder = item.bag and item.bagSlotFrameId and
addon.tips:GetHighlight(
fmt('ContainerFrame%sItem%s', item.bag + 1,
item.bagSlotFrameId))
if bagBorder then
if _G.IsBagOpen(item.bag) then
bagBorder:Show()
if addon.settings.profile.enableEmergencyIconAnimations and
not bagBorder.animation:IsPlaying() then
bagBorder.animation:Play()
end
else
bagBorder:Hide()
end
end
actionBarLookup = item.id and session.actionBarMap['item:' .. item.id]
if actionBarLookup then
actionBarBorder = addon.tips:GetHighlight(actionBarLookup.button)
if actionBarBorder then
actionBarBorder:Show()
if addon.settings.profile.enableEmergencyIconAnimations and
not actionBarBorder.animation:IsPlaying() then
actionBarBorder.animation:Play()
end
end
end
end
end
function addon.tips:HighlightEmergencySpell()
local actionBarLookup, actionBarBorder
for _, item in ipairs(session.emergencySpells) do
actionBarLookup = session.actionBarMap['spell:' .. item.id]
if actionBarLookup then
actionBarBorder = addon.tips:GetHighlight(actionBarLookup.button)
if actionBarBorder then
actionBarBorder:Show()
if addon.settings.profile.enableEmergencyIconAnimations and
not actionBarBorder.animation:IsPlaying() then
actionBarBorder.animation:Play()
end
end
end
end
end
function addon.tips:UNIT_INVENTORY_CHANGED(_, target)
if target ~= "player" then return end
self:CatalogInventory()
end
function addon.tips:BAG_NEW_ITEMS_UPDATED() self:CatalogInventory() end
-- Can be overriden by ElvUI, Bartender, Domino, etc
local ActionBars = {
'Action', 'MultiBarBottomLeft', 'MultiBarBottomRight', 'MultiBarRight',
'MultiBarLeft'
}
function addon.tips:CatalogActionBars()
session.actionBarMap = {}
local button, slot, actionType, id, key
for _, barName in pairs(ActionBars) do
for i = 1, 12 do
button = _G[barName .. 'Button' .. i]
slot = _G.ActionButton_GetPagedID(button) or
_G.ActionButton_CalculateAction(button) or
button:GetAttribute('action')
if button and slot and HasAction(slot) then
actionType, id = GetActionInfo(slot)
if actionType == 'macro' then
_, _, id = GetMacroSpell(id)
if id then key = 'spell:' .. id end
elseif actionType == 'item' and id then
key = 'item:' .. id
elseif actionType == 'spell' and id then
key = 'spell:' .. id
else
key = nil
id = nil
end
if id and key then
session.actionBarMap[key] = {
button = barName .. 'Button' .. i,
slot = slot
}
end
end
end
end
end
function addon.tips:ACTIONBAR_SLOT_CHANGED() self:CatalogActionBars() end
function addon.tips:CreateDangerWarning()
if self.dangerWarning then return end
local f = CreateFrame("Frame", "RXPDangerFrame", UIParent,
BackdropTemplateMixin and "BackdropTemplate")
f:SetFrameStrata("FULLSCREEN_DIALOG")
f:SetPoint('CENTER', UIParent, 'CENTER', 0, 1)
f:SetAllPoints(nil)
f.bg = f:CreateTexture(nil, 'BACKGROUND')
f.bg:SetTexture("Interface\\FullScreenTextures\\LowHealth")
f.bg:SetBlendMode('ADD')
f.bg:SetAllPoints(nil)
f.animation = f:CreateAnimationGroup()
f.animation:SetLooping("BOUNCE")
f.animation.pulse = f.animation:CreateAnimation("Alpha")
f.animation.pulse:SetDuration(0.5236)
f.animation.pulse:SetFromAlpha(0.75)
f.animation.pulse:SetToAlpha(0.2)
f:Hide()
f.animation:HookScript("OnLoop", function()
if f.doLoops < 0 then
f:Hide()
f.animation:Stop()
end
f.doLoops = f.doLoops - 1
end)
self.dangerWarning = f
end
function addon.tips:EnableDangerWarning(loops)
if not self.dangerWarning or tonumber(loops) == nil then return end
if loops > 0 then
self.dangerWarning.doLoops = loops
if not self.dangerWarning.animation:IsPlaying() then
self.dangerWarning.animation:Play()
end
self.dangerWarning:Show()
end
end
local function IsStepActive(self)
local levelBuffer = 1000
if (not addon.settings.profile.showDangerousMobsMap and self.mapTooltip) or
(self.isUnitscan and not addon.settings.profile.showDangerousUnitscan) then
-- DevTools_Dump(self.elements[1].unitscan)
-- DevTools_Dump(self.elements[1].targets)
return false
elseif not addon.settings.profile.debug and self.levelBuffer then
levelBuffer = self.levelBuffer or 0
end
if not self.MaxLevel or self.MaxLevel >= UnitLevel("player") - levelBuffer then
return true
end
end
function addon.tips:LoadDangerousMobs(reloadData)
if not (addon.dangerousMobs) then return end
local mapId = C_Map.GetBestMapForUnit("player") or 0
local zone = addon.mapIdToName and addon.mapIdToName[mapId] or
GetRealZoneText()
local zoneList
addon.UpdateMap()
if not zone or not addon.dangerousMobs[zone] and
not addon.settings.profile.debug then
addon.tips.dangerousMobs = nil
addon.generatedSteps["dangerousMobs"] = nil
return
end
local dangerousMobs = session.dangerousMobs[zone] or {}
session.dangerousMobs[zone] = dangerousMobs
zoneList = zoneList or {addon.dangerousMobs[zone]}
-- dangerousMobs DB has nested objects, flatten and fake step data
if not dangerousMobs.processed or reloadData == true then
addon.currentGuideName = "Addon Tips"
local steps = {}
for _, zoneData in pairs(zoneList) do
for name, list in pairs(zoneData) do
for _, mobData in ipairs(list) do
-- added a semicolon separator in case the database entry has multiple coords
for line in mobData.Location:gmatch("[^\r\n;]+") do
line:gsub("^%s+", "")
line:gsub("%s+$", "")
local element = addon.ParseLine(line)
local skip
if element then
local step = {}
element.step = step
-- element.drawCenterPoint = true--Adds an icon at the center of the lines
step.isActive = IsStepActive
step.levelBuffer =
mobData.Classification == "Normal" and 1 or 3
if element.wx or element.segments then
-- step.linethickness = 2
step.showTooltip = true -- Shows tooltip when hovering over a line
step.icon =
"|TInterface/GossipFrame/BattleMasterGossipIcon:0|t" -- texture used for the icon
step.mapTooltip = fmt("%s %s (%d)",
_G.VOICEMACRO_1_Sc_0,
name, mobData.MaxLevel) -- Tooltip title
-- Tooltip description:
element.mapTooltip = fmt("%s - %s\n%s",
mobData.Classification or
"",
mobData.Movement or "",
mobData.Notes or "")
elseif element.targets or element.unitscan or
element.mobs then
if not addon.settings.profile
.showDangerousUnitscan then
skip = true
-- DevTools_Dump(self.elements[1].mobs)
end
step.isUnitscan = true
end
if not skip then
step.elements = {element}
tinsert(steps, step)
end
end
end
end
end
end
addon.currentGuideName = nil
dangerousMobs.steps = steps
addon:ScheduleTask(addon.RegisterGeneratedSteps)
end
addon.generatedSteps["dangerousMobs"] = dangerousMobs.steps
dangerousMobs.processed = true
addon.tips.dangerousMobs = dangerousMobs
end
addon.tips.ZONE_CHANGED_NEW_AREA = addon.tips.LoadDangerousMobs