@@ -2668,6 +2668,92 @@ function ItemsTabClass:AddCustomModifierToDisplayItem()
26682668 local controls = { }
26692669 local sourceList = { }
26702670 local modList = { }
2671+ local sortList = { { label = " Default" , stat = nil } }
2672+ local sortTransforms = { }
2673+ for _ , entry in ipairs (data .powerStatList ) do
2674+ if entry .stat and not entry .ignoreForNodes then
2675+ t_insert (sortList , { label = entry .label , stat = entry .stat })
2676+ sortTransforms [entry .stat ] = entry .transform
2677+ end
2678+ end
2679+ local function setDefaultSortOrder ()
2680+ for index , listMod in ipairs (modList ) do
2681+ listMod .defaultSortOrder = index
2682+ listMod .sortValue = nil
2683+ listMod .sortValues = nil
2684+ end
2685+ end
2686+ local function getOutputStatValue (output , stat )
2687+ if stat == " FullDPS" then
2688+ if output [stat ] ~= nil then
2689+ return output [stat ]
2690+ end
2691+ if output .Minion and output .Minion .CombinedDPS ~= nil then
2692+ return output .Minion .CombinedDPS
2693+ end
2694+ end
2695+ if output .Minion and output .Minion [stat ] ~= nil then
2696+ return output .Minion [stat ]
2697+ end
2698+ if output [stat ] ~= nil then
2699+ return output [stat ]
2700+ end
2701+ return 0
2702+ end
2703+ local function getSortValue (listMod , stat , calcFunc , slotName , useFullDPS )
2704+ listMod .sortValues = listMod .sortValues or { }
2705+ if listMod .sortValues [stat ] ~= nil then
2706+ return listMod .sortValues [stat ]
2707+ end
2708+ local item = new (" Item" , self .displayItem :BuildRaw ())
2709+ item .id = self .displayItem .id
2710+ for _ , line in ipairs (listMod .mod ) do
2711+ t_insert (item .explicitModLines , { line = checkLineForAllocates (line , self .build .spec .nodes ), modTags = listMod .mod .modTags , [listMod .type ] = true })
2712+ end
2713+ item :BuildAndParseRaw ()
2714+ local output = calcFunc ({ repSlotName = slotName , repItem = item }, useFullDPS )
2715+ local value = getOutputStatValue (output , stat )
2716+ if sortTransforms [stat ] then
2717+ value = sortTransforms [stat ](value )
2718+ end
2719+ listMod .sortValues [stat ] = value
2720+ return value
2721+ end
2722+ local function applySort (stat , selectFirst )
2723+ if not controls .modSelect or not controls .modSelect :IsShown () then
2724+ return
2725+ end
2726+ local selected = not selectFirst and modList [controls .modSelect .selIndex ] or nil
2727+ if stat then
2728+ local slotName = self .displayItem :GetPrimarySlot ()
2729+ local calcFunc = self .build .calcsTab :GetMiscCalculator ()
2730+ local useFullDPS = stat == " FullDPS"
2731+ for _ , listMod in ipairs (modList ) do
2732+ listMod .sortValue = getSortValue (listMod , stat , calcFunc , slotName , useFullDPS )
2733+ end
2734+ table.sort (modList , function (a , b )
2735+ if a .sortValue ~= b .sortValue then
2736+ return a .sortValue > b .sortValue
2737+ end
2738+ return (a .defaultSortOrder or 0 ) < (b .defaultSortOrder or 0 )
2739+ end )
2740+ else
2741+ table.sort (modList , function (a , b )
2742+ return (a .defaultSortOrder or 0 ) < (b .defaultSortOrder or 0 )
2743+ end )
2744+ end
2745+ controls .modSelect :UpdateSearch ()
2746+ if selected then
2747+ for index , listMod in ipairs (modList ) do
2748+ if listMod == selected then
2749+ controls .modSelect .selIndex = index
2750+ break
2751+ end
2752+ end
2753+ else
2754+ controls .modSelect :SetSel (1 , true )
2755+ end
2756+ end
26712757 --- Mutates modList to contain mods from the specified source
26722758 --- @param sourceId string @The crafting source id to build the list of mods for
26732759 local function buildMods (sourceId )
@@ -2719,6 +2805,7 @@ function ItemsTabClass:AddCustomModifierToDisplayItem()
27192805 end
27202806 end )
27212807 end
2808+ setDefaultSortOrder ()
27222809 end
27232810 if not self .displayItem .crafted then
27242811 t_insert (sourceList , { label = " Prefix" , sourceId = " PREFIX" })
@@ -2752,8 +2839,21 @@ function ItemsTabClass:AddCustomModifierToDisplayItem()
27522839 controls .source = new (" DropDownControl" , {" TOPLEFT" ,nil ," TOPLEFT" }, {100 , 20 , 150 , 18 }, sourceList , function (index , value )
27532840 buildMods (value .sourceId )
27542841 controls .modSelect :SetSel (1 )
2842+ if controls .sort then
2843+ applySort (controls .sort .list [controls .sort .selIndex ].stat , true )
2844+ end
27552845 end )
27562846 controls .source .enabled = # sourceList > 1
2847+ controls .sortLabel = new (" LabelControl" , {" TOPRIGHT" ,nil ," TOPLEFT" }, {350 , 20 , 0 , 16 }, " ^7Sort by:" )
2848+ controls .sortLabel .shown = function ()
2849+ return sourceList [controls .source .selIndex ].sourceId ~= " CUSTOM"
2850+ end
2851+ controls .sort = new (" DropDownControl" , {" TOPLEFT" ,nil ," TOPLEFT" }, {355 , 20 , 240 , 18 }, sortList , function (index , value )
2852+ applySort (value .stat , true )
2853+ end )
2854+ controls .sort .shown = function ()
2855+ return sourceList [controls .source .selIndex ].sourceId ~= " CUSTOM"
2856+ end
27572857 controls .modSelectLabel = new (" LabelControl" , {" TOPRIGHT" ,nil ," TOPLEFT" }, {95 , 45 , 0 , 16 }, " ^7Modifier:" )
27582858 controls .modSelect = new (" DropDownControl" , {" TOPLEFT" ,nil ," TOPLEFT" }, {100 , 45 , 600 , 18 }, modList )
27592859 controls .modSelect .shown = function ()
0 commit comments