diff Summary.lua @ 9:3bac0bdd59e2

Close the summary frame when opening the config. Remove ?track at? data when exporting/importing a group. Don?t add items when importing a group that are already inside a group.
author Zerotorescue
date Sun, 10 Oct 2010 04:37:21 +0200
parents 1a815139e4c3
children c4d0e5d47e10
line wrap: on
line diff
--- a/Summary.lua	Fri Oct 08 17:11:05 2010 +0200
+++ b/Summary.lua	Sun Oct 10 04:37:21 2010 +0200
@@ -72,8 +72,8 @@
 	mod.frame:SetTitle("Inventory Summary");
 	mod.frame:SetLayout("Fill");
 	mod.frame:SetCallback("OnClose", function(widget)
-		AceGUI:Release(widget);
 		mod:CancelTimer(self.tmrUpdater, true);
+		mod:CloseFrame();
 	end);
 	
 	-- ScrollFrame child
@@ -86,6 +86,13 @@
 	table.wipe(itemsCache);
 end
 
+function mod:CloseFrame()
+	if mod.frame then
+		mod.frame:Release();
+		mod.frame = nil;
+	end
+end
+
 local sortMethod = "item";
 local sortDirectory = "ASC";
 local function ReSort(subject)
@@ -117,7 +124,7 @@
 		-- Does this group have any items and do we want to track it at this char?
 		if values.items and trackAt[playerName] then
 			-- Get group settings
-			local stockRequired = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock));
+			local minimumStock = (values.minimumStock or (values.minimumStock == nil and addon.db.global.defaults.minimumStock));
 			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));
@@ -157,13 +164,13 @@
 			iGroup:AddChild(lblQuantity);
 			
 			-- Required stock
-			local lblStockRequired = AceGUI:Create("InteractiveLabel");
-			lblStockRequired:SetText("|cfffed000Req.|r");
-			lblStockRequired:SetFontObject(GameFontHighlight);
-			lblStockRequired:SetRelativeWidth(0.099);
-			lblStockRequired:SetCallback("OnClick", function() ReSort("percentage"); end);
+			local lblMinimumStock = AceGUI:Create("InteractiveLabel");
+			lblMinimumStock:SetText("|cfffed000Req.|r");
+			lblMinimumStock:SetFontObject(GameFontHighlight);
+			lblMinimumStock:SetRelativeWidth(0.099);
+			lblMinimumStock:SetCallback("OnClick", function() ReSort("percentage"); end);
 			
-			iGroup:AddChild(lblStockRequired);
+			iGroup:AddChild(lblMinimumStock);
 			
 			-- Lowest value
 			local lblValue = AceGUI:Create("InteractiveLabel");
@@ -185,9 +192,9 @@
 						id = itemId,
 						name = itemName,
 						link = itemLink,
-						value = 0,--addon:GetAuctionValue(itemLink),
+						value = -3,--addon:GetAuctionValue(itemLink),
 						rarity = itemRarity,
-						count = 0,--addon:GetItemCount(itemId),
+						count = -3,--addon:GetItemCount(itemId),
 						set = {},
 					});
 					CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
@@ -217,9 +224,9 @@
 					end
 				elseif sortMethod == "percentage" then
 					if sortDirectory == "ASC" then
-						return ( a.count / stockRequired ) < ( b.count / stockRequired );
+						return ( a.count / lblMinimumStock ) < ( b.count / lblMinimumStock );
 					else
-						return ( a.count / stockRequired ) > ( b.count / stockRequired );
+						return ( a.count / lblMinimumStock ) > ( b.count / lblMinimumStock );
 					end
 				elseif sortMethod == "value" then
 					if sortDirectory == "ASC" then
@@ -232,7 +239,7 @@
 			
 			-- Show stuff
 			for i, item in pairs(itemsCache[groupName]) do
-				if ( item.count / stockRequired ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then
+				if ( item.count / minimumStock ) < showWhenBelow and not (hideWhenBelowPriceThreshold and item.value < priceThreshold) then
 					local btnItemLink = AceGUI:Create("ItemLinkButton");
 					btnItemLink:SetUserData("exec", function()
 						print("Win.");
@@ -244,17 +251,17 @@
 					
 					-- Current quantity
 					local lblQuantity = AceGUI:Create("Label");
-					lblQuantity:SetText(self:ColorCode(item.count, stockRequired));
+					lblQuantity:SetText(self:DisplayItemCount(item.count, minimumStock));
 					lblQuantity:SetRelativeWidth(0.099);
 					
 					iGroup:AddChild(lblQuantity);
 					
 					-- Required stock
-					local lblStockRequired = AceGUI:Create("Label");
-					lblStockRequired:SetText(stockRequired);
-					lblStockRequired:SetRelativeWidth(0.099);
+					local lblMinimumStock = AceGUI:Create("Label");
+					lblMinimumStock:SetText(minimumStock);
+					lblMinimumStock:SetRelativeWidth(0.099);
 					
-					iGroup:AddChild(lblStockRequired);
+					iGroup:AddChild(lblMinimumStock);
 					
 					-- Value
 					local lblValue = AceGUI:Create("Label");
@@ -292,16 +299,17 @@
 	for groupName, items in pairs(itemsCache) do
 		local minimumStock = addon:GetOptionByKey(groupName, "minimumStock");
 		local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
+		local groupUpdated;
 		
 		for _, item in pairs(items) do
 			if item.set then
 				item.count = addon:GetItemCount(item.id);
-				if item.set.current then
-					item.set.current:SetText(self:ColorCode(item.count, minimumStock));
+				if item.set.current and item.set.current.SetText then
+					item.set.current:SetText(self:DisplayItemCount(item.count, minimumStock));
 				end
 				
 				item.value = addon:GetAuctionValue(item.link);
-				if item.set.value then
+				if item.set.value and item.set.value.SetText then
 					item.set.value:SetText(self:DisplayMoney(item.value, priceThreshold));
 				end
 				
@@ -309,23 +317,28 @@
 				
 				i = i + 1;
 				CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1;
+				groupUpdated = true;
 				
-				mod.frame:SetStatusText(("Caching auction values and item-counts... %d% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
+				if mod.frame then
+					mod.frame:SetStatusText(("Caching auction values and item-counts... %d%% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
+				end
 				
 				if i >= CACHE_ITEMS_PER_UPDATE then
 					return;
 				end
 			end
 		end
+		
+		if groupUpdated then
+			-- Rebuild list so hidden items due to too low prices get added
+			self:Build();
+		end
 	end
 	
 	-- Reset trackers
 	CACHE_ITEMS_TOTAL = 0;
 	CACHE_ITEMS_CURRENT = 0;
 	
-	-- Rebuild list so hidden items due to too low prices get added
-	self:Build();
-	
 	-- Stop timer
 	self:CancelTimer(self.tmrUpdater, true);
 	
@@ -355,6 +368,8 @@
 		return "|cff0000ffNone up|r";
 	elseif value == -2 then
 		return "|cff0000ffNo AH mod|r";
+	elseif value == -3 then
+		return "|cffffff00Unknown|r";
 	elseif value < priceThreshold then
 		return ("|cffff0000%s|r"):format(addon:ReadableMoney(value or 0, true));
 	else
@@ -362,6 +377,14 @@
 	end
 end
 
+function mod:DisplayItemCount(value, minimumStock)
+	if value == -3 then
+		return "|cffffff00Unknown|r";
+	else
+		return self:ColorCode(value, minimumStock);
+	end
+end
+
 function mod:NumberFormat(num)
 	local formatted = string.gsub(num, "(%d)(%d%d%d)$", "%1,%2", 1);