|
| 1 | +-- Path of Building |
| 2 | +-- |
| 3 | +-- Class: Manage Loadouts List |
| 4 | +-- List control for managing whole loadouts (a passive tree + item/skill/config sets sharing a name). |
| 5 | +-- |
| 6 | +local ipairs = ipairs |
| 7 | + |
| 8 | +local ManageLoadoutsListClass = newClass("ManageLoadoutsListControl", "ListControl", function(self, anchor, rect, build) |
| 9 | + self.ListControl(anchor, rect, 16, "VERTICAL", true, { }) |
| 10 | + self.build = build |
| 11 | + self:BuildList() |
| 12 | + |
| 13 | + self.controls.copy = new("ButtonControl", {"BOTTOMLEFT",self,"TOP"}, {2, -4, 60, 18}, "Copy", function() |
| 14 | + self:CopyLoadout(self.selValue) |
| 15 | + end) |
| 16 | + self.controls.copy.enabled = function() |
| 17 | + return self.selValue ~= nil |
| 18 | + end |
| 19 | + self.controls.delete = new("ButtonControl", {"LEFT",self.controls.copy,"RIGHT"}, {4, 0, 60, 18}, "Delete", function() |
| 20 | + self:OnSelDelete(self.selIndex, self.selValue) |
| 21 | + end) |
| 22 | + self.controls.delete.enabled = function() |
| 23 | + return self.selValue ~= nil and #self.list > 1 |
| 24 | + end |
| 25 | + self.controls.rename = new("ButtonControl", {"BOTTOMRIGHT",self,"TOP"}, {-2, -4, 60, 18}, "Rename", function() |
| 26 | + self:RenameLoadout(self.selValue) |
| 27 | + end) |
| 28 | + self.controls.rename.enabled = function() |
| 29 | + return self.selValue ~= nil |
| 30 | + end |
| 31 | + self.controls.new = new("ButtonControl", {"RIGHT",self.controls.rename,"LEFT"}, {-4, 0, 60, 18}, "New", function() |
| 32 | + self.build:OpenNewLoadoutPopup(function() |
| 33 | + self:BuildList() |
| 34 | + end) |
| 35 | + end) |
| 36 | +end) |
| 37 | + |
| 38 | +-- Rebuild the list of loadout descriptors, preserving the current selection by tree spec identity. |
| 39 | +function ManageLoadoutsListClass:BuildList() |
| 40 | + local prevSpec = self.selValue and self.selValue.spec |
| 41 | + self.list = self.build:GetLoadouts() |
| 42 | + self.selIndex = nil |
| 43 | + self.selValue = nil |
| 44 | + if prevSpec then |
| 45 | + for index, loadout in ipairs(self.list) do |
| 46 | + if loadout.spec == prevSpec then |
| 47 | + self.selIndex = index |
| 48 | + self.selValue = loadout |
| 49 | + break |
| 50 | + end |
| 51 | + end |
| 52 | + end |
| 53 | +end |
| 54 | + |
| 55 | +function ManageLoadoutsListClass:GetRowValue(column, index, loadout) |
| 56 | + if column == 1 then |
| 57 | + local spec = loadout.spec |
| 58 | + local used = spec:CountAllocNodes() |
| 59 | + local className = spec.curAscendClassName ~= "None" and spec.curAscendClassName or spec.curClassName |
| 60 | + local isCurrent = self.build.treeTab.specList[self.build.treeTab.activeSpec] == spec |
| 61 | + return (spec.treeVersion ~= latestTreeVersion and ("["..treeVersions[spec.treeVersion].display.."] ") or "") |
| 62 | + .. loadout.name |
| 63 | + .. " (" .. className .. ", " .. used .. " points)" |
| 64 | + .. (isCurrent and " ^9(Current)" or "") |
| 65 | + end |
| 66 | +end |
| 67 | + |
| 68 | +function ManageLoadoutsListClass:OnSelClick(index, loadout, doubleClick) |
| 69 | + if doubleClick then |
| 70 | + self.build:SetActiveLoadout(loadout) |
| 71 | + self:BuildList() |
| 72 | + end |
| 73 | +end |
| 74 | + |
| 75 | +function ManageLoadoutsListClass:OnOrderChange() |
| 76 | + self.build:ApplyLoadoutOrder(self.list) |
| 77 | + self:BuildList() |
| 78 | +end |
| 79 | + |
| 80 | +function ManageLoadoutsListClass:OnSelDelete(index, loadout) |
| 81 | + if not loadout or #self.list <= 1 then |
| 82 | + return |
| 83 | + end |
| 84 | + main:OpenConfirmPopup("Delete Loadout", |
| 85 | + "Are you sure you want to delete the '"..loadout.name.."' loadout?\n" |
| 86 | + .. "This will delete its passive tree, item set, skill set and config set.\n" |
| 87 | + .. "This will not delete any items used by the set.", "Delete", function() |
| 88 | + self.build:DeleteLoadout(loadout) |
| 89 | + self:BuildList() |
| 90 | + end) |
| 91 | +end |
| 92 | + |
| 93 | +function ManageLoadoutsListClass:RenameLoadout(loadout) |
| 94 | + if not loadout then |
| 95 | + return |
| 96 | + end |
| 97 | + local controls = { } |
| 98 | + controls.label = new("LabelControl", nil, {0, 20, 0, 16}, "^7Enter name for this loadout:") |
| 99 | + controls.edit = new("EditControl", nil, {0, 40, 350, 20}, loadout.name, nil, nil, 100, function(buf) |
| 100 | + controls.save.enabled = buf:match("%S") |
| 101 | + end) |
| 102 | + controls.save = new("ButtonControl", nil, {-45, 70, 80, 20}, "Save", function() |
| 103 | + self.build:RenameLoadout(loadout, controls.edit.buf) |
| 104 | + self:BuildList() |
| 105 | + main:ClosePopup() |
| 106 | + end) |
| 107 | + controls.save.enabled = false |
| 108 | + controls.cancel = new("ButtonControl", nil, {45, 70, 80, 20}, "Cancel", function() |
| 109 | + main:ClosePopup() |
| 110 | + end) |
| 111 | + main:OpenPopup(370, 100, "Rename Loadout", controls, "save", "edit", "cancel") |
| 112 | +end |
| 113 | + |
| 114 | +function ManageLoadoutsListClass:CopyLoadout(loadout) |
| 115 | + if not loadout then |
| 116 | + return |
| 117 | + end |
| 118 | + local controls = { } |
| 119 | + controls.label = new("LabelControl", nil, {0, 20, 0, 16}, "^7Enter name for the copied loadout:") |
| 120 | + controls.edit = new("EditControl", nil, {0, 40, 350, 20}, loadout.name, nil, nil, 100, function(buf) |
| 121 | + controls.save.enabled = buf:match("%S") |
| 122 | + end) |
| 123 | + controls.save = new("ButtonControl", nil, {-45, 70, 80, 20}, "Save", function() |
| 124 | + self.build:CopyLoadout(loadout, controls.edit.buf) |
| 125 | + self:BuildList() |
| 126 | + main:ClosePopup() |
| 127 | + end) |
| 128 | + controls.save.enabled = false |
| 129 | + controls.cancel = new("ButtonControl", nil, {45, 70, 80, 20}, "Cancel", function() |
| 130 | + main:ClosePopup() |
| 131 | + end) |
| 132 | + main:OpenPopup(370, 100, "Copy Loadout", controls, "save", "edit", "cancel") |
| 133 | +end |
| 134 | + |
| 135 | +function ManageLoadoutsListClass:OnSelKeyDown(index, loadout, key) |
| 136 | + if key == "F2" then |
| 137 | + self:RenameLoadout(loadout) |
| 138 | + end |
| 139 | +end |
0 commit comments