From 0186060f708829198eda5878c5ee3542ad953099 Mon Sep 17 00:00:00 2001 From: Lag Date: Fri, 13 May 2022 11:32:32 +0200 Subject: [PATCH] add vendor prices into sources tt --- AtlasLootClassic/Addons/Sources.lua | 126 +++++++++++++++---- AtlasLootClassic/Button/Extra_Price_type.lua | 7 +- AtlasLootClassic/Constants.lua | 6 + AtlasLootClassic_Options/Addons.lua | 8 +- CHANGELOG.md | 2 + 5 files changed, 116 insertions(+), 33 deletions(-) diff --git a/AtlasLootClassic/Addons/Sources.lua b/AtlasLootClassic/Addons/Sources.lua index 34ed541f..92e8f82b 100644 --- a/AtlasLootClassic/Addons/Sources.lua +++ b/AtlasLootClassic/Addons/Sources.lua @@ -10,18 +10,26 @@ local Tooltip = AtlasLoot.Tooltip local Droprate = AtlasLoot.Data.Droprate local Profession = AtlasLoot.Data.Profession local Recipe = AtlasLoot.Data.Recipe +local VendorPrice = AtlasLoot.Data.VendorPrice -- lua local type = type local format = format +local str_split = string.split -- WoW +local GetCurrencyInfo, GetItemIcon = C_CurrencyInfo.GetCurrencyInfo, GetItemIcon + +-- AtlasLoot +local PRICE_INFO = VendorPrice.GetPriceInfoList() +local PRICE_ICON_REPLACE = ALPrivate.PRICE_ICON_REPLACE -- locals local TT_F = "%s |cFF00ccff%s|r" local DUMMY_ICON = "Interface\\Icons\\INV_Misc_QuestionMark" local TEXTURE_ICON_F, TEXTURE_ICON_FN, ATLAS_ICON_F = "|T%s:0|t ", "|T%d:0|t ", "|A:%s:0:0|a " +local TT_F_PRICE_T, TT_F_PRICE_TN = "|T%s:0|t|cFFffffff%s|r", "|T%d:0|t|cFFffffff%s|r" local RECIPE_ICON = format(TEXTURE_ICON_F, "134939") local ICON_TEXTURE = { [0] = format(TEXTURE_ICON_F, DUMMY_ICON), -- UNKNOWN @@ -66,6 +74,10 @@ local SOURCE_TYPES = { local SOURCE_DATA = {} local KEY_WEAK_MT = {__mode="k"} local AL_MODULE = "AtlasLootClassic_DungeonsAndRaids" +local PRICE_STRING_SPLIT_OR = "-" +local PRICE_STRING_SPLIT_AND = ":" +local PRICE_DELIMITER = " |cFFffffff&|r " +local PRICE_INFO_TT_START = format(TT_F.." ", ICON_TEXTURE[3], AL["Vendor:"]) local TooltipsHooked = false local TooltipCache, TooltipTextCache = {} @@ -77,6 +89,7 @@ Sources.DbDefaults = { showProfRank = true, showRecipeSource = true, showLineBreak = true, + showVendorPrices = true, ["Sources"] = { ["*"] = true, [16] = false, @@ -151,6 +164,42 @@ local function BuildSource(ini, boss, typ, item, isHeroic) return "" end +local function GetPriceToolTipString(icon, value) + if type(icon) == "number" then + return format(TT_F_PRICE_TN, icon, value) + else + return format(TT_F_PRICE_T, icon, value) + end +end + +local function GetPriceFormatString(priceList) + local fullString = PRICE_INFO_TT_START + for i = 1, #priceList, 2 do + local priceType, priceValue = priceList[i], priceList[i+1] + if i > 1 then fullString = fullString..PRICE_DELIMITER end + + if PRICE_INFO[priceType] then + if PRICE_INFO[priceType].func then + fullString = fullString..PRICE_INFO[priceType].func(priceValue) + elseif PRICE_INFO[priceType].icon then + fullString = fullString..GetPriceToolTipString(PRICE_INFO[priceType].icon, priceValue) + elseif PRICE_INFO[priceType].currencyID then + local info = GetCurrencyInfo(PRICE_INFO[priceType].currencyID) + if info then + fullString = fullString..GetPriceToolTipString(PRICE_ICON_REPLACE[priceType] or info.iconFileID, priceValue) + end + elseif PRICE_INFO[priceType].itemID then + PRICE_INFO[priceType].icon = GetItemIcon(PRICE_INFO[priceType].itemID) + fullString = fullString..GetPriceToolTipString(PRICE_INFO[priceType].icon, priceValue) + end + elseif tonumber(priceType) then + fullString = fullString..GetPriceToolTipString(GetItemIcon(priceType), priceValue) + end + end + + return fullString ~= PRICE_INFO_TT_START and fullString or nil +end + local function OnTooltipSetItem_Hook(self) if self:IsForbidden() or not SOURCE_DATA or not Sources.db.enabled then return end local _, item = self:GetItem() @@ -168,39 +217,62 @@ local function OnTooltipSetItem_Hook(self) end end - if item and sourceData then - if TooltipTextCache[item] ~= false then - if not TooltipTextCache[item] then - local iconTexture, baseItem - if type(sourceData.ItemData[item]) == "number" then - iconTexture = format(TEXTURE_ICON_FN, GetItemIcon(sourceData.ItemData[item])) - baseItem = sourceData.ItemData[item] - end - TooltipTextCache[item] = {} - if type(sourceData.ItemData[baseItem or item][1]) == "table" then - for i = 1, #sourceData.ItemData[baseItem or item] do - local data = sourceData.ItemData[baseItem or item][i] - if data[3] and Sources.db.Sources[data[3]] then - TooltipTextCache[item][i] = format(TT_F, iconTexture or ICON_TEXTURE[data[3] or 0], BuildSource(sourceData.AtlasLootIDs[data[1]], data[2], data[3], data[4] or baseItem or item, data[5])) - end - end - else - local data = sourceData.ItemData[baseItem or item] + if item then + local newAdded + -- sources from loot tables + if sourceData and TooltipTextCache[item] ~= false and not TooltipTextCache[item] then + local iconTexture, baseItem + if type(sourceData.ItemData[item]) == "number" then + iconTexture = format(TEXTURE_ICON_FN, GetItemIcon(sourceData.ItemData[item])) + baseItem = sourceData.ItemData[item] + end + TooltipTextCache[item] = {} + if type(sourceData.ItemData[baseItem or item][1]) == "table" then + for i = 1, #sourceData.ItemData[baseItem or item] do + local data = sourceData.ItemData[baseItem or item][i] if data[3] and Sources.db.Sources[data[3]] then - TooltipTextCache[item][1] = format(TT_F, iconTexture or ICON_TEXTURE[data[3] or 0], BuildSource(sourceData.AtlasLootIDs[data[1]], data[2], data[3], data[4] or baseItem or item, data[5])) + TooltipTextCache[item][i] = format(TT_F, iconTexture or ICON_TEXTURE[data[3] or 0], BuildSource(sourceData.AtlasLootIDs[data[1]], data[2], data[3], data[4] or baseItem or item, data[5])) end end - if #TooltipTextCache[item] < 1 then - TooltipTextCache[item] = false + else + local data = sourceData.ItemData[baseItem or item] + if data[3] and Sources.db.Sources[data[3]] then + TooltipTextCache[item][1] = format(TT_F, iconTexture or ICON_TEXTURE[data[3] or 0], BuildSource(sourceData.AtlasLootIDs[data[1]], data[2], data[3], data[4] or baseItem or item, data[5])) end end - if TooltipTextCache[item] then - if Sources.db.showLineBreak then - self:AddLine(" ") - end - for i = 1, #TooltipTextCache[item] do - self:AddLine(TooltipTextCache[item][i]) + if #TooltipTextCache[item] < 1 then + TooltipTextCache[item] = false + end + newAdded = true + end + + -- price sources + if Sources.db.showVendorPrices and (newAdded or not TooltipTextCache[item]) and VendorPrice.ItemHasVendorPrice(item) then + if not TooltipTextCache[item] then + TooltipTextCache[item] = {} + end + local priceString = VendorPrice.GetVendorPriceForItem(item) + -- split the price string into parts + local priceInfo = { str_split(PRICE_STRING_SPLIT_OR, priceString) } + if priceInfo[2] then + for i = 1, #priceInfo do + priceInfo[i] = { str_split(PRICE_STRING_SPLIT_AND, priceInfo[i]) } end + else + priceInfo = { { str_split(PRICE_STRING_SPLIT_AND, priceInfo[1]) } } + end + + for priceSumCount = 1, #priceInfo do + TooltipTextCache[item][ #TooltipTextCache[item] + 1 ] = GetPriceFormatString(priceInfo[priceSumCount]) + end + end + + if TooltipTextCache[item] then + if Sources.db.showLineBreak then + self:AddLine(" ") + end + for i = 1, #TooltipTextCache[item] do + self:AddLine(TooltipTextCache[item][i]) end end end diff --git a/AtlasLootClassic/Button/Extra_Price_type.lua b/AtlasLootClassic/Button/Extra_Price_type.lua index c23dfc5a..f8289e80 100644 --- a/AtlasLootClassic/Button/Extra_Price_type.lua +++ b/AtlasLootClassic/Button/Extra_Price_type.lua @@ -10,6 +10,7 @@ local GetCurrencyInfo, GetItemInfo, GetItemCount, GetItemIcon = C_CurrencyInfo.G -- ---------------------------------------------------------------------------- -- AddOn namespace. -- ---------------------------------------------------------------------------- +local ALName, ALPrivate = ... local AtlasLoot = _G.AtlasLoot local Price = AtlasLoot.Button:AddExtraType("Price") local AL = AtlasLoot.Locales @@ -31,11 +32,7 @@ local STRING_GREEN = "|cff1eff00" local PRICE_INFO = AtlasLoot.Data.VendorPrice.GetPriceInfoList() -local ICON_REPLACE = { - ["honor"] = UnitFactionGroup("player") == "Horde" and 136782 or 136781, - ["honorH"] = 136782, - ["honorA"] = 136781, -} +local ICON_REPLACE = ALPrivate.PRICE_ICON_REPLACE local Cache = {} setmetatable(Cache, {__mode = "kv"}) diff --git a/AtlasLootClassic/Constants.lua b/AtlasLootClassic/Constants.lua index bcf878d9..3e374a46 100644 --- a/AtlasLootClassic/Constants.lua +++ b/AtlasLootClassic/Constants.lua @@ -93,6 +93,12 @@ ALPrivate.CLASS_ICON_PATH = { DRUID = ICONS_PATH.."classicon_druid", } +ALPrivate.PRICE_ICON_REPLACE = { + ["honor"] = UnitFactionGroup("player") == "Horde" and 136782 or 136781, + ["honorH"] = 136782, + ["honorA"] = 136781, +} + ALPrivate.CLASS_BITS = { --NONE = 0, WARRIOR = 1, diff --git a/AtlasLootClassic_Options/Addons.lua b/AtlasLootClassic_Options/Addons.lua index f738228b..f5cf3780 100644 --- a/AtlasLootClassic_Options/Addons.lua +++ b/AtlasLootClassic_Options/Addons.lua @@ -367,10 +367,16 @@ local function CreateSourceOptions() width = "full", name = AL["Show recipe source if available."], }, - showLineBreak = { + showVendorPrices = { order = 5, type = "toggle", width = "full", + name = AL["Show vendor prices if available."], + }, + showLineBreak = { + order = 6, + type = "toggle", + width = "full", name = AL["Add line break before source."], }, typeSelection = { diff --git a/CHANGELOG.md b/CHANGELOG.md index a6863a7a..59f94391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,5 @@ This mod is distributed under Version 2 of the GPL. A copy of the GPL is includ [Changelog history](https://github.com/Hoizame/AtlasLootClassic/blob/master/AtlasLootClassic/Documentation/Release_Notes.md) ## v2.4.4 (May, XX, 2022) + +- add Vendor prices into tooltips