From fd2c3309ce4f0279635071036d7052bcdcc57d62 Mon Sep 17 00:00:00 2001 From: vaisest <4550061+vaisest@users.noreply.github.com> Date: Fri, 7 Aug 2026 18:48:11 +0300 Subject: [PATCH] Only enable optimise sockets button when it will do something --- src/Classes/SkillsTab.lua | 40 ++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Classes/SkillsTab.lua b/src/Classes/SkillsTab.lua index b1a56d40a6..29f1578751 100644 --- a/src/Classes/SkillsTab.lua +++ b/src/Classes/SkillsTab.lua @@ -243,6 +243,16 @@ function SkillsTabClass:SkillsTab(build) local item = getSelectedItem() return not not item end + local function getSocketCounts(item) + local abyssalSocketCount = 0 + for _, socket in ipairs(item.sockets) do + if socket.color == "A" then + abyssalSocketCount = abyssalSocketCount + 1 + end + end + local maxSockets = (item.base.socketLimit or 0) - abyssalSocketCount + return maxSockets, abyssalSocketCount + end self.controls.optimiseSockets = new("ButtonControl"):ButtonControl({ "LEFT", self.controls.socketsLabel, "RIGHT" }, { 4, 0, 120, 18 }, "^7Optimise Sockets", function() local item, groupSlot = getSelectedItem() if not item or not groupSlot or not item.base then @@ -251,17 +261,10 @@ function SkillsTabClass:SkillsTab(build) self.build.itemsTab:AddUndoState() - -- save count of abyssal sockets - local abyssalSocketCount = 0 - for _, socket in ipairs(item.sockets) do - if socket.color == "A" then - abyssalSocketCount = abyssalSocketCount + 1 - end - end + local maxSockets, abyssalSocketCount = getSocketCounts(item) local groupCount = 0 item.sockets = {} - local maxSockets = (item.base.socketLimit or 0) - abyssalSocketCount for _, group in ipairs(self.socketGroupList) do local colours = { "R", "G", "B" } if group.slot == groupSlot.slotName then @@ -276,7 +279,6 @@ function SkillsTabClass:SkillsTab(build) groupCount = groupCount + 1 end end - for _ = 0, abyssalSocketCount - 1 do groupCount = groupCount + 1 table.insert(item.sockets, { color = "A", group = groupCount }) @@ -289,6 +291,26 @@ function SkillsTabClass:SkillsTab(build) local item = getSelectedItem() return item and (item.base.socketLimit ~= nil) end + self.controls.optimiseSockets.enabled = function() + local item, groupSlot = getSelectedItem() + if not item or not groupSlot or not item.base then + return false + end + local maxSockets = getSocketCounts(item) + for _, group in ipairs(self.socketGroupList) do + if group.slot == groupSlot.slotName then + for _, gem in ipairs(group.gemList) do + if (gem.grantedEffect or (gem.gemData and gem.gemData.grantedEffect)) and maxSockets > 0 then + if not gem.matchesSocket then + return true + end + maxSockets -= 1 + end + end + end + end + return false + end self.controls.optimiseSockets.tooltipText = "Rebuild the item's sockets to match the groups assigned to it." -- self.imbuedSupportBySlot is used by CalcSetup to add an ExtraSupport mod of the selected gem -- Each displayGroup has its own "imbuedSupport" and is saved to the xml to load when changing sockets or loading a build