From 98aadc9b5c557e73cf56c74b60f8c7098cb2e15b Mon Sep 17 00:00:00 2001 From: Xruptor Date: Tue, 14 Dec 2010 08:44:42 -0500 Subject: [PATCH] -Added an 'Open All' mail button to the inbox window. --- xanAutoMail.lua | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ xanAutoMail.toc | 2 +- 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/xanAutoMail.lua b/xanAutoMail.lua index fff9678..abbe710 100644 --- a/xanAutoMail.lua +++ b/xanAutoMail.lua @@ -6,6 +6,11 @@ local DB_PLAYER local DB_RECENT local currentPlayer local currentRealm +local inboxAllButton +local old_InboxFrame_OnClick +local triggerStop = false +local numInboxItems = 0 +local timeChk, timeDelay = 0, 1 local xanAutoMail = CreateFrame("frame","xanAutoMailFrame",UIParent) xanAutoMail:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end) @@ -31,6 +36,14 @@ function xanAutoMail:PLAYER_LOGIN() self:HookScript(SendMailNameEditBox, "OnEditFocusGained") self:RawHook("AutoComplete_Update", true) + --make the open all button + local inboxAllButton = CreateFrame("Button", "xanAutoMail_OpenAllBTN", InboxFrame, "UIPanelButtonTemplate") + inboxAllButton:SetWidth(100) + inboxAllButton:SetHeight(20) + inboxAllButton:SetPoint("CENTER", InboxFrame, "TOP", 0, -55) + inboxAllButton:SetText("Open All") + inboxAllButton:SetScript("OnClick", function() xanAutoMail.GetMail() end) + self:UnregisterEvent("PLAYER_LOGIN") self.PLAYER_LOGIN = nil end @@ -161,5 +174,98 @@ function xanAutoMail:AutoComplete_Update(editBox, editBoxText, utf8Position, ... end end +--[[------------------------ + OPEN ALL MAIL +--------------------------]] + +function mailLoop(this, arg1) + timeChk = timeChk + arg1 + if triggerStop then return end + + if (timeChk > timeDelay) then + timeChk = 0 + + --check for last or no messages + if numInboxItems <= 0 or GetInboxNumItems() <= 0 then + triggerStop = true + xanAutoMail:StopMail() + return + end + + --lets get the mail + local _, _, _, _, money, COD, _, numItems = GetInboxHeaderInfo(numInboxItems) + + if money > 0 or (numItems and numItems > 0) and COD <= 0 then + AutoLootMailItem(numInboxItems) + end + + --decrease count + numInboxItems = numInboxItems - 1 + end +end + +function xanAutoMail:GetMail() + if GetInboxNumItems() == 0 then return end + + xanAutoMail_OpenAllBTN:Disable() --disable the button to prevent further clicks + triggerStop = false + timeChk, timeDelay = 0, 0.5 + numInboxItems = GetInboxNumItems() + + old_InboxFrame_OnClick = InboxFrame_OnClick + InboxFrame_OnClick = function() end + + --register for inventory full error + xanAutoMail:RegisterEvent("UI_ERROR_MESSAGE") + + --initiate the loop + xanAutoMail:SetScript("OnUpdate", mailLoop) +end + +function xanAutoMail:StopMail() + xanAutoMail_OpenAllBTN:Enable() --enable the button again + if old_InboxFrame_OnClick then + InboxFrame_OnClick = old_InboxFrame_OnClick + old_InboxFrame_OnClick = nil + end + xanAutoMail:UnregisterEvent("UI_ERROR_MESSAGE") + xanAutoMail:SetScript("OnUpdate", nil) +end + +--this is to stop the loop if our bags are filled +function xanAutoMail:UI_ERROR_MESSAGE(event, arg1) + if arg1 == ERR_INV_FULL then + triggerStop = true + xanAutoMail:StopMail() + DEFAULT_CHAT_FRAME:AddMessage("xanAutoMail: Your bags are full") + end +end + if IsLoggedIn() then xanAutoMail:PLAYER_LOGIN() else xanAutoMail:RegisterEvent("PLAYER_LOGIN") end + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xanAutoMail.toc b/xanAutoMail.toc index 9f05ca2..61e006c 100644 --- a/xanAutoMail.toc +++ b/xanAutoMail.toc @@ -2,7 +2,7 @@ ## Title: xanAutoMail ## Notes: Expands blizzards automatic name generation for sending Mail to include people outside the guild. ## Author: Xruptor -## Version: 1.0 +## Version: 1.1 ## SavedVariables: xanAutoMailDB libs\LibStub\LibStub.lua -- 1.7.9.5