-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathManageLoadoutsListControl.lua
More file actions
139 lines (129 loc) · 4.65 KB
/
Copy pathManageLoadoutsListControl.lua
File metadata and controls
139 lines (129 loc) · 4.65 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
-- Path of Building
--
-- Class: Manage Loadouts List
-- List control for managing whole loadouts (a passive tree + item/skill/config sets sharing a name).
--
local ipairs = ipairs
local ManageLoadoutsListClass = newClass("ManageLoadoutsListControl", "ListControl", function(self, anchor, rect, build)
self.ListControl(anchor, rect, 16, "VERTICAL", true, { })
self.build = build
self:BuildList()
self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function()
self:CopyLoadout(self.selValue)
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:RenameLoadout(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.build:OpenNewLoadoutPopup(function()
self:BuildList()
end)
end)
end)
-- Rebuild the list of loadout descriptors, preserving the current selection by tree spec identity.
function ManageLoadoutsListClass:BuildList()
local prevSpec = self.selValue and self.selValue.spec
self.list = self.build:GetLoadouts()
self.selIndex = nil
self.selValue = nil
if prevSpec then
for index, loadout in ipairs(self.list) do
if loadout.spec == prevSpec then
self.selIndex = index
self.selValue = loadout
break
end
end
end
end
function ManageLoadoutsListClass:GetRowValue(column, index, loadout)
if column == 1 then
local spec = loadout.spec
local used = spec:CountAllocNodes()
local className = spec.curAscendClassName ~= "None" and spec.curAscendClassName or spec.curClassName
local isCurrent = self.build.treeTab.specList[self.build.treeTab.activeSpec] == spec
return (spec.treeVersion ~= latestTreeVersion and ("["..treeVersions[spec.treeVersion].display.."] ") or "")
.. loadout.name
.. " (" .. className .. ", " .. used .. " points)"
.. (isCurrent and " ^9(Current)" or "")
end
end
function ManageLoadoutsListClass:OnSelClick(index, loadout, doubleClick)
if doubleClick then
self.build:SetActiveLoadout(loadout)
self:BuildList()
end
end
function ManageLoadoutsListClass:OnOrderChange()
self.build:ApplyLoadoutOrder(self.list)
self:BuildList()
end
function ManageLoadoutsListClass:OnSelDelete(index, loadout)
if not loadout or #self.list <= 1 then
return
end
main:OpenConfirmPopup("Delete Loadout",
"Are you sure you want to delete the '"..loadout.name.."' loadout?\n"
.. "This will delete its passive tree, item set, skill set and config set.\n"
.. "This will not delete any items used by the set.", "Delete", function()
self.build:DeleteLoadout(loadout)
self:BuildList()
end)
end
function ManageLoadoutsListClass:RenameLoadout(loadout)
if not loadout then
return
end
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}, loadout.name, nil, nil, 100, function(buf)
controls.save.enabled = buf:match("%S")
end)
controls.save = new("ButtonControl", nil, {-45, 70, 80, 20}, "Save", function()
self.build:RenameLoadout(loadout, controls.edit.buf)
self:BuildList()
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, "Rename Loadout", controls, "save", "edit", "cancel")
end
function ManageLoadoutsListClass:CopyLoadout(loadout)
if not loadout then
return
end
local controls = { }
controls.label = new("LabelControl", nil, {0, 20, 0, 16}, "^7Enter name for the copied loadout:")
controls.edit = new("EditControl", nil, {0, 40, 350, 20}, loadout.name, nil, nil, 100, function(buf)
controls.save.enabled = buf:match("%S")
end)
controls.save = new("ButtonControl", nil, {-45, 70, 80, 20}, "Save", function()
self.build:CopyLoadout(loadout, controls.edit.buf)
self:BuildList()
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, "Copy Loadout", controls, "save", "edit", "cancel")
end
function ManageLoadoutsListClass:OnSelKeyDown(index, loadout, key)
if key == "F2" then
self:RenameLoadout(loadout)
end
end