(coroutine.wrap(function()runService.Heartbeat:Wait()local v=require(script.Parent)local Y=((((((v.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")Y.deselectWhenOtherIconSelected=false local function y()local v=userInputService.MouseEnabled local y=userInputService.GamepadEnabled local w=Y.isSelected if v and y then Y:setEnabled(true)elseif v and not y then Y:setEnabled(false)IconController._enableControllerMode(false)Y:deselect()elseif not v and y then Y:setEnabled(false)IconController._enableControllerMode(true)end end;(userInputService:GetPropertyChangedSignal("\077\111\117\115\101\069\110\097\098\108\101\100")):Connect(y)userInputService.GamepadConnected:Connect(y)userInputService.GamepadDisconnected:Connect(y)y()local function w()local v=Y.isSelected local y=v 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"Y:setTip(y)IconController._enableControllerMode(v)end Y.selected:Connect(w)Y.deselected:Connect(w)userInputService.InputBegan:Connect(function(v,Y)if not IconController.controllerModeEnabled then return end if v.KeyCode==Enum.KeyCode.DPadDown then if not guiService.SelectedObject and checkTopbarEnabled()then IconController.setTopbarEnabled(true,false)end elseif v.KeyCode==Enum.KeyCode.ButtonB then IconController._previousSelectedObject=guiService.SelectedObject IconController._setControllerSelectedObject(nil)IconController.setTopbarEnabled(false,false)end v:Destroy()end)for Y,y in pairs(alignmentDetails)do if Y~="\109\105\100"then local w="\095\111\118\101\114\102\108\111\119\073\099\111\110-"..Y local I=(((v.new()):setImage(6069276526)):setName(w)):setEnabled(false)y.overflowIcon=I I.accountForWhenDisabled=true if Y=="\108\101\102\116"then I:setOrder(math.huge)I:setLeft()I:set("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116","\114\105\103\104\116")elseif Y=="\114\105\103\104\116"then I:setOrder(-math.huge)I:setRight()I:set("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116","\108\101\102\116")end I.lockedSettings={iconImage=true,order=true,alignment=true}end end end))()
-- BEHAVIOUR
--Controller support
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
			overflowIcon.lockedSettings = {
				["iconImage"] = true,
				["order"] = true,
				["alignment"] = true,
			}
		end
	end
end)()
