comparison Summary.lua @ 57:03c0610e9c1e

Added a minimum local stock option. I reckon people will want to keep maybe a stack in their bags/AH and another stack in their bank. Added a seperate alert option for the local stock option. When your selected item count addon isn?t enabled the options help text will now display the reason for this. No more debugging of something that ain?t broken. The minimum stock will now be displayed next to the current stock values rather than as a seperate column.
author Zerotorescue
date Tue, 21 Dec 2010 14:24:15 +0100
parents 06fee4208bf2
children d903b0a151d3
comparison
equal deleted inserted replaced
56:b33248fb89dd 57:03c0610e9c1e
95 self:CloseFrame(); 95 self:CloseFrame();
96 96
97 -- Main Window 97 -- Main Window
98 mod.frame = AceGUI:Create("Frame"); 98 mod.frame = AceGUI:Create("Frame");
99 _G["InventoriumSummary"] = mod.frame; -- name the global frame so it can be put in the UISpecialFrames 99 _G["InventoriumSummary"] = mod.frame; -- name the global frame so it can be put in the UISpecialFrames
100 mod.frame:SetTitle("Summary"); 100 mod.frame:SetTitle("Inventory Summary");
101 mod.frame:SetLayout("Fill"); 101 mod.frame:SetLayout("Fill");
102 mod.frame:SetCallback("OnClose", function(widget) 102 mod.frame:SetCallback("OnClose", function(widget)
103 mod:CancelTimer(self.tmrUpdater, true); 103 mod:CancelTimer(self.tmrUpdater, true);
104 mod:CloseFrame(); 104 mod:CloseFrame();
105 end); 105 end);
151 end 151 end
152 sortMethod = subject; 152 sortMethod = subject;
153 153
154 mod:Build(); 154 mod:Build();
155 end 155 end
156 156
157 -- From http://www.wowwiki.com/API_sort 157 -- From http://www.wowwiki.com/API_sort
158 local function pairsByKeys (t, f) 158 local function pairsByKeys (t, f)
159 local a = {} 159 local a = {}
160 for n in pairs(t) do table.insert(a, n) end 160 for n in pairs(t) do table.insert(a, n) end
161 table.sort(a, f) 161 table.sort(a, f)
274 -- Does this group have any items and do we want to track it at this char? 274 -- Does this group have any items and do we want to track it at this char?
275 if values.items and trackAt[playerName] then 275 if values.items and trackAt[playerName] then
276 276
277 277
278 -- Get group settings 278 -- Get group settings
279 local minimumStock = addon:GetOptionByKey(groupName, "minimumStock"); 279 local minGlobalStock = addon:GetOptionByKey(groupName, "minimumStock");
280 local minLocalStock = addon:GetOptionByKey(groupName, "minimumLocalStock");
280 local showWhenBelow = addon:GetOptionByKey(groupName, "summaryThresholdShow"); 281 local showWhenBelow = addon:GetOptionByKey(groupName, "summaryThresholdShow");
281 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold"); 282 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
282 local hideWhenBelowPriceThreshold = addon:GetOptionByKey(groupName, "summaryHidePriceThreshold"); 283 local hideWhenBelowPriceThreshold = addon:GetOptionByKey(groupName, "summaryHidePriceThreshold");
283 local alwaysGetAuctionValue = addon:GetOptionByKey(groupName, "alwaysGetAuctionValue"); 284 local alwaysGetAuctionValue = addon:GetOptionByKey(groupName, "alwaysGetAuctionValue");
284 285
303 304
304 -- Itemlink 305 -- Itemlink
305 local lblItem = AceGUI:Create("InteractiveLabel"); 306 local lblItem = AceGUI:Create("InteractiveLabel");
306 lblItem:SetText("|cfffed000Item|r"); 307 lblItem:SetText("|cfffed000Item|r");
307 lblItem:SetFontObject(GameFontHighlight); 308 lblItem:SetFontObject(GameFontHighlight);
308 lblItem:SetRelativeWidth(.6); 309 lblItem:SetRelativeWidth(.7);
309 lblItem:SetCallback("OnClick", function() ReSort("item"); end); 310 lblItem:SetCallback("OnClick", function() ReSort("item"); end);
310 lblItem:SetCallback("OnEnter", ShowTooltip); 311 lblItem:SetCallback("OnEnter", ShowTooltip);
311 lblItem:SetCallback("OnLeave", HideTooltip); 312 lblItem:SetCallback("OnLeave", HideTooltip);
312 lblItem.frame.tooltipTitle = "Item"; 313 lblItem.frame.tooltipTitle = "Item";
313 lblItem.frame.tooltip = "Sort on the item quality, then name."; 314 lblItem.frame.tooltip = "Sort on the item quality, then name.";
337 lblQuantity:SetCallback("OnLeave", HideTooltip); 338 lblQuantity:SetCallback("OnLeave", HideTooltip);
338 lblQuantity.frame.tooltipTitle = "Current stock"; 339 lblQuantity.frame.tooltipTitle = "Current stock";
339 lblQuantity.frame.tooltip = "Sort on the amount of items currently in stock."; 340 lblQuantity.frame.tooltip = "Sort on the amount of items currently in stock.";
340 341
341 iGroup:AddChild(lblQuantity); 342 iGroup:AddChild(lblQuantity);
342
343 -- Required stock
344 local lblMinimumStock = AceGUI:Create("InteractiveLabel");
345 lblMinimumStock:SetText("|cfffed000Min.|r");
346 lblMinimumStock:SetFontObject(GameFontHighlight);
347 lblMinimumStock:SetRelativeWidth(.099);
348 lblMinimumStock:SetCallback("OnClick", function() ReSort("percentage"); end);
349 lblMinimumStock:SetCallback("OnEnter", ShowTooltip);
350 lblMinimumStock:SetCallback("OnLeave", HideTooltip);
351 lblMinimumStock.frame.tooltipTitle = "Minimum stock";
352 lblMinimumStock.frame.tooltip = "Sort on the minimum amount of items you wish to keep in stock.";
353
354 iGroup:AddChild(lblMinimumStock);
355 343
356 -- Lowest value 344 -- Lowest value
357 local lblValue = AceGUI:Create("InteractiveLabel"); 345 local lblValue = AceGUI:Create("InteractiveLabel");
358 lblValue:SetText("|cfffed000Value|r"); 346 lblValue:SetText("|cfffed000Value|r");
359 lblValue:SetFontObject(GameFontHighlight); 347 lblValue:SetFontObject(GameFontHighlight);
419 if sortDirectory == "ASC" then 407 if sortDirectory == "ASC" then
420 return a.localCount < b.localCount; 408 return a.localCount < b.localCount;
421 else 409 else
422 return a.localCount > b.localCount; 410 return a.localCount > b.localCount;
423 end 411 end
424 elseif sortMethod == "percentage" then
425 if sortDirectory == "ASC" then
426 return ( a.count / minimumStock ) < ( b.count / minimumStock );
427 else
428 return ( a.count / minimumStock ) > ( b.count / minimumStock );
429 end
430 elseif sortMethod == "value" then 412 elseif sortMethod == "value" then
431 if sortDirectory == "ASC" then 413 if sortDirectory == "ASC" then
432 return a.value < b.value; 414 return a.value < b.value;
433 else 415 else
434 return a.value > b.value; 416 return a.value > b.value;
443 425
444 -- Show itemslist 426 -- Show itemslist
445 for i, item in pairs(itemsCache[groupName]) do 427 for i, item in pairs(itemsCache[groupName]) do
446 -- Go through all items for this group 428 -- Go through all items for this group
447 429
448 if (( item.count / minimumStock ) < showWhenBelow or ( item.localCount / minimumStock ) < showWhenBelow) and (not hideWhenBelowPriceThreshold or priceThreshold == 0 or item.value < 0 or item.value >= priceThreshold) then 430 if (( item.count / minGlobalStock ) < showWhenBelow or ( item.localCount / minLocalStock ) < showWhenBelow) and (not hideWhenBelowPriceThreshold or priceThreshold == 0 or item.value < 0 or item.value >= priceThreshold) then
449 -- if the option "hide when below threshold" is disabled or no price threshold is set or the value is above the price threshold or the value could not be determined, proceed 431 -- if the option "hide when below threshold" is disabled or no price threshold is set or the value is above the price threshold or the value could not be determined, proceed
450 432
451 local btnItemLink = AceGUI:Create("ItemLinkButton"); 433 local btnItemLink = AceGUI:Create("ItemLinkButton");
452 btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName) 434 btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName)
453 local itemName, itemLink = GetItemInfo(itemId); 435 local itemName, itemLink = GetItemInfo(itemId);
462 BrowseName:SetText(itemName) 444 BrowseName:SetText(itemName)
463 445
464 QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0); 446 QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0);
465 end 447 end
466 end); 448 end);
467 btnItemLink:SetRelativeWidth(.6); 449 btnItemLink:SetRelativeWidth(.7);
468 btnItemLink:SetItemId(item.id); 450 btnItemLink:SetItemId(item.id);
469 451
470 iGroup:AddChild(btnItemLink); 452 iGroup:AddChild(btnItemLink);
471 453
472 -- Local quantity 454 -- Local quantity
473 local lblLocal = AceGUI:Create("Label"); 455 local lblLocal = AceGUI:Create("Label");
474 lblLocal:SetText(self:DisplayItemCount(item.localCount, minimumStock)); 456 lblLocal:SetText(self:DisplayItemCount(item.localCount, minLocalStock));
475 lblLocal:SetRelativeWidth(.099); 457 lblLocal:SetRelativeWidth(.099);
476 458
477 iGroup:AddChild(lblLocal); 459 iGroup:AddChild(lblLocal);
478 460
479 -- Current quantity 461 -- Current quantity
480 local lblQuantity = AceGUI:Create("Label"); 462 local lblQuantity = AceGUI:Create("Label");
481 lblQuantity:SetText(self:DisplayItemCount(item.count, minimumStock)); 463 lblQuantity:SetText(self:DisplayItemCount(item.count, minGlobalStock));
482 lblQuantity:SetRelativeWidth(.099); 464 lblQuantity:SetRelativeWidth(.099);
483 465
484 iGroup:AddChild(lblQuantity); 466 iGroup:AddChild(lblQuantity);
485 467
486 -- Required stock 468 --[[
487 local lblMinimumStock = AceGUI:Create("Label"); 469 -- Required stock
488 lblMinimumStock:SetText(minimumStock); 470 local lblMinimumStock = AceGUI:Create("Label");
489 lblMinimumStock:SetRelativeWidth(.099); 471 lblMinimumStock:SetText(minGlobalStock);
490 472 lblMinimumStock:SetRelativeWidth(.099);
491 iGroup:AddChild(lblMinimumStock); 473
474 iGroup:AddChild(lblMinimumStock);
475 ]]
492 476
493 -- Value 477 -- Value
494 local lblValue = AceGUI:Create("Label"); 478 local lblValue = AceGUI:Create("Label");
495 lblValue:SetText(self:DisplayMoney(item.value, priceThreshold)); 479 lblValue:SetText(self:DisplayMoney(item.value, priceThreshold));
496 lblValue:SetRelativeWidth(.099); 480 lblValue:SetRelativeWidth(.099);
545 529
546 function mod:UpdateNextItem() 530 function mod:UpdateNextItem()
547 local i = 0; 531 local i = 0;
548 532
549 for groupName, items in pairs(itemsCache) do 533 for groupName, items in pairs(itemsCache) do
550 local minimumStock = addon:GetOptionByKey(groupName, "minimumStock"); 534 local minGlobalStock = addon:GetOptionByKey(groupName, "minimumStock");
535 local minLocalStock = addon:GetOptionByKey(groupName, "minimumLocalStock");
551 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold"); 536 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
552 537
553 for _, item in pairs(items) do 538 for _, item in pairs(items) do
554 if item.set then 539 if item.set then
555 if item.count == -3 then 540 if item.count == -3 then
556 -- Only if item count was queued, update it 541 -- Only if item count was queued, update it
557 item.count = addon:GetItemCount(item.id, groupName); 542 item.count = addon:GetItemCount(item.id, groupName);
558 if item.set.current and item.set.current.SetText then 543 if item.set.current and item.set.current.SetText then
559 item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock)); 544 item.set.current:SetText(self:DisplayItemCount(item.count, minGlobalStock));
560 end 545 end
561 end 546 end
562 547
563 if item.localCount == -3 then 548 if item.localCount == -3 then
564 -- Only if item count was queued, update it 549 -- Only if item count was queued, update it
565 item.localCount = addon:GetLocalItemCount(item.id, groupName); 550 item.localCount = addon:GetLocalItemCount(item.id, groupName);
566 if item.set.localCount and item.set.localCount.SetText then 551 if item.set.localCount and item.set.localCount.SetText then
567 item.set.localCount:SetText(self:DisplayItemCount(item.localCount, minimumStock)); 552 item.set.localCount:SetText(self:DisplayItemCount(item.localCount, minLocalStock));
568 end 553 end
569 end 554 end
570 555
571 if item.value == -3 then 556 if item.value == -3 then
572 -- Only if item value was queued, update it 557 -- Only if item value was queued, update it
651 if value == -1 then 636 if value == -1 then
652 return "|cffffff00Unknown|r"; 637 return "|cffffff00Unknown|r";
653 elseif value == -3 then 638 elseif value == -3 then
654 return "|cffffff00Unknown|r"; 639 return "|cffffff00Unknown|r";
655 else 640 else
656 return self:ColorCode(value, minimumStock); 641 return ("%s / %d"):format(self:ColorCode(value, minimumStock), minimumStock);
657 end 642 end
658 end 643 end
659 644
660 function mod:NumberFormat(num) 645 function mod:NumberFormat(num)
661 local formatted = string.gsub(num, "(%d)(%d%d%d)$", "%1,%2", 1); 646 local formatted = string.gsub(num, "(%d)(%d%d%d)$", "%1,%2", 1);