Quantcast

Search and red stuff. This closes #300

Darthpred [08-23-16 - 18:07]
Search and red stuff. This closes #300
Filename
ElvUI_SLE/skins/blizzard/merchant.lua
ElvUI_SLE/skins/blizzard/merchantList.lua
diff --git a/ElvUI_SLE/skins/blizzard/merchant.lua b/ElvUI_SLE/skins/blizzard/merchant.lua
index 962069f..a5e59d1 100644
--- a/ElvUI_SLE/skins/blizzard/merchant.lua
+++ b/ElvUI_SLE/skins/blizzard/merchant.lua
@@ -1,8 +1,9 @@
 local SLE, T, E, L, V, P, G = unpack(select(2, ...))
 local Sk = SLE:GetModule("Skins")
 local S = E:GetModule('Skins')
---GLOBALS: CreateFrame, MERCHANT_ITEMS_PER_PAGE, BUYBACK_ITEMS_PER_PAGE, hooksecurefunc, MERCHANT_PAGE_NUMBER
+--GLOBALS: CreateFrame, MERCHANT_ITEMS_PER_PAGE, BUYBACK_ITEMS_PER_PAGE, hooksecurefunc, MERCHANT_PAGE_NUMBER, UIParent, ChatFontSmall
 local _G = _G
+local strtrim = strtrim
 local ItemsPerSubpage, SubpagesPerPage
 local math_max, math_ceil = math.max, math.ceil
 local MerchantFrame_UpdateAltCurrency, MoneyFrame_Update = MerchantFrame_UpdateAltCurrency, MoneyFrame_Update
@@ -11,6 +12,13 @@ local GetMerchantItemInfo, GetMerchantItemLink = GetMerchantItemInfo, GetMerchan
 local SetItemButtonCount, SetItemButtonStock, SetItemButtonTexture = SetItemButtonCount, SetItemButtonStock, SetItemButtonTexture
 local SetItemButtonNameFrameVertexColor, SetItemButtonSlotVertexColor, SetItemButtonTextureVertexColor, SetItemButtonNormalTextureVertexColor = SetItemButtonNameFrameVertexColor, SetItemButtonSlotVertexColor, SetItemButtonTextureVertexColor, SetItemButtonNormalTextureVertexColor

+local RETRIEVING_ITEM_INFO, RETRIEVING_ITEM_INFO, MOUNT, ITEM_SPELL_KNOWN, SEARCH = RETRIEVING_ITEM_INFO, RETRIEVING_ITEM_INFO, MOUNT, ITEM_SPELL_KNOWN, SEARCH
+local MISCELLANEOUS = MISCELLANEOUS
+
+local RECIPE = GetItemClassInfo(LE_ITEM_CLASS_RECIPE)
+local searchBox
+local searching = ""
+
 local IgnoreCurrency = {
 	[T.GetCurrencyInfo(994)] = true,
 }
@@ -40,9 +48,11 @@ local function UpdateButtonsPositions(isBuyBack)
 	if (isBuyBack) then
 		vertSpacing = -30
 		horizSpacing = 50
+		searchBox:Hide()
 	else
 		vertSpacing = -16
 		horizSpacing = 12
+		searchBox:Show()
 	end
 	for i = 1, MERCHANT_ITEMS_PER_PAGE do
 		btn = _G["MerchantItem" .. i]
@@ -96,6 +106,38 @@ local function UpdateBuybackInfo()
 	end
 end

+local function isKnown(link, itemType, itemSubType)
+	if ( not link ) then
+		return false;
+	end
+	local upperLimit
+	local isMount = false
+	local isRecipe = false
+	if itemType == RECIPE then
+		isRecipe = true
+	elseif itemType == MISCELLANEOUS and itemSubType == MOUNT then
+		isMount = true
+	end
+
+	_G["SLE_Merchant_HiddenTooltip"]:SetOwner(UIParent, "ANCHOR_NONE");
+	_G["SLE_Merchant_HiddenTooltip"]:SetHyperlink(link);
+	upperLimit = isRecipe and _G["SLE_Merchant_HiddenTooltip"]:NumLines() - 1 or 0
+
+	for i=2, _G["SLE_Merchant_HiddenTooltip"]:NumLines() do
+		if (isRecipe and (i <= 5 or i == upperLimit)) or isMount or not isRecipe then
+			local text = _G["SLE_Merchant_HiddenTooltipTextLeft"..i];
+			local r, g, b = text:GetTextColor();
+			local gettext = text:GetText();
+
+			if ( gettext and r >= 0.9 and g <= 0.2 and b <= 0.2 and gettext ~= RETRIEVING_ITEM_INFO ) then
+				if gettext == ITEM_SPELL_KNOWN then return true end
+			end
+		end
+	end
+
+	return false
+end
+
 local function UpdateMerchantInfo()
 	UpdateButtonsPositions()

@@ -189,9 +231,24 @@ local function UpdateMerchantInfo()
 					slotColor = {r = 1.0, g = 0, b = 0};
 					detailColor = {r = 1.0, g = 0, b = 0};
 				else
-					slotColor = {r = 1.0, g = 1.0, b = 1.0};
-					detailColor = {r = 0.5, g = 0.5, b = 0.5};
+					-- print(itemType)
+					if not isKnown(itemButton.link, itemType, itemSubType) then
+						slotColor = {r = 1.0, g = 1.0, b = 1.0};
+						detailColor = {r = 0.5, g = 0.5, b = 0.5};
+					else
+						slotColor = {r = 1.0, g = 0, b = 0};
+						detailColor = {r = 1.0, g = 0, b = 0};
+					end
 				end
+				local alpha = 0.3;
+				if ( searching == "" or searching == SEARCH:lower() or name:lower():match(searching)
+					or ( quality and ( T.tostring(quality):lower():match(searching) or _G["ITEM_QUALITY"..T.tostring(quality).."_DESC"]:lower():match(searching) ) )
+					or ( itemType and itemType:lower():match(searching) )
+					or ( itemSubType and itemSubType:lower():match(searching) )
+					) then
+					alpha = 1;
+				end
+				merchantButton:SetAlpha(alpha);
 				SetItemButtonNameFrameVertexColor(merchantButton, detailColor.r * colorMult, detailColor.g * colorMult, detailColor.b * colorMult);
 				SetItemButtonSlotVertexColor(merchantButton, slotColor.r * colorMult, slotColor.g * colorMult, slotColor.b * colorMult);
 				SetItemButtonTextureVertexColor(itemButton, slotColor.r * colorMult, slotColor.g * colorMult, slotColor.b * colorMult);
@@ -241,6 +298,32 @@ local function RebuildMerchantFrame()
 	_G["MerchantExtraCurrencyBg"]:ClearAllPoints();
 	_G["MerchantExtraCurrencyBg"]:SetPoint("TOPLEFT", _G["MerchantExtraCurrencyInset"], "TOPLEFT", 3, -2);
 	_G["MerchantExtraCurrencyBg"]:SetPoint("BOTTOMRIGHT", _G["MerchantExtraCurrencyInset"], "BOTTOMRIGHT", -3, 2);
+
+	searchBox = CreateFrame("EditBox", "$parentSearchBox", _G["MerchantFrame"], "InputBoxTemplate");
+	searchBox:SetWidth(_G["MerchantItem1"]:GetWidth());
+	searchBox:SetHeight(24);
+	searchBox:SetPoint("BOTTOMLEFT", _G["MerchantItem1"], "TOPLEFT", 0, 9);
+	searchBox:SetAutoFocus(false);
+	searchBox:SetFontObject(ChatFontSmall);
+	searchBox:SetScript("OnTextChanged", function(self) searching = self:GetText():trim():lower(); UpdateMerchantInfo() end)
+	searchBox:SetScript("OnShow", function(self) self:SetText(SEARCH); searching = "" end)
+	searchBox:SetScript("OnEnterPressed", function(self)  self:ClearFocus() end)
+	searchBox:SetScript("OnEscapePressed", function(self)  self:ClearFocus(); self:SetText(SEARCH); searching = "" end)
+	searchBox:SetScript("OnEditFocusLost", function(self)
+		self:HighlightText(0, 0);
+		if ( strtrim(self:GetText()) == "" ) then
+			self:SetText(SEARCH);
+			searching = "";
+		end
+	end)
+	searchBox:SetScript("OnEditFocusGained", function(self)
+		self:HighlightText();
+		if ( self:GetText():trim():lower() == SEARCH:lower() ) then
+			self:SetText("");
+		end
+	end)
+	searchBox:SetText(SEARCH);
+	S:HandleEditBox(searchBox)
 end

 local function MerchantSkinInit()
@@ -249,6 +332,7 @@ local function MerchantSkinInit()
 	if E.private.sle.skins.merchant.style ~= "Default" then return end
 	RebuildMerchantFrame()
 	UpdateButtonsPositions()
+	CreateFrame("GameTooltip", "SLE_Merchant_HiddenTooltip", UIParent, "GameTooltipTemplate");

 	hooksecurefunc("MerchantFrame_UpdateMerchantInfo", UpdateMerchantInfo)
 end
diff --git a/ElvUI_SLE/skins/blizzard/merchantList.lua b/ElvUI_SLE/skins/blizzard/merchantList.lua
index 561cef3..59490a5 100644
--- a/ElvUI_SLE/skins/blizzard/merchantList.lua
+++ b/ElvUI_SLE/skins/blizzard/merchantList.lua
@@ -28,6 +28,7 @@ local MAX_ITEM_COST = MAX_ITEM_COST
 local RETRIEVING_ITEM_INFO = RETRIEVING_ITEM_INFO
 local ITEM_SPELL_KNOWN = ITEM_SPELL_KNOWN
 local NUM_BAG_SLOTS = NUM_BAG_SLOTS
+local MISCELLANEOUS, MOUNT = MISCELLANEOUS, MOUNT

 local RECIPE = GetItemClassInfo(LE_ITEM_CLASS_RECIPE)

@@ -195,7 +196,7 @@ local function ListItem_OnHide()
 	T.twipe(currencies);
 end

-local function List_GetError(link, isRecipe)
+local function List_GetError(link, itemType, itemSubType)
 	if ( not link ) then
 		return false;
 	end
@@ -205,65 +206,77 @@ local function List_GetError(link, isRecipe)
 	if ( errors[id] ) then
 		return errors[id];
 	end
+	local upperLimit
+	local isMount = false
+	local isRecipe = false
+	if itemType == RECIPE then
+		isRecipe = true
+	elseif itemType == MISCELLANEOUS and itemSubType == MOUNT then
+		isMount = true
+	end
+	local errormsg = "";

-	_G["GameTooltip"]:SetOwner(UIParent, "ANCHOR_NONE");
-	_G["GameTooltip"]:SetHyperlink(link);
+	_G["SLE_Merchant_HiddenTooltip"]:SetOwner(UIParent, "ANCHOR_NONE");
+	_G["SLE_Merchant_HiddenTooltip"]:SetHyperlink(link);
+	upperLimit = isRecipe and _G["SLE_Merchant_HiddenTooltip"]:NumLines() - 1 or 0

-	local errormsg = "";
-	for i=2, _G["GameTooltip"]:NumLines() do
-		local text = _G["GameTooltipTextLeft"..i];
-		local r, g, b = text:GetTextColor();
-		local gettext = text:GetText();
-		if ( gettext and r >= 0.9 and g <= 0.2 and b <= 0.2 and gettext ~= RETRIEVING_ITEM_INFO ) then
-			if ( errormsg ~= "" ) then
-				errormsg = errormsg..", ";
-			end
+	for i=2, _G["SLE_Merchant_HiddenTooltip"]:NumLines() do
+		if (isRecipe and (i <= 5 or i == upperLimit)) or isMount or not isRecipe then
+			local text = _G["SLE_Merchant_HiddenTooltipTextLeft"..i];
+			local r, g, b = text:GetTextColor();
+			local gettext = text:GetText();
+			if ( gettext and r >= 0.9 and g <= 0.2 and b <= 0.2 and gettext ~= RETRIEVING_ITEM_INFO ) then
+				if ( errormsg ~= "" ) then
+					errormsg = errormsg..", ";
+				end

-			local level = gettext:match(REQUIRES_LEVEL);
-			if ( level ) then
-				errormsg = errormsg..LEVEL:format(level);
-			end
+				local level = gettext:match(REQUIRES_LEVEL);
+				if ( level ) then
+					errormsg = errormsg..LEVEL:format(level);
+				end

-			local reputation, factionName = T.match(gettext, REQUIRES_REPUTATION);
-			if ( reputation ) then
-				errormsg = errormsg..reputation;
-				if not factionName then factionName = gettext:match(REQUIRES_REPUTATION_NAME); end
-				if ( factionName ) then
-						errormsg = errormsg.." ("..factionName..")";
+				local reputation, factionName = T.match(gettext, REQUIRES_REPUTATION);
+				if ( reputation ) then
+					errormsg = errormsg..reputation;
+					if not factionName then factionName = gettext:match(REQUIRES_REPUTATION_NAME); end
+					if ( factionName ) then
+							errormsg = errormsg.." ("..factionName..")";
+					end
 				end
-			end

-			local skill, slevel = gettext:match(REQUIRES_SKILL);
-			if ( skill and slevel ) then
-				errormsg = errormsg..SKILL:format(skill, slevel);
-			end
+				local skill, slevel = gettext:match(REQUIRES_SKILL);
+				if ( skill and slevel ) then
+					errormsg = errormsg..SKILL:format(skill, slevel);
+				end

-			local requires = gettext:match(REQUIRES);
-			if ( not level and not reputation and not skill and requires ) then
-				errormsg = errormsg..requires;
-			end
+				local requires = gettext:match(REQUIRES);
+				if ( not level and not reputation and not skill and requires ) then
+					errormsg = errormsg..requires;
+				end

-			if ( not level and not reputation and not skill and not requires ) then
-				if ( errormsg ~= "" ) then
-					errormsg = gettext..", "..errormsg;
-				else
-					errormsg = errormsg..gettext;
+				local known = gettext == ITEM_SPELL_KNOWN and true or false
+				if known then
+					errormsg = errormsg..ITEM_SPELL_KNOWN
 				end
-			end
-		end

-		local text = _G["GameTooltipTextRight"..i];
-		local r, g, b = text:GetTextColor();
-		local gettext = text:GetText();
-		if ( gettext and r >= 0.9 and g <= 0.2 and b <= 0.2 ) then
-			if ( errormsg ~= "" ) then
-				errormsg = errormsg..", ";
+				if ( not level and not reputation and not skill and not requires and not known) then
+					if ( errormsg ~= "" ) then
+						errormsg = gettext..", "..errormsg;
+					else
+						errormsg = errormsg..gettext;
+					end
+				end
 			end
-			errormsg = errormsg..gettext;
-		end

-		if ( isRecipe and i == 5 ) then
-			break;
+			local text = _G["SLE_Merchant_HiddenTooltipTextRight"..i];
+			local r, g, b = text:GetTextColor();
+			local gettext = text:GetText();
+			if ( gettext and r >= 0.9 and g <= 0.2 and b <= 0.2 ) then
+				if ( errormsg ~= "" ) then
+					errormsg = errormsg..", ";
+				end
+				errormsg = errormsg..gettext;
+			end
 		end
 	end

@@ -398,29 +411,6 @@ local function List_UpdateAltCurrency(button, index, i)
 	end
 end

-local function List_GetKnown(link)
-	if ( not link ) then
-		return false;
-	end
-
-	local id = link:match("item:(%d+)");
-	if ( knowns[id] ) then
-		return true;
-	end
-
-	_G["GameTooltip"]:SetOwner(UIParent, "ANCHOR_NONE");
-	_G["GameTooltip"]:SetHyperlink(link);
-
-	for i=1, _G["GameTooltip"]:NumLines() do
-		if ( _G["GameTooltipTextLeft"..i]:GetText() == ITEM_SPELL_KNOWN ) then
-			knowns[id] = true;
-			return true;
-		end
-	end
-
-	return false;
-end
-
 local function List_MerchantUpdate()
 	local self = _G["SLE_ListMerchantFrame"]
 	local numMerchantItems = GetMerchantNumItems();
@@ -502,21 +492,20 @@ local function List_MerchantUpdate()
 				button.highlight:SetVertexColor(1, 0.2, 0.2, 0.5);
 				button.highlight:Show();
 				button.isShown = 1;
-
-				local errors = List_GetError(link, itemType and itemType == RECIPE);
+
+				local errors = List_GetError(link, itemType, itemSubType);
 				if ( errors ) then
 					button.iteminfo:SetText("|cffd00000"..subtext.." - "..errors.."|r");
 				end
-			elseif ( itemType and itemType == RECIPE and not List_GetKnown(link) ) then
-				button.highlight:SetVertexColor(0.2, 1, 0.2, 0.5);
-				button.highlight:Show();
-				button.isShown = 1;
 			else
 				button.highlight:SetVertexColor(r, g, b, 0.5);
 				button.highlight:Hide();
 				button.isShown = nil;
-				local errors = List_GetError(link, itemType and itemType == RECIPE);
+				local errors = List_GetError(link, itemType, itemSubType);
 				if ( errors ) then
+					button.highlight:SetVertexColor(1, 0.2, 0.2, 0.5);
+					button.highlight:Show();
+					button.isShown = 1;
 					button.iteminfo:SetText("|cffd00000"..subtext.." - "..errors.."|r");
 				end
 			end
@@ -744,6 +733,7 @@ local function MerchantListSkinInit()
 	if not locale[GetLocale()] then
 		SLE:ErrorPrint("Your language is unavailable for selected merchant style. We would appretiate if ou contact us and provide needed translations.")
 	end
+	CreateFrame("GameTooltip", "SLE_Merchant_HiddenTooltip", UIParent, "GameTooltipTemplate");
 end

 hooksecurefunc(S, "Initialize", MerchantListSkinInit)
\ No newline at end of file