diff 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
line wrap: on
line diff
--- a/Modules/OpenAll.lua	Sun Sep 05 17:02:19 2010 +0200
+++ b/Modules/OpenAll.lua	Sun Sep 05 17:26:35 2010 +0200
@@ -144,11 +144,11 @@
     self:RegisterEvent("UI_ERROR_MESSAGE");
     -- Only look again after bags updated
 	self:RegisterEvent("BAG_UPDATE");
-	self:RegisterEvent("MAIL_INBOX_UPDATE");
     
     -- We need to know when to start opening
 	self:RegisterMessage("MO_OPEN_MAIL", "Open");
 	self:RegisterMessage("MO_SERVER_SYNCED");
+	self:RegisterMessage("MO_MAIL_DELETED");
 	
 	self:CancelTimer(self.tmrTimeRemaining, true);
 	self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1);
@@ -165,11 +165,11 @@
     -- We care about a full inventory just a little
     self:UnregisterEvent("UI_ERROR_MESSAGE");
     self:UnregisterEvent("BAG_UPDATE");
-    self:UnregisterEvent("MAIL_INBOX_UPDATE");
 	
 	-- We no longer care
 	self:UnregisterMessage("MO_OPEN_MAIL");
 	self:UnregisterMessage("MO_SERVER_SYNCED");
+	self:UnregisterMessage("MO_MAIL_DELETED");
     
 	self:CancelTimer(self.tmrMailOpener, true);
 	self:CancelTimer(self.tmrTimeRemaining, true);
@@ -180,12 +180,30 @@
 function OpenAll:MO_SERVER_SYNCED()
 	self:Debug("MO_SERVER_SYNCED");
 	
+	-- Stop opening now to prevent the opener from continue while Beancounter is counting
+	self:StopOpening(false);
+	
 	lastSync = GetTime();
 	
+	self:UpdateMailCount();
+end
+
+function OpenAll:MO_MAIL_DELETED()
+	self:Debug("MO_MAIL_DELETED");
+	
+	-- A mail has been deleted so we can process the next
+	continue = true;
+	
+	self:UpdateMailCount();
+end
+
+function OpenAll:UpdateMailCount()
 	local numItems, totalItems = GetInboxNumItems();
 	
 	numCurrentMail = numItems;
 	numHiddenMail = ( totalItems - numItems );
+	
+	self:UpdateTimer();
 end
 
 function OpenAll:BAG_UPDATE()
@@ -195,25 +213,6 @@
 	inventoryFullSoundPlayed = nil;
 end
 
-function OpenAll:MAIL_INBOX_UPDATE()
-	local numItems, totalItems = GetInboxNumItems();
-	
-	if numItems ~= numCurrentMail then
-		continue = true;
-		
-		if numCurrentMail ~= nil and numItems > numCurrentMail then
-			-- This is a server sync
-			
-			self:StopOpening(false);
-		end
-	end
-	
-	numCurrentMail = numItems;
-	numHiddenMail = ( totalItems - numItems );
-	
-	self:UpdateTimer();
-end
-
 -- 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
 function OpenAll:UI_ERROR_MESSAGE(e, errorMessage)
 	if errorMessage == ERR_INV_FULL then
@@ -434,6 +433,9 @@
 				else
 					continue = false;
 					
+					-- Notifiy other modules of opening
+					self:SendMessage("MO_OPENING_MAIL");
+					
 					-- Open current mail
 					AutoLootMailItem(index);
 					
@@ -492,6 +494,11 @@
 	end
 end
 
+function OpenAll:Continue()
+	continue = true;
+	self:OpenNext();
+end
+
 local mailRemainingPatterns = {
 	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)";
 	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)";
@@ -565,16 +572,18 @@
 end
 
 function OpenAll:StopOpening(simple)
+	-- Stop opener timer
+	self:CancelTimer(self.tmrMailOpener, true);
+	
 	if not simple then
+		-- A simple stop is an automated stop, an advance stop is one manually or after a sever sync
+		
 		-- Recheck inventory full
 		inventoryFull = false;
 		-- Replay sound
 		inventoryFullSoundPlayed = nil;
 	end
 	
-	-- Stop opener timer
-	self:CancelTimer(self.tmrMailOpener, true);
-	
 	-- Reset opener position
 	MAIL_ITEM_INDEX = 0;
 	-- Stopped opening, so allow to continue