Mercurial > wow > mailopener
diff Core.lua @ 174:463e29ca6b08
More merging'
| author | Zachary Kotlarek <zach@kotlarek.com> |
|---|---|
| date | Sun, 10 Mar 2013 16:08:39 -0700 |
| parents | 86d9e008b0ad |
| children |
line wrap: on
line diff
--- a/Core.lua Sun Mar 10 15:59:03 2013 -0700 +++ b/Core.lua Sun Mar 10 16:08:39 2013 -0700 @@ -6,7 +6,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, mailboxEmptySoundPlayedThisVisit; +local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed, mailboxEmptySoundPlayedThisVisit, hasOpenedMailAlready, originalCheckInbox; function MailOpener:OnInitialize() self:Debug("OnInitialize"); @@ -33,6 +33,7 @@ continueOpening = false, waitTime = 5, initialDelay = 0.5, + overrideCheckInbox = true, }, modules = { BeanCounterSupport = true, @@ -145,15 +146,20 @@ local frame = CreateFrame("Frame", nil, UIParent); frame:Hide(); frame.name = "Mail Opener"; + frame.fresh = true; frame:HookScript("OnShow", function(self) - -- Enable the config module - MailOpener:EnableConfigModule(); - - -- Load the options and add it to the blizzard interface list - MailOpenerConfig:Load(); - - -- Refresh the frame to instantly show the right options - InterfaceOptionsFrame_OpenToCategory(self.name) + if self.fresh then + self.fresh = nil; + + -- Enable the config module + MailOpener:EnableConfigModule(); + + -- Load the options and add it to the blizzard interface list + MailOpenerConfig:Load(); + + -- Refresh the frame to instantly show the right options + InterfaceOptionsFrame_OpenToCategory(self.name); + end end); -- And add it to the interface options InterfaceOptions_AddCategory(frame); @@ -283,27 +289,45 @@ self.PostalEnabled = true; -- Set this as an object variable so we can use it in our modules -- Ensure this addon is loaded if AddonLoader is installed - if AddonLoader and AddonLoader.LoadAddOn and not Postal then + if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("Postal") and not Postal then AddonLoader:LoadAddOn("Postal"); end end - if select(6, GetAddOnInfo("QuickAuctions")) == nil then - self.QuickAuctionsEnabled = true; -- Set this as an object variable so we can use it in our modules + if select(6, GetAddOnInfo("ZeroAuctions")) == nil then + self.ZeroAuctionsEnabled = true; -- Set this as an object variable so we can use it in our modules -- Ensure this addon is loaded if AddonLoader is installed - if AddonLoader and AddonLoader.LoadAddOn then - AddonLoader:LoadAddOn("QuickAuctions"); + if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("ZeroAuctions") then + AddonLoader:LoadAddOn("ZeroAuctions"); end end + if select(6, GetAddOnInfo("AuctionProfitMaster")) == nil then + self.ZeroAuctionsEnabled = true; -- Set this as an object variable so we can use it in our modules + + -- Ensure this addon is loaded if AddonLoader is installed + if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("AuctionProfitMaster") then + AddonLoader:LoadAddOn("AuctionProfitMaster"); + end + end + + if select(6, GetAddOnInfo("TradeSkillMaster_Mailing")) == nil then + self.TSMMailingEnabled = true; -- Set this as an object variable so we can use it in our modules + + -- Ensure this addon is loaded if AddonLoader is installed + if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("TradeSkillMaster_Mailing") then + AddonLoader:LoadAddOn("TradeSkillMaster_Mailing"); + end + end + -- ADJUST POSITIONS - if self.QuickAuctionsEnabled then + if self.ZeroAuctionsEnabled then -- QA is enabled so move the checkbox further to the right self.cbOpenAll:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 155, -13); @@ -324,10 +348,13 @@ lastAmount = 0; self.debugChannel = nil; - --BETA:if (self.db.profile.uses % 15) == 0 then - --BETA: -- Automatically show once every 15 uses - --BETA: self:ShowBetaPopup(); - --BETA:end + if not originalCheckInbox then + -- Override the CheckInbox function + -- Remember the original + originalCheckInbox = CheckInbox; + -- Then override that + CheckInbox = NewCheckInbox; + end -- If we were toggling this addon on while the mailbox is opened we must register all events again if MailFrame:IsVisible() then @@ -340,6 +367,13 @@ self.btnConfig:Hide(); + if originalCheckInbox then + -- Change checkinbox back to the original value + CheckInbox = originalCheckInbox; + -- Forget the other reference + originalCheckInbox = nil; + end + MailOpener:Stop(); end @@ -419,17 +453,25 @@ InboxTooMuchMail:Hide() InboxTooMuchMail.Show = function() end - if self.QuickAuctionsEnabled then - local QAMail = LibStub("AceAddon-3.0"):GetAddon("QuickAuctions", true):GetModule("Mail", true); - - if QAMail then - -- Hide the open all button - QAMail.massOpening:Hide(); - -- Hide the x mail remaining text - QAMail.totalMail:Hide(); + if self.ZeroAuctionsEnabled then + local AHAddon = LibStub("AceAddon-3.0"):GetAddon("ZeroAuctions", true) or LibStub("AceAddon-3.0"):GetAddon("AuctionProfitMaster", true); + if AHAddon then + local QAMail = AHAddon:GetModule("Mail", true); + + if QAMail then + if QAMail.massOpening then + -- Hide the open all button + QAMail.massOpening:Hide(); + end + if QAMail.totalMail then + -- Hide the x mail remaining text + QAMail.totalMail:Hide(); + end + end end end + hasOpenedMailAlready = nil; mailboxEmptySoundPlayed = nil; mailboxEmptySoundPlayedThisVisit = nil; @@ -542,26 +584,27 @@ self:CancelTimer(self.tmrTryAgain, true); -- Insurance - if QuickAuctionsAutoMail then + if self.ZeroAuctionsEnabled and ZeroAuctionsAutoMail then -- Remember the last known quick auctions status - lastQuickAuctionsStatus = QuickAuctionsAutoMail:GetChecked(); + lastQuickAuctionsStatus = ZeroAuctionsAutoMail:GetChecked(); end - if self.db.profile.general.autoDisableQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and QuickAuctionsAutoMail:GetChecked() then + if self.db.profile.general.autoDisableQAAutoMail and self.ZeroAuctionsEnabled and ZeroAuctionsAutoMail and ZeroAuctionsAutoMail:GetChecked() then -- If auto disable "QA Auto mail" is enabled and QA's auto mail is currently toggled on, turn it off -- We need to do this with a :click to trigger the right events self:Debug("Turning automail |cffff0000off|r."); - QuickAuctionsAutoMail:Click(); + ZeroAuctionsAutoMail:Click(); end + MailAddonBusy = self:GetName(); self:Debug("MO_OPEN_MAIL"); -- Summon the mail opening gods self:SendMessage("MO_OPEN_MAIL"); - else + elseif MailAddonBusy ~= self:GetName() then -- Another addon is ACTIVE self:Debug("Another addon active, waiting .5 seconds... (" .. MailAddonBusy .. ")"); @@ -577,6 +620,8 @@ MailAddonBusy = nil; end + hasOpenedMailAlready = true; + -- Try a recheck self:Recheck(); @@ -592,18 +637,18 @@ end end - if self.QuickAuctionsEnabled then - -- Quick Auctions enabled? + if self.ZeroAuctionsEnabled then + -- Zero Auctions enabled? -- Toggle automailing as per settings - if self.db.profile.general.autoReenableQAAutoMail and QuickAuctionsAutoMail and not QuickAuctionsAutoMail:GetChecked() then + if self.db.profile.general.autoReenableQAAutoMail and ZeroAuctionsAutoMail and not ZeroAuctionsAutoMail:GetChecked() then -- If auto re-enable "QA Auto mail" is enabled and QA's auto mail is currently toggled OFF, turn it on -- We need to do this with a :click to trigger the right events self:Debug("Turning automail |cff00ff00on|r."); - QuickAuctionsAutoMail:Click(); - elseif self.db.profile.general.autoSetBackQAAutoMail and QuickAuctionsAutoMail and lastQuickAuctionsStatus ~= QuickAuctionsAutoMail:GetChecked() then + ZeroAuctionsAutoMail:Click(); + elseif self.db.profile.general.autoSetBackQAAutoMail and ZeroAuctionsAutoMail and lastQuickAuctionsStatus ~= ZeroAuctionsAutoMail:GetChecked() then -- 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 -- We need to do this with a :click to trigger the right events @@ -613,7 +658,7 @@ self:Debug("Turning automail |cffff0000off|r."); end - QuickAuctionsAutoMail:Click(); + ZeroAuctionsAutoMail:Click(); end end @@ -640,7 +685,8 @@ --local BeanCounterActive = not InboxCloseButton:IsVisible(); --if not BeanCounterActive and AutoOpenMail and not MailAddonBusy then - if AutoOpenMail and not MailAddonBusy then + --if AutoOpenMail and not MailAddonBusy then + if not MailAddonBusy then -- Query the server CheckInbox(); end @@ -660,6 +706,8 @@ MailAddonBusy = nil; end + hasOpenedMailAlready = nil; + -- We won't need this anymore self:UnregisterEvent("MAIL_CLOSED"); self:UnregisterEvent("PLAYER_LEAVING_WORLD"); @@ -715,21 +763,32 @@ -- Toggle module (let Postal handle this) Postal.ToggleModule(nil, name, Postal:GetModule(name), status); end + + if self.TSMMailingEnabled then + local TSMMailing = LibStub("AceAddon-3.0"):GetAddon("TradeSkillMaster_Mailing"); + if TSMMailing and TSMMailing.massOpening then + if not status then + TSMMailing.massOpening:Hide(); + else + TSMMailing.massOpening:Show(); + end + end + end end -- Change Quick Auction's auto mail status based on our prefered settings function MailOpener:ToggleQAStatus() self:Debug("defaultQAStatus:" .. self.db.profile.general.defaultQAStatus); - if self.QuickAuctionsEnabled and self.db.profile.general.defaultQAStatus ~= "__remember" and QuickAuctionsAutoMail then - if self.db.profile.general.defaultQAStatus == "_enabled" and not QuickAuctionsAutoMail:GetChecked() then + if self.ZeroAuctionsEnabled and self.db.profile.general.defaultQAStatus ~= "__remember" and ZeroAuctionsAutoMail then + if self.db.profile.general.defaultQAStatus == "_enabled" and not ZeroAuctionsAutoMail:GetChecked() then self:Debug("Turning automail |cff00ff00on|r."); - QuickAuctionsAutoMail:Click(); - elseif self.db.profile.general.defaultQAStatus == "disabled" and QuickAuctionsAutoMail:GetChecked() then + ZeroAuctionsAutoMail:Click(); + elseif self.db.profile.general.defaultQAStatus == "disabled" and ZeroAuctionsAutoMail:GetChecked() then self:Debug("Turning automail |cffff0000off|r."); - QuickAuctionsAutoMail:Click(); + ZeroAuctionsAutoMail:Click(); end end end @@ -753,23 +812,21 @@ text = L["Press CTRL-C to copy."], button2 = CLOSE, hasEditBox = 1, - hasWideEditBox = 1, - OnShow = function() - local editBox = _G[this:GetName().."WideEditBox"]; - if editBox and MailOpener.currentPopupContents then - editBox:SetText(MailOpener.currentPopupContents); - editBox:SetFocus(); - editBox:HighlightText(0); + editBoxWidth = 360, + OnShow = function(self) + if self.editBox and MailOpener.currentPopupContents then + self.editBox:SetText(MailOpener.currentPopupContents); + self.editBox:SetFocus(); + self.editBox:HighlightText(0); end -- Position the close button in the middle - local button = _G[this:GetName().."Button2"]; - if button then + if self.button2 then -- Remove previous know position - button:ClearAllPoints(); - button:SetWidth(200); + self.button2:ClearAllPoints(); + self.button2:SetWidth(200); -- Reposition in the center - button:SetPoint("CENTER", editBox, "CENTER", 0, -30); + self.button2:SetPoint("CENTER", self.editBox, "CENTER", 0, -30); end end, EditBoxOnEscapePressed = function(self) @@ -781,117 +838,32 @@ maxLetters = 1024, }; ---BETA: The below either has to be removed or changed when releasing ---[[ -BETA/ALPHA request box -function MailOpener:ShowBetaPopup() - function TableDump(key, val, jumps) - local cache = ""; +-- The idea for this is to wait with refresing while there is still mail remaining which can be opened +-- This should speed things up a tiny bit, but might become buggy if coded wrong +-- We actually override the function in the onenable +function NewCheckInbox(...) + if not MailOpener.db.profile.general.overrideCheckInbox or not MailOpener.db.profile.general.continueOpening or not AutoOpenMail or not lastAmount or lastAmount == 0 then + -- If the override Check Inbox option is off + -- or continuous opening is off + -- or there's currently no mail visible - if not jumps then - jumps = 0; - end + MailOpener:Debug("CheckInbox:" .. tostring((not MailOpener.db.profile.general.overrideCheckInbox)) .. "/" .. tostring((not MailOpener.db.profile.general.continueOpening)) .. "/" .. tostring(lastAmount == 0)); - local spacer = ""; - if jumps > 0 then - for i = 1, jumps do - spacer = spacer .. " "; - end - end - - if type(val) == "table" then - cache = cache .. spacer .. key .. " = {\n"; - foreach(val, function(k, v) - cache = cache .. TableDump(k, v, (jumps + 1)); - end); - cache = cache .. spacer .. "},\n"; - else - cache = cache .. spacer .. key .. " = " .. tostring(val) .. ",\n"; - end - - return cache; + -- Just call the original function + return originalCheckInbox(...); end - local cache = ""; - foreach(MailOpener.db.profile, function(k, v) - cache = cache .. TableDump(k, v, 0); - end); - - local AceGUI = LibStub("AceGUI-3.0"); - local frame = AceGUI:Create("Frame"); - frame:SetTitle("Mail Opener ALPHA"); - frame:SetWidth(575); - frame:SetHeight(375); - - -- Add a normal description label - local desc = AceGUI:Create("Label"); - desc:SetText("|cff00ff00After you have been using Mail Opener for a while and configured it just as you want it to be, please report your favorite settings by copying the text below at either of the below links. Thanks in advance!|r\n\n"); - desc:SetFont(GameFontHighlightSmall:GetFont(), 13); - desc:SetFullWidth(true); - frame:AddChild(desc); - - -- Add a MultiLineEditBox - local settingsMLEEB = AceGUI:Create("MultiLineEditBox"); - settingsMLEEB:SetText(cache); - settingsMLEEB:SetLabel("Hit CTRL-A to select all and CTRL-C to copy the text. You can then use CTRL-V to paste."); - settingsMLEEB:SetFullWidth(true); - settingsMLEEB:SetNumLines(8); - settingsMLEEB:DisableButton(true); - settingsMLEEB:SetCallback("OnTextChanged", function() - settingsMLEEB:SetText(cache); - end); - frame:AddChild(settingsMLEEB); - - -- Empty line between the two links - local label = AceGUI:Create("Label"); - label:SetText("Please post the above text at either of these two links:"); - label:SetFullWidth(true); - frame:AddChild(label); - - local desc1 = AceGUI:Create("InteractiveLabel"); - desc1:SetText("|cff00bbbb[http://wow.curseforge.com/addons/mailopener/create-ticket/]|r"); - desc1:SetFont(GameFontHighlightSmall:GetFont(), 13); - desc1:SetFullWidth(true); - desc1:SetCallback("OnClick", function() - MailOpener.currentPopupContents = "http://wow.curseforge.com/addons/mailopener/create-ticket/"; + if not hasOpenedMailAlready then + -- If MO hasn't opened mail yet, we wait. + -- MO will call this function when mail opening is done - StaticPopup_Show("MailOpenerCopyWindow"); - end); - desc1:SetCallback("OnEnter", function() - frame:SetStatusText("Click to copy this URL."); - end); - desc1:SetCallback("OnLeave", function() - frame:SetStatusText(""); - end); - frame:AddChild(desc1); - - -- Empty line between the two links - local spacer = AceGUI:Create("Label"); - spacer:SetText(" "); - frame:AddChild(spacer); - - local desc2 = AceGUI:Create("InteractiveLabel"); - desc2:SetText("|cff00bbbb[http://20kleveling.com/JMTCforum/posting.php?mode=reply&f=9&t=1403]|r"); - desc2:SetFont(GameFontHighlightSmall:GetFont(), 13); - desc2:SetFullWidth(true); - desc2:SetCallback("OnClick", function() - MailOpener.currentPopupContents = "http://20kleveling.com/JMTCforum/posting.php?mode=reply&f=9&t=1403"; + MailOpener:Debug("CheckInbox:Waiting..."); - StaticPopup_Show("MailOpenerCopyWindow"); - end); - desc2:SetCallback("OnEnter", function() - frame:SetStatusText("Click to copy this URL."); - end); - desc2:SetCallback("OnLeave", function() - frame:SetStatusText(""); - end); - frame:AddChild(desc2); - - -- Empty line between the two links - local label = AceGUI:Create("Label"); - label:SetText("\n\nps. You can always view this window again at a later time by clicking the \"Config\" button in the mail frame.\nps2. The information above is completely Mail Opener related. It will be used to determine the best default settings."); - label:SetFullWidth(true); - frame:AddChild(label); + return false; + else + MailOpener:Debug("CheckInbox:Refresh!"); + + return originalCheckInbox(...); + end end -]] \ No newline at end of file
