44-- Item set list control.
55--
66local t_insert = table.insert
7+ local t_remove = table.remove
8+ local m_max = math.max
9+ local s_format = string.format
710
811local ItemSetListClass = newClass (" ItemSetListControl" , " ListControl" , function (self , anchor , rect , itemsTab )
912 self .ListControl (anchor , rect , 16 , " VERTICAL" , true , itemsTab .itemSetOrderList )
1013 self .itemsTab = itemsTab
11- self .itemSetService = new (" ItemSetService" , itemsTab )
1214 self .controls .copy = new (" ButtonControl" , {" BOTTOMLEFT" ,self ," TOP" }, {2 , - 4 , 60 , 18 }, " Copy" , function ()
13- self :CopyItemSet (self .selValue )
15+ local newSet = copyTable (itemsTab .itemSets [self .selValue ])
16+ newSet .id = 1
17+ while itemsTab .itemSets [newSet .id ] do
18+ newSet .id = newSet .id + 1
19+ end
20+ itemsTab .itemSets [newSet .id ] = newSet
21+ self :RenameSet (newSet , true )
1422 end )
1523 self .controls .copy .enabled = function ()
1624 return self .selValue ~= nil
@@ -22,68 +30,48 @@ local ItemSetListClass = newClass("ItemSetListControl", "ListControl", function(
2230 return self .selValue ~= nil and # self .list > 1
2331 end
2432 self .controls .rename = new (" ButtonControl" , {" BOTTOMRIGHT" ,self ," TOP" }, {- 2 , - 4 , 60 , 18 }, " Rename" , function ()
25- self :RenameItemSet ( self .selValue )
33+ self :RenameSet ( itemsTab . itemSets [ self .selValue ] )
2634 end )
2735 self .controls .rename .enabled = function ()
2836 return self .selValue ~= nil
2937 end
3038 self .controls .new = new (" ButtonControl" , {" RIGHT" ,self .controls .rename ," LEFT" }, {- 4 , 0 , 60 , 18 }, " New" , function ()
31- self :CreateItemSet ()
39+ local existing = { }
40+ for _ , id in ipairs (itemsTab .itemSetOrderList ) do
41+ t_insert (existing , itemsTab .itemSets [id ])
42+ end
43+ local newSet = itemsTab :NewItemSet ()
44+ require (" Modules/BuildExportPoE2" ).PresetNextLevels (existing , newSet )
45+ self :RenameSet (newSet , true )
3246 end )
3347end )
3448
35- function ItemSetListClass :CreateItemSet ()
36- local controls = {}
37- controls .label = new (" LabelControl" , nil , { 0 , 20 , 0 , 16 }, " ^7Enter name for new item set:" )
38- controls .edit = new (" EditControl" , nil , { 0 , 40 , 350 , 20 }, " New Item Set" , nil , nil , 100 , function (buf )
39- controls .save .enabled = buf :match (" %S" )
40- end )
41- controls .save = new (" ButtonControl" , nil , { - 45 , 70 , 80 , 20 }, " Save" , function ()
42- self .itemSetService :NewItemSet (controls .edit .buf )
43- main :ClosePopup ()
44- end )
45- controls .save .enabled = false
46- controls .cancel = new (" ButtonControl" , nil , { 45 , 70 , 80 , 20 }, " Cancel" , function ()
47- main :ClosePopup ()
48- end )
49- main :OpenPopup (370 , 100 , " Create Item Set" , controls , " save" , " edit" , " cancel" )
50- end
51-
52- function ItemSetListClass :CopyItemSet (selValue )
53- local itemSet = self .itemsTab .itemSets [selValue ]
54- local controls = {}
55- controls .label = new (" LabelControl" , nil , { 0 , 20 , 0 , 16 }, " ^7Enter name for this item set:" )
56- controls .edit = new (" EditControl" , nil , { 0 , 40 , 350 , 20 }, itemSet .title or " Default" , nil , nil , 100 , function (buf )
57- controls .save .enabled = buf :match (" %S" )
58- end )
59- controls .save = new (" ButtonControl" , nil , { - 45 , 70 , 80 , 20 }, " Save" , function ()
60- self .itemSetService :CopyItemSet (selValue , controls .edit .buf )
61- main :ClosePopup ()
62- end )
63- controls .save .enabled = false
64- controls .cancel = new (" ButtonControl" , nil , { 45 , 70 , 80 , 20 }, " Cancel" , function ()
65- main :ClosePopup ()
66- end )
67- main :OpenPopup (370 , 100 , " Copy Item Set" , controls , " save" , " edit" , " cancel" )
68- end
69-
70- function ItemSetListClass :RenameItemSet (selValue )
71- local itemSet = self .itemsTab .itemSets [selValue ]
72- local controls = {}
73- local setName = itemSet .title or " Default"
74- controls .label = new (" LabelControl" , nil , { 0 , 20 , 0 , 16 }, " ^7Enter name for this item set:" )
75- controls .edit = new (" EditControl" , nil , { 0 , 40 , 350 , 20 }, setName , nil , nil , 100 , function (buf )
49+ function ItemSetListClass :RenameSet (itemSet , addOnName )
50+ local controls = { }
51+ controls .label = new (" LabelControl" , nil , {0 , 20 , 0 , 16 }, " ^7Enter name for this item set:" )
52+ controls .edit = new (" EditControl" , nil , {0 , 40 , 350 , 20 }, itemSet .title , nil , nil , 100 , function (buf )
7653 controls .save .enabled = buf :match (" %S" )
7754 end )
78- controls .save = new (" ButtonControl" , nil , { - 45 , 70 , 80 , 20 }, " Save" , function ()
79- self .itemSetService :RenameItemSet (selValue , controls .edit .buf )
55+ controls .save = new (" ButtonControl" , nil , {- 45 , 70 , 80 , 20 }, " Save" , function ()
56+ itemSet .title = controls .edit .buf
57+ self .itemsTab .modFlag = true
58+ if addOnName then
59+ t_insert (self .list , itemSet .id )
60+ self .selIndex = # self .list
61+ self .selValue = itemSet .id
62+ end
63+ self .itemsTab :AddUndoState ()
64+ self .itemsTab .build :SyncLoadouts ()
8065 main :ClosePopup ()
8166 end )
8267 controls .save .enabled = false
83- controls .cancel = new (" ButtonControl" , nil , { 45 , 70 , 80 , 20 }, " Cancel" , function ()
68+ controls .cancel = new (" ButtonControl" , nil , {45 , 70 , 80 , 20 }, " Cancel" , function ()
69+ if addOnName then
70+ self .itemsTab .itemSets [itemSet .id ] = nil
71+ end
8472 main :ClosePopup ()
8573 end )
86- main :OpenPopup (370 , 100 , setName and " Rename Item Set " or " Set Name" , controls , " save" , " edit" , " cancel" )
74+ main :OpenPopup (370 , 100 , itemSet . title and " Rename" or " Set Name" , controls , " save" , " edit" , " cancel" )
8775end
8876
8977function ItemSetListClass :GetRowValue (column , index , itemSetId )
10997
11098function ItemSetListClass :ReceiveDrag (type , value , source )
11199 if type == " SharedItemList" then
112- local itemSet = self .itemsTab :CreateItemSet ()
100+ local itemSet = self .itemsTab :NewItemSet ()
113101 itemSet .title = value .title
114102 for slotName , item in pairs (value .slots ) do
115103 local newItem = new (" Item" , item .raw )
@@ -136,18 +124,23 @@ end
136124function ItemSetListClass :OnSelDelete (index , itemSetId )
137125 local itemSet = self .itemsTab .itemSets [itemSetId ]
138126 if # self .list > 1 then
139- main :OpenConfirmPopup (" Delete Item Set" ,
140- " Are you sure you want to delete '" ..
141- (itemSet .title or " Default" ) .. " '?\n This will not delete any items used by the set." , " Delete" , function ()
142- self .itemSetService :DeleteItemSet (itemSetId , index )
143- self .selIndex = nil
144- self .selValue = nil
145- end )
127+ main :OpenConfirmPopup (" Delete Item Set" , " Are you sure you want to delete '" .. (itemSet .title or " Default" ).. " '?\n This will not delete any items used by the set." , " Delete" , function ()
128+ t_remove (self .list , index )
129+ self .itemsTab .itemSets [itemSetId ] = nil
130+ self .selIndex = nil
131+ self .selValue = nil
132+ if itemSetId == self .itemsTab .activeItemSetId then
133+ self .itemsTab :SetActiveItemSet (self .list [m_max (1 , index - 1 )])
134+ end
135+ self .itemsTab :AddUndoState ()
136+ self .itemsTab .build :SyncLoadouts ()
137+ end )
146138 end
147139end
148140
149141function ItemSetListClass :OnSelKeyDown (index , itemSetId , key )
142+ local itemSet = self .itemsTab .itemSets [itemSetId ]
150143 if key == " F2" then
151- self :RenameItemSet ( itemSetId )
144+ self :RenameSet ( itemSet )
152145 end
153146end
0 commit comments