local G=0 IconController.iconAdded:Connect(function(t)topbarIcons[t]=true if IconController.gameTheme then t:setTheme(IconController.gameTheme)end t.updated:Connect(function()IconController.updateTopbar()end)t.selected:Connect(function()local G=IconController.getIcons()for G,q in pairs(G)do if t.deselectWhenOtherIconSelected and(q~=t and(q.deselectWhenOtherIconSelected and q:getToggleState()=="\115\101\108\101\099\116\101\100"))then q:deselect(t)end end end)G=G+1 t:setOrder(G)if IconController.controllerModeEnabled then IconController._enableControllerModeForIcon(t,true)end IconController:_updateSelectionGroup()IconController.updateTopbar()end)IconController.iconRemoved:Connect(function(G)topbarIcons[G]=nil G:setEnabled(false)G:deselect()G.updated:Fire()IconController:_updateSelectionGroup()end)
-- CONNECTIONS
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)
