From 90647f9e46e86053aade21b8430f04aac324decc Mon Sep 17 00:00:00 2001 From: BenDol Date: Sat, 16 Jun 2018 08:37:31 +1200 Subject: [PATCH] eqcompare: compare basic stats on items --- api/api.lua | 10 ++++++ modules/actionbar.lua | 2 +- modules/eqcompare.lua | 83 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/api/api.lua b/api/api.lua index 83ab278b..ddafc38c 100644 --- a/api/api.lua +++ b/api/api.lua @@ -310,6 +310,16 @@ function pfUI.api.hooksecurefunc(name, func, append) _G[name] = pfUI.hooks[tostring(func)]["function"] end +function pfUI.api.HookScript(f, script, func) + local prev = f:GetScript(script) + + f:SetScript(script, function(...) + if prev then prev() end + + func() + end) +end + -- [ QueueFunction ] -- Add functions to a FIFO queue for execution after a short delay. -- '...' [vararg] function, [arguments] diff --git a/modules/actionbar.lua b/modules/actionbar.lua index f497a00d..59d8d08f 100644 --- a/modules/actionbar.lua +++ b/modules/actionbar.lua @@ -563,7 +563,7 @@ pfUI:RegisterModule("actionbar", function () icon:SetTexCoord(.08, .92, .08, .92) local texture = _G["PetActionButton"..i..'NormalTexture2'] - texture :SetAlpha(0) + texture:SetAlpha(0) local castable = _G["PetActionButton"..i..'AutoCastable'] if C.bars.showcastable == "1" then diff --git a/modules/eqcompare.lua b/modules/eqcompare.lua index 125c3318..a7476c1d 100644 --- a/modules/eqcompare.lua +++ b/modules/eqcompare.lua @@ -40,6 +40,16 @@ pfUI:RegisterModule("eqcompare", function () [INVTYPE_THROWN] = "RangedSlot", } + HookScript(ShoppingTooltip1, "OnShow", function() + local targetData = pfUI.eqcompare:ExtractAttributes(ShoppingTooltip1) + pfUI.eqcompare:CompareAttributes(ShoppingTooltip1._data, targetData) + end) + + HookScript(ShoppingTooltip2, "OnShow", function() + local targetData = pfUI.eqcompare:ExtractAttributes(ShoppingTooltip2) + pfUI.eqcompare:CompareAttributes(ShoppingTooltip2._data, targetData) + end) + pfUI.eqcompare = CreateFrame( "Frame" , "pfEQCompare", GameTooltip ) pfUI.eqcompare.ShowCompare = function(tooltip) -- use GameTooltip as default @@ -49,6 +59,10 @@ pfUI:RegisterModule("eqcompare", function () return end + local data = pfUI.eqcompare:ExtractAttributes(tooltip) + ShoppingTooltip1._data = data + ShoppingTooltip2._data = data + local border = tonumber(C.appearance.border.default) for i=1,tooltip:NumLines() do @@ -93,10 +107,77 @@ pfUI:RegisterModule("eqcompare", function () ShoppingTooltip2:SetInventoryItem("player", slotID_other) ShoppingTooltip2:Show(); end - + return true end end end end pfUI.eqcompare:SetScript("OnShow", pfUI.eqcompare.ShowCompare) + + local function startsWith(str, start) + return string.sub(str, 1, string.len(start)) == start + end + + function pfUI.eqcompare:ExtractAttributes(tooltip) + local name = tooltip:GetName() + local data = {} + for i=1,30 do + local widget = _G[name.."TextLeft"..i] + if widget and widget:GetObjectType() == "FontString" then + local text = widget:GetText() + if text and not string.find(text, "-", 1, true) then + local start = 1 + if startsWith(text, "\+") or startsWith(text, "\(") then start = 2 end + + local space = string.find(text, " ", 1, true) + if space then + local value = tonumber(string.sub(text, start, space-1)) + if value and text then + -- we've found an attr + local attr = string.sub(text, space, string.len(text)) + data[attr] = { value = tonumber(value), widget = widget } + end + end + end + end + end + return data + end + + function pfUI.eqcompare:CompareAttributes(data, targetData) + if not data then return end + for attr,v in pairs(data) do + if targetData then + local target = targetData[attr] + if target then + if v.value ~= target.value then + if v.value > target.value then + target.widget:SetTextColor(2.55, .08, .08) + v.widget:SetTextColor(.2, 2.4, 0) + else + v.widget:SetTextColor(2.55, .08, .08) + target.widget:SetTextColor(.2, 2.4, 0) + end + target.processed = true + else + target.processed = true + end + else + -- this attribute doesnt exist in target + v.widget:SetTextColor(.2, 2.4, 0) + end + else + -- nothing to compare + v.widget:SetTextColor(.2, 2.4, 0) + end + end + + for _,target in pairs(targetData) do + if target and not target.processed then + -- we are an extra value + target.widget:SetTextColor(.2, 2.4, 0) + end + end + end + end)