From 7fa84fc29e15a440014a593657a1d5ada4d45aea 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 | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/Classes/SkillsTab.lua b/src/Classes/SkillsTab.lua index 5793c11ca2..a1d264fdb5 100644 --- a/src/Classes/SkillsTab.lua +++ b/src/Classes/SkillsTab.lua @@ -239,7 +239,17 @@ local SkillsTabClass = newClass("SkillsTab", "UndoHandler", "ControlHost", "Cont local item = getSelectedItem() return not not item end - self.controls.optimiseSockets = new("ButtonControl", { "LEFT", self.controls.socketsLabel, "RIGHT" }, { 4, 0, 120, 18 }, "^7Optimise Sockets", function() + 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", { "LEFT", self.controls.socketsLabel, "RIGHT" }, { 4, 0, 120, 18 }, "Optimise Sockets", function() local item, groupSlot = getSelectedItem() if not item or not groupSlot or not item.base then return @@ -247,17 +257,10 @@ local SkillsTabClass = newClass("SkillsTab", "UndoHandler", "ControlHost", "Cont 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 @@ -272,7 +275,6 @@ local SkillsTabClass = newClass("SkillsTab", "UndoHandler", "ControlHost", "Cont groupCount = groupCount + 1 end end - for _ = 0, abyssalSocketCount - 1 do groupCount = groupCount + 1 table.insert(item.sockets, { color = "A", group = groupCount }) @@ -285,6 +287,26 @@ local SkillsTabClass = newClass("SkillsTab", "UndoHandler", "ControlHost", "Cont 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