diff Core.lua @ 13:5006cb0e97c6

Removed sound media registrations since we don?t use them. Added an option to include tadeskill items above a certain item level threshold in the add items config tab. Renamed the variable for toggling hiding from summary when below price threshold-option. You will have to re-set it. Summary size and processing speed will now be remembered. Processing speed slider can now go up to 500% (up from 100%). Silver will be hidden from money when it includes more than 10 gold (down from 100g) and copper will be hidden if it includes more than 1 gold (down from 10g). Auction addons, crafting addons and itemcount addons can now register themselves through a few global functions. The most used addons have been included in the addon folder. You can now select the prefered default pricing, item count and crafting addons. Temporarily removed the ?dialogControl = ?DropDown?? from the track at select boxes. This functionality is broken within the Ace3 library and until it is fixed I wish to keep these options somewhat functional. The item list will now be truncated before rebuilding. Previously items disappearing from your inventory would still appear in this list. Mass add is now functional. All buttons and sliders that were meant to receive a tooltip (including the sort-headers), now have one. Added spacers between all buttons and sliders of the summary window. Added a ?queue all? button to the summary window. This button is not yet functional. If the value of an item is not retrieved from the auction prices database, it will appear as a dash (-) rather than ?0c?. If no item count is enabled, item counts will appear as ?Unknown? instead of breaking (or defaulting to 0).
author Zerotorescue
date Mon, 18 Oct 2010 15:26:42 +0200
parents 10a2244f7ff0
children 8f5c02113c5c
line wrap: on
line diff
--- a/Core.lua	Sat Oct 16 20:58:39 2010 +0200
+++ b/Core.lua	Mon Oct 18 15:26:42 2010 +0200
@@ -3,26 +3,16 @@
 
 local AceGUI = LibStub("AceGUI-3.0");
 
-local Media = LibStub("LibSharedMedia-3.0");
-Media:Register("sound", "Cartoon FX", [[Sound\Doodad\Goblin_Lottery_Open03.wav]]);
-Media:Register("sound", "Cheer", [[Sound\Event Sounds\OgreEventCheerUnique.wav]]);
-Media:Register("sound", "Explosion", [[Sound\Doodad\Hellfire_Raid_FX_Explosion05.wav]]);
-Media:Register("sound", "Fel Nova", [[Sound\Spells\SeepingGaseous_Fel_Nova.wav]]);
-Media:Register("sound", "Fel Portal", [[Sound\Spells\Sunwell_Fel_PortalStand.wav]]);
-Media:Register("sound", "Magic Click", [[Sound\interface\MagicClick.wav]]);
-Media:Register("sound", "Rubber Ducky", [[Sound\Doodad\Goblin_Lottery_Open01.wav]]);
-Media:Register("sound", "Shing!", [[Sound\Doodad\PortcullisActive_Closed.wav]]);
-Media:Register("sound", "Simon Chime", [[Sound\Doodad\SimonGame_LargeBlueTree.wav]]);
-Media:Register("sound", "Simon Error", [[Sound\Spells\SimonGame_Visual_BadPress.wav]]);
-Media:Register("sound", "Simon Start", [[Sound\Spells\SimonGame_Visual_GameStart.wav]]);
-Media:Register("sound", "War Drums", [[Sound\Event Sounds\Event_wardrum_ogre.wav]]);
-Media:Register("sound", "Wham!", [[Sound\Doodad\PVP_Lordaeron_Door_Open.wav]]);
-Media:Register("sound", "Whisper Ping", [[Sound\interface\iTellMessage.wav]]);
-Media:Register("sound", "You Will Die!", [[Sound\Creature\CThun\CThunYouWillDIe.wav]]);
-
 local AceConfigDialog, AceConfigRegistry, AceSerializer;
 local groupIdToName = {};
 local options = {};
+local includeTradeSkillItems = 500;
+
+--  All modules must be able to retrieve our supported addons database, thus keep it public
+addon.supportedAddons = {};
+addon.supportedAddons.auctionPricing = {};
+addon.supportedAddons.itemCount = {};
+addon.supportedAddons.crafting = {};
 
 function addon:OnInitialize()
 	self:Debug("OnInitialize");
@@ -33,6 +23,9 @@
 		global = {
 			groups = {},
 			defaults = {
+				auctionPricingAddon = "Auctioneer",
+				itemCountAddon = "Altoholic",
+				craftingAddon = "AdvancedTradeSkillWindow",
 				minimumStock = 60,
 				alertBelowMinimum = true,
 				summaryThresholdShow = 10,
@@ -40,8 +33,13 @@
 				minCraftingQueue = 0.05,
 				bonusQueue = 0.1,
 				priceThreshold = 0,
-				hideFromSummaryWhenBelowPriceThreshold = false,
+				summaryHidePriceThreshold = false,
 				trackAtCharacters = {},
+				summary = {
+					speed = 5,
+					width = 650,
+					height = 600,
+				},
 				colors = {
 					red = 0;
 					orange = 0.3;
@@ -361,13 +359,13 @@
 		text = goldText:format(text, gold);
 	end
 	
-	if not clean or (not gold or gold < 100) then
+	if not clean or (not gold or gold < 10) then
 		local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
 		if silver > 0 then
 			text = silverText:format(text, silver);
 		end
 		
-		if not clean or (not gold or gold < 10) then
+		if not clean or (not gold or gold < 1) then
 			local copper = floor( copper % COPPER_PER_SILVER );
 			if copper > 0 or text == "" then
 				text = copperText:format(text, copper);
@@ -428,28 +426,53 @@
 						type = "header",
 						name = "",
 					},
-					auctionAddon = {
+					auctionPricingAddon = {
 						order = 10,
 						type = "select",
 						name = "Prefered pricing addon",
-						values = {
-							Auctioneer = "Auctioneer",
-							Auctionator = "Auctionator",
-						},
-						get = function() end,
-						set = function(i, v) end,
+						desc = "Select the addon you prefer data 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(self.supportedAddons.auctionPricing) do
+								temp[name] = name;
+							end
+							
+							return temp;
+						end,
+						get = function() return self.db.global.defaults.auctionPricingAddon; end,
+						set = function(i, v) self.db.global.defaults.auctionPricingAddon = v; end,
 					},
 					itemCountAddon = {
 						order = 20,
 						type = "select",
 						name = "Prefered item count addon",
-						values = {
-							Altoholic = "Altoholic",
-							DataStore = "DataStore",
-							ItemCount = "ItemCount",
-						},
-						get = function() end,
-						set = function(i, v) end,
+						desc = "Select the addon you prefer data 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(self.supportedAddons.itemCount) do
+								temp[name] = name;
+							end
+							
+							return temp;
+						end,
+						get = function() return self.db.global.defaults.itemCountAddon; end,
+						set = function(i, v) self.db.global.defaults.itemCountAddon = v; end,
+					},
+					craftingAddon = {
+						order = 20,
+						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.",
+						values = function()
+							local temp = {};
+							for name, value in pairs(self.supportedAddons.crafting) do
+								temp[name] = name;
+							end
+							
+							return temp;
+						end,
+						get = function() return self.db.global.defaults.craftingAddon; end,
+						set = function(i, v) self.db.global.defaults.craftingAddon = v; end,
 					},
 				},
 			},
@@ -527,8 +550,7 @@
 								end
 							end
 						end,
-						confirm = true,
-						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.
+						--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.
 					},
 				},
 			},
@@ -599,13 +621,13 @@
 						get = function() return self:ReadableMoney(self.db.global.defaults.priceThreshold); end,
 						set = function(i, v) self.db.global.defaults.priceThreshold = self:ReadableMoneyToCopper(v); end,
 					},
-					hideFromSummaryWhenBelowPriceThreshold = { -- I wish this var could be a little bit shorter...
+					summaryHidePriceThreshold = {
 						order = 50,
 						type = "toggle",
 						name = "Hide when below threshold",
 						desc = "Hide items from the summary when their value is below the set price threshold.",
-						get = function() return self.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold; end,
-						set = function(i, v) self.db.global.defaults.hideFromSummaryWhenBelowPriceThreshold = v; end,
+						get = function() return self.db.global.defaults.summaryHidePriceThreshold; end,
+						set = function(i, v) self.db.global.defaults.summaryHidePriceThreshold = v; end,
 					},
 				},
 			},
@@ -859,6 +881,9 @@
 	
 	local ref = options.args.groups.args[info[2]].args.add.args.list.args;
 	
+	-- Remaking the list, so out with the old, in with the new
+	table.wipe(ref);
+	
 	-- Parse bags and show these
 	for bagID = 4, 0, -1 do
 		for slot = 1, GetContainerNumSlots(bagID) do
@@ -875,6 +900,38 @@
 			end
 		end
 	end
+	
+	if includeTradeSkillItems ~= 500 then
+		-- Include tradeskill items
+		
+		-- Go through all trade skills for the profession
+		for i = 1, GetNumTradeSkills() do
+			-- Try to retrieve the itemlink, this will be nil if current item is a group instead
+			local itemLink = GetTradeSkillItemLink(i);
+			
+			if itemLink then
+				local itemId = addon:GetItemId(itemLink);
+				if not itemId then
+					-- If this isn't an item, it can only be an enchant instead
+					itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
+					
+					itemId = scrollIds[itemId]; -- change enchantIds into scrollIds
+				end
+				
+				local itemLevel = select(4, GetItemInfo(itemId)) or 0;
+				
+				if includeTradeSkillItems == 0 or itemLevel >= includeTradeSkillItems then
+					if not items[itemId] then
+						-- If this item isn't used in any group yet
+						ref[itemId] = tblAddItemTemplate;
+					else
+						-- It's already used in a group, don't show it
+						ref[itemId] = nil;
+					end
+				end
+			end
+		end
+	end
 end
 
 local function UpdateRemoveItemList(info)
@@ -898,7 +955,7 @@
 end
 
 function addon:GetItemId(itemLink)
-	itemLink = itemLink and select(3, string.find(itemLink, "|Hitem:([-0-9]+):")); -- if itemLink is nil, it won't execute the second part
+	itemLink = itemLink and itemLink:match("|Hitem:([-0-9]+):"); -- if itemLink is nil, it won't execute the second part
 	itemLink = itemLink and tonumber(itemLink);
 	
 	return itemLink;
@@ -1018,8 +1075,7 @@
 								return temp;
 							end,
 							get = GetMultiOption,
-							confirm = true,
-							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.
+							--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.
 							arg = "overrideTrackAtCharacters",
 						},
 					},
@@ -1121,19 +1177,19 @@
 							set = function(i, v) SetOption(i, addon:ReadableMoneyToCopper(v)); end,
 							arg = "overridePriceThreshold",
 						},
-						overrideHideFromSummaryWhenBelowPriceThreshold = {
+						overrideSummaryHidePriceThreshold = {
 							order = 49,
 							type = "toggle",
 							name = "Override summary showing",
 							desc = "Allows you to override if items in this group should be hidden from the summary while their value is below the price threshold.",
-							arg = "hideFromSummaryWhenBelowPriceThreshold",
+							arg = "summaryHidePriceThreshold",
 						},
-						hideFromSummaryWhenBelowPriceThreshold = { -- I wish this var could be a little bit shorter...
+						summaryHidePriceThreshold = {
 							order = 50,
 							type = "toggle",
 							name = "Hide when below threshold",
 							desc = "Hide items from the summary when their value is below the set price threshold.",
-							arg = "overrideHideFromSummaryWhenBelowPriceThreshold",
+							arg = "overrideSummaryHidePriceThreshold",
 						},
 					},
 				},
@@ -1334,9 +1390,60 @@
 							type = "input",
 							name = "Add all items matching...",
 							desc = "Add every item in your inventory matching the name entered in this field. If you enter \"Glyph\" as a filter, any items in your inventory containing this in their name will be added to this group.",
-							--set = massAddItems,
+							set = function(info, value)
+								if not value then return; end
+								
+								value = value:lower();
+								
+								local ref = options.args.groups.args[info[2]].args.add.args.list.args;
+								
+								for itemId, test in pairs(ref) do
+									if test then
+										local itemName = GetItemInfo(itemId);
+										
+										if itemName:lower():find(value) then
+									    	local groupName = groupIdToName[info[2]];
+									    	
+									    	if not AddToGroup(groupName, itemId) then
+									    		print("|cffff0000Couldn't add the item with itemId (" .. itemId .. ") because it is already in a group.|r");
+									    	end
+										end
+									end
+								end
+							end,
 							get = false,
 						},
+						minItemLevel = {
+							order = 40,
+							type = "select",
+							values = function()
+								local temp = {};
+								
+								temp[0] = "Include everything";
+								
+								local itemLevelTemplate = "Itemlevel >= %d";
+								
+								for i = 1, 49 do
+									temp[( i * 10 )] = itemLevelTemplate:format(( i * 10 ));
+								end
+								
+								temp[500] = "Include nothing";
+								
+								return temp;
+							end,
+							name = "Include tradeskill items",
+							desc = "Include all items above this item level from the currently opened tradeskill window in the below item list.\n\nSetting this very low this might considerably slow down this config window.\n\nSet to 500 to disable showing of items completely.",
+							set = function(i, v) includeTradeSkillItems = v; end,
+							get = function() return includeTradeSkillItems; end,
+							disabled = function()
+								if GetTradeSkillLine() == "UNKNOWN" then
+									includeTradeSkillItems = 500;
+									return true; -- disabled
+								else
+									return false;
+								end
+							end,
+						},
 					},
 				},
 				list = {
@@ -1533,34 +1640,47 @@
 	end
 end
 
+
+
+-- General functions used addon-wide
+
 function addon:GetItemCount(itemId)
-	return Altoholic:GetItemCount(itemId);
+	itemId = tonumber(itemId);
+	
+	if not itemId then return; end
+	
+	if self.supportedAddons.itemCount[self.db.global.defaults.itemCountAddon] then
+		-- Try to use the default item count addon
+		
+		return self.supportedAddons.itemCount[self.db.global.defaults.itemCountAddon].GetCount(itemId);
+	else
+		-- Default not available, get the first one then
+		
+		for name, value in pairs(self.supportedAddons.itemCount) do
+			if value.IsEnabled() then
+				return value.GetCount(itemId);
+			end
+		end
+	end
+	
+	return -1;
 end
 
-function addon:GetAuctionValue(link)
-	if GetAuctionBuyout then
-		-- Auctionator support
+function addon:GetAuctionValue(itemLink)
+	if not itemLink then return; end
+	
+	if self.supportedAddons.auctionPricing[self.db.global.defaults.auctionPricingAddon] then
+		-- Try to use the default auction pricing addon
 		
-		local lowBuy = GetAuctionBuyout(link);
+		return self.supportedAddons.auctionPricing[self.db.global.defaults.auctionPricingAddon].GetValue(itemLink);
+	else
+		-- Default not available, get the first one then
 		
-		if lowBuy == nil then
-			-- No auctions up at this time
-			return -1;
+		for name, value in pairs(self.supportedAddons.auctionPricing) do
+			if value.IsEnabled() then
+				return value.GetValue(itemLink);
+			end
 		end
-		
-		return lowBuy;
-	elseif AucAdvanced ~= nil and AucAdvanced.Modules.Util.SimpleAuction ~= nil and AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems ~= nil then
-		-- Auctioneer support
-		
-		local imgSeen, _, _, _, _, lowBuy, _, _ = AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(link);
-		--local imgseen, image, matchBid, matchBuy, lowBid, lowBuy, aveBuy, aSeen 
-		
-		if imgSeen <= 0 then
-			-- No auctions up at this time
-			return -1;
-		end
-	
-		return lowBuy;
 	end
 	
 	return -2;
@@ -1568,6 +1688,32 @@
 
 
 
+-- Public
+
+function IMRegisterPricingAddon(name, get, enabled)
+	addon.supportedAddons.auctionPricing[name] = {
+		GetValue = get,
+		IsEnabled = enabled,
+	};
+end
+
+function IMRegisterItemCountAddon(name, get, enabled)
+	addon.supportedAddons.itemCount[name] = {
+		GetCount = get,
+		IsEnabled = enabled,
+	};
+end
+
+function IMRegisterCraftingAddon(name, queue, enabled)
+	addon.supportedAddons.crafting[name] = {
+		Queue = queue,
+		IsEnabled = enabled,
+	};
+end
+
+
+
+-- Debug
 
 function addon:Debug(t)
 	if not self.debugChannel and self.debugChannel ~= false then