local function z(z)return function(T)local P=Instance.new(z)local E=T.Parent T.Parent=nil for z,T in pairs(T)do if type(z)=="\115\116\114\105\110\103"then P[z]=T else T.Parent=P end end P.Parent=E return P end end local T=false local P local E local K local o local f local function x()assert(not T)P=(z("\083\099\114\101\101\110\071\117\105"))({Name="\082\098\120\067\097\109\101\114\097\085\073";AutoLocalize=false;Enabled=true;DisplayOrder=-1,IgnoreGuiInset=false,ResetOnSpawn=false,ZIndexBehavior=Enum.ZIndexBehavior.Sibling;(z("\073\109\097\103\101\076\097\098\101\108"))({Name="\084\111\097\115\116",Visible=false;AnchorPoint=Vector2.new(.5,0);BackgroundTransparency=1;BorderSizePixel=0;Position=UDim2.new(.5,0,0,8);Size=TOAST_CLOSED_SIZE;Image="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\117\105\047\067\097\109\101\114\097\047\067\097\109\101\114\097\084\111\097\115\116\057\083\108\105\099\101\046\112\110\103",ImageColor3=TOAST_BACKGROUND_COLOR;ImageRectSize=Vector2.new(6,6),ImageTransparency=1;ScaleType=Enum.ScaleType.Slice,SliceCenter=Rect.new(3,3,3,3),ClipsDescendants=true,(z("\070\114\097\109\101"))({Name="\073\099\111\110\066\117\102\102\101\114",BackgroundTransparency=1;BorderSizePixel=0;Position=UDim2.new(0,0,0,0),Size=UDim2.new(0,80,1,0),(z("\073\109\097\103\101\076\097\098\101\108"))({Name="\073\099\111\110";AnchorPoint=Vector2.new(.5,.5);BackgroundTransparency=1,Position=UDim2.new(.5,0,.5,0);Size=UDim2.new(0,48,0,48),ZIndex=2,Image="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\117\105\047\067\097\109\101\114\097\047\067\097\109\101\114\097\084\111\097\115\116\073\099\111\110\046\112\110\103";ImageColor3=TOAST_FOREGROUND_COLOR,ImageTransparency=1})}),(z("\070\114\097\109\101"))({Name="\084\101\120\116\066\117\102\102\101\114";BackgroundTransparency=1;BorderSizePixel=0;Position=UDim2.new(0,80,0,0);Size=UDim2.new(1,-80,1,0);ClipsDescendants=true,(z("\084\101\120\116\076\097\098\101\108"))({Name="\085\112\112\101\114";AnchorPoint=Vector2.new(0,1),BackgroundTransparency=1;Position=UDim2.new(0,0,.5,0),Size=UDim2.new(1,0,0,19),Font=Enum.Font.GothamSemibold;Text="\067\097\109\101\114\097 \099\111\110\116\114\111\108 \101\110\097\098\108\101\100";TextColor3=TOAST_FOREGROUND_COLOR;TextTransparency=1;TextSize=19;TextXAlignment=Enum.TextXAlignment.Left,TextYAlignment=Enum.TextYAlignment.Center}),(z("\084\101\120\116\076\097\098\101\108"))({Name="\076\111\119\101\114",AnchorPoint=Vector2.new(0,0);BackgroundTransparency=1,Position=UDim2.new(0,0,.5,3);Size=UDim2.new(1,0,0,15),Font=Enum.Font.Gotham;Text="\082\105\103\104\116 \109\111\117\115\101 \098\117\116\116\111\110 \116\111 \116\111\103\103\108\101";TextColor3=TOAST_FOREGROUND_COLOR,TextTransparency=1,TextSize=15,TextXAlignment=Enum.TextXAlignment.Left;TextYAlignment=Enum.TextYAlignment.Center})})});Parent=PlayerGui})E=P.Toast K=E.IconBuffer.Icon o=E.TextBuffer.Upper f=E.TextBuffer.Lower T=true end local c={}do function c.setCameraModeToastEnabled(z)if not z and not T then return end if not T then x()end E.Visible=z if not z then c.setCameraModeToastOpen(false)end end local z=TweenInfo.new(.25,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)function c.setCameraModeToastOpen(P)assert(T);(TweenService:Create(E,z,{Size=P and TOAST_OPEN_SIZE or TOAST_CLOSED_SIZE;ImageTransparency=P and TOAST_BACKGROUND_TRANS or 1})):Play();(TweenService:Create(K,z,{ImageTransparency=P and TOAST_FOREGROUND_TRANS or 1})):Play();(TweenService:Create(o,z,{TextTransparency=P and TOAST_FOREGROUND_TRANS or 1})):Play();(TweenService:Create(f,z,{TextTransparency=P and TOAST_FOREGROUND_TRANS or 1})):Play()end end return c

local function create(className)
	return function(props)
		local inst = Instance.new(className)
		local parent = props.Parent
		props.Parent = nil
		for name, val in pairs(props) do
			if type(name) == "string" then
				inst[name] = val
			else
				val.Parent = inst
			end
		end
		-- Only set parent after all other properties are initialized
		inst.Parent = parent
		return inst
	end
end

local initialized = false

local uiRoot
local toast
local toastIcon
local toastUpperText
local toastLowerText

local function initializeUI()
	assert(not initialized)

	uiRoot = create("ScreenGui"){
		Name = "RbxCameraUI",
		AutoLocalize = false,
		Enabled = true,
		DisplayOrder = -1, -- Appears behind default developer UI
		IgnoreGuiInset = false,
		ResetOnSpawn = false,
		ZIndexBehavior = Enum.ZIndexBehavior.Sibling,

		create("ImageLabel"){
			Name = "Toast",
			Visible = false,
			AnchorPoint = Vector2.new(0.5, 0),
			BackgroundTransparency = 1,
			BorderSizePixel = 0,
			Position = UDim2.new(0.5, 0, 0, 8),
			Size = TOAST_CLOSED_SIZE,
			Image = "rbxasset://textures/ui/Camera/CameraToast9Slice.png",
			ImageColor3 = TOAST_BACKGROUND_COLOR,
			ImageRectSize = Vector2.new(6, 6),
			ImageTransparency = 1,
			ScaleType = Enum.ScaleType.Slice,
			SliceCenter = Rect.new(3, 3, 3, 3),
			ClipsDescendants = true,

			create("Frame"){
				Name = "IconBuffer",
				BackgroundTransparency = 1,
				BorderSizePixel = 0,
				Position = UDim2.new(0, 0, 0, 0),
				Size = UDim2.new(0, 80, 1, 0),

				create("ImageLabel"){
					Name = "Icon",
					AnchorPoint = Vector2.new(0.5, 0.5),
					BackgroundTransparency = 1,
					Position = UDim2.new(0.5, 0, 0.5, 0),
					Size = UDim2.new(0, 48, 0, 48),
					ZIndex = 2,
					Image = "rbxasset://textures/ui/Camera/CameraToastIcon.png",
					ImageColor3 = TOAST_FOREGROUND_COLOR,
					ImageTransparency = 1,
				}
			},

			create("Frame"){
				Name = "TextBuffer",
				BackgroundTransparency = 1,
				BorderSizePixel = 0,
				Position = UDim2.new(0, 80, 0, 0),
				Size = UDim2.new(1, -80, 1, 0),
				ClipsDescendants = true,

				create("TextLabel"){
					Name = "Upper",
					AnchorPoint = Vector2.new(0, 1),
					BackgroundTransparency = 1,
					Position = UDim2.new(0, 0, 0.5, 0),
					Size = UDim2.new(1, 0, 0, 19),
					Font = Enum.Font.GothamSemibold,
					Text = "Camera control enabled",
					TextColor3 = TOAST_FOREGROUND_COLOR,
					TextTransparency = 1,
					TextSize = 19,
					TextXAlignment = Enum.TextXAlignment.Left,
					TextYAlignment = Enum.TextYAlignment.Center,
				},

				create("TextLabel"){
					Name = "Lower",
					AnchorPoint = Vector2.new(0, 0),
					BackgroundTransparency = 1,
					Position = UDim2.new(0, 0, 0.5, 3),
					Size = UDim2.new(1, 0, 0, 15),
					Font = Enum.Font.Gotham,
					Text = "Right mouse button to toggle",
					TextColor3 = TOAST_FOREGROUND_COLOR,
					TextTransparency = 1,
					TextSize = 15,
					TextXAlignment = Enum.TextXAlignment.Left,
					TextYAlignment = Enum.TextYAlignment.Center,
				},
			},
		},

		Parent = PlayerGui,
	}

	toast = uiRoot.Toast
	toastIcon = toast.IconBuffer.Icon
	toastUpperText = toast.TextBuffer.Upper
	toastLowerText = toast.TextBuffer.Lower

	initialized = true
end

local CameraUI = {}

do
	-- Instantaneously disable the toast or enable for opening later on. Used when switching camera modes.
	function CameraUI.setCameraModeToastEnabled(enabled)
		if not enabled and not initialized then
			return
		end

		if not initialized then
			initializeUI()
		end

		toast.Visible = enabled
		if not enabled then
			CameraUI.setCameraModeToastOpen(false)
		end
	end

	local tweenInfo = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

	-- Tween the toast in or out. Toast must be enabled with setCameraModeToastEnabled.
	function CameraUI.setCameraModeToastOpen(open)
		assert(initialized)

		TweenService:Create(toast, tweenInfo, {
			Size = open and TOAST_OPEN_SIZE or TOAST_CLOSED_SIZE,
			ImageTransparency = open and TOAST_BACKGROUND_TRANS or 1,
		}):Play()

		TweenService:Create(toastIcon, tweenInfo, {
			ImageTransparency = open and TOAST_FOREGROUND_TRANS or 1,
		}):Play()

		TweenService:Create(toastUpperText, tweenInfo, {
			TextTransparency = open and TOAST_FOREGROUND_TRANS or 1,
		}):Play()

		TweenService:Create(toastLowerText, tweenInfo, {
			TextTransparency = open and TOAST_FOREGROUND_TRANS or 1,
		}):Play()
	end
end

return CameraUI
