(coroutine.wrap(function()runService.Heartbeat:Wait()local l=require(script.Parent)local G=((((((l.new()):setName("\095\084\111\112\098\097\114\067\111\110\116\114\111\108\108\101\114\079\112\116\105\111\110")):setOrder(100)):setImage("\114\098\120\097\115\115\101\116\105\100\058\047\047\053\050\055\056\049\053\048\057\052\050")):setRight()):setEnabled(false)):setTip("\067\111\110\116\114\111\108\108\101\114 \109\111\100\101")G.deselectWhenOtherIconSelected=false local function M()local l=userInputService.MouseEnabled local M=userInputService.GamepadEnabled local C=G.isSelected if l and M then G:setEnabled(true)elseif l and not M then G:setEnabled(false)IconController._enableControllerMode(false)G:deselect()elseif not l and M then G:setEnabled(false)IconController._enableControllerMode(true)end end;(userInputService:GetPropertyChangedSignal("\077\111\117\115\101\069\110\097\098\108\101\100")):Connect(M)userInputService.GamepadConnected:Connect(M)userInputService.GamepadDisconnected:Connect(M)M()local function C()local l=G.isSelected local M=l and"\078\111\114\109\097\108 \109\111\100\101"or"\067\111\110\116\114\111\108\108\101\114 \109\111\100\101"G:setTip(M)IconController._enableControllerMode(l)end G.selected:Connect(C)G.deselected:Connect(C)userInputService.InputBegan:Connect(function(l,G)if not IconController.controllerModeEnabled then return end if l.KeyCode==Enum.KeyCode.DPadDown then if not guiService.SelectedObject and checkTopbarEnabled()then IconController.setTopbarEnabled(true,false)end elseif l.KeyCode==Enum.KeyCode.ButtonB then IconController._previousSelectedObject=guiService.SelectedObject IconController._setControllerSelectedObject(nil)IconController.setTopbarEnabled(false,false)end l:Destroy()end)for G,M in pairs(alignmentDetails)do if G~="\109\105\100"then local C="\095\111\118\101\114\102\108\111\119\073\099\111\110-"..G local s=(((l.new()):setImage(6069276526)):setName(C)):setEnabled(false)M.overflowIcon=s s.accountForWhenDisabled=true if G=="\108\101\102\116"then s:setOrder(math.huge)s:setLeft()s:set("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116","\114\105\103\104\116")elseif G=="\114\105\103\104\116"then s:setOrder(-math.huge)s:setRight()s:set("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116","\108\101\102\116")end end end end))()

coroutine.wrap(function()
	
	-- Create PC 'Enter Controller Mode' Icon
	runService.Heartbeat:Wait() -- This is required to prevent an infinite recursion
	local Icon = require(script.Parent)
	local controllerOptionIcon = Icon.new()
		:setName("_TopbarControllerOption")
		:setOrder(100)
		:setImage("rbxassetid://5278150942")
		:setRight()
		:setEnabled(false)
		:setTip("Controller mode")
	controllerOptionIcon.deselectWhenOtherIconSelected = false

	-- This decides what controller widgets and displays to show based upon their connected inputs
	-- For example, if on PC with a controller, give the player the option to enable controller mode with a toggle
	-- While if using a console (no mouse, but controller) then bypass the toggle and automatically enable controller mode
	local function determineDisplay()
		local mouseEnabled = userInputService.MouseEnabled
		local controllerEnabled = userInputService.GamepadEnabled
		local iconIsSelected = controllerOptionIcon.isSelected
		if mouseEnabled and controllerEnabled then
			-- Show icon
			controllerOptionIcon:setEnabled(true)
		elseif mouseEnabled and not controllerEnabled then
			-- Hide icon, disableControllerMode
			controllerOptionIcon:setEnabled(false)
			IconController._enableControllerMode(false)
			controllerOptionIcon:deselect()
		elseif not mouseEnabled and controllerEnabled then
			-- Hide icon, _enableControllerMode
			controllerOptionIcon:setEnabled(false)
			IconController._enableControllerMode(true)
		end
	end
	userInputService:GetPropertyChangedSignal("MouseEnabled"):Connect(determineDisplay)
	userInputService.GamepadConnected:Connect(determineDisplay)
	userInputService.GamepadDisconnected:Connect(determineDisplay)
	determineDisplay()

	-- Enable/Disable Controller Mode when icon clicked
	local function iconClicked()
		local isSelected = controllerOptionIcon.isSelected
		local iconTip = (isSelected and "Normal mode") or "Controller mode"
		controllerOptionIcon:setTip(iconTip)
		IconController._enableControllerMode(isSelected)
	end
	controllerOptionIcon.selected:Connect(iconClicked)
	controllerOptionIcon.deselected:Connect(iconClicked)

	-- Hide/show topbar when indicator action selected in controller mode
	userInputService.InputBegan:Connect(function(input,gpe)
		if not IconController.controllerModeEnabled then return end
		if input.KeyCode == Enum.KeyCode.DPadDown then
			if not guiService.SelectedObject and checkTopbarEnabled() then
				IconController.setTopbarEnabled(true,false)
			end
		elseif input.KeyCode == Enum.KeyCode.ButtonB then
			IconController._previousSelectedObject = guiService.SelectedObject
			IconController._setControllerSelectedObject(nil)
			IconController.setTopbarEnabled(false,false)
		end
		input:Destroy()
	end)

	-- Setup overflow icons
	for alignment, detail in pairs(alignmentDetails) do
		if alignment ~= "mid" then
			local overflowName = "_overflowIcon-"..alignment
			local overflowIcon = Icon.new()
				:setImage(6069276526)
				:setName(overflowName)
				:setEnabled(false)
			detail.overflowIcon = overflowIcon
			overflowIcon.accountForWhenDisabled = true
			if alignment == "left" then
				overflowIcon:setOrder(math.huge)
				overflowIcon:setLeft()
				overflowIcon:set("dropdownAlignment", "right")
			elseif alignment == "right" then
				overflowIcon:setOrder(-math.huge)
				overflowIcon:setRight()
				overflowIcon:set("dropdownAlignment", "left")
			end
		end
	end
end)()
