-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.lua
executable file
·77 lines (68 loc) · 2.45 KB
/
Main.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
local addon = LibStub("Addon-1.0"):New(...)
local Tooltip = LibStub("Tooltip-1.0")
local Colorizer = addon.Colorizer
local ADDON_LOAD_FAILED = "<< %s >> " .. ADDON_LOAD_FAILED
local function TryLoadAddOn(name)
local loaded, reason = C_AddOns.LoadAddOn(name)
if not loaded and not reason then
C_AddOns.LoadAddOn(name)
elseif reason then
local _, title = GetAddOnInfo(addon:GetName())
title = NORMAL_FONT_COLOR:WrapTextInColorCode(title)
local state = RED_FONT_COLOR:WrapTextInColorCode(_G["ADDON_" .. reason])
print(YELLOW_FONT_COLOR:WrapTextInColorCode(ADDON_LOAD_FAILED:format(title, name, state)))
return false
end
return true
end
function addon:OnInitialized()
self.DB = LibStub("AceDB-3.0"):New("WowInfoDB", {}, true)
SLASH_WOWINFO1 = "/wowinfo"
SLASH_WOWINFO2 = "/wowi"
SLASH_WOWINFO3 = "/wi"
SlashCmdList["WOWINFO"] = function(input)
if TryLoadAddOn("WowInfo_Options") then
if not addon.__options then
addon.__options = LibStub("AceOptions-1.0")
end
addon.__options:Open()
end
end
end
do
local MT = {
__index = function(t, key)
return Tooltip[key]
or Colorizer[key]
or rawget(t, "__friend") and t.__friend[key]
or rawget(t, "__extension") and t.__extension[key]
end
}
function addon:NewTooltip(name, extensionName)
local tooltip = addon:NewObject(name .. "Tooltip")
local friend = addon:GetObject(name .. "Extension", true)
-- When the Tooltip and the Extension have the same name they are considered friends,
-- meaning, the Tooltip can access the Extension as if it was part of the same object.
tooltip.__friend = friend
-- REVIEW: For now each Tooltip can have a single extension.
if extensionName then
tooltip.__extension = addon:GetObject(extensionName .. "Extension")
end
return setmetatable(tooltip, MT)
end
end
do
local MT = {
__index = function(t, key)
return Tooltip[key]
or Colorizer[key]
or rawget(t, "__root") and t.__root[key]
end
}
function addon:NewExtension(name)
local root = addon:GetObject(name)
local extension = addon:NewObject(name .. "Extension")
extension.__root = root
return setmetatable(extension, MT)
end
end