Mercurial > wow > mailopener
comparison Modules/OpenAll.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 | b79bb7b449c3 |
comparison
equal
deleted
inserted
replaced
| 30:4ab03ed958ed | 31:90d58723ac0a |
|---|---|
| 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); | 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); |
| 2 local OpenAll = MailOpener:NewModule("OpenAll", "AceEvent-3.0", "AceTimer-3.0"); | 2 local mod = MailOpener:NewModule("OpenAll", "AceEvent-3.0", "AceTimer-3.0"); |
| 3 | |
| 4 mod.moduleDescription = "The actual mail opening initiated by the core."; | |
| 5 mod.moduleRequired = true; | |
| 3 | 6 |
| 4 --[[ | 7 --[[ |
| 5 Module name: OpenAll | |
| 6 Description: The actual mail opening initiated by the core. | |
| 7 Required: Yes. | |
| 8 | |
| 9 Dev notes: | 8 Dev notes: |
| 10 When shift clicking the Open All button it should override all filters. | 9 When shift clicking the Open All button it should override all filters. |
| 11 ]] | 10 ]] |
| 12 | 11 |
| 13 local MAIL_ITEM_INDEX, mailTimer, inventoryFull, inventoryFullSoundPlayed, opening, lastSync, numCurrentMail, numHiddenMail, continue; | 12 local MAIL_ITEM_INDEX, mailTimer, inventoryFull, inventoryFullSoundPlayed, opening, lastSync, numCurrentMail, numHiddenMail, continue; |
| 14 | 13 |
| 15 function OpenAll:OnInitialize() | 14 function mod:OnInitialize() |
| 16 local defaults = { | 15 local defaults = { |
| 17 profile = { | 16 profile = { |
| 18 speed = 0.05, | 17 speed = 0.05, |
| 19 keepFreeSpace = 0, | 18 keepFreeSpace = 0, |
| 20 filter = { | 19 filter = { |
| 33 | 32 |
| 34 -- Register our saved variables NameSpace | 33 -- Register our saved variables NameSpace |
| 35 self.db = MailOpener.db:RegisterNamespace("OpenAll", defaults); | 34 self.db = MailOpener.db:RegisterNamespace("OpenAll", defaults); |
| 36 end | 35 end |
| 37 | 36 |
| 38 function OpenAll:OnEnable() | 37 function mod:OnEnable() |
| 39 self:RegisterEvent("MAIL_SHOW"); | 38 self:RegisterEvent("MAIL_SHOW"); |
| 40 | 39 |
| 41 if not self.btnOpenAll then | 40 if not self.btnOpenAll then |
| 42 -- Open all button | 41 -- Open all button |
| 43 local button = CreateFrame("Button", "btnMailOpenerOpenAll", InboxFrame, "UIPanelButtonTemplate") | 42 local button = CreateFrame("Button", "btnMailOpenerOpenAll", InboxFrame, "UIPanelButtonTemplate") |
| 44 button:SetText("Open all") | 43 button:SetText("Open all") |
| 45 button:SetHeight(26) | 44 button:SetHeight(26) |
| 46 button:SetWidth(120) | 45 button:SetWidth(120) |
| 47 button:SetPoint("BOTTOM", InboxFrame, "CENTER", -10, -165) | 46 button:SetPoint("BOTTOM", InboxFrame, "CENTER", -10, -165) |
| 48 button:SetScript("OnClick", function() OpenAll:Open(true) end) | 47 button:SetScript("OnClick", function() mod:Open(true) end) |
| 49 | 48 |
| 50 self.btnOpenAll = button; | 49 self.btnOpenAll = button; |
| 51 end | 50 end |
| 52 | 51 |
| 53 self.btnOpenAll:Show(); | 52 self.btnOpenAll:Show(); |
| 101 if MailFrame:IsVisible() then | 100 if MailFrame:IsVisible() then |
| 102 self:MAIL_SHOW(); | 101 self:MAIL_SHOW(); |
| 103 end | 102 end |
| 104 end | 103 end |
| 105 | 104 |
| 106 function OpenAll:OnDisable() | 105 function mod:OnDisable() |
| 107 self:UnregisterEvent("MAIL_SHOW"); | 106 self:UnregisterEvent("MAIL_SHOW"); |
| 108 | 107 |
| 109 if self.btnOpenAll then | 108 if self.btnOpenAll then |
| 110 self.btnOpenAll:Hide(); | 109 self.btnOpenAll:Hide(); |
| 111 end | 110 end |
| 131 end | 130 end |
| 132 | 131 |
| 133 self:Stop(); | 132 self:Stop(); |
| 134 end | 133 end |
| 135 | 134 |
| 136 function OpenAll:MAIL_SHOW() | 135 function mod:MAIL_SHOW() |
| 137 self:Debug("MAIL_SHOW"); | 136 self:Debug("MAIL_SHOW"); |
| 138 | 137 |
| 139 self:StopOpening(false); | 138 self:StopOpening(false); |
| 140 | 139 |
| 141 if MailOpener.PostalEnabled then | 140 if MailOpener.PostalEnabled then |
| 162 self:CancelTimer(self.tmrTimeRemaining, true); | 161 self:CancelTimer(self.tmrTimeRemaining, true); |
| 163 self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1); | 162 self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1); |
| 164 self:UpdateTimer(); | 163 self:UpdateTimer(); |
| 165 end | 164 end |
| 166 | 165 |
| 167 function OpenAll:Stop() | 166 function mod:Stop() |
| 168 self:Debug("Stop"); | 167 self:Debug("Stop"); |
| 169 | 168 |
| 170 -- We shutdown, so nothing to do when the mailbox is closed anymore | 169 -- We shutdown, so nothing to do when the mailbox is closed anymore |
| 171 self:UnregisterEvent("MAIL_CLOSED"); | 170 self:UnregisterEvent("MAIL_CLOSED"); |
| 172 self:UnregisterEvent("PLAYER_LEAVING_WORLD"); | 171 self:UnregisterEvent("PLAYER_LEAVING_WORLD"); |
| 184 self:CancelTimer(self.tmrTimeRemaining, true); | 183 self:CancelTimer(self.tmrTimeRemaining, true); |
| 185 | 184 |
| 186 self:SetOpeningStatus(false); | 185 self:SetOpeningStatus(false); |
| 187 end | 186 end |
| 188 | 187 |
| 189 function OpenAll:MO_SERVER_SYNCED() | 188 function mod:MO_SERVER_SYNCED() |
| 190 self:Debug("MO_SERVER_SYNCED"); | 189 self:Debug("MO_SERVER_SYNCED"); |
| 191 | 190 |
| 192 -- Stop opening now to prevent the opener from continue while Beancounter is counting | 191 -- Stop opening now to prevent the opener from continueing while BeanCounter is counting |
| 193 self:StopOpening(false); | 192 self:StopOpening(false); |
| 194 | 193 |
| 195 lastSync = GetTime(); | 194 lastSync = GetTime(); |
| 196 | 195 |
| 197 self:UpdateMailCount(); | 196 self:UpdateMailCount(); |
| 198 end | 197 end |
| 199 | 198 |
| 200 function OpenAll:MO_MAIL_EMPTIED() | 199 function mod:MO_MAIL_EMPTIED() |
| 201 -- A mail has been processed so we can process the next | 200 -- A mail has been processed so we can process the next |
| 202 continue = true; | 201 continue = true; |
| 203 | 202 |
| 204 self:UpdateTimer(); | 203 self:UpdateTimer(); |
| 205 end | 204 end |
| 206 | 205 |
| 207 function OpenAll:UpdateMailCount() | 206 function mod:UpdateMailCount() |
| 208 local numItems, totalItems = GetInboxNumItems(); | 207 local numItems, totalItems = GetInboxNumItems(); |
| 209 | 208 |
| 210 numCurrentMail = numItems; | 209 numCurrentMail = numItems; |
| 211 numHiddenMail = ( totalItems - numItems ); | 210 numHiddenMail = ( totalItems - numItems ); |
| 212 end | 211 end |
| 213 | 212 |
| 214 function OpenAll:BAG_UPDATE() | 213 function mod:BAG_UPDATE() |
| 215 -- If the bags are updated we should check if the inventory is full again | 214 -- If the bags are updated we should check if the inventory is full again |
| 216 inventoryFull = false; | 215 inventoryFull = false; |
| 217 -- Replay sound | 216 -- Replay sound |
| 218 inventoryFullSoundPlayed = nil; | 217 inventoryFullSoundPlayed = nil; |
| 219 end | 218 end |
| 220 | 219 |
| 221 -- We registered this event to look for the inventory full error message because this is faster than counting the amount of items in the inventory all the time | 220 -- We registered this event to look for the inventory full error message because this is faster than counting the amount of items in the inventory all the time |
| 222 function OpenAll:UI_ERROR_MESSAGE(e, errorMessage) | 221 function mod:UI_ERROR_MESSAGE(e, errorMessage) |
| 223 if errorMessage == ERR_INV_FULL then | 222 if errorMessage == ERR_INV_FULL then |
| 224 -- Inventory is full. | 223 -- Inventory is full. |
| 225 | 224 |
| 226 if not inventoryFull then | 225 if not inventoryFull then |
| 227 inventoryFull = true; | 226 inventoryFull = true; |
| 241 -- Continue opening mail (we still want to retrieve other items or gold) | 240 -- Continue opening mail (we still want to retrieve other items or gold) |
| 242 continue = true; | 241 continue = true; |
| 243 end | 242 end |
| 244 end | 243 end |
| 245 | 244 |
| 246 function OpenAll:Open(forced) | 245 function mod:Open(forced) |
| 247 self:Debug("Open"); | 246 self:Debug("Open"); |
| 248 | 247 |
| 249 if not opening or forced == true then | 248 if not opening or forced == true then |
| 250 local numItems, totalItems = GetInboxNumItems(); | 249 local numItems, totalItems = GetInboxNumItems(); |
| 251 -- Start at the end, add one because OpenNext will take it away again | 250 -- Start at the end, add one because OpenNext will take it away again |
| 288 expired = AUCTION_EXPIRED_MAIL_SUBJECT:replace("%s", ""), | 287 expired = AUCTION_EXPIRED_MAIL_SUBJECT:replace("%s", ""), |
| 289 outbid = AUCTION_OUTBID_MAIL_SUBJECT:replace("%s", ""), | 288 outbid = AUCTION_OUTBID_MAIL_SUBJECT:replace("%s", ""), |
| 290 success = AUCTION_SOLD_MAIL_SUBJECT:replace("%s", ""), | 289 success = AUCTION_SOLD_MAIL_SUBJECT:replace("%s", ""), |
| 291 won = AUCTION_WON_MAIL_SUBJECT:replace("%s", ""), | 290 won = AUCTION_WON_MAIL_SUBJECT:replace("%s", ""), |
| 292 }; | 291 }; |
| 293 function OpenAll:GetAuctionMailType(subject) | 292 function mod:GetAuctionMailType(subject) |
| 294 if subject then | 293 if subject then |
| 295 -- Check if any of our patterns match, sorted by most likely matches first (if one is true the rest shouldn't be evaluated) | 294 -- Check if any of our patterns match, sorted by most likely matches first (if one is true the rest shouldn't be evaluated) |
| 296 if subject:find(knownAHSubjectPatterns.expired) then | 295 if subject:find(knownAHSubjectPatterns.expired) then |
| 297 return "expired"; | 296 return "expired"; |
| 298 elseif subject:find(knownAHSubjectPatterns.success) then | 297 elseif subject:find(knownAHSubjectPatterns.success) then |
| 307 end | 306 end |
| 308 | 307 |
| 309 return; -- not auction mail | 308 return; -- not auction mail |
| 310 end | 309 end |
| 311 | 310 |
| 312 function OpenAll:OpenMail(index) | 311 function mod:OpenMail(index) |
| 313 if index > 0 then | 312 if index > 0 then |
| 314 -- LUA arrays start at 1, so mail with index 0 doesn't exist, so we're finished | 313 -- LUA arrays start at 1, so mail with index 0 doesn't exist, so we're finished |
| 315 | 314 |
| 316 local sender, subject, gold, cod, _, items, _, _, _, _, isGM = select(3, GetInboxHeaderInfo(index)); | 315 local sender, subject, gold, cod, _, items, _, _, _, _, isGM = select(3, GetInboxHeaderInfo(index)); |
| 317 local auctionMailType = self:GetAuctionMailType(subject); | 316 local auctionMailType = self:GetAuctionMailType(subject); |
| 483 -- Report that we're all done | 482 -- Report that we're all done |
| 484 self:SendMessage("MO_OPEN_COMPLETE"); | 483 self:SendMessage("MO_OPEN_COMPLETE"); |
| 485 end | 484 end |
| 486 end | 485 end |
| 487 | 486 |
| 488 function OpenAll:OpenNext() | 487 function mod:OpenNext() |
| 489 if continue then | 488 if continue then |
| 490 -- If the previous mail was opened successful, open the next | 489 -- If the previous mail was opened successful, open the next |
| 491 | 490 |
| 492 -- Next mail in line | 491 -- Next mail in line |
| 493 MAIL_ITEM_INDEX = ( MAIL_ITEM_INDEX - 1 ); | 492 MAIL_ITEM_INDEX = ( MAIL_ITEM_INDEX - 1 ); |
| 499 | 498 |
| 500 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed); | 499 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed); |
| 501 end | 500 end |
| 502 end | 501 end |
| 503 | 502 |
| 504 function OpenAll:Continue() | 503 function mod:Continue() |
| 505 continue = true; | 504 continue = true; |
| 506 self:OpenNext(); | 505 self:OpenNext(); |
| 507 end | 506 end |
| 508 | 507 |
| 509 local mailRemainingPatterns = { | 508 local mailRemainingPatterns = { |
| 514 waitingBatch = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for something from the current batch to be opened..."; | 513 waitingBatch = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for something from the current batch to be opened..."; |
| 515 waitingSync = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for the next mailbox refresh..."; | 514 waitingSync = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for the next mailbox refresh..."; |
| 516 soon = "|cffffffff%d|r/|cffffffff%d|r mail remaining - everything will be opened soon..."; | 515 soon = "|cffffffff%d|r/|cffffffff%d|r mail remaining - everything will be opened soon..."; |
| 517 }; | 516 }; |
| 518 | 517 |
| 519 function OpenAll:UpdateTimer() | 518 function mod:UpdateTimer() |
| 520 if lastSync then | 519 if lastSync then |
| 521 self:UpdateMailCount(); | 520 self:UpdateMailCount(); |
| 522 | 521 |
| 523 -- Calculate the total amount of mail waiting | 522 -- Calculate the total amount of mail waiting |
| 524 local numTotalMail = ( numHiddenMail + numCurrentMail ); | 523 local numTotalMail = ( numHiddenMail + numCurrentMail ); |
| 589 self.timeLeftFrame.smallText:SetText(""); | 588 self.timeLeftFrame.smallText:SetText(""); |
| 590 end | 589 end |
| 591 end | 590 end |
| 592 end | 591 end |
| 593 | 592 |
| 594 function OpenAll:StopOpening(simple) | 593 function mod:StopOpening(simple) |
| 595 -- Stop opener timer | 594 -- Stop opener timer |
| 596 self:CancelTimer(self.tmrMailOpener, true); | 595 self:CancelTimer(self.tmrMailOpener, true); |
| 597 | 596 |
| 598 if not simple then | 597 if not simple then |
| 599 -- A simple stop is an automated stop, an advance stop is one manually or after a sever sync | 598 -- A simple stop is an automated stop, an advance stop is one manually or after a sever sync |
| 606 | 605 |
| 607 -- Reset opener position | 606 -- Reset opener position |
| 608 MAIL_ITEM_INDEX = 0; | 607 MAIL_ITEM_INDEX = 0; |
| 609 -- Stopped opening, so allow to continue | 608 -- Stopped opening, so allow to continue |
| 610 continue = true; | 609 continue = true; |
| 610 | |
| 611 self:SetOpeningStatus(false); | 611 self:SetOpeningStatus(false); |
| 612 end | 612 end |
| 613 | 613 |
| 614 function OpenAll:SetOpeningStatus(openingStatus) | 614 function mod:SetOpeningStatus(openingStatus) |
| 615 opening = openingStatus; | 615 opening = openingStatus; |
| 616 | 616 |
| 617 if openingStatus then | 617 if openingStatus then |
| 618 self.btnOpenAll:SetText("Opening..."); | 618 self.btnOpenAll:SetText("Opening..."); |
| 619 else | 619 else |
| 620 self.btnOpenAll:SetText("Open all"); | 620 self.btnOpenAll:SetText("Open all"); |
| 621 end | 621 end |
| 622 end | 622 end |
| 623 | 623 |
| 624 function OpenAll:GetOptionsGroup() | 624 function mod:GetOptionsGroup() |
| 625 local configGroup = { | 625 local configGroup = { |
| 626 order = 300, | 626 order = 300, |
| 627 type = "group", | 627 type = "group", |
| 628 name = "Open All", | 628 name = "Open All", |
| 629 desc = "Change open all settings.", | 629 desc = "Change open all settings.", |
| 842 }; | 842 }; |
| 843 | 843 |
| 844 return configGroup; | 844 return configGroup; |
| 845 end | 845 end |
| 846 | 846 |
| 847 function OpenAll:Debug(t) | 847 function mod:Debug(t) |
| 848 return MailOpener:Debug("|cff00ff00OpenAll|r:" .. t); | 848 return MailOpener:Debug("|cff00ff00OpenAll|r:" .. t); |
| 849 end | 849 end |
