7e6c1d4 - Detach indicators from protected frames
[wowui.git] / OmaRF / Core.lua
1 local unpack, wipe, next, pairs, ipairs = unpack, wipe, next, pairs, ipairs;
2
3 OmaRF = CreateFrame("Frame");
4
5 OmaRF.normalBarColor = CreateColor(0.3, 0.3, 0.3);
6 OmaRF.dispelBarColor = CreateColor(1, 0.5, 0);
7 OmaRF.normalBackColor = {0.7, 0.7, 0.7};
8 OmaRF.dispelBackColor = {0.5, 0.2, 0};
9 OmaRF.positions = {
10     "TOPLEFT", "TOPRIGHT", "CENTER", "BOTTOMLEFT", "BOTTOMRIGHT"
11 };
12 OmaRF.running = false;
13 OmaRF.ooc_queue = {};
14
15 local defaults = {
16     profile = {
17         enabled = true,
18         majorAuras = {
19             auras = {"Aqua Bomb"},
20             max = 3;
21             iconSize = 24,
22             textSize = 10,
23         },
24         indicators = {
25             ['**'] = {
26                 auras = {},
27                 textSize = 10,
28                 textColor = {1, 1, 1, 1},
29                 mine = false,
30                 stack = true,
31                 showText = true,
32                 showIcon = true,
33                 useDefaultIcon = true,
34                 iconSize = 10,
35                 iconColor = {1, 1, 1, 1},
36             },
37         },
38     }
39 };
40
41 function OmaRF:OnInitialize()
42     self.db = LibStub("AceDB-3.0"):New("OmaRFDB", defaults);
43     self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig");
44     self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig");
45     self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig");
46 end
47
48 function OmaRF:OnEnable()
49     self:RefreshConfig();
50 end
51
52 function OmaRF:OnDisable()
53     self.running = false;
54     self.frameBase:Hide();
55 end
56
57 local function onEvent(self, event, ...)
58     if event == "PLAYER_REGEN_ENABLED" then
59         for _, t in pairs(self.ooc_queue) do
60             t.func(unpack(t.args));
61         end
62         if next(self.ooc_queue) ~= nil then
63             wipe(self.ooc_queue);
64         end
65     elseif event == "PLAYER_LOGIN" then
66         self:OnEnable();
67     elseif event == "ADDON_LOADED" then
68         self:OnInitialize();
69     end
70 end
71
72 SLASH_OMARF1 = "/omarf";
73 function SlashCmdList.OMARF(msg, editBox)
74     local loaded, finished = IsAddOnLoaded("OmaRFConfig");
75     if not loaded then
76         local loaded, reason = LoadAddOn("OmaRFConfig");
77         if not loaded then
78             if reason == "DISABLED" then
79                 print("OmaRFConfig is disabled");
80             elseif reason == "MISSING" then
81                 print("OmaRFConfig is missing");
82             elseif reason == "CORRUPT" then
83                 print("OmaRFConfig is corrupt");
84             elseif reason == "INCOMPATIBLE" then
85                 print("OmaRFConfig is incompatible");
86             elseif reason == "INTERFACE_VERSION" then
87                 print("OmaRFConfig has wrong interface version");
88             end
89             return;
90         end
91     elseif not finished then
92         -- slash command sent again when loading process is in progress
93         return;
94     end
95
96     InterfaceOptionsFrame_OpenToCategory(OmaRF.optionsFrames.Profile);
97     InterfaceOptionsFrame_OpenToCategory(OmaRF.optionsFrames.Indicators);
98 end
99
100 OmaRF:RegisterEvent("ADDON_LOADED");
101 OmaRF:RegisterEvent("PLAYER_LOGIN");
102 OmaRF:RegisterEvent("PLAYER_REGEN_ENABLED");
103 OmaRF:SetScript("OnEvent", onEvent);