@@ -3996,48 +3996,104 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode)
39963996 t_insert (compareSlots , slot )
39973997 end
39983998 end
3999- table.sort (compareSlots , function (a , b )
4000- if a ~= b then
4001- if slot == a then
4002- return true
4003- end
4004- if slot == b then
4005- return false
4006- end
4007- end
4008- if a .selItemId ~= b .selItemId then
4009- if item == self .items [a .selItemId ] then
4010- return true
4011- end
4012- if item == self .items [b .selItemId ] then
4013- return false
4014- end
3999+
4000+ tooltip :AddLine (14 , colorCodes .TIP .. " Tip: Press Ctrl+D to disable the display of stat differences." )
4001+
4002+ local function getReplacedItemAndOutput (compareSlot )
4003+ local selItem = self .items [compareSlot .selItemId ]
4004+ local output = calcFunc ({ repSlotName = compareSlot .slotName , repItem = item ~= selItem and item or nil })
4005+ return selItem , output
4006+ end
4007+ local function addCompareForSlot (compareSlot , selItem , output )
4008+ if not selItem or not output then
4009+ selItem , output = getReplacedItemAndOutput (compareSlot )
40154010 end
4016- local aNum = tonumber (a .slotName :match (" %d+" ))
4017- local bNum = tonumber (b .slotName :match (" %d+" ))
4018- if aNum and bNum then
4019- return aNum < bNum
4011+ local header
4012+ if item == selItem then
4013+ header = " ^7Removing this item from " .. compareSlot .label .. " will give you:"
40204014 else
4021- return a . slotName < b . slotName
4015+ header = string.format ( " ^7Equipping this item in %s will give you:%s " , compareSlot . label or compareSlot . slotName , selItem and " \n (replacing " .. colorCodes [ selItem . rarity ] .. selItem . name .. " ^7) " or " " )
40224016 end
4023- end )
4017+ self .build :AddStatComparesToTooltip (tooltip , calcBase , output , header )
4018+ end
40244019
4025- -- Add comparisons for each slot
4026- for _ , compareSlot in pairs (compareSlots ) do
4027- if not main .slotOnlyTooltips or (slot and (slot .nodeId == compareSlot .nodeId or slot .slotName == compareSlot .slotName )) or not slot or slot == compareSlot then
4028- local selItem = self .items [compareSlot .selItemId ]
4029- local output = calcFunc ({ repSlotName = compareSlot .slotName , repItem = item ~= selItem and item or nil })
4030- local header
4031- if item == selItem then
4032- header = " ^7Removing this item from " .. compareSlot .label .. " will give you:"
4033- else
4034- header = string.format (" ^7Equipping this item in %s will give you:%s" , compareSlot .label , selItem and " \n (replacing " .. colorCodes [selItem .rarity ].. selItem .name .. " ^7)" or " " )
4020+ -- if we have a specific slot to compare to, and the user has "Show
4021+ -- tooltips only for affected slots" checked, we can just compare that
4022+ -- one slot
4023+ if main .slotOnlyTooltips and slot then
4024+ addCompareForSlot (slot )
4025+ return
4026+ end
4027+
4028+
4029+ local slots = {}
4030+ local isUnique = item .rarity == " UNIQUE" or item .rarity == " RELIC"
4031+ local currentSameUniqueCount = 0
4032+ for _ , compareSlot in ipairs (compareSlots ) do
4033+ local selItem , output = getReplacedItemAndOutput (compareSlot )
4034+ local isSameUnique = isUnique and selItem and item .name == selItem .name
4035+ if isUnique and isSameUnique and item .limit then
4036+ currentSameUniqueCount = currentSameUniqueCount + 1
4037+ end
4038+ table.insert (slots ,
4039+ { selItem = selItem , output = output , compareSlot = compareSlot , isSameUnique = isSameUnique })
4040+ end
4041+
4042+ -- limited uniques: only compare to slots with the same item if more don't fit
4043+ if currentSameUniqueCount == item .limit then
4044+ for _ , slotEntry in ipairs (slots ) do
4045+ if slotEntry .isSameUnique then
4046+ addCompareForSlot (slotEntry .compareSlot , slotEntry .selItem , slotEntry .output )
4047+ end
4048+ end
4049+ return
4050+ end
4051+
4052+
4053+ -- either the same unique or same base type
4054+ local function similar (compareItem , sameUnique )
4055+ -- empty slot
4056+ if not compareItem then return 0 end
4057+
4058+ local sameBaseType = not isUnique
4059+ and compareItem .rarity ~= " UNIQUE" and compareItem .rarity ~= " RELIC"
4060+ and item .base .type == compareItem .base .type
4061+ and item .base .subType == compareItem .base .subType
4062+ if sameBaseType or sameUnique then
4063+ return 1
4064+ else
4065+ return 0
4066+ end
4067+ end
4068+ -- sort by:
4069+ -- 1. empty sockets
4070+ -- 2. same base group jewel or unique
4071+ -- 3. DPS
4072+ -- 4. EHP
4073+ local function sortFunc (a , b )
4074+ if a == b then return end
4075+
4076+ local aParams = { a .compareSlot .selItemId == 0 and 1 or 0 , similar (a .selItem , a .isSameUnique ), a .output .FullDPS , a .output .CombinedDPS , a .output .TotalEHP , a .compareSlot .label }
4077+ local bParams = { b .compareSlot .selItemId == 0 and 1 or 0 , similar (b .selItem , b .isSameUnique ), b .output .FullDPS , b
4078+ .output .CombinedDPS , b .output .TotalEHP , b .compareSlot .label }
4079+ for i = 1 , # aParams do
4080+ if aParams [i ] == nil or bParams [i ] == nil then
4081+ -- continue
4082+ elseif aParams [i ] > bParams [i ] then
4083+ return true
4084+ elseif aParams [i ] < bParams [i ] then
4085+ return false
40354086 end
4036- self .build :AddStatComparesToTooltip (tooltip , calcBase , output , header )
40374087 end
4088+ return true
4089+ end
4090+ table.sort (slots , sortFunc )
4091+
4092+ for _ , slotEntry in ipairs (slots ) do
4093+ addCompareForSlot (slotEntry .compareSlot , slotEntry .selItem , slotEntry .output )
40384094 end
4095+
40394096 end
4040- tooltip :AddLine (14 , colorCodes .TIP .. " Tip: Press Ctrl+D to disable the display of stat differences." )
40414097
40424098 if launch .devModeAlt then
40434099 -- Modifier debugging info
0 commit comments