Skip to content

Commit e34fc6f

Browse files
committed
1 parent b9aa7fb commit e34fc6f

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

src/Classes/ItemsTab.lua

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,6 +2636,92 @@ function ItemsTabClass:AddCustomModifierToDisplayItem()
26362636
local controls = { }
26372637
local sourceList = { }
26382638
local modList = { }
2639+
local sortList = { { label = "Default", stat = nil } }
2640+
local sortTransforms = { }
2641+
for _, entry in ipairs(data.powerStatList) do
2642+
if entry.stat and not entry.ignoreForNodes then
2643+
t_insert(sortList, { label = entry.label, stat = entry.stat })
2644+
sortTransforms[entry.stat] = entry.transform
2645+
end
2646+
end
2647+
local function setDefaultSortOrder()
2648+
for index, listMod in ipairs(modList) do
2649+
listMod.defaultSortOrder = index
2650+
listMod.sortValue = nil
2651+
listMod.sortValues = nil
2652+
end
2653+
end
2654+
local function getOutputStatValue(output, stat)
2655+
if stat == "FullDPS" then
2656+
if output[stat] ~= nil then
2657+
return output[stat]
2658+
end
2659+
if output.Minion and output.Minion.CombinedDPS ~= nil then
2660+
return output.Minion.CombinedDPS
2661+
end
2662+
end
2663+
if output.Minion and output.Minion[stat] ~= nil then
2664+
return output.Minion[stat]
2665+
end
2666+
if output[stat] ~= nil then
2667+
return output[stat]
2668+
end
2669+
return 0
2670+
end
2671+
local function getSortValue(listMod, stat, calcFunc, slotName, useFullDPS)
2672+
listMod.sortValues = listMod.sortValues or { }
2673+
if listMod.sortValues[stat] ~= nil then
2674+
return listMod.sortValues[stat]
2675+
end
2676+
local item = new("Item", self.displayItem:BuildRaw())
2677+
item.id = self.displayItem.id
2678+
for _, line in ipairs(listMod.mod) do
2679+
t_insert(item.explicitModLines, { line = checkLineForAllocates(line, self.build.spec.nodes), modTags = listMod.mod.modTags, [listMod.type] = true })
2680+
end
2681+
item:BuildAndParseRaw()
2682+
local output = calcFunc({ repSlotName = slotName, repItem = item }, useFullDPS)
2683+
local value = getOutputStatValue(output, stat)
2684+
if sortTransforms[stat] then
2685+
value = sortTransforms[stat](value)
2686+
end
2687+
listMod.sortValues[stat] = value
2688+
return value
2689+
end
2690+
local function applySort(stat, selectFirst)
2691+
if not controls.modSelect or not controls.modSelect:IsShown() then
2692+
return
2693+
end
2694+
local selected = not selectFirst and modList[controls.modSelect.selIndex] or nil
2695+
if stat then
2696+
local slotName = self.displayItem:GetPrimarySlot()
2697+
local calcFunc = self.build.calcsTab:GetMiscCalculator()
2698+
local useFullDPS = stat == "FullDPS"
2699+
for _, listMod in ipairs(modList) do
2700+
listMod.sortValue = getSortValue(listMod, stat, calcFunc, slotName, useFullDPS)
2701+
end
2702+
table.sort(modList, function(a, b)
2703+
if a.sortValue ~= b.sortValue then
2704+
return a.sortValue > b.sortValue
2705+
end
2706+
return (a.defaultSortOrder or 0) < (b.defaultSortOrder or 0)
2707+
end)
2708+
else
2709+
table.sort(modList, function(a, b)
2710+
return (a.defaultSortOrder or 0) < (b.defaultSortOrder or 0)
2711+
end)
2712+
end
2713+
controls.modSelect:UpdateSearch()
2714+
if selected then
2715+
for index, listMod in ipairs(modList) do
2716+
if listMod == selected then
2717+
controls.modSelect.selIndex = index
2718+
break
2719+
end
2720+
end
2721+
else
2722+
controls.modSelect:SetSel(1, true)
2723+
end
2724+
end
26392725
---Mutates modList to contain mods from the specified source
26402726
---@param sourceId string @The crafting source id to build the list of mods for
26412727
local function buildMods(sourceId)
@@ -2720,8 +2806,21 @@ function ItemsTabClass:AddCustomModifierToDisplayItem()
27202806
controls.source = new("DropDownControl", {"TOPLEFT",nil,"TOPLEFT"}, {100, 20, 150, 18}, sourceList, function(index, value)
27212807
buildMods(value.sourceId)
27222808
controls.modSelect:SetSel(1)
2809+
if controls.sort then
2810+
applySort(controls.sort.list[controls.sort.selIndex].stat)
2811+
end
27232812
end)
27242813
controls.source.enabled = #sourceList > 1
2814+
controls.sortLabel = new("LabelControl", {"TOPRIGHT",nil,"TOPLEFT"}, {350, 20, 0, 16}, "^7Sort by:")
2815+
controls.sortLabel.shown = function()
2816+
return sourceList[controls.source.selIndex].sourceId ~= "CUSTOM"
2817+
end
2818+
controls.sort = new("DropDownControl", {"TOPLEFT",nil,"TOPLEFT"}, {355, 20, 240, 18}, sortList, function(index, value)
2819+
applySort(value.stat, true)
2820+
end)
2821+
controls.sort.shown = function()
2822+
return sourceList[controls.source.selIndex].sourceId ~= "CUSTOM"
2823+
end
27252824
controls.modSelectLabel = new("LabelControl", {"TOPRIGHT",nil,"TOPLEFT"}, {95, 45, 0, 16}, "^7Modifier:")
27262825
controls.modSelect = new("DropDownControl", {"TOPLEFT",nil,"TOPLEFT"}, {100, 45, 600, 18}, modList)
27272826
controls.modSelect.shown = function()

src/Classes/ItemsTab.lua.rej

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
diff a/src/Classes/ItemsTab.lua b/src/Classes/ItemsTab.lua (rejected hunks)
2+
@@ -2846,6 +2927,7 @@ function ItemsTabClass:AddCustomModifierToDisplayItem()
3+
end
4+
end)
5+
end
6+
+ setDefaultSortOrder()
7+
end
8+
if self.displayItem.type ~= "Tincture" and self.displayItem.type ~= "Graft" then
9+
if self.displayItem.type ~= "Jewel" then

0 commit comments

Comments
 (0)