@@ -320,78 +320,51 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
320320 local oneConfig = self .configTab and # self .configTab .configSetOrderList == 1
321321
322322 -- *** big block of variables shared across Copy, Delete, and Rename Loadouts
323- -- generic SetListControls so we can reuse copy and delete functions
324- local passiveSpecListControl = { }
325- local itemSetListControl = { }
326- local skillSetListControl = { }
327- local configSetListControl = { }
328323 -- list for dropdown
329324 local existingLoadoutsList = self .controls .buildLoadouts .existingLoadoutsList or {}
330325 local selectedLoadoutTitle = existingLoadoutsList [1 ] or " Default"
331326 -- set indices of each type for selected loadout for copy/delete/rename
332- local selectedLoadoutTreeId = { }
333- local selectedLoadoutItemId , selectedLoadoutItemIndex = { }, { } -- index needed for delete loadout
334- local selectedLoadoutSkillId , selectedLoadoutSkillIndex = { }, { }
335- local selectedLoadoutConfigId , selectedLoadoutConfigIndex = { }, { }
327+ -- local selectedLoadout.treeId = { }
328+ -- local selectedLoadout.itemId, selectedLoadout.itemIndex = { }, { } -- index needed for delete loadout
329+ -- local selectedLoadout.skillId, selectedLoadout.skillIndex = { }, { }
330+ -- local selectedLoadout.configId, selectedLoadout.configIndex = { }, { }
331+
332+ local selectedLoadout = { }
333+ selectedLoadout .treeId = { }
334+ selectedLoadout .itemId , selectedLoadout .itemIndex = { }, { } -- index needed for delete loadout
335+ selectedLoadout .skillId , selectedLoadout .skillIndex = { }, { }
336+ selectedLoadout .configId , selectedLoadout .configIndex = { }, { }
336337 local loadoutTitleOrIdentifier = " "
337338 -- ***
338339
339340 local function setSelectedLoadout (title )
340- selectedLoadoutTreeId , loadoutTitleOrIdentifier = findNamedSetId (self .treeTab :GetSpecList (), title , self .treeListSpecialLinks )
341+ selectedLoadout . treeId , loadoutTitleOrIdentifier = findNamedSetId (self .treeTab :GetSpecList (), title , self .treeListSpecialLinks )
341342 -- because we are creating the ListControls in real time, the SetOrderLists can get out of sync with the ItemSets, SkillSets, ConfigSets
342343 -- so we will loop until we find the title or identifier match from the selected loadout
343344 for index , id in pairs (self .itemsTab .itemSetOrderList ) do
344345 if (string.match (self .itemsTab .itemSets [id ].title or " Default" , " %b{}" ) == loadoutTitleOrIdentifier ) or ((self .itemsTab .itemSets [id ].title or " Default" ) == loadoutTitleOrIdentifier ) then
345- selectedLoadoutItemId = id
346- selectedLoadoutItemIndex = index
346+ selectedLoadout . itemId = id
347+ selectedLoadout . itemIndex = index
347348 break
348349 end
349350 end
350351 for index , id in pairs (self .skillsTab .skillSetOrderList ) do
351352 if (string.match (self .skillsTab .skillSets [id ].title or " Default" , " %b{}" ) == loadoutTitleOrIdentifier ) or ((self .skillsTab .skillSets [id ].title or " Default" ) == loadoutTitleOrIdentifier ) then
352- selectedLoadoutSkillId = id
353- selectedLoadoutSkillIndex = index
353+ selectedLoadout . skillId = id
354+ selectedLoadout . skillIndex = index
354355 break
355356 end
356357 end
357358 for index , id in pairs (self .configTab .configSetOrderList ) do
358359 if (string.match (self .configTab .configSets [id ].title or " Default" , " %b{}" ) == loadoutTitleOrIdentifier ) or ((self .configTab .configSets [id ].title or " Default" ) == loadoutTitleOrIdentifier ) then
359- selectedLoadoutConfigId = id
360- selectedLoadoutConfigIndex = index
360+ selectedLoadout . configId = id
361+ selectedLoadout . configIndex = index
361362 break
362363 end
363364 end
364365 end
365366 setSelectedLoadout (selectedLoadoutTitle )
366367
367- local function initListControls ()
368- passiveSpecListControl = new (" PassiveSpecListControl" , nil , nil , self .treeTab )
369- itemSetListControl = new (" ItemSetListControl" , nil , nil , self .itemsTab )
370- skillSetListControl = new (" SkillSetListControl" , nil , nil , self .skillsTab )
371- configSetListControl = new (" ConfigSetListControl" , nil , nil , self .configTab )
372- end
373-
374- local function copyLoadout (loadoutTitle )
375- initListControls ()
376-
377- local oldSpec = self .treeTab .specList [selectedLoadoutTreeId ]
378- local newSpec = passiveSpecListControl .controls .copy .onClick (oldSpec )
379- t_insert (self .treeTab .specList , newSpec )
380- newSpec .title = loadoutTitle
381-
382- local newItemSet = itemSetListControl .controls .copy .onClick (selectedLoadoutItemId )
383- t_insert (self .itemsTab .itemSetOrderList , newItemSet .id )
384- newItemSet .title = loadoutTitle
385-
386- local newSkillSet = skillSetListControl .controls .copy .onClick (selectedLoadoutSkillId )
387- t_insert (self .skillsTab .skillSetOrderList , newSkillSet .id )
388- newSkillSet .title = loadoutTitle
389-
390- local newConfigSet = configSetListControl .controls .copy .onClick (selectedLoadoutConfigId )
391- t_insert (self .configTab .configSetOrderList , newConfigSet .id )
392- newConfigSet .title = loadoutTitle
393- end
394-
395368 local popup -- used for SelectControl to autofocus New, Rename, and Copy EditControls
396369 if value == " ^7^7Loadouts:" or value == " ^7^7-----" then
397370 self .controls .buildLoadouts :SetSel (1 )
@@ -417,27 +390,7 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
417390 createFromExistingSets = state
418391 end , " If unchecked, a loadout of empty sets will be created." )
419392 controls .save = new (" ButtonControl" , nil , {- 45 , 100 , 80 , 20 }, " Create" , function ()
420- local loadoutTitle = controls .loadoutName .buf
421- -- make a copy so we don't break any existing loadouts if any of their sets are currently active
422- if createFromExistingSets then
423- copyLoadout (loadoutTitle )
424- else
425- local newSpec = new (" PassiveSpec" , self , latestTreeVersion )
426- t_insert (self .treeTab .specList , newSpec )
427- newSpec .title = loadoutTitle
428-
429- local itemSet = self .itemsTab :NewItemSet (# self .itemsTab .itemSets + 1 )
430- t_insert (self .itemsTab .itemSetOrderList , itemSet .id )
431- itemSet .title = loadoutTitle
432-
433- local skillSet = self .skillsTab :NewSkillSet (# self .skillsTab .skillSets + 1 )
434- t_insert (self .skillsTab .skillSetOrderList , skillSet .id )
435- skillSet .title = loadoutTitle
436-
437- local configSet = self .configTab :NewConfigSet (# self .configTab .configSets + 1 )
438- t_insert (self .configTab .configSetOrderList , configSet .id )
439- configSet .title = loadoutTitle
440- end
393+ self :NewLoadout (createFromExistingSets , controls .loadoutName .buf , selectedLoadout )
441394 self :SyncLoadouts ()
442395 self .modFlag = true
443396 main :ClosePopup ()
@@ -463,12 +416,7 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
463416 end )
464417
465418 controls .rename = new (" ButtonControl" , nil , {- 45 , 125 , 80 , 20 }, " Rename" , function ()
466- local title = controls .loadoutName .buf
467- self .treeTab .specList [selectedLoadoutTreeId ].title = title
468- self .itemsTab .itemSets [selectedLoadoutItemId ].title = title
469- self .skillsTab .skillSets [selectedLoadoutSkillId ].title = title
470- self .configTab .configSets [selectedLoadoutConfigId ].title = title
471-
419+ self :RenameLoadout (controls .loadoutName .buf , selectedLoadout )
472420 self :SyncLoadouts ()
473421 self .modFlag = true
474422 main :ClosePopup ()
@@ -496,7 +444,7 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
496444 end )
497445
498446 controls .copy = new (" ButtonControl" , nil , {- 45 , 125 , 80 , 20 }, " Copy" , function ()
499- copyLoadout (controls .loadoutName .buf )
447+ self : CopyLoadout (controls .loadoutName .buf , selectedLoadout )
500448 self :SyncLoadouts ()
501449 self .modFlag = true
502450 main :ClosePopup ()
@@ -520,19 +468,13 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild, importLin
520468
521469 controls .delete = new (" ButtonControl" , nil , {- 45 , 85 , 80 , 20 }, " Delete" , function ()
522470 main :OpenConfirmPopup (" Delete All" , " Are you sure you want to delete this loadout?" , " Delete" , function ()
523- initListControls ()
524-
525- passiveSpecListControl :DeleteByIndex (selectedLoadoutTreeId )
526- itemSetListControl :DeleteById (selectedLoadoutItemIndex , selectedLoadoutItemId )
527- skillSetListControl :DeleteById (selectedLoadoutSkillIndex , selectedLoadoutSkillId )
528- configSetListControl :DeleteById (selectedLoadoutConfigIndex , selectedLoadoutConfigId )
529-
471+ self :DeleteLoadout (selectedLoadout )
530472 self :SyncLoadouts ()
531473 self .modFlag = true
532474 main :ClosePopup ()
533475 end )
534476 end )
535- controls .delete .enabled = # existingLoadoutsList > 0
477+ controls .delete .enabled = # existingLoadoutsList > 1
536478 controls .cancel = new (" ButtonControl" , nil , {45 , 85 , 80 , 20 }, " Cancel" , function ()
537479 main :ClosePopup ()
538480 end )
@@ -1030,6 +972,79 @@ function buildMode:SyncLoadouts()
1030972 return treeList , itemList , skillList , configList
1031973end
1032974
975+ -- generic SetListControls so we can reuse copy and delete functions for Loadouts
976+ local passiveSpecListControl = { }
977+ local itemSetListControl = { }
978+ local skillSetListControl = { }
979+ local configSetListControl = { }
980+
981+ function buildMode :NewLoadout (createFromExistingSets , loadoutTitle , selectedLoadout )
982+ -- make a copy so we don't break any existing loadouts if any of their sets are currently active
983+ if createFromExistingSets then
984+ self :CopyLoadout (loadoutTitle , selectedLoadout )
985+ else
986+ local newSpec = new (" PassiveSpec" , self , latestTreeVersion )
987+ t_insert (self .treeTab .specList , newSpec )
988+ newSpec .title = loadoutTitle
989+
990+ local itemSet = self .itemsTab :NewItemSet (# self .itemsTab .itemSets + 1 )
991+ t_insert (self .itemsTab .itemSetOrderList , itemSet .id )
992+ itemSet .title = loadoutTitle
993+
994+ local skillSet = self .skillsTab :NewSkillSet (# self .skillsTab .skillSets + 1 )
995+ t_insert (self .skillsTab .skillSetOrderList , skillSet .id )
996+ skillSet .title = loadoutTitle
997+
998+ local configSet = self .configTab :NewConfigSet (# self .configTab .configSets + 1 )
999+ t_insert (self .configTab .configSetOrderList , configSet .id )
1000+ configSet .title = loadoutTitle
1001+ end
1002+ end
1003+
1004+ function buildMode :RenameLoadout (title , selectedLoadout )
1005+ self .treeTab .specList [selectedLoadout .treeId ].title = title
1006+ self .itemsTab .itemSets [selectedLoadout .itemId ].title = title
1007+ self .skillsTab .skillSets [selectedLoadout .skillId ].title = title
1008+ self .configTab .configSets [selectedLoadout .configId ].title = title
1009+ end
1010+
1011+ function buildMode :CopyLoadout (loadoutTitle , selectedLoadout )
1012+ self :InitLoadoutListControls ()
1013+
1014+ local oldSpec = self .treeTab .specList [selectedLoadout .treeId ]
1015+ local newSpec = passiveSpecListControl .controls .copy .onClick (oldSpec )
1016+ t_insert (self .treeTab .specList , newSpec )
1017+ newSpec .title = loadoutTitle
1018+
1019+ local newItemSet = itemSetListControl .controls .copy .onClick (selectedLoadout .itemId )
1020+ t_insert (self .itemsTab .itemSetOrderList , newItemSet .id )
1021+ newItemSet .title = loadoutTitle
1022+
1023+ local newSkillSet = skillSetListControl .controls .copy .onClick (selectedLoadout .skillId )
1024+ t_insert (self .skillsTab .skillSetOrderList , newSkillSet .id )
1025+ newSkillSet .title = loadoutTitle
1026+
1027+ local newConfigSet = configSetListControl .controls .copy .onClick (selectedLoadout .configId )
1028+ t_insert (self .configTab .configSetOrderList , newConfigSet .id )
1029+ newConfigSet .title = loadoutTitle
1030+ end
1031+
1032+ function buildMode :DeleteLoadout (selectedLoadout )
1033+ self :InitLoadoutListControls ()
1034+
1035+ passiveSpecListControl :DeleteByIndex (selectedLoadout .treeId )
1036+ itemSetListControl :DeleteById (selectedLoadout .itemIndex , selectedLoadout .itemId )
1037+ skillSetListControl :DeleteById (selectedLoadout .skillIndex , selectedLoadout .skillId )
1038+ configSetListControl :DeleteById (selectedLoadout .configIndex , selectedLoadout .configId )
1039+ end
1040+
1041+ function buildMode :InitLoadoutListControls ()
1042+ passiveSpecListControl = new (" PassiveSpecListControl" , nil , nil , self .treeTab )
1043+ itemSetListControl = new (" ItemSetListControl" , nil , nil , self .itemsTab )
1044+ skillSetListControl = new (" SkillSetListControl" , nil , nil , self .skillsTab )
1045+ configSetListControl = new (" ConfigSetListControl" , nil , nil , self .configTab )
1046+ end
1047+
10331048function buildMode :EstimatePlayerProgress ()
10341049 local PointsUsed , AscUsed , SecondaryAscUsed = self .spec :CountAllocNodes ()
10351050 local extra = self .calcsTab .mainOutput and self .calcsTab .mainOutput .ExtraPoints or 0
0 commit comments