annotate Modules/Scanner.lua @ 110:67bd5057ecb7

Implemented vendor restocking with the mover. Comitting so I can always review this working version, but I?ll be disabling all part of it as it is not going to work properly without seriously compromising the code structure. Debug messages are now appended with ?Inventorium? (my MailOpener addon was making stuff difficult). Now properly removing the refill window from the displayed static popup windows list so new popups won?t be aligned at odd locations. Changed ?CreateMoverFrame? to not contain any scenario-specific info. All settings can be set with SetFrameSettings. Items that belong to speciality bags are now put there. Other items now ignore spaciality bags. Implemented test code for mailbox refill support. It has been disabled due to some issues but may be introduced later. The guild withdrawal limit is now taken into consideration. Queue is now reset before scanning again.
author Zerotorescue
date Fri, 14 Jan 2011 23:25:05 +0100
parents 3bbad0429d87
children 41f0689dfda1
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@110 21 local function UseStorageRefillST(withPrices)
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@110 29 ["width"] = (scrollTableWidth * ((withPrices and .5) or .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@110 59 ["width"] = (scrollTableWidth * ((withPrices and .2) or .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 if withPrices then
Zerotorescue@110 78 table.insert(headers, {
Zerotorescue@110 79 ["name"] = "Price",
Zerotorescue@110 80 ["width"] = (scrollTableWidth * .15),
Zerotorescue@110 81 ["align"] = "RIGHT",
Zerotorescue@110 82 ["defaultsort"] = "dsc",
Zerotorescue@110 83 ["sortnext"] = 1,
Zerotorescue@110 84 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Price"),
Zerotorescue@110 85 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the price of this item at this vendor."),
Zerotorescue@110 86 });
Zerotorescue@110 87 end
Zerotorescue@110 88
Zerotorescue@110 89 local proceedButton = {
Zerotorescue@110 90 text = "Move Items",
Zerotorescue@110 91 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Move Items"),
Zerotorescue@110 92 tooltip = (not addon.db.profile.defaults.hideHelp and "Start moving these items from the bank."),
Zerotorescue@110 93 onClick = OnMoveAccept,
Zerotorescue@110 94 };
Zerotorescue@110 95 local cancelButton = {
Zerotorescue@110 96 text = "Cancel",
Zerotorescue@110 97 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Cancel"),
Zerotorescue@110 98 tooltip = (not addon.db.profile.defaults.hideHelp and "Do not move anything and close the window."),
Zerotorescue@110 99 onClick = OnMoveCancel,
Zerotorescue@110 100 };
Zerotorescue@110 101
Zerotorescue@110 102 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 103 end
Zerotorescue@110 104
Zerotorescue@80 105 function mod:ClearCache()
Zerotorescue@80 106 table.wipe(itemCache);
Zerotorescue@80 107 end
Zerotorescue@80 108
Zerotorescue@80 109 function mod:CacheLocation(location, remember)
Zerotorescue@89 110 -- Reset cache just in case it was filled
Zerotorescue@89 111 self:ClearCache();
Zerotorescue@89 112
Zerotorescue@80 113 if location == addon.Locations.Bag or location == addon.Locations.Bank then
Zerotorescue@80 114 local start, stop;
Zerotorescue@80 115 if location == addon.Locations.Bag then
Zerotorescue@80 116 start = 0;
Zerotorescue@80 117 stop = NUM_BAG_SLOTS;
Zerotorescue@80 118 else
Zerotorescue@80 119 -- If we requested the bank then we don't want the bag info
Zerotorescue@80 120 start = ( NUM_BAG_SLOTS + 1 );
Zerotorescue@80 121 stop = ( NUM_BAG_SLOTS + NUM_BANKBAGSLOTS );
Zerotorescue@80 122 end
Zerotorescue@80 123
Zerotorescue@80 124 -- Go through all our bags, including the backpack
Zerotorescue@81 125 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 126 -- Scan the default 100 slots whenever we're at a non-existing index
Zerotorescue@80 127 local bagId = (i == (stop + 1) and BANK_CONTAINER) or i;
Zerotorescue@80 128 local slotId = GetContainerNumSlots(bagId);
Zerotorescue@80 129
Zerotorescue@80 130 while slotId ~= 0 do
Zerotorescue@80 131 -- A not equal-comparison should be quicker than a larger than-comparison
Zerotorescue@80 132
Zerotorescue@80 133 local itemId = GetContainerItemID(bagId, slotId);
Zerotorescue@80 134 local itemCount = itemId and select(2, GetContainerItemInfo(bagId, slotId));
Zerotorescue@80 135
Zerotorescue@80 136 if itemId and itemCount and itemCount > 0 then
Zerotorescue@80 137 local itemMove;
Zerotorescue@80 138 if not itemCache[itemId] then
Zerotorescue@80 139 -- If this is the first time we see this item, make a new object
Zerotorescue@81 140 itemMove = addon.ContainerItem:New();
Zerotorescue@81 141 itemCache[itemId] = itemMove;
Zerotorescue@80 142 else
Zerotorescue@80 143 -- If we had this item in another slot too
Zerotorescue@80 144 itemMove = itemCache[itemId];
Zerotorescue@80 145 end
Zerotorescue@80 146
Zerotorescue@81 147 itemMove:AddLocation(bagId, slotId, itemCount);
Zerotorescue@80 148 end
Zerotorescue@80 149
Zerotorescue@80 150 -- Continue scanning a different slot
Zerotorescue@80 151 slotId = (slotId - 1);
Zerotorescue@80 152 end
Zerotorescue@80 153 end
Zerotorescue@80 154 elseif location == addon.Locations.Guild then
Zerotorescue@84 155 for tabId = 1, GetNumGuildBankTabs() do
Zerotorescue@110 156 local _, _, isViewable, _, _, remainingWithdrawals = GetGuildBankTabInfo(tabId);
Zerotorescue@80 157
Zerotorescue@110 158 if isViewable and (remainingWithdrawals > 0 or remainingWithdrawals == -1) then
Zerotorescue@84 159 local slotId = (MAX_GUILDBANK_SLOTS_PER_TAB or 98); -- start by scanning the last slot
Zerotorescue@80 160
Zerotorescue@84 161 while slotId ~= 0 do
Zerotorescue@84 162 -- A not equal-comparison should be quicker than a larger than-comparison
Zerotorescue@84 163
Zerotorescue@84 164 local itemLink = GetGuildBankItemLink(tabId, slotId);
Zerotorescue@95 165 local itemId = itemLink and addon:GetItemId(itemLink);
Zerotorescue@84 166 local itemCount = itemLink and select(2, GetGuildBankItemInfo(tabId, slotId));
Zerotorescue@84 167
Zerotorescue@84 168 if itemLink and itemId and itemCount and itemCount > 0 then
Zerotorescue@84 169 -- If there is actually an item in this slot
Zerotorescue@84 170 local itemMove;
Zerotorescue@84 171 if not itemCache[itemId] then
Zerotorescue@84 172 -- If this is the first time we see this item, make a new object
Zerotorescue@84 173 itemMove = addon.ContainerItem:New();
Zerotorescue@84 174 itemCache[itemId] = itemMove;
Zerotorescue@84 175 else
Zerotorescue@84 176 -- If we had this item in another slot too
Zerotorescue@84 177 itemMove = itemCache[itemId];
Zerotorescue@84 178 end
Zerotorescue@84 179
Zerotorescue@84 180 itemMove:AddLocation(tabId, slotId, itemCount);
Zerotorescue@84 181 end
Zerotorescue@84 182
Zerotorescue@84 183 -- Continue scanning a different slot
Zerotorescue@84 184 slotId = (slotId - 1);
Zerotorescue@80 185 end
Zerotorescue@80 186 end
Zerotorescue@80 187 end
Zerotorescue@110 188 elseif location == addon.Locations.Mailbox then
Zerotorescue@110 189 for mailIndex = 1, GetInboxNumItems() do
Zerotorescue@110 190 -- All mail items
Zerotorescue@110 191
Zerotorescue@110 192 for attachIndex = 1, ATTACHMENTS_MAX_RECEIVE do
Zerotorescue@110 193 -- All attachments
Zerotorescue@110 194
Zerotorescue@110 195 local itemLink = GetInboxItemLink(mailIndex, attachIndex);
Zerotorescue@110 196 local itemId = itemLink and addon:GetItemId(itemLink);
Zerotorescue@110 197 local itemCount = itemLink and select(3, GetInboxItem(mailIndex, attachIndex));
Zerotorescue@110 198
Zerotorescue@110 199 if itemLink and itemId and itemCount and itemCount > 0 then
Zerotorescue@110 200 local itemMove;
Zerotorescue@110 201 if not itemCache[itemId] then
Zerotorescue@110 202 -- If this is the first time we see this item, make a new object
Zerotorescue@110 203 itemMove = addon.ContainerItem:New();
Zerotorescue@110 204 itemCache[itemId] = itemMove;
Zerotorescue@110 205 else
Zerotorescue@110 206 -- If we had this item in another slot too
Zerotorescue@110 207 itemMove = itemCache[itemId];
Zerotorescue@110 208 end
Zerotorescue@110 209
Zerotorescue@110 210 itemMove:AddLocation(mailIndex, attachIndex, itemCount);
Zerotorescue@110 211 end
Zerotorescue@110 212 end
Zerotorescue@110 213 end
Zerotorescue@110 214 elseif location == addon.Locations.Merchant then
Zerotorescue@110 215 for itemIndex = 1, GetMerchantNumItems() do
Zerotorescue@110 216 -- All merchant items
Zerotorescue@110 217
Zerotorescue@110 218 local itemLink = GetMerchantItemLink(itemIndex);
Zerotorescue@110 219 local itemId = itemLink and addon:GetItemId(itemLink);
Zerotorescue@110 220 local _, _, vendorValue, _, numAvailable, _, extendedCost = GetMerchantItemInfo(index);
Zerotorescue@110 221
Zerotorescue@110 222 if itemLink and itemId and numAvailable ~= 0 and not extendedCost then
Zerotorescue@110 223 local itemMove;
Zerotorescue@110 224 if not itemCache[itemId] then
Zerotorescue@110 225 -- If this is the first time we see this item, make a new object
Zerotorescue@110 226 itemMove = addon.ContainerItem:New();
Zerotorescue@110 227 itemCache[itemId] = itemMove;
Zerotorescue@110 228 else
Zerotorescue@110 229 -- If we had this item in another slot too
Zerotorescue@110 230 itemMove = itemCache[itemId];
Zerotorescue@110 231 end
Zerotorescue@110 232
Zerotorescue@110 233 itemMove:AddLocation(1, itemIndex, numAvailable, vendorValue);
Zerotorescue@110 234 end
Zerotorescue@110 235 end
Zerotorescue@80 236 else
Zerotorescue@82 237 error("Invalid location provided for CacheLocation. Must be Bank or Guild.");
Zerotorescue@80 238 end
Zerotorescue@80 239
Zerotorescue@80 240 if not remember then
Zerotorescue@80 241 -- Copy the table as clearing the cache wipes it empty (and tables are passed by reference)
Zerotorescue@80 242 local cacheCopy = CopyTable(itemCache);
Zerotorescue@80 243
Zerotorescue@80 244 self:ClearCache();
Zerotorescue@80 245
Zerotorescue@80 246 return cacheCopy;
Zerotorescue@80 247 end
Zerotorescue@80 248 end
Zerotorescue@80 249
Zerotorescue@80 250 function mod:Scan(location)
Zerotorescue@80 251 -- We might pause the scanning when we invoke moves ourself
Zerotorescue@80 252 if paused then
Zerotorescue@110 253 addon:Debug("Not scanning; paused...");
Zerotorescue@80 254 return;
Zerotorescue@80 255 end
Zerotorescue@80 256
Zerotorescue@80 257 local playerName = UnitName("player");
Zerotorescue@80 258
Zerotorescue@101 259 currentLocation = location;
Zerotorescue@80 260 self:CacheLocation(location, true);
Zerotorescue@80 261
Zerotorescue@110 262 -- Ensure previous queue isn't remaining
Zerotorescue@110 263 Mover:ResetQueue();
Zerotorescue@110 264
Zerotorescue@80 265 -- Go through all groups
Zerotorescue@80 266 for groupName, values in pairs(addon.db.profile.groups) do
Zerotorescue@80 267 local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
Zerotorescue@84 268 local localItemData = addon:GetOptionByKey(groupName, "localItemData");
Zerotorescue@80 269
Zerotorescue@82 270 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 271 -- Is this character interested in this data?
Zerotorescue@80 272
Zerotorescue@80 273 local minLocalStock = addon:GetOptionByKey(groupName, "minLocalStock");
Zerotorescue@80 274
Zerotorescue@80 275 -- Go through all items
Zerotorescue@80 276 for itemId, _ in pairs(values.items) do
Zerotorescue@80 277
Zerotorescue@81 278 -- Check if we have enough items local (but only do so if this location also has enough available)
Zerotorescue@81 279 local missingItems = itemCache[itemId] and (minLocalStock - addon:GetLocalItemCount(itemId, groupName));
Zerotorescue@80 280
Zerotorescue@81 281 if itemCache[itemId] and missingItems > 0 then
Zerotorescue@80 282 -- Check how many are available
Zerotorescue@81 283 local availableItems = ((itemCache[itemId] and itemCache[itemId].totalCount) or 0);
Zerotorescue@101 284 -- Calculate how many we'll be moving (less missing than available? use missing, otherwise use available)
Zerotorescue@110 285 local moving = (((availableItems == -1 or missingItems <= availableItems) and missingItems) or availableItems);
Zerotorescue@80 286
Zerotorescue@110 287 if availableItems ~= 0 then
Zerotorescue@110 288 addon:Debug("Insufficient %s but this location has %s (moving %d)", IdToItemLink(itemId), ((availableItems == -1 and "unlimited") or availableItems), moving);
Zerotorescue@80 289
Zerotorescue@110 290 Mover:AddMove(itemId, moving, missingItems, availableItems, itemCache[itemId]:GetVendorPrice());
Zerotorescue@80 291 end
Zerotorescue@80 292 end
Zerotorescue@80 293 end
Zerotorescue@80 294 end
Zerotorescue@80 295 end
Zerotorescue@80 296
Zerotorescue@80 297 self:ClearCache();
Zerotorescue@80 298
Zerotorescue@81 299 if Mover:HasMoves() then
Zerotorescue@101 300 if addon.db.profile.defaults.autoRefillSkipConfirm then
Zerotorescue@110 301 OnMoveAccept();
Zerotorescue@101 302 else
Zerotorescue@110 303 UseStorageRefillST((location == addon.Locations.Merchant));
Zerotorescue@110 304
Zerotorescue@106 305 -- This table is never copied, just referenced. It is the same for every row.
Zerotorescue@101 306 local columns = {
Zerotorescue@101 307 {
Zerotorescue@110 308 ["value"] = function(data, cols, realrow, column, table)
Zerotorescue@110 309 return IdToItemLink(data[realrow].rowData.itemId);
Zerotorescue@101 310 end,
Zerotorescue@101 311 }, -- item
Zerotorescue@101 312 {
Zerotorescue@110 313 ["value"] = function(data, cols, realrow, column, table)
Zerotorescue@106 314 return data[realrow].rowData.num;
Zerotorescue@101 315 end,
Zerotorescue@101 316 }, -- moving
Zerotorescue@101 317 {
Zerotorescue@110 318 ["value"] = function(data, cols, realrow, column, table)
Zerotorescue@106 319 return addon:DisplayItemCount(data[realrow].rowData.available, data[realrow].rowData.missing); -- available / missing
Zerotorescue@101 320 end,
Zerotorescue@110 321 ["color"] = function(data, cols, realrow, column, table)
Zerotorescue@106 322 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 323 end,
Zerotorescue@106 324 }, -- missing / available
Zerotorescue@101 325 };
Zerotorescue@110 326 if location == addon.Locations.Merchant then
Zerotorescue@110 327 table.insert(columns, {
Zerotorescue@110 328 ["value"] = function(data, cols, realrow, column, table)
Zerotorescue@110 329 return GetCoinTextureString(data[realrow].rowData.price * data[realrow].rowData.num);
Zerotorescue@110 330 end,
Zerotorescue@110 331 });
Zerotorescue@110 332 end
Zerotorescue@101 333
Zerotorescue@106 334 -- Store the list with rows in this
Zerotorescue@106 335 local data = {};
Zerotorescue@101 336
Zerotorescue@101 337 for i, move in pairs(Mover:GetMoves()) do
Zerotorescue@106 338 table.insert(data, {
Zerotorescue@106 339 ["rowData"] = move, -- this is not a key usually found in a row item and ignored by the library
Zerotorescue@101 340 ["cols"] = columns,
Zerotorescue@106 341 });
Zerotorescue@101 342 end
Zerotorescue@101 343
Zerotorescue@101 344 addon:SetMoverFrameData(data);
Zerotorescue@101 345 end
Zerotorescue@81 346 end
Zerotorescue@81 347 end
Zerotorescue@81 348
Zerotorescue@84 349
Zerotorescue@84 350
Zerotorescue@84 351 -- Events
Zerotorescue@84 352
Zerotorescue@84 353 -- Player bank
Zerotorescue@84 354
Zerotorescue@84 355 function mod:BANKFRAME_OPENED()
Zerotorescue@84 356 addon:Debug("Scanner:BANKFRAME_OPENED");
Zerotorescue@84 357
Zerotorescue@84 358 mod:RegisterEvent("BANKFRAME_CLOSED");
Zerotorescue@84 359
Zerotorescue@84 360 -- Scan once when the bank is opened, but no need to scan after
Zerotorescue@84 361 mod:Scan(addon.Locations.Bank);
Zerotorescue@84 362 end
Zerotorescue@84 363
Zerotorescue@84 364 function mod:BANKFRAME_CLOSED()
Zerotorescue@81 365 addon:Debug("Scanner:BANKFRAME_CLOSED");
Zerotorescue@81 366
Zerotorescue@89 367 self:ClearCache();
Zerotorescue@89 368
Zerotorescue@81 369 mod:UnregisterEvent("BANKFRAME_CLOSED");
Zerotorescue@81 370
Zerotorescue@101 371 InventoriumItemMover:Hide();
Zerotorescue@101 372 Mover:ResetQueue();
Zerotorescue@80 373 end
Zerotorescue@80 374
Zerotorescue@84 375 -- Guild bank
Zerotorescue@84 376
Zerotorescue@84 377 local tmrScanGuild, scanned;
Zerotorescue@84 378 function mod:GUILDBANKBAGSLOTS_CHANGED()
Zerotorescue@84 379 -- This event is spammed the first time the guild bank is opened
Zerotorescue@84 380 if not scanned then
Zerotorescue@84 381 self:CancelTimer(tmrScanGuild, true); -- silent
Zerotorescue@84 382 tmrScanGuild = self:ScheduleTimer("DoScanGuild", 1);
Zerotorescue@84 383 end
Zerotorescue@80 384 end
Zerotorescue@80 385
Zerotorescue@84 386 function mod:DoScanGuild()
Zerotorescue@84 387 if not scanned then
Zerotorescue@89 388 addon:Debug("Scanner:DoScanGuild");
Zerotorescue@84 389
Zerotorescue@84 390 scanned = true;
Zerotorescue@84 391
Zerotorescue@84 392 self:Scan(addon.Locations.Guild);
Zerotorescue@84 393 end
Zerotorescue@84 394 end
Zerotorescue@80 395
Zerotorescue@84 396 function mod:GUILDBANKFRAME_CLOSED()
Zerotorescue@81 397 addon:Debug("Scanner:GUILDBANKFRAME_CLOSED");
Zerotorescue@81 398
Zerotorescue@84 399 scanned = nil;
Zerotorescue@89 400 self:ClearCache();
Zerotorescue@81 401
Zerotorescue@84 402 self:UnregisterEvent("GUILDBANKFRAME_CLOSED");
Zerotorescue@84 403 self:UnregisterEvent("GUILDBANKBAGSLOTS_CHANGED");
Zerotorescue@84 404
Zerotorescue@84 405 self:CancelTimer(tmrScanGuild, true); -- silent
Zerotorescue@80 406
Zerotorescue@101 407 InventoriumItemMover:Hide();
Zerotorescue@101 408 Mover:ResetQueue();
Zerotorescue@80 409 end
Zerotorescue@80 410
Zerotorescue@84 411 function mod:GUILDBANKFRAME_OPENED()
Zerotorescue@81 412 addon:Debug("Scanner:GUILDBANKFRAME_OPENED");
Zerotorescue@81 413
Zerotorescue@84 414 scanned = nil;
Zerotorescue@80 415
Zerotorescue@84 416 -- Get the contents for every tab into our cache
Zerotorescue@84 417 for tabId = 1, GetNumGuildBankTabs() do
Zerotorescue@110 418 local _, _, isViewable, _, _, remainingWithdrawals = GetGuildBankTabInfo(tabId);
Zerotorescue@110 419
Zerotorescue@110 420 if isViewable and (remainingWithdrawals > 0 or remainingWithdrawals == -1) then
Zerotorescue@84 421 QueryGuildBankTab(tabId);
Zerotorescue@84 422 end
Zerotorescue@84 423 end
Zerotorescue@84 424
Zerotorescue@84 425 self:RegisterEvent("GUILDBANKFRAME_CLOSED");
Zerotorescue@84 426 self:RegisterEvent("GUILDBANKBAGSLOTS_CHANGED");
Zerotorescue@80 427 end
Zerotorescue@80 428
Zerotorescue@110 429 function mod:MERCHANT_SHOW()
Zerotorescue@110 430 addon:Debug("Scanner:MERCHANT_SHOW");
Zerotorescue@110 431
Zerotorescue@110 432 self:RegisterEvent("MERCHANT_CLOSED");
Zerotorescue@110 433
Zerotorescue@110 434 self:Scan(addon.Locations.Merchant);
Zerotorescue@110 435 end
Zerotorescue@110 436
Zerotorescue@110 437 function mod:MERCHANT_CLOSED()
Zerotorescue@110 438 addon:Debug("Scanner:MERCHANT_CLOSED");
Zerotorescue@110 439
Zerotorescue@110 440 self:ClearCache();
Zerotorescue@110 441
Zerotorescue@110 442 self:UnregisterEvent("MERCHANT_CLOSED");
Zerotorescue@110 443
Zerotorescue@110 444 InventoriumItemMover:Hide();
Zerotorescue@110 445 Mover:ResetQueue();
Zerotorescue@110 446 end
Zerotorescue@110 447
Zerotorescue@110 448 --local previousMailCount;
Zerotorescue@110 449 --function mod:MAIL_SHOW()
Zerotorescue@110 450 -- addon:Debug("Scanner:MAIL_SHOW");
Zerotorescue@110 451 --
Zerotorescue@110 452 -- self:RegisterEvent("MAIL_INBOX_UPDATE");
Zerotorescue@110 453 -- self:RegisterEvent("MAIL_CLOSED");
Zerotorescue@110 454 --
Zerotorescue@110 455 -- scanned = nil;
Zerotorescue@110 456 -- previousMailCount = nil;
Zerotorescue@110 457 --
Zerotorescue@110 458 -- self:Scan(addon.Locations.Mailbox);
Zerotorescue@110 459 --end
Zerotorescue@110 460
Zerotorescue@110 461 --function mod:MAIL_INBOX_UPDATE()
Zerotorescue@110 462 -- if not scanned then
Zerotorescue@110 463 -- addon:Debug("Scanner:MAIL_INBOX_UPDATE");
Zerotorescue@110 464 --
Zerotorescue@110 465 -- local current, total = GetInboxNumItems();
Zerotorescue@110 466 --
Zerotorescue@110 467 -- if not previousMailCount or current > previousMailCount then
Zerotorescue@110 468 -- -- New mail received
Zerotorescue@110 469 --
Zerotorescue@110 470 -- scanned = true;
Zerotorescue@110 471 --
Zerotorescue@110 472 -- self:Scan(addon.Locations.Mailbox);
Zerotorescue@110 473 -- end
Zerotorescue@110 474 --
Zerotorescue@110 475 -- -- Also remember the new mailcount when losing items, otherwise deleting item 50 and getting to 50 again wouldn't trigger a re-scan
Zerotorescue@110 476 -- previousMailCount = current;
Zerotorescue@110 477 -- else
Zerotorescue@110 478 -- addon:Debug("Scanner:MAIL_INBOX_UPDATE skipped, already scanned");
Zerotorescue@110 479 -- end
Zerotorescue@110 480 --end
Zerotorescue@110 481
Zerotorescue@110 482 --function mod:MAIL_CLOSED()
Zerotorescue@110 483 -- addon:Debug("Scanner:MAIL_CLOSED");
Zerotorescue@110 484 --
Zerotorescue@110 485 -- previousMailCount = nil;
Zerotorescue@110 486 -- scanned = nil;
Zerotorescue@110 487 -- self:ClearCache();
Zerotorescue@110 488 --
Zerotorescue@110 489 -- self:UnregisterEvent("MAIL_INBOX_UPDATE");
Zerotorescue@110 490 -- self:UnregisterEvent("MAIL_CLOSED");
Zerotorescue@110 491 --
Zerotorescue@110 492 -- InventoriumItemMover:Hide();
Zerotorescue@110 493 -- Mover:ResetQueue();
Zerotorescue@110 494 --end
Zerotorescue@110 495
Zerotorescue@80 496 function mod:OnEnable()
Zerotorescue@80 497 -- Scan once when the bankframe is opened
Zerotorescue@84 498 self:RegisterEvent("BANKFRAME_OPENED");
Zerotorescue@84 499 self:RegisterEvent("GUILDBANKFRAME_OPENED");
Zerotorescue@110 500 -- self:RegisterEvent("MAIL_SHOW");
Zerotorescue@110 501 self:RegisterEvent("MERCHANT_SHOW");
Zerotorescue@80 502
Zerotorescue@80 503 Mover = addon:GetModule("Mover");
Zerotorescue@101 504
Zerotorescue@101 505 if not InventoriumItemMover then
Zerotorescue@101 506 addon:CreateMoverFrame(OnMoveAccept, OnMoveCancel);
Zerotorescue@101 507 end
Zerotorescue@80 508 end
Zerotorescue@80 509
Zerotorescue@80 510 function mod:OnDisable()
Zerotorescue@80 511 Mover = nil;
Zerotorescue@101 512 currentLocation = nil;
Zerotorescue@101 513 paused = nil;
Zerotorescue@80 514
Zerotorescue@80 515 -- Bank
Zerotorescue@110 516 self:BANKFRAME_CLOSED();
Zerotorescue@84 517 self:UnregisterEvent("BANKFRAME_OPENED");
Zerotorescue@80 518
Zerotorescue@80 519 -- Guild
Zerotorescue@84 520 self:GUILDBANKFRAME_CLOSED();
Zerotorescue@84 521 self:UnregisterEvent("GUILDBANKFRAME_OPENED");
Zerotorescue@110 522
Zerotorescue@110 523 -- -- Mailbox
Zerotorescue@110 524 -- self:MAIL_CLOSED();
Zerotorescue@110 525 -- self:UnregisterEvent("MAIL_SHOW");
Zerotorescue@80 526 end
Zerotorescue@80 527
Zerotorescue@80 528 function mod:Pause()
Zerotorescue@80 529 paused = true;
Zerotorescue@80 530 end
Zerotorescue@80 531
Zerotorescue@80 532 function mod:Unpause()
Zerotorescue@80 533 paused = nil;
Zerotorescue@80 534 end