function Icon.join(n,Q,R,Y)if n._parentIcon then n:leave()end local x=R and R:lower()or"\100\114\111\112\100\111\119\110"local D="\098\101\102\111\114\101"..((R:sub(1,1)):upper()..R:sub(2))local s=Q.instances[R.."\070\114\097\109\101"]n.presentOnTopbar=false n.joinedFeatureName=R n._parentIcon=Q n.instances.iconContainer.Parent=s for R,Y in pairs(n.notices)do Q:notify(Y.clearNoticeEvent,R)end if R=="\100\114\111\112\100\111\119\110"then local R=Q:get("\100\114\111\112\100\111\119\110\083\113\117\097\114\101\067\111\114\110\101\114\115")n:set("\105\099\111\110\083\105\122\101",UDim2.new(1,0,0,(n:get("\105\099\111\110\083\105\122\101","\100\101\115\101\108\101\099\116\101\100")).Y.Offset),"\100\101\115\101\108\101\099\116\101\100",D)n:set("\105\099\111\110\083\105\122\101",UDim2.new(1,0,0,(n:get("\105\099\111\110\083\105\122\101","\115\101\108\101\099\116\101\100")).Y.Offset),"\115\101\108\101\099\116\101\100",D)if R then n:set("\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115",UDim.new(0,0),"\100\101\115\101\108\101\099\116\101\100",D)n:set("\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115",UDim.new(0,0),"\115\101\108\101\099\116\101\100",D)end n:set("\099\097\112\116\105\111\110\066\108\111\099\107\101\114\084\114\097\110\115\112\097\114\101\110\099\121",.4,nil,D)end local V=Q[x.."\073\099\111\110\115"]table.insert(V,n)if not Y then Q:_updateDropdown()end Q.deselectWhenOtherIconSelected=false IconController:_updateSelectionGroup()n:_decideToCallSignal("\100\114\111\112\100\111\119\110")n:_decideToCallSignal("\109\101\110\117")return n end function Icon.leave(Q)if Q._destroyed then return end local R={"\105\099\111\110\083\105\122\101","\099\097\112\116\105\111\110\066\108\111\099\107\101\114\084\114\097\110\115\112\097\114\101\110\099\121","\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115"}local Y=Q._parentIcon Q.instances.iconContainer.Parent=topbarContainer Q.presentOnTopbar=true Q.joinedFeatureName=nil local function n(n,x,D)for s,V in pairs(n)do if V==Q then for R,Y in pairs(R)do local n={"\100\101\115\101\108\101\099\116\101\100","\115\101\108\101\099\116\101\100"}for R,n in pairs(n)do local D,s=Q:get(Y,n,x)if s then Q:set(Y,s,n)end end end table.remove(n,s)D(Y)if#n==0 then Q._parentIcon.deselectWhenOtherIconSelected=true end break end end end n(Y.dropdownIcons,"\098\101\102\111\114\101\068\114\111\112\100\111\119\110",Y._updateDropdown)n(Y.menuIcons,"\098\101\102\111\114\101\077\101\110\117",Y._updateMenu)for Q,R in pairs(Q.notices)do local n=Y.notices[Q]if n then n.completeSignal:Fire()end end Q._parentIcon=nil IconController:_updateSelectionGroup()Q:_decideToCallSignal("\100\114\111\112\100\111\119\110")Q:_decideToCallSignal("\109\101\110\117")return Q end function Icon._decideToCallSignal(R,Q)local Y=R[Q.."\079\112\101\110"]local n="\095\112\114\101\118\105\111\117\115"..((string.sub(Q,1,1)):upper()..(Q:sub(2).."\079\112\101\110"))local x=R[n]local D=#R[Q.."\073\099\111\110\115"]if Y and(D>0 and x==false)then R[n]=true R[Q.."\079\112\101\110\101\100"]:Fire()elseif(not Y or D==0)and x==true then R[n]=false R[Q.."\067\108\111\115\101\100"]:Fire()end end function Icon._ignoreClipping(R,Q)local Y=R:get(Q.."\073\103\110\111\114\101\067\108\105\112\112\105\110\103")if R._parentIcon then local n=R["\095"..(Q.."\067\108\105\112\112\105\110\103\077\097\105\100")]local x=R.instances[Q.."\067\111\110\116\097\105\110\101\114"]n:clean()if Y then local Q=Instance.new("\070\114\097\109\101")Q.Name=x.Name.."\070\097\107\101\070\114\097\109\101"Q.ClipsDescendants=true Q.BackgroundTransparency=1 Q.Size=x.Size Q.Position=x.Position Q.Parent=activeItems for R,Y in pairs(x:GetChildren())do Y.Parent=Q end local function R()local R=x.AbsoluteSize Q.Size=UDim2.new(0,R.X,0,R.Y)end n:give((x:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(function()R()end))R()local function Y()local R=x.absolutePosition Q.Position=UDim2.new(0,R.X,0,R.Y+36)end n:give((x:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110")):Connect(function()Y()end))Y()n:give(function()for Q,R in pairs(Q:GetChildren())do R.Parent=x end Q.Name="\068\101\115\116\114\111\121\105\110\103\046\046\046"Q:Destroy()end)end end R._ignoreClippingChanged:Fire(Q,Y)end

function Icon:join(parentIcon, featureName, dontUpdate)
	if self._parentIcon then
		self:leave()
	end
	local newFeatureName = (featureName and featureName:lower()) or "dropdown"
	local beforeName = "before"..featureName:sub(1,1):upper()..featureName:sub(2)
	local parentFrame = parentIcon.instances[featureName.."Frame"]
	self.presentOnTopbar = false
	self.joinedFeatureName = featureName
	self._parentIcon = parentIcon
	self.instances.iconContainer.Parent = parentFrame
	for noticeId, noticeDetail in pairs(self.notices) do
		parentIcon:notify(noticeDetail.clearNoticeEvent, noticeId)
		--parentIcon:notify(noticeDetail.completeSignal, noticeId)
	end
	
	if featureName == "dropdown" then
		local squareCorners = parentIcon:get("dropdownSquareCorners")
		self:set("iconSize", UDim2.new(1, 0, 0, self:get("iconSize", "deselected").Y.Offset), "deselected", beforeName)
		self:set("iconSize", UDim2.new(1, 0, 0, self:get("iconSize", "selected").Y.Offset), "selected", beforeName)
		if squareCorners then
			self:set("iconCornerRadius", UDim.new(0, 0), "deselected", beforeName)
			self:set("iconCornerRadius", UDim.new(0, 0), "selected", beforeName)
		end
		self:set("captionBlockerTransparency", 0.4, nil, beforeName)
	end
	local array = parentIcon[newFeatureName.."Icons"]
	table.insert(array, self)
	if not dontUpdate then
		parentIcon:_updateDropdown()
	end
	parentIcon.deselectWhenOtherIconSelected = false
	--
	IconController:_updateSelectionGroup()
	self:_decideToCallSignal("dropdown")
	self:_decideToCallSignal("menu")
	--
	return self
end

function Icon:leave()
	if self._destroyed then return end
	local settingsToReset = {"iconSize", "captionBlockerTransparency", "iconCornerRadius"}
	local parentIcon = self._parentIcon
	self.instances.iconContainer.Parent = topbarContainer
	self.presentOnTopbar = true
	self.joinedFeatureName = nil
	local function scanFeature(t, prevReference, updateMethod)
		for i, otherIcon in pairs(t) do
			if otherIcon == self then
				for _, settingName in pairs(settingsToReset) do
					local states = {"deselected", "selected"}
					for _, toggleState in pairs(states) do
						local currentSetting, previousSetting = self:get(settingName, toggleState, prevReference)
						if previousSetting then
							self:set(settingName, previousSetting, toggleState)
						end
					end
				end
				table.remove(t, i)
				updateMethod(parentIcon)
				if #t == 0 then
					self._parentIcon.deselectWhenOtherIconSelected = true
				end
				break
			end
		end
	end
	scanFeature(parentIcon.dropdownIcons, "beforeDropdown", parentIcon._updateDropdown)
	scanFeature(parentIcon.menuIcons, "beforeMenu", parentIcon._updateMenu)
	--
	for noticeId, noticeDetail in pairs(self.notices) do
		local parentIconNoticeDetail = parentIcon.notices[noticeId]
		if parentIconNoticeDetail then
			parentIconNoticeDetail.completeSignal:Fire()
		end
	end
	--
	self._parentIcon = nil
	--
	IconController:_updateSelectionGroup()
	self:_decideToCallSignal("dropdown")
	self:_decideToCallSignal("menu")
	--
	return self
end

function Icon:_decideToCallSignal(featureName)
	local isOpen = self[featureName.."Open"]
	local previousIsOpenName = "_previous"..string.sub(featureName, 1, 1):upper()..featureName:sub(2).."Open"
	local previousIsOpen = self[previousIsOpenName]
	local totalIcons = #self[featureName.."Icons"]
	if isOpen and totalIcons > 0 and previousIsOpen == false then
		self[previousIsOpenName] = true
		self[featureName.."Opened"]:Fire()
	elseif (not isOpen or totalIcons == 0) and previousIsOpen == true then
		self[previousIsOpenName] = false
		self[featureName.."Closed"]:Fire()
	end
end

function Icon:_ignoreClipping(featureName)
	local ignoreClipping = self:get(featureName.."IgnoreClipping")
	if self._parentIcon then
		local maid = self["_"..featureName.."ClippingMaid"]
		local frame = self.instances[featureName.."Container"]
		maid:clean()
		if ignoreClipping then
			local fakeFrame = Instance.new("Frame")
			fakeFrame.Name = frame.Name.."FakeFrame"
			fakeFrame.ClipsDescendants = true
			fakeFrame.BackgroundTransparency = 1
			fakeFrame.Size = frame.Size
			fakeFrame.Position = frame.Position
			fakeFrame.Parent = activeItems
			--
			for a,b in pairs(frame:GetChildren()) do
				b.Parent = fakeFrame
			end
			--
			local function updateSize()
				local absoluteSize = frame.AbsoluteSize
				fakeFrame.Size = UDim2.new(0, absoluteSize.X, 0, absoluteSize.Y)
			end
			maid:give(frame:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
				updateSize()
			end))
			updateSize()
			local function updatePos()
				local absolutePosition = frame.absolutePosition
				fakeFrame.Position = UDim2.new(0, absolutePosition.X, 0, absolutePosition.Y+36)
			end
			maid:give(frame:GetPropertyChangedSignal("AbsolutePosition"):Connect(function()
				updatePos()
			end))
			updatePos()
			maid:give(function()
				for a,b in pairs(fakeFrame:GetChildren()) do
					b.Parent = frame
				end
				fakeFrame.Name = "Destroying..."
				fakeFrame:Destroy()
			end)
		end
	end
	self._ignoreClippingChanged:Fire(featureName, ignoreClipping)
end
