-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathSkillSetListControl.lua
More file actions
141 lines (133 loc) · 4.8 KB
/
SkillSetListControl.lua
File metadata and controls
141 lines (133 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
-- Path of Building
--
-- Class: Skill Set List
-- Skill set list control.
--
local t_insert = table.insert
local t_remove = table.remove
local m_max = math.max
local s_format = string.format
local SkillSetListClass = newClass("SkillSetListControl", "ListControl", function(self, anchor, rect, skillsTab)
self.ListControl(anchor, rect, 16, "VERTICAL", true, skillsTab.skillSetOrderList)
self.skillsTab = skillsTab
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function(id) -- id is for Loadouts using copy.onClick()
local skillSet = skillsTab.skillSets[id or self.selValue]
local newSkillSet = copyTable(skillSet, true)
newSkillSet.socketGroupList = { }
for socketGroupIndex, socketGroup in pairs(skillSet.socketGroupList) do
local newGroup = copyTable(socketGroup, true)
newGroup.gemList = { }
for gemIndex, gem in pairs(socketGroup.gemList) do
newGroup.gemList[gemIndex] = copyTable(gem, true)
end
t_insert(newSkillSet.socketGroupList, newGroup)
end
newSkillSet.id = 1
while skillsTab.skillSets[newSkillSet.id] do
newSkillSet.id = newSkillSet.id + 1
end
skillsTab.skillSets[newSkillSet.id] = newSkillSet
if not id then
self:RenameSet(newSkillSet, true)
else
return newSkillSet
end
end)
self.controls.copy.enabled = function()
return self.selValue ~= nil
end
self.controls.delete = new("ButtonControl", {"LEFT",self.controls.copy,"RIGHT"}, {4, 0, 60, 18}, "Delete", function()
self:OnSelDelete(self.selIndex, self.selValue)
end)
self.controls.delete.enabled = function()
return self.selValue ~= nil and #self.list > 1
end
self.controls.rename = new("ButtonControl", {"BOTTOMRIGHT",self,"TOP"}, {-2, -4, 60, 18}, "Rename", function()
self:RenameSet(skillsTab.skillSets[self.selValue])
end)
self.controls.rename.enabled = function()
return self.selValue ~= nil
end
self.controls.new = new("ButtonControl", {"RIGHT",self.controls.rename,"LEFT"}, {-4, 0, 60, 18}, "New", function()
self:RenameSet(skillsTab:NewSkillSet(), true)
end)
end)
function SkillSetListClass:RenameSet(skillSet, addOnName)
local controls = { }
controls.label = new("LabelControl", nil, {0, 20, 0, 16}, "^7Enter name for this skill set:")
controls.edit = new("EditControl", nil, {0, 40, 350, 20}, skillSet.title, nil, nil, 100, function(buf)
controls.save.enabled = buf:match("%S")
end)
controls.save = new("ButtonControl", nil, {-45, 70, 80, 20}, "Save", function()
skillSet.title = controls.edit.buf
self.skillsTab.modFlag = true
if addOnName then
t_insert(self.list, skillSet.id)
self.selIndex = #self.list
self.selValue = skillSet.id
end
self.skillsTab:AddUndoState()
self.skillsTab.build:SyncLoadouts()
main:ClosePopup()
end)
controls.save.enabled = false
controls.cancel = new("ButtonControl", nil, {45, 70, 80, 20}, "Cancel", function()
if addOnName then
self.skillsTab.skillSets[skillSet.id] = nil
end
main:ClosePopup()
end)
main:OpenPopup(370, 100, skillSet.title and "Rename" or "Set Name", controls, "save", "edit", "cancel")
end
function SkillSetListClass:GetRowValue(column, index, skillSetId)
local skillSet = self.skillsTab.skillSets[skillSetId]
if column == 1 then
return (skillSet.title or "Default") .. (skillSetId == self.skillsTab.activeSkillSetId and " ^9(Current)" or "")
end
end
function SkillSetListClass:OnOrderChange()
self.skillsTab.modFlag = true
end
function SkillSetListClass:OnSelClick(index, skillSetId, doubleClick)
if doubleClick and skillSetId ~= self.skillsTab.activeSkillSetId then
self.skillsTab:SetActiveSkillSet(skillSetId)
self.skillsTab:AddUndoState()
end
end
function SkillSetListClass:OnSelDelete(index, skillSetId)
local skillSet = self.skillsTab.skillSets[skillSetId]
if #self.list > 1 then
main:OpenConfirmPopup("Delete Item Set", "Are you sure you want to delete '"..(skillSet.title or "Default").."'?", "Delete", function()
t_remove(self.list, index)
self.skillsTab.skillSets[skillSetId] = nil
self.selIndex = nil
self.selValue = nil
if skillSetId == self.skillsTab.activeSkillSetId then
self.skillsTab:SetActiveSkillSet(self.list[m_max(1, index - 1)])
end
self.skillsTab:AddUndoState()
self.skillsTab.build:SyncLoadouts()
end)
end
end
-- bypass confirmation popup, used by Loadouts
function SkillSetListClass:DeleteById(index, skillSetId, sync)
if #self.list > 1 then
t_remove(self.list, index)
self.skillsTab.skillSets[skillSetId] = nil
self.selIndex = nil
self.selValue = nil
if skillSetId == self.skillsTab.activeSkillSetId then
self.skillsTab:SetActiveSkillSet(self.list[m_max(1, index - 1)])
end
self.skillsTab:AddUndoState()
if sync then
self.skillsTab.build:SyncLoadouts()
end
end
end
function SkillSetListClass:OnSelKeyDown(index, skillSetId, key)
if key == "F2" then
self:RenameSet(self.skillsTab.skillSets[skillSetId])
end
end