changeset 42:8168280420ae

Added a new option to both sound notifications to limit playing of the sound to once per mailbox visit, instead of once per mailbox refresh / bags update.
author Zerotorescue
date Sat, 11 Sep 2010 21:31:26 +0200
parents 2b2bea9c7446
children ec609592bfcc
files Core.lua Modules/Config.lua Modules/FailSafe.lua Modules/OpenAll.lua
diffstat 4 files changed, 49 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Core.lua	Sat Sep 11 18:43:14 2010 +0200
+++ b/Core.lua	Sat Sep 11 21:31:26 2010 +0200
@@ -5,7 +5,7 @@
 -- MailAddonBusy will be nil when nothing is happening or filled with the addon name when MO is working
 -- Another addon can use this variable to indicate they're working too, MailOpener will then wait for that to finish
 
-local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed;
+local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed, mailboxEmptySoundPlayedThisVisit;
 
 function MailOpener:OnInitialize()
 	self:Debug("OnInitialize");
@@ -72,10 +72,12 @@
 				bagsFullSoundFile = "Sound\\Spells\\SimonGame_Visual_BadPress.wav",
 				bagsFullSoundFileName = "Simon Error",
 				bagsFullSoundOnlyOnce = true,
+				bagsFullSoundOnlyOncePerMailboxVisit = false,
 				mailboxEmptySound = false,
 				mailboxEmptySoundFile = "Sound\\Spells\\SimonGame_Visual_GameStart.wav",
 				mailboxEmptySoundFileName = "Simon Start",
 				mailboxEmptySoundOnlyOnce = true,
+				mailboxEmptySoundOnlyOncePerMailboxVisit = false,
 			},
 		},
 	};
@@ -393,6 +395,7 @@
 	end
 	
 	mailboxEmptySoundPlayed = nil;
+	mailboxEmptySoundPlayedThisVisit = nil;
 	
 	self:Recheck();
 	
@@ -554,9 +557,10 @@
 	if (total - current) == 0 then
 		-- There is probably no unopenable mail remaining, so play the sound (if enabled)
 		
-		if self.db.profile.notifications.mailboxEmptySound and (not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce or not mailboxEmptySoundPlayed) then
+		if self.db.profile.notifications.mailboxEmptySound and (not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce or not mailboxEmptySoundPlayed) and (not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOncePerMailboxVisit or not mailboxEmptySoundPlayedThisVisit) then
 			PlaySoundFile(self.db.profile.notifications.mailboxEmptySoundFile);
 			mailboxEmptySoundPlayed = true;
+			mailboxEmptySoundPlayedThisVisit = true;
 		end
 	end
 	
--- a/Modules/Config.lua	Sat Sep 11 18:43:14 2010 +0200
+++ b/Modules/Config.lua	Sat Sep 11 21:31:26 2010 +0200
@@ -679,14 +679,19 @@
 				inline = true,
 				name = "Sound Notifications",
 				args = {
+					descriptionMailProcessed = {
+						order = 61,
+						type = "description",
+						name = "Play a sound when...",
+					},
 					bagsFullSound = {
 						order = 100,
 						type = "toggle",
-						name = "Play a sound when your |cfffed000inventory is full|r",
+						name = "Inventory is full",
 						desc = "Play a sound when your inventory is full. You can select what sound in the select box next to this.",
 						set = function(i, v) MailOpener.db.profile.notifications.bagsFullSound = v; end,
 						get = function() return MailOpener.db.profile.notifications.bagsFullSound; end,
-						width = "double",
+						width = "medium",
 					},
 					bagsFullSoundFile = {
 						order = 101,
@@ -710,19 +715,29 @@
 						order = 102,
 						type = "toggle",
 						name = "Only once",
-						desc = "Only play this sound once each time new mail has been arrived.",
+						desc = "Only play this sound once each time new mail has been arrived or your bags are updated.",
 						set = function(i, v) MailOpener.db.profile.notifications.bagsFullSoundOnlyOnce = v; end,
 						get = function() return MailOpener.db.profile.notifications.bagsFullSoundOnlyOnce; end,
 						disabled = function() return (not MailOpener.db.profile.notifications.bagsFullSound); end,
+						--width = "half",
+					},
+					bagsFullSoundOnlyOncePerMailboxVisit = {
+						order = 103,
+						type = "toggle",
+						name = "...per mailbox visit",
+						desc = "Only play this sound once each time you visit the mailbox.",
+						set = function(i, v) MailOpener.db.profile.notifications.bagsFullSoundOnlyOncePerMailboxVisit = v; end,
+						get = function() return MailOpener.db.profile.notifications.bagsFullSoundOnlyOncePerMailboxVisit; end,
+						disabled = function() return (not MailOpener.db.profile.notifications.bagsFullSound or not MailOpener.db.profile.notifications.bagsFullSoundOnlyOnce); end,
 					},
 					mailboxEmptySound = {
 						order = 110,
 						type = "toggle",
-						name = "Play a sound when |cfffed000no more mail can be opened|r",
+						name = "No more mail can be opened",
 						desc = "Play a sound when no more mail can be opened. You can select what sound in the select box next to this.",
 						set = function(i, v) MailOpener.db.profile.notifications.mailboxEmptySound = v; end,
 						get = function() return MailOpener.db.profile.notifications.mailboxEmptySound; end,
-						width = "double",
+						--width = "double",
 					},
 					mailboxEmptySoundFile = {
 						order = 111,
@@ -750,6 +765,16 @@
 						set = function(i, v) MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce = v; end,
 						get = function() return MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce; end,
 						disabled = function() return (not MailOpener.db.profile.notifications.mailboxEmptySound); end,
+						--width = "half",
+					},
+					mailboxEmptySoundOnlyOncePerMailboxVisit = {
+						order = 113,
+						type = "toggle",
+						name = "...per mailbox visit",
+						desc = "Only play this sound once each time you visit the mailbox.",
+						set = function(i, v) MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOncePerMailboxVisit = v; end,
+						get = function() return MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOncePerMailboxVisit; end,
+						disabled = function() return (not MailOpener.db.profile.notifications.bagsFullSound or not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce); end,
 					},
 				},
 			}, -- end Sound Notifications config inline group
--- a/Modules/FailSafe.lua	Sat Sep 11 18:43:14 2010 +0200
+++ b/Modules/FailSafe.lua	Sat Sep 11 21:31:26 2010 +0200
@@ -31,6 +31,11 @@
 	self:Debug("OnDisable");
 	
 	self:UnregisterEvent("MAIL_SHOW");
+	
+	-- If we were toggling this module off while the mailbox is opened we must unregister all events
+	if MailFrame:IsVisible() then
+		self:MAIL_CLOSED();
+	end
 end
 
 function mod:MAIL_SHOW()
--- a/Modules/OpenAll.lua	Sat Sep 11 18:43:14 2010 +0200
+++ b/Modules/OpenAll.lua	Sat Sep 11 21:31:26 2010 +0200
@@ -9,7 +9,7 @@
 When shift clicking the Open All button it should override all filters.
 ]]
 
-local MAIL_ITEM_INDEX, mailTimer, inventoryFull, inventoryFullSoundPlayed, opening, lastSync, numCurrentMail, numHiddenMail, continue;
+local MAIL_ITEM_INDEX, mailTimer, inventoryFull, inventoryFullSoundPlayed, inventoryFullSoundPlayedThisVisit, opening, lastSync, numCurrentMail, numHiddenMail, continue;
 
 function mod:OnInitialize()
 	local defaults = {
@@ -36,7 +36,7 @@
 
 function mod:OnEnable()
 	self:RegisterEvent("MAIL_SHOW");
-
+	
 	if not self.btnOpenAll then
 		-- Open all button
 		local button = CreateFrame("Button", "btnMailOpenerOpenAll", InboxFrame, "UIPanelButtonTemplate")
@@ -88,6 +88,7 @@
 	self.timeLeftFrame:Show();
 	
 	-- Go through all children of the mail frame to find QA's element and hide it
+	-- There's no other way to do this because QuickAuctions has a local referrence to it (not as a property of the object like most other frames)
 	local kids = { MailFrame:GetChildren() };
 	
 	for _, child in ipairs(kids) do
@@ -121,6 +122,7 @@
 	end
 	
 	-- Go through all children of the mail frame to find QA's elements and SHOW these
+	-- There's no other way to do this because QuickAuctions has a local referrence to it (not as a property of the object like most other frames)
 	local kids = { MailFrame:GetChildren() };
 	
 	for _, child in ipairs(kids) do
@@ -136,6 +138,8 @@
 	self:Debug("MAIL_SHOW");
 	
 	self:StopOpening(false);
+
+	inventoryFullSoundPlayedThisVisit = nil;
 	
 	if MailOpener.PostalEnabled then
 		-- Disable Postal's openers so we can do it ourselves
@@ -226,9 +230,10 @@
 			inventoryFull = true;
 			
 			-- Play the sound
-			if MailOpener.db.profile.notifications.bagsFullSound and (not MailOpener.db.profile.notifications.bagsFullSoundOnlyOnce or not inventoryFullSoundPlayed) then
+			if MailOpener.db.profile.notifications.bagsFullSound and (not MailOpener.db.profile.notifications.bagsFullSoundOnlyOnce or not inventoryFullSoundPlayed) and (not MailOpener.db.profile.notifications.bagsFullSoundOnlyOncePerMailboxVisit or not inventoryFullSoundPlayedThisVisit) then
 				PlaySoundFile(MailOpener.db.profile.notifications.bagsFullSoundFile);
 				inventoryFullSoundPlayed = true;
+				inventoryFullSoundPlayedThisVisit = true;
 			end
 		end