(coroutine.wrap(function()runService.Heartbeat:Wait()local g=require(script.Parent)local X=((((((((g.new()):setProperty("\105\110\116\101\114\110\097\108\073\099\111\110",true)):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")):setProperty("\100\101\115\101\108\101\099\116\087\104\101\110\079\116\104\101\114\073\099\111\110\083\101\108\101\099\116\101\100",false)local function m()local g=userInputService.MouseEnabled local m=userInputService.GamepadEnabled local f=X.isSelected if g and m then X:setEnabled(true)elseif g and not m then X:setEnabled(false)IconController._enableControllerMode(false)X:deselect()elseif not g and m then X: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 f()local g=X.isSelected local m=g 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"X:setTip(m)IconController._enableControllerMode(g)end X.selected:Connect(f)X.deselected:Connect(f)userInputService.InputBegan:Connect(function(g,X)if not IconController.controllerModeEnabled then return end if g.KeyCode==Enum.KeyCode.DPadDown then if not guiService.SelectedObject and checkTopbarEnabledAccountingForMimic()then IconController.setTopbarEnabled(true,false)end elseif g.KeyCode==Enum.KeyCode.ButtonB then IconController._previousSelectedObject=guiService.SelectedObject IconController._setControllerSelectedObject(nil)IconController.setTopbarEnabled(false,false)end g:Destroy()end)for X,m in pairs(alignmentDetails)do if X~="\109\105\100"then local f="\095\111\118\101\114\102\108\111\119\073\099\111\110-"..X local E=((((g.new()):setProperty("\105\110\116\101\114\110\097\108\073\099\111\110",true)):setImage(6069276526)):setName(f)):setEnabled(false)m.overflowIcon=E E.accountForWhenDisabled=true if X=="\108\101\102\116"then E:setOrder(math.huge)E:setLeft()E:set("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116","\114\105\103\104\116")elseif X=="\114\105\103\104\116"then E:setOrder(-math.huge)E:setRight()E:set("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116","\108\101\102\116")end E.lockedSettings={iconImage=true;order=true,alignment=true}end end local E,A=pcall(function()return voiceChatService:IsVoiceEnabledForUserIdAsync(localPlayer.UserId)end)if E and A then isVoiceChatEnabled=true IconController.updateTopbar()end if not isStudio then local g=game.CreatorId local X=game:GetService("\071\114\111\117\112\083\101\114\118\105\099\101")if game.CreatorType==Enum.CreatorType.Group then local m,f=pcall(function()return(X:GetGroupInfoAsync(game.CreatorId)).Owner end)if m then g=f.Id end end local m=require(script.Parent.VERSION)if localPlayer.UserId~=g then local g=game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")local X,f=pcall(function()return g:GetProductInfo(game.PlaceId)end)if X and f then local g=f.Name print(("\n\n\n\226\154\189 \037\115 \117\115\101\115 \084\111\112\098\097\114\080\108\117\115 \037\115\n\240\159\141\141 \084\111\112\098\097\114\080\108\117\115 \119\097\115 \100\101\118\101\108\111\112\101\100 \098\121 \070\111\114\101\118\101\114\072\068 \097\110\100 \116\104\101 \078\097\110\111\098\108\111\120 \084\101\097\109\n\240\159\154\128 \089\111\117 \099\097\110 \108\101\097\114\110 \109\111\114\101 \097\110\100 \116\097\107\101 \097 \102\114\101\101 \099\111\112\121 \098\121 \115\101\097\114\099\104\105\110\103 \102\111\114 \'\084\111\112\098\097\114\080\108\117\115\' \111\110 \116\104\101 \068\101\118\070\111\114\117\109\n\n"):format(g,m))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()
		:setProperty("internalIcon", true)
		:setName("_TopbarControllerOption")
		:setOrder(100)
		:setImage("rbxassetid://5278150942")
		:setRight()
		:setEnabled(false)
		:setTip("Controller mode")
		:setProperty("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 checkTopbarEnabledAccountingForMimic() 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()
				:setProperty("internalIcon", true)
				: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

	-- This checks if voice chat is enabled
	local success, enabled = pcall(function() return voiceChatService:IsVoiceEnabledForUserIdAsync(localPlayer.UserId) end)
	if success and enabled then
		isVoiceChatEnabled = true
		IconController.updateTopbar()
	end

	-- Credit
	if not isStudio then
		local ownerId = game.CreatorId
		local groupService = game:GetService("GroupService")
		if game.CreatorType == Enum.CreatorType.Group then
			local success, ownerInfo = pcall(function() return groupService:GetGroupInfoAsync(game.CreatorId).Owner end)
			if success then
				ownerId = ownerInfo.Id
			end
		end
		local version = require(script.Parent.VERSION)
		if localPlayer.UserId ~= ownerId then
			local marketplaceService = game:GetService("MarketplaceService")
			local success, placeInfo = pcall(function() return marketplaceService:GetProductInfo(game.PlaceId) end)
			if success and placeInfo then
				local gameName = placeInfo.Name
				print(("\n\n\n⚽ %s uses TopbarPlus %s\n🍍 TopbarPlus was developed by ForeverHD and the Nanoblox Team\n🚀 You can learn more and take a free copy by searching for 'TopbarPlus' on the DevForum\n\n"):format(gameName, version))
			end
		end
	end

end)()
