-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathBuildSetListControl.lua
More file actions
217 lines (198 loc) · 8.26 KB
/
BuildSetListControl.lua
File metadata and controls
217 lines (198 loc) · 8.26 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
-- Path of Building
--
-- Class: Build Set List
-- Build set list control.
--
local t_insert = table.insert
local t_remove = table.remove
local BuildSetListClass = newClass("BuildSetListControl", "ListControl", function(self, anchor, rect, buildMode)
self.ListControl(anchor, rect, 16, "VERTICAL", true, buildMode.treeTab.specList)
self.buildMode = buildMode
self.buildSetService = new("BuildSetService", buildMode)
self.controls.new = new("ButtonControl", { "BOTTOMLEFT", self, "TOP" }, { -190, -4, 60, 18 }, "New",
function()
self:NewLoadout()
end)
self.controls.rename = new("ButtonControl", { "LEFT", self.controls.new, "RIGHT" }, { 5, 0, 60, 18 }, "Rename", function()
self:RenameLoadout(self.selValue)
end)
self.controls.rename.enabled = function()
return self.selValue ~= nil
end
self.controls.copy = new("ButtonControl", { "LEFT", self.controls.rename, "RIGHT" }, { 5, 0, 60, 18 }, "Copy", function()
local loadoutNameToCopy = self.selValue.title or "Default"
local build = buildMode:GetLoadoutByName(loadoutNameToCopy)
self:CopyLoadoutClick(build)
end)
self.controls.copy.enabled = function()
return self.selValue ~= nil
end
self.controls.delete = new("ButtonControl", { "LEFT", self.controls.copy, "RIGHT" }, { 5, 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.custom = new("ButtonControl", { "LEFT", self.controls.delete, "RIGHT" }, { 5, 0, 120, 18 },
"New/Copy Custom",
function()
if self.selValue == nil then
self:CopyCustom({
specId = 0,
itemSetId = 0,
skillSetId = 0,
configSetId = 0,
})
else
local loadoutNameToCopy = self.selValue.title or "Default"
local build = buildMode:GetLoadoutByName(loadoutNameToCopy)
self:CopyCustom(build)
end
end)
end)
function BuildSetListClass:RenameLoadout(spec)
local controls = {}
local specName = spec.title or "Default"
controls.label = new("LabelControl", nil, { 0, 20, 0, 16 }, "^7Enter name for this loadout:")
controls.edit = new("EditControl", nil, { 0, 40, 350, 20 }, specName, nil, nil, 100, function(buf)
controls.save.enabled = buf:match("%S")
end)
controls.save = new("ButtonControl", nil, { -45, 70, 80, 20 }, "Save", function()
local newTitle = controls.edit.buf
self.buildSetService:RenameLoadout(specName, newTitle)
main:ClosePopup()
end)
controls.save.enabled = false
controls.cancel = new("ButtonControl", nil, { 45, 70, 80, 20 }, "Cancel", function()
main:ClosePopup()
end)
main:OpenPopup(370, 100, specName and "Rename Loadout" or "Set Name", controls, "save", "edit", "cancel")
end
function BuildSetListClass:CopyLoadoutClick(build)
local controls = {}
local buildName = self.buildMode.treeTab.specList[build.specId].title
controls.label = new("LabelControl", nil, { 0, 20, 0, 16 }, "^7Enter name for this loadout:")
controls.edit = new("EditControl", nil, { 0, 40, 350, 20 }, buildName, nil, nil, 100, function(buf)
controls.save.enabled = buf:match("%S")
end)
controls.save = new("ButtonControl", nil, { -45, 70, 80, 20 }, "Save", function()
self.buildSetService:CopyLoadout(build.specId, build.itemSetId, build.skillSetId, build.configSetId,
controls.edit.buf)
main:ClosePopup()
end)
controls.save.enabled = false
controls.cancel = new("ButtonControl", nil, { 45, 70, 80, 20 }, "Cancel", function()
main:ClosePopup()
end)
main:OpenPopup(370, 100, buildName and "Rename" or "Set Name", controls, "save", "edit", "cancel")
end
function BuildSetListClass:CopyCustom(build)
local function getList(setList, orderList, activeId)
local newSetList = { "^7New" }
local activeIndex = 1
for index, setId in ipairs(orderList) do
local set = setList[setId]
t_insert(newSetList, set.title or "Default")
if setId == activeId then
activeIndex = index + 1
end
end
return newSetList, activeIndex
end
local controls = {}
local buildName = build.specId > 0 and self.buildMode.treeTab.specList[build.specId].title or "New Loadout"
controls.label = new("LabelControl", nil, { 0, 20, 0, 16 }, "^7Enter name for this loadout:")
controls.edit = new("EditControl", nil, { 0, 40, 350, 20 }, buildName, nil, nil, 100, function(buf)
controls.save.enabled = buf:match("%S")
end)
local treeList = self.buildMode.treeTab:GetSpecList()
t_insert(treeList, 1, "^7New")
controls.treeDropDown = new("DropDownControl", nil, { 0, 90, 350, 20 }, treeList, function(index)
end)
controls.treeDropDown:SetSel(build.specId + 1)
controls.treeLabel = new("LabelControl", { "BOTTOMLEFT", controls.treeDropDown, "TOPLEFT" }, { 4, -4, 0, 16 },
"^7Copy from Tree:")
local skillList, activeSkillIndex = getList(self.buildMode.skillsTab.skillSets,
self.buildMode.skillsTab.skillSetOrderList, build.skillSetId)
controls.skillDropDown = new("DropDownControl", nil, { 0, 140, 350, 20 }, skillList, function(index)
end)
controls.skillDropDown:SetSel(activeSkillIndex)
controls.skillLabel = new("LabelControl", { "BOTTOMLEFT", controls.skillDropDown, "TOPLEFT" }, { 4, -4, 0, 16 },
"^7Copy from Skill Set:")
local itemList, activeItemIndex = getList(self.buildMode.itemsTab.itemSets, self.buildMode.itemsTab.itemSetOrderList,
build.itemSetId)
controls.itemDropDown = new("DropDownControl", nil, { 0, 190, 350, 20 }, itemList, function(index)
end)
controls.itemDropDown:SetSel(activeItemIndex)
controls.itemLabel = new("LabelControl", { "BOTTOMLEFT", controls.itemDropDown, "TOPLEFT" }, { 4, -4, 0, 16 },
"^7Copy from Item Set:")
local configList, activeConfigIndex = getList(self.buildMode.configTab.configSets,
self.buildMode.configTab.configSetOrderList, build.configSetId)
controls.configDropDown = new("DropDownControl", nil, { 0, 240, 350, 20 }, configList, function(index)
end)
controls.configDropDown:SetSel(activeConfigIndex)
controls.configLabel = new("LabelControl", { "BOTTOMLEFT", controls.configDropDown, "TOPLEFT" }, { 4, -4, 0, 16 },
"^7Copy from Config Set:")
controls.save = new("ButtonControl", nil, { -45, 270, 80, 20 }, "Save", function()
self.buildSetService:CopyLoadout(build.specId, build.itemSetId, build.skillSetId, build.configSetId,
controls.edit.buf)
main:ClosePopup()
end)
controls.save.enabled = false
controls.cancel = new("ButtonControl", nil, { 45, 270, 80, 20 }, "Cancel", function()
main:ClosePopup()
end)
main:OpenPopup(370, 300, "Create Custom Loadout", controls, "save", "edit", "cancel")
end
function BuildSetListClass:NewLoadout()
local controls = {}
controls.label = new("LabelControl", nil, { 0, 20, 0, 16 }, "^7Enter name for this loadout:")
controls.edit = new("EditControl", nil, { 0, 40, 350, 20 }, "New Loadout", nil, nil, 100, function(buf)
controls.save.enabled = buf:match("%S")
end)
controls.save = new("ButtonControl", nil, { -45, 70, 80, 20 }, "Save", function()
self.buildSetService:NewLoadout(controls.edit.buf)
main:ClosePopup()
end)
controls.save.enabled = false
controls.cancel = new("ButtonControl", nil, { 45, 70, 80, 20 }, "Cancel", function()
main:ClosePopup()
end)
main:OpenPopup(370, 100, "Set Name", controls, "save", "edit", "cancel")
end
function BuildSetListClass:GetRowValue(column, index, spec)
if column == 1 then
local used = spec:CountAllocNodes()
return (spec.treeVersion ~= latestTreeVersion and ("[" .. treeVersions[spec.treeVersion].display .. "] ") or "")
.. (spec.title or "Default")
..
" (" ..
(spec.curAscendClassName ~= "None" and spec.curAscendClassName or spec.curClassName) ..
", " .. used .. " points)"
.. (index == self.buildMode.treeTab.activeSpec and " ^9(Current)" or "")
end
end
function BuildSetListClass:OnOrderChange()
self.buildMode.modFlag = true
end
function BuildSetListClass:OnSelClick(index, spec, doubleClick)
if doubleClick and index ~= self.buildMode.treeTab.activeSpec then
self.buildMode.controls.buildLoadouts:SetSel(index + 1)
end
end
function BuildSetListClass:OnSelDelete(index, spec)
if #self.list > 1 then
main:OpenConfirmPopup("Delete Loadout", "Are you sure you want to delete '" .. (spec.title or "Default") .. "'?",
"Delete", function()
self.buildSetService:DeleteLoadout(index, self.list, spec)
self.selIndex = nil
self.selValue = nil
end)
end
end
function BuildSetListClass:OnSelKeyDown(index, spec, key)
if key == "F2" then
self:RenameLoadout(spec)
end
end