changeset 73:6216b754350d

Default size for the summary window increase to 700 pixels (from 650). Cached item name and rarity no longer have a default and will be nil if the value is unknown. Cached item name, rarity and link can now be updated when the itemlink element is build. Item element now gets the item table passed rather than just the item id. If the item link is already known, this prevent an additional GetItemInfo call.
author Zerotorescue
date Fri, 24 Dec 2010 16:10:20 +0100
parents 7ca83ad9d67a
children 8d11fc88ecab
files Summary.lua Widgets.lua
diffstat 2 files changed, 44 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Summary.lua	Thu Dec 23 18:33:05 2010 +0100
+++ b/Summary.lua	Fri Dec 24 16:10:20 2010 +0100
@@ -25,7 +25,7 @@
 	-- /im reset
 	addon:RegisterSlash(function()
 		if mod.frame then
-			mod.frame:SetWidth(650);
+			mod.frame:SetWidth(700);
 			mod.frame:SetHeight(600);
 			
 			print("Resetting width and height of the summary frame.");
@@ -328,10 +328,10 @@
 					
 					tinsert(itemsCache[groupName], {
 						id = itemId,
-						name = itemName or printf(unknownItemName, itemId),
-						link = itemLink,
+						name = itemName, -- may be nil
+						link = itemLink, -- may be nil
 						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,
+						rarity = itemRarity, -- may be nil
 						count = -3,--addon:GetItemCount(itemId, groupName),
 						localCount = -3,
 						set = {},
@@ -346,19 +346,26 @@
 			
 			-- Sort items
 			table.sort(itemsCache[groupName], function(a, b)
-				if sortMethod == "item" and a.rarity == b.rarity then
+				local aRarity = a.rarity or 1;
+				local bRarity = b.rarity or 1;
+				
+				if sortMethod == "item" and aRarity == bRarity then
 					-- Do a name-compare for items of the same rarity
 					-- Otherwise epics first, then junk
+					
+					local aName = a.name or printf(unknownItemName, a.id);
+					local bName = b.name or printf(unknownItemName, b.id);
+					
 					if sortDirectory == "ASC" then
-						return supper(a.name) < supper(b.name);
+						return supper(aName) < supper(bName);
 					else
-						return supper(a.name) > supper(b.name);
+						return supper(aName) > supper(bName);
 					end
 				elseif sortMethod == "item"  then
 					if sortDirectory == "ASC" then
-						return a.rarity > b.rarity; -- the comparers were reversed because we want epics first
+						return aRarity > bRarity; -- the comparers were reversed because we want epics first
 					else
-						return a.rarity < b.rarity; -- the comparers were reversed because we want epics first
+						return aRarity < bRarity; -- the comparers were reversed because we want epics first
 					end
 				elseif sortMethod == "current" then
 					if sortDirectory == "ASC" then
@@ -410,7 +417,7 @@
 						end
 					end);
 					btnItemLink:SetRelativeWidth(.7);
-					btnItemLink:SetItemId(item.id);
+					btnItemLink:SetItem(item);
 					
 					iGroup:AddChild(btnItemLink);
 					
--- a/Widgets.lua	Thu Dec 23 18:33:05 2010 +0100
+++ b/Widgets.lua	Fri Dec 24 16:10:20 2010 +0100
@@ -109,6 +109,33 @@
     		
     		self:originalSetText(itemLink);
 	    end;
+	    widget.SetItem = function(self, item)
+ 		   	self:SetUserData("itemId", item.id);
+ 		   	
+	   		-- Put the icon in front of it
+			self:SetImage(GetItemIcon(item.id));
+			-- Standardize the size
+			self:SetImageSize(16, 16);
+    		
+			-- Make readable font
+    		self:SetFontObject(GameFontHighlight);
+    		
+    		if not item.link then
+    			-- If no item link was cached, give it another try
+    			
+				local itemName, itemLink, itemRarity = GetItemInfo(item.id);
+    			
+				-- item is a table, so passed by reference, so updatable
+				item.name = itemName;
+				item.link = itemLink;
+				item.rarity = itemRarity;
+    		end
+    		
+    		-- We don't want to set the itemId as text, but rather the item link, so get that.
+    		local itemLink = item.link or ("Unknown (#%d)"):format(itemId);
+    		
+    		self:originalSetText(itemLink);
+	    end;
 		
 		return widget;
 	end