Zerotorescue@3: -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("MailOpener") Zerotorescue@3: local MailOpener = LibStub("AceAddon-3.0"):NewAddon("MailOpener", "AceEvent-3.0", "AceTimer-3.0"); Zerotorescue@68: local L = LibStub("AceLocale-3.0"):GetLocale("MailOpener"); Zerotorescue@0: Zerotorescue@8: -- You can check if MailOpener is busy with the global MailAddonBusy (if not MailAddonBusy then ...do something... end) Zerotorescue@8: -- MailAddonBusy will be nil when nothing is happening or filled with the addon name when MO is working Zerotorescue@8: -- Another addon can use this variable to indicate they're working too, MailOpener will then wait for that to finish Zerotorescue@3: Zerotorescue@115: local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed, mailboxEmptySoundPlayedThisVisit, hasOpenedMailAlready, originalCheckInbox; Zerotorescue@0: Zerotorescue@0: function MailOpener:OnInitialize() Zerotorescue@31: self:Debug("OnInitialize"); Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: -- SAVED VARIABLES Zerotorescue@31: Zerotorescue@0: local defaults = { Zerotorescue@60: global = { Zerotorescue@60: currentTip = -1, -- even though LUA table indexes start at one, Config's OnEnable will increase this value by one the first time you run it and another 1 to adjust for the % modifier, so we still actually start at the table index 1 Zerotorescue@60: }, Zerotorescue@0: profile = { Zerotorescue@8: uses = 0, Zerotorescue@0: general = { Zerotorescue@8: defaultStatus = "disabled", -- addon enabled, but mail opening not auto on Zerotorescue@0: defaultQAStatus = "__remember", Zerotorescue@0: continueOpeningStackableItems = false, Zerotorescue@51: showHelpTooltips = true, Zerotorescue@0: autoDisableQAAutoMail = true, Zerotorescue@0: autoReenableQAAutoMail = false, Zerotorescue@0: autoSetBackQAAutoMail = true, Zerotorescue@0: continueOpening = false, Zerotorescue@0: waitTime = 5, Zerotorescue@0: initialDelay = 0.5, Zerotorescue@111: overrideCheckInbox = true, Zerotorescue@0: }, Zerotorescue@0: modules = { Zerotorescue@31: BeanCounterSupport = true, Zerotorescue@31: Config = false, Zerotorescue@0: Collected = true, Zerotorescue@5: FailSafe = true, Zerotorescue@0: }, Zerotorescue@0: notifications = { Zerotorescue@3: welcome = false, Zerotorescue@3: bye = false, Zerotorescue@0: finishedCurrentBatch = true, Zerotorescue@0: mailboxIsEmpty = true, Zerotorescue@0: Zerotorescue@0: skipped = { Zerotorescue@0: all = true, Zerotorescue@0: inventoryFull = true, Zerotorescue@0: keepFreeSpaceLimit = true, Zerotorescue@0: GMMail = true, Zerotorescue@0: COD = true, Zerotorescue@0: normalGoldMail = true, Zerotorescue@0: normalItemsMail = true, Zerotorescue@0: AHexpired = true, Zerotorescue@0: AHsuccess = true, Zerotorescue@0: AHwon = true, Zerotorescue@0: AHcanceled = true, Zerotorescue@0: AHoutbid = true, Zerotorescue@0: other = true, Zerotorescue@0: }, Zerotorescue@0: processed = { Zerotorescue@0: all = true, Zerotorescue@0: normalGoldMail = true, Zerotorescue@0: normalItemsMail = true, Zerotorescue@0: AHexpired = true, Zerotorescue@0: AHsuccess = true, Zerotorescue@0: AHwon = true, Zerotorescue@0: AHcanceled = true, Zerotorescue@0: AHoutbid = true, Zerotorescue@0: other = true, Zerotorescue@0: }, Zerotorescue@0: Zerotorescue@0: bagsFullSound = false, Zerotorescue@0: bagsFullSoundFile = "Sound\\Spells\\SimonGame_Visual_BadPress.wav", Zerotorescue@0: bagsFullSoundFileName = "Simon Error", Zerotorescue@0: bagsFullSoundOnlyOnce = true, Zerotorescue@42: bagsFullSoundOnlyOncePerMailboxVisit = false, Zerotorescue@0: mailboxEmptySound = false, Zerotorescue@0: mailboxEmptySoundFile = "Sound\\Spells\\SimonGame_Visual_GameStart.wav", Zerotorescue@0: mailboxEmptySoundFileName = "Simon Start", Zerotorescue@0: mailboxEmptySoundOnlyOnce = true, Zerotorescue@42: mailboxEmptySoundOnlyOncePerMailboxVisit = false, Zerotorescue@0: }, Zerotorescue@0: }, Zerotorescue@0: }; Zerotorescue@0: Zerotorescue@0: -- Register our saved variables database Zerotorescue@0: self.db = LibStub("AceDB-3.0"):New("MailOpenerDB", defaults, true); Zerotorescue@0: Zerotorescue@0: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: -- MODULE TOGGLING Zerotorescue@0: Zerotorescue@0: -- Don't enable the config module until we need it Zerotorescue@0: for name, module in self:IterateModules() do Zerotorescue@31: if self.db.profile.modules[name] ~= nil then Zerotorescue@0: if self.db.profile.modules[name] then Zerotorescue@68: self:Debug(("|cff00ff00Enabling|r module: "):format(name)); Zerotorescue@0: else Zerotorescue@68: self:Debug(("|cffff0000Disabling|r module: "):format(name)); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: module:SetEnabledState(self.db.profile.modules[name]); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: -- SLASH COMMANDS Zerotorescue@31: Zerotorescue@31: -- Disable the AddonLoader slash commands Zerotorescue@31: SLASH_MO1 = nil; Zerotorescue@31: SLASH_MAILOPEN1 = nil; Zerotorescue@31: SLASH_MAILOPENER1 = nil; Zerotorescue@31: Zerotorescue@31: -- Register our own slash commands Zerotorescue@31: SLASH_MAILOPENER1 = "/mo"; Zerotorescue@31: SLASH_MAILOPENER2 = "/mailopen"; Zerotorescue@31: SLASH_MAILOPENER3 = "/mailopener"; Zerotorescue@31: SlashCmdList["MAILOPENER"] = function(msg) Zerotorescue@31: MailOpener:EnableConfigModule(); Zerotorescue@31: Zerotorescue@31: MailOpenerConfig:CommandHandler(msg); Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: -- INTERFACE OPTIONS Zerotorescue@31: Zerotorescue@31: -- Attempt to remove the interface options added by AddonLoader (if enabled) Zerotorescue@31: if AddonLoader and AddonLoader.RemoveInterfaceOptions then Zerotorescue@31: AddonLoader:RemoveInterfaceOptions("Mail Opener"); Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: -- Now create our own options frame Zerotorescue@31: local frame = CreateFrame("Frame", nil, UIParent); Zerotorescue@31: frame:Hide(); Zerotorescue@31: frame.name = "Mail Opener"; Zerotorescue@135: frame.fresh = true; Zerotorescue@31: frame:HookScript("OnShow", function(self) Zerotorescue@135: if self.fresh then Zerotorescue@135: self.fresh = nil; Zerotorescue@135: Zerotorescue@135: -- Enable the config module Zerotorescue@135: MailOpener:EnableConfigModule(); Zerotorescue@135: Zerotorescue@135: -- Load the options and add it to the blizzard interface list Zerotorescue@135: MailOpenerConfig:Load(); Zerotorescue@135: Zerotorescue@135: -- Refresh the frame to instantly show the right options Zerotorescue@135: InterfaceOptionsFrame_OpenToCategory(self.name); Zerotorescue@135: end Zerotorescue@31: end); Zerotorescue@31: -- And add it to the interface options Zerotorescue@31: InterfaceOptions_AddCategory(frame); Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: -- ADDON / MAIL OPENING STATUS TOGGLER Zerotorescue@31: Zerotorescue@0: -- Make the open all checkbox Zerotorescue@50: local check = CreateFrame("CheckButton", "cbMailOpenerEnable", MailFrame, "OptionsCheckButtonTemplate"); Zerotorescue@0: check:SetHeight(26); Zerotorescue@0: check:SetWidth(26); Zerotorescue@50: check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 68, -13); Zerotorescue@3: check:SetChecked(true); Zerotorescue@0: check:SetHitRectInsets(0, -80, 0, 0); Zerotorescue@91: check:SetScript("OnClick", function(cbSelf) Zerotorescue@3: if IsShiftKeyDown() then Zerotorescue@3: -- Shift key = toggle addon on or off, since addon is already on there's only one option Zerotorescue@3: Zerotorescue@91: if not self:IsEnabled() then Zerotorescue@91: self:Print(L["Shift key was held down, so |cff00ff00enabling|r the entire addon as well as automatic opening of mail."]); Zerotorescue@3: Zerotorescue@91: self:Enable(); Zerotorescue@3: Zerotorescue@3: -- The above calls MAIL_SHOW which changes AutoOpenMail, so we can't remember the old setting Zerotorescue@3: AutoOpenMail = true; Zerotorescue@3: Zerotorescue@91: cbSelf:SetChecked(true); Zerotorescue@3: else Zerotorescue@91: self:Print(L["Shift key was held down, so |cffff0000disabling|r the entire addon."]); Zerotorescue@3: Zerotorescue@91: self:Disable(); Zerotorescue@3: Zerotorescue@91: cbSelf:SetChecked(false); Zerotorescue@3: end Zerotorescue@0: else Zerotorescue@3: -- Normal click Zerotorescue@3: Zerotorescue@91: if cbSelf:GetChecked() then Zerotorescue@91: self:Print(L["|cff00ff00Enabling|r automatic opening of mail."]); Zerotorescue@3: Zerotorescue@3: AutoOpenMail = true; Zerotorescue@91: self:ScheduleOpen(false); Zerotorescue@3: else Zerotorescue@91: self:Print(L["|cffff0000Disabling|r automatic opening of mail."]); Zerotorescue@3: Zerotorescue@3: AutoOpenMail = false; Zerotorescue@3: end Zerotorescue@0: end Zerotorescue@0: end); Zerotorescue@68: check.tooltipTitle = L["Mail Opener status"]; Zerotorescue@68: check.tooltip = L["Toggle automatic mail opening |cff00ff00on|r or |cffff0000off|r (you can also enforce this by holding shift when opening the mailbox).\n\nYou can toggle this addon |cff00ff00on|r or |cffff0000off|r by |cfffed000shift-clicking|r this checkbox."]; Zerotorescue@91: check:SetScript("OnEnter", function(cbSelf) Zerotorescue@91: if self.db.profile.general.showHelpTooltips then Zerotorescue@91: GameTooltip:SetOwner(cbSelf, "ANCHOR_BOTTOM") Zerotorescue@91: GameTooltip:SetPoint("BOTTOM", cbSelf, "BOTTOM") Zerotorescue@91: GameTooltip:SetText(cbSelf.tooltipTitle, 1, .82, 0, 1) Zerotorescue@51: Zerotorescue@91: if type(cbSelf.tooltip) == "string" then Zerotorescue@91: GameTooltip:AddLine(cbSelf.tooltip, 1, 1, 1, 1); Zerotorescue@51: end Zerotorescue@51: Zerotorescue@51: GameTooltip:Show(); Zerotorescue@50: end Zerotorescue@50: end); Zerotorescue@91: check:SetScript("OnLeave", function(cbSelf) Zerotorescue@50: GameTooltip:Hide(); Zerotorescue@50: end); Zerotorescue@0: Zerotorescue@0: -- Get reference to the text field Zerotorescue@0: local checkboxText = _G[check:GetName() .. "Text"]; Zerotorescue@68: checkboxText:SetText(L["Mail Opener"]); Zerotorescue@0: Zerotorescue@0: self.cbOpenAll = check; Zerotorescue@0: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: -- CONFIG BUTTON Zerotorescue@31: Zerotorescue@0: -- Make the config button Zerotorescue@0: local button = CreateFrame("Button", "btnMailOpenerConfig", MailFrame, "UIPanelButtonTemplate") Zerotorescue@68: button:SetText(L["Config"]) Zerotorescue@0: button:SetHeight(23) Zerotorescue@0: button:SetWidth(55) Zerotorescue@31: button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -55, -13); Zerotorescue@0: button:SetScript("OnClick", function() Zerotorescue@0: MailOpener:EnableConfigModule(); Zerotorescue@0: Zerotorescue@0: MailOpenerConfig:Show(); Zerotorescue@0: Zerotorescue@8: --BETA:if MailOpener.db.profile.uses >= 15 then Zerotorescue@7: --BETA: MailOpener:ShowBetaPopup(); Zerotorescue@7: --BETA:end Zerotorescue@0: end); Zerotorescue@68: button.tooltipTitle = L["Mail Opener Config"]; Zerotorescue@68: button.tooltip = L["Click to open the configuration window for Mail Opener."]; Zerotorescue@91: button:SetScript("OnEnter", function(btnSelf) Zerotorescue@91: if self.db.profile.general.showHelpTooltips then Zerotorescue@91: GameTooltip:SetOwner(btnSelf, "ANCHOR_BOTTOM") Zerotorescue@91: GameTooltip:SetPoint("BOTTOM", btnSelf, "TOP") Zerotorescue@91: GameTooltip:SetText(btnSelf.tooltipTitle, 1, .82, 0, 1) Zerotorescue@51: Zerotorescue@91: if type(btnSelf.tooltip) == "string" then Zerotorescue@91: GameTooltip:AddLine(btnSelf.tooltip, 1, 1, 1, 1); Zerotorescue@51: end Zerotorescue@51: Zerotorescue@51: GameTooltip:Show(); Zerotorescue@50: end Zerotorescue@50: end); Zerotorescue@91: button:SetScript("OnLeave", function(btnSelf) Zerotorescue@50: GameTooltip:Hide(); Zerotorescue@50: end); Zerotorescue@0: Zerotorescue@0: self.btnConfig = button; Zerotorescue@0: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: -- ADDON LOADING Zerotorescue@31: -- THE BELOW WILL TAKE SOME TIME; WE WILL BE LOADING OTHER ADDONS Zerotorescue@31: Zerotorescue@31: if select(6, GetAddOnInfo("Postal")) == nil then Zerotorescue@31: self.PostalEnabled = true; -- Set this as an object variable so we can use it in our modules Zerotorescue@0: Zerotorescue@31: -- Ensure this addon is loaded if AddonLoader is installed Zerotorescue@126: if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("Postal") and not Postal then Zerotorescue@31: AddonLoader:LoadAddOn("Postal"); Zerotorescue@31: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@118: if select(6, GetAddOnInfo("ZeroAuctions")) == nil then Zerotorescue@118: self.ZeroAuctionsEnabled = true; -- Set this as an object variable so we can use it in our modules Zerotorescue@116: Zerotorescue@116: -- Ensure this addon is loaded if AddonLoader is installed Zerotorescue@126: if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("ZeroAuctions") then Zerotorescue@116: AddonLoader:LoadAddOn("ZeroAuctions"); Zerotorescue@116: end Zerotorescue@31: end Zerotorescue@31: Zerotorescue@132: if select(6, GetAddOnInfo("AuctionProfitMaster")) == nil then Zerotorescue@132: self.ZeroAuctionsEnabled = true; -- Set this as an object variable so we can use it in our modules Zerotorescue@132: Zerotorescue@132: -- Ensure this addon is loaded if AddonLoader is installed Zerotorescue@132: if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("AuctionProfitMaster") then Zerotorescue@132: AddonLoader:LoadAddOn("AuctionProfitMaster"); Zerotorescue@132: end Zerotorescue@132: end Zerotorescue@132: Zerotorescue@154: if select(6, GetAddOnInfo("TradeSkillMaster_Mailing")) == nil then Zerotorescue@154: self.TSMMailingEnabled = true; -- Set this as an object variable so we can use it in our modules Zerotorescue@154: Zerotorescue@154: -- Ensure this addon is loaded if AddonLoader is installed Zerotorescue@154: if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("TradeSkillMaster_Mailing") then Zerotorescue@154: AddonLoader:LoadAddOn("TradeSkillMaster_Mailing"); Zerotorescue@154: end Zerotorescue@154: end Zerotorescue@154: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: Zerotorescue@31: -- ADJUST POSITIONS Zerotorescue@31: Zerotorescue@123: if self.ZeroAuctionsEnabled then Zerotorescue@31: -- QA is enabled so move the checkbox further to the right Zerotorescue@0: Zerotorescue@31: self.cbOpenAll:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 155, -13); Zerotorescue@31: end Zerotorescue@31: Zerotorescue@31: if self.PostalEnabled then Zerotorescue@31: self.btnConfig:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -75, -13); Zerotorescue@31: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:OnEnable() Zerotorescue@0: self:RegisterEvent("MAIL_SHOW"); Zerotorescue@0: self:RegisterEvent("PLAYER_ENTERING_WORLD"); Zerotorescue@0: Zerotorescue@0: self.btnConfig:Show(); Zerotorescue@0: Zerotorescue@139: -- Reset variables Zerotorescue@139: lastAmount = 0; Zerotorescue@139: self.debugChannel = nil; Zerotorescue@139: Zerotorescue@115: if not originalCheckInbox then Zerotorescue@115: -- Override the CheckInbox function Zerotorescue@115: -- Remember the original Zerotorescue@115: originalCheckInbox = CheckInbox; Zerotorescue@115: -- Then override that Zerotorescue@115: CheckInbox = NewCheckInbox; Zerotorescue@115: end Zerotorescue@115: Zerotorescue@0: -- If we were toggling this addon on while the mailbox is opened we must register all events again Zerotorescue@0: if MailFrame:IsVisible() then Zerotorescue@0: self:MAIL_SHOW(); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:OnDisable() Zerotorescue@0: self:UnregisterEvent("MAIL_SHOW"); Zerotorescue@0: Zerotorescue@0: self.btnConfig:Hide(); Zerotorescue@0: Zerotorescue@115: if originalCheckInbox then Zerotorescue@115: -- Change checkinbox back to the original value Zerotorescue@115: CheckInbox = originalCheckInbox; Zerotorescue@115: -- Forget the other reference Zerotorescue@115: originalCheckInbox = nil; Zerotorescue@115: end Zerotorescue@115: Zerotorescue@0: MailOpener:Stop(); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- We must disable Quick Auction's auto mail (if set up that way in the settings) before opening the mailbox or it will instantly start sending stuff Zerotorescue@0: function MailOpener:PLAYER_ENTERING_WORLD() Zerotorescue@0: self:UnregisterEvent("PLAYER_ENTERING_WORLD"); Zerotorescue@0: Zerotorescue@0: self:ToggleQAStatus(); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Fired when the mailbox is opened Zerotorescue@0: function MailOpener:MAIL_SHOW() Zerotorescue@0: -- To stop the timer when the mailbox is closed Zerotorescue@0: self:RegisterEvent("MAIL_CLOSED", "Stop"); Zerotorescue@0: self:RegisterEvent("PLAYER_LEAVING_WORLD", "Stop"); Zerotorescue@0: Zerotorescue@0: -- To set the timer for when to refresh again Zerotorescue@0: self:RegisterEvent("MAIL_INBOX_UPDATE"); Zerotorescue@0: Zerotorescue@0: -- We need to know when opening has completed Zerotorescue@0: self:RegisterMessage("MO_OPEN_COMPLETE"); Zerotorescue@0: Zerotorescue@19: if self.db.profile.uses == 0 and MailOpener.db.profile.general.defaultStatus ~= "_enabled" then Zerotorescue@19: StaticPopupDialogs["MailOpenerFirstUseConfirmBox"] = { Zerotorescue@68: text = L["You are using |cff15ff00Mail Opener|r for the first time. Do you wish to always |cf00ff000enable|r |cfffed000automatic mail opening when you open the mailbox|r?\n\nYou can always change the standard behavior in the General options."], Zerotorescue@68: button1 = L["Yes"], Zerotorescue@68: button2 = L["No"], Zerotorescue@19: OnAccept = function() Zerotorescue@19: MailOpener.db.profile.general.defaultStatus = "_enabled"; Zerotorescue@85: MailOpener:Print(L["You can always change the default status in the General config (|cff00ffff/mo c|r)."]); Zerotorescue@19: Zerotorescue@85: MailOpener:Print(L["|cff00ff00Enabling|r automatic opening of mail."]); Zerotorescue@19: MailOpener.cbOpenAll:SetChecked(true); Zerotorescue@19: Zerotorescue@19: AutoOpenMail = true; Zerotorescue@19: MailOpener:ScheduleOpen(false); Zerotorescue@19: end, Zerotorescue@91: OnCancel = function () Zerotorescue@85: MailOpener:Print(L["You can always change the default status in the General config (|cff00ffff/mo c|r)."]); Zerotorescue@19: end, Zerotorescue@19: timeout = 0, Zerotorescue@19: whileDead = 1, Zerotorescue@19: hideOnEscape = 1, Zerotorescue@19: }; Zerotorescue@19: StaticPopup_Show("MailOpenerFirstUseConfirmBox"); Zerotorescue@8: end Zerotorescue@8: Zerotorescue@8: self.db.profile.uses = ( self.db.profile.uses + 1 ); Zerotorescue@8: Zerotorescue@0: self:Debug("defaultStatus:" .. self.db.profile.general.defaultStatus); Zerotorescue@0: -- Change the mail opening status according to our settings Zerotorescue@0: if self.db.profile.general.defaultStatus == "_enabled" then Zerotorescue@3: AutoOpenMail = true; Zerotorescue@3: self.cbOpenAll:SetChecked(true); Zerotorescue@3: elseif self.db.profile.general.defaultStatus == "disabled" then Zerotorescue@3: -- Disable auto opening but leave mail opener enabled Zerotorescue@3: Zerotorescue@3: AutoOpenMail = false; Zerotorescue@3: self.cbOpenAll:SetChecked(false); Zerotorescue@3: elseif self.db.profile.general.defaultStatus == "xdisabled" then Zerotorescue@3: -- Disable entire addon Zerotorescue@3: Zerotorescue@3: MailOpener:Disable(); Zerotorescue@3: self.cbOpenAll:SetChecked(false); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@46: if IsShiftKeyDown() then Zerotorescue@68: self:Print(L["|cffff0000Disabling|r automatic opening of mail, shift key was down when opening the mailbox."]); Zerotorescue@46: Zerotorescue@46: AutoOpenMail = false; Zerotorescue@46: self.cbOpenAll:SetChecked(false); Zerotorescue@46: end Zerotorescue@46: Zerotorescue@0: self:ToggleQAStatus(); Zerotorescue@0: Zerotorescue@0: -- Hide the InboxTooMuchMail warning to allow room for our mail remaining info line Zerotorescue@0: InboxTooMuchMail:Hide() Zerotorescue@0: InboxTooMuchMail.Show = function() end Zerotorescue@0: Zerotorescue@118: if self.ZeroAuctionsEnabled then Zerotorescue@132: local AHAddon = LibStub("AceAddon-3.0"):GetAddon("ZeroAuctions", true) or LibStub("AceAddon-3.0"):GetAddon("AuctionProfitMaster", true); Zerotorescue@132: if AHAddon then Zerotorescue@132: local QAMail = AHAddon:GetModule("Mail", true); Zerotorescue@132: Zerotorescue@132: if QAMail then Zerotorescue@143: if QAMail.massOpening then Zerotorescue@143: -- Hide the open all button Zerotorescue@143: QAMail.massOpening:Hide(); Zerotorescue@143: end Zerotorescue@143: if QAMail.totalMail then Zerotorescue@143: -- Hide the x mail remaining text Zerotorescue@143: QAMail.totalMail:Hide(); Zerotorescue@143: end Zerotorescue@132: end Zerotorescue@8: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@108: hasOpenedMailAlready = nil; Zerotorescue@0: mailboxEmptySoundPlayed = nil; Zerotorescue@42: mailboxEmptySoundPlayedThisVisit = nil; Zerotorescue@0: Zerotorescue@0: self:Recheck(); Zerotorescue@0: Zerotorescue@0: if self.db.profile.general.continueOpening then Zerotorescue@6: -- Continue opening mail, but use the "initial mail opening interval" as time Zerotorescue@6: self:ScheduleOpen(false); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Fired after a successful server sync Zerotorescue@0: -- Fired when mail is deleted (which happens after taking all attachments from a mail sent by the game) Zerotorescue@0: function MailOpener:MAIL_INBOX_UPDATE() Zerotorescue@0: local current, total = GetInboxNumItems(); Zerotorescue@0: Zerotorescue@3: -- Calculate the amount of mail waiting that actually have attachments Zerotorescue@3: -- If we just compare numbers we won't be including mail that isn't automatically deleted when opened, such as mail with attachments sent by other players Zerotorescue@3: local currentMailWithAttachments = 0; Zerotorescue@3: for i = 1, current do Zerotorescue@3: local _, _, _, _, money, _, _, items = GetInboxHeaderInfo(i); Zerotorescue@3: Zerotorescue@3: if (items and items > 0) or (money and money > 0) then Zerotorescue@3: currentMailWithAttachments = currentMailWithAttachments + 1; Zerotorescue@3: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@3: local tempLastAmount = lastAmount; Zerotorescue@3: lastAmount = currentMailWithAttachments; Zerotorescue@3: Zerotorescue@11: --if currentMailWithAttachments ~= tempLastAmount then Zerotorescue@11: -- self:Debug("MAIL_INBOX_UPDATE - lastAmount:" .. tempLastAmount .. " - current:" .. currentMailWithAttachments); Zerotorescue@11: --end Zerotorescue@3: Zerotorescue@3: if currentMailWithAttachments > tempLastAmount then Zerotorescue@0: -- New messages arrived in our mailbox, so this was a refresh, so set a timer Zerotorescue@0: Zerotorescue@3: self:Debug("MO_SERVER_SYNCED"); Zerotorescue@3: Zerotorescue@0: -- Yell that we successfully synced with the server Zerotorescue@0: self:SendMessage("MO_SERVER_SYNCED"); Zerotorescue@0: Zerotorescue@29: if MailAddonBusy == MailOpener:GetName() then Zerotorescue@29: MailAddonBusy = nil; Zerotorescue@29: end Zerotorescue@29: Zerotorescue@0: -- This list is fresh Zerotorescue@0: freshList = true; Zerotorescue@0: mailboxEmptySoundPlayed = nil; Zerotorescue@0: Zerotorescue@0: -- Stop previous timer Zerotorescue@0: self:CancelTimer(self.tmrRecheck, true); Zerotorescue@0: -- More will arrive in 60 seconds Zerotorescue@0: self.tmrRecheck = self:ScheduleTimer(function() Zerotorescue@0: self:Debug("tmrRecheck 61 finished"); Zerotorescue@0: Zerotorescue@0: -- We can get a fresh list now, so query the server Zerotorescue@0: freshList = false; Zerotorescue@0: Zerotorescue@0: -- Look for mail Zerotorescue@0: self:Recheck(); Zerotorescue@0: end, 61); Zerotorescue@0: self:Debug("tmrRecheck 61"); Zerotorescue@0: Zerotorescue@46: -- Open the current mail Zerotorescue@46: self:ScheduleOpen(false); Zerotorescue@3: elseif currentMailWithAttachments < tempLastAmount then Zerotorescue@2: -- We lost a mail Zerotorescue@2: Zerotorescue@19: --TODO: NYI: May need to delay this until the mail is actually deleted to keep the mail count more realtime Zerotorescue@3: Zerotorescue@3: self:Debug("MO_MAIL_EMPTIED"); Zerotorescue@3: Zerotorescue@2: -- Yell that we successfully opened/removed a mail Zerotorescue@3: self:SendMessage("MO_MAIL_EMPTIED"); Zerotorescue@3: elseif (currentMailWithAttachments == 50 and tempLastAmount == 50) then Zerotorescue@46: -- Open the current mail Zerotorescue@46: self:ScheduleOpen(false); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:ScheduleOpen(continued) Zerotorescue@0: if lastAmount > 0 then Zerotorescue@0: local waitTime; Zerotorescue@0: if continued then Zerotorescue@0: waitTime = self.db.profile.general.waitTime; Zerotorescue@0: else Zerotorescue@0: -- Even though this is not a continuation and should be instant, we set a .5 second timer to prevent multiple calls of the OpenNow function Zerotorescue@0: waitTime = self.db.profile.general.initialDelay; Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Stop previous timer Zerotorescue@0: self:CancelTimer(self.tmrOpenNow, true); Zerotorescue@0: -- Schedule the next open Zerotorescue@0: self.tmrOpenNow = self:ScheduleTimer("OpenNow", waitTime); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:OpenNow() Zerotorescue@8: self:Debug("OpenNow (" .. ((MailAddonBusy and "1") or "0") .. ")"); Zerotorescue@8: if MailFrame:IsVisible() and AutoOpenMail then Zerotorescue@0: self:Debug("OpenNow"); Zerotorescue@0: Zerotorescue@0: -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that Zerotorescue@31: --local BeanCounterActive = not InboxCloseButton:IsVisible(); Zerotorescue@0: Zerotorescue@31: --if not BeanCounterActive and not MailAddonBusy then Zerotorescue@31: if not MailAddonBusy then Zerotorescue@8: -- No other addon is currently active Zerotorescue@0: Zerotorescue@0: self:CancelTimer(self.tmrTryAgain, true); -- Insurance Zerotorescue@0: Zerotorescue@118: if self.ZeroAuctionsEnabled and ZeroAuctionsAutoMail then Zerotorescue@118: -- Remember the last known quick auctions status Zerotorescue@118: lastQuickAuctionsStatus = ZeroAuctionsAutoMail:GetChecked(); Zerotorescue@118: end Zerotorescue@118: if self.db.profile.general.autoDisableQAAutoMail and self.ZeroAuctionsEnabled and ZeroAuctionsAutoMail and ZeroAuctionsAutoMail:GetChecked() then Zerotorescue@118: -- If auto disable "QA Auto mail" is enabled and QA's auto mail is currently toggled on, turn it off Zerotorescue@118: -- We need to do this with a :click to trigger the right events Zerotorescue@118: Zerotorescue@118: self:Debug("Turning automail |cffff0000off|r."); Zerotorescue@118: Zerotorescue@118: ZeroAuctionsAutoMail:Click(); Zerotorescue@118: end Zerotorescue@118: Zerotorescue@0: Zerotorescue@8: MailAddonBusy = self:GetName(); Zerotorescue@0: Zerotorescue@0: self:Debug("MO_OPEN_MAIL"); Zerotorescue@0: Zerotorescue@0: -- Summon the mail opening gods Zerotorescue@0: self:SendMessage("MO_OPEN_MAIL"); Zerotorescue@129: elseif MailAddonBusy ~= self:GetName() then Zerotorescue@8: -- Another addon is ACTIVE Zerotorescue@31: self:Debug("Another addon active, waiting .5 seconds... (" .. MailAddonBusy .. ")"); Zerotorescue@0: Zerotorescue@0: self:CancelTimer(self.tmrTryAgain, true); -- Insurance Zerotorescue@8: -- Try again every 0.5 seconds Zerotorescue@0: self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:MO_OPEN_COMPLETE() Zerotorescue@8: if MailAddonBusy == self:GetName() then Zerotorescue@8: MailAddonBusy = nil; Zerotorescue@8: end Zerotorescue@1: Zerotorescue@108: hasOpenedMailAlready = true; Zerotorescue@108: Zerotorescue@1: -- Try a recheck Zerotorescue@1: self:Recheck(); Zerotorescue@1: Zerotorescue@0: local current, total = GetInboxNumItems(); Zerotorescue@0: Zerotorescue@0: if (total - current) == 0 then Zerotorescue@3: -- There is probably no unopenable mail remaining, so play the sound (if enabled) Zerotorescue@3: Zerotorescue@42: 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 Zerotorescue@0: PlaySoundFile(self.db.profile.notifications.mailboxEmptySoundFile); Zerotorescue@0: mailboxEmptySoundPlayed = true; Zerotorescue@42: mailboxEmptySoundPlayedThisVisit = true; Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@118: if self.ZeroAuctionsEnabled then Zerotorescue@118: -- Zero Auctions enabled? Zerotorescue@118: -- Toggle automailing as per settings Zerotorescue@118: Zerotorescue@118: if self.db.profile.general.autoReenableQAAutoMail and ZeroAuctionsAutoMail and not ZeroAuctionsAutoMail:GetChecked() then Zerotorescue@118: -- If auto re-enable "QA Auto mail" is enabled and QA's auto mail is currently toggled OFF, turn it on Zerotorescue@118: -- We need to do this with a :click to trigger the right events Zerotorescue@118: Zerotorescue@118: self:Debug("Turning automail |cff00ff00on|r."); Zerotorescue@118: Zerotorescue@118: ZeroAuctionsAutoMail:Click(); Zerotorescue@118: elseif self.db.profile.general.autoSetBackQAAutoMail and ZeroAuctionsAutoMail and lastQuickAuctionsStatus ~= ZeroAuctionsAutoMail:GetChecked() then Zerotorescue@118: -- If auto set back "QA Auto mail" is enabled and QA's auto mail is currently not the same as it was before starting, toggle it Zerotorescue@118: -- We need to do this with a :click to trigger the right events Zerotorescue@118: Zerotorescue@118: if lastQuickAuctionsStatus then Zerotorescue@118: self:Debug("Turning automail |cff00ff00on|r."); Zerotorescue@118: else Zerotorescue@118: self:Debug("Turning automail |cffff0000off|r."); Zerotorescue@118: end Zerotorescue@118: Zerotorescue@118: ZeroAuctionsAutoMail:Click(); Zerotorescue@118: end Zerotorescue@118: end Zerotorescue@118: Zerotorescue@0: if self.db.profile.general.continueOpening then Zerotorescue@0: self:ScheduleOpen(true); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Run another CheckInbox Zerotorescue@0: function MailOpener:Recheck() Zerotorescue@0: self:Debug("|cffffff00Recheck|r"); Zerotorescue@0: Zerotorescue@0: -- Freshlist prevents this from being run too often Zerotorescue@0: -- It is set to true after a server sync Zerotorescue@0: -- and set to false 61 seconds afterwards with a recheck called instantly after it Zerotorescue@3: Zerotorescue@3: -- We're not refreshing while we're opening because it is automatically done when current batch was completely opened Zerotorescue@8: if not freshList and MailFrame:IsVisible() then Zerotorescue@0: self:Debug("|cff00ff00Recheck|r"); Zerotorescue@0: Zerotorescue@0: -- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed Zerotorescue@0: Zerotorescue@0: -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that Zerotorescue@31: --local BeanCounterActive = not InboxCloseButton:IsVisible(); Zerotorescue@0: Zerotorescue@31: --if not BeanCounterActive and AutoOpenMail and not MailAddonBusy then Zerotorescue@31: if AutoOpenMail and not MailAddonBusy then Zerotorescue@0: -- Query the server Zerotorescue@0: CheckInbox(); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Stop previous timer Zerotorescue@0: self:CancelTimer(self.tmrRecheck, true); Zerotorescue@0: -- Keep trying until it works Zerotorescue@0: self.tmrRecheck = self:ScheduleTimer("Recheck", 2); Zerotorescue@0: Zerotorescue@0: self:Debug("tmrRecheck 2"); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Stop checking for new mail and unregister the events we needed Zerotorescue@0: function MailOpener:Stop() Zerotorescue@8: if MailAddonBusy == self:GetName() then Zerotorescue@8: MailAddonBusy = nil; Zerotorescue@8: end Zerotorescue@0: Zerotorescue@108: hasOpenedMailAlready = nil; Zerotorescue@108: Zerotorescue@0: -- We won't need this anymore Zerotorescue@0: self:UnregisterEvent("MAIL_CLOSED"); Zerotorescue@0: self:UnregisterEvent("PLAYER_LEAVING_WORLD"); Zerotorescue@0: self:UnregisterEvent("MAIL_INBOX_UPDATE"); Zerotorescue@0: Zerotorescue@0: -- Messages Zerotorescue@0: self:UnregisterMessage("MO_OPEN_COMPLETE"); Zerotorescue@0: Zerotorescue@0: -- Timers Zerotorescue@0: self:CancelTimer(self.tmrTryAgain, true); Zerotorescue@0: self:CancelTimer(self.tmrOpenNow, true); Zerotorescue@0: Zerotorescue@0: -- If we wait with disabling QA automail until MAIL_SHOW, QA will beat us to it and already start sending stuff Zerotorescue@0: self:ToggleQAStatus(); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:Debug(t) Zerotorescue@0: if not self.debugChannel and self.debugChannel ~= false then Zerotorescue@0: -- We want to check just once, so if you add a debug channel later just do a /reload (registering an event for this is wasted resources) Zerotorescue@0: self.debugChannel = false; Zerotorescue@0: Zerotorescue@0: for i = 1, NUM_CHAT_WINDOWS do Zerotorescue@0: local name = GetChatWindowInfo(i); Zerotorescue@0: Zerotorescue@0: if name:upper() == "DEBUG" then Zerotorescue@0: self.debugChannel = _G["ChatFrame" .. i]; Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: if self.debugChannel then Zerotorescue@0: self.debugChannel:AddMessage(t); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@68: function MailOpener:Print(text) Zerotorescue@68: print(L["|cff15ff00Mail Opener|r: %s"]:format(text)); Zerotorescue@68: end Zerotorescue@68: Zerotorescue@0: -- Enable our config module if it's disabled and make a reference to it Zerotorescue@0: function MailOpener:EnableConfigModule() Zerotorescue@0: if not MailOpenerConfig then Zerotorescue@0: MailOpenerConfig = self:GetModule("Config"); Zerotorescue@0: MailOpenerConfig:Enable(); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Toggle Postal's opening modules on or off Zerotorescue@0: function MailOpener:TogglePostalModule(name, status) Zerotorescue@60: if self.PostalEnabled and Postal then Zerotorescue@0: -- Postal must be enabled Zerotorescue@0: Zerotorescue@3: -- Toggle module (let Postal handle this) Zerotorescue@3: Postal.ToggleModule(nil, name, Postal:GetModule(name), status); Zerotorescue@0: end Zerotorescue@154: Zerotorescue@154: if self.TSMMailingEnabled then Zerotorescue@154: local TSMMailing = LibStub("AceAddon-3.0"):GetAddon("TradeSkillMaster_Mailing"); Zerotorescue@154: if TSMMailing and TSMMailing.massOpening then Zerotorescue@159: if not status then Zerotorescue@159: TSMMailing.massOpening:Hide(); Zerotorescue@159: else Zerotorescue@159: TSMMailing.massOpening:Show(); Zerotorescue@159: end Zerotorescue@154: end Zerotorescue@154: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Change Quick Auction's auto mail status based on our prefered settings Zerotorescue@0: function MailOpener:ToggleQAStatus() Zerotorescue@0: self:Debug("defaultQAStatus:" .. self.db.profile.general.defaultQAStatus); Zerotorescue@0: Zerotorescue@118: if self.ZeroAuctionsEnabled and self.db.profile.general.defaultQAStatus ~= "__remember" and ZeroAuctionsAutoMail then Zerotorescue@118: if self.db.profile.general.defaultQAStatus == "_enabled" and not ZeroAuctionsAutoMail:GetChecked() then Zerotorescue@118: self:Debug("Turning automail |cff00ff00on|r."); Zerotorescue@118: Zerotorescue@118: ZeroAuctionsAutoMail:Click(); Zerotorescue@118: elseif self.db.profile.general.defaultQAStatus == "disabled" and ZeroAuctionsAutoMail:GetChecked() then Zerotorescue@118: self:Debug("Turning automail |cffff0000off|r."); Zerotorescue@118: Zerotorescue@118: ZeroAuctionsAutoMail:Click(); Zerotorescue@118: end Zerotorescue@118: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:FormatMoney(copper) Zerotorescue@0: local gold = floor( copper / 10000 ); Zerotorescue@0: local silver = floor( ( copper - ( gold * 10000 ) ) / 100 ); Zerotorescue@0: local copper = mod(copper, 100); Zerotorescue@0: Zerotorescue@0: if gold > 0 then Zerotorescue@0: return format(GOLD_AMOUNT_TEXTURE .. " " .. SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, gold, 0, 0, silver, 0, 0, copper, 0, 0); Zerotorescue@0: elseif silver > 0 then Zerotorescue@0: return format(SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, silver, 0, 0, copper, 0, 0); Zerotorescue@0: else Zerotorescue@0: return format(COPPER_AMOUNT_TEXTURE, copper, 0, 0); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@7: -- General copy window for multiple things (clickable URLs, the time remaining, and such) Zerotorescue@0: StaticPopupDialogs["MailOpenerCopyWindow"] = { Zerotorescue@68: text = L["Press CTRL-C to copy."], Zerotorescue@0: button2 = CLOSE, Zerotorescue@0: hasEditBox = 1, Zerotorescue@123: editBoxWidth = 360, Zerotorescue@123: OnShow = function(self) Zerotorescue@123: if self.editBox and MailOpener.currentPopupContents then Zerotorescue@123: self.editBox:SetText(MailOpener.currentPopupContents); Zerotorescue@123: self.editBox:SetFocus(); Zerotorescue@123: self.editBox:HighlightText(0); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Position the close button in the middle Zerotorescue@123: if self.button2 then Zerotorescue@0: -- Remove previous know position Zerotorescue@123: self.button2:ClearAllPoints(); Zerotorescue@123: self.button2:SetWidth(200); Zerotorescue@0: -- Reposition in the center Zerotorescue@123: self.button2:SetPoint("CENTER", self.editBox, "CENTER", 0, -30); Zerotorescue@0: end Zerotorescue@0: end, Zerotorescue@92: EditBoxOnEscapePressed = function(self) Zerotorescue@92: self:GetParent():Hide(); Zerotorescue@0: end, Zerotorescue@0: timeout = 0, Zerotorescue@0: whileDead = 1, Zerotorescue@0: hideOnEscape = 1, Zerotorescue@0: maxLetters = 1024, Zerotorescue@1: }; Zerotorescue@1: Zerotorescue@0: Zerotorescue@108: -- The idea for this is to wait with refresing while there is still mail remaining which can be opened Zerotorescue@108: -- This should speed things up a tiny bit, but might become buggy if coded wrong Zerotorescue@115: -- We actually override the function in the onenable Zerotorescue@115: function NewCheckInbox(...) Zerotorescue@139: if not MailOpener.db.profile.general.overrideCheckInbox or not MailOpener.db.profile.general.continueOpening or not lastAmount or lastAmount == 0 then Zerotorescue@108: -- If the override Check Inbox option is off Zerotorescue@108: -- or continuous opening is off Zerotorescue@108: -- or there's currently no mail visible Zerotorescue@0: Zerotorescue@115: MailOpener:Debug("CheckInbox:" .. tostring((not MailOpener.db.profile.general.overrideCheckInbox)) .. "/" .. tostring((not MailOpener.db.profile.general.continueOpening)) .. "/" .. tostring(lastAmount == 0)); Zerotorescue@0: Zerotorescue@108: -- Just call the original function Zerotorescue@108: return originalCheckInbox(...); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@108: if not hasOpenedMailAlready then Zerotorescue@108: -- If MO hasn't opened mail yet, we wait. Zerotorescue@108: -- MO will call this function when mail opening is done Zerotorescue@0: Zerotorescue@108: MailOpener:Debug("CheckInbox:Waiting..."); Zerotorescue@0: Zerotorescue@108: return false; Zerotorescue@108: else Zerotorescue@108: MailOpener:Debug("CheckInbox:Refresh!"); Zerotorescue@108: Zerotorescue@108: return originalCheckInbox(...); Zerotorescue@108: end Zerotorescue@139: end