Skip to content

Commit fcaf69c

Browse files
committed
Add support for skill sets (socket group sets)
Adds support for skill sets for socket groups. This is useful for adding different sets for different character state or progression (e.g Acts/Starter/High Budget etc). Fixes #2060 Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent aa092d6 commit fcaf69c

File tree

3 files changed

+240
-19
lines changed

3 files changed

+240
-19
lines changed

src/Classes/SkillListControl.lua

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ local ipairs = ipairs
77
local t_insert = table.insert
88
local t_remove = table.remove
99

10+
function indexOf(array, value)
11+
for i, v in ipairs(array) do
12+
if v == value then
13+
return i
14+
end
15+
end
16+
return nil
17+
end
18+
1019
local SkillListClass = newClass("SkillListControl", "ListControl", function(self, anchor, x, y, width, height, skillsTab)
1120
self.ListControl(anchor, x, y, width, height, 16, "VERTICAL", true, skillsTab.socketGroupList)
1221
self.skillsTab = skillsTab
@@ -31,14 +40,16 @@ local SkillListClass = newClass("SkillListControl", "ListControl", function(self
3140
return #self.list > 0
3241
end
3342
self.controls.new = new("ButtonControl", {"RIGHT",self.controls.deleteAll,"LEFT"}, -4, 0, 60, 18, "New", function()
34-
local newGroup = {
43+
local newGroup = {
3544
label = "",
36-
enabled = true,
45+
enabled = true,
46+
skillSet = skillsTab.activeSkillSetId,
3747
gemList = { }
3848
}
39-
t_insert(self.list, newGroup)
49+
t_insert(skillsTab.allSocketGroupList, newGroup)
4050
self.selIndex = #self.list
4151
self.selValue = newGroup
52+
skillsTab:SetActiveSkillSet()
4253
skillsTab:SetDisplayGroup(newGroup)
4354
skillsTab:AddUndoState()
4455
skillsTab.build.buildFlag = true
@@ -52,7 +63,7 @@ function SkillListClass:GetRowValue(column, index, socketGroup)
5263
if not socketGroup.enabled or not socketGroup.slotEnabled then
5364
label = "^x7F7F7F" .. label .. " (Disabled)"
5465
end
55-
if self.skillsTab.build.mainSocketGroup == index then
66+
if self.skillsTab.build.mainSocketGroup == index then
5667
label = label .. colorCodes.RELIC .. " (Active)"
5768
end
5869
if socketGroup.includeInFullDPS then
@@ -91,7 +102,8 @@ function SkillListClass:OnSelDelete(index, socketGroup)
91102
if socketGroup.source then
92103
main:OpenMessagePopup("Delete Socket Group", "This socket group cannot be deleted as it is created by an equipped item.")
93104
elseif not socketGroup.gemList[1] then
94-
t_remove(self.list, index)
105+
t_remove(self.skillsTab.allSocketGroupList, indexOf(self.skillsTab.allSocketGroupList, socketGroup))
106+
self.skillsTab:SetActiveSkillSet()
95107
if self.skillsTab.displayGroup == socketGroup then
96108
self.skillsTab.displayGroup = nil
97109
end
@@ -100,7 +112,8 @@ function SkillListClass:OnSelDelete(index, socketGroup)
100112
self.selValue = nil
101113
else
102114
main:OpenConfirmPopup("Delete Socket Group", "Are you sure you want to delete '"..socketGroup.displayLabel.."'?", "Delete", function()
103-
t_remove(self.list, index)
115+
t_remove(self.skillsTab.allSocketGroupList, indexOf(self.skillsTab.allSocketGroupList, socketGroup))
116+
self.skillsTab:SetActiveSkillSet()
104117
if self.skillsTab.displayGroup == socketGroup then
105118
self.skillsTab:SetDisplayGroup()
106119
end
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
-- Path of Building
2+
--
3+
-- Class: Skill Set List
4+
-- Skill set list control.
5+
--
6+
local t_insert = table.insert
7+
local t_remove = table.remove
8+
local m_max = math.max
9+
local s_format = string.format
10+
11+
local SkillSetListClass = newClass("SkillSetListControl", "ListControl", function(self, anchor, x, y, width, height, skillsTab)
12+
self.ListControl(anchor, x, y, width, height, 16, "VERTICAL", true, skillsTab.skillSetOrderList)
13+
self.skillsTab = skillsTab
14+
self.controls.delete = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, 2, -4, 60, 18, "Delete", function()
15+
self:OnSelDelete(self.selIndex, self.selValue)
16+
end)
17+
self.controls.delete.enabled = function()
18+
return self.selValue ~= nil and #self.list > 1
19+
end
20+
self.controls.rename = new("ButtonControl", {"BOTTOMRIGHT",self,"TOP"}, -2, -4, 60, 18, "Rename", function()
21+
self:RenameSet(skillsTab.skillSets[self.selValue])
22+
end)
23+
self.controls.rename.enabled = function()
24+
return self.selValue ~= nil
25+
end
26+
self.controls.new = new("ButtonControl", {"RIGHT",self.controls.rename,"LEFT"}, -4, 0, 60, 18, "New", function()
27+
self:RenameSet(skillsTab:NewSkillSet(), true)
28+
end)
29+
end)
30+
31+
function SkillSetListClass:RenameSet(skillSet, addOnName)
32+
local controls = { }
33+
controls.label = new("LabelControl", nil, 0, 20, 0, 16, "^7Enter name for this skill set:")
34+
controls.edit = new("EditControl", nil, 0, 40, 350, 20, skillSet.title, nil, nil, 100, function(buf)
35+
controls.save.enabled = buf:match("%S")
36+
end)
37+
controls.save = new("ButtonControl", nil, -45, 70, 80, 20, "Save", function()
38+
skillSet.title = controls.edit.buf
39+
self.skillsTab.modFlag = true
40+
if addOnName then
41+
t_insert(self.list, skillSet.id)
42+
self.selIndex = #self.list
43+
self.selValue = skillSet
44+
end
45+
self.skillsTab:AddUndoState()
46+
main:ClosePopup()
47+
end)
48+
controls.save.enabled = false
49+
controls.cancel = new("ButtonControl", nil, 45, 70, 80, 20, "Cancel", function()
50+
if addOnName then
51+
self.skillsTab.skillSets[skillSet.id] = nil
52+
end
53+
main:ClosePopup()
54+
end)
55+
main:OpenPopup(370, 100, skillSet.title and "Rename" or "Set Name", controls, "save", "edit", "cancel")
56+
end
57+
58+
function SkillSetListClass:GetRowValue(column, index, skillSetId)
59+
local skillSet = self.skillsTab.skillSets[skillSetId]
60+
if column == 1 then
61+
return (skillSet.title or "Default") .. (skillSetId == self.skillsTab.activeSkillSetId and " ^9(Current)" or "")
62+
end
63+
end
64+
65+
function SkillSetListClass:OnOrderChange()
66+
self.skillsTab.modFlag = true
67+
end
68+
69+
function SkillSetListClass:OnSelClick(index, skillSetId, doubleClick)
70+
if doubleClick and skillSetId ~= self.skillsTab.activeSkillSetId then
71+
self.skillsTab:SetActiveSkillSet(skillSetId)
72+
self.skillsTab:AddUndoState()
73+
end
74+
end
75+
76+
function SkillSetListClass:OnSelDelete(index, skillSetId)
77+
local skillSet = self.skillsTab.skillSets[skillSetId]
78+
if #self.list > 1 then
79+
main:OpenConfirmPopup("Delete Item Set", "Are you sure you want to delete '"..(skillSet.title or "Default").."'?", "Delete", function()
80+
t_remove(self.list, index)
81+
self.skillsTab.skillSets[skillSetId] = nil
82+
self.selIndex = nil
83+
self.selValue = nil
84+
for k,v in pairs(self.skillsTab.allSocketGroupList) do
85+
if v.skillSet == skillSet.id then
86+
self.skillsTab.allSocketGroupList[k] = nil
87+
end
88+
end
89+
if skillSetId == self.skillsTab.activeSkillSetId then
90+
self.skillsTab:SetActiveSkillSet(self.list[m_max(1, index - 1)])
91+
end
92+
self.skillsTab:AddUndoState()
93+
end)
94+
end
95+
end
96+
97+
function SkillSetListClass:OnSelKeyDown(index, skillSetId, key)
98+
if key == "F2" then
99+
self:RenameSet(skillSetId)
100+
end
101+
end

0 commit comments

Comments
 (0)