comparison Summary.lua @ 23:7d7aaa3fbe94

If Auctioneer data can not be retrieved, it will now display as ?Error? rather than break the caching. The premade group update check should now be fully functional. You can now shift-click item links into other text fields and alt-click while the auction house window is open to search it. Added an option to the config to select the data used for the local item data. This option currently does nothing and is just a placeholder (just like the ?alert when below threshold? option). Removed useless pullout hiding code for the track at characters option. Added an option to always show the auction value, even when the threshold is nil. When overriding an option, the default value should now be copied into the group, even without you changing it back and forth (previously if you overridden an option and didn?t change the value, it would still use the default value). The ?Stock settings? tab is now called the ?General? tab. The ?Group Management? tab is now called ?Management? tab. Added tooltip descriptions to the ?Add items? and ?Current items? tabs. Added the option to override the preferred addons to individual groups. No longer copying tables when making the groups list in the config. We can just reference it (saves quite some memory). Bumped the interface version from 30300 to 40000. Added slash command arguement ?reset? (or the short version ?r?) to reset the size of the summary frame (I messed mine up while making some screenshots /facepalm). You can now close the summary frame with escape.
author Zerotorescue
date Thu, 28 Oct 2010 19:14:30 +0200
parents 8f5c02113c5c
children 95c813292a88
comparison
equal deleted inserted replaced
22:46815d4f69e8 23:7d7aaa3fbe94
1 local addon = select(2, ...); 1 local addon = select(2, ...);
2 local mod = addon:NewModule("Summary", "AceEvent-3.0", "AceTimer-3.0"); 2 local mod = addon:NewModule("Summary", "AceEvent-3.0", "AceTimer-3.0");
3 3
4 local AceGUI = LibStub("AceGUI-3.0"); 4 local AceGUI = LibStub("AceGUI-3.0");
5
6 local unknownItemName = "Unknown (#%d)";
7
8 local itemsCache = {};
9
10 local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT = 0, 0;
11 local cacheStart;
5 12
6 function mod:OnEnable() 13 function mod:OnEnable()
7 self:RegisterWidgets(); 14 self:RegisterWidgets();
8 15
9 -- Register our own slash commands 16 -- Register our own slash commands
10 addon:RegisterSlash(function() 17 addon:RegisterSlash(function()
11 mod:BuildMain(); 18 mod:BuildMain();
12 mod:Build(); 19 mod:Build();
13 end, "s", "sum", "summary"); 20 end, "s", "sum", "summary");
21 addon:RegisterSlash(function()
22 if mod.frame then
23 mod.frame:SetWidth(650);
24 mod.frame:SetHeight(600);
25
26 print("Resetting width and height of the summary frame.");
27 end
28 end, "r", "reset");
14 end 29 end
15 30
16 local function ShowTooltip(self) 31 local function ShowTooltip(self)
17 -- If this function is called from a widget, self is the widget and self.frame the actual frame 32 -- If this function is called from a widget, self is the widget and self.frame the actual frame
18 local this = self.frame or self; 33 local this = self.frame or self;
72 end 87 end
73 88
74 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion); 89 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion);
75 end 90 end
76 91
77 local itemsCache = {};
78
79 local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT = 0, 0;
80 local cacheStart;
81
82 function mod:BuildMain() 92 function mod:BuildMain()
83 LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions"); 93 LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions");
84 94
85 self:CloseFrame(); 95 self:CloseFrame();
86 96
87 -- Main Window 97 -- Main Window
88 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
89 mod.frame:SetTitle("Summary"); 100 mod.frame:SetTitle("Summary");
90 mod.frame:SetLayout("Fill"); 101 mod.frame:SetLayout("Fill");
91 mod.frame:SetCallback("OnClose", function(widget) 102 mod.frame:SetCallback("OnClose", function(widget)
92 mod:CancelTimer(self.tmrUpdater, true); 103 mod:CancelTimer(self.tmrUpdater, true);
93 mod:CloseFrame(); 104 mod:CloseFrame();
99 end; 110 end;
100 mod.frame.OnHeightSet = function(_, height) 111 mod.frame.OnHeightSet = function(_, height)
101 addon.db.global.defaults.summary.height = height; 112 addon.db.global.defaults.summary.height = height;
102 end; 113 end;
103 114
115 -- Close on escape
116 tinsert(UISpecialFrames, "InventoriumSummary");
117
104 -- ScrollFrame child 118 -- ScrollFrame child
105 mod.scrollFrame = AceGUI:Create("ScrollFrame"); 119 mod.scrollFrame = AceGUI:Create("ScrollFrame");
106 mod.scrollFrame:SetLayout("Flow"); 120 mod.scrollFrame:SetLayout("Flow");
107 121
108 mod.frame:AddChild(mod.scrollFrame); 122 mod.frame:AddChild(mod.scrollFrame);
263 -- Get group settings 277 -- Get group settings
264 local minimumStock = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock)); 278 local minimumStock = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock));
265 local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow)); 279 local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow));
266 local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold)); 280 local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold));
267 local hideWhenBelowPriceThreshold = (values.hideFromSummaryWhenBelowPriceThreshold or (values.hideFromSummaryWhenBelowPriceThreshold == nil and addon.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold)); 281 local hideWhenBelowPriceThreshold = (values.hideFromSummaryWhenBelowPriceThreshold or (values.hideFromSummaryWhenBelowPriceThreshold == nil and addon.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold));
268 282 local alwaysGetAuctionValue = (values.alwaysGetAuctionValue or (values.alwaysGetAuctionValue == nil and addon.db.global.defaults.alwaysGetAuctionValue));
269 283
270 -- Make group container 284 -- Make group container
271 local iGroup = AceGUI:Create("InlineGroupWithButton"); 285 local iGroup = AceGUI:Create("InlineGroupWithButton");
272 iGroup:PauseLayout(); 286 iGroup:PauseLayout();
273 iGroup:SetTitle(groupName); 287 iGroup:SetTitle(groupName);
341 355
342 -- Retrieve items list 356 -- Retrieve items list
343 if not itemsCache[groupName] then 357 if not itemsCache[groupName] then
344 itemsCache[groupName] = {}; 358 itemsCache[groupName] = {};
345 359
346 local unknownItemName = "Unknown (#%d)";
347
348 -- Sort item list 360 -- Sort item list
349 for itemId, _ in pairs(values.items) do 361 for itemId, _ in pairs(values.items) do
350 local itemName, itemLink, itemRarity = GetItemInfo(itemId); 362 local itemName, itemLink, itemRarity = GetItemInfo(itemId);
351 363
352 table.insert(itemsCache[groupName], { 364 table.insert(itemsCache[groupName], {
353 id = itemId, 365 id = itemId,
354 name = itemName or unknownItemName:format(itemId), 366 name = itemName or unknownItemName:format(itemId),
355 link = itemLink or unknownItemName:format(itemId), 367 link = itemLink,
356 value = ((priceThreshold == 0) and -4) or -3,-- if no price threshold is set for this item, then don't look it up either --addon:GetAuctionValue(itemLink), 368 value = ((priceThreshold == 0 and not alwaysGetAuctionValue) and -4) or -3,-- if (no price threshold is set for this item and you don't want to always get auction value), then don't look it up either --addon:GetAuctionValue(itemLink),
357 rarity = itemRarity or 1, 369 rarity = itemRarity or 1,
358 count = -3,--addon:GetItemCount(itemId), 370 count = -3,--addon:GetItemCount(itemId, groupName),
359 set = {}, 371 set = {},
360 }); 372 });
361 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1; 373 CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
362 end 374 end
363 end 375 end
410 422
411 -- Show itemslist 423 -- Show itemslist
412 for i, item in pairs(itemsCache[groupName]) do 424 for i, item in pairs(itemsCache[groupName]) do
413 if ( item.count / minimumStock ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then 425 if ( item.count / minimumStock ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then
414 local btnItemLink = AceGUI:Create("ItemLinkButton"); 426 local btnItemLink = AceGUI:Create("ItemLinkButton");
415 --btnItemLink:SetUserData("exec", function() 427 btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName)
416 -- print("Nothing happening yet."); 428 local itemName, itemLink = GetItemInfo(itemId);
417 --end); 429
430 if buttonName == "LeftButton" and IsShiftKeyDown() and itemLink then
431 ChatEdit_InsertLink(itemLink);
432 elseif buttonName == "LeftButton" and IsAltKeyDown() and itemName and AuctionFrame and AuctionFrame:IsShown() and AuctionFrameBrowse then
433 -- Start search at page 0
434 AuctionFrameBrowse.page = 0;
435
436 -- Set the search field (even though we could use "ChatEdit_InsertLink", this ensures the right field is updated)
437 BrowseName:SetText(itemName)
438
439 QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0);
440 end
441 end);
418 btnItemLink:SetRelativeWidth(.7); 442 btnItemLink:SetRelativeWidth(.7);
419 btnItemLink:SetItemId(item.id); 443 btnItemLink:SetItemId(item.id);
420 444
421 iGroup:AddChild(btnItemLink); 445 iGroup:AddChild(btnItemLink);
422 446
493 517
494 for _, item in pairs(items) do 518 for _, item in pairs(items) do
495 if item.set then 519 if item.set then
496 if item.count == -3 then 520 if item.count == -3 then
497 -- Only if item count was queued, update it 521 -- Only if item count was queued, update it
498 item.count = addon:GetItemCount(item.id); 522 item.count = addon:GetItemCount(item.id, groupName);
499 if item.set.current and item.set.current.SetText then 523 if item.set.current and item.set.current.SetText then
500 item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock)); 524 item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock));
501 end 525 end
502 end 526 end
503 527
504 if item.value == -3 then 528 if item.value == -3 then
505 -- Only if item value was queued, update it 529 -- Only if item value was queued, update it
506 item.value = addon:GetAuctionValue(item.link); 530
507 if item.set.value and item.set.value.SetText then 531 -- The itemlink might not have been loaded yet in which case we retry
508 item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold)); 532 item.link = item.link or select(2, GetItemInfo(item.id));
533
534 if item.link then
535 item.value = addon:GetAuctionValue(item.link, groupName);
536 if item.set.value and item.set.value.SetText then
537 item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
538 end
509 end 539 end
510 end 540 end
511 541
512 item.set = nil; 542 item.set = nil;
513 543
563 return "|cff0000ffNo AH mod|r"; 593 return "|cff0000ffNo AH mod|r";
564 elseif value == -3 then 594 elseif value == -3 then
565 return "|cffffff00Unknown|r"; 595 return "|cffffff00Unknown|r";
566 elseif value == -4 then 596 elseif value == -4 then
567 return "|cff00ff00-|r"; 597 return "|cff00ff00-|r";
568 elseif value < priceThreshold then 598 elseif value == -5 then
599 return "|cffff9933Error|r";
600 elseif priceThreshold and value < priceThreshold then
569 return ("|cffaaaaaa%s|r"):format(addon:ReadableMoney(value or 0, true):gsub("|([a-fA-F0-9]+)([gsc]+)|r", "%2")); 601 return ("|cffaaaaaa%s|r"):format(addon:ReadableMoney(value or 0, true):gsub("|([a-fA-F0-9]+)([gsc]+)|r", "%2"));
570 else 602 else
571 return addon:ReadableMoney(value or 0, true); 603 return addon:ReadableMoney(value or 0, true);
572 end 604 end
573 end 605 end