Skip to content

Commit c9b5563

Browse files
committed
initial impl of Renaming, Copying, and Deleting Loadouts, will update for clean up and other comments
1 parent 703f469 commit c9b5563

5 files changed

Lines changed: 389 additions & 73 deletions

File tree

src/Classes/ConfigSetListControl.lua

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ local m_max = math.max
1010
local ConfigSetListClass = newClass("ConfigSetListControl", "ListControl", function(self, anchor, rect, configTab)
1111
self.ListControl(anchor, rect, 16, "VERTICAL", true, configTab.configSetOrderList)
1212
self.configTab = configTab
13-
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function()
14-
local configSet = configTab.configSets[self.selValue]
13+
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function(id) -- id is for Loadouts using copy.onClick()
14+
local configSet = configTab.configSets[id or self.selValue]
1515
local newConfigSet = copyTable(configSet)
1616
newConfigSet.id = 1
1717
while configTab.configSets[newConfigSet.id] do
1818
newConfigSet.id = newConfigSet.id + 1
1919
end
2020
configTab.configSets[newConfigSet.id] = newConfigSet
21-
self:RenameSet(newConfigSet, true)
21+
if not id then
22+
self:RenameSet(newConfigSet, true)
23+
else
24+
return newConfigSet
25+
end
2226
end)
2327
self.controls.copy.enabled = function()
2428
return self.selValue ~= nil
@@ -103,6 +107,23 @@ function ConfigSetListClass:OnSelDelete(index, configSetId)
103107
end
104108
end
105109

110+
-- bypass confirmation popup, used by Loadouts
111+
function ConfigSetListClass:DeleteById(index, configSetId, sync)
112+
if #self.list > 1 then
113+
t_remove(self.list, index)
114+
self.configTab.configSets[configSetId] = nil
115+
self.selIndex = nil
116+
self.selValue = nil
117+
if configSetId == self.configTab.activeConfigSetId then
118+
self.configTab:SetActiveConfigSet(self.list[m_max(1, index - 1)])
119+
end
120+
self.configTab:AddUndoState()
121+
if sync then
122+
self.configTab.build:SyncLoadouts()
123+
end
124+
end
125+
end
126+
106127
function ConfigSetListClass:OnSelKeyDown(index, configSetId, key)
107128
if key == "F2" then
108129
self:RenameSet(self.configTab.configSets[configSetId])

src/Classes/ItemSetListControl.lua

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ local s_format = string.format
1111
local ItemSetListClass = newClass("ItemSetListControl", "ListControl", function(self, anchor, rect, itemsTab)
1212
self.ListControl(anchor, rect, 16, "VERTICAL", true, itemsTab.itemSetOrderList)
1313
self.itemsTab = itemsTab
14-
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function()
15-
local newSet = copyTable(itemsTab.itemSets[self.selValue])
14+
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function(id) -- id is for Loadouts using copy.onClick()
15+
local newSet = copyTable(itemsTab.itemSets[id or self.selValue])
1616
newSet.id = 1
1717
while itemsTab.itemSets[newSet.id] do
1818
newSet.id = newSet.id + 1
1919
end
2020
itemsTab.itemSets[newSet.id] = newSet
21-
self:RenameSet(newSet, true)
21+
if not id then
22+
self:RenameSet(newSet, true)
23+
else
24+
return newSet
25+
end
2226
end)
2327
self.controls.copy.enabled = function()
2428
return self.selValue ~= nil
@@ -118,6 +122,7 @@ end
118122

119123
function ItemSetListClass:OnSelDelete(index, itemSetId)
120124
local itemSet = self.itemsTab.itemSets[itemSetId]
125+
--ConPrintf("OnSelDelete, itemSet = "..itemSet.title or "Default"..", index = "..index..", itemSetId = "..itemSetId)
121126
if #self.list > 1 then
122127
main:OpenConfirmPopup("Delete Item Set", "Are you sure you want to delete '"..(itemSet.title or "Default").."'?\nThis will not delete any items used by the set.", "Delete", function()
123128
t_remove(self.list, index)
@@ -133,6 +138,25 @@ function ItemSetListClass:OnSelDelete(index, itemSetId)
133138
end
134139
end
135140

141+
-- bypass confirmation popup, used by Loadouts
142+
function ItemSetListClass:DeleteById(index, itemSetId, sync)
143+
local itemSet = self.itemsTab.itemSets[itemSetId]
144+
--ConPrintf("DeleteById, itemSet = "..itemSet.title or "Default"..", index = "..index..", itemSetId = "..itemSetId)
145+
if #self.list > 1 then
146+
t_remove(self.list, index)
147+
self.itemsTab.itemSets[itemSetId] = nil
148+
self.selIndex = nil
149+
self.selValue = nil
150+
if itemSetId == self.itemsTab.activeItemSetId then
151+
self.itemsTab:SetActiveItemSet(self.list[m_max(1, index - 1)])
152+
end
153+
self.itemsTab:AddUndoState()
154+
if sync then
155+
self.itemsTab.build:SyncLoadouts()
156+
end
157+
end
158+
end
159+
136160
function ItemSetListClass:OnSelKeyDown(index, itemSetId, key)
137161
local itemSet = self.itemsTab.itemSets[itemSetId]
138162
if key == "F2" then

src/Classes/PassiveSpecListControl.lua

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ local m_max = math.max
1010
local PassiveSpecListClass = newClass("PassiveSpecListControl", "ListControl", function(self, anchor, rect, treeTab)
1111
self.ListControl(anchor, rect, 16, "VERTICAL", true, treeTab.specList)
1212
self.treeTab = treeTab
13-
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function()
14-
local newSpec = new("PassiveSpec", treeTab.build, self.selValue.treeVersion)
15-
newSpec.title = self.selValue.title
16-
newSpec.jewels = copyTable(self.selValue.jewels)
17-
newSpec:RestoreUndoState(self.selValue:CreateUndoState())
13+
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function(spec) -- spec is for Loadouts using copy.onClick()
14+
local selValue = spec or self.selValue
15+
local newSpec = new("PassiveSpec", treeTab.build, selValue.treeVersion)
16+
newSpec.title = selValue.title
17+
newSpec.jewels = copyTable(selValue.jewels)
18+
newSpec:RestoreUndoState(selValue:CreateUndoState())
1819
newSpec:BuildClusterJewelGraphs()
19-
self:RenameSpec(newSpec, "Copy Tree", true)
20+
if not spec then
21+
self:RenameSpec(newSpec, "Copy Tree", true)
22+
else
23+
return newSpec
24+
end
2025
end)
2126
self.controls.copy.enabled = function()
2227
return self.selValue ~= nil
@@ -110,6 +115,25 @@ function PassiveSpecListClass:OnSelDelete(index, spec)
110115
end
111116
end
112117

118+
-- bypass confirmation popup, used by Loadouts
119+
function PassiveSpecListClass:DeleteByIndex(index, sync)
120+
if #self.list > 1 then
121+
t_remove(self.list, index)
122+
self.selIndex = nil
123+
self.selValue = nil
124+
if index == self.treeTab.activeSpec then
125+
self.treeTab:SetActiveSpec(1)
126+
else
127+
self.treeTab.activeSpec = isValueInArray(self.list, self.treeTab.build.spec)
128+
end
129+
self.treeTab.modFlag = true
130+
self:UpdateItemsTabPassiveTreeDropdown()
131+
if sync then
132+
self.treeTab.build:SyncLoadouts()
133+
end
134+
end
135+
end
136+
113137
function PassiveSpecListClass:OnSelKeyDown(index, spec, key)
114138
if key == "F2" then
115139
self:RenameSpec(spec, "Rename Tree")

src/Classes/SkillSetListControl.lua

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ local s_format = string.format
1111
local SkillSetListClass = newClass("SkillSetListControl", "ListControl", function(self, anchor, rect, skillsTab)
1212
self.ListControl(anchor, rect, 16, "VERTICAL", true, skillsTab.skillSetOrderList)
1313
self.skillsTab = skillsTab
14-
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function()
15-
local skillSet = skillsTab.skillSets[self.selValue]
14+
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function(id) -- id is for Loadouts using copy.onClick()
15+
local skillSet = skillsTab.skillSets[id or self.selValue]
1616
local newSkillSet = copyTable(skillSet, true)
1717
newSkillSet.socketGroupList = { }
1818
for socketGroupIndex, socketGroup in pairs(skillSet.socketGroupList) do
@@ -28,7 +28,11 @@ local SkillSetListClass = newClass("SkillSetListControl", "ListControl", functio
2828
newSkillSet.id = newSkillSet.id + 1
2929
end
3030
skillsTab.skillSets[newSkillSet.id] = newSkillSet
31-
self:RenameSet(newSkillSet, true)
31+
if not id then
32+
self:RenameSet(newSkillSet, true)
33+
else
34+
return newSkillSet
35+
end
3236
end)
3337
self.controls.copy.enabled = function()
3438
return self.selValue ~= nil
@@ -113,6 +117,23 @@ function SkillSetListClass:OnSelDelete(index, skillSetId)
113117
end
114118
end
115119

120+
-- bypass confirmation popup, used by Loadouts
121+
function SkillSetListClass:DeleteById(index, skillSetId, sync)
122+
if #self.list > 1 then
123+
t_remove(self.list, index)
124+
self.skillsTab.skillSets[skillSetId] = nil
125+
self.selIndex = nil
126+
self.selValue = nil
127+
if skillSetId == self.skillsTab.activeSkillSetId then
128+
self.skillsTab:SetActiveSkillSet(self.list[m_max(1, index - 1)])
129+
end
130+
self.skillsTab:AddUndoState()
131+
if sync then
132+
self.skillsTab.build:SyncLoadouts()
133+
end
134+
end
135+
end
136+
116137
function SkillSetListClass:OnSelKeyDown(index, skillSetId, key)
117138
if key == "F2" then
118139
self:RenameSet(self.skillsTab.skillSets[skillSetId])

0 commit comments

Comments
 (0)