initial commit

This commit is contained in:
Gitea
2020-11-13 14:13:12 -05:00
commit 05df49ff60
368 changed files with 128754 additions and 0 deletions

View File

@@ -0,0 +1,153 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Accounting = TSM.Tooltip:NewPackage("Accounting")
local L = TSM.Include("Locale").GetTable()
local Math = TSM.Include("Util.Math")
local ItemString = TSM.Include("Util.ItemString")
local CustomPrice = TSM.Include("Service.CustomPrice")
local private = {}
-- ============================================================================
-- Module Functions
-- ============================================================================
function Accounting.OnInitialize()
TSM.Tooltip.Register(TSM.Tooltip.CreateInfo()
:SetHeadings(L["TSM Accounting"])
:SetSettingsModule("Accounting")
:AddSettingEntry("purchase", true, private.PopulatePurchaseLines)
:AddSettingEntry("sale", true, private.PopulateSaleLines)
:AddSettingEntry("saleRate", false, private.PopulateSaleRateLine)
:AddSettingEntry("expiredAuctions", false, private.PopulateExpireLine)
:AddSettingEntry("cancelledAuctions", false, private.PopulateCancelLine)
)
end
-- ============================================================================
-- Private Helper Functions
-- ============================================================================
function private.PopulateSaleLines(tooltip, itemString)
local showTotals = itemString ~= ItemString.GetPlaceholder() and IsShiftKeyDown()
local avgSalePrice, totalSaleNum, lastSaleTime, minSellPrice, maxSellPrice = nil, nil, nil, nil, nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
avgSalePrice = 20
totalSaleNum = 5
lastSaleTime = time() - 60
minSellPrice = 10
maxSellPrice = 50
else
local totalPrice = nil
totalPrice, totalSaleNum = TSM.Accounting.Transactions.GetSaleStats(itemString)
if not totalSaleNum then
return
end
avgSalePrice = totalPrice and Math.Round(totalPrice / totalSaleNum) or nil
lastSaleTime = TSM.Accounting.Transactions.GetLastSaleTime(itemString)
if not showTotals then
minSellPrice = CustomPrice.GetItemPrice(itemString, "MinSell") or 0
maxSellPrice = CustomPrice.GetItemPrice(itemString, "MaxSell") or 0
end
end
if showTotals then
tooltip:AddQuantityValueLine(L["Sold (Total Price)"], totalSaleNum, avgSalePrice * totalSaleNum)
else
assert(minSellPrice and maxSellPrice)
tooltip:AddQuantityValueLine(L["Sold (Min/Avg/Max Price)"], totalSaleNum, minSellPrice, avgSalePrice, maxSellPrice)
end
tooltip:AddTextLine(L["Last Sold"], format(L["%s ago"], SecondsToTime(time() - lastSaleTime)))
end
function private.PopulateExpireLine(tooltip, itemString)
local expiredNum = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
expiredNum = 2
else
local lastSaleTime = TSM.Accounting.Transactions.GetLastSaleTime(itemString)
expiredNum = select(2, TSM.Accounting.Auctions.GetStats(itemString, lastSaleTime))
if expiredNum == 0 then
expiredNum = nil
end
end
if expiredNum then
tooltip:AddTextLine(L["Expired Since Last Sale"], expiredNum)
end
end
function private.PopulateCancelLine(tooltip, itemString)
local cancelledNum = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
cancelledNum = 2
else
local lastSaleTime = TSM.Accounting.Transactions.GetLastSaleTime(itemString)
cancelledNum = TSM.Accounting.Auctions.GetStats(itemString, lastSaleTime)
if cancelledNum == 0 then
cancelledNum = nil
end
end
if cancelledNum then
tooltip:AddTextLine(L["Cancelled Since Last Sale"], cancelledNum)
end
end
function private.PopulateSaleRateLine(tooltip, itemString)
local saleRate = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
saleRate = 0.7
else
saleRate = CustomPrice.GetItemPrice(itemString, "SaleRate")
if not saleRate then
return
end
end
tooltip:AddTextLine(L["Sale Rate"], saleRate)
end
function private.PopulatePurchaseLines(tooltip, itemString)
local showTotals = itemString ~= ItemString.GetPlaceholder() and IsShiftKeyDown()
local smartAvgPrice, totalPrice, totalNum, minPrice, maxPrice, lastBuyTime = nil, nil, nil, nil, nil, nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
smartAvgPrice = 25
totalPrice = 78
totalNum = 3
minPrice = 15
maxPrice = 55
lastBuyTime = time() - 3600
else
smartAvgPrice = CustomPrice.GetItemPrice(itemString, "SmartAvgBuy")
totalPrice, totalNum = TSM.Accounting.Transactions.GetBuyStats(itemString, false)
if not totalPrice then
return
end
if not showTotals then
minPrice = CustomPrice.GetItemPrice(itemString, "MinBuy") or 0
maxPrice = CustomPrice.GetItemPrice(itemString, "MaxBuy") or 0
end
lastBuyTime = TSM.Accounting.Transactions.GetLastBuyTime(itemString)
end
if showTotals then
tooltip:AddQuantityValueLine(L["Purchased (Total Price)"], totalNum, totalPrice)
else
assert(minPrice and maxPrice)
tooltip:AddQuantityValueLine(L["Purchased (Min/Avg/Max Price)"], totalNum, minPrice, Math.Round(totalPrice / totalNum), maxPrice)
end
tooltip:AddValueLine(L["Smart Avg Buy Price"], smartAvgPrice)
tooltip:AddTextLine(L["Last Purchased"], format(L["%s ago"], SecondsToTime(time() - lastBuyTime)))
end

View File

@@ -0,0 +1,84 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local AuctionDB = TSM.Tooltip:NewPackage("AuctionDB")
local L = TSM.Include("Locale").GetTable()
local ItemString = TSM.Include("Util.ItemString")
local Theme = TSM.Include("Util.Theme")
local private = {}
local INFO = {
{ key = "minBuyout", default = true, label = L["Min Buyout"] },
{ key = "marketValue", default = true, label = L["Market Value"] },
{ key = "historical", default = false, label = L["Historical Price"] },
{ key = "regionMinBuyout", default = false, label = L["Region Min Buyout Avg"] },
{ key = "regionMarketValue", default = true, label = L["Region Market Value Avg"] },
{ key = "regionHistorical", default = false, label = L["Region Historical Price"] },
{ key = "regionSale", default = true, label = L["Region Sale Avg"] },
{ key = "regionSalePercent", default = true, label = L["Region Sale Rate"] },
{ key = "regionSoldPerDay", default = true, label = L["Region Avg Daily Sold"] },
}
local DATA_OLD_THRESHOLD_SECONDS = 60 * 60 * 3
-- ============================================================================
-- Module Functions
-- ============================================================================
function AuctionDB.OnInitialize()
local tooltipInfo = TSM.Tooltip.CreateInfo()
:SetHeadings(L["TSM AuctionDB"], private.PopulateRightText)
:SetSettingsModule("AuctionDB")
for _, info in ipairs(INFO) do
tooltipInfo:AddSettingEntry(info.key, info.default, private.PopulateLine, info)
end
TSM.Tooltip.Register(tooltipInfo)
end
-- ============================================================================
-- Private Helper Functions
-- ============================================================================
function private.PopulateLine(tooltip, itemString, info)
local value = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
value = 11
elseif strmatch(info.key, "^region") then
value = TSM.AuctionDB.GetRegionItemData(itemString, info.key)
else
value = TSM.AuctionDB.GetRealmItemData(itemString, info.key)
end
if value then
if info.key == "regionSalePercent" or info.key == "regionSoldPerDay" then
tooltip:AddTextLine(info.label, format("%0.2f", value/100))
else
tooltip:AddItemValueLine(info.label, value)
end
end
end
function private.PopulateRightText(tooltip, itemString)
local lastScan, numAuctions = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
lastScan = time() - 120
numAuctions = 5
else
lastScan = TSM.AuctionDB.GetRealmItemData(itemString, "lastScan")
numAuctions = TSM.AuctionDB.GetRealmItemData(itemString, "numAuctions") or 0
end
if lastScan then
local timeColor = (time() - lastScan) > DATA_OLD_THRESHOLD_SECONDS and Theme.GetFeedbackColor("RED") or Theme.GetFeedbackColor("GREEN")
local timeDiff = SecondsToTime(time() - lastScan)
return tooltip:ApplyValueColor(format(L["%d auctions"], numAuctions)).." ("..timeColor:ColorText(format(L["%s ago"], timeDiff))..")"
else
return tooltip:ApplyValueColor(L["Not Scanned"])
end
end

View File

@@ -0,0 +1,79 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Auctioning = TSM.Tooltip:NewPackage("Auctioning")
local L = TSM.Include("Locale").GetTable()
local ItemString = TSM.Include("Util.ItemString")
local ItemInfo = TSM.Include("Service.ItemInfo")
local private = {}
-- ============================================================================
-- Module Functions
-- ============================================================================
function Auctioning.OnInitialize()
TSM.Tooltip.Register(TSM.Tooltip.CreateInfo()
:SetHeadings(L["TSM Auctioning"])
:SetSettingsModule("Auctioning")
:AddSettingEntry("postQuantity", false, private.PopulatePostQuantityLine)
:AddSettingEntry("operationPrices", false, private.PopulatePricesLine)
)
end
-- ============================================================================
-- Private Helper Functions
-- ============================================================================
function private.PopulatePostQuantityLine(tooltip, itemString)
local postCap, stackSize = nil, nil
if itemString == ItemString.GetPlaceholder() then
postCap = 5
stackSize = TSM.IsWowClassic() and 200
elseif ItemInfo.IsSoulbound(itemString) then
return
else
itemString = TSM.Groups.TranslateItemString(itemString)
local _, operation = TSM.Operations.GetFirstOperationByItem("Auctioning", itemString)
if not operation then
return
end
postCap = TSM.Auctioning.Util.GetPrice("postCap", operation, itemString)
stackSize = TSM.IsWowClassic() and TSM.Auctioning.Util.GetPrice("stackSize", operation, itemString)
end
if TSM.IsWowClassic() then
tooltip:AddTextLine(L["Post Quantity"], postCap and stackSize and postCap.."x"..stackSize or "---")
else
tooltip:AddTextLine(L["Post Quantity"], postCap or "---")
end
end
function private.PopulatePricesLine(tooltip, itemString)
local minPrice, normalPrice, maxPrice = nil, nil, nil
if itemString == ItemString.GetPlaceholder() then
minPrice = 20
normalPrice = 24
maxPrice = 29
elseif ItemInfo.IsSoulbound(itemString) then
return
else
itemString = TSM.Groups.TranslateItemString(itemString)
local _, operation = TSM.Operations.GetFirstOperationByItem("Auctioning", itemString)
if not operation then
return
end
minPrice = TSM.Auctioning.Util.GetPrice("minPrice", operation, itemString)
normalPrice = TSM.Auctioning.Util.GetPrice("normalPrice", operation, itemString)
maxPrice = TSM.Auctioning.Util.GetPrice("maxPrice", operation, itemString)
end
tooltip:AddValueLine(L["Min/Normal/Max Prices"], minPrice, normalPrice, maxPrice)
end

View File

@@ -0,0 +1,275 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Tooltip = TSM:NewPackage("Tooltip")
local ItemString = TSM.Include("Util.ItemString")
local ObjectPool = TSM.Include("Util.ObjectPool")
local ItemTooltip = TSM.Include("Service.ItemTooltip")
local Settings = TSM.Include("Service.Settings")
local LibTSMClass = TSM.Include("LibTSMClass")
local TooltipInfo = LibTSMClass.DefineClass("TooltipInfo")
local TooltipEntry = LibTSMClass.DefineClass("TooltipEntry")
local private = {
entryObjPool = ObjectPool.New("TOOLTIP_ENTRY", TooltipEntry),
settings = nil,
registeredInfo = {},
settingsBuilder = nil,
}
local ITER_INDEX_PART_MULTIPLE = 1000
-- ============================================================================
-- Module Functions
-- ============================================================================
function Tooltip.OnInitialize()
private.settings = Settings.NewView()
:AddKey("global", "tooltipOptions", "moduleTooltips")
:AddKey("global", "tooltipOptions", "customPriceTooltips")
:AddKey("global", "tooltipOptions", "vendorBuyTooltip")
:AddKey("global", "tooltipOptions", "vendorSellTooltip")
:AddKey("global", "tooltipOptions", "groupNameTooltip")
:AddKey("global", "tooltipOptions", "detailedDestroyTooltip")
:AddKey("global", "tooltipOptions", "millTooltip")
:AddKey("global", "tooltipOptions", "prospectTooltip")
:AddKey("global", "tooltipOptions", "deTooltip")
:AddKey("global", "tooltipOptions", "transformTooltip")
:AddKey("global", "tooltipOptions", "operationTooltips")
:AddKey("global", "tooltipOptions", "inventoryTooltipFormat")
ItemTooltip.SetWrapperPopulateFunction(private.PopulateTooltip)
private.settingsBuilder = ItemTooltip.CreateBuilder()
end
function Tooltip.CreateInfo()
return TooltipInfo()
end
function Tooltip.Register(info)
info:_CheckDefaults()
tinsert(private.registeredInfo, info)
end
function Tooltip.SettingsLineIterator()
assert(not private.settingsBuilder:_Prepare(ItemString.GetPlaceholder(), 1))
return private.SettingsLineIteratorHelper, nil, 0
end
-- ============================================================================
-- TooltipInfo Class
-- ============================================================================
function TooltipInfo.__init(self)
self._headingLeft = nil
self._headingRight = nil
self._settingsModule = nil
self._entries = {}
end
function TooltipInfo.SetHeadings(self, left, right)
self._headingLeft = left
self._headingRight = right
return self
end
function TooltipInfo.SetSettingsModule(self, settingsModule)
self._settingsModule = settingsModule
return self
end
function TooltipInfo.AddSettingEntry(self, key, defaultValue, populateFunc, populateArg)
if defaultValue == nil then
defaultValue = private.settings:GetDefaultReadOnly(key)
end
assert(type(defaultValue) == "boolean")
local entry = private.entryObjPool:Get()
entry:_Acquire(self, key, true, false, defaultValue, populateFunc, populateArg)
tinsert(self._entries, entry)
return self
end
function TooltipInfo.AddSettingValueEntry(self, key, setValue, clearValue, populateFunc, populateArg)
local entry = private.entryObjPool:Get()
entry:_Acquire(self, key, setValue, clearValue, nil, populateFunc, populateArg)
tinsert(self._entries, entry)
return self
end
function TooltipInfo.DeleteSettingsByKeyMatch(self, matchStr)
for i = #self._entries, 1, -1 do
local entry = self._entries[i]
if entry:KeyMatches(matchStr) then
tremove(self._entries, i)
entry:_Release()
private.entryObjPool:Recycle(entry)
end
end
end
function TooltipInfo._CheckDefaults(self)
if self._settingsModule and not private.settings.moduleTooltips[self._settingsModule] then
-- populate all the default values
private.settings.moduleTooltips[self._settingsModule] = {}
for _, entry in ipairs(self._entries) do
entry:_ResetSetting()
end
end
end
function TooltipInfo._GetSettingsTable(self)
if self._settingsModule then
return private.settings.moduleTooltips[self._settingsModule]
else
return private.settings
end
end
function TooltipInfo._Populate(self, tooltip, itemString)
local headingRightText = self._headingRight and self._headingRight(tooltip, itemString) or nil
tooltip:StartSection(self._headingLeft, headingRightText)
for _, entry in ipairs(self._entries) do
if entry:IsEnabled() then
entry:_Populate(tooltip, itemString)
end
end
tooltip:EndSection()
end
function TooltipInfo._GetEntry(self, index)
return self._entries[index]
end
-- ============================================================================
-- TooltipEntry Class
-- ============================================================================
function TooltipEntry.__init(self)
self._info = nil
self._settingKey = nil
self._settingSetValue = nil
self._settingClearValue = nil
self._settingDefaultValue = nil
self._populateFunc = nil
self._populateArg = nil
end
function TooltipEntry._Acquire(self, info, key, setValue, clearValue, defaultValue, populateFunc, populateArg)
assert(setValue == nil or setValue, "'setValue' must be truthy")
assert(info and key and populateFunc)
assert(clearValue ~= nil or defaultValue ~= nil)
self._info = info
self._settingKey = key
self._settingSetValue = setValue or true
self._settingClearValue = clearValue or false
self._settingDefaultValue = defaultValue
self._populateFunc = populateFunc
self._populateArg = populateArg
end
function TooltipEntry._Release(self)
self._info = nil
self._settingKey = nil
self._settingSetValue = nil
self._settingClearValue = nil
self._settingDefaultValue = nil
self._populateFunc = nil
self._populateArg = nil
end
function TooltipEntry.GetSettingInfo(self)
local tbl = self._info:_GetSettingsTable()
local key, key2, extra = strsplit(".", self._settingKey)
assert(key and not extra)
if key2 then
tbl = tbl[key]
key = key2
end
assert(type(tbl) == "table")
return tbl, key
end
function TooltipEntry.IsEnabled(self)
local settingTbl, settingKey = self:GetSettingInfo()
local settingValue = settingTbl[settingKey]
if settingValue == nil then
assert(self._settingDefaultValue ~= nil)
settingTbl[settingKey] = self._settingDefaultValue
settingValue = settingTbl[settingKey]
end
return settingValue == self._settingSetValue
end
function TooltipEntry.KeyMatches(self, matchStr)
return strmatch(self._settingKey, matchStr) and true or false
end
function TooltipEntry._ResetSetting(self, value)
local tbl = self._info:_GetSettingsTable()
if self._settingDefaultValue ~= nil then
tbl[self._settingKey] = self._settingDefaultValue
elseif self._settingClearValue ~= nil then
tbl[self._settingKey] = self._settingClearValue
else
error("Invalid setting info")
end
end
function TooltipEntry._Populate(self, tooltip, itemString)
self._populateFunc(tooltip, itemString, self._populateArg)
end
-- ============================================================================
-- Private Helper Functions
-- ============================================================================
function private.PopulateTooltip(tooltip, itemString)
for _, info in ipairs(private.registeredInfo) do
info:_Populate(tooltip, itemString)
end
end
function private.SettingsLineIteratorHelper(_, index)
local infoIndex = floor(index / (ITER_INDEX_PART_MULTIPLE ^ 2))
local entryIndex = floor(index / ITER_INDEX_PART_MULTIPLE) % ITER_INDEX_PART_MULTIPLE
local lineIndex = index % ITER_INDEX_PART_MULTIPLE
local info, entry = nil, nil
while lineIndex >= private.settingsBuilder:GetNumLines() do
-- move to the next entry
info = private.registeredInfo[infoIndex]
entryIndex = entryIndex + 1
entry = info and info:_GetEntry(entryIndex)
if entry then
private.settingsBuilder:SetDisabled(not entry:IsEnabled())
entry:_Populate(private.settingsBuilder, ItemString.GetPlaceholder())
private.settingsBuilder:SetDisabled(false)
else
-- move to the next info
if infoIndex > 0 then
private.settingsBuilder:EndSection()
end
infoIndex = infoIndex + 1
info = private.registeredInfo[infoIndex]
if info then
private.settingsBuilder:StartSection(info._headingLeft)
entryIndex = 0
else
return
end
end
end
lineIndex = lineIndex + 1
index = infoIndex * ITER_INDEX_PART_MULTIPLE ^ 2 + entryIndex * ITER_INDEX_PART_MULTIPLE + lineIndex
local leftText, rightText, lineColor = private.settingsBuilder:GetLine(lineIndex)
assert(infoIndex < ITER_INDEX_PART_MULTIPLE and entryIndex < ITER_INDEX_PART_MULTIPLE and lineIndex < ITER_INDEX_PART_MULTIPLE)
return index, leftText, rightText, lineColor
end

View File

@@ -0,0 +1,95 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Crafting = TSM.Tooltip:NewPackage("Crafting")
local L = TSM.Include("Locale").GetTable()
local ItemString = TSM.Include("Util.ItemString")
local Theme = TSM.Include("Util.Theme")
local private = {}
-- ============================================================================
-- Module Functions
-- ============================================================================
function Crafting.OnInitialize()
TSM.Tooltip.Register(TSM.Tooltip.CreateInfo()
:SetHeadings(L["TSM Crafting"])
:SetSettingsModule("Crafting")
:AddSettingEntry("craftingCost", true, private.PopulateCostLine)
:AddSettingEntry("detailedMats", false, private.PopulateDetailedMatsLines)
:AddSettingEntry("matPrice", false, private.PopulateMatPriceLine)
)
end
-- ============================================================================
-- Private Helper Functions
-- ============================================================================
function private.PopulateCostLine(tooltip, itemString)
itemString = itemString and ItemString.GetBaseFast(itemString)
assert(itemString)
local cost, profit = nil, nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
cost = 55
profit = 20
elseif not TSM.Crafting.CanCraftItem(itemString) then
return
else
cost = TSM.Crafting.Cost.GetLowestCostByItem(itemString)
local buyout = cost and TSM.Crafting.Cost.GetCraftedItemValue(itemString) or nil
profit = buyout and (buyout - cost) or nil
end
local costText = tooltip:FormatMoney(cost)
local profitText = tooltip:FormatMoney(profit, profit and Theme.GetFeedbackColor(profit >= 0 and "GREEN" or "RED") or nil)
tooltip:AddLine(L["Crafting Cost"], format(L["%s (%s profit)"], costText, profitText))
end
function private.PopulateDetailedMatsLines(tooltip, itemString)
itemString = itemString and ItemString.GetBaseFast(itemString)
assert(itemString)
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
tooltip:StartSection()
tooltip:AddSubItemValueLine(ItemString.GetPlaceholder(), 11, 5)
tooltip:EndSection()
return
elseif not TSM.Crafting.CanCraftItem(itemString) then
return
end
local _, spellId = TSM.Crafting.Cost.GetLowestCostByItem(itemString)
if not spellId then
return
end
tooltip:StartSection()
local numResult = TSM.Crafting.GetNumResult(spellId)
for _, matItemString, matQuantity in TSM.Crafting.MatIterator(spellId) do
tooltip:AddSubItemValueLine(matItemString, TSM.Crafting.Cost.GetMatCost(matItemString), matQuantity / numResult)
end
tooltip:EndSection()
end
function private.PopulateMatPriceLine(tooltip, itemString)
itemString = itemString and ItemString.GetBase(itemString) or nil
local matCost = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
matCost = 17
else
matCost = TSM.Crafting.Cost.GetMatCost(itemString)
end
if matCost then
tooltip:AddItemValueLine(L["Material Cost"], matCost)
end
end

View File

@@ -0,0 +1,389 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local General = TSM.Tooltip:NewPackage("General")
local L = TSM.Include("Locale").GetTable()
local DisenchantInfo = TSM.Include("Data.DisenchantInfo")
local TempTable = TSM.Include("Util.TempTable")
local String = TSM.Include("Util.String")
local ItemString = TSM.Include("Util.ItemString")
local ItemInfo = TSM.Include("Service.ItemInfo")
local CustomPrice = TSM.Include("Service.CustomPrice")
local Conversions = TSM.Include("Service.Conversions")
local Inventory = TSM.Include("Service.Inventory")
local private = {
tooltipInfo = nil,
}
local DESTROY_INFO = {
{ key = "deTooltip", method = Conversions.METHOD.DISENCHANT },
{ key = "millTooltip", method = Conversions.METHOD.MILL },
{ key = "prospectTooltip", method = Conversions.METHOD.PROSPECT },
{ key = "transformTooltip", method = Conversions.METHOD.TRANSFORM },
}
-- ============================================================================
-- Module Functions
-- ============================================================================
function General.OnInitialize()
local tooltipInfo = TSM.Tooltip.CreateInfo()
:SetHeadings(L["TSM General Info"])
private.tooltipInfo = tooltipInfo
CustomPrice.RegisterCustomSourceCallback(private.UpdateCustomSources)
-- group name
tooltipInfo:AddSettingEntry("groupNameTooltip", nil, private.PopulateGroupLine)
-- operations
for _, moduleName in TSM.Operations.ModuleIterator() do
tooltipInfo:AddSettingEntry("operationTooltips."..moduleName, false, private.PopulateOperationLine, moduleName)
end
-- destroy info
for _, info in ipairs(DESTROY_INFO) do
tooltipInfo:AddSettingEntry(info.key, nil, private.PopulateDestroyValueLine, info.method)
tooltipInfo:AddSettingEntry("detailedDestroyTooltip", nil, private.PopulateDetailLines, info.method)
end
-- vendor prices
tooltipInfo:AddSettingEntry("vendorBuyTooltip", nil, private.PopulateVendorBuyLine)
tooltipInfo:AddSettingEntry("vendorSellTooltip", nil, private.PopulateVendorSellLine)
-- custom sources
private.UpdateCustomSources()
-- inventory info
tooltipInfo:AddSettingValueEntry("inventoryTooltipFormat", "full", "none", private.PopulateFullInventoryLines)
tooltipInfo:AddSettingValueEntry("inventoryTooltipFormat", "simple", "none", private.PopulateSimpleInventoryLine)
TSM.Tooltip.Register(tooltipInfo)
end
function private.UpdateCustomSources()
private.tooltipInfo:DeleteSettingsByKeyMatch("^customPriceTooltips%.")
local customPriceSources = TempTable.Acquire()
for name in pairs(TSM.db.global.userData.customPriceSources) do
tinsert(customPriceSources, name)
end
sort(customPriceSources)
for _, name in ipairs(customPriceSources) do
private.tooltipInfo:AddSettingEntry("customPriceTooltips."..name, false, private.PopulateCustomPriceLine, name)
end
TempTable.Release(customPriceSources)
end
-- ============================================================================
-- Private Helper Functions
-- ============================================================================
function private.PopulateGroupLine(tooltip, itemString)
-- add group / operation info
local groupPath, itemInGroup = nil, nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
groupPath = L["Example"]
itemInGroup = true
else
groupPath = TSM.Groups.GetPathByItem(itemString)
if groupPath == TSM.CONST.ROOT_GROUP_PATH then
groupPath = nil
else
itemInGroup = TSM.Groups.IsItemInGroup(itemString)
end
end
if groupPath then
local leftText = itemInGroup and GROUP or (GROUP.." ("..L["Base Item"]..")")
tooltip:AddTextLine(leftText, TSM.Groups.Path.Format(groupPath))
end
end
function private.PopulateOperationLine(tooltip, itemString, moduleName)
assert(moduleName)
local operations = TempTable.Acquire()
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
tinsert(operations, L["Example"])
else
local groupPath = TSM.Groups.GetPathByItem(itemString)
if groupPath == TSM.CONST.ROOT_GROUP_PATH then
groupPath = nil
end
if not groupPath then
TempTable.Release(operations)
return
end
for _, operationName in TSM.Operations.GroupOperationIterator(moduleName, groupPath) do
tinsert(operations, operationName)
end
end
if #operations > 0 then
tooltip:AddLine(format(#operations == 1 and L["%s operation"] or L["%s operations"], TSM.Operations.GetLocalizedName(moduleName)), tooltip:ApplyValueColor(table.concat(operations, ", ")))
end
TempTable.Release(operations)
end
function private.PopulateDestroyValueLine(tooltip, itemString, method)
local value = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
if method == Conversions.METHOD.DISENCHANT then
value = 10
elseif method == Conversions.METHOD.MILL then
value = 50
elseif method == Conversions.METHOD.PROSPECT then
value = 20
elseif method == Conversions.METHOD.TRANSFORM then
value = 30
else
error("Invalid method: "..tostring(method))
end
else
value = CustomPrice.GetConversionsValue(itemString, TSM.db.global.coreOptions.destroyValueSource, method)
end
if not value then
return
end
local label = nil
if method == Conversions.METHOD.DISENCHANT then
label = L["Disenchant Value"]
elseif method == Conversions.METHOD.MILL then
label = L["Mill Value"]
elseif method == Conversions.METHOD.PROSPECT then
label = L["Prospect Value"]
elseif method == Conversions.METHOD.TRANSFORM then
label = L["Transform Value"]
else
error("Invalid method: "..tostring(method))
end
tooltip:AddItemValueLine(label, value)
end
function private.PopulateDetailLines(tooltip, itemString, method)
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
tooltip:StartSection()
if method == Conversions.METHOD.DISENCHANT then
tooltip:AddSubItemValueLine(ItemString.GetPlaceholder(), 1, 10, 1, 1, 20)
elseif method == Conversions.METHOD.MILL then
tooltip:AddSubItemValueLine(ItemString.GetPlaceholder(), 5, 10, 1)
elseif method == Conversions.METHOD.PROSPECT then
tooltip:AddSubItemValueLine(ItemString.GetPlaceholder(), 2, 10, 1, 1, 20)
elseif method == Conversions.METHOD.TRANSFORM then
tooltip:AddSubItemValueLine(ItemString.GetPlaceholder(), 3, 10, 1)
else
error("Invalid method: "..tostring(method))
end
tooltip:EndSection()
return
elseif not CustomPrice.GetConversionsValue(itemString, TSM.db.global.coreOptions.destroyValueSource, method) then
return
end
tooltip:StartSection()
if method == Conversions.METHOD.DISENCHANT then
local quality = ItemInfo.GetQuality(itemString)
local ilvl = ItemInfo.GetItemLevel(ItemString.GetBase(itemString))
local classId = ItemInfo.GetClassId(itemString)
for targetItemString in DisenchantInfo.TargetItemIterator() do
local amountOfMats, matRate, minAmount, maxAmount = DisenchantInfo.GetTargetItemSourceInfo(targetItemString, classId, quality, ilvl)
if amountOfMats then
local matValue = CustomPrice.GetValue(TSM.db.global.coreOptions.destroyValueSource, targetItemString) or 0
if matValue > 0 then
tooltip:AddSubItemValueLine(targetItemString, matValue, amountOfMats, matRate, minAmount, maxAmount)
end
end
end
else
for targetItemString, amountOfMats, matRate, minAmount, maxAmount in Conversions.TargetItemsByMethodIterator(itemString, method) do
local matValue = CustomPrice.GetValue(TSM.db.global.coreOptions.destroyValueSource, targetItemString) or 0
if matValue > 0 then
tooltip:AddSubItemValueLine(targetItemString, matValue, amountOfMats, matRate, minAmount, maxAmount)
end
end
end
tooltip:EndSection()
end
function private.PopulateVendorBuyLine(tooltip, itemString)
local value = nil
if itemString == ItemString.GetPlaceholder() then
-- example item
value = 50
else
value = ItemInfo.GetVendorBuy(itemString) or 0
end
if value > 0 then
tooltip:AddItemValueLine(L["Vendor Buy Price"], value)
end
end
function private.PopulateVendorSellLine(tooltip, itemString)
local value = nil
if itemString == ItemString.GetPlaceholder() then
-- example item
value = 8
else
value = ItemInfo.GetVendorSell(itemString) or 0
end
if value > 0 then
tooltip:AddItemValueLine(L["Vendor Sell Price"], value)
end
end
function private.PopulateCustomPriceLine(tooltip, itemString, name)
assert(name)
if not TSM.db.global.userData.customPriceSources[name] then
-- TODO: this custom price source has been removed (ideally shouldn't get here)
return
end
local value = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
value = 10
else
value = CustomPrice.GetValue(name, itemString) or 0
end
if value > 0 then
tooltip:AddItemValueLine(L["Custom Source"].." ("..name..")", value)
end
end
function private.PopulateFullInventoryLines(tooltip, itemString)
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
local totalNum = 0
local playerName = UnitName("player")
local bag, bank, auction, mail, guildQuantity = 5, 4, 4, 9, 1
local playerTotal = bag + bank + auction + mail
totalNum = totalNum + playerTotal
tooltip:StartSection(L["Inventory"], format(L["%s total"], tooltip:ApplyValueColor(totalNum)))
local classColor = RAID_CLASS_COLORS[TSM.db:Get("sync", TSM.db:GetSyncScopeKeyByCharacter(UnitName("player")), "internalData", "classKey")]
local rightText = private.RightTextFormatHelper(tooltip, L["%s (%s bags, %s bank, %s AH, %s mail)"], playerTotal, bag, bank, auction, mail)
if classColor then
tooltip:AddLine("|c"..classColor.colorStr..playerName.."|r", rightText)
else
tooltip:AddLine(playerName, rightText)
end
totalNum = totalNum + guildQuantity
tooltip:AddLine(L["Example"], format(L["%s in guild vault"], tooltip:ApplyValueColor(guildQuantity)))
tooltip:EndSection()
return
end
-- calculate the total number
local totalNum = 0
for factionrealm in TSM.db:GetConnectedRealmIterator("factionrealm") do
for _, character in TSM.db:FactionrealmCharacterIterator(factionrealm) do
local bag = Inventory.GetBagQuantity(itemString, character, factionrealm)
local bank = Inventory.GetBankQuantity(itemString, character, factionrealm)
local reagentBank = Inventory.GetReagentBankQuantity(itemString, character, factionrealm)
local auction = Inventory.GetAuctionQuantity(itemString, character, factionrealm)
local mail = Inventory.GetMailQuantity(itemString, character, factionrealm)
totalNum = totalNum + bag + bank + reagentBank + auction + mail
end
end
for guildName in pairs(TSM.db.factionrealm.internalData.guildVaults) do
local guildQuantity = Inventory.GetGuildQuantity(itemString, guildName)
totalNum = totalNum + guildQuantity
end
tooltip:StartSection(L["Inventory"], format(L["%s total"], tooltip:ApplyValueColor(totalNum)))
-- add the lines
for factionrealm in TSM.db:GetConnectedRealmIterator("factionrealm") do
for _, character in TSM.db:FactionrealmCharacterIterator(factionrealm) do
local realm = strmatch(factionrealm, "^.* "..String.Escape("-").." (.*)")
if realm == GetRealmName() then
realm = ""
else
realm = " - "..realm
end
local bag = Inventory.GetBagQuantity(itemString, character, factionrealm)
local bank = Inventory.GetBankQuantity(itemString, character, factionrealm)
local reagentBank = Inventory.GetReagentBankQuantity(itemString, character, factionrealm)
local auction = Inventory.GetAuctionQuantity(itemString, character, factionrealm)
local mail = Inventory.GetMailQuantity(itemString, character, factionrealm)
local playerTotal = bag + bank + reagentBank + auction + mail
if playerTotal > 0 then
local classColor = RAID_CLASS_COLORS[TSM.db:Get("sync", TSM.db:GetSyncScopeKeyByCharacter(character, factionrealm), "internalData", "classKey")]
local rightText = private.RightTextFormatHelper(tooltip, L["%s (%s bags, %s bank, %s AH, %s mail)"], playerTotal, bag, bank + reagentBank, auction, mail)
if classColor then
tooltip:AddLine("|c"..classColor.colorStr..character..realm.."|r", rightText)
else
tooltip:AddLine(character..realm, rightText)
end
end
end
end
for guildName in pairs(TSM.db.factionrealm.internalData.guildVaults) do
local guildQuantity = Inventory.GetGuildQuantity(itemString, guildName)
if guildQuantity > 0 then
tooltip:AddLine(guildName, format(L["%s in guild vault"], tooltip:ApplyValueColor(guildQuantity)))
end
end
tooltip:EndSection()
end
function private.PopulateSimpleInventoryLine(tooltip, itemString)
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
local totalPlayer, totalAlt, totalGuild, totalAuction = 18, 0, 1, 4
local totalNum2 = totalPlayer + totalAlt + totalGuild + totalAuction
local rightText2 = nil
if not TSM.IsWowClassic() then
rightText2 = private.RightTextFormatHelper(tooltip, L["%s (%s player, %s alts, %s guild, %s AH)"], totalNum2, totalPlayer, totalAlt, totalGuild, totalAuction)
else
rightText2 = private.RightTextFormatHelper(tooltip, L["%s (%s player, %s alts, %s AH)"], totalNum2, totalPlayer, totalAlt, totalAuction)
end
tooltip:AddLine(L["Inventory"], rightText2)
end
local totalPlayer, totalAlt, totalGuild, totalAuction = 0, 0, 0, 0
for factionrealm in TSM.db:GetConnectedRealmIterator("factionrealm") do
for _, character in TSM.db:FactionrealmCharacterIterator(factionrealm) do
local bag = Inventory.GetBagQuantity(itemString, character, factionrealm)
local bank = Inventory.GetBankQuantity(itemString, character, factionrealm)
local reagentBank = Inventory.GetReagentBankQuantity(itemString, character, factionrealm)
local auction = Inventory.GetAuctionQuantity(itemString, character, factionrealm)
local mail = Inventory.GetMailQuantity(itemString, character, factionrealm)
if character == UnitName("player") then
totalPlayer = totalPlayer + bag + bank + reagentBank + mail
totalAuction = totalAuction + auction
else
totalAlt = totalAlt + bag + bank + reagentBank + mail
totalAuction = totalAuction + auction
end
end
end
for guildName in pairs(TSM.db.factionrealm.internalData.guildVaults) do
totalGuild = totalGuild + Inventory.GetGuildQuantity(itemString, guildName)
end
local totalNum = totalPlayer + totalAlt + totalGuild + totalAuction
if totalNum > 0 then
local rightText = nil
if not TSM.IsWowClassic() then
rightText = private.RightTextFormatHelper(tooltip, L["%s (%s player, %s alts, %s guild, %s AH)"], totalNum, totalPlayer, totalAlt, totalGuild, totalAuction)
else
rightText = private.RightTextFormatHelper(tooltip, L["%s (%s player, %s alts, %s AH)"], totalNum, totalPlayer, totalAlt, totalAuction)
end
tooltip:AddLine(L["Inventory"], rightText)
end
end
function private.RightTextFormatHelper(tooltip, fmtStr, ...)
local parts = TempTable.Acquire(...)
for i = 1, #parts do
parts[i] = tooltip:ApplyValueColor(parts[i])
end
local result = format(fmtStr, unpack(parts))
TempTable.Release(parts)
return result
end

View File

@@ -0,0 +1,44 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Shopping = TSM.Tooltip:NewPackage("Shopping")
local L = TSM.Include("Locale").GetTable()
local ItemString = TSM.Include("Util.ItemString")
local private = {}
-- ============================================================================
-- Module Functions
-- ============================================================================
function Shopping.OnInitialize()
TSM.Tooltip.Register(TSM.Tooltip.CreateInfo()
:SetHeadings(L["TSM Shopping"])
:SetSettingsModule("Shopping")
:AddSettingEntry("maxPrice", false, private.PopulateMaxPriceLine)
)
end
-- ============================================================================
-- Private Helper Functions
-- ============================================================================
function private.PopulateMaxPriceLine(tooltip, itemString)
local maxPrice = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
maxPrice = 37
else
maxPrice = TSM.Operations.Shopping.GetMaxPrice(itemString)
end
if maxPrice then
tooltip:AddItemValueLine(L["Max Shopping Price"], maxPrice)
end
end

View File

@@ -0,0 +1,44 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Sniper = TSM.Tooltip:NewPackage("Sniper")
local L = TSM.Include("Locale").GetTable()
local ItemString = TSM.Include("Util.ItemString")
local private = {}
-- ============================================================================
-- Module Functions
-- ============================================================================
function Sniper.OnInitialize()
TSM.Tooltip.Register(TSM.Tooltip.CreateInfo()
:SetHeadings(L["TSM Sniper"])
:SetSettingsModule("Sniper")
:AddSettingEntry("belowPrice", false, private.PopulateBelowPriceLine)
)
end
-- ============================================================================
-- Private Helper Functions
-- ============================================================================
function private.PopulateBelowPriceLine(tooltip, itemString)
local belowPrice = nil
if itemString == ItemString.GetPlaceholder() then
-- example tooltip
belowPrice = 35
else
belowPrice = TSM.Operations.Sniper.GetBelowPrice(itemString)
end
if belowPrice then
tooltip:AddItemValueLine(L["Sniper Below Price"], belowPrice)
end
end