Mercurial > wow > mailopener
comparison Core.lua @ 8:1b2d819b4fa8
Now using the global MailAddonBusy to indicate MailOpener is busy, read comments in Core.lua for more info.
Default status is now ?enabled without automatic mail opening? to let first time users look around before MailOpener messes up their heads. A StaticPopupDialog will be added later to ask if they want to auto-enable.
When ?enabled without automatic mail opening? is on and you toggle the mail opening checkbox on, mail opening will automatically start.
| author | Zerotorescue |
|---|---|
| date | Thu, 09 Sep 2010 10:53:19 +0200 |
| parents | 7249f9f1205a |
| children | fb952805d8b7 |
comparison
equal
deleted
inserted
replaced
| 7:7249f9f1205a | 8:1b2d819b4fa8 |
|---|---|
| 1 -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("MailOpener") | 1 -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("MailOpener") |
| 2 local MailOpener = LibStub("AceAddon-3.0"):NewAddon("MailOpener", "AceEvent-3.0", "AceTimer-3.0"); | 2 local MailOpener = LibStub("AceAddon-3.0"):NewAddon("MailOpener", "AceEvent-3.0", "AceTimer-3.0"); |
| 3 | 3 |
| 4 -- You can check if MailOpener is busy with LibStub("AceAddon-3.0"):GetAddon("MailOpener").busy (true or false/nil) | 4 -- You can check if MailOpener is busy with the global MailAddonBusy (if not MailAddonBusy then ...do something... end) |
| 5 -- MailAddonBusy will be nil when nothing is happening or filled with the addon name when MO is working | |
| 6 -- Another addon can use this variable to indicate they're working too, MailOpener will then wait for that to finish | |
| 5 | 7 |
| 6 local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed; | 8 local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed; |
| 7 | 9 |
| 8 function MailOpener:OnInitialize() | 10 function MailOpener:OnInitialize() |
| 9 local defaults = { | 11 local defaults = { |
| 10 --BETA:global = { | |
| 11 --BETA: uses = 0; | |
| 12 --BETA:}, | |
| 13 profile = { | 12 profile = { |
| 13 uses = 0, | |
| 14 general = { | 14 general = { |
| 15 defaultStatus = "_enabled", | 15 defaultStatus = "disabled", -- addon enabled, but mail opening not auto on |
| 16 defaultQAStatus = "__remember", | 16 defaultQAStatus = "__remember", |
| 17 continueOpeningStackableItems = false, | 17 continueOpeningStackableItems = false, |
| 18 autoDisableQAAutoMail = true, | 18 autoDisableQAAutoMail = true, |
| 19 autoReenableQAAutoMail = false, | 19 autoReenableQAAutoMail = false, |
| 20 autoSetBackQAAutoMail = true, | 20 autoSetBackQAAutoMail = true, |
| 139 | 139 |
| 140 if self:GetChecked() then | 140 if self:GetChecked() then |
| 141 print("|cff15ff00Mail Opener|r: |cff00ff00Enabling|r automatic opening of mail."); | 141 print("|cff15ff00Mail Opener|r: |cff00ff00Enabling|r automatic opening of mail."); |
| 142 | 142 |
| 143 AutoOpenMail = true; | 143 AutoOpenMail = true; |
| 144 MailOpener:ScheduleOpen(false); | |
| 144 else | 145 else |
| 145 print("|cff15ff00Mail Opener|r: |cffff0000Disabling|r automatic opening of mail."); | 146 print("|cff15ff00Mail Opener|r: |cffff0000Disabling|r automatic opening of mail."); |
| 146 | 147 |
| 147 AutoOpenMail = false; | 148 AutoOpenMail = false; |
| 148 end | 149 end |
| 178 button:SetScript("OnClick", function() | 179 button:SetScript("OnClick", function() |
| 179 MailOpener:EnableConfigModule(); | 180 MailOpener:EnableConfigModule(); |
| 180 | 181 |
| 181 MailOpenerConfig:Show(); | 182 MailOpenerConfig:Show(); |
| 182 | 183 |
| 183 --BETA:if MailOpener.db.global.uses >= 15 then | 184 --BETA:if MailOpener.db.profile.uses >= 15 then |
| 184 --BETA: MailOpener:ShowBetaPopup(); | 185 --BETA: MailOpener:ShowBetaPopup(); |
| 185 --BETA:end | 186 --BETA:end |
| 186 end); | 187 end); |
| 187 | 188 |
| 188 self.btnConfig = button; | 189 self.btnConfig = button; |
| 233 | 234 |
| 234 -- Reset variables | 235 -- Reset variables |
| 235 lastAmount = 0; | 236 lastAmount = 0; |
| 236 self.debugChannel = nil; | 237 self.debugChannel = nil; |
| 237 | 238 |
| 238 --BETA:self.db.global.uses = ( self.db.global.uses + 1 ); | 239 --BETA:if (self.db.profile.uses % 15) == 0 then |
| 239 | |
| 240 --BETA:if (self.db.global.uses % 15) == 0 then | |
| 241 --BETA: -- Automatically show once every 15 uses | 240 --BETA: -- Automatically show once every 15 uses |
| 242 --BETA: self:ShowBetaPopup(); | 241 --BETA: self:ShowBetaPopup(); |
| 243 --BETA:end | 242 --BETA:end |
| 244 | 243 |
| 245 -- If we were toggling this addon on while the mailbox is opened we must register all events again | 244 -- If we were toggling this addon on while the mailbox is opened we must register all events again |
| 272 -- To set the timer for when to refresh again | 271 -- To set the timer for when to refresh again |
| 273 self:RegisterEvent("MAIL_INBOX_UPDATE"); | 272 self:RegisterEvent("MAIL_INBOX_UPDATE"); |
| 274 | 273 |
| 275 -- We need to know when opening has completed | 274 -- We need to know when opening has completed |
| 276 self:RegisterMessage("MO_OPEN_COMPLETE"); | 275 self:RegisterMessage("MO_OPEN_COMPLETE"); |
| 276 | |
| 277 if self.db.profile.uses == 0 then | |
| 278 --TODO:statispopupdialog | |
| 279 end | |
| 280 | |
| 281 self.db.profile.uses = ( self.db.profile.uses + 1 ); | |
| 277 | 282 |
| 278 self:Debug("defaultStatus:" .. self.db.profile.general.defaultStatus); | 283 self:Debug("defaultStatus:" .. self.db.profile.general.defaultStatus); |
| 279 -- Change the mail opening status according to our settings | 284 -- Change the mail opening status according to our settings |
| 280 if self.db.profile.general.defaultStatus == "_enabled" then | 285 if self.db.profile.general.defaultStatus == "_enabled" then |
| 281 AutoOpenMail = true; | 286 AutoOpenMail = true; |
| 297 -- Hide the InboxTooMuchMail warning to allow room for our mail remaining info line | 302 -- Hide the InboxTooMuchMail warning to allow room for our mail remaining info line |
| 298 InboxTooMuchMail:Hide() | 303 InboxTooMuchMail:Hide() |
| 299 InboxTooMuchMail.Show = function() end | 304 InboxTooMuchMail.Show = function() end |
| 300 | 305 |
| 301 if self.QuickAuctionsEnabled then | 306 if self.QuickAuctionsEnabled then |
| 302 local QAMail = LibStub("AceAddon-3.0"):GetAddon("QuickAuctions"):GetModule("Mail"); | 307 local QAMail = LibStub("AceAddon-3.0"):GetAddon("QuickAuctions", true):GetModule("Mail", true); |
| 303 | 308 |
| 304 -- Hide the open all button | 309 if QAMail then |
| 305 QAMail.massOpening:Hide(); | 310 -- Hide the open all button |
| 306 -- Hide the x mail remaining text | 311 QAMail.massOpening:Hide(); |
| 307 QAMail.totalMail:Hide(); | 312 -- Hide the x mail remaining text |
| 313 QAMail.totalMail:Hide(); | |
| 314 end | |
| 308 end | 315 end |
| 309 | 316 |
| 310 if self.db.profile.notifications.welcome then | 317 if self.db.profile.notifications.welcome then |
| 311 -- Welcome notification | 318 -- Welcome notification |
| 312 local _, c = UnitClass("player"); | 319 local _, c = UnitClass("player"); |
| 416 self.tmrOpenNow = self:ScheduleTimer("OpenNow", waitTime); | 423 self.tmrOpenNow = self:ScheduleTimer("OpenNow", waitTime); |
| 417 end | 424 end |
| 418 end | 425 end |
| 419 | 426 |
| 420 function MailOpener:OpenNow() | 427 function MailOpener:OpenNow() |
| 421 self:Debug("OpenNow (" .. ((self.busy and "1") or "0") .. ")"); | 428 self:Debug("OpenNow (" .. ((MailAddonBusy and "1") or "0") .. ")"); |
| 422 if not self.busy and MailFrame:IsVisible() and AutoOpenMail then | 429 if MailFrame:IsVisible() and AutoOpenMail then |
| 423 self:Debug("OpenNow"); | 430 self:Debug("OpenNow"); |
| 424 | 431 |
| 425 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that | 432 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that |
| 426 local BeanCounterActive = not InboxCloseButton:IsVisible(); | 433 local BeanCounterActive = not InboxCloseButton:IsVisible(); |
| 427 | 434 |
| 428 if not BeanCounterActive then | 435 if not BeanCounterActive and not MailAddonBusy then |
| 429 -- BeanCounter is INACTIVE | 436 -- No other addon is currently active |
| 430 | 437 |
| 431 self:CancelTimer(self.tmrTryAgain, true); -- Insurance | 438 self:CancelTimer(self.tmrTryAgain, true); -- Insurance |
| 432 | 439 |
| 433 if QuickAuctionsAutoMail then | 440 if QuickAuctionsAutoMail then |
| 434 -- Remember the last known quick auctions status | 441 -- Remember the last known quick auctions status |
| 441 self:Debug("Turning automail |cffff0000off|r."); | 448 self:Debug("Turning automail |cffff0000off|r."); |
| 442 | 449 |
| 443 QuickAuctionsAutoMail:Click(); | 450 QuickAuctionsAutoMail:Click(); |
| 444 end | 451 end |
| 445 | 452 |
| 446 self.busy = true; | 453 MailAddonBusy = self:GetName(); |
| 447 | 454 |
| 448 self:Debug("MO_OPEN_MAIL"); | 455 self:Debug("MO_OPEN_MAIL"); |
| 449 | 456 |
| 450 -- Summon the mail opening gods | 457 -- Summon the mail opening gods |
| 451 self:SendMessage("MO_OPEN_MAIL"); | 458 self:SendMessage("MO_OPEN_MAIL"); |
| 452 else | 459 else |
| 453 -- BeanCounter is ACTIVE | 460 -- Another addon is ACTIVE |
| 454 self:Debug("BeanCounter active, waiting .5 seconds..."); | 461 self:Debug("Another addon active, waiting .5 seconds..."); |
| 455 | 462 |
| 456 self:CancelTimer(self.tmrTryAgain, true); -- Insurance | 463 self:CancelTimer(self.tmrTryAgain, true); -- Insurance |
| 457 -- Wait with summoning until BeanCounter is done, try again every 0.5 seconds | 464 -- Try again every 0.5 seconds |
| 458 self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5); | 465 self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5); |
| 459 end | 466 end |
| 460 end | 467 end |
| 461 end | 468 end |
| 462 | 469 |
| 463 function MailOpener:MO_OPEN_COMPLETE() | 470 function MailOpener:MO_OPEN_COMPLETE() |
| 464 self.busy = false; | 471 if MailAddonBusy == self:GetName() then |
| 472 MailAddonBusy = nil; | |
| 473 end | |
| 465 | 474 |
| 466 -- Try a recheck | 475 -- Try a recheck |
| 467 self:Recheck(); | 476 self:Recheck(); |
| 468 | 477 |
| 469 local current, total = GetInboxNumItems(); | 478 local current, total = GetInboxNumItems(); |
| 514 -- Freshlist prevents this from being run too often | 523 -- Freshlist prevents this from being run too often |
| 515 -- It is set to true after a server sync | 524 -- It is set to true after a server sync |
| 516 -- and set to false 61 seconds afterwards with a recheck called instantly after it | 525 -- and set to false 61 seconds afterwards with a recheck called instantly after it |
| 517 | 526 |
| 518 -- We're not refreshing while we're opening because it is automatically done when current batch was completely opened | 527 -- We're not refreshing while we're opening because it is automatically done when current batch was completely opened |
| 519 if not freshList and not self.busy and MailFrame:IsVisible() then | 528 if not freshList and MailFrame:IsVisible() then |
| 520 self:Debug("|cff00ff00Recheck|r"); | 529 self:Debug("|cff00ff00Recheck|r"); |
| 521 | 530 |
| 522 -- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed | 531 -- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed |
| 523 | 532 |
| 524 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that | 533 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that |
| 525 local BeanCounterActive = not InboxCloseButton:IsVisible(); | 534 local BeanCounterActive = not InboxCloseButton:IsVisible(); |
| 526 | 535 |
| 527 if not BeanCounterActive and AutoOpenMail then | 536 if not BeanCounterActive and AutoOpenMail and not MailAddonBusy then |
| 528 -- Query the server | 537 -- Query the server |
| 529 CheckInbox(); | 538 CheckInbox(); |
| 530 end | 539 end |
| 531 | 540 |
| 532 -- Stop previous timer | 541 -- Stop previous timer |
| 542 function MailOpener:Stop() | 551 function MailOpener:Stop() |
| 543 if self.db.profile.notifications.bye then | 552 if self.db.profile.notifications.bye then |
| 544 print("|cff15ff00Mail Opener|r: Have a nice day. :)"); | 553 print("|cff15ff00Mail Opener|r: Have a nice day. :)"); |
| 545 end | 554 end |
| 546 | 555 |
| 547 self.busy = false; | 556 if MailAddonBusy == self:GetName() then |
| 557 MailAddonBusy = nil; | |
| 558 end | |
| 548 | 559 |
| 549 -- We won't need this anymore | 560 -- We won't need this anymore |
| 550 self:UnregisterEvent("MAIL_CLOSED"); | 561 self:UnregisterEvent("MAIL_CLOSED"); |
| 551 self:UnregisterEvent("PLAYER_LEAVING_WORLD"); | 562 self:UnregisterEvent("PLAYER_LEAVING_WORLD"); |
| 552 self:UnregisterEvent("MAIL_INBOX_UPDATE"); | 563 self:UnregisterEvent("MAIL_INBOX_UPDATE"); |
