Quantcast

Finishing touches on Professions Window added new Recipes Window

Xruptor [08-27-16 - 03:25]
Finishing touches on Professions Window added new Recipes Window
-Finished up the Professions Window.  You can now left click on a Profession to view all the recipes in the new Recipes Window.
-Slight formatting change to how Professions and Currency were stored. I prefer tables with keys rather then constantly splitting up strings honestly.
Filename
BagSync.lua
BagSync.toc
locale/enUS.lua
modules/blacklist.lua
modules/professions.lua
modules/profiles.lua
modules/recipes.lua
modules/search.lua
diff --git a/BagSync.lua b/BagSync.lua
index 2a345bc..51dc7c4 100644
--- a/BagSync.lua
+++ b/BagSync.lua
@@ -770,7 +770,10 @@ function BSYC:ScanCurrency()
 			end
 			if (not isHeader) then
 				self.db.currency[self.currentRealm][self.currentPlayer] = self.db.currency[self.currentRealm][self.currentPlayer] or {}
-				self.db.currency[self.currentRealm][self.currentPlayer][name] = format("%s,%s,%s", count, lastHeader, icon)
+				self.db.currency[self.currentRealm][self.currentPlayer][name] = {}
+				self.db.currency[self.currentRealm][self.currentPlayer][name].count = count
+				self.db.currency[self.currentRealm][self.currentPlayer][name].header = lastHeader
+				self.db.currency[self.currentRealm][self.currentPlayer][name].icon = icon
 			end
 		end
 	end
@@ -1533,18 +1536,9 @@ end
 function BSYC:doRegularTradeSkill(numIndex, dbPlayer, dbIdx)
 	local name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine, skillModifier = GetProfessionInfo(numIndex)
 	if name and skillLevel then
-		--don't overwrite recipe list
-		if dbPlayer[dbIdx] then
-			local name, level, list = strsplit(",", dbPlayer[dbIdx])
-			if list then
-				--only record list again if we even have a list to work with
-				dbPlayer[dbIdx] = format("%s,%s,%s", name, skillLevel, list)
-			else
-				dbPlayer[dbIdx] = format("%s,%s", name, skillLevel)
-			end
-		else
-			dbPlayer[dbIdx] = format("%s,%s", name, skillLevel)
-		end
+		dbPlayer[dbIdx] = dbPlayer[dbIdx] or {}
+		dbPlayer[dbIdx].name = name
+		dbPlayer[dbIdx].level = skillLevel
 	end
 end

@@ -1665,7 +1659,8 @@ function BSYC:TRADE_SKILL_LIST_UPDATE()
 		--only record if we have something to work with
 		if name and skillLevel and string.len(recipeString) > 0 then
 			recipeString = strsub(recipeString, string.len("|") + 1) --remove the delimiter in front of recipeID list
-			dbPlayer[getIndex] = format("%s,%s,%s", name, skillLevel, recipeString)
+			dbPlayer[getIndex] = dbPlayer[getIndex] or {}
+			dbPlayer[getIndex].recipes = recipeString
 		end

 	end
diff --git a/BagSync.toc b/BagSync.toc
index 72da643..3183eff 100644
--- a/BagSync.toc
+++ b/BagSync.toc
@@ -36,6 +36,7 @@ modules\minimap.lua
 modules\search.lua
 modules\currency.lua
 modules\professions.lua
+modules\recipes.lua
 modules\blacklist.lua
 modules\profiles.lua
 modules\config.lua
diff --git a/locale/enUS.lua b/locale/enUS.lua
index 86c16bc..61d437d 100644
--- a/locale/enUS.lua
+++ b/locale/enUS.lua
@@ -18,6 +18,7 @@ L.Profiles = "Profiles"
 L.Professions = "Professions"
 L.Currency = "Currency"
 L.Blacklist = "Blacklist"
+L.Recipes = "Recipes"
 L.Gold = "Gold"
 L.Close = "Close"
 L.FixDB = "FixDB"
diff --git a/modules/blacklist.lua b/modules/blacklist.lua
index 5f3ad95..a1aac2a 100644
--- a/modules/blacklist.lua
+++ b/modules/blacklist.lua
@@ -11,7 +11,7 @@ function Blacklist:OnEnable()
 	local BlacklistFrame = AceGUI:Create("Window")
 	Blacklist.frame = BlacklistFrame

-	BlacklistFrame:SetTitle("BagSync "..L.Blacklist)
+	BlacklistFrame:SetTitle("BagSync - "..L.Blacklist)
 	BlacklistFrame:SetHeight(500)
 	BlacklistFrame:SetWidth(380)
 	BlacklistFrame:EnableResize(false)
diff --git a/modules/professions.lua b/modules/professions.lua
index fd0d98e..46505c1 100644
--- a/modules/professions.lua
+++ b/modules/professions.lua
@@ -10,8 +10,9 @@ function Professions:OnEnable()
 	--lets create our widgets
 	local ProfessionsFrame = AceGUI:Create("Window")
 	Professions.frame = ProfessionsFrame
+	Professions.parentFrame = ProfessionsFrame.frame

-	ProfessionsFrame:SetTitle("BagSync "..L.Professions)
+	ProfessionsFrame:SetTitle("BagSync - "..L.Professions)
 	ProfessionsFrame:SetHeight(500)
 	ProfessionsFrame:SetWidth(380)
 	ProfessionsFrame:EnableResize(false)
@@ -72,7 +73,7 @@ function Professions:AddEntry(entry, isHeader)
 		label:SetFullWidth(true)
 		label:SetColor(unpack(label.userdata.color))
 		label.label:SetJustifyH("CENTER") --don't like doing this until they update Ace3GUI
-		label.userdata.isHeader = isHeader
+		label.userdata.isHeader = true
 		label.userdata.hasRecipes = false
 		label.headerhighlight:Show()
 	else
@@ -82,27 +83,27 @@ function Professions:AddEntry(entry, isHeader)
 		label:SetFullWidth(true)
 		if entry.recipes then
 			label.userdata.color = {153/255,204/255,51/255} --primary profession color it green
+			label.userdata.hasRecipes = true
 		else
 			label.userdata.color = {102/255,153/255,1} --gathering profession color it blue
+			label.userdata.hasRecipes = false
 		end
 		label:SetColor(unpack(label.userdata.color))
 		label.label:SetJustifyH("LEFT")--don't like doing this until they update Ace3GUI
-		label.userdata.isHeader = isHeader
-		label.userdata.hasRecipes = entry.recipes
+		label.userdata.isHeader = false
 	end

 	label:SetCallback(
 		"OnClick",
 		function (widget, sometable, button)
 			if "LeftButton" == button and label.userdata.hasRecipes then
-				print("left")
+				BSYC:GetModule("Recipes"):ViewRecipes(entry.name, entry.level, entry.recipes)
 			end
 		end)
 	label:SetCallback(
 		"OnEnter",
 		function (widget, sometable)
 			label:SetColor(unpack(highlightColor))
-
 		end)
 	label:SetCallback(
 		"OnLeave",
@@ -132,10 +133,7 @@ function Professions:DisplayList()
 		local playerName = BSYC:GetCharacterRealmInfo(yName, yRealm)

 		for q, r in pairs(v) do
-			local chkRecipes = false
-			local tName, tLevel, tRecipeList = strsplit(",", r)
-			if tRecipeList then chkRecipes = true end
-			table.insert(tmp, { name=tName, level=tLevel, player=playerName, recipeIndex=q, recipes=chkRecipes } )
+			table.insert(tmp, { player=playerName, name=r.name, level=r.level, recipes=r.recipes } )
 			count = count + 1
 		end

diff --git a/modules/profiles.lua b/modules/profiles.lua
index 8256b8f..453cc3e 100644
--- a/modules/profiles.lua
+++ b/modules/profiles.lua
@@ -23,7 +23,7 @@ function Profiles:OnEnable()
 	ProfilesFrame:AddChild(confirmButton)

 	--set the defaults for the main frame
-	ProfilesFrame:SetTitle("BagSync "..L.Profiles)
+	ProfilesFrame:SetTitle("BagSync - "..L.Profiles)
 	ProfilesFrame:SetHeight(200)
 	ProfilesFrame:SetWidth(375)
 	ProfilesFrame:EnableResize(false)
diff --git a/modules/recipes.lua b/modules/recipes.lua
new file mode 100644
index 0000000..56da92a
--- /dev/null
+++ b/modules/recipes.lua
@@ -0,0 +1,148 @@
+
+local BSYC = select(2, ...) --grab the addon namespace
+local Recipes = BSYC:NewModule("Recipes")
+
+local L = LibStub("AceLocale-3.0"):GetLocale("BagSync", true)
+local AceGUI = LibStub("AceGUI-3.0")
+
+function Recipes:OnEnable()
+
+	--lets create our widgets
+	local RecipesFrame = AceGUI:Create("Window")
+	Recipes.frame = RecipesFrame
+
+	RecipesFrame:SetTitle("BagSync - "..L.Recipes)
+	RecipesFrame:SetHeight(500)
+	RecipesFrame:SetWidth(380)
+	RecipesFrame:EnableResize(false)
+
+	local information = AceGUI:Create("Label")
+	information:SetText(L.ProfessionLeftClick)
+	information:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE)
+	information:SetColor(153/255,204/255,51/255)
+	information:SetFullWidth(true)
+	RecipesFrame:AddChild(information)
+
+	Recipes.information = information
+
+	local label = AceGUI:Create("InteractiveLabel")
+	label:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE)
+	label:SetFullWidth(true)
+	label:SetText(" ") --add an empty space just to show the label
+
+	--I know you aren't supposed to but I'm going to have to put it on the label object.  Only because when using userdata the texture sticks around even with release.
+	--So I'm forced to have to add it to label and do a custom OnRelease to get rid of it for other addons.
+	if not label.headerhighlight then
+		label.headerhighlight = label.frame:CreateTexture(nil, "BACKGROUND") --userdata gets deleted when widget is recycled
+		label.headerhighlight:SetAllPoints()
+		label.headerhighlight:SetBlendMode("ADD")
+		label.headerhighlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") --userdata gets deleted when widget is recycled
+		label.headerhighlight:Show()
+	end
+	--remove the highlight texture on widget release for other addons
+	local oldOnRelease = label.OnRelease
+	label.OnRelease = function(self)
+		if self.headerhighlight then
+			self.headerhighlight:SetTexture(nil)
+			self.headerhighlight = nil
+		end
+		if oldOnRelease then
+			oldOnRelease(self)
+		end
+	end
+	RecipesFrame:AddChild(label)
+
+	local scrollframe = AceGUI:Create("ScrollFrame");
+	scrollframe:SetFullWidth(true)
+	scrollframe:SetLayout("Flow")
+
+	Recipes.scrollframe = scrollframe
+	RecipesFrame:AddChild(scrollframe)
+
+	hooksecurefunc(RecipesFrame, "Show" ,function()
+		--always show the recipes frame on the right of the Professions window
+		RecipesFrame:SetPoint( "TOPLEFT", BSYC:GetModule("Professions").parentFrame, "TOPRIGHT", 0, 0)
+	end)
+
+	RecipesFrame:Hide()
+end
+
+function Recipes:AddEntry(entry)
+
+	local name, recipeID = entry.name, entry.recipeID
+
+	local highlightColor = {1, 0, 0}
+	local label = AceGUI:Create("InteractiveLabel")
+
+	label:SetText(name)
+	label:SetFont("Fonts\\FRIZQT__.TTF", 14, THICKOUTLINE)
+	label:SetFullWidth(true)
+	label:SetColor( 1,1,1)
+	label:SetCallback(
+		"OnClick",
+		function (widget, sometable, button)
+			ChatEdit_InsertLink(GetSpellLink(recipeID))
+		end)
+	label:SetCallback(
+		"OnEnter",
+		function (widget, sometable)
+			label:SetColor(unpack(highlightColor))
+			GameTooltip:SetOwner(label.frame, "ANCHOR_BOTTOMRIGHT")
+			GameTooltip:SetSpellByID(recipeID)
+			GameTooltip:Show()
+		end)
+	label:SetCallback(
+		"OnLeave",
+		function (widget, sometable)
+			label:SetColor(1,1,1)
+			GameTooltip:Hide()
+		end)
+
+	self.scrollframe:AddChild(label)
+end
+
+function Recipes:ViewRecipes(tradeName, tradeLevel, tradeRecipes)
+	self.information:SetText(tradeName..format(" |cFFFFFFFF(%s)|r", tradeLevel))
+	self:DisplayList(tradeRecipes)
+	self.frame:Show()
+end
+
+function Recipes:DisplayList(tradeRecipes)
+
+	self.scrollframe:ReleaseChildren() --clear out the scrollframe
+
+	local searchTable = {}
+	local count = 0
+
+	--loop through our Recipes
+	local valuesList = {strsplit("|", tradeRecipes)}
+
+	for idx = 1, #valuesList do
+
+		local recipe_info = _G.C_TradeSkillUI.GetRecipeInfo(valuesList[idx])
+		local craftName = valuesList[idx]
+
+		if recipe_info and recipe_info.name then
+			craftName = recipe_info.name
+		elseif GetSpellInfo(valuesList[idx]) then
+			craftName = GetSpellInfo(valuesList[idx])
+		else
+			craftName = L.ProfessionsFailedRequest:format(valuesList[idx])
+		end
+
+		count = count + 1
+		table.insert(searchTable, {name=craftName, recipeID=valuesList[idx]})
+	end
+
+	--show or hide the scrolling frame depending on count
+	if count > 0 then
+		table.sort(searchTable, function(a,b) return (a.name < b.name) end)
+		for i=1, #searchTable do
+			self:AddEntry(searchTable[i])
+		end
+		self.scrollframe.frame:Show()
+	else
+		self.scrollframe.frame:Hide()
+	end
+
+end
\ No newline at end of file
diff --git a/modules/search.lua b/modules/search.lua
index 56be3bf..5e8155f 100644
--- a/modules/search.lua
+++ b/modules/search.lua
@@ -42,7 +42,7 @@ function Search:OnEnable()
 	local SearchFrame = AceGUI:Create("Window")
 	Search.frame = SearchFrame

-	SearchFrame:SetTitle("BagSync "..L.Search)
+	SearchFrame:SetTitle("BagSync - "..L.Search)
 	SearchFrame:SetHeight(500)
 	SearchFrame:SetWidth(380)
 	SearchFrame:EnableResize(false)