Skip to content

Commit 3458d28

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 8ca83d8 commit 3458d28

4 files changed

Lines changed: 99 additions & 52 deletions

File tree

src/Classes/ItemsTab.lua

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

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: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,14 +1105,11 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
11051105
local item = new("Item", result.item_string)
11061106
tooltip:Clear()
11071107
if slotTbl.slotName == "Watcher's Eye" then
1108-
local firstValidSlot = self:findValidSlotForWatchersEye()
1109-
local currentItem = firstValidSlot.selItemId ~= 0 and self.itemsTab.items[firstValidSlot.selItemId]
1110-
local eyeEquipped = currentItem and currentItem.name:find("Watcher's Eye")
1111-
-- for watcher's eye we can compare to an already existing one, or
1112-
-- default to comparing with all active sockets
1113-
self.itemsTab:AddItemTooltip(tooltip, item, eyeEquipped and firstValidSlot or nil)
1108+
-- for watcher's eye we don't have a target slot. this will also
1109+
-- mean we compare against an existing watcher's eye if one exists
1110+
self.itemsTab:AddItemTooltip(tooltip, item, nil)
11141111
else
1115-
self.itemsTab:AddItemTooltip(tooltip, item, slotTbl)
1112+
self.itemsTab:AddItemTooltip(tooltip, item, activeSlot)
11161113
end
11171114
addMegalomaniacCompareToTooltipIfApplicable(tooltip, pb_index)
11181115
tooltip:AddSeparator(10)
@@ -1141,17 +1138,11 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
11411138
-- item.baseName is nil and throws error in the following AddItemTooltip func
11421139
-- if the item is unidentified
11431140
local item = new("Item", item_string)
1144-
-- for watcher's eye we can compare to an already existing one, or
1145-
-- default to comparing with all active sockets
11461141
if slotTbl.slotName == "Watcher's Eye" then
1147-
local firstValidSlot = self:findValidSlotForWatchersEye()
1148-
local currentItem = firstValidSlot.selItemId ~= 0 and self.itemsTab.items[firstValidSlot.selItemId]
1149-
local eyeEquipped = currentItem and currentItem.name:find("Watcher's Eye")
1150-
-- for watcher's eye we can compare to an already existing one, or
1151-
-- default to comparing with all active sockets
1152-
self.itemsTab:AddItemTooltip(tooltip, item, eyeEquipped and firstValidSlot or nil, true)
1142+
-- we have no comparison slot for the watcher's eye
1143+
self.itemsTab:AddItemTooltip(tooltip, item, nil, true)
11531144
else
1154-
self.itemsTab:AddItemTooltip(tooltip, item, slotTbl, true)
1145+
self.itemsTab:AddItemTooltip(tooltip, item, activeSlot, true)
11551146
end
11561147
addMegalomaniacCompareToTooltipIfApplicable(tooltip, selected_result_index)
11571148
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)