-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventHandling.lua
119 lines (92 loc) · 3.88 KB
/
eventHandling.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
-- Define and attach event handlers.
local thisAddonName, namespace = ...
local logMessage = function(message)
-- Log the specified 'message' with an addon-specific prefix.
print(string.format("|cFF5555BB%s:|r %s", thisAddonName, message))
end
local CombatLoggerMixin = {
["_loggingEnabled"] = false,
["_enableLogging"] = function(self)
-- If combat logging is not already enabled, print a message and enable
-- it. Otherwise, do nothing.
if self._loggingEnabled then
return
end
self._loggingEnabled = true
logMessage("|cFF00FF00ENABLING|r combat logging.")
LoggingCombat(true)
end,
["_disableLogging"] = function(self)
-- If combat logging is not already disabled, print a message and
-- disable it. Otherwise, do nothing.
if not self._loggingEnabled then
return
end
self._loggingEnabled = false
logMessage("|cFFFF0000DISABLING|r combat logging.")
LoggingCombat(false)
end,
["_registerOptions"] = function(self)
local category = Settings.RegisterVerticalLayoutCategory(thisAddonName)
for _, difficultyInfo in ipairs(namespace.instanceDifficulties) do
local variable = thisAddonName .. '_' .. difficultyInfo['id']
local setting = Settings.RegisterAddOnSetting(
category,
variable,
difficultyInfo['id'],
_G["AutoCombatLogEnabledDifficultyIds"],
type(true),
difficultyInfo['name'],
difficultyInfo['default'] or false)
setting['difficultyId'] = difficultyInfo['Id']
setting:SetValueChangedCallback(function() self:update() end)
Settings.CreateCheckbox(category, setting)
end
Settings.RegisterAddOnCategory(category)
end,
["update"] = function(self)
-- Check the current instance difficulty and enable or disable combat
-- logging accordingly. Note that this handles the
-- "UPDATE_INSTANCE_INFO" event.
local difficultyId = select(3, GetInstanceInfo())
local enabledDifficultyIds = _G["AutoCombatLogEnabledDifficultyIds"] or {}
if enabledDifficultyIds[difficultyId] then
self:_enableLogging()
else
self:_disableLogging()
end
end,
["_ADDON_LOADED"] = function(self, addonName)
-- If the specified 'addonName' is the name of this addon, then stop
-- listening for "ADDON_LOADED" events and re-execute the
-- enablement/disablement of combat logging. Otherwise, if 'addonName'
-- is not the name of this addon, do nothing.
if addonName ~= thisAddonName then
return
end
self:UnregisterEvent("ADDON_LOADED")
self:_registerOptions()
self:update()
end,
["_UPDATE_INSTANCE_INFO"] = function(self)
return self:update()
end,
["_PLAYER_DIFFICULTY_CHANGED"] = function(self)
return self:update()
end,
["registerEvents"] = function(self)
-- Invoke methods from the 'Frame' mixin to listen for API events and
-- to match those events to callbacks.
-- "UPDATE_INSTANCE_INFO" is fired upon entering or leaving an
-- instance. "PLAYER_DIFFICULTY_CHANGED" is fired upon starting a
-- keystone.
self:RegisterEvent("UPDATE_INSTANCE_INFO")
self:RegisterEvent("PLAYER_DIFFICULTY_CHANGED")
self:RegisterEvent("ADDON_LOADED")
self:SetScript("OnEvent",
function(self, event, ...) self["_" .. event](self, ...) end)
end,
}
local frame = CreateFrame("Frame")
Mixin(frame, CombatLoggerMixin)
frame:registerEvents()