Quantcast

In addon:TRADE_SKILL_SHOW(): Re-wrote alt-tradeskill code.

torhal [11-17-09 - 08:36]
In addon:TRADE_SKILL_SHOW(): Re-wrote alt-tradeskill code.
Re-wrote addon:SearchRecipeDB() and moved it into addon:InitializeFrame() as the local function SearchRecipes() to be set as scripts for the search button and search entry box.
Changed addon.RepFilterSwitch() to RepFilterSwitch()
Filename
ARLFrame.lua
AckisRecipeList.lua
diff --git a/ARLFrame.lua b/ARLFrame.lua
index 3e6f619..d298474 100644
--- a/ARLFrame.lua
+++ b/ARLFrame.lua
@@ -2249,7 +2249,7 @@ end

 -- Description: Rep Filtering panel switcher

-function addon.RepFilterSwitch(whichrep)
+function RepFilterSwitch(whichrep)
 	-- 1	ARL_RepOldWorldCB		Old World Rep
 	-- 2	ARL_RepBCCB				Burning Crusade
 	-- 3	ARL_RepLKCB				Wrath of the Lich King
@@ -2308,8 +2308,7 @@ function addon.RepFilterSwitch(whichrep)

 	end

-	if (ShowPanel == true) then
-
+	if ShowPanel then
 		addon.flyTexture:ClearAllPoints()
 		addon.Flyaway:SetWidth(296)
 		addon.Flyaway:SetHeight(312)
@@ -3345,6 +3344,39 @@ function addon:InitializeFrame()
 	ARL_ExpandButton:SetText(L["EXPANDALL"])
 	SetTooltipScripts(ARL_ExpandButton, L["EXPANDALL_DESC"])

+	local SearchRecipes
+	do
+		local search_params = {
+			["ItemID"]	= true,
+			["Name"]	= true,
+			["Locations"]	= true,
+			["Specialty"]	= true,
+			["Level"]	= true,
+			["Rarity"]	= true,
+		}
+		---Scans through the recipe database and toggles the flag on if the item is in the search criteria
+		function SearchRecipes(pattern)
+			if not pattern then
+				return
+			end
+			pattern = pattern:lower()
+
+			for index in pairs(recipeDB) do
+				local entry = recipeDB[index]
+				entry["Search"] = false
+
+				for field in pairs(search_params) do
+					local str = entry[field] and tostring(entry[field]):lower() or nil
+
+					if str and str:find(pattern) then
+						entry["Search"] = true
+						break
+					end
+				end
+			end
+		end
+	end	-- do
+
 	local ARL_SearchButton = GenericCreateButton("ARL_SearchButton", MainPanel,
 						     25, 74, "TOPLEFT", ARL_DD_Sort, "BOTTOMRIGHT", 1, 4, "GameFontDisableSmall",
 						     "GameFontHighlightSmall", L["Search"], "CENTER", L["SEARCH_DESC"], 1)
@@ -3357,7 +3389,7 @@ function addon:InitializeFrame()
 					   if (searchtext ~= "") then
 						   ARL_LastSearchedText = searchtext

-						   addon:SearchRecipeDB(recipeDB, searchtext)
+						   SearchRecipes(searchtext)
 						   initDisplayStrings()
 						   RecipeList_Update()

@@ -3403,7 +3435,7 @@ function addon:InitializeFrame()
 					 if (searchtext ~= "") and (searchtext ~= L["SEARCH_BOX_DESC"]) then
 						 ARL_LastSearchedText = searchtext

-						 addon:SearchRecipeDB(recipeDB, searchtext)
+						 SearchRecipes(searchtext)
 						 initDisplayStrings()
 						 RecipeList_Update()

@@ -4144,15 +4176,15 @@ function addon:InitializeFrame()

 	ARL_RepOldWorldCB = addon:CreateExpCB("ARL_RepOldWorldCB", "Glues-WoW-Logo", 1)
 	ARL_RepOldWorldCB:SetPoint("TOPLEFT", addon.Fly_Rep, "TOPLEFT", 0, -10)
-	ARL_RepOldWorldCB:SetScript("OnClick", function() addon.RepFilterSwitch(1) end)
+	ARL_RepOldWorldCB:SetScript("OnClick", function() RepFilterSwitch(1) end)

 	ARL_RepBCCB = addon:CreateExpCB("ARL_RepBCCB", "GLUES-WOW-BCLOGO", 1)
 	ARL_RepBCCB:SetPoint("TOPLEFT", addon.Fly_Rep, "TOPLEFT", 0, -60)
-	ARL_RepBCCB:SetScript("OnClick", function() addon.RepFilterSwitch(2) end)
+	ARL_RepBCCB:SetScript("OnClick", function() RepFilterSwitch(2) end)

 	ARL_RepLKCB = addon:CreateExpCB("ARL_RepLKCB", "wotlk_logo", 1)
 	ARL_RepLKCB:SetPoint("TOPLEFT", addon.Fly_Rep, "TOPLEFT", 0, -110)
-	ARL_RepLKCB:SetScript("OnClick", function() addon.RepFilterSwitch(3) end)
+	ARL_RepLKCB:SetScript("OnClick", function() RepFilterSwitch(3) end)

 	-------------------------------------------------------------------------------
 	-- Original Reputations
diff --git a/AckisRecipeList.lua b/AckisRecipeList.lua
index 365db4f..a913abc 100644
--- a/AckisRecipeList.lua
+++ b/AckisRecipeList.lua
@@ -655,29 +655,22 @@ do
 	local IsTradeSkillLinked = _G.IsTradeSkillLinked

 	function addon:TRADE_SKILL_SHOW()
-		local ownskill = IsTradeSkillLinked()
+		local is_linked = IsTradeSkillLinked()

 		-- If this is our own skill, save it, if not don't save it
-		if not ownskill then
-			-- Create an entry in the db to track alt trade skills
-			local pname = UnitName("player")
-			local prealm = GetRealmName()
+		if not is_linked then
 			local tradelink = GetTradeSkillListLink()
-			local tradename = GetTradeSkillLine()

 			if tradelink then
-				-- Actual alt information saved here. -Torhal
-				if not addon.db.global.tradeskill then
-					addon.db.global.tradeskill = {}
-				end
+				local pname = UnitName("player")
+				local prealm = GetRealmName()
+				local tradename = GetTradeSkillLine()

-				if not addon.db.global.tradeskill[prealm] then
-					addon.db.global.tradeskill[prealm] = {}
-				end
+				-- Actual alt information saved here. -Torhal
+				addon.db.global.tradeskill = addon.db.global.tradeskill or {}
+				addon.db.global.tradeskill[prealm] = addon.db.global.tradeskill[prealm] or {}
+				addon.db.global.tradeskill[prealm][pname] = addon.db.global.tradeskill[prealm][pname] or {}

-				if not addon.db.global.tradeskill[prealm][pname] then
-					addon.db.global.tradeskill[prealm][pname] = {}
-				end
 				addon.db.global.tradeskill[prealm][pname][tradename] = tradelink
 			end
 		end
@@ -1657,45 +1650,6 @@ end
 -------------------------------------------------------------------------------
 -- Searching Functions
 -------------------------------------------------------------------------------
-
----Scans through the recipe database and toggles the flag on if the item is in the search criteria
-function addon:SearchRecipeDB(RecipeDB, searchstring)
-	if not searchstring then
-		return
-	end
-	searchstring = strlower(searchstring)
-
-	for SpellID in pairs(RecipeDB) do
-		local recipe = RecipeDB[SpellID]
-
-		-- Set the search as false automatically
-		recipe["Search"] = false
-
-		-- Allow us to search by spell ID
-		if strfind(strlower(SpellID), searchstring) or
-
-			-- Allow us to search by item ID
-			(recipe["ItemID"] and strfind(strlower(recipe["ItemID"]), searchstring)) or
-
-			-- Allow us to search by name
-			(recipe["Name"] and strfind(strlower(recipe["Name"]), searchstring)) or
-
-			-- Allow us to search by locations
-			(recipe["Locations"] and strfind(recipe["Locations"], searchstring)) or
-
-			-- Allow us to search by specialty
-			(recipe["Specialty"] and strfind(recipe["Specialty"], searchstring)) or
-
-			-- Allow us to search by skill level
-			(recipe["Level"] and strfind(recipe["Level"], searchstring)) or
-
-			-- Allow us to search by Rarity
-			(recipe["Rarity"] and strfind(recipe["Rarity"], searchstring)) then
-			recipe["Search"] = true
-		end
-	end
-end
-
 ---Goes through the recipe database and resets all the search flags
 function addon:ResetSearch(RecipeDB)
 	for SpellID in pairs(RecipeDB) do