@@ -2698,6 +2698,87 @@ function ItemsTabClass:AddCustomModifierToDisplayItem()
26982698 local controls = { }
26992699 local sourceList = { }
27002700 local modList = { }
2701+ local sortList = { { label = " Default" , stat = nil } }
2702+ for _ , entry in ipairs (data .powerStatList ) do
2703+ if entry .stat and not entry .ignoreForNodes then
2704+ t_insert (sortList , { label = entry .label , stat = entry .stat })
2705+ end
2706+ end
2707+ local function setDefaultSortOrder ()
2708+ for index , listMod in ipairs (modList ) do
2709+ listMod .defaultSortOrder = index
2710+ listMod .sortValue = nil
2711+ listMod .sortValues = nil
2712+ end
2713+ end
2714+ local function getOutputStatValue (output , stat )
2715+ if stat == " FullDPS" then
2716+ if output [stat ] ~= nil then
2717+ return output [stat ]
2718+ end
2719+ if output .Minion and output .Minion .CombinedDPS ~= nil then
2720+ return output .Minion .CombinedDPS
2721+ end
2722+ end
2723+ if output .Minion and output .Minion [stat ] ~= nil then
2724+ return output .Minion [stat ]
2725+ end
2726+ if output [stat ] ~= nil then
2727+ return output [stat ]
2728+ end
2729+ return 0
2730+ end
2731+ local function getSortValue (listMod , stat , calcFunc , slotName , useFullDPS )
2732+ listMod .sortValues = listMod .sortValues or { }
2733+ if listMod .sortValues [stat ] ~= nil then
2734+ return listMod .sortValues [stat ]
2735+ end
2736+ local item = new (" Item" , self .displayItem :BuildRaw ())
2737+ item .id = self .displayItem .id
2738+ for _ , line in ipairs (listMod .mod ) do
2739+ t_insert (item .explicitModLines , { line = checkLineForAllocates (line , self .build .spec .nodes ), modTags = listMod .mod .modTags , [listMod .type ] = true })
2740+ end
2741+ item :BuildAndParseRaw ()
2742+ local output = calcFunc ({ repSlotName = slotName , repItem = item }, useFullDPS )
2743+ local value = getOutputStatValue (output , stat )
2744+ listMod .sortValues [stat ] = value
2745+ return value
2746+ end
2747+ local function applySort (stat , selectFirst )
2748+ if not controls .modSelect or not controls .modSelect :IsShown () then
2749+ return
2750+ end
2751+ local selected = not selectFirst and modList [controls .modSelect .selIndex ] or nil
2752+ if stat then
2753+ local slotName = self .displayItem :GetPrimarySlot ()
2754+ local calcFunc = self .build .calcsTab :GetMiscCalculator ()
2755+ local useFullDPS = stat == " FullDPS"
2756+ for _ , listMod in ipairs (modList ) do
2757+ listMod .sortValue = getSortValue (listMod , stat , calcFunc , slotName , useFullDPS )
2758+ end
2759+ table.sort (modList , function (a , b )
2760+ if a .sortValue ~= b .sortValue then
2761+ return a .sortValue > b .sortValue
2762+ end
2763+ return (a .defaultSortOrder or 0 ) < (b .defaultSortOrder or 0 )
2764+ end )
2765+ else
2766+ table.sort (modList , function (a , b )
2767+ return (a .defaultSortOrder or 0 ) < (b .defaultSortOrder or 0 )
2768+ end )
2769+ end
2770+ controls .modSelect :UpdateSearch ()
2771+ if selected then
2772+ for index , listMod in ipairs (modList ) do
2773+ if listMod == selected then
2774+ controls .modSelect .selIndex = index
2775+ break
2776+ end
2777+ end
2778+ else
2779+ controls .modSelect :SetSel (1 , true )
2780+ end
2781+ end
27012782 --- Mutates modList to contain mods from the specified source
27022783 --- @param sourceId string @The crafting source id to build the list of mods for
27032784 local function buildMods (sourceId )
@@ -2846,6 +2927,7 @@ function ItemsTabClass:AddCustomModifierToDisplayItem()
28462927 end
28472928 end )
28482929 end
2930+ setDefaultSortOrder ()
28492931 end
28502932 if self .displayItem .type ~= " Tincture" and self .displayItem .type ~= " Graft" then
28512933 if self .displayItem .type ~= " Jewel" then
@@ -2890,8 +2972,21 @@ function ItemsTabClass:AddCustomModifierToDisplayItem()
28902972 controls .source = new (" DropDownControl" , {" TOPLEFT" ,nil ," TOPLEFT" }, {100 , 20 , 150 , 18 }, sourceList , function (index , value )
28912973 buildMods (value .sourceId )
28922974 controls .modSelect :SetSel (1 )
2975+ if controls .sort then
2976+ applySort (controls .sort .list [controls .sort .selIndex ].stat )
2977+ end
28932978 end )
28942979 controls .source .enabled = # sourceList > 1
2980+ controls .sortLabel = new (" LabelControl" , {" TOPRIGHT" ,nil ," TOPLEFT" }, {350 , 20 , 0 , 16 }, " ^7Sort by:" )
2981+ controls .sortLabel .shown = function ()
2982+ return sourceList [controls .source .selIndex ].sourceId ~= " CUSTOM"
2983+ end
2984+ controls .sort = new (" DropDownControl" , {" TOPLEFT" ,nil ," TOPLEFT" }, {355 , 20 , 240 , 18 }, sortList , function (index , value )
2985+ applySort (value .stat , true )
2986+ end )
2987+ controls .sort .shown = function ()
2988+ return sourceList [controls .source .selIndex ].sourceId ~= " CUSTOM"
2989+ end
28952990 controls .modSelectLabel = new (" LabelControl" , {" TOPRIGHT" ,nil ," TOPLEFT" }, {95 , 45 , 0 , 16 }, " ^7Modifier:" )
28962991 controls .modSelect = new (" DropDownControl" , {" TOPLEFT" ,nil ," TOPLEFT" }, {100 , 45 , 600 , 18 }, modList )
28972992 controls .modSelect .shown = function ()
0 commit comments