local R={}function ResizeTool.Equip()ShowUI()ShowHandles()BindShortcutKeys()end function ResizeTool.Unequip()HideUI()HideHandles()ClearConnections()SnapTracking.StopTracking()FinishSnapping()end function ClearConnections()for j,h in pairs(R)do h:Disconnect()R[j]=nil end end function ClearConnection(j)local h=R[j]if h then h:Disconnect()R[j]=nil end end function ShowUI()if ResizeTool.UI then ResizeTool.UI.Visible=true UIUpdater=Support.ScheduleRecurringTask(UpdateUI,.1)return end ResizeTool.UI=Core.Tool.Interfaces.BTResizeToolGUI:Clone()ResizeTool.UI.Parent=Core.UI ResizeTool.UI.Visible=true local R=ResizeTool.UI.DirectionsOption R.Normal.Button.MouseButton1Down:Connect(function()SetDirections("\078\111\114\109\097\108")end)R.Both.Button.MouseButton1Down:Connect(function()SetDirections("\066\111\116\104")end)local j=ResizeTool.UI.IncrementOption.Increment.TextBox j.FocusLost:Connect(function(R)ResizeTool.Increment=tonumber(j.Text)or ResizeTool.Increment j.Text=Support.Round(ResizeTool.Increment,4)end)local h=ResizeTool.UI.Info.SizeInfo.X.TextBox local q=ResizeTool.UI.Info.SizeInfo.Y.TextBox local y=ResizeTool.UI.Info.SizeInfo.Z.TextBox h.FocusLost:Connect(function(R)local j=tonumber(h.Text)if j then SetAxisSize("\088",j)end end)q.FocusLost:Connect(function(R)local j=tonumber(q.Text)if j then SetAxisSize("\089",j)end end)y.FocusLost:Connect(function(R)local j=tonumber(y.Text)if j then SetAxisSize("\090",j)end end)local b=(ResizeTool.UI:WaitForChild("\084\105\116\108\101")):WaitForChild("\083\105\103\110\097\116\117\114\101")ListenForManualWindowTrigger(ResizeTool.ManualText,ResizeTool.Color.Color,b)UIUpdater=Support.ScheduleRecurringTask(UpdateUI,.1)end function HideUI()if not ResizeTool.UI then return end ResizeTool.UI.Visible=false UIUpdater:Stop()end function UpdateUI()if not ResizeTool.UI then return end if#Selection.Parts==0 then ResizeTool.UI.Info.Visible=false ResizeTool.UI.Size=UDim2.new(0,245,0,90)return else ResizeTool.UI.Info.Visible=true ResizeTool.UI.Size=UDim2.new(0,245,0,150)end local R,j,h={},{},{}for q,y in pairs(Selection.Parts)do table.insert(R,Support.Round(y.Size.X,3))table.insert(j,Support.Round(y.Size.Y,3))table.insert(h,Support.Round(y.Size.Z,3))end local q=Support.IdentifyCommonItem(R)local y=Support.IdentifyCommonItem(j)local b=Support.IdentifyCommonItem(h)local P=ResizeTool.UI.Info.SizeInfo.X.TextBox local v=ResizeTool.UI.Info.SizeInfo.Y.TextBox local z=ResizeTool.UI.Info.SizeInfo.Z.TextBox if not P:IsFocused()then P.Text=q or"\042"end if not v:IsFocused()then v.Text=y or"\042"end if not z:IsFocused()then z.Text=b or"\042"end end function SetDirections(R)ResizeTool.Directions=R if ResizeTool.UI then Core.ToggleSwitch(R,ResizeTool.UI.DirectionsOption)end end
-- Container for temporary connections (disconnected automatically)
local Connections = {}

function ResizeTool.Equip()
	-- Enables the tool's equipped functionality

	-- Start up our interface
	ShowUI()
	ShowHandles()
	BindShortcutKeys()
end

function ResizeTool.Unequip()
	-- Disables the tool's equipped functionality

	-- Clear unnecessary resources
	HideUI()
	HideHandles()
	ClearConnections()
	SnapTracking.StopTracking()
	FinishSnapping()
end

function ClearConnections()
	-- Clears out temporary connections

	for ConnectionKey, Connection in pairs(Connections) do
		Connection:Disconnect()
		Connections[ConnectionKey] = nil
	end
end

function ClearConnection(ConnectionKey)
	-- Clears the given specific connection

	local Connection = Connections[ConnectionKey]

	-- Disconnect the connection if it exists
	if Connection then
		Connection:Disconnect()
		Connections[ConnectionKey] = nil
	end
end

function ShowUI()
	-- Creates and reveals the UI

	-- Reveal UI if already created
	if ResizeTool.UI then
		-- Reveal the UI
		ResizeTool.UI.Visible = true

		-- Update the UI every 0.1 seconds
		UIUpdater = Support.ScheduleRecurringTask(UpdateUI, 0.1)

		-- Skip UI creation
		return
	end

	-- Create the UI
	ResizeTool.UI = Core.Tool.Interfaces.BTResizeToolGUI:Clone()
	ResizeTool.UI.Parent = Core.UI
	ResizeTool.UI.Visible = true

	-- Add functionality to the directions option switch
	local DirectionsSwitch = ResizeTool.UI.DirectionsOption
	DirectionsSwitch.Normal.Button.MouseButton1Down:Connect(function()
		SetDirections("Normal")
	end)
	DirectionsSwitch.Both.Button.MouseButton1Down:Connect(function()
		SetDirections("Both")
	end)

	-- Add functionality to the increment input
	local IncrementInput = ResizeTool.UI.IncrementOption.Increment.TextBox
	IncrementInput.FocusLost:Connect(function(EnterPressed)
		ResizeTool.Increment = tonumber(IncrementInput.Text) or ResizeTool.Increment
		IncrementInput.Text = Support.Round(ResizeTool.Increment, 4)
	end)

	-- Add functionality to the size inputs
	local XInput = ResizeTool.UI.Info.SizeInfo.X.TextBox
	local YInput = ResizeTool.UI.Info.SizeInfo.Y.TextBox
	local ZInput = ResizeTool.UI.Info.SizeInfo.Z.TextBox
	XInput.FocusLost:Connect(function(EnterPressed)
		local NewSize = tonumber(XInput.Text)
		if NewSize then
			SetAxisSize("X", NewSize)
		end
	end)
	YInput.FocusLost:Connect(function(EnterPressed)
		local NewSize = tonumber(YInput.Text)
		if NewSize then
			SetAxisSize("Y", NewSize)
		end
	end)
	ZInput.FocusLost:Connect(function(EnterPressed)
		local NewSize = tonumber(ZInput.Text)
		if NewSize then
			SetAxisSize("Z", NewSize)
		end
	end)

	-- Hook up manual triggering
	local SignatureButton = ResizeTool.UI:WaitForChild("Title"):WaitForChild("Signature")
	ListenForManualWindowTrigger(ResizeTool.ManualText, ResizeTool.Color.Color, SignatureButton)

	-- Update the UI every 0.1 seconds
	UIUpdater = Support.ScheduleRecurringTask(UpdateUI, 0.1)
end

function HideUI()
	-- Hides the tool UI

	-- Make sure there's a UI
	if not ResizeTool.UI then
		return
	end

	-- Hide the UI
	ResizeTool.UI.Visible = false

	-- Stop updating the UI
	UIUpdater:Stop()
end

function UpdateUI()
	-- Updates information on the UI

	-- Make sure the UI's on
	if not ResizeTool.UI then
		return
	end

	-- Only show and calculate selection info if it's not empty
	if #Selection.Parts == 0 then
		ResizeTool.UI.Info.Visible = false
		ResizeTool.UI.Size = UDim2.new(0, 245, 0, 90)
		return
	else
		ResizeTool.UI.Info.Visible = true
		ResizeTool.UI.Size = UDim2.new(0, 245, 0, 150)
	end

	-----------------------------------------
	-- Update the size information indicators
	-----------------------------------------

	-- Identify common sizes across axes
	local XVariations, YVariations, ZVariations = {}, {}, {}
	for _, Part in pairs(Selection.Parts) do
		table.insert(XVariations, Support.Round(Part.Size.X, 3))
		table.insert(YVariations, Support.Round(Part.Size.Y, 3))
		table.insert(ZVariations, Support.Round(Part.Size.Z, 3))
	end
	local CommonX = Support.IdentifyCommonItem(XVariations)
	local CommonY = Support.IdentifyCommonItem(YVariations)
	local CommonZ = Support.IdentifyCommonItem(ZVariations)

	-- Shortcuts to indicators
	local XIndicator = ResizeTool.UI.Info.SizeInfo.X.TextBox
	local YIndicator = ResizeTool.UI.Info.SizeInfo.Y.TextBox
	local ZIndicator = ResizeTool.UI.Info.SizeInfo.Z.TextBox

	-- Update each indicator if it's not currently being edited
	if not XIndicator:IsFocused() then
		XIndicator.Text = CommonX or "*"
	end
	if not YIndicator:IsFocused() then
		YIndicator.Text = CommonY or "*"
	end
	if not ZIndicator:IsFocused() then
		ZIndicator.Text = CommonZ or "*"
	end
end

function SetDirections(DirectionMode)
	-- Sets the given resizing direction mode

	-- Update setting
	ResizeTool.Directions = DirectionMode

	-- Update the UI switch
	if ResizeTool.UI then
		Core.ToggleSwitch(DirectionMode, ResizeTool.UI.DirectionsOption)
	end
end
