Mercurial > wow > mailopener
diff Modules/OpenAll.lua @ 174:463e29ca6b08
More merging'
| author | Zachary Kotlarek <zach@kotlarek.com> |
|---|---|
| date | Sun, 10 Mar 2013 16:08:39 -0700 |
| parents | 2b11229bf239 |
| children |
line wrap: on
line diff
--- a/Modules/OpenAll.lua Sun Mar 10 15:59:03 2013 -0700 +++ b/Modules/OpenAll.lua Sun Mar 10 16:08:39 2013 -0700 @@ -10,7 +10,7 @@ When shift clicking the Open All button it should override all filters. ]] -local MAIL_ITEM_INDEX, MAIL_OPEN_EVERYTHING, mailTimer, inventoryFull, inventoryFullSoundPlayed, inventoryFullSoundPlayedThisVisit, opening, lastSync, numCurrentMail, numHiddenMail, continue; +local MAIL_ITEM_INDEX, MAIL_OPEN_EVERYTHING, mailTimer, inventoryFull, inventoryFullSoundPlayed, inventoryFullSoundPlayedThisVisit, opening, lastSync, numCurrentMail, numHiddenMail, continue, firstOpenThisSync, takingSingleItem; function mod:OnInitialize() local defaults = { @@ -46,9 +46,16 @@ button:SetHeight(26); button:SetWidth(120); button:SetPoint("BOTTOM", InboxFrame, "CENTER", -10, -165); - button:RegisterForClicks("LeftButtonUp", "RightButtonUp"); + button:RegisterForClicks("LeftButtonUp", "RightButtonUp", "MiddleButtonUp"); button:SetScript("OnClick", function(self, mouseButton) + local action = "open"; if mouseButton == "RightButton" then + action = "menu"; + elseif mouseButton == "MiddleButton" or (mouseButton == "LeftButton" and IsAltKeyDown()) then + action = "stop"; + end + + if action == "menu" then -- Hide the gametooltip GameTooltip:Hide(); @@ -118,7 +125,7 @@ info.checked = mod.db.profile.filter.normalMoney; UIDropDownMenu_AddButton(info, level); - -- Make Other mail with gold + -- Close link info.text = CLOSE; info.func = function() CloseDropDownMenus(); end; info.checked = nil; @@ -133,12 +140,16 @@ end ToggleDropDownMenu(1, nil, mod.ddmFilters, self:GetName(), 0, 0); + elseif action == "stop" then + MailOpener:Print(L["Interrupting mail opening as the alt key was held down while clicking the open all button or the middle mouse-button was used on it."]); + + mod:StopOpening(true); else mod:Open(true, IsShiftKeyDown()); end end); button.tooltipTitle = L["Open all"]; - button.tooltip = L["Hold |cfffed000shift|r while clicking this button to temporarily override your filters and loot every single mail containing attachments and/or gold.\n\n|cfffed000Right|r click this button to quickly adjust mail opening filters for this profile."]; + button.tooltip = L["Hold |cfffed000shift|r while clicking this button to temporarily override your filters and loot every single mail containing attachments and/or gold.\n\n|cfffed000Right|r click this button to quickly adjust mail opening filters for this profile.\n\n|cfffed000Middle|r click or hold |cfffed000alt|r while clicking this button to interrupt mail opening."]; button:SetScript("OnEnter", function(self) if MailOpener.db.profile.general.showHelpTooltips then GameTooltip:SetOwner(self, "ANCHOR_NONE") @@ -271,6 +282,7 @@ self:RegisterMessage("MO_OPEN_MAIL", "Open"); self:RegisterMessage("MO_SERVER_SYNCED"); self:RegisterMessage("MO_MAIL_EMPTIED"); + self:RegisterMessage("MO_STOP_MAIL_OPENING"); self:CancelTimer(self.tmrTimeRemaining, true); self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1); @@ -292,6 +304,7 @@ self:UnregisterMessage("MO_OPEN_MAIL"); self:UnregisterMessage("MO_SERVER_SYNCED"); self:UnregisterMessage("MO_MAIL_EMPTIED"); + self:UnregisterMessage("MO_STOP_MAIL_OPENING"); self:CancelTimer(self.tmrMailOpener, true); self:CancelTimer(self.tmrTimeRemaining, true); @@ -308,6 +321,9 @@ lastSync = GetTime(); self:UpdateMailCount(); + + -- While this is true, we'll announce mail skipped - will be set to false after opening happened once + firstOpenThisSync = true; end function mod:MO_MAIL_EMPTIED() @@ -317,6 +333,10 @@ self:UpdateTimer(); end +function mod:MO_STOP_MAIL_OPENING() + self:StopOpening(true); +end + function mod:UpdateMailCount() local numItems, totalItems = GetInboxNumItems(); @@ -329,6 +349,10 @@ inventoryFull = false; -- Replay sound inventoryFullSoundPlayed = nil; + + if opening and takingSingleItem then + self:ScheduleTimer("Continue", self.db.profile.speed); + end 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 @@ -370,6 +394,9 @@ -- Stop the previous opening and restart if forced == true then + -- Show skips again + firstOpenThisSync = true; + self:StopOpening(false); -- this is not a "simple" stop, so also reset inventory full warning else self:StopOpening(true); -- forced is false - automated action - simple reset, skip inventory full reset to avoid sound spam @@ -406,11 +433,11 @@ -- Return the type of mail a message subject is local knownAHSubjectPatterns = { - canceled = AUCTION_REMOVED_MAIL_SUBJECT:replace("%s", ""), - expired = AUCTION_EXPIRED_MAIL_SUBJECT:replace("%s", ""), - outbid = AUCTION_OUTBID_MAIL_SUBJECT:replace("%s", ""), - success = AUCTION_SOLD_MAIL_SUBJECT:replace("%s", ""), - won = AUCTION_WON_MAIL_SUBJECT:replace("%s", ""), + canceled = AUCTION_REMOVED_MAIL_SUBJECT:format(""), + expired = AUCTION_EXPIRED_MAIL_SUBJECT:format(""), + outbid = AUCTION_OUTBID_MAIL_SUBJECT:format(""), + success = AUCTION_SOLD_MAIL_SUBJECT:format(""), + won = AUCTION_WON_MAIL_SUBJECT:format(""), }; function mod:GetAuctionMailType(subject) if subject then @@ -431,6 +458,8 @@ return; -- not auction mail end +local slotsAvailable; + function mod:OpenMail(index) if index and index > 0 then -- LUA arrays start at 1, so mail with index 0 doesn't exist, so we're finished @@ -440,11 +469,13 @@ if not subject then subject = ""; end + local onlyShowOnceCheck = firstOpenThisSync; + local skippingString = L["Skipping %d: %s (%s)"]; if isGM then -- Blizzard Mail - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.GMMail then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.GMMail then print(skippingString:format(index, subject, L["Blizzard mail"])); end @@ -453,7 +484,7 @@ return; elseif cod and cod > 0 then -- Cost on delivery - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.COD then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.COD then print(skippingString:format(index, subject, L["C.O.D."])); end @@ -463,7 +494,6 @@ elseif ((gold and gold > 0) or (items and items > 0)) then -- Mail with some sort of attachments - local slotsAvailable; if self.db.profile.keepFreeSpace > 0 then slotsAvailable = 0; @@ -480,7 +510,7 @@ -- and not MAIL_OPEN_EVERYTHING -- Removed above part from below if statement, I forgot why I put it here and now it makes no sense if inventoryFull and not MailOpener.db.profile.general.continueOpeningStackableItems and items and items > 0 then - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.inventoryFull then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.inventoryFull then print(skippingString:format(index, subject, L["inventory is full"])); end @@ -488,7 +518,7 @@ return; elseif self.db.profile.keepFreeSpace > 0 and items and slotsAvailable ~= nil and slotsAvailable <= 0 then - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.keepFreeSpaceLimit then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.keepFreeSpaceLimit then print(skippingString:format(index, subject, L["keep free space limit"])); end @@ -514,7 +544,7 @@ end if not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.normalMoney and mailType == "normalGoldMail" then - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then print(skippingString:format(index, subject, L["normal mail with gold"])); end @@ -522,7 +552,7 @@ return; elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.normalAttachments and mailType == "normalItemsMail" then - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then print(skippingString:format(index, subject, L["normal mail with attachments"])); end @@ -530,7 +560,7 @@ return; elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.expired and mailType == "AHexpired" then - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then print(skippingString:format(index, subject, L["expired auction"])); end @@ -538,7 +568,7 @@ return; elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.success and mailType == "AHsuccess" then - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then print(skippingString:format(index, subject, L["successful auction"])); end @@ -546,7 +576,7 @@ return; elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.won and mailType == "AHwon" then - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then print(skippingString:format(index, subject, L["auction won"])); end @@ -554,7 +584,7 @@ return; elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.canceled and mailType == "AHcanceled" then - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then print(skippingString:format(index, subject, L["canceled auction"])); end @@ -562,7 +592,7 @@ return; elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.outbid and mailType == "AHoutbid" then - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then print(skippingString:format(index, subject, L["outbid on auction"])); end @@ -590,12 +620,18 @@ self:Debug("Taking attachment " .. attachIndex); TakeInboxItem(index, attachIndex); + takingSingleItem = true; + + -- We want to open the next attachment for this same mail again, so set the index one back + MAIL_ITEM_INDEX = ( MAIL_ITEM_INDEX + 1 ); -- Gained an item, lost an available slot slotsAvailable = ( slotsAvailable - 1 ); + + break; else -- No more room available, announce and go to next item - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.keepFreeSpaceLimit then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.keepFreeSpaceLimit then print(skippingString:format(index, subject, L["keep free space limit"])); end @@ -621,13 +657,14 @@ end end + self:CancelTimer(self.tmrMailOpener, true); -- And prepare for the next self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed); end end else -- Unknown, probably just text - if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.other then + if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.other then print(L["Skipping %d: %s"]:format(index, subject)); end @@ -635,10 +672,13 @@ end else -- Finished! - if MailOpener.db.profile.notifications.finishedCurrentBatch then + if MailOpener.db.profile.notifications.finishedCurrentBatch and firstOpenThisSync then print(L["Finished opening the current batch."]); end + -- We have opened mail once this batch, so quit notifying + firstOpenThisSync = nil; + self:SetOpeningStatus(false); self:Debug("MO_OPEN_COMPLETE"); @@ -660,13 +700,14 @@ else -- Try again at the next interval + self:CancelTimer(self.tmrMailOpener, true); self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed); end end function mod:Continue() continue = true; - self:OpenNext(); + takingSingleItem = nil; end local mailRemainingPatterns = { @@ -774,6 +815,8 @@ -- Stopped opening, so allow to continue continue = true; + takingSingleItem = nil; + self:SetOpeningStatus(false); end
