Skip to content

Commit 4cf7ca2

Browse files
committed
Add more specific jewel tooltip comparison sorting by sorting by:
1. empty sockets 2. same base group jewel or same unique 3. DPS 4. EHP
1 parent d126ab7 commit 4cf7ca2

4 files changed

Lines changed: 94 additions & 38 deletions

File tree

src/Classes/ItemsTab.lua

Lines changed: 90 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/Classes/PassiveTreeView.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ function PassiveTreeViewClass:AddNodeTooltip(tooltip, node, build)
12231223
if node.type == "Socket" and node.alloc then
12241224
local socket, jewel = build.itemsTab:GetSocketAndJewelForNodeID(node.id)
12251225
if jewel then
1226-
build.itemsTab:AddItemTooltip(tooltip, jewel, { nodeId = node.id })
1226+
build.itemsTab:AddItemTooltip(tooltip, jewel, socket)
12271227
if node.distanceToClassStart and node.distanceToClassStart > 0 then
12281228
tooltip:AddSeparator(14)
12291229
tooltip:AddLine(16, string.format("^7Distance to start: %d", node.distanceToClassStart))

src/Classes/TradeQuery.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
10131013
local result = self.resultTbl[row_idx][pb_index]
10141014
local item = new("Item", result.item_string)
10151015
tooltip:Clear()
1016-
self.itemsTab:AddItemTooltip(tooltip, item, slotTbl)
1016+
self.itemsTab:AddItemTooltip(tooltip, item, activeSlot)
10171017
addMegalomaniacCompareToTooltipIfApplicable(tooltip, pb_index)
10181018
tooltip:AddSeparator(10)
10191019
tooltip:AddLine(16, string.format("^7Price: %s %s", result.amount, result.currency))
@@ -1041,7 +1041,7 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
10411041
-- item.baseName is nil and throws error in the following AddItemTooltip func
10421042
-- if the item is unidentified
10431043
local item = new("Item", item_string)
1044-
self.itemsTab:AddItemTooltip(tooltip, item, slotTbl, true)
1044+
self.itemsTab:AddItemTooltip(tooltip, item, activeSlot, true)
10451045
addMegalomaniacCompareToTooltipIfApplicable(tooltip, selected_result_index)
10461046
end
10471047
end

src/Modules/Main.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ function main:OpenOptionsPopup()
10321032
nextRow()
10331033
controls.slotOnlyTooltips = new("CheckBoxControl", { "TOPLEFT", nil, "TOPLEFT" }, { defaultLabelPlacementX, currentY, 20 }, "^7Show tooltips only for affected slots:", function(state)
10341034
self.slotOnlyTooltips = state
1035-
end)
1035+
end, "Shows comparisons in tooltips only for the slot you are currently placing the item in, instead of all slots.")
10361036
controls.slotOnlyTooltips.state = self.slotOnlyTooltips
10371037

10381038
nextRow()

0 commit comments

Comments
 (0)