-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInit.lua
More file actions
147 lines (134 loc) · 5.14 KB
/
Copy pathInit.lua
File metadata and controls
147 lines (134 loc) · 5.14 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
local ADDON_NAME, ns = ...
-- Variables.
local minimapButton = LibStub("LibDBIcon-1.0")
local isLogging = false
-- Localized stuff
local GetInstanceInfo, LoggingCombat = GetInstanceInfo, LoggingCombat
-- Shows or hides the minimap button.
local function ToggleMinimapButton()
ALCOptions.minimapTable.hide = not ALCOptions.minimapTable.hide
if ALCOptions.minimapTable.hide then
minimapButton:Hide("AutoLoggerClassic")
print("|cFFFFFF00AutoLoggerClassic:|r Minimap button hidden. Type /alc minimap to show it again.")
else
minimapButton:Show("AutoLoggerClassic")
end
end
local function ToggleLoginMessage()
ALCOptionsGlobal.disableLoginMessage = not ALCOptionsGlobal.disableLoginMessage
if ALCOptionsGlobal.disableLoginMessage then
print("|cFFFFFF00AutoLoggerClassic:|r Login message disabled. Type /alc loginmessage to show it again.")
else
print("|cFFFFFF00AutoLoggerClassic:|r Login message enabled.")
end
end
-- Initializes the minimap button.
local function InitMinimapButton()
local obj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("AutoLoggerClassic", {
type = "launcher",
text = "AutoLoggerClassic",
icon = "Interface/ICONS/Trade_Engineering",
OnClick = function(self, button)
if button == "LeftButton" then
ns:ToggleFrame()
elseif button == "RightButton" then
ToggleMinimapButton()
end
end,
OnEnter = function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine("|cFFFFFFFFAutoLoggerClassic|r")
GameTooltip:AddLine("Left click to open options.")
GameTooltip:AddLine("Right click to hide this minimap button.")
GameTooltip:Show()
end,
OnLeave = function(self)
GameTooltip:Hide()
end,
})
minimapButton:Register("AutoLoggerClassic", obj, ALCOptions.minimapTable)
end
-- Initializes slash commands.
local function InitSlash()
SLASH_AutoLoggerClassic1 = "/AutoLoggerClassic"
SLASH_AutoLoggerClassic2 = "/alc"
SlashCmdList["AutoLoggerClassic"] = function(msg)
msg = msg:lower()
if msg == "minimap" then
ToggleMinimapButton()
return
elseif msg == "loginmessage" then
ToggleLoginMessage()
return
elseif msg == "help" then
print("|cFFFFFF00AutoLoggerClassic:|r\n"
.. "/alc or /autologgerclassic both work to toggle the addon.\n"
.. "/alc minimap toggles the minimap button.\n"
.. "/alc loginmessage toggles the login message.")
return
end
ns:ToggleFrame()
end
end
-- Loads all saved variables.
local function LoadVariables()
ALCOptions = ALCOptions or {}
ALCOptionsGlobal = ALCOptionsGlobal or {}
ALCOptions.minimapTable = ALCOptions.minimapTable or {}
if not ALCOptions.instances then
ALCOptions.instances = {}
-- Default raids to true and dungeons to false.
for instanceID in pairs(ns.RAIDS) do
ALCOptions.instances[instanceID] = true
end
else
-- Default new raids to true and dungeons to false.
for instanceID in pairs(ns.RAIDS) do
if ALCOptions.instances[instanceID] == nil then
ALCOptions.instances[instanceID] = true
end
end
end
ALCOptionsGlobal.disableLoginMessage = ALCOptionsGlobal.disableLoginMessage == nil and false or ALCOptionsGlobal.disableLoginMessage
end
-- Toggles logging if player is not logging and is in the right instance.
function ns:ToggleLogging()
local id = select(8, GetInstanceInfo())
if not isLogging and ALCOptions.instances[id] then
LoggingCombat(true)
isLogging = true
print("|cFFFFFF00AutoLoggerClassic|r: Combat logging enabled.")
elseif isLogging and not ALCOptions.instances[id] then
LoggingCombat(false)
isLogging = false
print("|cFFFFFF00AutoLoggerClassic|r: Combat logging disabled.")
end
end
-- Called when entering a raid.
function ns:OnRaidInstanceWelcome()
ns:ToggleLogging()
end
-- Called when most game data is available.
function ns:OnPlayerEnteringWorld()
ns:ToggleLogging()
end
-- Called on ADDON_LOADED.
function ns:OnAddonLoaded(addonName)
if addonName == ADDON_NAME then
LoadVariables()
InitMinimapButton()
InitSlash()
ns:InitMainFrame()
if not ALCOptionsGlobal.disableLoginMessage then
print("|cFFFFFF00AutoLoggerClassic|r loaded! Type /alc to toggle options. Type /fg help for commands. Remember to enable advanced combat logging in Options > Network and clear your combat log often.")
end
-- LoggingCombat() can return nil seemingly randomly
isLogging = LoggingCombat() or false
end
end
-- Registers for events.
local function Initialize()
ns.eventFrame = CreateFrame("Frame")
ns:RegisterAllEvents(ns.eventFrame)
end
Initialize()