@@ -21,6 +21,7 @@ export type ClassType = typeof(setmetatable(
2121 tooltip : TextLabel ,
2222 },
2323 _connections : { RBXScriptConnection },
24+ _toolChangedConnection : RBXScriptConnection ? ,
2425 },
2526 SlotButton
2627))
@@ -53,6 +54,7 @@ function SlotButton.new(): ClassType
5354 tooltip = tooltipText ,
5455 },
5556 _connections = {},
57+ _toolChangedConnection = nil ,
5658 }, SlotButton )
5759
5860 self :setText ("" )
@@ -67,14 +69,6 @@ function SlotButton.new(): ClassType
6769 self :onPreferredInputChanged ()
6870 table.insert (self ._connections , preferredInputChangedConnection )
6971
70- -- local defaultTransparency = buttonInstance.BackgroundTransparency
71- -- local preferredTransparencyChangedConnection = GuiService:GetPropertyChangedSignal("PreferredTransparency")
72- -- :Connect(function()
73- -- self:onPreferredTransparencyChanged(defaultTransparency)
74- -- end)
75- -- self:onPreferredTransparencyChanged(defaultTransparency)
76- -- table.insert(self._connections, preferredTransparencyChangedConnection)
77-
7872 return self
7973end
8074
@@ -83,25 +77,16 @@ function SlotButton.destroy(self: ClassType)
8377 self .tool = nil
8478 self ._instance .button :Destroy ()
8579
80+ if self ._toolChangedConnection then
81+ self ._toolChangedConnection :Disconnect ()
82+ self ._toolChangedConnection = nil
83+ end
84+
8685 for _ , connection in self ._connections do
8786 connection :Disconnect ()
8887 end
8988end
9089
91- -- Updates the hint visibility based on preferred input method
92- function SlotButton .onPreferredInputChanged (self : ClassType )
93- local preferredInput = UserInputService .PreferredInput
94- local isKeyboardAndMouse = preferredInput == Enum.PreferredInput.KeyboardAndMouse
95-
96- self ._instance .hint .Visible = isKeyboardAndMouse
97- end
98-
99- -- function SlotButton.onPreferredTransparencyChanged(self: ClassType, defaultTransparency: number)
100- -- local preferredTransparency = GuiService.PreferredTransparency
101-
102- -- self._instance.button.BackgroundTransparency = defaultTransparency * preferredTransparency
103- -- end
104-
10590-- Sets whether this slot is unlocked and draggable
10691function SlotButton .setUnlocked (self : ClassType , unlocked : boolean )
10792 if unlocked then
122107
123108-- Sets the tool associated with this slot button
124109function SlotButton .setTool (self : ClassType , tool : Tool | HopperBin )
110+ if self ._toolChangedConnection then
111+ self ._toolChangedConnection :Disconnect ()
112+ self ._toolChangedConnection = nil
113+ end
114+
125115 self .tool = tool
126116
127117 -- Update the button based on the tool
@@ -131,18 +121,19 @@ function SlotButton.setTool(self: ClassType, tool: Tool | HopperBin)
131121 self :setIcon (self .tool .TextureId )
132122 if self .tool :IsA ("Tool" ) then
133123 self :setTooltip (self .tool .ToolTip )
124+ else
125+ self :setTooltip ("" )
134126 end
135127 end
136128 end
137129 onToolChange ()
138130
139131 -- Connect to tool property changes
140- local toolChangedConnection = tool .Changed :Connect (function (property )
132+ self . _toolChangedConnection = tool .Changed :Connect (function (property )
141133 if property == "Name" or property == "TextureId" or property == "ToolTip" then
142134 onToolChange ()
143135 end
144136 end )
145- table.insert (self ._connections , toolChangedConnection )
146137end
147138
148139-- Sets the text displayed on the slot button
@@ -176,4 +167,12 @@ function SlotButton.setParent(self: ClassType, parent: GuiBase2d?)
176167 self ._instance .button .Parent = parent
177168end
178169
170+ -- Updates the hint visibility based on preferred input method
171+ function SlotButton .onPreferredInputChanged (self : ClassType )
172+ local preferredInput = UserInputService .PreferredInput
173+ local isKeyboardAndMouse = preferredInput == Enum.PreferredInput.KeyboardAndMouse
174+
175+ self ._instance .hint .Visible = isKeyboardAndMouse
176+ end
177+
179178return SlotButton
0 commit comments