View Single Post
12-06-19, 11:43 PM   #1
hasnogaems
A Flamescale Wyrmkin
 
hasnogaems's Avatar
Join Date: Apr 2016
Posts: 109
Make TSM show craft price and profit on all craftable items.

In wow classic. I'm trying to edit file that I think must regulate its behaviour, so far my tinkering made TSM crafting tab completely dissapear from tooltips.
Default behaviour is showing crafting tab only for learned recipes.
https://imgur.com/a/v9w5bxw

Here is the code:
Code:
-- ------------------------------------------------------------------------------ --
--                                TradeSkillMaster                                --
--                http://www.curse.com/addons/wow/tradeskill-master               --
--                                                                                --
--             A TradeSkillMaster Addon (http://tradeskillmaster.com)             --
--    All Rights Reserved* - Detailed license information included with addon.    --
-- ------------------------------------------------------------------------------ --

local _, TSM = ...
local Crafting = TSM.Tooltip:NewPackage("Crafting")
local L = TSM.L
local private = {}
local DEFAULTS = {
	craftingCost = true,
	matPrice = false,
	detailedMats = false,
}



-- ============================================================================
-- Module Functions
-- ============================================================================

function Crafting.OnInitialize()
	TSM.Tooltip.Register("Crafting", DEFAULTS, private.LoadTooltip)
end



-- ============================================================================
-- Private Helper Functions
-- ============================================================================

function private.LoadTooltip(tooltip, itemString, options)
	itemString = TSMAPI_FOUR.Item.ToBaseItemString(itemString)

	if TSM.Crafting.CanCraftItem(itemString) and options.craftingCost then
		local cost, spellId = TSM.Crafting.Cost.GetLowestCostByItem(itemString)
		if cost then
			local buyout = TSM.Crafting.Cost.GetCraftedItemValue(itemString)
			local profit = buyout and (buyout - cost) or nil

			local costText = cost and tooltip:FormatMoney(cost) or "|cffffffff---|r"
			local profitColor = (profit or 0) < 0 and "|cffff0000" or "|cff00ff00"
			local profitText = profit and tooltip:FormatMoney(profit, profitColor) or "|cffffffff---|r"
			tooltip:AddLine(L["Crafting Cost"], format(L["%s (%s profit)"], costText, profitText))

			if options.detailedMats then
				tooltip:StartSection()
				local numResult = TSM.Crafting.GetNumResult(spellId)
				for _, matItemString, matQuantity in TSM.Crafting.MatIterator(spellId) do
					local name = TSMAPI_FOUR.Item.GetName(matItemString)
					local matCost = TSM.Crafting.Cost.GetMatCost(matItemString)
					local quality = TSMAPI_FOUR.Item.GetQuality(matItemString)
					if name and matCost and quality then
						tooltip:AddSubItemValueLine(matItemString, matCost, matQuantity / numResult)
					end
				end
				tooltip:EndSection()
			end
		end
	end

	-- add mat price
	if options.matPrice then
		local matCost = TSM.Crafting.Cost.GetMatCost(itemString)
		if matCost then
			tooltip:AddItemValueLine(L["Mat Cost"], matCost)
		end
	end
end
I highlighted the line that I want to be displayed on every craftable item, not only on which I can craft myself.

Last edited by hasnogaems : 12-16-19 at 11:52 PM.
  Reply With Quote