function IconController._updateSelectionGroup(S,T)if IconController._navigationEnabled then guiService:RemoveSelectionGroup("\084\111\112\098\097\114\080\108\117\115\073\099\111\110\115")end if T then guiService.CoreGuiNavigationEnabled=IconController._originalCoreGuiNavigationEnabled guiService.GuiNavigationEnabled=IconController._originalGuiNavigationEnabled IconController._navigationEnabled=nil elseif IconController.controllerModeEnabled then local T=IconController.getIcons()local S={}for T,v in pairs(T)do local t=v.joinedFeatureName if not t or v._parentIcon[v.joinedFeatureName.."\079\112\101\110"]==true then table.insert(S,v.instances.iconButton)end end guiService:AddSelectionTuple("\084\111\112\098\097\114\080\108\117\115\073\099\111\110\115",table.unpack(S))if not IconController._navigationEnabled then IconController._originalCoreGuiNavigationEnabled=guiService.CoreGuiNavigationEnabled IconController._originalGuiNavigationEnabled=guiService.GuiNavigationEnabled guiService.CoreGuiNavigationEnabled=false guiService.GuiNavigationEnabled=true IconController._navigationEnabled=true end end end local function T()if guiService:IsTenFootInterface()then return 3 else return 1.3 end end function IconController._setControllerSelectedObject(T)local S=IconController._controllerSetCount and IconController._controllerSetCount+1 or 0 IconController._controllerSetCount=S guiService.SelectedObject=T delay(.1,function()local v=IconController._controllerSetCount if S==v then guiService.SelectedObject=T end end)end function IconController._enableControllerMode(S)local v=TopbarPlusGui.Indicator local t=IconController.getIcon("\095\084\111\112\098\097\114\067\111\110\116\114\111\108\108\101\114\079\112\116\105\111\110")if IconController.controllerModeEnabled==S then return end IconController.controllerModeEnabled=S if S then TopbarPlusGui.TopbarContainer.Position=UDim2.new(0,0,0,5)TopbarPlusGui.TopbarContainer.Visible=false local S=T()v.Position=UDim2.new(.5,0,0,5)v.Size=UDim2.new(0,18*S,0,18*S)v.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\050\055\056\049\053\049\053\053\054"v.Visible=checkTopbarEnabled()v.Position=UDim2.new(.5,0,0,5)else TopbarPlusGui.TopbarContainer.Position=UDim2.new(0,0,0,0)TopbarPlusGui.TopbarContainer.Visible=checkTopbarEnabled()v.Visible=false IconController._setControllerSelectedObject(nil)end for T,v in pairs(topbarIcons)do IconController._enableControllerModeForIcon(T,S)end end function IconController._enableControllerModeForIcon(S,v)local t=S._parentIcon local a=S.joinedFeatureName if t then S:leave()end if v then local v=T()local t=S:get("\105\099\111\110\083\105\122\101","\100\101\115\101\108\101\099\116\101\100")local a=S:get("\105\099\111\110\083\105\122\101","\115\101\108\101\099\116\101\100")local u=S:getHovering("\105\099\111\110\083\105\122\101")S:set("\105\099\111\110\083\105\122\101",UDim2.new(0,t.X.Offset*v,0,t.Y.Offset*v),"\100\101\115\101\108\101\099\116\101\100","\099\111\110\116\114\111\108\108\101\114\077\111\100\101")S:set("\105\099\111\110\083\105\122\101",UDim2.new(0,a.X.Offset*v,0,a.Y.Offset*v),"\115\101\108\101\099\116\101\100","\099\111\110\116\114\111\108\108\101\114\077\111\100\101")if u then S:set("\105\099\111\110\083\105\122\101",UDim2.new(0,a.X.Offset*v,0,a.Y.Offset*v),"\104\111\118\101\114\105\110\103","\099\111\110\116\114\111\108\108\101\114\077\111\100\101")end S:set("\097\108\105\103\110\109\101\110\116","\109\105\100","\100\101\115\101\108\101\099\116\101\100","\099\111\110\116\114\111\108\108\101\114\077\111\100\101")S:set("\097\108\105\103\110\109\101\110\116","\109\105\100","\115\101\108\101\099\116\101\100","\099\111\110\116\114\111\108\108\101\114\077\111\100\101")else local T={"\100\101\115\101\108\101\099\116\101\100","\115\101\108\101\099\116\101\100";"\104\111\118\101\114\105\110\103"}for T,v in pairs(T)do local t,a=S:get("\097\108\105\103\110\109\101\110\116",v,"\099\111\110\116\114\111\108\108\101\114\077\111\100\101")if a then S:set("\097\108\105\103\110\109\101\110\116",a,v)end local u,R=S:get("\105\099\111\110\083\105\122\101",v,"\099\111\110\116\114\111\108\108\101\114\077\111\100\101")if R then S:set("\105\099\111\110\083\105\122\101",R,v)end end end if t then S:join(t,a)end end

function IconController:_updateSelectionGroup(clearAll)
	if IconController._navigationEnabled then
		guiService:RemoveSelectionGroup("TopbarPlusIcons")
	end
	if clearAll then
		guiService.CoreGuiNavigationEnabled = IconController._originalCoreGuiNavigationEnabled
		guiService.GuiNavigationEnabled = IconController._originalGuiNavigationEnabled
		IconController._navigationEnabled = nil
	elseif IconController.controllerModeEnabled then
		local icons = IconController.getIcons()
		local iconContainers = {}
		for i, otherIcon in pairs(icons) do
			local featureName = otherIcon.joinedFeatureName
			if not featureName or otherIcon._parentIcon[otherIcon.joinedFeatureName.."Open"] == true then
				table.insert(iconContainers, otherIcon.instances.iconButton)
			end
		end
		guiService:AddSelectionTuple("TopbarPlusIcons", table.unpack(iconContainers))
		if not IconController._navigationEnabled then
			IconController._originalCoreGuiNavigationEnabled = guiService.CoreGuiNavigationEnabled
			IconController._originalGuiNavigationEnabled = guiService.GuiNavigationEnabled
			guiService.CoreGuiNavigationEnabled = false
			guiService.GuiNavigationEnabled = true
			IconController._navigationEnabled = true
		end
	end
end

local function getScaleMultiplier()
	if guiService:IsTenFootInterface() then
		return 3
	else
		return 1.3
	end
end

function IconController._setControllerSelectedObject(object)
	local startId = (IconController._controllerSetCount and IconController._controllerSetCount + 1) or 0
	IconController._controllerSetCount = startId
	guiService.SelectedObject = object
	delay(0.1, function() -- blame the roblox guiservice its a piece of doo doo
		local finalId = IconController._controllerSetCount
		if startId == finalId then
			guiService.SelectedObject = object
		end
	end)
end

function IconController._enableControllerMode(bool)
	local indicator = TopbarPlusGui.Indicator
	local controllerOptionIcon = IconController.getIcon("_TopbarControllerOption")
	if IconController.controllerModeEnabled == bool then
		return
	end
	IconController.controllerModeEnabled = bool
	if bool then
		TopbarPlusGui.TopbarContainer.Position = UDim2.new(0,0,0,5)
		TopbarPlusGui.TopbarContainer.Visible = false
		local scaleMultiplier = getScaleMultiplier()
		indicator.Position = UDim2.new(0.5,0,0,5)
		indicator.Size = UDim2.new(0, 18*scaleMultiplier, 0, 18*scaleMultiplier)
		indicator.Image = "rbxassetid://5278151556"
		indicator.Visible = checkTopbarEnabled()
		indicator.Position = UDim2.new(0.5,0,0,5)
	else
		TopbarPlusGui.TopbarContainer.Position = UDim2.new(0,0,0,0)
		TopbarPlusGui.TopbarContainer.Visible = checkTopbarEnabled()
		indicator.Visible = false
		IconController._setControllerSelectedObject(nil)
	end
	for icon, _ in pairs(topbarIcons) do
		IconController._enableControllerModeForIcon(icon, bool)
	end
end

function IconController._enableControllerModeForIcon(icon, bool)
	local parentIcon = icon._parentIcon
	local featureName = icon.joinedFeatureName
	if parentIcon then
		icon:leave()
	end
	if bool then
		local scaleMultiplier = getScaleMultiplier()
		local currentSizeDeselected = icon:get("iconSize", "deselected")
		local currentSizeSelected = icon:get("iconSize", "selected")
		local currentSizeHovering = icon:getHovering("iconSize")
		icon:set("iconSize", UDim2.new(0, currentSizeDeselected.X.Offset*scaleMultiplier, 0, currentSizeDeselected.Y.Offset*scaleMultiplier), "deselected", "controllerMode")
		icon:set("iconSize", UDim2.new(0, currentSizeSelected.X.Offset*scaleMultiplier, 0, currentSizeSelected.Y.Offset*scaleMultiplier), "selected", "controllerMode")
		if currentSizeHovering then
			icon:set("iconSize", UDim2.new(0, currentSizeSelected.X.Offset*scaleMultiplier, 0, currentSizeSelected.Y.Offset*scaleMultiplier), "hovering", "controllerMode")
		end
		icon:set("alignment", "mid", "deselected", "controllerMode")
		icon:set("alignment", "mid", "selected", "controllerMode")
	else
		local states = {"deselected", "selected", "hovering"}
		for _, iconState in pairs(states) do
			local _, previousAlignment = icon:get("alignment", iconState, "controllerMode")
			if previousAlignment then
				icon:set("alignment", previousAlignment, iconState)
			end
			local currentSize, previousSize = icon:get("iconSize", iconState, "controllerMode")
			if previousSize then
				icon:set("iconSize", previousSize, iconState)
			end
		end
	end
	if parentIcon then
		icon:join(parentIcon, featureName)
	end
end


