diff Summary.lua @ 50:9607b3251655

Added OnSelect event support to both item count as crafting addons. Added basic local item count data support. Fixed "Show in summary when below" option to allow a value of up to 10.000%. Summary should now respect virtual groups.
author Zerotorescue
date Sat, 18 Dec 2010 00:22:06 +0100
parents 58fb38f0b447
children 06fee4208bf2
line wrap: on
line diff
--- a/Summary.lua	Fri Dec 17 00:51:00 2010 +0100
+++ b/Summary.lua	Sat Dec 18 00:22:06 2010 +0100
@@ -268,18 +268,19 @@
 	for groupName, values in pairsByKeys(addon.db.global.groups, function(a, b) return a:lower() < b:lower(); end) do
 		local groupStartTime, groupTimes = GetTime(), {};
 		
-		local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
+		local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
+		
 		
 		-- 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 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.summaryHidePriceThreshold or (values.summaryHidePriceThreshold == nil and addon.db.global.defaults.summaryHidePriceThreshold));
-			local alwaysGetAuctionValue = (values.alwaysGetAuctionValue or (values.alwaysGetAuctionValue == nil and addon.db.global.defaults.alwaysGetAuctionValue));
+			local minimumStock = addon:GetOptionByKey(groupName, "minimumStock");
+			local showWhenBelow = addon:GetOptionByKey(groupName, "summaryThresholdShow");
+			local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
+			local hideWhenBelowPriceThreshold = addon:GetOptionByKey(groupName, "summaryHidePriceThreshold");
+			local alwaysGetAuctionValue = addon:GetOptionByKey(groupName, "alwaysGetAuctionValue");
 			
 			-- Make group container
 			local iGroup = AceGUI:Create("InlineGroupWithButton");
@@ -304,7 +305,7 @@
 			local lblItem = AceGUI:Create("InteractiveLabel");
 			lblItem:SetText("|cfffed000Item|r");
 			lblItem:SetFontObject(GameFontHighlight);
-			lblItem:SetRelativeWidth(.7);
+			lblItem:SetRelativeWidth(.6);
 			lblItem:SetCallback("OnClick", function() ReSort("item"); end);
 			lblItem:SetCallback("OnEnter", ShowTooltip);
 			lblItem:SetCallback("OnLeave", HideTooltip);
@@ -313,6 +314,19 @@
 			
 			iGroup:AddChild(lblItem);
 			
+			-- Local quantity
+			local lblLocal = AceGUI:Create("InteractiveLabel");
+			lblLocal:SetText("|cfffed000Loc.|r");
+			lblLocal:SetFontObject(GameFontHighlight);
+			lblLocal:SetRelativeWidth(.099);
+			lblLocal:SetCallback("OnClick", function() ReSort("local"); end);
+			lblLocal:SetCallback("OnEnter", ShowTooltip);
+			lblLocal:SetCallback("OnLeave", HideTooltip);
+			lblLocal.frame.tooltipTitle = "Local stock";
+			lblLocal.frame.tooltip = "Sort on the amount of items currently in local stock.";
+			
+			iGroup:AddChild(lblLocal);
+			
 			-- Current quantity
 			local lblQuantity = AceGUI:Create("InteractiveLabel");
 			lblQuantity:SetText("|cfffed000Cur.|r");
@@ -326,19 +340,6 @@
 			
 			iGroup:AddChild(lblQuantity);
 			
-			-- Local quantity
-			--[[local lblLocal = AceGUI:Create("InteractiveLabel");
-			lblLocal:SetText("|cfffed000Loc.|r");
-			lblLocal:SetFontObject(GameFontHighlight);
-			lblLocal:SetRelativeWidth(.099);
-			lblLocal:SetCallback("OnClick", function() ReSort("current"); end);
-			lblLocal:SetCallback("OnEnter", ShowTooltip);
-			lblLocal:SetCallback("OnLeave", HideTooltip);
-			lblLocal.frame.tooltipTitle = "Local stock";
-			lblLocal.frame.tooltip = "Sort on the amount of items currently in local stock.";
-			
-			iGroup:AddChild(lblLocal);]]
-			
 			-- Required stock
 			local lblMinimumStock = AceGUI:Create("InteractiveLabel");
 			lblMinimumStock:SetText("|cfffed000Min.|r");
@@ -381,7 +382,7 @@
 						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, groupName),
-						--localCount = -3,
+						localCount = -3,
 						set = {},
 					});
 					CACHE_ITEMS_TOTAL = CACHE_ITEMS_TOTAL + 1;
@@ -414,6 +415,12 @@
 					else
 						return a.count > b.count;
 					end
+				elseif sortMethod == "local" then
+					if sortDirectory == "ASC" then
+						return a.localCount < b.localCount;
+					else
+						return a.localCount > b.localCount;
+					end
 				elseif sortMethod == "percentage" then
 					if sortDirectory == "ASC" then
 						return ( a.count / minimumStock ) < ( b.count / minimumStock );
@@ -438,8 +445,9 @@
 			for i, item in pairs(itemsCache[groupName]) do
 				-- Go through all items for this group
 				
-				if ( item.count / minimumStock ) < showWhenBelow and (not hideWhenBelowPriceThreshold or priceThreshold == 0 or item.value < 0 or item.value >= priceThreshold) then
+				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
 																-- 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
+																
 					local btnItemLink = AceGUI:Create("ItemLinkButton");
 					btnItemLink:SetUserData("exec", function(_, itemId, _, buttonName)
 						local itemName, itemLink = GetItemInfo(itemId);
@@ -456,11 +464,18 @@
 							QueryAuctionItems(itemName, nil, nil, 0, 0, 0, 0, 0, 0);
 						end
 					end);
-					btnItemLink:SetRelativeWidth(.7);
+					btnItemLink:SetRelativeWidth(.6);
 					btnItemLink:SetItemId(item.id);
 					
 					iGroup:AddChild(btnItemLink);
 					
+					-- Local quantity
+					local lblLocal = AceGUI:Create("Label");
+					lblLocal:SetText(self:DisplayItemCount(item.localCount, minimumStock));
+					lblLocal:SetRelativeWidth(.099);
+					
+					iGroup:AddChild(lblLocal);
+					
 					-- Current quantity
 					local lblQuantity = AceGUI:Create("Label");
 					lblQuantity:SetText(self:DisplayItemCount(item.count, minimumStock));
@@ -468,13 +483,6 @@
 					
 					iGroup:AddChild(lblQuantity);
 					
-					-- Local quantity
-					--[[local lblLocal = AceGUI:Create("Label");
-					lblLocal:SetText(self:DisplayItemCount(item.count, minimumStock));
-					lblLocal:SetRelativeWidth(.099);
-					
-					iGroup:AddChild(lblLocal);]]
-					
 					-- Required stock
 					local lblMinimumStock = AceGUI:Create("Label");
 					lblMinimumStock:SetText(minimumStock);
@@ -498,9 +506,12 @@
 						if item.count == -3 then
 							item.set.current = lblQuantity;
 						end
+						if item.localCount == -3 then
+							item.set.localCount = lblLocal;
+						end
 						
 						-- Don't queue if we already know everything we want to know
-						if item.value ~= -3 and item.count ~= -3 then
+						if item.value ~= -3 and item.count ~= -3 and item.localCount ~= -3 then
 							item.set = nil;
 						end
 					end
@@ -549,6 +560,14 @@
 					end
 				end
 				
+				if item.localCount == -3 then
+					-- Only if item count was queued, update it
+					item.localCount = addon:GetItemCount(item.id, groupName);
+					if item.set.localCount and item.set.localCount.SetText then
+						item.set.localCount:SetText(self:DisplayItemCount(item.localCount, minimumStock));
+					end
+				end
+				
 				if item.value == -3 then
 					-- Only if item value was queued, update it