annotate Core.lua @ 2:57ba1593ac42

Reducing amount of calculations regarding mail updates, all mail changes are now addon-wide broadcasted messages. Main reason for this is to allow for another plugin.
author Zerotorescue
date Sun, 05 Sep 2010 17:26:35 +0200
parents 6f17035de058
children c6f0976069c7
rev   line source
Zerotorescue@0 1 MailOpener = LibStub("AceAddon-3.0"):NewAddon("MailOpener", "AceEvent-3.0", "AceTimer-3.0");
Zerotorescue@0 2
Zerotorescue@0 3 local enabled = true;
Zerotorescue@0 4 local MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, opening, freshList, mailboxEmptySoundPlayed;
Zerotorescue@0 5
Zerotorescue@0 6 function MailOpener:OnInitialize()
Zerotorescue@0 7 local defaults = {
Zerotorescue@0 8 global = {
Zerotorescue@0 9 uses = 0;
Zerotorescue@0 10 },
Zerotorescue@0 11 profile = {
Zerotorescue@0 12 general = {
Zerotorescue@0 13 defaultStatus = "_enabled",
Zerotorescue@0 14 defaultQAStatus = "__remember",
Zerotorescue@0 15 continueOpeningStackableItems = false,
Zerotorescue@0 16 autoDisableQAAutoMail = true,
Zerotorescue@0 17 autoReenableQAAutoMail = false,
Zerotorescue@0 18 autoSetBackQAAutoMail = true,
Zerotorescue@0 19 continueOpening = false,
Zerotorescue@0 20 waitTime = 5,
Zerotorescue@0 21 initialDelay = 0.5,
Zerotorescue@0 22 },
Zerotorescue@0 23 modules = {
Zerotorescue@0 24 Collected = true,
Zerotorescue@0 25 },
Zerotorescue@0 26 notifications = {
Zerotorescue@0 27 welcome = true,
Zerotorescue@0 28 bye = true,
Zerotorescue@0 29 finishedCurrentBatch = true,
Zerotorescue@0 30 mailboxIsEmpty = true,
Zerotorescue@0 31
Zerotorescue@0 32 skipped = {
Zerotorescue@0 33 all = true,
Zerotorescue@0 34 inventoryFull = true,
Zerotorescue@0 35 keepFreeSpaceLimit = true,
Zerotorescue@0 36 GMMail = true,
Zerotorescue@0 37 COD = true,
Zerotorescue@0 38 normalGoldMail = true,
Zerotorescue@0 39 normalItemsMail = true,
Zerotorescue@0 40 AHexpired = true,
Zerotorescue@0 41 AHsuccess = true,
Zerotorescue@0 42 AHwon = true,
Zerotorescue@0 43 AHcanceled = true,
Zerotorescue@0 44 AHoutbid = true,
Zerotorescue@0 45 other = true,
Zerotorescue@0 46 },
Zerotorescue@0 47 processed = {
Zerotorescue@0 48 all = true,
Zerotorescue@0 49 normalGoldMail = true,
Zerotorescue@0 50 normalItemsMail = true,
Zerotorescue@0 51 AHexpired = true,
Zerotorescue@0 52 AHsuccess = true,
Zerotorescue@0 53 AHwon = true,
Zerotorescue@0 54 AHcanceled = true,
Zerotorescue@0 55 AHoutbid = true,
Zerotorescue@0 56 other = true,
Zerotorescue@0 57 },
Zerotorescue@0 58
Zerotorescue@0 59 bagsFullSound = false,
Zerotorescue@0 60 bagsFullSoundFile = "Sound\\Spells\\SimonGame_Visual_BadPress.wav",
Zerotorescue@0 61 bagsFullSoundFileName = "Simon Error",
Zerotorescue@0 62 bagsFullSoundOnlyOnce = true,
Zerotorescue@0 63 mailboxEmptySound = false,
Zerotorescue@0 64 mailboxEmptySoundFile = "Sound\\Spells\\SimonGame_Visual_GameStart.wav",
Zerotorescue@0 65 mailboxEmptySoundFileName = "Simon Start",
Zerotorescue@0 66 mailboxEmptySoundOnlyOnce = true,
Zerotorescue@0 67 },
Zerotorescue@0 68 },
Zerotorescue@0 69 };
Zerotorescue@0 70
Zerotorescue@0 71 -- Register our saved variables database
Zerotorescue@0 72 self.db = LibStub("AceDB-3.0"):New("MailOpenerDB", defaults, true);
Zerotorescue@0 73
Zerotorescue@0 74 -- Set these as object variables so we can use them in our modules
Zerotorescue@0 75 if select(6, GetAddOnInfo("Postal")) == nil then
Zerotorescue@0 76 self.PostalEnabled = true;
Zerotorescue@0 77
Zerotorescue@0 78 -- Ensure this addon is loaded if AddonLoader is installed
Zerotorescue@0 79 if AddonLoader and AddonLoader.LoadAddOn and not Postal then
Zerotorescue@0 80 AddonLoader:LoadAddOn("Postal");
Zerotorescue@0 81 end
Zerotorescue@0 82 end
Zerotorescue@0 83
Zerotorescue@0 84 if select(6, GetAddOnInfo("QuickAuctions")) == nil then
Zerotorescue@0 85 self.QuickAuctionsEnabled = true;
Zerotorescue@0 86
Zerotorescue@0 87 -- Ensure this addon is loaded if AddonLoader is installed
Zerotorescue@0 88 if AddonLoader and AddonLoader.LoadAddOn then
Zerotorescue@0 89 AddonLoader:LoadAddOn("QuickAuctions");
Zerotorescue@0 90 end
Zerotorescue@0 91 end
Zerotorescue@0 92
Zerotorescue@0 93 -- Don't enable the config module until we need it
Zerotorescue@0 94 for name, module in self:IterateModules() do
Zerotorescue@0 95 if name == "Config" then
Zerotorescue@0 96 module:SetEnabledState(false);
Zerotorescue@0 97 elseif self.db.profile.modules[name] ~= nil then
Zerotorescue@0 98 if self.db.profile.modules[name] then
Zerotorescue@0 99 self:Debug("|cff00ff00Enabling|r module: " .. name);
Zerotorescue@0 100 else
Zerotorescue@0 101 self:Debug("|cffff0000Disabling|r module: " .. name);
Zerotorescue@0 102 end
Zerotorescue@0 103
Zerotorescue@0 104 module:SetEnabledState(self.db.profile.modules[name]);
Zerotorescue@0 105 end
Zerotorescue@0 106 end
Zerotorescue@0 107
Zerotorescue@0 108 -- Make the open all checkbox
Zerotorescue@0 109 local check = CreateFrame("CheckButton", "cbMailOpenerEnable", MailFrame, "ChatConfigCheckButtonTemplate");
Zerotorescue@0 110 check:SetHeight(26);
Zerotorescue@0 111 check:SetWidth(26);
Zerotorescue@0 112 check:SetChecked(enabled);
Zerotorescue@0 113 check:SetHitRectInsets(0, -80, 0, 0);
Zerotorescue@0 114 check:SetScript("OnClick", function(self)
Zerotorescue@0 115 if self:GetChecked() then
Zerotorescue@0 116 MailOpener:Enable();
Zerotorescue@0 117 else
Zerotorescue@0 118 MailOpener:Disable();
Zerotorescue@0 119 end
Zerotorescue@0 120 end);
Zerotorescue@0 121 check.tooltip = "Toggle Mail Opener on or off.";
Zerotorescue@0 122 check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 68, -13)
Zerotorescue@0 123
Zerotorescue@0 124 if self.QuickAuctionsEnabled then
Zerotorescue@0 125 -- QA is enabled so move the checkbox further to the right
Zerotorescue@0 126
Zerotorescue@0 127 check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 155, -13);
Zerotorescue@0 128 end
Zerotorescue@0 129
Zerotorescue@0 130 -- Get reference to the text field
Zerotorescue@0 131 local checkboxText = _G[check:GetName() .. "Text"];
Zerotorescue@0 132 checkboxText:SetText("Mail Opener");
Zerotorescue@0 133 -- We like this color more
Zerotorescue@0 134 checkboxText:SetTextColor(1, 0.8, 0, 1);
Zerotorescue@0 135
Zerotorescue@0 136 self.cbOpenAll = check;
Zerotorescue@0 137
Zerotorescue@0 138 -- Make the config button
Zerotorescue@0 139 local button = CreateFrame("Button", "btnMailOpenerConfig", MailFrame, "UIPanelButtonTemplate")
Zerotorescue@0 140 button:SetText("Config")
Zerotorescue@0 141 button:SetHeight(23)
Zerotorescue@0 142 button:SetWidth(55)
Zerotorescue@0 143 if self.PostalEnabled then
Zerotorescue@0 144 button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -75, -13);
Zerotorescue@0 145 else
Zerotorescue@0 146 button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -55, -13);
Zerotorescue@0 147 end
Zerotorescue@0 148 button:SetScript("OnClick", function()
Zerotorescue@0 149 MailOpener:EnableConfigModule();
Zerotorescue@0 150
Zerotorescue@0 151 MailOpenerConfig:Show();
Zerotorescue@0 152
Zerotorescue@0 153 if MailOpener.db.global.uses >= 15 then
Zerotorescue@0 154 MailOpener:ShowBetaPopup();
Zerotorescue@0 155 end
Zerotorescue@0 156 end);
Zerotorescue@0 157
Zerotorescue@0 158 self.btnConfig = button;
Zerotorescue@0 159
Zerotorescue@0 160 -- Disable the AddonLoader slash commands
Zerotorescue@0 161 SLASH_MO1 = nil;
Zerotorescue@0 162 SLASH_MAILOPEN1 = nil;
Zerotorescue@0 163 SLASH_MAILOPENER1 = nil;
Zerotorescue@0 164
Zerotorescue@0 165 -- Register our own slash commands
Zerotorescue@0 166 SLASH_MAILOPENER1 = "/mo";
Zerotorescue@0 167 SLASH_MAILOPENER2 = "/mailopen";
Zerotorescue@0 168 SLASH_MAILOPENER3 = "/mailopener";
Zerotorescue@0 169 SlashCmdList["MAILOPENER"] = function(msg)
Zerotorescue@0 170 MailOpener:EnableConfigModule();
Zerotorescue@0 171
Zerotorescue@0 172 MailOpenerConfig:CommandHandler(msg);
Zerotorescue@0 173 end
Zerotorescue@0 174
Zerotorescue@0 175 -- Attempt to remove the interface options added by AddonLoader (if enabled)
Zerotorescue@0 176 if AddonLoader and AddonLoader.RemoveInterfaceOptions then
Zerotorescue@0 177 AddonLoader:RemoveInterfaceOptions("Mail Opener");
Zerotorescue@0 178 end
Zerotorescue@0 179
Zerotorescue@0 180 -- Now create our own options frame
Zerotorescue@0 181 local frame = CreateFrame("Frame", nil, UIParent);
Zerotorescue@0 182 frame:Hide();
Zerotorescue@0 183 frame.name = "Mail Opener";
Zerotorescue@0 184 frame:HookScript("OnShow", function(self)
Zerotorescue@0 185 -- Enable the config module
Zerotorescue@0 186 MailOpener:EnableConfigModule();
Zerotorescue@0 187
Zerotorescue@0 188 -- Load the options and add it to the blizzard interface list
Zerotorescue@0 189 MailOpenerConfig:Load();
Zerotorescue@0 190
Zerotorescue@0 191 -- Refresh the frame to instantly show the right options
Zerotorescue@0 192 InterfaceOptionsFrame_OpenToCategory(self.name)
Zerotorescue@0 193 end);
Zerotorescue@0 194 -- And add it to the interface options
Zerotorescue@0 195 InterfaceOptions_AddCategory(frame);
Zerotorescue@0 196 end
Zerotorescue@0 197
Zerotorescue@0 198 function MailOpener:OnEnable()
Zerotorescue@0 199 self:RegisterEvent("MAIL_SHOW");
Zerotorescue@0 200 self:RegisterEvent("PLAYER_ENTERING_WORLD");
Zerotorescue@0 201
Zerotorescue@0 202 self.btnConfig:Show();
Zerotorescue@0 203
Zerotorescue@0 204 -- Reset variables
Zerotorescue@0 205 lastAmount = 0;
Zerotorescue@0 206 self.debugChannel = nil;
Zerotorescue@0 207
Zerotorescue@0 208 self.db.global.uses = ( self.db.global.uses + 1 );
Zerotorescue@0 209
Zerotorescue@0 210 if self.db.global.uses == 15 then
Zerotorescue@0 211 self:ShowBetaPopup();
Zerotorescue@0 212 end
Zerotorescue@0 213
Zerotorescue@0 214 -- If we were toggling this addon on while the mailbox is opened we must register all events again
Zerotorescue@0 215 if MailFrame:IsVisible() then
Zerotorescue@0 216 self:MAIL_SHOW();
Zerotorescue@0 217 end
Zerotorescue@0 218 end
Zerotorescue@0 219
Zerotorescue@0 220 function MailOpener:OnDisable()
Zerotorescue@0 221 self:UnregisterEvent("MAIL_SHOW");
Zerotorescue@0 222
Zerotorescue@0 223 self.btnConfig:Hide();
Zerotorescue@0 224
Zerotorescue@0 225 enabled = false;
Zerotorescue@0 226 MailOpener:Stop();
Zerotorescue@0 227 end
Zerotorescue@0 228
Zerotorescue@0 229 -- We must disable Quick Auction's auto mail (if set up that way in the settings) before opening the mailbox or it will instantly start sending stuff
Zerotorescue@0 230 function MailOpener:PLAYER_ENTERING_WORLD()
Zerotorescue@0 231 self:UnregisterEvent("PLAYER_ENTERING_WORLD");
Zerotorescue@0 232
Zerotorescue@0 233 self:ToggleQAStatus();
Zerotorescue@0 234 end
Zerotorescue@0 235
Zerotorescue@0 236 -- Fired when the mailbox is opened
Zerotorescue@0 237 function MailOpener:MAIL_SHOW()
Zerotorescue@0 238 -- To stop the timer when the mailbox is closed
Zerotorescue@0 239 self:RegisterEvent("MAIL_CLOSED", "Stop");
Zerotorescue@0 240 self:RegisterEvent("PLAYER_LEAVING_WORLD", "Stop");
Zerotorescue@0 241
Zerotorescue@0 242 -- To set the timer for when to refresh again
Zerotorescue@0 243 self:RegisterEvent("MAIL_INBOX_UPDATE");
Zerotorescue@0 244
Zerotorescue@0 245 -- We need to know when opening has completed
Zerotorescue@0 246 self:RegisterMessage("MO_OPEN_COMPLETE");
Zerotorescue@0 247
Zerotorescue@0 248 self:Debug("defaultStatus:" .. self.db.profile.general.defaultStatus);
Zerotorescue@0 249 -- Change the mail opening status according to our settings
Zerotorescue@0 250 if self.db.profile.general.defaultStatus == "_enabled" then
Zerotorescue@0 251 enabled = true;
Zerotorescue@0 252 else
Zerotorescue@0 253 enabled = false;
Zerotorescue@0 254 end
Zerotorescue@0 255 self.cbOpenAll:SetChecked(enabled);
Zerotorescue@0 256
Zerotorescue@0 257 self:ToggleQAStatus();
Zerotorescue@0 258
Zerotorescue@0 259 -- Hide the InboxTooMuchMail warning to allow room for our mail remaining info line
Zerotorescue@0 260 InboxTooMuchMail:Hide()
Zerotorescue@0 261 InboxTooMuchMail.Show = function() end
Zerotorescue@0 262
Zerotorescue@0 263 if self.QuickAuctionsEnabled then
Zerotorescue@0 264 -- Go through all children of the mail frame to find the post button
Zerotorescue@0 265 local kids = { InboxFrame:GetChildren() };
Zerotorescue@0 266
Zerotorescue@0 267 for _, child in ipairs(kids) do
Zerotorescue@0 268 if child then
Zerotorescue@0 269 local width = floor( child:GetWidth() + .5 );
Zerotorescue@0 270 local height = floor( child:GetHeight() + .5 );
Zerotorescue@0 271
Zerotorescue@0 272 -- The open all button has a static width and height
Zerotorescue@0 273 if width == 130 and height == 24 then
Zerotorescue@0 274 child:Hide();
Zerotorescue@0 275 break;
Zerotorescue@0 276 end
Zerotorescue@0 277 end
Zerotorescue@0 278 end
Zerotorescue@0 279 end
Zerotorescue@0 280
Zerotorescue@0 281 if self.db.profile.notifications.welcome then
Zerotorescue@0 282 -- Welcome notification
Zerotorescue@0 283 local _, c = UnitClass("player");
Zerotorescue@0 284 c = RAID_CLASS_COLORS[c];
Zerotorescue@0 285 c = string.format("|cff%02x%02x%02x", c.r * 255 + 0.5, c.g * 255 + 0.5, c.b * 255 + 0.5);
Zerotorescue@0 286
Zerotorescue@0 287 print("|cff15ff00Mail Opener|r: Welcome back "..c..UnitName("player").."|r. Requesting new mail from the local Postal Service, your mail will automatically be opened when it becomes available.");
Zerotorescue@0 288 end
Zerotorescue@0 289
Zerotorescue@0 290 mailboxEmptySoundPlayed = nil;
Zerotorescue@0 291
Zerotorescue@0 292 self:Recheck();
Zerotorescue@0 293
Zerotorescue@0 294 if self.db.profile.general.continueOpening then
Zerotorescue@0 295 self:ScheduleOpen(true);
Zerotorescue@0 296 end
Zerotorescue@0 297 end
Zerotorescue@0 298
Zerotorescue@0 299 -- Fired after a successful server sync
Zerotorescue@0 300 -- Fired when mail is deleted (which happens after taking all attachments from a mail sent by the game)
Zerotorescue@0 301 function MailOpener:MAIL_INBOX_UPDATE()
Zerotorescue@0 302 local current, total = GetInboxNumItems();
Zerotorescue@0 303
Zerotorescue@0 304 local tempLastAmount = lastAmount;
Zerotorescue@0 305 lastAmount = current;
Zerotorescue@0 306
Zerotorescue@0 307 if current ~= tempLastAmount then
Zerotorescue@0 308 self:Debug("MAIL_INBOX_UPDATE - lastAmount:" .. tempLastAmount .. " - current:" .. current);
Zerotorescue@0 309 end
Zerotorescue@0 310
Zerotorescue@0 311 if current > tempLastAmount then
Zerotorescue@0 312 -- New messages arrived in our mailbox, so this was a refresh, so set a timer
Zerotorescue@0 313
Zerotorescue@0 314 -- Yell that we successfully synced with the server
Zerotorescue@0 315 self:SendMessage("MO_SERVER_SYNCED");
Zerotorescue@0 316
Zerotorescue@0 317 -- This list is fresh
Zerotorescue@0 318 freshList = true;
Zerotorescue@0 319 mailboxEmptySoundPlayed = nil;
Zerotorescue@0 320
Zerotorescue@0 321 -- Stop previous timer
Zerotorescue@0 322 self:CancelTimer(self.tmrRecheck, true);
Zerotorescue@0 323 -- More will arrive in 60 seconds
Zerotorescue@0 324 self.tmrRecheck = self:ScheduleTimer(function()
Zerotorescue@0 325 self:Debug("tmrRecheck 61 finished");
Zerotorescue@0 326
Zerotorescue@0 327 -- We can get a fresh list now, so query the server
Zerotorescue@0 328 freshList = false;
Zerotorescue@0 329
Zerotorescue@0 330 -- Look for mail
Zerotorescue@0 331 self:Recheck();
Zerotorescue@0 332 end, 61);
Zerotorescue@0 333 self:Debug("tmrRecheck 61");
Zerotorescue@0 334
Zerotorescue@0 335 if not IsShiftKeyDown() then
Zerotorescue@0 336 -- Allow overriding of mailopening with the shift key
Zerotorescue@0 337
Zerotorescue@0 338 -- Open the current mail
Zerotorescue@0 339 self:ScheduleOpen(false);
Zerotorescue@0 340 end
Zerotorescue@2 341 elseif current < tempLastAmount then
Zerotorescue@2 342 -- We lost a mail
Zerotorescue@2 343
Zerotorescue@2 344 -- Yell that we successfully opened/removed a mail
Zerotorescue@2 345 self:SendMessage("MO_MAIL_DELETED");
Zerotorescue@0 346 elseif (current == 50 and tempLastAmount == 50) then
Zerotorescue@0 347 if not IsShiftKeyDown() then
Zerotorescue@0 348 -- Allow overriding of mailopening with the shift key
Zerotorescue@0 349
Zerotorescue@0 350 -- Open the current mail
Zerotorescue@0 351 self:ScheduleOpen(false);
Zerotorescue@0 352 end
Zerotorescue@0 353 end
Zerotorescue@0 354
Zerotorescue@0 355 tempLastAmount = current;
Zerotorescue@0 356 end
Zerotorescue@0 357
Zerotorescue@0 358 function MailOpener:ScheduleOpen(continued)
Zerotorescue@0 359 if lastAmount > 0 then
Zerotorescue@0 360 local waitTime;
Zerotorescue@0 361 if continued then
Zerotorescue@0 362 waitTime = self.db.profile.general.waitTime;
Zerotorescue@0 363 else
Zerotorescue@0 364 -- Even though this is not a continuation and should be instant, we set a .5 second timer to prevent multiple calls of the OpenNow function
Zerotorescue@0 365 waitTime = self.db.profile.general.initialDelay;
Zerotorescue@0 366 end
Zerotorescue@0 367
Zerotorescue@0 368 -- Stop previous timer
Zerotorescue@0 369 self:CancelTimer(self.tmrOpenNow, true);
Zerotorescue@0 370 -- Schedule the next open
Zerotorescue@0 371 self.tmrOpenNow = self:ScheduleTimer("OpenNow", waitTime);
Zerotorescue@0 372 end
Zerotorescue@0 373 end
Zerotorescue@0 374
Zerotorescue@0 375 function MailOpener:OpenNow()
Zerotorescue@0 376 self:Debug("OpenNow (" .. ((opening and "1") or "0") .. ")");
Zerotorescue@0 377 if not opening and MailFrame:IsVisible() then
Zerotorescue@0 378 self:Debug("OpenNow");
Zerotorescue@0 379
Zerotorescue@0 380 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that
Zerotorescue@0 381 local BeanCounterActive = not InboxCloseButton:IsVisible();
Zerotorescue@0 382
Zerotorescue@0 383 if not BeanCounterActive then
Zerotorescue@0 384 -- BeanCounter is INACTIVE
Zerotorescue@0 385
Zerotorescue@0 386 self:CancelTimer(self.tmrTryAgain, true); -- Insurance
Zerotorescue@0 387
Zerotorescue@0 388 if QuickAuctionsAutoMail then
Zerotorescue@0 389 -- Remember the last known quick auctions status
Zerotorescue@0 390 lastQuickAuctionsStatus = QuickAuctionsAutoMail:GetChecked();
Zerotorescue@0 391 end
Zerotorescue@0 392 if self.db.profile.general.autoDisableQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and QuickAuctionsAutoMail:GetChecked() then
Zerotorescue@0 393 -- If auto disable "QA Auto mail" is enabled and QA's auto mail is currently toggled on, turn it off
Zerotorescue@0 394 -- We need to do this with a :click to trigger the right events
Zerotorescue@0 395
Zerotorescue@0 396 self:Debug("Turning automail |cffff0000off|r.");
Zerotorescue@0 397
Zerotorescue@0 398 QuickAuctionsAutoMail:Click();
Zerotorescue@0 399 end
Zerotorescue@0 400
Zerotorescue@0 401 opening = true;
Zerotorescue@0 402
Zerotorescue@0 403 self:Debug("MO_OPEN_MAIL");
Zerotorescue@0 404
Zerotorescue@0 405 -- Summon the mail opening gods
Zerotorescue@0 406 self:SendMessage("MO_OPEN_MAIL");
Zerotorescue@0 407 else
Zerotorescue@0 408 -- BeanCounter is ACTIVE
Zerotorescue@0 409 self:Debug("BeanCounter active, waiting .5 seconds...");
Zerotorescue@0 410
Zerotorescue@0 411 self:CancelTimer(self.tmrTryAgain, true); -- Insurance
Zerotorescue@0 412 -- Wait with summoning until BeanCounter is done, try again every 0.5 seconds
Zerotorescue@0 413 self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5);
Zerotorescue@0 414 end
Zerotorescue@0 415 end
Zerotorescue@0 416 end
Zerotorescue@0 417
Zerotorescue@0 418 function MailOpener:MO_OPEN_COMPLETE()
Zerotorescue@0 419 opening = false;
Zerotorescue@1 420
Zerotorescue@1 421 -- Try a recheck
Zerotorescue@1 422 self:Recheck();
Zerotorescue@1 423
Zerotorescue@0 424 local current, total = GetInboxNumItems();
Zerotorescue@0 425
Zerotorescue@0 426 if (total - current) == 0 then
Zerotorescue@0 427 -- Play the sound
Zerotorescue@0 428 if self.db.profile.notifications.mailboxEmptySound and (not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce or not mailboxEmptySoundPlayed) then
Zerotorescue@0 429 PlaySoundFile(self.db.profile.notifications.mailboxEmptySoundFile);
Zerotorescue@0 430 mailboxEmptySoundPlayed = true;
Zerotorescue@0 431 end
Zerotorescue@0 432 end
Zerotorescue@0 433
Zerotorescue@0 434 if self.db.profile.general.autoReenableQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and not QuickAuctionsAutoMail:GetChecked() then
Zerotorescue@0 435 -- If auto re-enable "QA Auto mail" is enabled and QA's auto mail is currently toggled OFF, turn it on
Zerotorescue@0 436 -- We need to do this with a :click to trigger the right events
Zerotorescue@0 437
Zerotorescue@0 438 self:Debug("Turning automail |cff00ff00on|r.");
Zerotorescue@0 439
Zerotorescue@0 440 QuickAuctionsAutoMail:Click();
Zerotorescue@0 441 elseif self.db.profile.general.autoSetBackQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and lastQuickAuctionsStatus ~= QuickAuctionsAutoMail:GetChecked() then
Zerotorescue@0 442 -- If auto set back "QA Auto mail" is enabled and QA's auto mail is currently not the same as it was before starting, toggle it
Zerotorescue@0 443 -- We need to do this with a :click to trigger the right events
Zerotorescue@0 444
Zerotorescue@0 445 if lastQuickAuctionsStatus then
Zerotorescue@0 446 self:Debug("Turning automail |cff00ff00on|r.");
Zerotorescue@0 447 else
Zerotorescue@0 448 self:Debug("Turning automail |cffff0000off|r.");
Zerotorescue@0 449 end
Zerotorescue@0 450
Zerotorescue@0 451 QuickAuctionsAutoMail:Click();
Zerotorescue@0 452 end
Zerotorescue@0 453
Zerotorescue@0 454 if self.db.profile.general.continueOpening then
Zerotorescue@0 455 self:ScheduleOpen(true);
Zerotorescue@0 456 end
Zerotorescue@0 457 end
Zerotorescue@0 458
Zerotorescue@0 459 -- Run another CheckInbox
Zerotorescue@0 460 function MailOpener:Recheck()
Zerotorescue@0 461 self:Debug("|cffffff00Recheck|r");
Zerotorescue@0 462
Zerotorescue@0 463 -- Freshlist prevents this from being run too often
Zerotorescue@0 464 -- It is set to true after a server sync
Zerotorescue@0 465 -- and set to false 61 seconds afterwards with a recheck called instantly after it
Zerotorescue@0 466 if not freshList and MailFrame:IsVisible() then
Zerotorescue@0 467 self:Debug("|cff00ff00Recheck|r");
Zerotorescue@0 468
Zerotorescue@0 469 -- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed
Zerotorescue@0 470
Zerotorescue@0 471 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that
Zerotorescue@0 472 local BeanCounterActive = not InboxCloseButton:IsVisible();
Zerotorescue@0 473
Zerotorescue@0 474 if not BeanCounterActive then
Zerotorescue@0 475 -- Query the server
Zerotorescue@0 476 CheckInbox();
Zerotorescue@0 477 end
Zerotorescue@0 478
Zerotorescue@0 479 -- Stop previous timer
Zerotorescue@0 480 self:CancelTimer(self.tmrRecheck, true);
Zerotorescue@0 481 -- Keep trying until it works
Zerotorescue@0 482 self.tmrRecheck = self:ScheduleTimer("Recheck", 2);
Zerotorescue@0 483
Zerotorescue@0 484 self:Debug("tmrRecheck 2");
Zerotorescue@0 485 end
Zerotorescue@0 486 end
Zerotorescue@0 487
Zerotorescue@0 488 -- Stop checking for new mail and unregister the events we needed
Zerotorescue@0 489 function MailOpener:Stop()
Zerotorescue@0 490 if self.db.profile.notifications.bye then
Zerotorescue@0 491 print("|cff15ff00Mail Opener|r: Have a nice day. :)");
Zerotorescue@0 492 end
Zerotorescue@0 493
Zerotorescue@0 494 opening = false;
Zerotorescue@0 495
Zerotorescue@0 496 -- We won't need this anymore
Zerotorescue@0 497 self:UnregisterEvent("MAIL_CLOSED");
Zerotorescue@0 498 self:UnregisterEvent("PLAYER_LEAVING_WORLD");
Zerotorescue@0 499 self:UnregisterEvent("MAIL_INBOX_UPDATE");
Zerotorescue@0 500
Zerotorescue@0 501 -- Messages
Zerotorescue@0 502 self:UnregisterMessage("MO_OPEN_COMPLETE");
Zerotorescue@0 503
Zerotorescue@0 504 -- Timers
Zerotorescue@0 505 self:CancelTimer(self.tmrTryAgain, true);
Zerotorescue@0 506 self:CancelTimer(self.tmrOpenNow, true);
Zerotorescue@0 507
Zerotorescue@0 508 -- If we wait with disabling QA automail until MAIL_SHOW, QA will beat us to it and already start sending stuff
Zerotorescue@0 509 self:ToggleQAStatus();
Zerotorescue@0 510 end
Zerotorescue@0 511
Zerotorescue@0 512 function MailOpener:Debug(t)
Zerotorescue@0 513 if not self.debugChannel and self.debugChannel ~= false then
Zerotorescue@0 514 -- We want to check just once, so if you add a debug channel later just do a /reload (registering an event for this is wasted resources)
Zerotorescue@0 515 self.debugChannel = false;
Zerotorescue@0 516
Zerotorescue@0 517 for i = 1, NUM_CHAT_WINDOWS do
Zerotorescue@0 518 local name = GetChatWindowInfo(i);
Zerotorescue@0 519
Zerotorescue@0 520 if name:upper() == "DEBUG" then
Zerotorescue@0 521 self.debugChannel = _G["ChatFrame" .. i];
Zerotorescue@0 522 end
Zerotorescue@0 523 end
Zerotorescue@0 524 end
Zerotorescue@0 525
Zerotorescue@0 526 if self.debugChannel then
Zerotorescue@0 527 self.debugChannel:AddMessage(t);
Zerotorescue@0 528 end
Zerotorescue@0 529 end
Zerotorescue@0 530
Zerotorescue@0 531 -- Enable our config module if it's disabled and make a reference to it
Zerotorescue@0 532 function MailOpener:EnableConfigModule()
Zerotorescue@0 533 if not MailOpenerConfig then
Zerotorescue@0 534 MailOpenerConfig = self:GetModule("Config");
Zerotorescue@0 535 MailOpenerConfig:Enable();
Zerotorescue@0 536 end
Zerotorescue@0 537 end
Zerotorescue@0 538
Zerotorescue@0 539 -- Toggle Postal's opening modules on or off
Zerotorescue@0 540 function MailOpener:TogglePostalModule(name, status)
Zerotorescue@0 541 if MailOpener.PostalEnabled and Postal then
Zerotorescue@0 542 -- Postal must be enabled
Zerotorescue@0 543
Zerotorescue@0 544 -- Remember the setting in Postal
Zerotorescue@0 545 Postal.db.profile.ModuleEnabledState[name] = status;
Zerotorescue@0 546
Zerotorescue@0 547 -- Toggle module
Zerotorescue@0 548 if status then
Zerotorescue@0 549 Postal:GetModule(name):Enable();
Zerotorescue@0 550 else
Zerotorescue@0 551 Postal:GetModule(name):Disable();
Zerotorescue@0 552 end
Zerotorescue@0 553 end
Zerotorescue@0 554 end
Zerotorescue@0 555
Zerotorescue@0 556 -- Change Quick Auction's auto mail status based on our prefered settings
Zerotorescue@0 557 function MailOpener:ToggleQAStatus()
Zerotorescue@0 558 self:Debug("defaultQAStatus:" .. self.db.profile.general.defaultQAStatus);
Zerotorescue@0 559
Zerotorescue@0 560 if self.QuickAuctionsEnabled and self.db.profile.general.defaultQAStatus ~= "__remember" and QuickAuctionsAutoMail then
Zerotorescue@0 561 if self.db.profile.general.defaultQAStatus == "_enabled" and not QuickAuctionsAutoMail:GetChecked() then
Zerotorescue@0 562 self:Debug("Turning automail |cff00ff00on|r.");
Zerotorescue@0 563
Zerotorescue@0 564 QuickAuctionsAutoMail:Click();
Zerotorescue@0 565 elseif self.db.profile.general.defaultQAStatus == "disabled" and QuickAuctionsAutoMail:GetChecked() then
Zerotorescue@0 566 self:Debug("Turning automail |cffff0000off|r.");
Zerotorescue@0 567
Zerotorescue@0 568 QuickAuctionsAutoMail:Click();
Zerotorescue@0 569 end
Zerotorescue@0 570 end
Zerotorescue@0 571 end
Zerotorescue@0 572
Zerotorescue@0 573 function MailOpener:FormatMoney(copper)
Zerotorescue@0 574 local gold = floor( copper / 10000 );
Zerotorescue@0 575 local silver = floor( ( copper - ( gold * 10000 ) ) / 100 );
Zerotorescue@0 576 local copper = mod(copper, 100);
Zerotorescue@0 577
Zerotorescue@0 578 if gold > 0 then
Zerotorescue@0 579 return format(GOLD_AMOUNT_TEXTURE .. " " .. SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, gold, 0, 0, silver, 0, 0, copper, 0, 0);
Zerotorescue@0 580 elseif silver > 0 then
Zerotorescue@0 581 return format(SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, silver, 0, 0, copper, 0, 0);
Zerotorescue@0 582 else
Zerotorescue@0 583 return format(COPPER_AMOUNT_TEXTURE, copper, 0, 0);
Zerotorescue@0 584 end
Zerotorescue@0 585 end
Zerotorescue@0 586
Zerotorescue@0 587 StaticPopupDialogs["MailOpenerCopyWindow"] = {
Zerotorescue@0 588 text = "Please CTRL-C to copy.",
Zerotorescue@0 589 button2 = CLOSE,
Zerotorescue@0 590 hasEditBox = 1,
Zerotorescue@0 591 hasWideEditBox = 1,
Zerotorescue@0 592 OnShow = function()
Zerotorescue@0 593 local editBox = _G[this:GetName().."WideEditBox"];
Zerotorescue@0 594 if editBox and MailOpener.currentPopupContents then
Zerotorescue@0 595 editBox:SetText(MailOpener.currentPopupContents);
Zerotorescue@0 596 editBox:SetFocus();
Zerotorescue@0 597 editBox:HighlightText(0);
Zerotorescue@0 598 end
Zerotorescue@0 599
Zerotorescue@0 600 -- Position the close button in the middle
Zerotorescue@0 601 local button = _G[this:GetName().."Button2"];
Zerotorescue@0 602 if button then
Zerotorescue@0 603 -- Remove previous know position
Zerotorescue@0 604 button:ClearAllPoints();
Zerotorescue@0 605 button:SetWidth(200);
Zerotorescue@0 606 -- Reposition in the center
Zerotorescue@0 607 button:SetPoint("CENTER", editBox, "CENTER", 0, -30);
Zerotorescue@0 608 end
Zerotorescue@0 609 end,
Zerotorescue@0 610 EditBoxOnEscapePressed = function()
Zerotorescue@0 611 this:GetParent():Hide();
Zerotorescue@0 612 end,
Zerotorescue@0 613 timeout = 0,
Zerotorescue@0 614 whileDead = 1,
Zerotorescue@0 615 hideOnEscape = 1,
Zerotorescue@0 616 maxLetters = 1024,
Zerotorescue@1 617 };
Zerotorescue@1 618
Zerotorescue@1 619 -- The below either has to be removed or changed when releasing
Zerotorescue@0 620
Zerotorescue@0 621 function MailOpener:ShowBetaPopup()
Zerotorescue@0 622 function TableDump(key, val, jumps)
Zerotorescue@0 623 local cache = "";
Zerotorescue@0 624
Zerotorescue@0 625 if not jumps then
Zerotorescue@0 626 jumps = 0;
Zerotorescue@0 627 end
Zerotorescue@0 628
Zerotorescue@0 629 local spacer = "";
Zerotorescue@0 630 if jumps > 0 then
Zerotorescue@0 631 for i = 1, jumps do
Zerotorescue@0 632 spacer = spacer .. " ";
Zerotorescue@0 633 end
Zerotorescue@0 634 end
Zerotorescue@0 635
Zerotorescue@0 636 if type(val) == "table" then
Zerotorescue@0 637 cache = cache .. spacer .. key .. " = {\n";
Zerotorescue@0 638 foreach(val, function(k, v)
Zerotorescue@0 639 cache = cache .. TableDump(k, v, (jumps + 1));
Zerotorescue@0 640 end);
Zerotorescue@0 641 cache = cache .. spacer .. "},\n";
Zerotorescue@0 642 else
Zerotorescue@0 643 cache = cache .. spacer .. key .. " = " .. tostring(val) .. ",\n";
Zerotorescue@0 644 end
Zerotorescue@0 645
Zerotorescue@0 646 return cache;
Zerotorescue@0 647 end
Zerotorescue@0 648
Zerotorescue@0 649 local cache = "";
Zerotorescue@0 650 foreach(MailOpener.db.profile, function(k, v)
Zerotorescue@0 651 cache = cache .. TableDump(k, v, 0);
Zerotorescue@0 652 end);
Zerotorescue@0 653
Zerotorescue@0 654 local AceGUI = LibStub("AceGUI-3.0");
Zerotorescue@0 655 local frame = AceGUI:Create("Frame");
Zerotorescue@0 656 frame:SetTitle("Mail Opener ALPHA");
Zerotorescue@0 657 frame:SetWidth(575);
Zerotorescue@0 658 frame:SetHeight(375);
Zerotorescue@0 659
Zerotorescue@0 660 -- Add a normal description label
Zerotorescue@0 661 local desc = AceGUI:Create("Label");
Zerotorescue@0 662 desc:SetText("|cff00ff00After you have been using Mail Opener for a while and configured it just as you want it to be, please report your favorite settings by copying the text below at either of the below links. Thanks in advance!|r\n\n");
Zerotorescue@0 663 desc:SetFont(GameFontHighlightSmall:GetFont(), 13);
Zerotorescue@0 664 desc:SetFullWidth(true);
Zerotorescue@0 665 frame:AddChild(desc);
Zerotorescue@0 666
Zerotorescue@0 667 -- Add a MultiLineEditBox
Zerotorescue@0 668 local settingsMLEEB = AceGUI:Create("MultiLineEditBox");
Zerotorescue@0 669 settingsMLEEB:SetText(cache);
Zerotorescue@0 670 settingsMLEEB:SetLabel("Hit CTRL-A to select all and CTRL-C to copy the text. You can then use CTRL-V to paste.");
Zerotorescue@0 671 settingsMLEEB:SetFullWidth(true);
Zerotorescue@0 672 settingsMLEEB:SetNumLines(8);
Zerotorescue@0 673 settingsMLEEB:DisableButton(true);
Zerotorescue@0 674 settingsMLEEB:SetCallback("OnTextChanged", function()
Zerotorescue@0 675 settingsMLEEB:SetText(cache);
Zerotorescue@0 676 end);
Zerotorescue@0 677 frame:AddChild(settingsMLEEB);
Zerotorescue@0 678
Zerotorescue@0 679 -- Empty line between the two links
Zerotorescue@0 680 local label = AceGUI:Create("Label");
Zerotorescue@0 681 label:SetText("Please post the above text at either of these two links:");
Zerotorescue@0 682 label:SetFullWidth(true);
Zerotorescue@0 683 frame:AddChild(label);
Zerotorescue@0 684
Zerotorescue@0 685 local desc1 = AceGUI:Create("InteractiveLabel");
Zerotorescue@0 686 desc1:SetText("|cff00bbbb[http://wow.curseforge.com/addons/mailopener/create-ticket/]|r");
Zerotorescue@0 687 desc1:SetFont(GameFontHighlightSmall:GetFont(), 13);
Zerotorescue@0 688 desc1:SetFullWidth(true);
Zerotorescue@0 689 desc1:SetCallback("OnClick", function()
Zerotorescue@0 690 MailOpener.currentPopupContents = "http://wow.curseforge.com/addons/mailopener/create-ticket/";
Zerotorescue@0 691
Zerotorescue@0 692 StaticPopup_Show("MailOpenerCopyWindow");
Zerotorescue@0 693 end);
Zerotorescue@0 694 desc1:SetCallback("OnEnter", function()
Zerotorescue@0 695 frame:SetStatusText("Click to copy this URL.");
Zerotorescue@0 696 end);
Zerotorescue@0 697 desc1:SetCallback("OnLeave", function()
Zerotorescue@0 698 frame:SetStatusText("");
Zerotorescue@0 699 end);
Zerotorescue@0 700 frame:AddChild(desc1);
Zerotorescue@0 701
Zerotorescue@0 702 -- Empty line between the two links
Zerotorescue@0 703 local spacer = AceGUI:Create("Label");
Zerotorescue@0 704 spacer:SetText(" ");
Zerotorescue@0 705 frame:AddChild(spacer);
Zerotorescue@0 706
Zerotorescue@0 707 local desc2 = AceGUI:Create("InteractiveLabel");
Zerotorescue@0 708 desc2:SetText("|cff00bbbb[http://20kleveling.com/JMTCforum/posting.php?mode=reply&f=9&t=1403]|r");
Zerotorescue@0 709 desc2:SetFont(GameFontHighlightSmall:GetFont(), 13);
Zerotorescue@0 710 desc2:SetFullWidth(true);
Zerotorescue@0 711 desc2:SetCallback("OnClick", function()
Zerotorescue@0 712 MailOpener.currentPopupContents = "http://20kleveling.com/JMTCforum/posting.php?mode=reply&f=9&t=1403";
Zerotorescue@0 713
Zerotorescue@0 714 StaticPopup_Show("MailOpenerCopyWindow");
Zerotorescue@0 715 end);
Zerotorescue@0 716 desc2:SetCallback("OnEnter", function()
Zerotorescue@0 717 frame:SetStatusText("Click to copy this URL.");
Zerotorescue@0 718 end);
Zerotorescue@0 719 desc2:SetCallback("OnLeave", function()
Zerotorescue@0 720 frame:SetStatusText("");
Zerotorescue@0 721 end);
Zerotorescue@0 722 frame:AddChild(desc2);
Zerotorescue@0 723
Zerotorescue@0 724 -- Empty line between the two links
Zerotorescue@0 725 local label = AceGUI:Create("Label");
Zerotorescue@0 726 label:SetText("\n\nps. You can always view this window again at a later time by clicking the \"Config\" button in the mail frame.\nps2. The information above is completely Mail Opener related. It will be used to determine the best default settings.");
Zerotorescue@0 727 label:SetFullWidth(true);
Zerotorescue@0 728 frame:AddChild(label);
Zerotorescue@0 729 end