- 'Scan Prices' button is enabled only after the search cooldown is reached

Yaron Kfir [07-07-14 - 01:00]
 - 'Scan Prices' button is enabled only after the search cooldown is reached
Filename
Changelog
PriceTracker.lua
PriceTracker.txt
diff --git a/Changelog b/Changelog
index 56596fd..22f8966 100644
--- a/Changelog
+++ b/Changelog
@@ -1,9 +1,12 @@
 Changelog

+v1.8
+ - 'Scan Prices' button is enabled only after the search cooldown is reached
+
 v1.7
  - Indexing items by itemId rather than name
  - Using item level as a sub-index
-
+
 v1.6
  - Improved search algorithm to avoid trading house error messages
  - Properly changing guilds between searches to avoid error messages
diff --git a/PriceTracker.lua b/PriceTracker.lua
index 108d105..420e1b2 100644
--- a/PriceTracker.lua
+++ b/PriceTracker.lua
@@ -24,7 +24,9 @@ function PriceTracker:OnLoad(eventCode, addOnName)

 	EVENT_MANAGER:RegisterForEvent("OnSearchResultsReceived", EVENT_TRADING_HOUSE_SEARCH_RESULTS_RECEIVED, function(...) self:OnSearchResultsReceived(...) end)
 	EVENT_MANAGER:RegisterForEvent("OnSearchResultsError", EVENT_TRADING_HOUSE_ERROR, function(...) self:OnSearchResultsError(...) end)
+	EVENT_MANAGER:RegisterForEvent("OnTradingHouseOpened", EVENT_OPEN_TRADING_HOUSE, function(...) self:OnTradingHouseOpened(...) end)
 	EVENT_MANAGER:RegisterForEvent("OnTradingHouseClosed", EVENT_CLOSE_TRADING_HOUSE, function(...) self:OnTradingHouseClosed(...) end)
+	EVENT_MANAGER:RegisterForEvent("OnTradingHouseCooldown", EVENT_TRADING_HOUSE_SEARCH_COOLDOWN_UPDATE, function(...) self:OnTradingHouseCooldown(...) end)

 	LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_CLICKED_EVENT, PriceTracker.OnLinkClicked, self)

@@ -182,6 +184,10 @@ function PriceTracker:OnScanPrices()
 	zo_callLater(function() ExecuteTradingHouseSearch(0, TRADING_HOUSE_SORT_SALE_PRICE, true) end, GetTradingHouseCooldownRemaining() + 1000)
 end

+function PriceTracker:OnTradingHouseOpened(eventCode)
+	self.isSearching = false
+end
+
 function PriceTracker:OnSearchResultsReceived(eventId, guildId, numItemsOnPage, currentPage, hasMorePages)
 	if not self.isSearching then return end

@@ -208,16 +214,22 @@ function PriceTracker:OnSearchResultsReceived(eventId, guildId, numItemsOnPage,
 	end
 end

+function PriceTracker:OnTradingHouseCooldown(eventCode, cooldownMilliseconds)
+	self.button:SetEnabled(not self.isSearching)
+end
+
 function PriceTracker:OnSearchResultsError(eventCode, errorCode)
-	if not self.isSearching then return end
+	if errorCode == TRADING_HOUSE_RESULT_NOT_OPEN then
+		self.button:SetEnabled(not self.isSearching)
+		return
+	end

-	self:OnSearchResultsReceived(eventCode, self.currentGuild, 0, self.currentPage, false)
-	zo_callLater(function() ExecuteTradingHouseSearch(self.currentPage, TRADING_HOUSE_SORT_SALE_PRICE, true) end, GetTradingHouseCooldownRemaining() + 1000)
+	d("Error scanning prices.  Please try again.")
+	self:OnTradingHouseClosed()
 end

-function PriceTracker:OnTradingHouseClosed()
+function PriceTracker:OnTradingHouseClosed(eventCode)
 	self.isSearching = false
-	self.button:SetEnabled(true)
 end

 function PriceTracker:OnLinkClicked(rawLink, mouseButton, linkText, color, linkType, itemId, ...)
diff --git a/PriceTracker.txt b/PriceTracker.txt
index da2dbf3..3c1b8ca 100644
--- a/PriceTracker.txt
+++ b/PriceTracker.txt
@@ -1,6 +1,6 @@
 ## Title: PriceTracker
 ## Author: Barvazon
-## Version: 1.7
+## Version: 1.8
 ## SavedVariables: PriceTrackerSettings
 ## APIVersion: 100007
 ## OptionalDependsOn: LibAddonMenu-2.0