Skip to content

Commit

Permalink
add vendor prices into sources tt
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoizame committed May 13, 2022
1 parent 3f79288 commit 0186060
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 33 deletions.
126 changes: 99 additions & 27 deletions AtlasLootClassic/Addons/Sources.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}
Expand All @@ -77,6 +89,7 @@ Sources.DbDefaults = {
showProfRank = true,
showRecipeSource = true,
showLineBreak = true,
showVendorPrices = true,
["Sources"] = {
["*"] = true,
[16] = false,
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
7 changes: 2 additions & 5 deletions AtlasLootClassic/Button/Extra_Price_type.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"})
Expand Down
6 changes: 6 additions & 0 deletions AtlasLootClassic/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion AtlasLootClassic_Options/Addons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0186060

Please sign in to comment.