Skip to content

Commit fd2c330

Browse files
committed
Only enable optimise sockets button when it will do something
1 parent bcbca9b commit fd2c330

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

‎src/Classes/SkillsTab.lua‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ function SkillsTabClass:SkillsTab(build)
243243
local item = getSelectedItem()
244244
return not not item
245245
end
246+
local function getSocketCounts(item)
247+
local abyssalSocketCount = 0
248+
for _, socket in ipairs(item.sockets) do
249+
if socket.color == "A" then
250+
abyssalSocketCount = abyssalSocketCount + 1
251+
end
252+
end
253+
local maxSockets = (item.base.socketLimit or 0) - abyssalSocketCount
254+
return maxSockets, abyssalSocketCount
255+
end
246256
self.controls.optimiseSockets = new("ButtonControl"):ButtonControl({ "LEFT", self.controls.socketsLabel, "RIGHT" }, { 4, 0, 120, 18 }, "^7Optimise Sockets", function()
247257
local item, groupSlot = getSelectedItem()
248258
if not item or not groupSlot or not item.base then
@@ -251,17 +261,10 @@ function SkillsTabClass:SkillsTab(build)
251261

252262
self.build.itemsTab:AddUndoState()
253263

254-
-- save count of abyssal sockets
255-
local abyssalSocketCount = 0
256-
for _, socket in ipairs(item.sockets) do
257-
if socket.color == "A" then
258-
abyssalSocketCount = abyssalSocketCount + 1
259-
end
260-
end
264+
local maxSockets, abyssalSocketCount = getSocketCounts(item)
261265

262266
local groupCount = 0
263267
item.sockets = {}
264-
local maxSockets = (item.base.socketLimit or 0) - abyssalSocketCount
265268
for _, group in ipairs(self.socketGroupList) do
266269
local colours = { "R", "G", "B" }
267270
if group.slot == groupSlot.slotName then
@@ -276,7 +279,6 @@ function SkillsTabClass:SkillsTab(build)
276279
groupCount = groupCount + 1
277280
end
278281
end
279-
280282
for _ = 0, abyssalSocketCount - 1 do
281283
groupCount = groupCount + 1
282284
table.insert(item.sockets, { color = "A", group = groupCount })
@@ -289,6 +291,26 @@ function SkillsTabClass:SkillsTab(build)
289291
local item = getSelectedItem()
290292
return item and (item.base.socketLimit ~= nil)
291293
end
294+
self.controls.optimiseSockets.enabled = function()
295+
local item, groupSlot = getSelectedItem()
296+
if not item or not groupSlot or not item.base then
297+
return false
298+
end
299+
local maxSockets = getSocketCounts(item)
300+
for _, group in ipairs(self.socketGroupList) do
301+
if group.slot == groupSlot.slotName then
302+
for _, gem in ipairs(group.gemList) do
303+
if (gem.grantedEffect or (gem.gemData and gem.gemData.grantedEffect)) and maxSockets > 0 then
304+
if not gem.matchesSocket then
305+
return true
306+
end
307+
maxSockets -= 1
308+
end
309+
end
310+
end
311+
end
312+
return false
313+
end
292314
self.controls.optimiseSockets.tooltipText = "Rebuild the item's sockets to match the groups assigned to it."
293315
-- self.imbuedSupportBySlot is used by CalcSetup to add an ExtraSupport mod of the selected gem
294316
-- Each displayGroup has its own "imbuedSupport" and is saved to the xml to load when changing sockets or loading a build

0 commit comments

Comments
 (0)