# HG changeset patch # User Zerotorescue # Date 1295093716 -3600 # Node ID 239e25a058c7c5e4e579f71937c80584092a00da # Parent 8356e5acefdcd48f08a9db0d196ad0d680218798 Implemented mail refilling support. Respecting the MailAddonBusy global when opening so addons like MailOpener shouldn?t interfere. diff -r 8356e5acefdc -r 239e25a058c7 Classes/ContainerItem.class.lua --- a/Classes/ContainerItem.class.lua Fri Jan 14 23:46:05 2011 +0100 +++ b/Classes/ContainerItem.class.lua Sat Jan 15 13:15:16 2011 +0100 @@ -6,13 +6,12 @@ addon.ContainerItem.__index = addon.ContainerItem; -- Construct -function addon.ContainerItem:New(id) +function addon.ContainerItem:New() local self = {}; setmetatable(self, addon.ContainerItem); -- Standard info everything needs - self.id = id; self.totalCount = 0; self.locations = {}; diff -r 8356e5acefdc -r 239e25a058c7 Modules/Mover.lua --- a/Modules/Mover.lua Fri Jan 14 23:46:05 2011 +0100 +++ b/Modules/Mover.lua Sat Jan 15 13:15:16 2011 +0100 @@ -371,6 +371,11 @@ if movesSource == addon.Locations.Mailbox then MailAddonBusy = addon:GetName(); + + -- Since mailbox indexes change as mail is emptied (emptied mail is automatically deleted, thus number 50 would become 49 when 1 disappears), we must start with the last mail first + table.sort(combinedMoves, function(a, b) + return a.sourceContainer < b.sourceContainer; + end); end self:RegisterEvent(ContainerFunctions[movesSource].Event, "SourceUpdated"); diff -r 8356e5acefdc -r 239e25a058c7 Modules/Scanner.lua --- a/Modules/Scanner.lua Fri Jan 14 23:46:05 2011 +0100 +++ b/Modules/Scanner.lua Sat Jan 15 13:15:16 2011 +0100 @@ -386,59 +386,59 @@ self:RegisterEvent("GUILDBANKBAGSLOTS_CHANGED"); end ---local previousMailCount; ---function mod:MAIL_SHOW() --- addon:Debug("Scanner:MAIL_SHOW"); --- --- self:RegisterEvent("MAIL_INBOX_UPDATE"); --- self:RegisterEvent("MAIL_CLOSED"); --- --- scanned = nil; --- previousMailCount = nil; --- --- self:Scan(addon.Locations.Mailbox); ---end +local previousMailCount; +function mod:MAIL_SHOW() + addon:Debug("Scanner:MAIL_SHOW"); + + self:RegisterEvent("MAIL_INBOX_UPDATE"); + self:RegisterEvent("MAIL_CLOSED"); + + scanned = nil; + previousMailCount = nil; + + self:Scan(addon.Locations.Mailbox); +end ---function mod:MAIL_INBOX_UPDATE() --- if not scanned then --- addon:Debug("Scanner:MAIL_INBOX_UPDATE"); --- --- local current, total = GetInboxNumItems(); --- --- if not previousMailCount or current > previousMailCount then --- -- New mail received --- --- scanned = true; --- --- self:Scan(addon.Locations.Mailbox); --- end --- --- -- Also remember the new mailcount when losing items, otherwise deleting item 50 and getting to 50 again wouldn't trigger a re-scan --- previousMailCount = current; --- else --- addon:Debug("Scanner:MAIL_INBOX_UPDATE skipped, already scanned"); --- end ---end +function mod:MAIL_INBOX_UPDATE() + if not scanned then + addon:Debug("Scanner:MAIL_INBOX_UPDATE"); + + local current, total = GetInboxNumItems(); + + if not previousMailCount or current > previousMailCount then + -- New mail received + + scanned = true; + + self:Scan(addon.Locations.Mailbox); + end + + -- Also remember the new mailcount when losing items, otherwise deleting item 50 and getting to 50 again wouldn't trigger a re-scan + previousMailCount = current; + else + addon:Debug("Scanner:MAIL_INBOX_UPDATE skipped, already scanned"); + end +end ---function mod:MAIL_CLOSED() --- addon:Debug("Scanner:MAIL_CLOSED"); --- --- previousMailCount = nil; --- scanned = nil; --- self:ClearCache(); --- --- self:UnregisterEvent("MAIL_INBOX_UPDATE"); --- self:UnregisterEvent("MAIL_CLOSED"); --- --- InventoriumItemMover:Hide(); --- Mover:ResetQueue(); ---end +function mod:MAIL_CLOSED() + addon:Debug("Scanner:MAIL_CLOSED"); + + previousMailCount = nil; + scanned = nil; + self:ClearCache(); + + self:UnregisterEvent("MAIL_INBOX_UPDATE"); + self:UnregisterEvent("MAIL_CLOSED"); + + InventoriumItemMover:Hide(); + Mover:ResetQueue(); +end function mod:OnEnable() -- Scan once when the bankframe is opened self:RegisterEvent("BANKFRAME_OPENED"); self:RegisterEvent("GUILDBANKFRAME_OPENED"); --- self:RegisterEvent("MAIL_SHOW"); + self:RegisterEvent("MAIL_SHOW"); Mover = addon:GetModule("Mover"); @@ -460,9 +460,9 @@ self:GUILDBANKFRAME_CLOSED(); self:UnregisterEvent("GUILDBANKFRAME_OPENED"); --- -- Mailbox --- self:MAIL_CLOSED(); --- self:UnregisterEvent("MAIL_SHOW"); + -- Mailbox + self:MAIL_CLOSED(); + self:UnregisterEvent("MAIL_SHOW"); end function mod:Pause()