comparison Modules/Scanner.lua @ 111:41f0689dfda1

This implementation of vendor buying did not work well. Too many customizations were needed that made the code hard to read and understand and eventually it was found that vendor buying should be based on refill target, not local stock. The mover/refiller is not meant for this, we should just do this somewhere else.
author Zerotorescue
date Fri, 14 Jan 2011 23:31:12 +0100
parents 67bd5057ecb7
children 239e25a058c7
comparison
equal deleted inserted replaced
110:67bd5057ecb7 111:41f0689dfda1
16 currentLocation = nil; 16 currentLocation = nil;
17 17
18 InventoriumItemMover:Hide(); 18 InventoriumItemMover:Hide();
19 end 19 end
20 20
21 local function UseStorageRefillST(withPrices) 21 local function UseStorageRefillST()
22 local frame = InventoriumItemMover; -- both for speed as code-consistency 22 local frame = InventoriumItemMover; -- both for speed as code-consistency
23 23
24 -- Scrolling table with a list of items to be moved 24 -- Scrolling table with a list of items to be moved
25 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size 25 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size
26 local headers = { 26 local headers = {
27 { 27 {
28 ["name"] = "Item", 28 ["name"] = "Item",
29 ["width"] = (scrollTableWidth * ((withPrices and .5) or .60)), 29 ["width"] = (scrollTableWidth * .60),
30 ["defaultsort"] = "asc", 30 ["defaultsort"] = "asc",
31 ["comparesort"] = function(this, aRow, bRow, column) 31 ["comparesort"] = function(this, aRow, bRow, column)
32 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId); 32 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId);
33 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId); 33 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId);
34 local template = "%d%s"; 34 local template = "%d%s";
54 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Moving"), 54 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Moving"),
55 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of movable items."), 55 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of movable items."),
56 }, 56 },
57 { 57 {
58 ["name"] = "Available", 58 ["name"] = "Available",
59 ["width"] = (scrollTableWidth * ((withPrices and .2) or .25)), 59 ["width"] = (scrollTableWidth * .25),
60 ["align"] = "RIGHT", 60 ["align"] = "RIGHT",
61 ["defaultsort"] = "dsc", 61 ["defaultsort"] = "dsc",
62 ["sortnext"] = 1, 62 ["sortnext"] = 1,
63 ["comparesort"] = function(this, aRow, bRow, column) 63 ["comparesort"] = function(this, aRow, bRow, column)
64 local aAvailablePercent = (this:GetRow(aRow).rowData.available / this:GetRow(aRow).rowData.missing); 64 local aAvailablePercent = (this:GetRow(aRow).rowData.available / this:GetRow(aRow).rowData.missing);
72 end, 72 end,
73 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"), 73 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"),
74 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the availibility percentage."), 74 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the availibility percentage."),
75 }, 75 },
76 }; 76 };
77 if withPrices then
78 table.insert(headers, {
79 ["name"] = "Price",
80 ["width"] = (scrollTableWidth * .15),
81 ["align"] = "RIGHT",
82 ["defaultsort"] = "dsc",
83 ["sortnext"] = 1,
84 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Price"),
85 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the price of this item at this vendor."),
86 });
87 end
88 77
89 local proceedButton = { 78 local proceedButton = {
90 text = "Move Items", 79 text = "Move Items",
91 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Move Items"), 80 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Move Items"),
92 tooltip = (not addon.db.profile.defaults.hideHelp and "Start moving these items from the bank."), 81 tooltip = (not addon.db.profile.defaults.hideHelp and "Start moving these items from the bank."),
209 198
210 itemMove:AddLocation(mailIndex, attachIndex, itemCount); 199 itemMove:AddLocation(mailIndex, attachIndex, itemCount);
211 end 200 end
212 end 201 end
213 end 202 end
214 elseif location == addon.Locations.Merchant then
215 for itemIndex = 1, GetMerchantNumItems() do
216 -- All merchant items
217
218 local itemLink = GetMerchantItemLink(itemIndex);
219 local itemId = itemLink and addon:GetItemId(itemLink);
220 local _, _, vendorValue, _, numAvailable, _, extendedCost = GetMerchantItemInfo(index);
221
222 if itemLink and itemId and numAvailable ~= 0 and not extendedCost then
223 local itemMove;
224 if not itemCache[itemId] then
225 -- If this is the first time we see this item, make a new object
226 itemMove = addon.ContainerItem:New();
227 itemCache[itemId] = itemMove;
228 else
229 -- If we had this item in another slot too
230 itemMove = itemCache[itemId];
231 end
232
233 itemMove:AddLocation(1, itemIndex, numAvailable, vendorValue);
234 end
235 end
236 else 203 else
237 error("Invalid location provided for CacheLocation. Must be Bank or Guild."); 204 error("Invalid location provided for CacheLocation. Must be Bank or Guild.");
238 end 205 end
239 206
240 if not remember then 207 if not remember then
280 247
281 if itemCache[itemId] and missingItems > 0 then 248 if itemCache[itemId] and missingItems > 0 then
282 -- Check how many are available 249 -- Check how many are available
283 local availableItems = ((itemCache[itemId] and itemCache[itemId].totalCount) or 0); 250 local availableItems = ((itemCache[itemId] and itemCache[itemId].totalCount) or 0);
284 -- Calculate how many we'll be moving (less missing than available? use missing, otherwise use available) 251 -- Calculate how many we'll be moving (less missing than available? use missing, otherwise use available)
285 local moving = (((availableItems == -1 or missingItems <= availableItems) and missingItems) or availableItems); 252 local moving = ((missingItems <= availableItems and missingItems) or availableItems);
286 253
287 if availableItems ~= 0 then 254 if availableItems > 0 then
288 addon:Debug("Insufficient %s but this location has %s (moving %d)", IdToItemLink(itemId), ((availableItems == -1 and "unlimited") or availableItems), moving); 255 addon:Debug("Insufficient %s but this location has %d (moving %d)", IdToItemLink(itemId), availableItems, moving);
289 256
290 Mover:AddMove(itemId, moving, missingItems, availableItems, itemCache[itemId]:GetVendorPrice()); 257 Mover:AddMove(itemId, moving, missingItems, availableItems);
291 end 258 end
292 end 259 end
293 end 260 end
294 end 261 end
295 end 262 end
298 265
299 if Mover:HasMoves() then 266 if Mover:HasMoves() then
300 if addon.db.profile.defaults.autoRefillSkipConfirm then 267 if addon.db.profile.defaults.autoRefillSkipConfirm then
301 OnMoveAccept(); 268 OnMoveAccept();
302 else 269 else
303 UseStorageRefillST((location == addon.Locations.Merchant)); 270 UseStorageRefillST();
304 271
305 -- This table is never copied, just referenced. It is the same for every row. 272 -- This table is never copied, just referenced. It is the same for every row.
306 local columns = { 273 local columns = {
307 { 274 {
308 ["value"] = function(data, cols, realrow, column, table) 275 ["value"] = function(data, cols, realrow, column, table)
321 ["color"] = function(data, cols, realrow, column, table) 288 ["color"] = function(data, cols, realrow, column, table)
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 }; 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 };
323 end, 290 end,
324 }, -- missing / available 291 }, -- missing / available
325 }; 292 };
326 if location == addon.Locations.Merchant then
327 table.insert(columns, {
328 ["value"] = function(data, cols, realrow, column, table)
329 return GetCoinTextureString(data[realrow].rowData.price * data[realrow].rowData.num);
330 end,
331 });
332 end
333 293
334 -- Store the list with rows in this 294 -- Store the list with rows in this
335 local data = {}; 295 local data = {};
336 296
337 for i, move in pairs(Mover:GetMoves()) do 297 for i, move in pairs(Mover:GetMoves()) do
422 end 382 end
423 end 383 end
424 384
425 self:RegisterEvent("GUILDBANKFRAME_CLOSED"); 385 self:RegisterEvent("GUILDBANKFRAME_CLOSED");
426 self:RegisterEvent("GUILDBANKBAGSLOTS_CHANGED"); 386 self:RegisterEvent("GUILDBANKBAGSLOTS_CHANGED");
427 end
428
429 function mod:MERCHANT_SHOW()
430 addon:Debug("Scanner:MERCHANT_SHOW");
431
432 self:RegisterEvent("MERCHANT_CLOSED");
433
434 self:Scan(addon.Locations.Merchant);
435 end
436
437 function mod:MERCHANT_CLOSED()
438 addon:Debug("Scanner:MERCHANT_CLOSED");
439
440 self:ClearCache();
441
442 self:UnregisterEvent("MERCHANT_CLOSED");
443
444 InventoriumItemMover:Hide();
445 Mover:ResetQueue();
446 end 387 end
447 388
448 --local previousMailCount; 389 --local previousMailCount;
449 --function mod:MAIL_SHOW() 390 --function mod:MAIL_SHOW()
450 -- addon:Debug("Scanner:MAIL_SHOW"); 391 -- addon:Debug("Scanner:MAIL_SHOW");
496 function mod:OnEnable() 437 function mod:OnEnable()
497 -- Scan once when the bankframe is opened 438 -- Scan once when the bankframe is opened
498 self:RegisterEvent("BANKFRAME_OPENED"); 439 self:RegisterEvent("BANKFRAME_OPENED");
499 self:RegisterEvent("GUILDBANKFRAME_OPENED"); 440 self:RegisterEvent("GUILDBANKFRAME_OPENED");
500 -- self:RegisterEvent("MAIL_SHOW"); 441 -- self:RegisterEvent("MAIL_SHOW");
501 self:RegisterEvent("MERCHANT_SHOW");
502 442
503 Mover = addon:GetModule("Mover"); 443 Mover = addon:GetModule("Mover");
504 444
505 if not InventoriumItemMover then 445 if not InventoriumItemMover then
506 addon:CreateMoverFrame(OnMoveAccept, OnMoveCancel); 446 addon:CreateMoverFrame(OnMoveAccept, OnMoveCancel);