976f219 - Add major aura indicator
[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.majorFrames = {};
10 OmaRF.positions = {
11     "TOPLEFT", "TOPRIGHT", "CENTER", "BOTTOMLEFT", "BOTTOMRIGHT"
12 };
13
14 OmaRF.running = false;
15
16 local defaults = {
17     profile = {
18         enabled = true,
19         majorAuras = {
20             auras = {"Aqua Bomb"},
21             max = 3;
22             iconSize = 24,
23             textSize = 10,
24         },
25         indicators = {
26             ['**'] = {
27                 auras = {},
28                 textSize = 10,
29                 textColor = {1, 1, 1, 1},
30                 mine = false,
31                 stack = true,
32                 showText = true,
33                 showIcon = true,
34                 useDefaultIcon = true,
35                 iconSize = 10,
36                 iconColor = {1, 1, 1, 1},
37             },
38         },
39     }
40 };
41
42 function OmaRF:OnInitialize()
43     self.db = LibStub("AceDB-3.0"):New("OmaRFDB", defaults);
44     self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig");
45     self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig");
46     self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig");
47 end
48
49 function OmaRF:OnEnable()
50     self:RefreshConfig();
51 end
52
53 function OmaRF:OnDisable()
54     self.running = false;
55     for name, frame in pairs(self.frames) do
56         for _, ind in pairs(frame) do
57             ind.text:Hide();
58             ind.icon:Hide();
59         end
60         for _, ind in ipairs(self.majorFrames[name]) do
61             ind.icon:Hide();
62             ind.expire:Hide();
63             ind.stack:Hide();
64         end
65     end
66 end
67
68 SLASH_OMARF1 = "/omarf";
69 function SlashCmdList.OMARF(msg, editBox)
70     local loaded, finished = IsAddOnLoaded("OmaRFConfig");
71     if not loaded then
72         local loaded, reason = LoadAddOn("OmaRFConfig");
73         if not loaded then
74             if reason == "DISABLED" then
75                 print("OmaRFConfig is disabled");
76             elseif reason == "MISSING" then
77                 print("OmaRFConfig is missing");
78             elseif reason == "CORRUPT" then
79                 print("OmaRFConfig is corrupt");
80             elseif reason == "INCOMPATIBLE" then
81                 print("OmaRFConfig is incompatible");
82             elseif reason == "INTERFACE_VERSION" then
83                 print("OmaRFConfig has wrong interface version");
84             end
85             return;
86         end
87     elseif not finished then
88         -- slash command sent again when loading process is in progress
89         return;
90     end
91
92     InterfaceOptionsFrame_OpenToCategory(OmaRF.optionsFrames.Profile);
93     InterfaceOptionsFrame_OpenToCategory(OmaRF.optionsFrames.Indicators);
94 end