b8c7045 - Rename
[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                 textSize = 10,
23                 textColor = {1, 1, 1, 1},
24                 mine = false,
25                 stack = true,
26                 showText = true,
27                 showIcon = true,
28                 useDefaultIcon = true,
29                 iconSize = 10,
30                 iconColor = {1, 1, 1, 1},
31             },
32         },
33     }
34 };
35
36 function OmaRF:OnInitialize()
37     self.db = LibStub("AceDB-3.0"):New("OmaRFDB", defaults);
38     self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig");
39     self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig");
40     self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig");
41 end
42
43 function OmaRF:OnEnable()
44     self:RefreshConfig();
45 end
46
47 function OmaRF:OnDisable()
48     self.running = false;
49     for _, frame in pairs(self.frames) do
50         for _, ind in pairs(frame) do
51             ind.text:SetText("");
52             ind.icon:SetTexture("");
53         end
54     end
55 end
56
57 SLASH_OMARF1 = "/omarf";
58 function SlashCmdList.OMARF(msg, editBox)
59     local loaded, finished = IsAddonLoaded("OmaRFConfig");
60     if not loaded then
61         local loaded, reason = LoadAddon("OmaRFConfig");
62         if not loaded then
63             if reason == "DISABLED" then
64                 print("OmaRFConfig is disabled");
65             elseif reason == "MISSING" then
66                 print("OmaRFConfig is missing");
67             elseif reason == "CORRUPT" then
68                 print("OmaRFConfig is corrupt");
69             elseif reason == "INCOMPATIBLE" then
70                 print("OmaRFConfig is incompatible");
71             elseif reason == "INTERFACE_VERSION" then
72                 print("OmaRFConfig has wrong interface version");
73             end
74             return;
75         end
76     elseif not finished then
77         -- slash command sent again when loading process is in progress
78         return;
79     end
80
81     InterfaceOptionsFrame_OpenToCategory(OmaRF.optionsFrames.Indicators);
82 end