9bc8361 - Fix bugs found in testing
[wowui.git] / OmaRF / Core.lua
1 OmaRF = LibStub("AceAddon-3.0"):NewAddon("OmaRF");
2
3 OmaRF.normalBarColor = CreateColor(0.3, 0.3, 0.3);
4 OmaRF.dispelBarColor = CreateColor(1, 0.5, 0);
5 OmaRF.normalBackColor = {0.7, 0.7, 0.7};
6 OmaRF.dispelBackColor = {0.5, 0.2, 0};
7
8 OmaRF.frames = {};
9 OmaRF.positions = {
10     "TOPLEFT", "TOPRIGHT", "CENTER", "BOTTOMLEFT", "BOTTOMRIGHT"
11 };
12
13 OmaRF.running = false;
14
15 local defaults = {
16     profile = {
17         indicatorFont = "Arial Narrow",
18         showIcons = true,
19         enabled = true,
20         indicators = {
21             ['**'] = {
22                 auras = {},
23                 textSize = 10,
24                 textColor = {1, 1, 1, 1},
25                 mine = false,
26                 stack = true,
27                 showText = true,
28                 showIcon = true,
29                 useDefaultIcon = true,
30                 iconSize = 10,
31                 iconColor = {1, 1, 1, 1},
32             },
33         },
34     }
35 };
36
37 function OmaRF:OnInitialize()
38     self.db = LibStub("AceDB-3.0"):New("OmaRFDB", defaults);
39     self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig");
40     self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig");
41     self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig");
42 end
43
44 function OmaRF:OnEnable()
45     self:RefreshConfig();
46 end
47
48 function OmaRF:OnDisable()
49     self.running = false;
50     for _, frame in pairs(self.frames) do
51         for _, ind in pairs(frame) do
52             ind.text:SetText("");
53             ind.icon:SetTexture("");
54         end
55     end
56 end
57
58 SLASH_OMARF1 = "/omarf";
59 function SlashCmdList.OMARF(msg, editBox)
60     local loaded, finished = IsAddOnLoaded("OmaRFConfig");
61     if not loaded then
62         local loaded, reason = LoadAddOn("OmaRFConfig");
63         if not loaded then
64             if reason == "DISABLED" then
65                 print("OmaRFConfig is disabled");
66             elseif reason == "MISSING" then
67                 print("OmaRFConfig is missing");
68             elseif reason == "CORRUPT" then
69                 print("OmaRFConfig is corrupt");
70             elseif reason == "INCOMPATIBLE" then
71                 print("OmaRFConfig is incompatible");
72             elseif reason == "INTERFACE_VERSION" then
73                 print("OmaRFConfig has wrong interface version");
74             end
75             return;
76         end
77     elseif not finished then
78         -- slash command sent again when loading process is in progress
79         return;
80     end
81
82     InterfaceOptionsFrame_OpenToCategory(OmaRF.optionsFrames.Indicators);
83 end