34b465786e338a53fb25798b8d42b6c8b4edd102
[wowui.git] / OmaRF / Core.lua
1 OmaRF = CreateFrame("Frame");
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 OmaRF.ooc_queue = {};
17
18 local defaults = {
19     profile = {
20         enabled = true,
21         majorAuras = {
22             auras = {"Aqua Bomb"},
23             max = 3;
24             iconSize = 24,
25             textSize = 10,
26         },
27         indicators = {
28             ['**'] = {
29                 auras = {},
30                 textSize = 10,
31                 textColor = {1, 1, 1, 1},
32                 mine = false,
33                 stack = true,
34                 showText = true,
35                 showIcon = true,
36                 useDefaultIcon = true,
37                 iconSize = 10,
38                 iconColor = {1, 1, 1, 1},
39             },
40         },
41     }
42 };
43
44 function OmaRF:OnInitialize()
45     self.db = LibStub("AceDB-3.0"):New("OmaRFDB", defaults);
46     self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig");
47     self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig");
48     self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig");
49 end
50
51 function OmaRF:OnEnable()
52     self:RefreshConfig();
53 end
54
55 function OmaRF:OnDisable()
56     self.running = false;
57     for name, frame in pairs(self.frames) do
58         for _, ind in pairs(frame) do
59             ind.text:Hide();
60             ind.icon:Hide();
61         end
62         for _, ind in ipairs(self.majorFrames[name]) do
63             ind.icon:Hide();
64             ind.expire:Hide();
65             ind.stack:Hide();
66         end
67     end
68 end
69
70 local function onEvent(self, event, ...)
71     if event == "PLAYER_REGEN_ENABLED" then
72         for _, t in pairs(self.ooc_queue) do
73             t.func(t.args);
74         end
75         if next(self.ooc_queue) ~= nil then
76             wipe(self.ooc_queue);
77         end
78     elseif event == "PLAYER_LOGIN" then
79         self:OnEnable();
80     elseif event == "ADDON_LOADED" then
81         self:OnInitialize();
82     end
83 end
84
85 SLASH_OMARF1 = "/omarf";
86 function SlashCmdList.OMARF(msg, editBox)
87     local loaded, finished = IsAddOnLoaded("OmaRFConfig");
88     if not loaded then
89         local loaded, reason = LoadAddOn("OmaRFConfig");
90         if not loaded then
91             if reason == "DISABLED" then
92                 print("OmaRFConfig is disabled");
93             elseif reason == "MISSING" then
94                 print("OmaRFConfig is missing");
95             elseif reason == "CORRUPT" then
96                 print("OmaRFConfig is corrupt");
97             elseif reason == "INCOMPATIBLE" then
98                 print("OmaRFConfig is incompatible");
99             elseif reason == "INTERFACE_VERSION" then
100                 print("OmaRFConfig has wrong interface version");
101             end
102             return;
103         end
104     elseif not finished then
105         -- slash command sent again when loading process is in progress
106         return;
107     end
108
109     InterfaceOptionsFrame_OpenToCategory(OmaRF.optionsFrames.Profile);
110     InterfaceOptionsFrame_OpenToCategory(OmaRF.optionsFrames.Indicators);
111 end
112
113 OmaRF:RegisterEvent("ADDON_LOADED");
114 OmaRF:RegisterEvent("PLAYER_LOGIN");
115 OmaRF:RegisterEvent("PLAYER_REGEN_ENABLED");
116 OmaRF:SetScript("OnEvent", onEvent);