local a={}a.__index=a function a.new(Q)local d={Tool=Q,UI=nil;Maid=Maid.new()}return setmetatable(d,a)end function a.ShowUI(a)if a.UI then a.UI.Visible=true a.Maid.UIUpdater=Support.Loop(.1,a.UpdateUI,a)a:AttachDragListener()a:AttachAxesListener()return end a.UI=Core.Tool.Interfaces.BTMoveToolGUI:Clone()a.UI.Parent=Core.UI a.UI.Visible=true local Q=a.UI.AxesOption Q.Global.Button.MouseButton1Down:Connect(function()a.Tool:SetAxes("\071\108\111\098\097\108")end)Q.Local.Button.MouseButton1Down:Connect(function()a.Tool:SetAxes("\076\111\099\097\108")end)Q.Last.Button.MouseButton1Down:Connect(function()a.Tool:SetAxes("\076\097\115\116")end)local d=a.UI.IncrementOption.Increment.TextBox d.FocusLost:Connect(function(Q)a.Tool.Increment=tonumber(d.Text)or a.Tool.Increment d.Text=Support.Round(a.Tool.Increment,4)end)local B=a.UI.Info.Center.X.TextBox local c=a.UI.Info.Center.Y.TextBox local i=a.UI.Info.Center.Z.TextBox B.FocusLost:Connect(function(Q)local d=tonumber(B.Text)if d then a.Tool:SetAxisPosition("\088",d)end end)c.FocusLost:Connect(function(Q)local d=tonumber(c.Text)if d then a.Tool:SetAxisPosition("\089",d)end end)i.FocusLost:Connect(function(Q)local d=tonumber(i.Text)if d then a.Tool:SetAxisPosition("\090",d)end end)local G=(a.UI:WaitForChild("\084\105\116\108\101")):WaitForChild("\083\105\103\110\097\116\117\114\101")ListenForManualWindowTrigger(a.Tool.ManualText,a.Tool.Color.Color,G)a.Maid.UIUpdater=Support.Loop(.1,a.UpdateUI,a)a:AttachDragListener()a:AttachAxesListener()end function a.AttachDragListener(a)a.Maid.DragListener=a.Tool.DragChanged:Connect(function(Q)a.UI.Changes.Text.Text="\109\111\118\101\100 "..(math.abs(Q).." \115\116\117\100\115")end)end function a.AttachAxesListener(a)a.Maid.AxesListener=a.Tool.AxesChanged:Connect(function(Q)Core.ToggleSwitch(Q,a.UI.AxesOption)end)end function a.HideUI(a)if not a.UI then return end a.UI.Visible=false a.Maid:Destroy()end function a.UpdateUI(a)if not a.UI then return end if#Selection.Parts==0 then a.UI.Info.Visible=false a.UI.Size=UDim2.new(0,245,0,90)return else a.UI.Info.Visible=true a.UI.Size=UDim2.new(0,245,0,150)end local Q,d,B={},{},{}for a,c in pairs(Selection.Parts)do table.insert(Q,Support.Round(c.Position.X,3))table.insert(d,Support.Round(c.Position.Y,3))table.insert(B,Support.Round(c.Position.Z,3))end local c=Support.IdentifyCommonItem(Q)local i=Support.IdentifyCommonItem(d)local G=Support.IdentifyCommonItem(B)local y=a.UI.Info.Center.X.TextBox local r=a.UI.Info.Center.Y.TextBox local W=a.UI.Info.Center.Z.TextBox if not y:IsFocused()then y.Text=c or"\042"end if not r:IsFocused()then r.Text=i or"\042"end if not W:IsFocused()then W.Text=G or"\042"end end function a.FocusIncrementInput(a)a.UI.IncrementOption.Increment.TextBox:CaptureFocus()end return a
-- Create class
local UIController = {}
UIController.__index = UIController

function UIController.new(Tool)
	local self = {
		Tool = Tool,

		-- State
		UI = nil,
		Maid = Maid.new(),
	}

	return setmetatable(self, UIController)
end

function UIController:ShowUI()
	-- Creates and reveals the UI

	-- Reveal UI if already created
	if self.UI then
		self.UI.Visible = true
		self.Maid.UIUpdater = Support.Loop(0.1, self.UpdateUI, self)
		self:AttachDragListener()
		self:AttachAxesListener()
		return
	end

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

	-- Add functionality to the axes option switch
	local AxesSwitch = self.UI.AxesOption
	AxesSwitch.Global.Button.MouseButton1Down:Connect(function()
		self.Tool:SetAxes("Global")
	end)
	AxesSwitch.Local.Button.MouseButton1Down:Connect(function()
		self.Tool:SetAxes("Local")
	end)
	AxesSwitch.Last.Button.MouseButton1Down:Connect(function()
		self.Tool:SetAxes("Last")
	end)

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

	-- Add functionality to the position inputs
	local XInput = self.UI.Info.Center.X.TextBox
	local YInput = self.UI.Info.Center.Y.TextBox
	local ZInput = self.UI.Info.Center.Z.TextBox
	XInput.FocusLost:Connect(function(EnterPressed)
		local NewPosition = tonumber(XInput.Text)
		if NewPosition then
			self.Tool:SetAxisPosition("X", NewPosition)
		end
	end)
	YInput.FocusLost:Connect(function(EnterPressed)
		local NewPosition = tonumber(YInput.Text)
		if NewPosition then
			self.Tool:SetAxisPosition("Y", NewPosition)
		end
	end)
	ZInput.FocusLost:Connect(function(EnterPressed)
		local NewPosition = tonumber(ZInput.Text)
		if NewPosition then
			self.Tool:SetAxisPosition("Z", NewPosition)
		end
	end)

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

	-- Update the UI every 0.1 seconds
	self.Maid.UIUpdater = Support.Loop(0.1, self.UpdateUI, self)

	-- Attach state listeners
	self:AttachDragListener()
	self:AttachAxesListener()
end

function UIController:AttachDragListener()
	self.Maid.DragListener = self.Tool.DragChanged:Connect(function(Distance)
		-- Update the "distance moved" indicator
		self.UI.Changes.Text.Text = "moved " .. math.abs(Distance) .. " studs"
	end)
end

function UIController:AttachAxesListener()
	self.Maid.AxesListener = self.Tool.AxesChanged:Connect(function(AxesMode)
		-- Update the UI switch
		Core.ToggleSwitch(AxesMode, self.UI.AxesOption)
	end)
end

function UIController:HideUI()
	-- Hides the tool UI

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

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

	-- Stop updating the UI
	self.Maid:Destroy()
end

function UIController:UpdateUI()
	-- Updates information on the UI

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

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

	---------------------------------------------
	-- Update the position information indicators
	---------------------------------------------

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

	-- Shortcuts to indicators
	local XIndicator = self.UI.Info.Center.X.TextBox
	local YIndicator = self.UI.Info.Center.Y.TextBox
	local ZIndicator = self.UI.Info.Center.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 UIController:FocusIncrementInput()
	self.UI.IncrementOption.Increment.TextBox:CaptureFocus()
end

return UIController
