------------------------------------------------------------------------
--Actual script starts here. I don't reccomend modifying anything past this point.

local UserInputService = game:GetService('UserInputService')

local IsMobile = UserInputService.TouchEnabled --Is true if on mobile.

if IsMobile then --Only does things if it's on mobile.
	local PlayerGui = game.Players.LocalPlayer:WaitForChild"PlayerGui"
	local PlayerScripts = game.Players.LocalPlayer:WaitForChild"PlayerScripts"
	
	local SHIFT_LOCK_OFF = 'rbxasset://textures/ui/mouseLock_off.png'
	local SHIFT_LOCK_ON = 'rbxasset://textures/ui/mouseLock_on.png'
	local SHIFT_LOCK_CURSOR = 'rbxasset://textures/MouseLockedCursor.png'
	
	--This essentially does what the scripts do for non-mobile players.
	--It is important to do it or else shift lock wouldn't work on mobile.
	local CM = PlayerScripts:WaitForChild"PlayerModule".CameraModule
	local CameraModule = require(CM).new()
	local MLC = require(CM.MouseLockController)
	
	CameraModule.activeMouseLockController = MLC.new()
	local toggleEvent = CameraModule.activeMouseLockController:GetBindableToggleEvent()
	if toggleEvent then
		toggleEvent:Connect(function()
			CameraModule:OnMouseLockToggled()
		end)
	end
	
	--Create the gui.
	local MouseLockController = CameraModule.activeMouseLockController
	local frame = Instance.new('Frame')
	frame.Name = "BottomLeftControl"
	frame.Size = UDim2.new(.1, 0, .1, 0)
	frame.Position = UDim2.new(1, 0, 1, 0)
	frame.AnchorPoint = Vector2.new(1,1)
	frame.BackgroundTransparency = 1
	frame.ZIndex = 10
	frame.Parent = script.Parent
	
	local ShiftLockIcon = Instance.new('ImageButton')
	ShiftLockIcon.Name = "MouseLockLabel"
	ShiftLockIcon.Size = UDim2.new(1, 0, 1, 0)
	ShiftLockIcon.Position = UDim2.new(0, 0, 0, 0)
	ShiftLockIcon.BackgroundTransparency = 1
	ShiftLockIcon.Image = SHIFT_LOCK_OFF
	ShiftLockIcon.Visible = true
	ShiftLockIcon.Parent = frame
	
	local frame2 = Instance.new('Frame')
	frame2.Name = "MiddleIcon"
	frame2.Size = UDim2.new(.1, 0, .1, 0)
	frame2.Position = UDim2.new(.5, 0, .5, 0)
	frame2.AnchorPoint = Vector2.new(.5,.5)
	frame2.BackgroundTransparency = 1
	frame2.ZIndex = 10
	frame2.Visible = false
	frame2.Parent = script.Parent
	
	local MouseLockCursor = Instance.new('ImageButton')
	MouseLockCursor.Name = "MouseLockLabel"
	MouseLockCursor.Size = UDim2.new(1, 0, 1, 0)
	MouseLockCursor.Position = UDim2.new(0, 0, 0, 0)
	MouseLockCursor.BackgroundTransparency = 1
	MouseLockCursor.Image = SHIFT_LOCK_CURSOR
	MouseLockCursor.Visible = true
	MouseLockCursor.Parent = frame2
	
	local arc = Instance.new("UIAspectRatioConstraint")
	arc.AspectRatio = 1
	arc.DominantAxis = "Height"
	arc.Parent = frame
	arc:Clone().Parent = frame2
	
	--This event fires when shift lock is activated.
	--It just changes the icon.
	toggleEvent:Connect(function()
		local IsLocked = CameraModule.activeMouseLockController:IsMouseLocked()
		ShiftLockIcon.Image = IsLocked and SHIFT_LOCK_ON or SHIFT_LOCK_OFF
		if SHOW_CENTER_CURSOR then
			frame2.Visible = IsLocked
		end
	end)
	
	--When the icon is pressed, get the camera module to toggle shift lock.
	ShiftLockIcon.Activated:connect(function()
		MouseLockController:DoMouseLockSwitch(0, Enum.UserInputState.Begin)
	end)
end