@@ -4016,48 +4016,104 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode)
40164016 t_insert (compareSlots , slot )
40174017 end
40184018 end
4019- table.sort (compareSlots , function (a , b )
4020- if a ~= b then
4021- if slot == a then
4022- return true
4023- end
4024- if slot == b then
4025- return false
4026- end
4027- end
4028- if a .selItemId ~= b .selItemId then
4029- if item == self .items [a .selItemId ] then
4030- return true
4031- end
4032- if item == self .items [b .selItemId ] then
4033- return false
4034- end
4019+
4020+ tooltip :AddLine (14 , colorCodes .TIP .. " Tip: Press Ctrl+D to disable the display of stat differences." )
4021+
4022+ local function getReplacedItemAndOutput (compareSlot )
4023+ local selItem = self .items [compareSlot .selItemId ]
4024+ local output = calcFunc ({ repSlotName = compareSlot .slotName , repItem = item ~= selItem and item or nil })
4025+ return selItem , output
4026+ end
4027+ local function addCompareForSlot (compareSlot , selItem , output )
4028+ if not selItem or not output then
4029+ selItem , output = getReplacedItemAndOutput (compareSlot )
40354030 end
4036- local aNum = tonumber (a .slotName :match (" %d+" ))
4037- local bNum = tonumber (b .slotName :match (" %d+" ))
4038- if aNum and bNum then
4039- return aNum < bNum
4031+ local header
4032+ if item == selItem then
4033+ header = " ^7Removing this item from " .. compareSlot .label .. " will give you:"
40404034 else
4041- return a . slotName < b . slotName
4035+ 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 " " )
40424036 end
4043- end )
4037+ self .build :AddStatComparesToTooltip (tooltip , calcBase , output , header )
4038+ end
40444039
4045- -- Add comparisons for each slot
4046- for _ , compareSlot in pairs (compareSlots ) do
4047- if not main .slotOnlyTooltips or (slot and (slot .nodeId == compareSlot .nodeId or slot .slotName == compareSlot .slotName )) or not slot or slot == compareSlot then
4048- local selItem = self .items [compareSlot .selItemId ]
4049- local output = calcFunc ({ repSlotName = compareSlot .slotName , repItem = item ~= selItem and item or nil })
4050- local header
4051- if item == selItem then
4052- header = " ^7Removing this item from " .. compareSlot .label .. " will give you:"
4053- else
4054- 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 " " )
4040+ -- if we have a specific slot to compare to, and the user has "Show
4041+ -- tooltips only for affected slots" checked, we can just compare that
4042+ -- one slot
4043+ if main .slotOnlyTooltips and slot then
4044+ addCompareForSlot (slot )
4045+ return
4046+ end
4047+
4048+
4049+ local slots = {}
4050+ local isUnique = item .rarity == " UNIQUE" or item .rarity == " RELIC"
4051+ local currentSameUniqueCount = 0
4052+ for _ , compareSlot in ipairs (compareSlots ) do
4053+ local selItem , output = getReplacedItemAndOutput (compareSlot )
4054+ local isSameUnique = isUnique and selItem and item .name == selItem .name
4055+ if isUnique and isSameUnique and item .limit then
4056+ currentSameUniqueCount = currentSameUniqueCount + 1
4057+ end
4058+ table.insert (slots ,
4059+ { selItem = selItem , output = output , compareSlot = compareSlot , isSameUnique = isSameUnique })
4060+ end
4061+
4062+ -- limited uniques: only compare to slots with the same item if more don't fit
4063+ if currentSameUniqueCount == item .limit then
4064+ for _ , slotEntry in ipairs (slots ) do
4065+ if slotEntry .isSameUnique then
4066+ addCompareForSlot (slotEntry .compareSlot , slotEntry .selItem , slotEntry .output )
4067+ end
4068+ end
4069+ return
4070+ end
4071+
4072+
4073+ -- either the same unique or same base type
4074+ local function similar (compareItem , sameUnique )
4075+ -- empty slot
4076+ if not compareItem then return 0 end
4077+
4078+ local sameBaseType = not isUnique
4079+ and compareItem .rarity ~= " UNIQUE" and compareItem .rarity ~= " RELIC"
4080+ and item .base .type == compareItem .base .type
4081+ and item .base .subType == compareItem .base .subType
4082+ if sameBaseType or sameUnique then
4083+ return 1
4084+ else
4085+ return 0
4086+ end
4087+ end
4088+ -- sort by:
4089+ -- 1. empty sockets
4090+ -- 2. same base group jewel or unique
4091+ -- 3. DPS
4092+ -- 4. EHP
4093+ local function sortFunc (a , b )
4094+ if a == b then return end
4095+
4096+ 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 }
4097+ local bParams = { b .compareSlot .selItemId == 0 and 1 or 0 , similar (b .selItem , b .isSameUnique ), b .output .FullDPS , b
4098+ .output .CombinedDPS , b .output .TotalEHP , b .compareSlot .label }
4099+ for i = 1 , # aParams do
4100+ if aParams [i ] == nil or bParams [i ] == nil then
4101+ -- continue
4102+ elseif aParams [i ] > bParams [i ] then
4103+ return true
4104+ elseif aParams [i ] < bParams [i ] then
4105+ return false
40554106 end
4056- self .build :AddStatComparesToTooltip (tooltip , calcBase , output , header )
40574107 end
4108+ return true
4109+ end
4110+ table.sort (slots , sortFunc )
4111+
4112+ for _ , slotEntry in ipairs (slots ) do
4113+ addCompareForSlot (slotEntry .compareSlot , slotEntry .selItem , slotEntry .output )
40584114 end
4115+
40594116 end
4060- tooltip :AddLine (14 , colorCodes .TIP .. " Tip: Press Ctrl+D to disable the display of stat differences." )
40614117
40624118 if launch .devModeAlt then
40634119 -- Modifier debugging info
0 commit comments