Quantcast

-Changes to work with new Firelands and future updates :)

Xruptor [10-24-11 - 13:55]
-Changes to work with new Firelands and future updates :)
-Yes I'm back to playing WOW!
-Expect updates to all my addons.
Filename
BagSync.lua
BagSync.toc
BagSync_Search.lua
README.textile
libs/LibItemSearch-1.0.lua
diff --git a/BagSync.lua b/BagSync.lua
index c9f62a1..3468831 100644
--- a/BagSync.lua
+++ b/BagSync.lua
@@ -23,12 +23,14 @@ local lastDisplayed = {}
 local currentPlayer
 local currentRealm
 local playerClass
+local playerFaction
 local NUM_EQUIPMENT_SLOTS = 19
 local BS_DB
 local BS_GD
 local BS_TD
 local MAX_GUILDBANK_SLOTS_PER_TAB = 98
 local doTokenUpdate = 0
+local guildTabQueryQueue = {}

 local SILVER = '|cffc7c7cf%s|r'
 local MOSS = '|cFF80FF00%s|r'
@@ -100,6 +102,7 @@ function BagSync:PLAYER_LOGIN()
 	currentPlayer = UnitName('player')
 	currentRealm = GetRealmName()
 	playerClass = select(2, UnitClass("player"))
+	playerFaction = UnitFactionGroup("player")

 	--initiate the db
 	self:StartupDB()
@@ -120,6 +123,10 @@ function BagSync:PLAYER_LOGIN()

 	--save the class information
 	BS_DB["class:0:0"] = playerClass
+
+	--save the faction information
+	--"Alliance", "Horde" or nil
+	BS_DB["faction:0:0"] = playerFaction

 	--check for player not in guild
 	if IsInGuild() or GetNumGuildMembers(true) > 0 then
@@ -168,6 +175,7 @@ function BagSync:PLAYER_LOGIN()
 		[L["guild"]] = "enableGuild",
 		[L["mailbox"]] = "enableMailbox",
 		[L["unitclass"]] = "enableUnitClass",
+		[L["faction"]] = "enableFaction",
 	}

 	SLASH_BAGSYNC1 = "/bagsync"
@@ -226,7 +234,7 @@ function BagSync:PLAYER_LOGIN()
 				--do an item search
 				if BagSync_SearchFrame then
 					if not BagSync_SearchFrame:IsVisible() then BagSync_SearchFrame:Show() end
-					BagSync_SearchFrame.SEARCHBTN:SetText(c:lower())
+					BagSync_SearchFrame.SEARCHBTN:SetText(msg)
 					BagSync_SearchFrame:DoSearch()
 				end
 				return true
@@ -245,6 +253,7 @@ function BagSync:PLAYER_LOGIN()
 		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs throttle - Toggles the throttle when displaying tooltips. (ON = Prevents Lag)."])
 		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs guild - Toggles the displaying of guild information."])
 		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs minimap - Toggles the displaying of BagSync minimap button."])
+		DEFAULT_CHAT_FRAME:AddMessage(L["/bgs faction - Toggles the displaying of items for both factions (Alliance/Horde)."])

 	end

@@ -292,7 +301,8 @@ function BagSync:GUILDBANKFRAME_OPENED()

 	local numTabs = GetNumGuildBankTabs()
 	for tab = 1, numTabs do
-		QueryGuildBankTab(tab)
+		-- add this tab to the queue to refresh; if we do them all at once the server bugs and sends massive amounts of events
+		guildTabQueryQueue[tab] = true
 	end
 end

@@ -302,8 +312,17 @@ end

 function BagSync:GUILDBANKBAGSLOTS_CHANGED()
 	if not BagSyncOpt.enableGuild then return end
+
 	if self.atGuildBank then
-		self:ScanGuildBank()
+		-- check if we need to process the queue
+		local tab = next(guildTabQueryQueue)
+		if tab then
+			QueryGuildBankTab(tab)
+			guildTabQueryQueue[tab] = nil
+		else
+			-- the bank is ready for reading
+			self:ScanGuildBank()
+		end
 	end
 end

@@ -353,6 +372,7 @@ function BagSync:StartupDB()
 	if BagSyncOpt.enableMailbox == nil then BagSyncOpt.enableMailbox = true end
 	if BagSyncOpt.enableUnitClass == nil then BagSyncOpt.enableUnitClass = false end
 	if BagSyncOpt.enableMinimap == nil then BagSyncOpt.enableMinimap = false end
+	if BagSyncOpt.enableFaction == nil then BagSyncOpt.enableFaction = true end

 	BagSyncGUILD_DB = BagSyncGUILD_DB or {}
 	BagSyncGUILD_DB[currentRealm] = BagSyncGUILD_DB[currentRealm] or {}
@@ -1047,59 +1067,65 @@ local function AddOwners(frame, link)

 		local infoString
 		local invCount, bankCount, equipCount, guildCount, mailboxCount = 0, 0, 0, 0, 0
+		local pFaction = v["faction:0:0"] or 'unknown' --just in case ;)

-		--now count the stuff for the user
-		for q, r in pairs(v) do
-			if itemLink then
-				local dblink, dbcount = strsplit(',', r)
-				if dblink then
-					if string.find(q, 'bank') and dblink == itemLink then
-						bankCount = bankCount + (dbcount or 1)
-					elseif string.find(q, 'bag') and dblink == itemLink then
-						invCount = invCount + (dbcount or 1)
-					elseif string.find(q, 'key') and dblink == itemLink then
-						invCount = invCount + (dbcount or 1)
-					elseif string.find(q, 'equip') and dblink == itemLink then
-						equipCount = equipCount + (dbcount or 1)
-					elseif string.find(q, 'mailbox') and dblink == itemLink then
-						mailboxCount = mailboxCount + (dbcount or 1)
+		--check if we should show both factions or not
+		if BagSyncOpt.enableFaction or pFaction == playerFaction then
+
+			--now count the stuff for the user
+			for q, r in pairs(v) do
+				if itemLink then
+					local dblink, dbcount = strsplit(',', r)
+					if dblink then
+						if string.find(q, 'bank') and dblink == itemLink then
+							bankCount = bankCount + (dbcount or 1)
+						elseif string.find(q, 'bag') and dblink == itemLink then
+							invCount = invCount + (dbcount or 1)
+						elseif string.find(q, 'key') and dblink == itemLink then
+							invCount = invCount + (dbcount or 1)
+						elseif string.find(q, 'equip') and dblink == itemLink then
+							equipCount = equipCount + (dbcount or 1)
+						elseif string.find(q, 'mailbox') and dblink == itemLink then
+							mailboxCount = mailboxCount + (dbcount or 1)
+						end
 					end
 				end
 			end
-		end

-		if BagSyncOpt.enableGuild then
-			local guildN = v.guild or nil
+			if BagSyncOpt.enableGuild then
+				local guildN = v.guild or nil

-			--check the guild bank if the character is in a guild
-			if BS_GD and guildN and BS_GD[guildN] then
-				--check to see if this guild has already been done through this run (so we don't do it multiple times)
-				if not previousGuilds[guildN] then
-					--we only really need to see this information once per guild
-					local tmpCount = 0
-					for q, r in pairs(BS_GD[guildN]) do
-						if itemLink then
-							local dblink, dbcount = strsplit(',', r)
-							if dblink and dblink == itemLink then
-								guildCount = guildCount + (dbcount or 1)
-								tmpCount = tmpCount + (dbcount or 1)
+				--check the guild bank if the character is in a guild
+				if BS_GD and guildN and BS_GD[guildN] then
+					--check to see if this guild has already been done through this run (so we don't do it multiple times)
+					if not previousGuilds[guildN] then
+						--we only really need to see this information once per guild
+						local tmpCount = 0
+						for q, r in pairs(BS_GD[guildN]) do
+							if itemLink then
+								local dblink, dbcount = strsplit(',', r)
+								if dblink and dblink == itemLink then
+									guildCount = guildCount + (dbcount or 1)
+									tmpCount = tmpCount + (dbcount or 1)
+								end
 							end
 						end
+						previousGuilds[guildN] = tmpCount
 					end
-					previousGuilds[guildN] = tmpCount
 				end
 			end
-		end

-		--get class for the unit if there is one
-		local pClass = v["class:0:0"] or nil
+			--get class for the unit if there is one
+			local pClass = v["class:0:0"] or nil

-		infoString = CountsToInfoString(invCount, bankCount, equipCount, guildCount, mailboxCount)
-		grandTotal = grandTotal + invCount + bankCount + equipCount + guildCount + mailboxCount
+			infoString = CountsToInfoString(invCount, bankCount, equipCount, guildCount, mailboxCount)
+			grandTotal = grandTotal + invCount + bankCount + equipCount + guildCount + mailboxCount
+
+			if infoString and infoString ~= '' then
+				frame:AddDoubleLine(getNameColor(k, pClass), infoString)
+				table.insert(lastDisplayed, getNameColor(k or 'Unknown', pClass).."@"..(infoString or 'unknown'))
+			end

-		if infoString and infoString ~= '' then
-			frame:AddDoubleLine(getNameColor(k, pClass), infoString)
-			table.insert(lastDisplayed, getNameColor(k or 'Unknown', pClass).."@"..(infoString or 'unknown'))
 		end

 	end
@@ -1125,44 +1151,57 @@ local function AddOwners(frame, link)
 	frame:Show()
 end

-local function HookTip(tooltip)
-	tooltip:HookScript('OnTooltipSetItem', function(self, ...)
-		local _, itemLink = self:GetItem()
-		if itemLink and GetItemInfo(itemLink) then
-			local itemName = GetItemInfo(itemLink)
-			if BagSyncOpt.enableThrottle then
-				if not self.BagSyncThrottle then self.BagSyncThrottle = GetTime() end
-				if not self.BagSyncPrevious then self.BagSyncPrevious = itemName end
-				if not self.BagSyncShowOnce and self:GetName() == "GameTooltip" then self.BagSyncShowOnce = true end
-
-				if itemName ~= self.BagSyncPrevious then
-					self.BagSyncPrevious = itemName
-					self.BagSyncThrottle = GetTime()
-				end
-				if self:GetName() == "GameTooltip" and (GetTime() - self.BagSyncThrottle) >= 0.05 then
-					self.BagSyncShowOnce = nil
-					AddOwners(self, itemLink)
-				elseif self:GetName() ~= "GameTooltip" then
-					self.BagSyncShowOnce = nil
-					AddOwners(self, itemLink)
-				end
-			else
-				AddOwners(self, itemLink)
+--Thanks to Aranarth from wowinterface.  Replaced HookScript with insecure hooks
+local orgTipSetItem = {}
+local orgTipOnUpdate = {}
+
+local function Tip_OnSetItem(self, ...)
+	orgTipSetItem[self](self, ...)
+	local _, itemLink = self:GetItem()
+	if itemLink and GetItemInfo(itemLink) then
+		local itemName = GetItemInfo(itemLink)
+		if BagSyncOpt.enableThrottle then
+			if not self.BagSyncThrottle then self.BagSyncThrottle = GetTime() end
+			if not self.BagSyncPrevious then self.BagSyncPrevious = itemName end
+			if not self.BagSyncShowOnce and self:GetName() == "GameTooltip" then self.BagSyncShowOnce = true end
+
+			if itemName ~= self.BagSyncPrevious then
+				self.BagSyncPrevious = itemName
+				self.BagSyncThrottle = GetTime()
 			end
-		end
-	end)
-
-	tooltip:HookScript('OnUpdate', function(self, ...)
-		if self:GetName() == "GameTooltip" and self.BagSyncShowOnce and self.BagSyncThrottle and (GetTime() - self.BagSyncThrottle) >= 0.05 then
-			local _, itemLink = self:GetItem()
-			self.BagSyncShowOnce = nil
-			if itemLink then
-				AddOwners(self, itemLink)
+
+			if self:GetName() ~= "GameTooltip" or (GetTime() - self.BagSyncThrottle) >= 0.05 then
+				self.BagSyncShowOnce = nil
+				return AddOwners(self, itemLink)
 			end
+		else
+			return AddOwners(self, itemLink)
 		end
-	end)
+	end
 end

-HookTip(GameTooltip)
-HookTip(ItemRefTooltip)
+local function Tip_OnUpdate(self, ...)
+	orgTipOnUpdate[self](self, ...)
+	if self:GetName() == "GameTooltip" and self.BagSyncShowOnce and self.BagSyncThrottle and (GetTime() - self.BagSyncThrottle) >= 0.05 then
+		local _, itemLink = self:GetItem()
+		self.BagSyncShowOnce = nil
+		if itemLink then
+			return AddOwners(self, itemLink)
+		end
+	end
+end
+
+for _, tip in next, { GameTooltip, ItemRefTooltip } do
+
+	orgTipSetItem[tip] = tip:GetScript"OnTooltipSetItem"
+	tip:SetScript("OnTooltipSetItem", Tip_OnSetItem)
+
+	if tip == ItemRefTooltip then
+		orgTipOnUpdate[tip] = tip.UpdateTooltip
+		tip.UpdateTooltip = Tip_OnUpdate
+	else
+		orgTipOnUpdate[tip] = tip:GetScript"OnUpdate"
+		tip:SetScript("OnUpdate", Tip_OnUpdate)
+	end
+end

diff --git a/BagSync.toc b/BagSync.toc
index 4b14673..7180426 100644
--- a/BagSync.toc
+++ b/BagSync.toc
@@ -1,8 +1,8 @@
-## Interface: 40000
+## Interface: 40200
 ## Title: BagSync
 ## Notes: BagSync tracks your characters items and displays it within tooltips.
 ## Author: Xruptor
-## Version: 6.0
+## Version: 6.3.4
 ## SavedVariables: BagSyncDB, BagSyncOpt, BagSyncGUILD_DB, BagSyncTOKEN_DB

 localization\localization.lua
@@ -17,4 +17,4 @@ BagSync_Minimap.lua
 BagSync_Search.lua
 BagSync_Tokens.lua
 BagSync_Profiles.lua
-BagSync.lua
\ No newline at end of file
+BagSync.lua
diff --git a/BagSync_Search.lua b/BagSync_Search.lua
index 8c9e3f3..9bdd8b2 100644
--- a/BagSync_Search.lua
+++ b/BagSync_Search.lua
@@ -1,7 +1,6 @@
 local L = BAGSYNC_L
 local searchTable = {}
 local rows, anchor = {}
-local currentPlayer = UnitName('player')
 local currentRealm = GetRealmName()
 local GetItemInfo = _G['GetItemInfo']

@@ -66,7 +65,10 @@ bgSearch.totalC = totalC
 local closeButton = CreateFrame("Button", nil, bgSearch, "UIPanelCloseButton");
 closeButton:SetPoint("TOPRIGHT", bgSearch, -15, -8);

-bgSearch:SetScript("OnShow", function(self) self:LoadSlider(); end)
+bgSearch:SetScript("OnShow", function(self)
+	self:LoadSlider()
+	self.SEARCHBTN:SetFocus()
+end)
 bgSearch:SetScript("OnHide", function(self)
 	searchTable = {}
 	self.SEARCHBTN:SetText("")
@@ -147,7 +149,8 @@ function bgSearch:LoadSlider()
 			if (i + offset) <= #searchTable then
 				if searchTable[i + offset] then
 					if searchTable[i + offset].rarity then
-						local hex = (select(4, GetItemQualityColor(searchTable[i + offset].rarity)))
+						--local hex = (select(4, GetItemQualityColor(searchTable[i + offset].rarity)))
+						local hex = ("|c" .. select(4, GetItemQualityColor(searchTable[i + offset].rarity))) --@Tonyleila Fix from Wowinterface
 						row.title:SetText(format('%s%s|r', hex, searchTable[i + offset].name) or searchTable[i + offset].name)
 					else
 						row.title:SetText(searchTable[i + offset].name)
@@ -207,50 +210,60 @@ function bgSearch:DoSearch()
 	local count = 0

 	if strlen(searchStr) > 0 then
+
+		local playerFaction = UnitFactionGroup("player")
+
 		--loop through our characters
 		for k, v in pairs(BagSyncDB[currentRealm]) do

-			--now count the stuff for the user
-			for q, r in pairs(BagSyncDB[currentRealm][k]) do
-				local dblink, dbcount = strsplit(',', r)
-				if dblink then
-					local dName, dItemLink, dRarity = GetItemInfo(dblink)
-					if dName and dItemLink then
-						--we found a match
-						if not tempList[dblink] and ItemSearch:Find(dItemLink, searchStr) then
-							table.insert(searchTable, { name=dName, link=dItemLink, rarity=dRarity } )
-							tempList[dblink] = dName
-							count = count + 1
+			local pFaction = v["faction:0:0"] or 'unknown' --just in case ;)
+
+			--check if we should show both factions or not
+			if BagSyncOpt.enableFaction or pFaction == playerFaction then
+
+				--now count the stuff for the user
+				for q, r in pairs(BagSyncDB[currentRealm][k]) do
+					local dblink, dbcount = strsplit(',', r)
+					if dblink then
+						local dName, dItemLink, dRarity = GetItemInfo(dblink)
+						if dName and dItemLink then
+							--we found a match
+							if not tempList[dblink] and ItemSearch:Find(dItemLink, searchStr) then
+								table.insert(searchTable, { name=dName, link=dItemLink, rarity=dRarity } )
+								tempList[dblink] = dName
+								count = count + 1
+							end
 						end
 					end
 				end
-			end

-			--only search guild if the guild features are on
-			if BagSyncOpt.enableGuild then
-				local guildN = BagSyncDB[currentRealm][k].guild or nil
+				--only search guild if the guild features are on
+				if BagSyncOpt.enableGuild then
+					local guildN = BagSyncDB[currentRealm][k].guild or nil

-				--check the guild bank if the character is in a guild
-				if BagSyncGUILD_DB and guildN and BagSyncGUILD_DB[currentRealm][guildN] then
-					--check to see if this guild has already been done through this run (so we don't do it multiple times)
-					if not previousGuilds[guildN] then
-						for q, r in pairs(BagSyncGUILD_DB[currentRealm][guildN]) do
-							local dblink, dbcount = strsplit(',', r)
-							if dblink then
-								local dName, dItemLink, dRarity = GetItemInfo(dblink)
-								if dName then
-									--we found a match
-									if not tempList[dblink] and ItemSearch:Find(dItemLink, searchStr) then
-										table.insert(searchTable, { name=dName, link=dItemLink, rarity=dRarity } )
-										tempList[dblink] = dName
-										count = count + 1
+					--check the guild bank if the character is in a guild
+					if BagSyncGUILD_DB and guildN and BagSyncGUILD_DB[currentRealm][guildN] then
+						--check to see if this guild has already been done through this run (so we don't do it multiple times)
+						if not previousGuilds[guildN] then
+							for q, r in pairs(BagSyncGUILD_DB[currentRealm][guildN]) do
+								local dblink, dbcount = strsplit(',', r)
+								if dblink then
+									local dName, dItemLink, dRarity = GetItemInfo(dblink)
+									if dName then
+										--we found a match
+										if not tempList[dblink] and ItemSearch:Find(dItemLink, searchStr) then
+											table.insert(searchTable, { name=dName, link=dItemLink, rarity=dRarity } )
+											tempList[dblink] = dName
+											count = count + 1
+										end
 									end
 								end
 							end
+							previousGuilds[guildN] = true
 						end
-						previousGuilds[guildN] = true
 					end
 				end
+
 			end

 		end
@@ -263,4 +276,4 @@ function bgSearch:DoSearch()
 	bgSearch:LoadSlider()
 end

-bgSearch:Hide()
\ No newline at end of file
+bgSearch:Hide()
diff --git a/README.textile b/README.textile
new file mode 100644
index 0000000..83365f7
--- /dev/null
+++ b/README.textile
@@ -0,0 +1,3 @@
+h3. (5-30-2011) Major Restructuring of BagSync (Blame Curse at CurseForge.com)
+
+* I had to remove pretty much all previous version tags of BagSync prior to the v6.X format. The primary reason for this was an incompatibility with P.O.S. CurseForge. Now I know why I prefer WOWInterface over CurseForge. In any case, apparently they are extraordinarily picky on how tags should be placed on git. So I had to modify the current tag system for BagSync in order to bend my back so it works on their system. Granted it worked fine on EVERY other Git Respository I used, minus CurseForge of course  <em>(Rollseyes)</em>. So from now on I'm going to use the vX.X format.
diff --git a/libs/LibItemSearch-1.0.lua b/libs/LibItemSearch-1.0.lua
index 85cce6f..e7f52a6 100644
--- a/libs/LibItemSearch-1.0.lua
+++ b/libs/LibItemSearch-1.0.lua
@@ -18,7 +18,7 @@
 	I kindof half want to make a full parser for this
 --]]

-local MAJOR, MINOR = "LibItemSearch-1.0", 3
+local MAJOR, MINOR = "LibItemSearch-1.0", 2
 local ItemSearch = LibStub:NewLibrary(MAJOR, MINOR)
 if not ItemSearch then return end

@@ -317,33 +317,6 @@ ItemSearch:RegisterTypedSearch{
 	}
 }

-ItemSearch:RegisterTypedSearch{
-	id = 'tooltipDesc',
-
-	isSearch = function(self, search)
-		return search and search:match('^tt:(.+)$')
-	end,
-
-	findItem = function(self, itemLink, search)
-		--no match?, pull in the resut from tooltip parsing
-		tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE')
-		tooltipScanner:SetHyperlink(itemLink)
-
-		local i = 1
-		while i <= tooltipScanner:NumLines() do
-			local text =  _G[tooltipScanner:GetName() .. 'TextLeft' .. i]:GetText():lower()
-			if text and text:match(search) then
-				tooltipScanner:Hide()
-				return true
-			end
-			i = i + 1
-		end
-
-		tooltipScanner:Hide()
-		return false
-	end,
-}
-

 --[[ equipment set search ]]--