diff 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
line wrap: on
line diff
--- a/Summary.lua	Wed Oct 20 01:37:22 2010 +0200
+++ b/Summary.lua	Thu Oct 28 19:14:30 2010 +0200
@@ -3,6 +3,13 @@
 
 local AceGUI = LibStub("AceGUI-3.0");
 
+local unknownItemName = "Unknown (#%d)";
+
+local itemsCache = {};
+
+local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT = 0, 0;
+local cacheStart;
+
 function mod:OnEnable()
 	self:RegisterWidgets();
 	
@@ -11,6 +18,14 @@
 		mod:BuildMain();
 		mod:Build();
 	end, "s", "sum", "summary");
+	addon:RegisterSlash(function()
+		if mod.frame then
+			mod.frame:SetWidth(650);
+			mod.frame:SetHeight(600);
+			
+			print("Resetting width and height of the summary frame.");
+		end
+	end, "r", "reset");
 end
 
 local function ShowTooltip(self)
@@ -74,11 +89,6 @@
 	AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion);
 end
 
-local itemsCache = {};
-
-local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT = 0, 0;
-local cacheStart;
-
 function mod:BuildMain()
 	LibStub("AceConfigDialog-3.0"):Close("InventoriumOptions");
 	
@@ -86,6 +96,7 @@
 	
 	-- Main Window
 	mod.frame = AceGUI:Create("Frame");
+	_G["InventoriumSummary"] = mod.frame; -- name the global frame so it can be put in the UISpecialFrames
 	mod.frame:SetTitle("Summary");
 	mod.frame:SetLayout("Fill");
 	mod.frame:SetCallback("OnClose", function(widget)
@@ -101,6 +112,9 @@
 		addon.db.global.defaults.summary.height = height;
 	end;
 	
+	-- Close on escape
+	tinsert(UISpecialFrames, "InventoriumSummary");
+	
 	-- ScrollFrame child
 	mod.scrollFrame = AceGUI:Create("ScrollFrame");
 	mod.scrollFrame:SetLayout("Flow");
@@ -265,7 +279,7 @@
 			local showWhenBelow = (values.summaryThresholdShow or (values.summaryThresholdShow == nil and addon.db.global.defaults.summaryThresholdShow));
 			local priceThreshold = (values.priceThreshold or (values.priceThreshold == nil and addon.db.global.defaults.priceThreshold));
 			local hideWhenBelowPriceThreshold = (values.hideFromSummaryWhenBelowPriceThreshold or (values.hideFromSummaryWhenBelowPriceThreshold == nil and addon.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold));
-			
+			local alwaysGetAuctionValue = (values.alwaysGetAuctionValue or (values.alwaysGetAuctionValue == nil and addon.db.global.defaults.alwaysGetAuctionValue));
 			
 			-- Make group container
 			local iGroup = AceGUI:Create("InlineGroupWithButton");
@@ -343,8 +357,6 @@
 			if not itemsCache[groupName] then
 				itemsCache[groupName] = {};
 				
-				local unknownItemName = "Unknown (#%d)";
-				
 				-- Sort item list
 				for itemId, _ in pairs(values.items) do
 					local itemName, itemLink, itemRarity = GetItemInfo(itemId);
@@ -352,10 +364,10 @@
 					table.insert(itemsCache[groupName], {
 						id = itemId,
 						name = itemName or unknownItemName:format(itemId),
-						link = itemLink or unknownItemName:format(itemId),
-						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),
+						link = itemLink,
+						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),
 						rarity = itemRarity or 1,
-						count = -3,--addon:GetItemCount(itemId),
+						count = -3,--addon:GetItemCount(itemId, groupName),
 						set = {},
 					});
 					CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
@@ -412,9 +424,21 @@
 			for i, item in pairs(itemsCache[groupName]) do
 				if ( item.count / minimumStock ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then
 					local btnItemLink = AceGUI:Create("ItemLinkButton");
-					--btnItemLink:SetUserData("exec", function()
-					--	print("Nothing happening yet.");
-					--end);
+					btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName)
+						local itemName, itemLink = GetItemInfo(itemId);
+						
+						if buttonName == "LeftButton" and IsShiftKeyDown() and itemLink then
+							ChatEdit_InsertLink(itemLink);
+						elseif buttonName == "LeftButton" and IsAltKeyDown() and itemName and AuctionFrame and AuctionFrame:IsShown() and AuctionFrameBrowse then
+							-- Start search at page 0
+							AuctionFrameBrowse.page = 0;
+							
+							-- Set the search field (even though we could use "ChatEdit_InsertLink", this ensures the right field is updated)
+							BrowseName:SetText(itemName)
+							
+							QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0);
+						end
+					end);
 					btnItemLink:SetRelativeWidth(.7);
 					btnItemLink:SetItemId(item.id);
 					
@@ -495,7 +519,7 @@
 			if item.set then
 				if item.count == -3 then
 					-- Only if item count was queued, update it
-					item.count = addon:GetItemCount(item.id);
+					item.count = addon:GetItemCount(item.id, groupName);
 					if item.set.current and item.set.current.SetText then
 						item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock));
 					end
@@ -503,9 +527,15 @@
 				
 				if item.value == -3 then
 					-- Only if item value was queued, update it
-					item.value = addon:GetAuctionValue(item.link);
-					if item.set.value and item.set.value.SetText then
-						item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
+					
+					-- The itemlink might not have been loaded yet in which case we retry
+					item.link = item.link or select(2, GetItemInfo(item.id));
+					
+					if item.link then
+						item.value = addon:GetAuctionValue(item.link, groupName);
+						if item.set.value and item.set.value.SetText then
+							item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
+						end
 					end
 				end
 				
@@ -565,7 +595,9 @@
 		return "|cffffff00Unknown|r";
 	elseif value == -4 then
 		return "|cff00ff00-|r";
-	elseif value < priceThreshold then
+	elseif value == -5 then
+		return "|cffff9933Error|r";
+	elseif priceThreshold and value < priceThreshold then
 		return ("|cffaaaaaa%s|r"):format(addon:ReadableMoney(value or 0, true):gsub("|([a-fA-F0-9]+)([gsc]+)|r", "%2"));
 	else
 		return addon:ReadableMoney(value or 0, true);