@ -140,7 +140,12 @@ function GUI:ShowProfessionWindow()
GUI : UpdateTradeSkills ( GetTradeSkillLine ( ) )
TradeSkillFrame : SetScript ( " OnHide " , nil )
HideUIPanel ( TradeSkillFrame )
TradeSkillFrame : SetScript ( " OnHide " , function ( ) if not GUI.noClose then GUI.switchBtn : Hide ( ) CloseTradeSkill ( ) end end )
TradeSkillFrame : SetScript ( " OnHide " , function ( )
if not GUI.noClose and not GUI.switchingProfession then
GUI.switchBtn : Hide ( )
CloseTradeSkill ( )
end
end )
priceTextCache.lastClear = 0
GUI.switchBtn : Update ( )
@ -202,6 +207,7 @@ function GUI:EventHandler(event, ...)
local unittest = ...
if unittest == " player " or unittest == nil then --Changing tradeskill frames and stuff has "nil" unit, when other players cast this also triggers with nil
if event == " TRADE_SKILL_CLOSE " then
if GUI.switchingProfession then return end
GUI.frame : Hide ( )
elseif event == " TRADE_SKILL_UPDATE " or event == " TRADE_SKILL_FILTER_UPDATE " then
if GetTradeSkillLine ( ) ~= GUI.currentTradeSkill or select ( 2 , IsTradeSkillLinked ( ) ) ~= GUI.currentLinkedPlayer then
@ -475,13 +481,13 @@ function GUI:CreateGUI()
local frameDefaults = {
x = 100 ,
y = 300 ,
width = 4 50,
width = 52 0 ,
height = 500 ,
scale = 1 ,
}
local frame = TSMAPI : CreateMovableFrame ( " TSMCraftingTradeSkillFrame " , frameDefaults )
frame : SetResizable ( true )
frame : SetMinResize ( 4 50, 400 )
frame : SetMinResize ( 52 0 , 400 )
TSMAPI.Design : SetFrameBackdropColor ( frame )
frame : Show ( )
frame : SetScript ( " OnHide " , function ( ) if not GUI.noClose then GUI.switchBtn : Hide ( ) TradeSkillFrame : Show ( ) CloseTradeSkill ( ) end end )
@ -900,17 +906,52 @@ function GUI:CreateProfessionsTab(parent)
local currentSelection
local player = UnitName ( " player " )
local function SetNoClose ( )
GUI.noClose = true
GUI.switchingProfession = true
TSMAPI : CreateTimeDelay ( " craftingNoCloseClear " , 0.6 , function ( ) GUI.noClose = nil end )
TSMAPI : CreateTimeDelay ( " craftingSwitchingClear " , 0.8 , function ( ) GUI.switchingProfession = nil end )
end
local function SelectSpellInProfession ( profession , spellID )
if GetTradeSkillLine ( ) ~= profession then
local link = TSM.db . realm.tradeSkills [ player ] and TSM.db . realm.tradeSkills [ player ] [ profession ] and TSM.db . realm.tradeSkills [ player ] [ profession ] . link
if not link then return end
local tradeString = strsub ( select ( 3 , ( " | " ) : split ( link ) ) , 2 )
SetNoClose ( )
SetItemRef ( tradeString , link , " LeftButton " , ChatFrame1 )
return
end
for i = 1 , GetNumTradeSkills ( ) do
if TSM.Util : GetSpellID ( i ) == spellID then
TradeSkillFrame_SetSelection ( i )
TradeSkillFrame_Update ( )
GUI : UpdateSelectedTradeSkill ( true )
return
end
end
end
local HaveMatsCheckBox
local function UpdateProfession ( self )
local list = { }
list [ " ALL " ] = L [ " All Professions " ]
for playerName , professionData in pairs ( TSM.db . realm.tradeSkills ) do
for name , data in pairs ( professionData ) do
if not data.isSecondary and playerName == player then -- only display current player profs until blizz fix it
if playerName == player then -- only display current player profs until blizz fix it
list [ playerName .. " ~ " .. name ] = format ( " %s %d/%d - %s " , name , data.level or " ? " , data.maxLevel or " ? " , playerName )
end
end
end
self.dropdown : SetList ( list )
if TSM.db . global.showAllProfessions then
self.dropdown : SetValue ( " ALL " )
self.dropdown : SetText ( L [ " All Professions " ] )
return
end
local playerName = select ( 2 , IsTradeSkillLinked ( ) ) or player
local professionName , level , maxLevel = GetTradeSkillLine ( )
local professionString = format ( " %s %d/%d - %s " , professionName , level , maxLevel , playerName )
@ -925,13 +966,36 @@ function GUI:CreateProfessionsTab(parent)
frame : SetScript ( " OnShow " , UpdateProfession )
local function OnValueChanged ( _ , _ , index )
if index == " ALL " then
TSM.db . global.showAllProfessions = true
frame : UpdateProfession ( )
GUI : UpdateProfessionsTabST ( )
return
end
if TSM.db . global.showAllProfessions then
SetNoClose ( )
TSM.db . global.showAllProfessions = false
end
local playerName , profession = ( " ~ " ) : split ( index )
local currentPlayer = select ( 2 , IsTradeSkillLinked ( ) ) or player
local currentProfession = GetTradeSkillLine ( )
if playerName == currentPlayer and profession == currentProfession then
frame : UpdateProfession ( )
GUI : ShowProfessionsTab ( )
currentSelection = index
return
end
if playerName == player then
if profession == " Mining " then
CastSpellByName ( " Smelting " )
else
CastSpellByName ( profession )
local link = TSM.db . realm.tradeSkills [ playerName ] and TSM.db . realm.tradeSkills [ playerName ] [ profession ] and TSM.db . realm.tradeSkills [ playerName ] [ profession ] . link
if not link then
TSM : Printf ( L [ " Profession data not found for %s on %s. Logging into this player and opening the profession may solve this issue. " ] , profession , playerName )
return OnValueChanged ( _ , _ , currentSelect ion)
end
local tradeString = strsub ( select ( 3 , ( " | " ) : split ( link ) ) , 2 )
SetNoClose ( )
SetItemRef ( tradeString , link , " LeftButton " , ChatFrame1 )
else
local link = TSM.db . realm.tradeSkills [ playerName ] [ profession ] . link
if not link then
@ -939,7 +1003,8 @@ function GUI:CreateProfessionsTab(parent)
return OnValueChanged ( _ , _ , currentSelection )
end
local tradeString = strsub ( select ( 3 , ( " | " ) : split ( link ) ) , 2 )
SetItemRef ( tradeString , link )
SetNoClose ( )
SetItemRef ( tradeString , link , " LeftButton " , ChatFrame1 )
end
currentSelection = index
end
@ -951,15 +1016,19 @@ function GUI:CreateProfessionsTab(parent)
dd : SetCallback ( " OnValueChanged " , OnValueChanged )
frame.dropdown = dd
local HaveMatsCheckBox = TSMAPI.GUI : CreateCheckBox ( frame )
HaveMatsCheckBox = TSMAPI.GUI : CreateCheckBox ( frame )
HaveMatsCheckBox : SetLabel ( " Have Mats " )
HaveMatsCheckBox : SetPoint ( " TOPLEFT " , 252 , - 4 )
HaveMatsCheckBox : SetWidth ( 90 )
HaveMatsCheckBox : SetHeight ( 26 )
frame.HaveMatsCheckBox = HaveMatsCheckBox
HaveMatsCheckBox : SetCallback ( " OnValueChanged " , function ( _ , _ , value )
if TSM.db . global.showAllProfessions then
GUI : UpdateProfessionsTabST ( )
else
TradeSkillFrameAvailableFilterCheckButton : SetChecked ( value )
TradeSkillOnlyShowMakeable ( value )
end
end )
local RestockBtn = TSMAPI.GUI : CreateButton ( frame , 14 )
@ -971,6 +1040,7 @@ function GUI:CreateProfessionsTab(parent)
QuickRestock = true
GUI.ShowGroupsTab ( )
end )
frame.restockBtn = RestockBtn
local linkBtn = TSMAPI.GUI : CreateButton ( frame , 14 )
linkBtn : SetPoint ( " TOPRIGHT " , - 5 , - 4 )
@ -1029,7 +1099,9 @@ function GUI:CreateProfessionsTab(parent)
end )
searchBar : SetScript ( " OnTextChanged " , function ( self )
local text = self : GetText ( )
if not TSM.db . global.showAllProfessions then
SetTradeSkillItemNameFilter ( text == SEARCH and " " or text )
end
GUI : UpdateProfessionsTabST ( )
end )
searchBar : SetScript ( " OnEnterPressed " , searchBar.ClearFocus )
@ -1070,7 +1142,17 @@ function GUI:CreateProfessionsTab(parent)
TSMAPI.GUI : CreateHorizontalLine ( frame , - 64 )
local function OnSTRowClick ( _ , data , _ , button )
if data.isCollapseAll then
if TSM.db . global.showAllProfessions and data.spellID then
if IsModifiedClick ( ) then
local itemID = TSM.db . realm.crafts [ data.spellID ] and TSM.db . realm.crafts [ data.spellID ] . itemID
if itemID then
HandleModifiedItemClick ( itemID )
end
else
SelectSpellInProfession ( data.profession , data.spellID )
end
return
elseif data.isCollapseAll then
TradeSkillCollapseAllButton : Click ( )
GUI : UpdateProfessionsTabST ( )
elseif button == " LeftButton " then
@ -1084,26 +1166,29 @@ function GUI:CreateProfessionsTab(parent)
end
end
local function GetPriceColumnText ( )
if TSM.db . global.priceColumn == 1 then
return L [ " Crafting Cost " ]
elseif TSM.db . global.priceColumn == 2 then
return L [ " Item Value " ]
elseif TSM.db . global.priceColumn == 3 then
return L [ " Profit " ]
end
end
local function OnSTColumnClick ( self )
if self.colNum == 2 then
TSM.db . global.priceColumn = TSM.db . global.priceColumn + 1
TSM.db . global.priceColumn = TSM.db . global.priceColumn > 3 and 1 or TSM.db . global.priceColumn
self : SetText ( GetPriceColumnText ( ) )
wipe ( priceTextCache )
priceTextCache.lastClear = time ( )
if TSM.db . global.showAllProfessions then
local sortKey
if self.colNum == 1 then
sortKey = " available "
elseif self.colNum == 3 then
sortKey = " cost "
elseif self.colNum == 4 then
sortKey = " profit "
elseif self.colNum == 5 then
sortKey = " profitPercent "
end
if sortKey then
if TSM.db . global.showAllProfessionsSortKey ~= sortKey then
TSM.db . global.showAllProfessionsSortKey = sortKey
TSM.db . global.showAllProfessionsSortDescending = true
else
TSM.db . global.showAllProfessionsSortDescending = not TSM.db . global.showAllProfessionsSortDescending
end
GUI : UpdateProfessionsTabST ( )
end
end
end
local stContainer = CreateFrame ( " Frame " , nil , frame )
stContainer : SetPoint ( " TOPLEFT " , 5 , - 70 )
@ -1112,11 +1197,11 @@ function GUI:CreateProfessionsTab(parent)
TSMAPI.Design : SetFrameColor ( stContainer )
local stCols = {
-- { name = L["Name"], width = 0.725, align = "LEFT" } ,
-- { name = GetPriceColumnText(), width = 0.275, align = "LEFT" } ,
{ name = L [ " Name " ] , width = 0.7 , a lign = " LEFT " } ,
{ name = GetPriceColumnText ( ) , width = 0.2 , align = " LEFT " } ,
{ name = " P. %" , width = 0.1 , a lign = " LEFT " }
{ name = " # " , width = 0.08 , align = " LEFT " , headAlign = " LEFT " } ,
{ name = L [ " Name " ] , width = 0.40 , align = " LEFT " , headAlign = " LEFT " } ,
{ name = L [ " Cost " ] , width = 0.16 , align = " LEFT " , headA lign = " LEFT " } ,
{ name = L [ " Profit " ] , width = 0.18 , align = " LEFT " , he adA lign = " LEFT " } ,
{ name = " % " , width = 0.08 , align = " LEFT " , headA lign = " LEFT " }
}
frame.st = TSMAPI : CreateScrollingTable ( stContainer , stCols , { OnClick = OnSTRowClick , OnColumnClick = OnSTColumnClick } )
@ -1510,6 +1595,8 @@ function GUI:UpdateProfessionsTabST()
local stData = { }
TSM : UpdateCraftReverseLookup ( )
local showAll = TSM.db . global.showAllProfessions
local player = UnitName ( " player " )
local function RGBPercToHex ( tbl )
local r = tbl.r
@ -1526,25 +1613,206 @@ function GUI:UpdateProfessionsTabST()
priceTextCache.lastClear = time ( )
end
local function GetInventoryTotals ( )
local totals = { }
local bags = TSMAPI : ModuleAPI ( " ItemTracker " , " playerbags " , player )
local bank = TSMAPI : ModuleAPI ( " ItemTracker " , " playerbank " , player )
if bags or bank then
for itemString , quantity in pairs ( bags or { } ) do
totals [ itemString ] = ( totals [ itemString ] or 0 ) + quantity
end
for itemString , quantity in pairs ( bank or { } ) do
totals [ itemString ] = ( totals [ itemString ] or 0 ) + quantity
end
return totals
end
return select ( 4 , TSM.Inventory : GetTotals ( ) )
end
local ts = " "
local numAvailableAllCache = { }
local inventoryTotals = GetInventoryTotals ( )
if showAll then
local searchText = GUI.frame and GUI.frame . content and GUI.frame . content.professionsTab and GUI.frame . content.professionsTab . searchBar and GUI.frame . content.professionsTab . searchBar : GetText ( ) or " "
if searchText == SEARCH then
searchText = " "
end
searchText = strlower ( searchText or " " )
local filterHaveMats = GUI.frame and GUI.frame . content and GUI.frame . content.professionsTab and GUI.frame . content.professionsTab . HaveMatsCheckBox and GUI.frame . content.professionsTab . HaveMatsCheckBox : GetValue ( )
local craftList = { }
for spellID , data in pairs ( TSM.db . realm.crafts ) do
if data.players and data.players [ UnitName ( " player " ) ] then
tinsert ( craftList , {
spellID = spellID ,
name = data.name or " " ,
profession = data.profession or UNKNOWN ,
numResult = data.numResult or 1 ,
} )
end
end
for _ , craft in ipairs ( craftList ) do
craft.cost , craft.buyout , craft.profit = TSM.Cost : GetCraftPrices ( craft.spellID )
if craft.profit and craft.cost and craft.cost > 0 then
craft.profitPercent = ( craft.profit / craft.cost ) * 100
else
craft.profitPercent = nil
end
local available = math.huge
if TSM.db . realm.crafts [ craft.spellID ] then
for itemString , quantity in pairs ( TSM.db . realm.crafts [ craft.spellID ] . mats ) do
available = min ( available , floor ( ( inventoryTotals [ itemString ] or 0 ) / quantity ) )
end
end
craft.available = available ~= math.huge and available or 0
end
if searchText ~= " " or filterHaveMats then
local filtered = { }
for _ , craft in ipairs ( craftList ) do
if ( searchText == " " or strfind ( strlower ( craft.name or " " ) , searchText , 1 , true ) ) and ( not filterHaveMats or craft.available > 0 ) then
tinsert ( filtered , craft )
end
end
craftList = filtered
end
if TSM.db . global.showAllProfessionsSortKey == " cost " then
sort ( craftList , function ( a , b )
local aValue = tonumber ( a.cost ) or math.huge
local bValue = tonumber ( b.cost ) or math.huge
if aValue == bValue then
return a.name < b.name
end
if TSM.db . global.showAllProfessionsSortDescending then
return aValue > bValue
end
return aValue < bValue
end )
elseif TSM.db . global.showAllProfessionsSortKey == " profit " then
sort ( craftList , function ( a , b )
local aValue = tonumber ( a.profit ) or - math.huge
local bValue = tonumber ( b.profit ) or - math.huge
if aValue == bValue then
return a.name < b.name
end
if TSM.db . global.showAllProfessionsSortDescending then
return aValue > bValue
end
return aValue < bValue
end )
elseif TSM.db . global.showAllProfessionsSortKey == " available " then
sort ( craftList , function ( a , b )
local aValue = tonumber ( a.available ) or - math.huge
local bValue = tonumber ( b.available ) or - math.huge
if aValue == bValue then
return a.name < b.name
end
if TSM.db . global.showAllProfessionsSortDescending then
return aValue > bValue
end
return aValue < bValue
end )
elseif TSM.db . global.showAllProfessionsSortKey == " profitPercent " then
sort ( craftList , function ( a , b )
local aValue = tonumber ( a.profitPercent ) or - math.huge
local bValue = tonumber ( b.profitPercent ) or - math.huge
if aValue == bValue then
return a.name < b.name
end
if TSM.db . global.showAllProfessionsSortDescending then
return aValue > bValue
end
return aValue < bValue
end )
else
sort ( craftList , function ( a , b )
if TSM.db . global.showAllProfessionsSortDescending then
return a.name > b.name
end
return a.name < b.name
end )
end
for _ , craft in ipairs ( craftList ) do
local spellID = craft.spellID
local craftName = craft.name
if not numAvailableAllCache [ spellID ] then
local numAvailableAll = math.huge
if spellID and TSM.db . realm.crafts [ spellID ] then
for itemString , quantity in pairs ( TSM.db . realm.crafts [ spellID ] . mats ) do
numAvailableAll = min ( numAvailableAll , floor ( ( inventoryTotals [ itemString ] or 0 ) / quantity ) )
end
end
if numAvailableAll ~= math.huge then
numAvailableAllCache [ spellID ] = numAvailableAll
end
end
local available = craft.available or 0
local displayName = craftName
local costText
local profitText
local cost , _ , profit = craft.cost , craft.buyout , craft.profit
if cost and cost > 0 then
costText = TSMAPI : FormatTextMoney ( cost , TSMAPI.Design : GetInlineColor ( " link " ) )
else
costText = " --- "
end
if profit then
if profit < 0 then
profitText = " |cffff0000-|r " .. TSMAPI : FormatTextMoney ( - profit , " |cffff0000 " )
else
profitText = TSMAPI : FormatTextMoney ( profit , " |cff00ff00 " )
end
else
profitText = " --- "
end
local profitPercent = " --- "
if profit and cost and cost > 0 then
profitPercent = craft.profitPercent
if profit < 0 then
profitPercent = format ( " %s%.0f%%|r " , " |cffff0000 " , profitPercent )
else
profitPercent = format ( " %s%.0f%%|r " , " |cff00ff00 " , profitPercent )
end
end
tinsert ( stData , {
cols = {
{ value = available } ,
{ value = displayName } ,
{ value = costText or " " } ,
{ value = profitText or " " } ,
{ value = profitPercent or " " } ,
} ,
spellID = spellID ,
profession = craft.profession ,
} )
end
local frame = GUI.frame . content.professionsTab
frame.st : SetData ( stData )
return
end
local collapseAllRow = {
cols = {
{ value = " " } ,
{
value = " |cff " .. RGBPercToHex ( TradeSkillTypeColor.header ) .. ALL .. " [ " .. ( TradeSkillCollapseAllButton.collapsed and " + " or " - " ) .. " ]|r " ,
} ,
{
value = " " ,
} ,
{
value = " " ,
} ,
{ value = " " } ,
{ value = " " } ,
{ value = " " } ,
} ,
isCollapseAll = true ,
}
tinsert ( stData , collapseAllRow )
local ts = " "
local numAvailableAllCache = { }
local inventoryTotals = select ( 4 , TSM.Inventory : GetTotals ( ) )
for i = 1 , GetNumTradeSkills ( ) do
-- local skillName, skillType, numAvailable, isExpanded, _, numSkillUps, _, showProgressBar, currentRank, maxRank = GetTradeSkillInfo(i)
local skillName , skillType , numAvailable , isExpanded , _ = GetTradeSkillInfo ( i )
@ -1580,50 +1848,29 @@ function GUI:UpdateProfessionsTabST()
end
end
if numAvailable > 0 or ( numAvailableAllCache [ spellID ] and numAvailableAllCache [ spellID ] > 0 ) then
local availableText = numAvailable .. " ( " .. ( numAvailableAllCache [ spellID ] or 0 ) .. " ) "
skillName = ts .. " |cff " .. RGBPercToHex ( TradeSkillTypeColor [ skillType ] ) .. skillName .. " [ " .. availableText .. " ]|r "
else
local available = numAvailableAllCache [ spellID ] or 0
skillName = ts .. " |cff " .. RGBPercToHex ( TradeSkillTypeColor [ skillType ] ) .. skillName .. " |r "
end
local priceText = priceTextCache [ spellID ]
local cost , buyout , profit = TSM.Cost : GetCraftPrices ( spellID )
if spellID and not priceText then
--local cost, buyout, profit = TSM.Cost:GetCraftPrices(spellID)
if TSM.db . global.priceColumn == 1 then -- Crafting Cost
local costText
local profitText
local cost , _ , profit = TSM.Cost : GetCraftPrices ( spellID )
if cost and cost > 0 then
priceText = TSMAPI : FormatTextMoney ( cost , TSMAPI.Design : GetInlineColor ( " link " ) )
end
elseif TSM.db . global.priceColumn == 2 then -- Item Value
if buyout and buyout > 0 then
priceText = TSMAPI : FormatTextMoney ( buyout , TSMAPI.Design : GetInlineColor ( " link " ) )
costText = TSMAPI : FormatTextMoney ( cost , TSMAPI.Design : GetInlineColor ( " link " ) )
else
costText = " --- "
end
elseif TSM.db . global.priceColumn == 3 then -- Profit
if profit then
-- if profit < 0 then
-- priceText = "|cffff0000-|r" .. TSMAPI:FormatTextMoney(-profit, "|cffff0000") .. format(" (%s%.0f%%|r)", "|cffff0000", profitPercent)
-- else
-- priceText = TSMAPI:FormatTextMoney(profit, "|cff00ff00") .. format(" (%s%.0f%%|r)", "|cff00ff00", profitPercent)
-- end
if profit < 0 then
price Text = " |cffff0000-|r " .. TSMAPI : FormatTextMoney ( - profit , " |cffff0000 " )
profitText = " |cffff0000-|r " .. TSMAPI : FormatTextMoney ( - profit , " |cffff0000 " )
else
priceText = TSMAPI : FormatTextMoney ( profit , " |cff00ff00 " )
end
end
profitText = TSMAPI : FormatTextMoney ( profit , " |cff00ff00 " )
end
if priceText then
priceTextCache [ spellID ] = priceText
else
priceText = " --- "
end
profitText = " --- "
end
local profitPercent = " --- "
if profit then
if profit and cost and cost > 0 then
profitPercent = profit / cost * 100
if profit < 0 then
profitPercent = format ( " %s%.0f%%|r " , " |cffff0000 " , profitPercent )
@ -1634,11 +1881,17 @@ function GUI:UpdateProfessionsTabST()
local row = {
cols = {
{
value = spellID and available or " " ,
} ,
{
value = skillName ,
} ,
{
value = spellID and priceText or " " ,
value = spellID and costText or " " ,
} ,
{
value = spellID and profitText or " " ,
} ,
{
value = spellID and profitPercent or " " ,
@ -1665,7 +1918,12 @@ function GUI:UpdateSelectedTradeSkill(forceUpdate)
local frame = GUI.frame . content.professionsTab
TradeSkillFrame.selectedSkill = TradeSkillFrame.selectedSkill or 1
if forceUpdate or frame.st : GetSelection ( ) - 1 ~= TradeSkillFrame.selectedSkill then
if TSM.db . global.showAllProfessions then
frame.craftInfoFrame : SetTradeSkillIndex ( TradeSkillFrame.selectedSkill )
return
end
local selection = frame.st : GetSelection ( ) or 0
if forceUpdate or selection - 1 ~= TradeSkillFrame.selectedSkill then
frame.st : SetSelection ( TradeSkillFrame.selectedSkill + 1 )
frame.craftInfoFrame : SetTradeSkillIndex ( TradeSkillFrame.selectedSkill )
end