diff Core.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 db57cd9273f1
line wrap: on
line diff
--- a/Core.lua	Wed Oct 20 01:37:22 2010 +0200
+++ b/Core.lua	Thu Oct 28 19:14:30 2010 +0200
@@ -99,8 +99,89 @@
 		-- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports.
 		self.db.global.defaults.trackAtCharacters[playerName] = true;
 	end
+	
+	self:PremadeGroupsCheck();
 end
 
+function addon:PremadeGroupsCheck(updateGroupName, updateKey, accept)
+	-- Compare the current premade groups with those used, notify about changes
+	if addon.defaultGroups then
+		for key, groupInfo in pairs(addon.defaultGroups) do
+			-- Go through all default groups
+			
+			for groupName, values in pairs(addon.db.global.groups) do
+				-- Go through all groups to find those with this premade group
+				
+				if values.premadeGroups and values.premadeGroups[key] and values.premadeGroups[key] < groupInfo.version then
+					-- Outdated group
+					
+					if updateGroupName and updateKey then
+						-- This function was called after pressing yes or no in a confirm box
+						
+						if accept then
+							-- Yes was clicked
+							
+							for itemId, version in pairs(groupInfo.items) do
+								-- Go through all items in this premade group
+								
+								if version > values.premadeGroups[key] then
+									-- This item was added in a more recent version than this group: Add item
+									
+									if InGroup(itemId) then
+										print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
+									elseif AddToGroup(groupName, itemId) then
+										print(("Added %s (#%d) found in the premade group |cfffed000%s|r to the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
+									end
+								end
+							end
+							
+							-- Remember the new version
+							values.premadeGroups[key] = groupInfo.version;
+						else
+							-- No was clicked
+							
+							-- Let user know what was not added
+							for itemId, version in pairs(groupInfo.items) do
+								-- Go through all items in this premade group
+								
+								if version > values.premadeGroups[key] then
+									-- This item was added in a more recent version than this group: don't add (since we clicked no), but announce it
+									
+									print(("Skipping %s (#%d) found in the premade group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
+								end
+							end
+							
+							-- Remember the new version
+							values.premadeGroups[key] = groupInfo.version;
+						end
+					else
+						StaticPopupDialogs["InventoriumConfirmUpdatePremadeGroup"] = {
+							text = "The premade group |cfffed000%s|r used in the group |cfffed000%s|r has been changed. Do you wish to copy these changes?",
+							button1 = YES,
+							button2 = NO,
+							OnAccept = function(self)
+								addon:PremadeGroupsCheck(groupName, key, true);
+							end,
+							OnCancel = function(self, _, reason)
+								if reason == "clicked" then
+									addon:PremadeGroupsCheck(groupName, key, false);
+								end
+							end,
+							timeout = 0,
+							whileDead = 1,
+							hideOnEscape = 1,
+						};
+						StaticPopup_Show("InventoriumConfirmUpdatePremadeGroup", key, groupName);
+						
+						return;
+					end
+				end
+			end
+		end
+	end
+end
+
+
 local slashArgs = {};
 function addon:RegisterSlash(func, ...)
 	for _, arg in pairs({ ... }) do
@@ -170,9 +251,10 @@
 		    self:SetCallback("CustomOnLeave", function(this)
 		    	GameTooltip:Hide();
 		    end);
-		    self:SetCallback("CustomOnClick", function(this)
+		    self:SetCallback("CustomOnClick", function(this, ...)
+		    	-- Below is used in child widgets to prepare for onclick
 		    	if this.OnClick then
-		    		this.OnClick(this);
+		    		this.OnClick(this, ...);
 		    	end
 		    	
 		    	local func = this:GetUserData("exec");
@@ -183,7 +265,7 @@
 		    		local path = this:GetUserData("path");
 		    		local groupId = (path and path[2]) or nil;
 		    		
-		    		func(groupId, itemId);
+		    		func(groupId, itemId, ...);
 		    	end
 		    end);
 		    
@@ -420,7 +502,7 @@
 					description = {
 						order = 0,
 						type = "description",
-						name = "Change general settings unrelated to groups.",
+						name = "Here you can set general settings. The settings entered here will be used when you choose not to override the settings within an individual group.",
 					},
 					header = {
 						order = 5,
@@ -460,7 +542,7 @@
 						set = function(i, v) self.db.global.defaults.itemCountAddon = v; end,
 					},
 					craftingAddon = {
-						order = 20,
+						order = 30,
 						type = "select",
 						name = "Prefered crafting addon",
 						desc = "Select the addon you prefer data to be queued into. A random supported addon will be used if the selected addon can not be found.",
@@ -475,6 +557,21 @@
 						get = function() return self.db.global.defaults.craftingAddon; end,
 						set = function(i, v) self.db.global.defaults.craftingAddon = v; end,
 					},
+					localItemData = {
+						order = 40,
+						type = "multiselect",
+						name = "Include in local item data NYI | PH",
+						desc = "Select which data should be included in the local item data.",
+						values = {
+							["Bag"] = "Bag",
+							["Bank"] = "Bank",
+							["Auction House"] = "Auction House",
+							["Mailbox"] = "Mailbox",
+						},
+						get = function(i, v) return self.db.global.defaults.localItemData and self.db.global.defaults.localItemData[v]; end,
+						set = function(i, v, e) self.db.global.defaults.localItemData[v] = e or nil; end,
+						--dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
+					},
 				},
 			},
 			minimumStock = {
@@ -540,17 +637,7 @@
 							return temp;
 						end,
 						get = function(i, v) return self.db.global.defaults.trackAtCharacters[v]; end,
-						set = function(i, v, e)
-							self.db.global.defaults.trackAtCharacters[v] = e or nil;
-							
-							-- We MUST close this pullout or we can get errors or even game client crashes once we click another group or close the config dialog!
-							local count = AceGUI:GetNextWidgetNum("Dropdown-Pullout");
-							for i = 1, count do
-								if _G['AceGUI30Pullout' .. i] then
-									_G['AceGUI30Pullout' .. i]:Hide();
-								end
-							end
-						end,
+						set = function(i, v, e) self.db.global.defaults.trackAtCharacters[v] = e or nil; end,
 						--dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
 					},
 				},
@@ -630,6 +717,14 @@
 						get = function() return self.db.global.defaults.summaryHidePriceThreshold; end,
 						set = function(i, v) self.db.global.defaults.summaryHidePriceThreshold = v; end,
 					},
+					alwaysGetAuctionValue = {
+						order = 60,
+						type = "toggle",
+						name = "Always show auction value",
+						desc = "Always cache and show the auction value of items, even if the price threshold is set to 0.",
+						get = function() return self.db.global.defaults.alwaysGetAuctionValue; end,
+						set = function(i, v) self.db.global.defaults.alwaysGetAuctionValue = v; end,
+					},
 				},
 			},
 			colorCodes = {
@@ -709,12 +804,20 @@
 	local groupName = groupIdToName[info[2]];
 	local optionName = info[#info];
 	
-	-- No need to store a setting if it's disabled (false)
-	if not value and info.arg and not info.arg:find("override") then
-		value = nil;
-		
-		-- If this is an override toggler then also set the related field to nil
-		addon.db.global.groups[groupName][info.arg] = nil;
+	-- Special treatment for override toggle boxes
+	if not info.arg:find("override") then
+		if not value and info.arg then
+			-- If this override was disabled and a saved variable name was provided, set it to nil rather than false
+			
+			value = nil;
+			
+			-- If this is an override toggler then also set the related field to nil
+			addon.db.global.groups[groupName][info.arg] = nil;
+		elseif value and info.arg then
+			-- If this override is now enabled, we need to copy the default into this field (unless it is not nil (which is supposed to be impossible), in which case we'll use the already selected value)
+			
+			addon.db.global.groups[groupName][info.arg] = addon:GetOptionByKey(groupName, info.arg);
+		end
 	end
 	
 	if multiSelectEnabled ~= nil then
@@ -730,10 +833,10 @@
 end
 
 function addon:GetOptionByKey(groupName, optionName, noDefault)
-	if addon.db.global.groups[groupName][optionName] ~= nil then
-		return addon.db.global.groups[groupName][optionName];
-	elseif addon.db.global.defaults[optionName] and not noDefault then
-		return addon.db.global.defaults[optionName];
+	if groupName and self.db.global.groups[groupName] and self.db.global.groups[groupName][optionName] ~= nil then
+		return self.db.global.groups[groupName][optionName];
+	elseif self.db.global.defaults[optionName] and not noDefault then
+		return self.db.global.defaults[optionName];
 	else
 		return nil;
 	end
@@ -978,9 +1081,96 @@
 		general = {
 			order = 10,
 			type = "group",
-			name = "Stock settings",
-			desc = "Change the stock settings for just this group.",
+			name = "General",
+			desc = "Change the general settings for just this group.",
 			args = {
+				general = {
+					order = 0,
+					type = "group",
+					inline = true,
+					name = "General",
+					set = SetOption,
+					get = GetOption,
+					disabled = GetDisabled,
+					args = {
+						description = {
+							order = 0,
+							type = "description",
+							name = "Here you can set general settings for the currently selected group. If you do not wish to override a setting, the default setting specified in the general group will be used.",
+						},
+						header = {
+							order = 5,
+							type = "header",
+							name = "",
+						},
+						overrideAuctionPricingAddon = {
+							order = 9,
+							type = "toggle",
+							name = "Override pricing addon",
+							desc = "Allows you to override the pricing addon setting for this group.",
+							arg = "auctionPricingAddon",
+						},
+						auctionPricingAddon = {
+							order = 10,
+							type = "select",
+							name = "Prefered pricing addon",
+							desc = "Select the addon you prefer data for this group to be retrieved from. A random supported addon will be used if the selected addon can not be found.",
+							values = function()
+								local temp = {};
+								for name, value in pairs(addon.supportedAddons.auctionPricing) do
+									temp[name] = name;
+								end
+								
+								return temp;
+							end,
+							arg = "overrideAuctionPricingAddon",
+						},
+						overrideItemCountAddon = {
+							order = 19,
+							type = "toggle",
+							name = "Override item count addon",
+							desc = "Allows you to override the item count addon setting for this group.",
+							arg = "itemCountAddon",
+						},
+						itemCountAddon = {
+							order = 20,
+							type = "select",
+							name = "Prefered item count addon",
+							desc = "Select the addon you prefer data for this group to be retrieved from. A random supported addon will be used if the selected addon can not be found.",
+							values = function()
+								local temp = {};
+								for name, value in pairs(addon.supportedAddons.itemCount) do
+									temp[name] = name;
+								end
+								
+								return temp;
+							end,
+							arg = "overrideItemCountAddon",
+						},
+						overrideCraftingAddon = {
+							order = 29,
+							type = "toggle",
+							name = "Override crafting addon",
+							desc = "Allows you to override the crafting addon setting for this group.",
+							arg = "craftingAddon",
+						},
+						craftingAddon = {
+							order = 30,
+							type = "select",
+							name = "Prefered crafting addon",
+							desc = "Select the addon you prefer data from this group to be queued into. A random supported addon will be used if the selected addon can not be found.",
+							values = function()
+								local temp = {};
+								for name, value in pairs(addon.supportedAddons.crafting) do
+									temp[name] = name;
+								end
+								
+								return temp;
+							end,
+							arg = "overrideCraftingAddon",
+						},
+					},
+				},
 				minimumStock = {
 					order = 10,
 					type = "group",
@@ -1069,14 +1259,6 @@
 									temp[charName] = charName;
 								end
 								
-								-- We MUST close this pullout or we can get errors or even game client crashes once we click another group or close the config dialog!
-								local count = AceGUI:GetNextWidgetNum("Dropdown-Pullout");
-								for i = 1, count do
-									if _G['AceGUI30Pullout' .. i] then
-										_G['AceGUI30Pullout' .. i]:Hide();
-									end
-								end
-								
 								return temp;
 							end,
 							get = GetMultiOption,
@@ -1196,6 +1378,20 @@
 							desc = "Hide items from the summary when their value is below the set price threshold.",
 							arg = "overrideSummaryHidePriceThreshold",
 						},
+						overrideAlwaysGetAuctionValue = {
+							order = 59,
+							type = "toggle",
+							name = "Override auction value showing",
+							desc = "Allows you to override if the auction value of items in this group should be cached and displayed even when the price threshold is set to 0.",
+							arg = "alwaysGetAuctionValue",
+						},
+						alwaysGetAuctionValue = {
+							order = 60,
+							type = "toggle",
+							name = "Always show auction value",
+							desc = "Always cache and show the auction value of items in this group, even if the price threshold is set to 0.",
+							arg = "overrideAlwaysGetAuctionValue",
+						},
 					},
 				},
 			},
@@ -1203,8 +1399,8 @@
 		group = {
 			order = 20,
 			type = "group",
-			name = "Group Management",
-			desc = "Rename, delete or export this group.",
+			name = "Management",
+			desc = "Rename, delete, duplicate or export this group.",
 			args = {
 				actions = {
 					order = 10,
@@ -1307,6 +1503,7 @@
 			order = 30,
 			type = "group",
 			name = "Add items",
+			desc = "Add new items to this group.",
 			args = {
 				singleAdd = {
 					order = 10,
@@ -1505,6 +1702,7 @@
 			order = 40,
 			type = "group",
 			name = "Current items",
+			desc = "View, export or remove items from this group.",
 			args = {
 				help = {
 					order = 10,
@@ -1549,7 +1747,7 @@
 							order = 30,
 							type = "select",
 							name = "Imported premade groups",
-							desc = "This is a list of all premade groups that were imported into this group. You will be notified when any of these premade groups have changed and you will be able to import these changes.\n\nSelect a group to remove it from this list and prevent notifications about changes made to this group. This will require you to manually update this when new items are added to the game.",
+							desc = "This is a list of all premade groups that were imported into this group. You will be notified when any of these premade groups have changed and you will be able to import these changes.\n\nSelect a group to stop reminding you of changes to the premade group (the item list will be unaffected). Doing so will require you to manually update this when new items are added to the game.",
 							values = function(info)
 						    	local groupName = groupIdToName[info[2]];
 						    	
@@ -1702,7 +1900,7 @@
 										end
 									end
 									
-									-- Ensure this data isn't received (this would be buggy as exports from other accounts won't know what to do with this)
+									-- Ensure this data isn't received (this would be silly/buggy as exports from other accounts - with different characters - won't know what to do with this)
 									temp.trackAtCharacters = nil;
 									temp.overrideTrackAtCharacters = nil;
 									
@@ -1732,7 +1930,7 @@
 	
 	for name, values in pairs(self.db.global.groups) do
 		if not groupIdToName[name] then
-			options.args.groups.args[tostring(count)] = CopyTable(defaultGroup);
+			options.args.groups.args[tostring(count)] = defaultGroup;
 			
 			groupIdToName[tostring(count)] = name;
 			groupIdToName[name] = true;
@@ -1746,15 +1944,17 @@
 
 -- General functions used addon-wide
 
-function addon:GetItemCount(itemId)
+function addon:GetItemCount(itemId, group)
 	itemId = tonumber(itemId);
 	
 	if not itemId then return; end
 	
-	if self.supportedAddons.itemCount[self.db.global.defaults.itemCountAddon] then
+	local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
+	
+	if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then
 		-- Try to use the default item count addon
 		
-		return self.supportedAddons.itemCount[self.db.global.defaults.itemCountAddon].GetTotalCount(itemId);
+		return self.supportedAddons.itemCount[selectedExternalAddon].GetTotalCount(itemId);
 	else
 		-- Default not available, get the first one then
 		
@@ -1768,13 +1968,15 @@
 	return -1;
 end
 
-function addon:GetAuctionValue(itemLink)
-	if not itemLink then return; end
+function addon:GetAuctionValue(itemLink, group)
+	if not itemLink then return -5; end
 	
-	if self.supportedAddons.auctionPricing[self.db.global.defaults.auctionPricingAddon] then
+	local selectedExternalAddon = self:GetOptionByKey(group, "auctionPricingAddon");
+	
+	if self.supportedAddons.auctionPricing[selectedExternalAddon] and self.supportedAddons.auctionPricing[selectedExternalAddon].IsEnabled() then
 		-- Try to use the default auction pricing addon
 		
-		return self.supportedAddons.auctionPricing[self.db.global.defaults.auctionPricingAddon].GetValue(itemLink);
+		return self.supportedAddons.auctionPricing[selectedExternalAddon].GetValue(itemLink);
 	else
 		-- Default not available, get the first one then