Skip to content

Commit 51df964

Browse files
committed
Port jewel comparison tooltip socket sorting from pob1
1 parent 7ee6401 commit 51df964

3 files changed

Lines changed: 95 additions & 36 deletions

File tree

src/Classes/ItemsTab.lua

Lines changed: 93 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,49 +3435,108 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode)
34353435
t_insert(compareSlots, slot)
34363436
end
34373437
end
3438-
table.sort(compareSlots, function(a, b)
3439-
if a ~= b then
3440-
if slot == a then
3441-
return true
3442-
end
3443-
if slot == b then
3444-
return false
3438+
3439+
tooltip:AddLine(14, colorCodes.TIP .. "Tip: Press Ctrl+D to disable the display of stat differences.", "VAR")
3440+
3441+
local function getReplacedItemAndOutput(compareSlot)
3442+
local selItem = self.items[compareSlot.selItemId]
3443+
local output = calcFunc({ repSlotName = compareSlot.slotName, repItem = item ~= selItem and item or nil })
3444+
return selItem, output
3445+
end
3446+
local function addCompareForSlot(compareSlot, selItem, output)
3447+
if not selItem or not output then
3448+
selItem, output = getReplacedItemAndOutput(compareSlot)
3449+
end
3450+
local header
3451+
if item == selItem then
3452+
header = "^7Removing this item from " .. compareSlot.label .. " will give you:"
3453+
else
3454+
header = string.format("^7Equipping this item in %s will give you:%s",
3455+
compareSlot.label or compareSlot.slotName,
3456+
selItem and "\n(replacing " .. colorCodes[selItem.rarity] .. selItem.name .. "^7)" or "")
3457+
end
3458+
self.build:AddStatComparesToTooltip(tooltip, calcBase, output, header)
3459+
end
3460+
3461+
-- if we have a specific slot to compare to, and the user has "Show
3462+
-- tooltips only for affected slots" checked, we can just compare that
3463+
-- one slot
3464+
if main.slotOnlyTooltips and slot then
3465+
slot = type(slot) ~= "string" and slot or self.slots[slot]
3466+
if slot then addCompareForSlot(slot) end
3467+
return
3468+
end
3469+
3470+
3471+
local slots = {}
3472+
local isUnique = item.rarity == "UNIQUE" or item.rarity == "RELIC"
3473+
local currentSameUniqueCount = 0
3474+
for _, compareSlot in ipairs(compareSlots) do
3475+
local selItem, output = getReplacedItemAndOutput(compareSlot)
3476+
local isSameUnique = isUnique and selItem and item.name == selItem.name
3477+
if isUnique and isSameUnique and item.limit then
3478+
currentSameUniqueCount = currentSameUniqueCount + 1
3479+
end
3480+
table.insert(slots,
3481+
{ selItem = selItem, output = output, compareSlot = compareSlot, isSameUnique = isSameUnique })
3482+
end
3483+
3484+
-- limited uniques: only compare to slots with the same item if more don't fit
3485+
if currentSameUniqueCount == item.limit then
3486+
for _, slotEntry in ipairs(slots) do
3487+
if slotEntry.isSameUnique then
3488+
addCompareForSlot(slotEntry.compareSlot, slotEntry.selItem, slotEntry.output)
34453489
end
34463490
end
3447-
if a.selItemId ~= b.selItemId then
3448-
if item == self.items[a.selItemId] then
3491+
return
3492+
end
3493+
3494+
3495+
-- either the same unique or same base type
3496+
local function similar(compareItem, sameUnique)
3497+
-- empty slot
3498+
if not compareItem then return 0 end
3499+
3500+
local sameBaseType = not isUnique
3501+
and compareItem.rarity ~= "UNIQUE" and compareItem.rarity ~= "RELIC"
3502+
and item.base.type == compareItem.base.type
3503+
and item.base.subType == compareItem.base.subType
3504+
if sameBaseType or sameUnique then
3505+
return 1
3506+
else
3507+
return 0
3508+
end
3509+
end
3510+
-- sort by:
3511+
-- 1. empty sockets
3512+
-- 2. same base group jewel or unique
3513+
-- 3. DPS
3514+
-- 4. EHP
3515+
local function sortFunc(a, b)
3516+
if a == b then return end
3517+
3518+
local aParams = { a.compareSlot.selItemId == 0 and 1 or 0, similar(a.selItem, a.isSameUnique), a.output
3519+
.FullDPS, a.output.CombinedDPS, a.output.TotalEHP, a.compareSlot.label, a.compareSlot.slotName }
3520+
local bParams = { b.compareSlot.selItemId == 0 and 1 or 0, similar(b.selItem, b.isSameUnique), b.output
3521+
.FullDPS, b
3522+
.output.CombinedDPS, b.output.TotalEHP, b.compareSlot.label, b.compareSlot.slotName }
3523+
for i = 1, #aParams do
3524+
if aParams[i] == nil or bParams[i] == nil then
3525+
-- continue
3526+
elseif aParams[i] > bParams[i] then
34493527
return true
3450-
end
3451-
if item == self.items[b.selItemId] then
3528+
elseif aParams[i] < bParams[i] then
34523529
return false
34533530
end
34543531
end
3455-
local aNum = tonumber(a.slotName:match("%d+"))
3456-
local bNum = tonumber(b.slotName:match("%d+"))
3457-
if aNum and bNum then
3458-
return aNum < bNum
3459-
else
3460-
return a.slotName < b.slotName
3461-
end
3462-
end)
3532+
return false
3533+
end
3534+
table.sort(slots, sortFunc)
34633535

3464-
-- Add comparisons for each slot
3465-
for _, compareSlot in pairs(compareSlots) do
3466-
if not main.slotOnlyTooltips or (slot and (slot.nodeId == compareSlot.nodeId or slot.slotName == compareSlot.slotName)) or not slot or slot == compareSlot then
3467-
local selItem = self.items[compareSlot.selItemId]
3468-
local output = calcFunc({ repSlotName = compareSlot.slotName, repItem = item ~= selItem and item or nil})
3469-
local header
3470-
if item == selItem then
3471-
header = "^7Removing this item from "..compareSlot.label.." will give you:"
3472-
else
3473-
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 "")
3474-
end
3475-
self.build:AddStatComparesToTooltip(tooltip, calcBase, output, header)
3476-
end
3536+
for _, slotEntry in ipairs(slots) do
3537+
addCompareForSlot(slotEntry.compareSlot, slotEntry.selItem, slotEntry.output)
34773538
end
34783539
end
3479-
tooltip:AddLine(14, colorCodes.TIP.."Tip: Press Ctrl+D to disable the display of stat differences.", "VAR")
3480-
34813540
if launch.devModeAlt then
34823541
-- Modifier debugging info
34833542
tooltip:AddSeparator(10)

src/Classes/PassiveTreeView.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ function PassiveTreeViewClass:AddNodeTooltip(tooltip, node, build, incSmallPassi
13361336
if (node.type == "Socket" or node.containJewelSocket) and node.alloc then
13371337
local socket, jewel = build.itemsTab:GetSocketAndJewelForNodeID(node.id)
13381338
if jewel then
1339-
build.itemsTab:AddItemTooltip(tooltip, jewel, { nodeId = node.id })
1339+
build.itemsTab:AddItemTooltip(tooltip, jewel, socket)
13401340
if node.distanceToClassStart and node.distanceToClassStart > 0 then
13411341
tooltip:AddSeparator(14)
13421342
tooltip:AddLine(16, string.format("^7Distance to start: %d", node.distanceToClassStart))

src/Modules/Main.lua

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

10831083
nextRow()

0 commit comments

Comments
 (0)