annotate Modules/Scanner.lua @ 117:239e25a058c7

Implemented mail refilling support. Respecting the MailAddonBusy global when opening so addons like MailOpener shouldn?t interfere.
author Zerotorescue
date Sat, 15 Jan 2011 13:15:16 +0100
parents 41f0689dfda1
children dc6f405c1a5d
rev   line source
Zerotorescue@80 1 local addon = select(2, ...);
Zerotorescue@84 2 local mod = addon:NewModule("Scanner", "AceEvent-3.0", "AceTimer-3.0");
Zerotorescue@80 3
Zerotorescue@101 4 local Mover, paused, currentLocation;
Zerotorescue@80 5 local itemCache = {};
Zerotorescue@80 6
Zerotorescue@110 7 local function OnMoveAccept()
Zerotorescue@101 8 mod:Pause();
Zerotorescue@101 9 Mover:BeginMove(currentLocation, mod.Unpause);
Zerotorescue@101 10
Zerotorescue@101 11 InventoriumItemMover:Hide();
Zerotorescue@101 12 end
Zerotorescue@101 13
Zerotorescue@110 14 local function OnMoveCancel()
Zerotorescue@101 15 Mover:ResetQueue();
Zerotorescue@101 16 currentLocation = nil;
Zerotorescue@101 17
Zerotorescue@101 18 InventoriumItemMover:Hide();
Zerotorescue@101 19 end
Zerotorescue@101 20
Zerotorescue@111 21 local function UseStorageRefillST()
Zerotorescue@110 22 local frame = InventoriumItemMover; -- both for speed as code-consistency
Zerotorescue@110 23
Zerotorescue@110 24 -- Scrolling table with a list of items to be moved
Zerotorescue@110 25 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size
Zerotorescue@110 26 local headers = {
Zerotorescue@110 27 {
Zerotorescue@110 28 ["name"] = "Item",
Zerotorescue@111 29 ["width"] = (scrollTableWidth * .60),
Zerotorescue@110 30 ["defaultsort"] = "asc",
Zerotorescue@110 31 ["comparesort"] = function(this, aRow, bRow, column)
Zerotorescue@110 32 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId);
Zerotorescue@110 33 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId);
Zerotorescue@110 34 local template = "%d%s";
Zerotorescue@110 35 aName = template:format((10 - (aRarity or 10)), (aName or ""):lower());
Zerotorescue@110 36 bName = template:format((10 - (bRarity or 10)), (bName or ""):lower());
Zerotorescue@110 37
Zerotorescue@110 38 if this.cols[column].sort == "dsc" then
Zerotorescue@110 39 return aName > bName;
Zerotorescue@110 40 else
Zerotorescue@110 41 return aName < bName;
Zerotorescue@110 42 end
Zerotorescue@110 43 end,
Zerotorescue@110 44 ["sort"] = "asc", -- when the data is set, use this column so sort the default data
Zerotorescue@110 45 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"),
Zerotorescue@110 46 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by item quality then item name."),
Zerotorescue@110 47 },
Zerotorescue@110 48 {
Zerotorescue@110 49 ["name"] = "Moving",
Zerotorescue@110 50 ["width"] = (scrollTableWidth * .15),
Zerotorescue@110 51 ["align"] = "RIGHT",
Zerotorescue@110 52 ["defaultsort"] = "dsc",
Zerotorescue@110 53 ["sortnext"] = 1,
Zerotorescue@110 54 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Moving"),
Zerotorescue@110 55 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of movable items."),
Zerotorescue@110 56 },
Zerotorescue@110 57 {
Zerotorescue@110 58 ["name"] = "Available",
Zerotorescue@111 59 ["width"] = (scrollTableWidth * .25),
Zerotorescue@110 60 ["align"] = "RIGHT",
Zerotorescue@110 61 ["defaultsort"] = "dsc",
Zerotorescue@110 62 ["sortnext"] = 1,
Zerotorescue@110 63 ["comparesort"] = function(this, aRow, bRow, column)
Zerotorescue@110 64 local aAvailablePercent = (this:GetRow(aRow).rowData.available / this:GetRow(aRow).rowData.missing);
Zerotorescue@110 65 local bAvailablePercent = (this:GetRow(bRow).rowData.available / this:GetRow(bRow).rowData.missing);
Zerotorescue@110 66
Zerotorescue@110 67 if this.cols[column].sort == "dsc" then
Zerotorescue@110 68 return aAvailablePercent > bAvailablePercent;
Zerotorescue@110 69 else
Zerotorescue@110 70 return aAvailablePercent < bAvailablePercent;
Zerotorescue@110 71 end
Zerotorescue@110 72 end,
Zerotorescue@110 73 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"),
Zerotorescue@110 74 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the availibility percentage."),
Zerotorescue@110 75 },
Zerotorescue@110 76 };
Zerotorescue@110 77
Zerotorescue@110 78 local proceedButton = {
Zerotorescue@110 79 text = "Move Items",
Zerotorescue@110 80 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Move Items"),
Zerotorescue@110 81 tooltip = (not addon.db.profile.defaults.hideHelp and "Start moving these items from the bank."),
Zerotorescue@110 82 onClick = OnMoveAccept,
Zerotorescue@110 83 };
Zerotorescue@110 84 local cancelButton = {
Zerotorescue@110 85 text = "Cancel",
Zerotorescue@110 86 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Cancel"),
Zerotorescue@110 87 tooltip = (not addon.db.profile.defaults.hideHelp and "Do not move anything and close the window."),
Zerotorescue@110 88 onClick = OnMoveCancel,
Zerotorescue@110 89 };
Zerotorescue@110 90
Zerotorescue@110 91 addon:SetFrameSettings("Inventorium Bank Refill", "The items listed below can be refilled from this location, do you wish to move them to your bags?", proceedButton, cancelButton, headers);
Zerotorescue@110 92 end
Zerotorescue@110 93
Zerotorescue@80 94 function mod:ClearCache()
Zerotorescue@80 95 table.wipe(itemCache);
Zerotorescue@80 96 end
Zerotorescue@80 97
Zerotorescue@80 98 function mod:CacheLocation(location, remember)
Zerotorescue@89 99 -- Reset cache just in case it was filled
Zerotorescue@89 100 self:ClearCache();
Zerotorescue@89 101
Zerotorescue@80 102 if location == addon.Locations.Bag or location == addon.Locations.Bank then
Zerotorescue@80 103 local start, stop;
Zerotorescue@80 104 if location == addon.Locations.Bag then
Zerotorescue@80 105 start = 0;
Zerotorescue@80 106 stop = NUM_BAG_SLOTS;
Zerotorescue@80 107 else
Zerotorescue@80 108 -- If we requested the bank then we don't want the bag info
Zerotorescue@80 109 start = ( NUM_BAG_SLOTS + 1 );
Zerotorescue@80 110 stop = ( NUM_BAG_SLOTS + NUM_BANKBAGSLOTS );
Zerotorescue@80 111 end
Zerotorescue@80 112
Zerotorescue@80 113 -- Go through all our bags, including the backpack
Zerotorescue@81 114 for i = start, ((location == addon.Locations.Bag and stop) or (location == addon.Locations.Bank and (stop + 1))) do -- if scanning bags stop at normal bag slot, if scanning bank, stop one later to allow BANK_CONTAINER to be scanned too
Zerotorescue@80 115 -- Scan the default 100 slots whenever we're at a non-existing index
Zerotorescue@80 116 local bagId = (i == (stop + 1) and BANK_CONTAINER) or i;
Zerotorescue@80 117 local slotId = GetContainerNumSlots(bagId);
Zerotorescue@80 118
Zerotorescue@80 119 while slotId ~= 0 do
Zerotorescue@80 120 -- A not equal-comparison should be quicker than a larger than-comparison
Zerotorescue@80 121
Zerotorescue@80 122 local itemId = GetContainerItemID(bagId, slotId);
Zerotorescue@80 123 local itemCount = itemId and select(2, GetContainerItemInfo(bagId, slotId));
Zerotorescue@80 124
Zerotorescue@80 125 if itemId and itemCount and itemCount > 0 then
Zerotorescue@80 126 local itemMove;
Zerotorescue@80 127 if not itemCache[itemId] then
Zerotorescue@80 128 -- If this is the first time we see this item, make a new object
Zerotorescue@81 129 itemMove = addon.ContainerItem:New();
Zerotorescue@81 130 itemCache[itemId] = itemMove;
Zerotorescue@80 131 else
Zerotorescue@80 132 -- If we had this item in another slot too
Zerotorescue@80 133 itemMove = itemCache[itemId];
Zerotorescue@80 134 end
Zerotorescue@80 135
Zerotorescue@81 136 itemMove:AddLocation(bagId, slotId, itemCount);
Zerotorescue@80 137 end
Zerotorescue@80 138
Zerotorescue@80 139 -- Continue scanning a different slot
Zerotorescue@80 140 slotId = (slotId - 1);
Zerotorescue@80 141 end
Zerotorescue@80 142 end
Zerotorescue@80 143 elseif location == addon.Locations.Guild then
Zerotorescue@84 144 for tabId = 1, GetNumGuildBankTabs() do
Zerotorescue@110 145 local _, _, isViewable, _, _, remainingWithdrawals = GetGuildBankTabInfo(tabId);
Zerotorescue@80 146
Zerotorescue@110 147 if isViewable and (remainingWithdrawals > 0 or remainingWithdrawals == -1) then
Zerotorescue@84 148 local slotId = (MAX_GUILDBANK_SLOTS_PER_TAB or 98); -- start by scanning the last slot
Zerotorescue@80 149
Zerotorescue@84 150 while slotId ~= 0 do
Zerotorescue@84 151 -- A not equal-comparison should be quicker than a larger than-comparison
Zerotorescue@84 152
Zerotorescue@84 153 local itemLink = GetGuildBankItemLink(tabId, slotId);
Zerotorescue@95 154 local itemId = itemLink and addon:GetItemId(itemLink);
Zerotorescue@84 155 local itemCount = itemLink and select(2, GetGuildBankItemInfo(tabId, slotId));
Zerotorescue@84 156
Zerotorescue@84 157 if itemLink and itemId and itemCount and itemCount > 0 then
Zerotorescue@84 158 -- If there is actually an item in this slot
Zerotorescue@84 159 local itemMove;
Zerotorescue@84 160 if not itemCache[itemId] then
Zerotorescue@84 161 -- If this is the first time we see this item, make a new object
Zerotorescue@84 162 itemMove = addon.ContainerItem:New();
Zerotorescue@84 163 itemCache[itemId] = itemMove;
Zerotorescue@84 164 else
Zerotorescue@84 165 -- If we had this item in another slot too
Zerotorescue@84 166 itemMove = itemCache[itemId];
Zerotorescue@84 167 end
Zerotorescue@84 168
Zerotorescue@84 169 itemMove:AddLocation(tabId, slotId, itemCount);
Zerotorescue@84 170 end
Zerotorescue@84 171
Zerotorescue@84 172 -- Continue scanning a different slot
Zerotorescue@84 173 slotId = (slotId - 1);
Zerotorescue@80 174 end
Zerotorescue@80 175 end
Zerotorescue@80 176 end
Zerotorescue@110 177 elseif location == addon.Locations.Mailbox then
Zerotorescue@110 178 for mailIndex = 1, GetInboxNumItems() do
Zerotorescue@110 179 -- All mail items
Zerotorescue@110 180
Zerotorescue@110 181 for attachIndex = 1, ATTACHMENTS_MAX_RECEIVE do
Zerotorescue@110 182 -- All attachments
Zerotorescue@110 183
Zerotorescue@110 184 local itemLink = GetInboxItemLink(mailIndex, attachIndex);
Zerotorescue@110 185 local itemId = itemLink and addon:GetItemId(itemLink);
Zerotorescue@110 186 local itemCount = itemLink and select(3, GetInboxItem(mailIndex, attachIndex));
Zerotorescue@110 187
Zerotorescue@110 188 if itemLink and itemId and itemCount and itemCount > 0 then
Zerotorescue@110 189 local itemMove;
Zerotorescue@110 190 if not itemCache[itemId] then
Zerotorescue@110 191 -- If this is the first time we see this item, make a new object
Zerotorescue@110 192 itemMove = addon.ContainerItem:New();
Zerotorescue@110 193 itemCache[itemId] = itemMove;
Zerotorescue@110 194 else
Zerotorescue@110 195 -- If we had this item in another slot too
Zerotorescue@110 196 itemMove = itemCache[itemId];
Zerotorescue@110 197 end
Zerotorescue@110 198
Zerotorescue@110 199 itemMove:AddLocation(mailIndex, attachIndex, itemCount);
Zerotorescue@110 200 end
Zerotorescue@110 201 end
Zerotorescue@110 202 end
Zerotorescue@80 203 else
Zerotorescue@82 204 error("Invalid location provided for CacheLocation. Must be Bank or Guild.");
Zerotorescue@80 205 end
Zerotorescue@80 206
Zerotorescue@80 207 if not remember then
Zerotorescue@80 208 -- Copy the table as clearing the cache wipes it empty (and tables are passed by reference)
Zerotorescue@80 209 local cacheCopy = CopyTable(itemCache);
Zerotorescue@80 210
Zerotorescue@80 211 self:ClearCache();
Zerotorescue@80 212
Zerotorescue@80 213 return cacheCopy;
Zerotorescue@80 214 end
Zerotorescue@80 215 end
Zerotorescue@80 216
Zerotorescue@80 217 function mod:Scan(location)
Zerotorescue@80 218 -- We might pause the scanning when we invoke moves ourself
Zerotorescue@80 219 if paused then
Zerotorescue@110 220 addon:Debug("Not scanning; paused...");
Zerotorescue@80 221 return;
Zerotorescue@80 222 end
Zerotorescue@80 223
Zerotorescue@80 224 local playerName = UnitName("player");
Zerotorescue@80 225
Zerotorescue@101 226 currentLocation = location;
Zerotorescue@80 227 self:CacheLocation(location, true);
Zerotorescue@80 228
Zerotorescue@110 229 -- Ensure previous queue isn't remaining
Zerotorescue@110 230 Mover:ResetQueue();
Zerotorescue@110 231
Zerotorescue@80 232 -- Go through all groups
Zerotorescue@80 233 for groupName, values in pairs(addon.db.profile.groups) do
Zerotorescue@80 234 local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
Zerotorescue@84 235 local localItemData = addon:GetOptionByKey(groupName, "localItemData");
Zerotorescue@80 236
Zerotorescue@82 237 if values.items and trackAt[playerName] and addon:GetOptionByKey(groupName, "autoRefill") and (location ~= addon.Locations.Bank or not localItemData or not localItemData["Bank"]) then
Zerotorescue@80 238 -- Is this character interested in this data?
Zerotorescue@80 239
Zerotorescue@80 240 local minLocalStock = addon:GetOptionByKey(groupName, "minLocalStock");
Zerotorescue@80 241
Zerotorescue@80 242 -- Go through all items
Zerotorescue@80 243 for itemId, _ in pairs(values.items) do
Zerotorescue@80 244
Zerotorescue@81 245 -- Check if we have enough items local (but only do so if this location also has enough available)
Zerotorescue@81 246 local missingItems = itemCache[itemId] and (minLocalStock - addon:GetLocalItemCount(itemId, groupName));
Zerotorescue@80 247
Zerotorescue@81 248 if itemCache[itemId] and missingItems > 0 then
Zerotorescue@80 249 -- Check how many are available
Zerotorescue@81 250 local availableItems = ((itemCache[itemId] and itemCache[itemId].totalCount) or 0);
Zerotorescue@101 251 -- Calculate how many we'll be moving (less missing than available? use missing, otherwise use available)
Zerotorescue@111 252 local moving = ((missingItems <= availableItems and missingItems) or availableItems);
Zerotorescue@80 253
Zerotorescue@111 254 if availableItems > 0 then
Zerotorescue@111 255 addon:Debug("Insufficient %s but this location has %d (moving %d)", IdToItemLink(itemId), availableItems, moving);
Zerotorescue@80 256
Zerotorescue@111 257 Mover:AddMove(itemId, moving, missingItems, availableItems);
Zerotorescue@80 258 end
Zerotorescue@80 259 end
Zerotorescue@80 260 end
Zerotorescue@80 261 end
Zerotorescue@80 262 end
Zerotorescue@80 263
Zerotorescue@80 264 self:ClearCache();
Zerotorescue@80 265
Zerotorescue@81 266 if Mover:HasMoves() then
Zerotorescue@101 267 if addon.db.profile.defaults.autoRefillSkipConfirm then
Zerotorescue@110 268 OnMoveAccept();
Zerotorescue@101 269 else
Zerotorescue@111 270 UseStorageRefillST();
Zerotorescue@110 271
Zerotorescue@106 272 -- This table is never copied, just referenced. It is the same for every row.
Zerotorescue@101 273 local columns = {
Zerotorescue@101 274 {
Zerotorescue@110 275 ["value"] = function(data, cols, realrow, column, table)
Zerotorescue@110 276 return IdToItemLink(data[realrow].rowData.itemId);
Zerotorescue@101 277 end,
Zerotorescue@101 278 }, -- item
Zerotorescue@101 279 {
Zerotorescue@110 280 ["value"] = function(data, cols, realrow, column, table)
Zerotorescue@106 281 return data[realrow].rowData.num;
Zerotorescue@101 282 end,
Zerotorescue@101 283 }, -- moving
Zerotorescue@101 284 {
Zerotorescue@110 285 ["value"] = function(data, cols, realrow, column, table)
Zerotorescue@106 286 return addon:DisplayItemCount(data[realrow].rowData.available, data[realrow].rowData.missing); -- available / missing
Zerotorescue@101 287 end,
Zerotorescue@110 288 ["color"] = function(data, cols, realrow, column, table)
Zerotorescue@106 289 return ((data[realrow].rowData.available < data[realrow].rowData.missing) and { r = 1, g = 0, b = 0, a = 1 }) or { r = 1, g = 1, b = 1, a = 1 };
Zerotorescue@101 290 end,
Zerotorescue@106 291 }, -- missing / available
Zerotorescue@101 292 };
Zerotorescue@101 293
Zerotorescue@106 294 -- Store the list with rows in this
Zerotorescue@106 295 local data = {};
Zerotorescue@101 296
Zerotorescue@101 297 for i, move in pairs(Mover:GetMoves()) do
Zerotorescue@106 298 table.insert(data, {
Zerotorescue@106 299 ["rowData"] = move, -- this is not a key usually found in a row item and ignored by the library
Zerotorescue@101 300 ["cols"] = columns,
Zerotorescue@106 301 });
Zerotorescue@101 302 end
Zerotorescue@101 303
Zerotorescue@101 304 addon:SetMoverFrameData(data);
Zerotorescue@101 305 end
Zerotorescue@81 306 end
Zerotorescue@81 307 end
Zerotorescue@81 308
Zerotorescue@84 309
Zerotorescue@84 310
Zerotorescue@84 311 -- Events
Zerotorescue@84 312
Zerotorescue@84 313 -- Player bank
Zerotorescue@84 314
Zerotorescue@84 315 function mod:BANKFRAME_OPENED()
Zerotorescue@84 316 addon:Debug("Scanner:BANKFRAME_OPENED");
Zerotorescue@84 317
Zerotorescue@84 318 mod:RegisterEvent("BANKFRAME_CLOSED");
Zerotorescue@84 319
Zerotorescue@84 320 -- Scan once when the bank is opened, but no need to scan after
Zerotorescue@84 321 mod:Scan(addon.Locations.Bank);
Zerotorescue@84 322 end
Zerotorescue@84 323
Zerotorescue@84 324 function mod:BANKFRAME_CLOSED()
Zerotorescue@81 325 addon:Debug("Scanner:BANKFRAME_CLOSED");
Zerotorescue@81 326
Zerotorescue@89 327 self:ClearCache();
Zerotorescue@89 328
Zerotorescue@81 329 mod:UnregisterEvent("BANKFRAME_CLOSED");
Zerotorescue@81 330
Zerotorescue@101 331 InventoriumItemMover:Hide();
Zerotorescue@101 332 Mover:ResetQueue();
Zerotorescue@80 333 end
Zerotorescue@80 334
Zerotorescue@84 335 -- Guild bank
Zerotorescue@84 336
Zerotorescue@84 337 local tmrScanGuild, scanned;
Zerotorescue@84 338 function mod:GUILDBANKBAGSLOTS_CHANGED()
Zerotorescue@84 339 -- This event is spammed the first time the guild bank is opened
Zerotorescue@84 340 if not scanned then
Zerotorescue@84 341 self:CancelTimer(tmrScanGuild, true); -- silent
Zerotorescue@84 342 tmrScanGuild = self:ScheduleTimer("DoScanGuild", 1);
Zerotorescue@84 343 end
Zerotorescue@80 344 end
Zerotorescue@80 345
Zerotorescue@84 346 function mod:DoScanGuild()
Zerotorescue@84 347 if not scanned then
Zerotorescue@89 348 addon:Debug("Scanner:DoScanGuild");
Zerotorescue@84 349
Zerotorescue@84 350 scanned = true;
Zerotorescue@84 351
Zerotorescue@84 352 self:Scan(addon.Locations.Guild);
Zerotorescue@84 353 end
Zerotorescue@84 354 end
Zerotorescue@80 355
Zerotorescue@84 356 function mod:GUILDBANKFRAME_CLOSED()
Zerotorescue@81 357 addon:Debug("Scanner:GUILDBANKFRAME_CLOSED");
Zerotorescue@81 358
Zerotorescue@84 359 scanned = nil;
Zerotorescue@89 360 self:ClearCache();
Zerotorescue@81 361
Zerotorescue@84 362 self:UnregisterEvent("GUILDBANKFRAME_CLOSED");
Zerotorescue@84 363 self:UnregisterEvent("GUILDBANKBAGSLOTS_CHANGED");
Zerotorescue@84 364
Zerotorescue@84 365 self:CancelTimer(tmrScanGuild, true); -- silent
Zerotorescue@80 366
Zerotorescue@101 367 InventoriumItemMover:Hide();
Zerotorescue@101 368 Mover:ResetQueue();
Zerotorescue@80 369 end
Zerotorescue@80 370
Zerotorescue@84 371 function mod:GUILDBANKFRAME_OPENED()
Zerotorescue@81 372 addon:Debug("Scanner:GUILDBANKFRAME_OPENED");
Zerotorescue@81 373
Zerotorescue@84 374 scanned = nil;
Zerotorescue@80 375
Zerotorescue@84 376 -- Get the contents for every tab into our cache
Zerotorescue@84 377 for tabId = 1, GetNumGuildBankTabs() do
Zerotorescue@110 378 local _, _, isViewable, _, _, remainingWithdrawals = GetGuildBankTabInfo(tabId);
Zerotorescue@110 379
Zerotorescue@110 380 if isViewable and (remainingWithdrawals > 0 or remainingWithdrawals == -1) then
Zerotorescue@84 381 QueryGuildBankTab(tabId);
Zerotorescue@84 382 end
Zerotorescue@84 383 end
Zerotorescue@84 384
Zerotorescue@84 385 self:RegisterEvent("GUILDBANKFRAME_CLOSED");
Zerotorescue@84 386 self:RegisterEvent("GUILDBANKBAGSLOTS_CHANGED");
Zerotorescue@80 387 end
Zerotorescue@80 388
Zerotorescue@117 389 local previousMailCount;
Zerotorescue@117 390 function mod:MAIL_SHOW()
Zerotorescue@117 391 addon:Debug("Scanner:MAIL_SHOW");
Zerotorescue@117 392
Zerotorescue@117 393 self:RegisterEvent("MAIL_INBOX_UPDATE");
Zerotorescue@117 394 self:RegisterEvent("MAIL_CLOSED");
Zerotorescue@117 395
Zerotorescue@117 396 scanned = nil;
Zerotorescue@117 397 previousMailCount = nil;
Zerotorescue@117 398
Zerotorescue@117 399 self:Scan(addon.Locations.Mailbox);
Zerotorescue@117 400 end
Zerotorescue@110 401
Zerotorescue@117 402 function mod:MAIL_INBOX_UPDATE()
Zerotorescue@117 403 if not scanned then
Zerotorescue@117 404 addon:Debug("Scanner:MAIL_INBOX_UPDATE");
Zerotorescue@117 405
Zerotorescue@117 406 local current, total = GetInboxNumItems();
Zerotorescue@117 407
Zerotorescue@117 408 if not previousMailCount or current > previousMailCount then
Zerotorescue@117 409 -- New mail received
Zerotorescue@117 410
Zerotorescue@117 411 scanned = true;
Zerotorescue@117 412
Zerotorescue@117 413 self:Scan(addon.Locations.Mailbox);
Zerotorescue@117 414 end
Zerotorescue@117 415
Zerotorescue@117 416 -- Also remember the new mailcount when losing items, otherwise deleting item 50 and getting to 50 again wouldn't trigger a re-scan
Zerotorescue@117 417 previousMailCount = current;
Zerotorescue@117 418 else
Zerotorescue@117 419 addon:Debug("Scanner:MAIL_INBOX_UPDATE skipped, already scanned");
Zerotorescue@117 420 end
Zerotorescue@117 421 end
Zerotorescue@110 422
Zerotorescue@117 423 function mod:MAIL_CLOSED()
Zerotorescue@117 424 addon:Debug("Scanner:MAIL_CLOSED");
Zerotorescue@117 425
Zerotorescue@117 426 previousMailCount = nil;
Zerotorescue@117 427 scanned = nil;
Zerotorescue@117 428 self:ClearCache();
Zerotorescue@117 429
Zerotorescue@117 430 self:UnregisterEvent("MAIL_INBOX_UPDATE");
Zerotorescue@117 431 self:UnregisterEvent("MAIL_CLOSED");
Zerotorescue@117 432
Zerotorescue@117 433 InventoriumItemMover:Hide();
Zerotorescue@117 434 Mover:ResetQueue();
Zerotorescue@117 435 end
Zerotorescue@110 436
Zerotorescue@80 437 function mod:OnEnable()
Zerotorescue@80 438 -- Scan once when the bankframe is opened
Zerotorescue@84 439 self:RegisterEvent("BANKFRAME_OPENED");
Zerotorescue@84 440 self:RegisterEvent("GUILDBANKFRAME_OPENED");
Zerotorescue@117 441 self:RegisterEvent("MAIL_SHOW");
Zerotorescue@80 442
Zerotorescue@80 443 Mover = addon:GetModule("Mover");
Zerotorescue@101 444
Zerotorescue@101 445 if not InventoriumItemMover then
Zerotorescue@101 446 addon:CreateMoverFrame(OnMoveAccept, OnMoveCancel);
Zerotorescue@101 447 end
Zerotorescue@80 448 end
Zerotorescue@80 449
Zerotorescue@80 450 function mod:OnDisable()
Zerotorescue@80 451 Mover = nil;
Zerotorescue@101 452 currentLocation = nil;
Zerotorescue@101 453 paused = nil;
Zerotorescue@80 454
Zerotorescue@80 455 -- Bank
Zerotorescue@110 456 self:BANKFRAME_CLOSED();
Zerotorescue@84 457 self:UnregisterEvent("BANKFRAME_OPENED");
Zerotorescue@80 458
Zerotorescue@80 459 -- Guild
Zerotorescue@84 460 self:GUILDBANKFRAME_CLOSED();
Zerotorescue@84 461 self:UnregisterEvent("GUILDBANKFRAME_OPENED");
Zerotorescue@110 462
Zerotorescue@117 463 -- Mailbox
Zerotorescue@117 464 self:MAIL_CLOSED();
Zerotorescue@117 465 self:UnregisterEvent("MAIL_SHOW");
Zerotorescue@80 466 end
Zerotorescue@80 467
Zerotorescue@80 468 function mod:Pause()
Zerotorescue@80 469 paused = true;
Zerotorescue@80 470 end
Zerotorescue@80 471
Zerotorescue@80 472 function mod:Unpause()
Zerotorescue@80 473 paused = nil;
Zerotorescue@80 474 end