Quantcast

-added attempt to store professions for characters.

Xruptor [12-07-11 - 20:14]
-added attempt to store professions for characters.
-note that this is still in the works and hasn't been fully tested.
Filename
BagSync.lua
BagSync.toc
BagSync_Crafts.lua
BagSync_Minimap.lua
BagSync_Tokens.lua
Bindings.xml
localization/localization.lua
diff --git a/BagSync.lua b/BagSync.lua
index 2e75890..50108ce 100644
--- a/BagSync.lua
+++ b/BagSync.lua
@@ -28,6 +28,7 @@ local NUM_EQUIPMENT_SLOTS = 19
 local BS_DB
 local BS_GD
 local BS_TD
+local BS_CD
 local MAX_GUILDBANK_SLOTS_PER_TAB = 98
 local doTokenUpdate = 0
 local guildTabQueryQueue = {}
@@ -95,6 +96,8 @@ function BagSync:PLAYER_LOGIN()
 	 BINDING_NAME_BAGSYNCTOGGLESEARCH = L["Toggle Search"]
 	 BINDING_NAME_BAGSYNCTOGGLETOKENS = L["Toggle Tokens"]
 	 BINDING_NAME_BAGSYNCTOGGLEPROFILES = L["Toggle Profiles"]
+	 BINDING_NAME_BAGSYNCTOGGLECRAFTS = L["Toggle Professions"]
+

 	local ver = GetAddOnMetadata("BagSync","Version") or 0

@@ -179,6 +182,9 @@ function BagSync:PLAYER_LOGIN()
 	self:RegisterEvent("VOID_STORAGE_CONTENTS_UPDATE")
 	self:RegisterEvent("VOID_TRANSFER_DONE")

+	--this will be used for getting the tradeskill link
+	self:RegisterEvent("TRADE_SKILL_SHOW")
+
 	SLASH_BAGSYNC1 = "/bagsync"
 	SLASH_BAGSYNC2 = "/bgs"
 	SlashCmdList["BAGSYNC"] = function(msg)
@@ -210,6 +216,13 @@ function BagSync:PLAYER_LOGIN()
 					BagSync_ProfilesFrame:Show()
 				end
 				return true
+			elseif c and c:lower() == L["professions"] then
+				if BagSync_CraftsFrame:IsVisible() then
+					BagSync_CraftsFrame:Hide()
+				else
+					BagSync_CraftsFrame:Show()
+				end
+				return true
 			elseif c and c:lower() == L["fixdb"] then
 				self:FixDB_Data()
 				return true
@@ -233,6 +246,7 @@ function BagSync:PLAYER_LOGIN()
 		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs gold - Displays a tooltip with the amount of gold on each character."])
 		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs tokens - Opens the tokens/currency window."])
 		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs profiles - Opens the profiles window."])
+		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs professions - Opens the professions window."])
 		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs fixdb - Runs the database fix (FixDB) on BagSync."])
 		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs config - Opens the BagSync Config Window"] )

@@ -379,6 +393,93 @@ function BagSync:AUCTION_OWNED_LIST_UPDATE()
 end

 ------------------------------
+--     TRADE SKILLS         --
+------------------------------
+
+--list of tradeskills with NO skill link but can be used as primaries (ex. a person with two gathering skills)
+local noLinkTS = {
+	["Interface\Icons\Trade_Herbalism"] = true, --this is Herbalism
+	["Interface\Icons\INV_Misc_Pelt_Wolf_01"] = true, --this is Skinning
+	["Interface\Icons\INV_Pick_02"] = true, --this is Mining
+}
+
+local function doRegularTradeSkill(numIndex, dbIdx)
+	local name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine, skillModifier = GetProfessionInfo(numIndex)
+	if name and skillLevel then
+		BS_CD[dbIdx] = format('%s,%s', name, skillLevel)
+	end
+end
+
+function BagSync:TRADE_SKILL_SHOW()
+	--IsTradeSkillLinked() returns true only if trade window was opened from chat link (meaning another player)
+	if (not IsTradeSkillLinked()) then
+
+		local tradename = _G.GetTradeSkillLine()
+		local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions()
+		if not tradename then return end
+
+		--prof1
+		if prof1 and (GetProfessionInfo(prof1) == tradename) and GetTradeSkillListLink() then
+			local skill = select(3, GetProfessionInfo(prof1))
+			BS_CD[1] = { tradename, GetTradeSkillListLink(), skill }
+		elseif prof1 and select(2, GetProfessionInfo(prof1)) and noLinkTS[select(2, GetProfessionInfo(prof1))] then
+			--only store if it's herbalism, skinning, or mining
+			doRegularTradeSkill(prof1, 1)
+		elseif not prof1 and BS_CD[1] then
+			--they removed a profession
+			BS_CD[1] = nil
+		end
+
+		--prof2
+		if prof2 and (GetProfessionInfo(prof2) == tradename) and GetTradeSkillListLink() then
+			local skill = select(3, GetProfessionInfo(prof2))
+			BS_CD[2] = { tradename, GetTradeSkillListLink(), skill }
+		elseif prof2 and select(2, GetProfessionInfo(prof2)) and noLinkTS[select(2, GetProfessionInfo(prof2))] then
+			--only store if it's herbalism, skinning, or mining
+			doRegularTradeSkill(prof2, 2)
+		elseif not prof2 and BS_CD[2] then
+			--they removed a profession
+			BS_CD[2] = nil
+		end
+
+		--archaeology
+		if archaeology then
+			doRegularTradeSkill(archaeology, 3)
+		elseif not archaeology and BS_CD[3] then
+			--they removed a profession
+			BS_CD[3] = nil
+		end
+
+		--fishing
+		if fishing then
+			doRegularTradeSkill(fishing, 4)
+		elseif not fishing and BS_CD[4] then
+			--they removed a profession
+			BS_CD[4] = nil
+		end
+
+		--cooking
+		if cooking and (GetProfessionInfo(cooking) == tradename) and GetTradeSkillListLink() then
+			local skill = select(3, GetProfessionInfo(cooking))
+			BS_CD[5] = { tradename, GetTradeSkillListLink(), skill }
+		elseif not cooking and BS_CD[5] then
+			--they removed a profession
+			BS_CD[5] = nil
+		end
+
+		--firstAid
+		if firstAid and (GetProfessionInfo(firstAid) == tradename) and GetTradeSkillListLink() then
+			local skill = select(3, GetProfessionInfo(firstAid))
+			BS_CD[6] = { tradename, GetTradeSkillListLink(), skill }
+		elseif not firstAid and BS_CD[6] then
+			--they removed a profession
+			BS_CD[6] = nil
+		end
+
+	end
+end
+
+------------------------------
 --      BAG UPDATES  	    --
 ------------------------------

@@ -425,6 +526,11 @@ function BagSync:StartupDB()
 	BagSyncTOKEN_DB = BagSyncTOKEN_DB or {}
 	BagSyncTOKEN_DB[currentRealm] = BagSyncTOKEN_DB[currentRealm] or {}
 	BS_TD = BagSyncTOKEN_DB[currentRealm]
+
+	BagSyncCRAFT_DB = BagSyncCRAFT_DB or {}
+	BagSyncCRAFT_DB[currentRealm] = BagSyncCRAFT_DB[currentRealm] or {}
+	BagSyncCRAFT_DB[currentRealm][currentPlayer] = BagSyncCRAFT_DB[currentRealm][currentPlayer] or {}
+	BS_CD = BagSyncCRAFT_DB[currentRealm][currentPlayer]
 end

 function BagSync:FixDB_Data(onlyChkGuild)
@@ -432,6 +538,7 @@ function BagSync:FixDB_Data(onlyChkGuild)
 	--Removes obsolete guild information
 	--Removes obsolete characters from tokens db
 	--Removes obsolete keyring information
+	--Removes obsolete profession information
 	--Will only check guild related information if the paramater is passed as true

 	local storeUsers = {}
@@ -467,10 +574,11 @@ function BagSync:FixDB_Data(onlyChkGuild)
 		end
 	end

-	--token data, only do if were not doing a guild check
+	--token data and profession data, only do if were not doing a guild check
 	--also display fixdb message only if were not doing a guild check
 	if not onlyChkGuild then

+		--fix tokens
 		for realm, rd in pairs(BagSyncTOKEN_DB) do
 			--realm
 			if not storeUsers[realm] then
@@ -494,6 +602,22 @@ function BagSync:FixDB_Data(onlyChkGuild)
 			end
 		end

+		--fix professions
+		for realm, rd in pairs(BagSyncCRAFT_DB) do
+			--realm
+			if not storeUsers[realm] then
+				--if it's not a realm that ANY users are on then delete it
+				BagSyncCRAFT_DB[realm] = nil
+			else
+				for k, v in pairs(rd) do
+					if not storeUsers[realm][k] then
+						--if the user doesn't exist then delete data
+						BagSyncCRAFT_DB[realm][k] = nil
+					end
+				end
+			end
+		end
+
 		DEFAULT_CHAT_FRAME:AddMessage("|cFF99CC33BagSync:|r |cFFFF9900"..L["A FixDB has been performed on BagSync!  The database is now optimized!"].."|r")
 	end

@@ -788,7 +912,7 @@ function BagSync:ScanAuctionHouse()
 	local ahCount = 0
 	local numActiveAuctions = GetNumAuctionItems("owner")

-	if not BS_DB.AH_LastScan then BS_DB.AH_LastScan = time() end --this is only really used once, at first activation of v6.3
+	if not BS_DB.AH_LastScan then BS_DB.AH_LastScan = time() end --this is only really used once, at first activation of v6.7

 	--scan the auction house
 	if (numActiveAuctions > 0) then
diff --git a/BagSync.toc b/BagSync.toc
index 166a742..4c1a082 100644
--- a/BagSync.toc
+++ b/BagSync.toc
@@ -2,8 +2,8 @@
 ## Title: BagSync
 ## Notes: BagSync tracks your characters items and displays it within tooltips.
 ## Author: Xruptor
-## Version: 6.6.2
-## SavedVariables: BagSyncDB, BagSyncOpt, BagSyncGUILD_DB, BagSyncTOKEN_DB
+## Version: 6.7
+## SavedVariables: BagSyncDB, BagSyncOpt, BagSyncGUILD_DB, BagSyncTOKEN_DB, BagSyncCRAFT_DB

 localization\localization.lua
 libs\LibStub.lua
@@ -16,6 +16,7 @@ libs\LibDataBroker-1.1.lua
 BagSync_Minimap.lua
 BagSync_Search.lua
 BagSync_Tokens.lua
+BagSync_Crafts.lua
 BagSync_Profiles.lua
 BagSync_Config.lua
 BagSync.lua
diff --git a/BagSync_Crafts.lua b/BagSync_Crafts.lua
new file mode 100644
index 0000000..ea6c716
--- /dev/null
+++ b/BagSync_Crafts.lua
@@ -0,0 +1,234 @@
+local L = BAGSYNC_L
+local craftsTable = {}
+local tRows, tAnchor = {}
+local currentPlayer = UnitName('player')
+local currentRealm = GetRealmName()
+
+local bgCrafts = CreateFrame("Frame","BagSync_CraftsFrame", UIParent)
+
+local function LoadSlider()
+
+	local function OnEnter(self)
+		if self.canLink and self.owner then
+			GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
+			GameTooltip:AddLine(format('|cFF99CC33%s|r', self.owner))
+			GameTooltip:AddLine(L["Left Click = Link to view tradeskill."])
+			GameTooltip:AddLine(L["Right Click = Insert tradeskill link."])
+			GameTooltip:Show()
+		end
+	end
+
+	local function OnLeave() GameTooltip:Hide() end
+
+	local EDGEGAP, ROWHEIGHT, ROWGAP, GAP = 16, 20, 2, 4
+	local FRAME_HEIGHT = bgCrafts:GetHeight() - 50
+	local SCROLL_TOP_POSITION = -80
+	local totaltRows = math.floor((FRAME_HEIGHT-22)/(ROWHEIGHT + ROWGAP))
+
+	for i=1, totaltRows do
+		if not tRows[i] then
+			local row = CreateFrame("Button", nil, bgCrafts)
+			if not tAnchor then row:SetPoint("BOTTOMLEFT", bgCrafts, "TOPLEFT", 0, SCROLL_TOP_POSITION)
+			else row:SetPoint("TOP", tAnchor, "BOTTOM", 0, -ROWGAP) end
+			row:SetPoint("LEFT", EDGEGAP, 0)
+			row:SetPoint("RIGHT", -EDGEGAP*2-8, 0)
+			row:SetHeight(ROWHEIGHT)
+			row:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
+			tAnchor = row
+			tRows[i] = row
+
+			local title = row:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
+			title:SetPoint("LEFT")
+			title:SetJustifyH("LEFT")
+			title:SetWidth(row:GetWidth())
+			title:SetHeight(ROWHEIGHT)
+			row.title = title
+
+			row:RegisterForClicks("LeftButtonUp", "RightButtonUp")
+			row:SetScript("OnEnter", OnEnter)
+			row:SetScript("OnLeave", OnLeave)
+			row:SetScript("OnClick", function (self, button, down)
+				if self.link then
+					if button == "LeftButton" then
+						DEFAULT_CHAT_FRAME:AddMessage(format('%s|cFF99CC33%s|r ==> %s', L["Click to view profession: "], self.owner, self.link))
+					else
+						local editBox = ChatEdit_ChooseBoxForSend()
+
+						if editBox then
+							editBox:Insert(self.link)
+							ChatFrame_OpenChat(editBox:GetText())
+						end
+					end
+				end
+			end)
+		end
+	end
+
+	local offset = 0
+	local RefreshCrafts = function()
+		if not BagSync_CraftsFrame:IsVisible() then return end
+
+		for i,row in ipairs(tRows) do
+			if (i + offset) <= #craftsTable then
+				if craftsTable[i + offset] then
+
+					if craftsTable[i + offset].isHeader then
+						row.title:SetText("|cFFFFFFFF"..craftsTable[i + offset].name.."|r")
+					else
+						row.title:SetText( format('|cFF99CC33%s|r |cFFFFFFFF(%s)|r', craftsTable[i + offset].name,  craftsTable[i + offset].level))
+					end
+
+					--header texture and parameters
+					if craftsTable[i + offset].isHeader then
+						row:LockHighlight()
+						row.title:SetJustifyH("CENTER")
+						row.canLink = nil
+					else
+						row:UnlockHighlight()
+						row.title:SetJustifyH("LEFT")
+						row.canLink = craftsTable[i + offset].isLink
+						row.link = craftsTable[i + offset].link
+						row.owner = craftsTable[i + offset].owner
+					end
+
+				end
+			else
+				row:Hide()
+			end
+		end
+	end
+
+	RefreshCrafts()
+
+	if not bgCrafts.scrollbar then
+		bgCrafts.scrollbar = LibStub("tekKonfig-Scroll").new(bgCrafts, nil, #tRows/2)
+		bgCrafts.scrollbar:ClearAllPoints()
+		bgCrafts.scrollbar:SetPoint("TOP", tRows[1], 0, -16)
+		bgCrafts.scrollbar:SetPoint("BOTTOM", tRows[#tRows], 0, 16)
+		bgCrafts.scrollbar:SetPoint("RIGHT", -16, 0)
+	end
+
+	if #craftsTable > 0 then
+		bgCrafts.scrollbar:SetMinMaxValues(0, math.max(0, #craftsTable - #tRows))
+		bgCrafts.scrollbar:SetValue(0)
+		bgCrafts.scrollbar:Show()
+	else
+		bgCrafts.scrollbar:Hide()
+	end
+
+	local f = bgCrafts.scrollbar:GetScript("OnValueChanged")
+	bgCrafts.scrollbar:SetScript("OnValueChanged", function(self, value, ...)
+		offset = math.floor(value)
+		RefreshCrafts()
+		return f(self, value, ...)
+	end)
+
+	bgCrafts:EnableMouseWheel()
+	bgCrafts:SetScript("OnMouseWheel", function(self, val)
+		bgCrafts.scrollbar:SetValue(bgCrafts.scrollbar:GetValue() - val*#tRows/2)
+	end)
+end
+
+local function DoCrafts()
+	if not BagSync or not BagSyncCRAFT_DB then return end
+	if not BagSyncCRAFT_DB[currentRealm] then return end
+
+	craftsTable = {} --reset
+	local tmp = {}
+
+	--loop through our characters
+	-----------------------------------
+	if BagSyncCRAFT_DB[currentRealm] then
+		for k, v in pairs(BagSyncCRAFT_DB[currentRealm]) do
+
+			tmp = {}
+			for q, r in pairs(v) do
+				if type(r) == "string" then
+					local trName, trSkillLevel = strsplit(',', r)
+					if trName and trSkillLevel then
+						table.insert(tmp, { name=trName, level=trSkillLevel, isLink=false, owner=k} )
+					end
+				elseif type(r) == "table" and r[1] and r[2] and r[3] then
+					table.insert(tmp, { name=r[1], link=r[2], level=r[3], isLink=true, owner=k} )
+				end
+			end
+			table.sort(tmp, function(a,b) return (a.name < b.name) end)
+
+			--now add it to master table to sort later, only add if we have something to add
+			if #tmp > 0 then
+				table.insert(craftsTable, {header=k, info=tmp})
+			end
+		end
+	end
+	-----------------------------------
+
+	--sort it
+	table.sort(craftsTable, function(a,b)
+		if a.header < b.header then
+			return true;
+		end
+	end)
+
+	--now that the header names are sorted lets add all headers and info to master table
+	tmp = {} --reset
+
+	for i=1, #craftsTable do
+		--insert header
+		table.insert(tmp, { name=craftsTable[i].header, isHeader=true } )
+		--insert sub information :)
+		for y=1, #craftsTable[i].info do
+			table.insert(tmp, craftsTable[i].info[y])
+		end
+	end
+	craftsTable = tmp
+
+	LoadSlider()
+end
+
+bgCrafts:SetFrameStrata("HIGH")
+bgCrafts:SetToplevel(true)
+bgCrafts:EnableMouse(true)
+bgCrafts:SetMovable(true)
+bgCrafts:SetClampedToScreen(true)
+bgCrafts:SetWidth(380)
+bgCrafts:SetHeight(500)
+
+bgCrafts:SetBackdrop({
+		bgFile = "Interface/Tooltips/UI-Tooltip-Background",
+		edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
+		tile = true,
+		tileSize = 16,
+		edgeSize = 32,
+		insets = { left = 5, right = 5, top = 5, bottom = 5 }
+})
+
+bgCrafts:SetBackdropColor(0,0,0,1)
+bgCrafts:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
+
+local addonTitle = bgCrafts:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
+addonTitle:SetPoint("CENTER", bgCrafts, "TOP", 0, -20)
+addonTitle:SetText("|cFF99CC33BagSync|r |cFFFFFFFF("..L["Professions"]..")|r")
+
+local closeButton = CreateFrame("Button", nil, bgCrafts, "UIPanelCloseButton");
+closeButton:SetPoint("TOPRIGHT", bgCrafts, -15, -8);
+
+bgCrafts:SetScript("OnShow", function(self) DoCrafts(); LoadSlider(); end)
+bgCrafts:SetScript("OnHide", function(self)
+	craftsTable = {}
+end)
+
+bgCrafts:SetScript("OnMouseDown", function(frame, button)
+	if frame:IsMovable() then
+		frame.isMoving = true
+		frame:StartMoving()
+	end
+end)
+
+bgCrafts:SetScript("OnMouseUp", function(frame, button)
+	if( frame.isMoving ) then
+		frame.isMoving = nil
+		frame:StopMovingOrSizing()
+	end
+end)
+
+bgCrafts:Hide()
\ No newline at end of file
diff --git a/BagSync_Minimap.lua b/BagSync_Minimap.lua
index 88df847..d252b88 100644
--- a/BagSync_Minimap.lua
+++ b/BagSync_Minimap.lua
@@ -50,6 +50,9 @@ bgsMinimapDD.initialize = function(self, level)
 		addButton(level, L["Profiles"], nil, 1, nil, 'profiles', function(frame, ...)
 			if BagSync_ProfilesFrame then BagSync_ProfilesFrame:Show() end
 		end)
+		addButton(level, L["Professions"], nil, 1, nil, 'professions', function(frame, ...)
+			if BagSync_CraftsFrame then BagSync_CraftsFrame:Show() end
+		end)
 		addButton(level, L["Gold"], nil, 1, nil, 'gold', function(frame, ...)
 			if BagSync then BagSync:ShowMoneyTooltip() end
 		end)
diff --git a/BagSync_Tokens.lua b/BagSync_Tokens.lua
index f9d7e28..3297881 100644
--- a/BagSync_Tokens.lua
+++ b/BagSync_Tokens.lua
@@ -80,6 +80,7 @@ local function LoadSlider()
 					if tokensTable[i + offset].isHeader then
 						row:LockHighlight()
 						row.title:SetJustifyH("CENTER")
+						row.tooltip = nil
 					else
 						row:UnlockHighlight()
 						row.title:SetJustifyH("LEFT")
diff --git a/Bindings.xml b/Bindings.xml
index 31804f7..230a5bf 100644
--- a/Bindings.xml
+++ b/Bindings.xml
@@ -20,4 +20,11 @@
 		BagSync_ProfilesFrame:Show()
 	end
   </Binding>
-</Bindings>
\ No newline at end of file
+   <Binding name="BAGSYNCTOGGLECRAFTS" header="BAGSYNC">
+	if BagSync_CraftsFrame:IsVisible() then
+		BagSync_CraftsFrame:Hide()
+	else
+		BagSync_CraftsFrame:Show()
+	end
+  </Binding>
+</Bindings>
diff --git a/localization/localization.lua b/localization/localization.lua
index 9f1d6b0..f2ab3a1 100644
--- a/localization/localization.lua
+++ b/localization/localization.lua
@@ -12,6 +12,7 @@
 -- ["Total:"] = "",
 -- ["Tokens"] = "",
 -- ["Profiles"] = "",
+-- ["Professions"] = "",
 -- ["Gold"] = "",
 -- ["Close"] = "",
 -- ["FixDB"] = "",
@@ -22,11 +23,15 @@
 -- ["Toggle Search"] = "",
 -- ["Toggle Tokens"] = "",
 -- ["Toggle Profiles"] = "",
+-- ["Toggle Professions"] = "",
 -- ["A FixDB has been performed on BagSync!  The database is now optimized!"] = "",
 -- ["ON"] = "",
 -- ["OFF"] = "",
 -- ["Left Click = Search Window"] = "",
 -- ["Right Click = BagSync Menu"] = "",
+-- ["Left Click = Link to view tradeskill."] = "",
+-- ["Right Click = Insert tradeskill link."] = "",
+-- ["Click to view profession: "] = "",
 -- ----THESE ARE FOR SLASH COMMANDS
 -- ["[itemname]"] = "",
 -- ["search"] = "",
@@ -34,6 +39,7 @@
 -- ["tokens"] = "",
 -- ["fixdb"] = "",
 -- ["profiles"] = "",
+-- ["professions"] = "",
 -- ----------------------
 -- ["/bgs [itemname] - Does a quick search for an item"] = "",
 -- ["/bgs search - Opens the search window"] = "",
@@ -42,6 +48,7 @@
 -- ["/bgs profiles - Opens the profiles window."] = "",
 -- ["/bgs fixdb - Runs the database fix (FixDB) on BagSync."] = "",
 -- ["/bgs config - Opens the BagSync Config Window"] = "",
+-- ["/bgs professions - Opens the professions window."] = "",
 -- ["Display [Total] in tooltips and gold display."] = "",
 -- ["Display [Guild Name] display in tooltips."] = "",
 -- ["Enable guild bank items."] = "",