- Support API version 100008

Yaron Kfir [08-06-14 - 21:45]
 - Support API version 100008
 - Preserve price history from previous API version
Filename
Changelog
PriceTracker.lua
PriceTracker.txt
diff --git a/Changelog b/Changelog
index f0472a5..89b0041 100644
--- a/Changelog
+++ b/Changelog
@@ -1,5 +1,9 @@
 Changelog

+v2.0
+ - Support API version 100008
+ - Preserve price history from previous API version
+
 v1.9
  - Fixed bug causing ESO to crash when hovering over a guild store listing item
  - Cleaning stale items now works as expected
diff --git a/PriceTracker.lua b/PriceTracker.lua
index 8fc1a8d..15de4cb 100644
--- a/PriceTracker.lua
+++ b/PriceTracker.lua
@@ -104,6 +104,13 @@ function PriceTracker:Housekeeping()
 		self.settings.itemList = {}
 	end

+	-- Preserve prices from previous UI versions
+	if PriceTrackerSettings["Default"][""] ~= nil then
+		PriceTrackerSettings["Default"][GetDisplayName()] = PriceTrackerSettings["Default"][""]
+		PriceTrackerSettings["Default"][""] = nil
+		SLASH_COMMANDS["/reloadui"]()
+	end
+
 	for k, v in pairs(self.settings.itemList) do
 		-- Remove any empty items
 		for level, item in pairs(v) do
@@ -117,30 +124,22 @@ function PriceTracker:Housekeeping()
 end

 function PriceTracker:OnUpdateTooltip(item, tooltip)
-	local _
 	if not tooltip then tooltip = ItemTooltip end
 	if not item or not item.dataEntry or not item.dataEntry.data or not self.menu:IsKeyPressed() or self.selectedItem[tooltip] == item then return end
 	self.selectedItem[tooltip] = item
 	local stackCount = item.dataEntry.data.stackCount or item.dataEntry.data.stack
 	if not stackCount then return end

-	-- Attempt to find the item ID and level
-	local itemId = item.dataEntry.data.itemId
-	local level = item.dataEntry.data.level
-	if not item.dataEntry.data.itemId then
-		if item.dataEntry.data.searchData then
-			-- Must be a bag or bank item
-			_, _, _, itemId, _, level = ZO_LinkHandler_ParseLink(GetItemLink(item.dataEntry.data.searchData.bagId, item.dataEntry.data.searchData.slotIndex, item.dataEntry.data.searchData.type))
-		end
-		if item.dataEntry.data.itemIndex then
-			if ZO_TradingHouseMenuBarButton1.m_object.m_state == 1 then
-				-- Must be a store search item
-				_, _, _, itemId, _, level = ZO_LinkHandler_ParseLink(GetTradingHouseSearchResultItemLink(item.dataEntry.data.itemIndex))
-			end
-			if ZO_TradingHouseMenuBarButton3.m_object.m_state == 1 then
-				-- Must be a store listing item
-				_, _, _, itemId, _, level = ZO_LinkHandler_ParseLink(GetTradingHouseListingItemLink(item.dataEntry.data.itemIndex))
-			end
+	local itemLink = self:GetItemLink(item)
+	local _, _, _, itemId = ZO_LinkHandler_ParseLink(itemLink)
+	local level = self:GetItemLevel(itemLink)
+
+	if not itemLink then
+		if item.dataEntry and item.dataEntry.data and item.dataEntry.data.itemId then
+			itemId = item.dataEntry.data.itemId
+			level = tonumber(item.dataEntry.data.level)
+		else
+			return
 		end
 	end

@@ -260,7 +259,9 @@ end

 function PriceTracker:AddItem(index)
 	local icon, itemName, quality, stackCount, sellerName, timeRemaining, purchasePrice = GetTradingHouseSearchResultItemInfo(index)
-	local _, _, _, itemId, _, level, enchantmentType, enchantmentStrength1, enchantmentStrength2, _, _, _, _, _, _, _, _, _, style, crafted, _, charge = ZO_LinkHandler_ParseLink(GetTradingHouseSearchResultItemLink(index))
+	local itemLink = GetTradingHouseSearchResultItemLink(index)
+	local _, _, _, itemId = ZO_LinkHandler_ParseLink(itemLink)
+	local level = self:GetItemLevel(itemLink)

 	if not purchasePrice or not stackCount then return end

@@ -275,13 +276,7 @@ function PriceTracker:AddItem(index)
 		purchasePrice = purchasePrice,
 		eachPrice = purchasePrice / stackCount,
 		guildId = self.currentGuild,
-		guildName = GetGuildName(self.currentGuild),
-		enchantmentType = enchantmentType,
-		enchantmentStrength1 = enchantmentStrength1,
-		enchantmentStrength2 = enchantmentStrength2,
-		style = style,
-		crafted = (crafted == 1),
-		charge = charge
+		guildName = GetGuildName(self.currentGuild)
 	}

 	if not self.settings.itemList[itemId] then
@@ -320,7 +315,8 @@ function PriceTracker:GetMatches(itemId, itemLevel)

 	local matches = {}
 	for level, items in pairs(self.settings.itemList[itemId]) do
-		if (not itemLevel or itemLevel == level) then
+		level = tonumber(level)
+		if not itemLevel or itemLevel == level or (itemLevel < 2 and level < 2) then
 			local index = next(items)
 			while index do
 				if limitToGuild == 1 or items[index].guildId == GetGuildId(limitToGuild - 1) then
@@ -334,7 +330,6 @@ function PriceTracker:GetMatches(itemId, itemLevel)
 	return matches
 end

--- TODO: Base calculation on user preference
 function PriceTracker:SuggestPrice(matches)
 	if self.settings.algorithm == self.menu.algorithmTable[1] then
 		return self.mathUtils:WeightedAverage(matches)
@@ -370,4 +365,38 @@ function PriceTracker:NormalizeName(name)
 	return zo_strformat(SI_TOOLTIP_ITEM_NAME, name)
 end

+function PriceTracker:GetItemLink(item)
+	if not item or not item.GetParent then return nil end
+
+	local parent = item:GetParent()
+	if not parent then return nil end
+
+	local parentName = parent:GetName()
+	if parentName.find(parentName, "BackpackContents") then
+		return GetItemLink(item.dataEntry.data.bagId, item.dataEntry.data.slotIndex, LINK_STYLE_DEFAULT)
+	end
+	if parentName == "ZO_StoreWindowListContents" then
+		return GetStoreItemLink(item.dataEntry.data.slotIndex, LINK_STYLE_DEFAULT)
+	end
+	if parentName == "ZO_TradingHouseItemPaneSearchResultsContents" then
+		return GetTradingHouseSearchResultItemLink(item.dataEntry.data.slotIndex)
+	end
+	if parentName == "ZO_TradingHousePostedItemsListContents" then
+		return GetTradingHouseListingItemLink(item.dataEntry.data.slotIndex)
+	end
+	if parentName == "ZO_BuyBackListContents" then
+		return GetBuybackItemLink(item.dataEntry.data.slotIndex)
+	end
+	d("Could not get item link for " .. parentName)
+	return nil
+end
+
+function PriceTracker:GetItemLevel(itemLink)
+	local level = GetItemLinkRequiredLevel(itemLink)
+	if level == 50 then
+		level = level + GetItemLinkRequiredVeteranRank(itemLink)
+	end
+	return level
+end
+
 EVENT_MANAGER:RegisterForEvent("PriceTrackerLoaded", EVENT_ADD_ON_LOADED, function(...) PriceTracker:OnLoad(...) end)
diff --git a/PriceTracker.txt b/PriceTracker.txt
index bb32cfa..7c72a75 100644
--- a/PriceTracker.txt
+++ b/PriceTracker.txt
@@ -1,8 +1,8 @@
 ## Title: PriceTracker
 ## Author: Barvazon
-## Version: 1.9
+## Version: 2.0
 ## SavedVariables: PriceTrackerSettings
-## APIVersion: 100007
+## APIVersion: 100008
 ## OptionalDependsOn: LibAddonMenu-2.0

 PriceTracker.xml