comparison Core.lua @ 31:90d58723ac0a

- Removed all BeanCounter checks in files. + Added a new module: BeanCounter Support. This module will now take care of preventing mail opening while BeanCounter is scanning. + Added AceHook library for the BeanCounter Support module. ~ Sorted the Core.lua OnInitialize to properly toggle modules before doing time consuming things. ~ All module comments are now a property of the modules themselves and can be retrieved with (string)?.moduleDescription? and (bool)?.moduleRequired?. ~ All module references are now called ?mod?. ! Added a new config group: Modules. This group will show the module statuses and descriptions and it will contain all optional modules (with their settings) as subgroups. - Removed all libraries from the repository.
author Zerotorescue
date Fri, 10 Sep 2010 18:59:58 +0200
parents d52e64bd048f
children 8168280420ae
comparison
equal deleted inserted replaced
30:4ab03ed958ed 31:90d58723ac0a
6 -- Another addon can use this variable to indicate they're working too, MailOpener will then wait for that to finish 6 -- Another addon can use this variable to indicate they're working too, MailOpener will then wait for that to finish
7 7
8 local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed; 8 local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed;
9 9
10 function MailOpener:OnInitialize() 10 function MailOpener:OnInitialize()
11 self:Debug("OnInitialize");
12
13
14
15
16 -- SAVED VARIABLES
17
11 local defaults = { 18 local defaults = {
12 profile = { 19 profile = {
13 uses = 0, 20 uses = 0,
14 general = { 21 general = {
15 defaultStatus = "disabled", -- addon enabled, but mail opening not auto on 22 defaultStatus = "disabled", -- addon enabled, but mail opening not auto on
21 continueOpening = false, 28 continueOpening = false,
22 waitTime = 5, 29 waitTime = 5,
23 initialDelay = 0.5, 30 initialDelay = 0.5,
24 }, 31 },
25 modules = { 32 modules = {
33 BeanCounterSupport = true,
34 Config = false,
26 Collected = true, 35 Collected = true,
27 FailSafe = true, 36 FailSafe = true,
28 }, 37 },
29 notifications = { 38 notifications = {
30 welcome = false, 39 welcome = false,
72 }; 81 };
73 82
74 -- Register our saved variables database 83 -- Register our saved variables database
75 self.db = LibStub("AceDB-3.0"):New("MailOpenerDB", defaults, true); 84 self.db = LibStub("AceDB-3.0"):New("MailOpenerDB", defaults, true);
76 85
77 -- Set these as object variables so we can use them in our modules 86
78 if select(6, GetAddOnInfo("Postal")) == nil then 87
79 self.PostalEnabled = true; 88
80 89
81 -- Ensure this addon is loaded if AddonLoader is installed 90 -- MODULE TOGGLING
82 if AddonLoader and AddonLoader.LoadAddOn and not Postal then
83 AddonLoader:LoadAddOn("Postal");
84 end
85 end
86
87 if select(6, GetAddOnInfo("QuickAuctions")) == nil then
88 self.QuickAuctionsEnabled = true;
89
90 -- Ensure this addon is loaded if AddonLoader is installed
91 if AddonLoader and AddonLoader.LoadAddOn then
92 AddonLoader:LoadAddOn("QuickAuctions");
93 end
94 end
95 91
96 -- Don't enable the config module until we need it 92 -- Don't enable the config module until we need it
97 for name, module in self:IterateModules() do 93 for name, module in self:IterateModules() do
98 if name == "Config" then 94 if self.db.profile.modules[name] ~= nil then
99 module:SetEnabledState(false);
100 elseif self.db.profile.modules[name] ~= nil then
101 if self.db.profile.modules[name] then 95 if self.db.profile.modules[name] then
102 self:Debug("|cff00ff00Enabling|r module: " .. name); 96 self:Debug("|cff00ff00Enabling|r module: " .. name);
103 else 97 else
104 self:Debug("|cffff0000Disabling|r module: " .. name); 98 self:Debug("|cffff0000Disabling|r module: " .. name);
105 end 99 end
106 100
107 module:SetEnabledState(self.db.profile.modules[name]); 101 module:SetEnabledState(self.db.profile.modules[name]);
108 end 102 end
109 end 103 end
104
105
106
107
108
109 -- SLASH COMMANDS
110
111 -- Disable the AddonLoader slash commands
112 SLASH_MO1 = nil;
113 SLASH_MAILOPEN1 = nil;
114 SLASH_MAILOPENER1 = nil;
115
116 -- Register our own slash commands
117 SLASH_MAILOPENER1 = "/mo";
118 SLASH_MAILOPENER2 = "/mailopen";
119 SLASH_MAILOPENER3 = "/mailopener";
120 SlashCmdList["MAILOPENER"] = function(msg)
121 MailOpener:EnableConfigModule();
122
123 MailOpenerConfig:CommandHandler(msg);
124 end
125
126
127
128
129
130 -- INTERFACE OPTIONS
131
132 -- Attempt to remove the interface options added by AddonLoader (if enabled)
133 if AddonLoader and AddonLoader.RemoveInterfaceOptions then
134 AddonLoader:RemoveInterfaceOptions("Mail Opener");
135 end
136
137 -- Now create our own options frame
138 local frame = CreateFrame("Frame", nil, UIParent);
139 frame:Hide();
140 frame.name = "Mail Opener";
141 frame:HookScript("OnShow", function(self)
142 -- Enable the config module
143 MailOpener:EnableConfigModule();
144
145 -- Load the options and add it to the blizzard interface list
146 MailOpenerConfig:Load();
147
148 -- Refresh the frame to instantly show the right options
149 InterfaceOptionsFrame_OpenToCategory(self.name)
150 end);
151 -- And add it to the interface options
152 InterfaceOptions_AddCategory(frame);
153
154
155
156
157
158 -- ADDON / MAIL OPENING STATUS TOGGLER
110 159
111 -- Make the open all checkbox 160 -- Make the open all checkbox
112 local check = CreateFrame("CheckButton", "cbMailOpenerEnable", MailFrame, "ChatConfigCheckButtonTemplate"); 161 local check = CreateFrame("CheckButton", "cbMailOpenerEnable", MailFrame, "ChatConfigCheckButtonTemplate");
113 check:SetHeight(26); 162 check:SetHeight(26);
114 check:SetWidth(26); 163 check:SetWidth(26);
148 AutoOpenMail = false; 197 AutoOpenMail = false;
149 end 198 end
150 end 199 end
151 end); 200 end);
152 check.tooltip = "Toggle automatic mail opening on or off (you can force this by holding shift when opening the mailbox.\n\nHold the |cffffffffSHIFT|r key to disable the entire addon."; 201 check.tooltip = "Toggle automatic mail opening on or off (you can force this by holding shift when opening the mailbox.\n\nHold the |cffffffffSHIFT|r key to disable the entire addon.";
153 check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 68, -13) 202 check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 68, -13);
154
155 if self.QuickAuctionsEnabled then
156 -- QA is enabled so move the checkbox further to the right
157
158 check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 155, -13);
159 end
160 203
161 -- Get reference to the text field 204 -- Get reference to the text field
162 local checkboxText = _G[check:GetName() .. "Text"]; 205 local checkboxText = _G[check:GetName() .. "Text"];
163 checkboxText:SetText("Mail Opener"); 206 checkboxText:SetText("Mail Opener");
164 -- We like this color more 207 -- We like this color more
165 checkboxText:SetTextColor(1, 0.8, 0, 1); 208 checkboxText:SetTextColor(1, 0.8, 0, 1);
166 209
167 self.cbOpenAll = check; 210 self.cbOpenAll = check;
168 211
212
213
214
215 -- CONFIG BUTTON
216
169 -- Make the config button 217 -- Make the config button
170 local button = CreateFrame("Button", "btnMailOpenerConfig", MailFrame, "UIPanelButtonTemplate") 218 local button = CreateFrame("Button", "btnMailOpenerConfig", MailFrame, "UIPanelButtonTemplate")
171 button:SetText("Config") 219 button:SetText("Config")
172 button:SetHeight(23) 220 button:SetHeight(23)
173 button:SetWidth(55) 221 button:SetWidth(55)
174 if self.PostalEnabled then 222 button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -55, -13);
175 button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -75, -13);
176 else
177 button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -55, -13);
178 end
179 button:SetScript("OnClick", function() 223 button:SetScript("OnClick", function()
180 MailOpener:EnableConfigModule(); 224 MailOpener:EnableConfigModule();
181 225
182 MailOpenerConfig:Show(); 226 MailOpenerConfig:Show();
183 227
185 --BETA: MailOpener:ShowBetaPopup(); 229 --BETA: MailOpener:ShowBetaPopup();
186 --BETA:end 230 --BETA:end
187 end); 231 end);
188 232
189 self.btnConfig = button; 233 self.btnConfig = button;
190 234
191 -- Disable the AddonLoader slash commands 235
192 SLASH_MO1 = nil; 236
193 SLASH_MAILOPEN1 = nil; 237
194 SLASH_MAILOPENER1 = nil; 238
195 239 -- ADDON LOADING
196 -- Register our own slash commands 240 -- THE BELOW WILL TAKE SOME TIME; WE WILL BE LOADING OTHER ADDONS
197 SLASH_MAILOPENER1 = "/mo"; 241
198 SLASH_MAILOPENER2 = "/mailopen"; 242 if select(6, GetAddOnInfo("Postal")) == nil then
199 SLASH_MAILOPENER3 = "/mailopener"; 243 self.PostalEnabled = true; -- Set this as an object variable so we can use it in our modules
200 SlashCmdList["MAILOPENER"] = function(msg) 244
201 MailOpener:EnableConfigModule(); 245 -- Ensure this addon is loaded if AddonLoader is installed
202 246 if AddonLoader and AddonLoader.LoadAddOn and not Postal then
203 MailOpenerConfig:CommandHandler(msg); 247 AddonLoader:LoadAddOn("Postal");
204 end 248 end
205 249 end
206 -- Attempt to remove the interface options added by AddonLoader (if enabled) 250
207 if AddonLoader and AddonLoader.RemoveInterfaceOptions then 251 if select(6, GetAddOnInfo("QuickAuctions")) == nil then
208 AddonLoader:RemoveInterfaceOptions("Mail Opener"); 252 self.QuickAuctionsEnabled = true; -- Set this as an object variable so we can use it in our modules
209 end 253
210 254 -- Ensure this addon is loaded if AddonLoader is installed
211 -- Now create our own options frame 255 if AddonLoader and AddonLoader.LoadAddOn then
212 local frame = CreateFrame("Frame", nil, UIParent); 256 AddonLoader:LoadAddOn("QuickAuctions");
213 frame:Hide(); 257 end
214 frame.name = "Mail Opener"; 258 end
215 frame:HookScript("OnShow", function(self) 259
216 -- Enable the config module 260
217 MailOpener:EnableConfigModule(); 261
218 262
219 -- Load the options and add it to the blizzard interface list 263
220 MailOpenerConfig:Load(); 264 -- ADJUST POSITIONS
221 265
222 -- Refresh the frame to instantly show the right options 266 if self.QuickAuctionsEnabled then
223 InterfaceOptionsFrame_OpenToCategory(self.name) 267 -- QA is enabled so move the checkbox further to the right
224 end); 268
225 -- And add it to the interface options 269 self.cbOpenAll:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 155, -13);
226 InterfaceOptions_AddCategory(frame); 270 end
271
272 if self.PostalEnabled then
273 self.btnConfig:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -75, -13);
274 end
227 end 275 end
228 276
229 function MailOpener:OnEnable() 277 function MailOpener:OnEnable()
230 self:RegisterEvent("MAIL_SHOW"); 278 self:RegisterEvent("MAIL_SHOW");
231 self:RegisterEvent("PLAYER_ENTERING_WORLD"); 279 self:RegisterEvent("PLAYER_ENTERING_WORLD");
453 self:Debug("OpenNow (" .. ((MailAddonBusy and "1") or "0") .. ")"); 501 self:Debug("OpenNow (" .. ((MailAddonBusy and "1") or "0") .. ")");
454 if MailFrame:IsVisible() and AutoOpenMail then 502 if MailFrame:IsVisible() and AutoOpenMail then
455 self:Debug("OpenNow"); 503 self:Debug("OpenNow");
456 504
457 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that 505 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that
458 local BeanCounterActive = not InboxCloseButton:IsVisible(); 506 --local BeanCounterActive = not InboxCloseButton:IsVisible();
459 507
460 if not BeanCounterActive and not MailAddonBusy then 508 --if not BeanCounterActive and not MailAddonBusy then
509 if not MailAddonBusy then
461 -- No other addon is currently active 510 -- No other addon is currently active
462 511
463 self:CancelTimer(self.tmrTryAgain, true); -- Insurance 512 self:CancelTimer(self.tmrTryAgain, true); -- Insurance
464 513
465 if QuickAuctionsAutoMail then 514 if QuickAuctionsAutoMail then
481 530
482 -- Summon the mail opening gods 531 -- Summon the mail opening gods
483 self:SendMessage("MO_OPEN_MAIL"); 532 self:SendMessage("MO_OPEN_MAIL");
484 else 533 else
485 -- Another addon is ACTIVE 534 -- Another addon is ACTIVE
486 self:Debug("Another addon active, waiting .5 seconds..."); 535 self:Debug("Another addon active, waiting .5 seconds... (" .. MailAddonBusy .. ")");
487 536
488 self:CancelTimer(self.tmrTryAgain, true); -- Insurance 537 self:CancelTimer(self.tmrTryAgain, true); -- Insurance
489 -- Try again every 0.5 seconds 538 -- Try again every 0.5 seconds
490 self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5); 539 self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5);
491 end 540 end
554 self:Debug("|cff00ff00Recheck|r"); 603 self:Debug("|cff00ff00Recheck|r");
555 604
556 -- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed 605 -- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed
557 606
558 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that 607 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that
559 local BeanCounterActive = not InboxCloseButton:IsVisible(); 608 --local BeanCounterActive = not InboxCloseButton:IsVisible();
560 609
561 if not BeanCounterActive and AutoOpenMail and not MailAddonBusy then 610 --if not BeanCounterActive and AutoOpenMail and not MailAddonBusy then
611 if AutoOpenMail and not MailAddonBusy then
562 -- Query the server 612 -- Query the server
563 CheckInbox(); 613 CheckInbox();
564 end 614 end
565 615
566 -- Stop previous timer 616 -- Stop previous timer