--[[ Local Functions ]]
--
local function onShiftLockToggled(Value, Lock) -- NEW: everything here
	
	-- Process if not prevented, or prevention being disabled
	if PreventShiftLock == false or Lock == false then		
		
		-- Change
		IsShiftLocked = Value ~= nil and Value or not IsShiftLocked
		
		-- Begin prevention
		if Lock ~= nil then
			PreventShiftLock = Lock
			if Lock == false and Value == false then -- When unlocked set to prior state before lock
				IsShiftLocked = ShiftLockedBefore
			end
		else
			ShiftLockedBefore = IsShiftLocked -- Remember for when unlocking
		end
		
		-- Update mouse cursor
		if IsShiftLocked then
			ShiftLockIcon.Image = SHIFT_LOCK_ON
			Mouse.Icon = SHIFT_LOCK_CURSOR
		else
			ShiftLockIcon.Image = SHIFT_LOCK_OFF
			Mouse.Icon = ""
		end
		
		-- Fire!
		ShiftLockController.OnShiftLockToggled:Fire()
	end
end

local function initialize()
	if ScreenGui then
		ScreenGui:Destroy()
		ScreenGui = nil
	end
	ScreenGui = Instance.new('ScreenGui')
	ScreenGui.Name = "ControlGui"
	
	local frame = Instance.new('Frame')
	frame.Name = "BottomLeftControl"
	frame.Size = UDim2.new(0, 130, 0, 46)
	frame.Position = UDim2.new(0, 0, 1, -46)
	frame.BackgroundTransparency = 1
	frame.Parent = ScreenGui
	
	ShiftLockIcon = Instance.new('ImageButton')
	ShiftLockIcon.Name = "MouseLockLabel"
	ShiftLockIcon.Size = UDim2.new(0, 31, 0, 31)
	ShiftLockIcon.Position = UDim2.new(0, 12, 0, 2)
	ShiftLockIcon.BackgroundTransparency = 1
	ShiftLockIcon.Image = IsShiftLocked and SHIFT_LOCK_ON or SHIFT_LOCK_OFF
	ShiftLockIcon.Visible = true
	ShiftLockIcon.Parent = frame
	
	ShiftLockIcon.MouseButton1Click:connect(onShiftLockToggled)
	
	ScreenGui.Parent = IsShiftLockMode and PlayerGui or nil
end
