function Icon.join(G,i,F,r)if G._parentIcon then G:leave()end local h=F and F:lower()or"\100\114\111\112\100\111\119\110"local A="\098\101\102\111\114\101"..((F:sub(1,1)):upper()..F:sub(2))local X=i.instances[F.."\070\114\097\109\101"]G.presentOnTopbar=false G.joinedFeatureName=F G._parentIcon=i G.instances.iconContainer.Parent=X for F,r in pairs(G.notices)do i:notify(r.clearNoticeEvent,F)end if F=="\100\114\111\112\100\111\119\110"then local F=i:get("\100\114\111\112\100\111\119\110\083\113\117\097\114\101\067\111\114\110\101\114\115")G:set("\105\099\111\110\083\105\122\101",UDim2.new(1,0,0,(G: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",A)G:set("\105\099\111\110\083\105\122\101",UDim2.new(1,0,0,(G: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",A)if F then G: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",A)G: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",A)end G: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,A)end local C=i[h.."\073\099\111\110\115"]table.insert(C,G)if not r then i:_updateDropdown()end i.deselectWhenOtherIconSelected=false IconController:_updateSelectionGroup()G:_decideToCallSignal("\100\114\111\112\100\111\119\110")G:_decideToCallSignal("\109\101\110\117")return G end function Icon.leave(i)if i._destroyed or i.instances.iconContainer.Parent==nil then return end local F={"\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 r=i._parentIcon i.instances.iconContainer.Parent=topbarContainer i.presentOnTopbar=true i.joinedFeatureName=nil local function G(G,h,A)for X,C in pairs(G)do if C==i then for F,r in pairs(F)do local G={"\100\101\115\101\108\101\099\116\101\100","\115\101\108\101\099\116\101\100"}for F,G in pairs(G)do local A,X=i:get(r,G,h)if X then i:set(r,X,G)end end end table.remove(G,X)A(r)if#G==0 then i._parentIcon.deselectWhenOtherIconSelected=true end break end end end G(r.dropdownIcons,"\098\101\102\111\114\101\068\114\111\112\100\111\119\110",r._updateDropdown)G(r.menuIcons,"\098\101\102\111\114\101\077\101\110\117",r._updateMenu)for i,F in pairs(i.notices)do local G=r.notices[i]if G then G.completeSignal:Fire()end end i._parentIcon=nil IconController:_updateSelectionGroup()i:_decideToCallSignal("\100\114\111\112\100\111\119\110")i:_decideToCallSignal("\109\101\110\117")return i end function Icon._decideToCallSignal(F,i)local r=F[i.."\079\112\101\110"]local G="\095\112\114\101\118\105\111\117\115"..((string.sub(i,1,1)):upper()..(i:sub(2).."\079\112\101\110"))local h=F[G]local A=#F[i.."\073\099\111\110\115"]if r and(A>0 and h==false)then F[G]=true F[i.."\079\112\101\110\101\100"]:Fire()elseif(not r or A==0)and h==true then F[G]=false F[i.."\067\108\111\115\101\100"]:Fire()end end function Icon._ignoreClipping(F,i)local r=F:get(i.."\073\103\110\111\114\101\067\108\105\112\112\105\110\103")if F._parentIcon then local G=F["\095"..(i.."\067\108\105\112\112\105\110\103\077\097\105\100")]local h=F.instances[i.."\067\111\110\116\097\105\110\101\114"]G:clean()if r then local i=Instance.new("\070\114\097\109\101")i.Name=h.Name.."\070\097\107\101\070\114\097\109\101"i.ClipsDescendants=true i.BackgroundTransparency=1 i.Size=h.Size i.Position=h.Position i.Parent=activeItems for F,r in pairs(h:GetChildren())do r.Parent=i end local function F()local F=h.AbsoluteSize i.Size=UDim2.new(0,F.X,0,F.Y)end G:give((h:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(function()F()end))F()local function r()local F=h.absolutePosition i.Position=UDim2.new(0,F.X,0,F.Y+36)end G:give((h:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110")):Connect(function()r()end))r()G:give(function()for i,F in pairs(i:GetChildren())do F.Parent=h end i.Name="\068\101\115\116\114\111\121\105\110\103\046\046\046"i:Destroy()end)end end F._ignoreClippingChanged:Fire(i,r)end
-- Join or leave a special feature such as a Dropdown or Menu
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 or self.instances.iconContainer.Parent == nil 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
