local U=0 IconController.iconAdded:Connect(function(F)topbarIcons[F]=true if IconController.gameTheme then F:setTheme(IconController.gameTheme)end F.updated:Connect(function()IconController.updateTopbar()end)F.selected:Connect(function()local U=IconController.getIcons()for U,i in pairs(U)do if F.deselectWhenOtherIconSelected and(i~=F and(i.deselectWhenOtherIconSelected and i:getToggleState()=="\115\101\108\101\099\116\101\100"))then i:deselect(F)end end end)U=U+1 F:setOrder(U)if IconController.controllerModeEnabled then IconController._enableControllerModeForIcon(F,true)end IconController:_updateSelectionGroup()IconController.updateTopbar()end)IconController.iconRemoved:Connect(function(U)topbarIcons[U]=nil U:setEnabled(false)U:deselect()U.updated:Fire()IconController:_updateSelectionGroup()end)

local iconCreationCount = 0
IconController.iconAdded:Connect(function(icon)
	topbarIcons[icon] = true
	if IconController.gameTheme then
		icon:setTheme(IconController.gameTheme)
	end
	icon.updated:Connect(function()
		IconController.updateTopbar()
	end)
	-- When this icon is selected, deselect other icons if necessary
	icon.selected:Connect(function()
		local allIcons = IconController.getIcons()
		for _, otherIcon in pairs(allIcons) do
			if icon.deselectWhenOtherIconSelected and otherIcon ~= icon and otherIcon.deselectWhenOtherIconSelected and otherIcon:getToggleState() == "selected" then
				otherIcon:deselect(icon)
			end
		end
	end)
	-- Order by creation if no order specified
	iconCreationCount = iconCreationCount + 1
	icon:setOrder(iconCreationCount)
	-- Apply controller view if enabled
	if IconController.controllerModeEnabled then
		IconController._enableControllerModeForIcon(icon, true)
	end
	IconController:_updateSelectionGroup()
	IconController.updateTopbar()
end)

IconController.iconRemoved:Connect(function(icon)
	topbarIcons[icon] = nil
	icon:setEnabled(false)
	icon:deselect()
	icon.updated:Fire()
	IconController:_updateSelectionGroup()
end)


