Mercurial > wow > mailopener
comparison Modules/OpenAll.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 |
comparison
equal
deleted
inserted
replaced
| 1:6f17035de058 | 2:57ba1593ac42 |
|---|---|
| 142 | 142 |
| 143 -- Look if the mailbox is full | 143 -- Look if the mailbox is full |
| 144 self:RegisterEvent("UI_ERROR_MESSAGE"); | 144 self:RegisterEvent("UI_ERROR_MESSAGE"); |
| 145 -- Only look again after bags updated | 145 -- Only look again after bags updated |
| 146 self:RegisterEvent("BAG_UPDATE"); | 146 self:RegisterEvent("BAG_UPDATE"); |
| 147 self:RegisterEvent("MAIL_INBOX_UPDATE"); | |
| 148 | 147 |
| 149 -- We need to know when to start opening | 148 -- We need to know when to start opening |
| 150 self:RegisterMessage("MO_OPEN_MAIL", "Open"); | 149 self:RegisterMessage("MO_OPEN_MAIL", "Open"); |
| 151 self:RegisterMessage("MO_SERVER_SYNCED"); | 150 self:RegisterMessage("MO_SERVER_SYNCED"); |
| 151 self:RegisterMessage("MO_MAIL_DELETED"); | |
| 152 | 152 |
| 153 self:CancelTimer(self.tmrTimeRemaining, true); | 153 self:CancelTimer(self.tmrTimeRemaining, true); |
| 154 self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1); | 154 self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1); |
| 155 self:UpdateTimer(); | 155 self:UpdateTimer(); |
| 156 end | 156 end |
| 163 self:UnregisterEvent("PLAYER_LEAVING_WORLD"); | 163 self:UnregisterEvent("PLAYER_LEAVING_WORLD"); |
| 164 | 164 |
| 165 -- We care about a full inventory just a little | 165 -- We care about a full inventory just a little |
| 166 self:UnregisterEvent("UI_ERROR_MESSAGE"); | 166 self:UnregisterEvent("UI_ERROR_MESSAGE"); |
| 167 self:UnregisterEvent("BAG_UPDATE"); | 167 self:UnregisterEvent("BAG_UPDATE"); |
| 168 self:UnregisterEvent("MAIL_INBOX_UPDATE"); | |
| 169 | 168 |
| 170 -- We no longer care | 169 -- We no longer care |
| 171 self:UnregisterMessage("MO_OPEN_MAIL"); | 170 self:UnregisterMessage("MO_OPEN_MAIL"); |
| 172 self:UnregisterMessage("MO_SERVER_SYNCED"); | 171 self:UnregisterMessage("MO_SERVER_SYNCED"); |
| 172 self:UnregisterMessage("MO_MAIL_DELETED"); | |
| 173 | 173 |
| 174 self:CancelTimer(self.tmrMailOpener, true); | 174 self:CancelTimer(self.tmrMailOpener, true); |
| 175 self:CancelTimer(self.tmrTimeRemaining, true); | 175 self:CancelTimer(self.tmrTimeRemaining, true); |
| 176 | 176 |
| 177 self:SetOpeningStatus(false); | 177 self:SetOpeningStatus(false); |
| 178 end | 178 end |
| 179 | 179 |
| 180 function OpenAll:MO_SERVER_SYNCED() | 180 function OpenAll:MO_SERVER_SYNCED() |
| 181 self:Debug("MO_SERVER_SYNCED"); | 181 self:Debug("MO_SERVER_SYNCED"); |
| 182 | 182 |
| 183 -- Stop opening now to prevent the opener from continue while Beancounter is counting | |
| 184 self:StopOpening(false); | |
| 185 | |
| 183 lastSync = GetTime(); | 186 lastSync = GetTime(); |
| 184 | 187 |
| 188 self:UpdateMailCount(); | |
| 189 end | |
| 190 | |
| 191 function OpenAll:MO_MAIL_DELETED() | |
| 192 self:Debug("MO_MAIL_DELETED"); | |
| 193 | |
| 194 -- A mail has been deleted so we can process the next | |
| 195 continue = true; | |
| 196 | |
| 197 self:UpdateMailCount(); | |
| 198 end | |
| 199 | |
| 200 function OpenAll:UpdateMailCount() | |
| 185 local numItems, totalItems = GetInboxNumItems(); | 201 local numItems, totalItems = GetInboxNumItems(); |
| 186 | 202 |
| 187 numCurrentMail = numItems; | 203 numCurrentMail = numItems; |
| 188 numHiddenMail = ( totalItems - numItems ); | 204 numHiddenMail = ( totalItems - numItems ); |
| 205 | |
| 206 self:UpdateTimer(); | |
| 189 end | 207 end |
| 190 | 208 |
| 191 function OpenAll:BAG_UPDATE() | 209 function OpenAll:BAG_UPDATE() |
| 192 -- If the bags are updated we should check if the inventory is full again | 210 -- If the bags are updated we should check if the inventory is full again |
| 193 inventoryFull = false; | 211 inventoryFull = false; |
| 194 -- Replay sound | 212 -- Replay sound |
| 195 inventoryFullSoundPlayed = nil; | 213 inventoryFullSoundPlayed = nil; |
| 196 end | |
| 197 | |
| 198 function OpenAll:MAIL_INBOX_UPDATE() | |
| 199 local numItems, totalItems = GetInboxNumItems(); | |
| 200 | |
| 201 if numItems ~= numCurrentMail then | |
| 202 continue = true; | |
| 203 | |
| 204 if numCurrentMail ~= nil and numItems > numCurrentMail then | |
| 205 -- This is a server sync | |
| 206 | |
| 207 self:StopOpening(false); | |
| 208 end | |
| 209 end | |
| 210 | |
| 211 numCurrentMail = numItems; | |
| 212 numHiddenMail = ( totalItems - numItems ); | |
| 213 | |
| 214 self:UpdateTimer(); | |
| 215 end | 214 end |
| 216 | 215 |
| 217 -- 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 | 216 -- 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 |
| 218 function OpenAll:UI_ERROR_MESSAGE(e, errorMessage) | 217 function OpenAll:UI_ERROR_MESSAGE(e, errorMessage) |
| 219 if errorMessage == ERR_INV_FULL then | 218 if errorMessage == ERR_INV_FULL then |
| 432 | 431 |
| 433 return; | 432 return; |
| 434 else | 433 else |
| 435 continue = false; | 434 continue = false; |
| 436 | 435 |
| 436 -- Notifiy other modules of opening | |
| 437 self:SendMessage("MO_OPENING_MAIL"); | |
| 438 | |
| 437 -- Open current mail | 439 -- Open current mail |
| 438 AutoLootMailItem(index); | 440 AutoLootMailItem(index); |
| 439 | 441 |
| 440 if MailOpener.db.profile.notifications.processed.all and MailOpener.db.profile.notifications.processed[mailType] then | 442 if MailOpener.db.profile.notifications.processed.all and MailOpener.db.profile.notifications.processed[mailType] then |
| 441 if gold and gold > 0 then | 443 if gold and gold > 0 then |
| 488 else | 490 else |
| 489 -- Try again at the next interval | 491 -- Try again at the next interval |
| 490 | 492 |
| 491 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed); | 493 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed); |
| 492 end | 494 end |
| 495 end | |
| 496 | |
| 497 function OpenAll:Continue() | |
| 498 continue = true; | |
| 499 self:OpenNext(); | |
| 493 end | 500 end |
| 494 | 501 |
| 495 local mailRemainingPatterns = { | 502 local mailRemainingPatterns = { |
| 496 minutesSeconds = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes and |cffffffff%d|r seconds (next refresh in |cffffffff%d|r seconds)"; | 503 minutesSeconds = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes and |cffffffff%d|r seconds (next refresh in |cffffffff%d|r seconds)"; |
| 497 minutes = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes (next refresh in |cffffffff%d|r seconds)"; | 504 minutes = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes (next refresh in |cffffffff%d|r seconds)"; |
| 563 end | 570 end |
| 564 end | 571 end |
| 565 end | 572 end |
| 566 | 573 |
| 567 function OpenAll:StopOpening(simple) | 574 function OpenAll:StopOpening(simple) |
| 575 -- Stop opener timer | |
| 576 self:CancelTimer(self.tmrMailOpener, true); | |
| 577 | |
| 568 if not simple then | 578 if not simple then |
| 579 -- A simple stop is an automated stop, an advance stop is one manually or after a sever sync | |
| 580 | |
| 569 -- Recheck inventory full | 581 -- Recheck inventory full |
| 570 inventoryFull = false; | 582 inventoryFull = false; |
| 571 -- Replay sound | 583 -- Replay sound |
| 572 inventoryFullSoundPlayed = nil; | 584 inventoryFullSoundPlayed = nil; |
| 573 end | 585 end |
| 574 | |
| 575 -- Stop opener timer | |
| 576 self:CancelTimer(self.tmrMailOpener, true); | |
| 577 | 586 |
| 578 -- Reset opener position | 587 -- Reset opener position |
| 579 MAIL_ITEM_INDEX = 0; | 588 MAIL_ITEM_INDEX = 0; |
| 580 -- Stopped opening, so allow to continue | 589 -- Stopped opening, so allow to continue |
| 581 continue = true; | 590 continue = true; |
