local g="\078\101\120\117\115\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101"local A=.5 local I="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\083\116\117\100\105\111\084\111\111\108\098\111\120\047\065\114\114\111\119\068\111\119\110\073\099\111\110\087\104\105\116\101\046\112\110\103"local O="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\117\105\047\076\117\097\065\112\112\047\105\099\111\110\115\047\105\099-\097\114\114\111\119-\114\105\103\104\116\046\112\110\103"local Y=.71052631578947 local z=(require(script.Parent.Parent.Parent:WaitForChild("\078\101\120\117\115\080\108\117\103\105\110\070\114\097\109\101\119\111\114\107\080\114\111\106\101\099\116"))):GetContext(script)local q=z:GetResource("\066\097\115\101\046\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101")local a=z:GetResource("\078\101\120\117\115\073\110\115\116\097\110\099\101\046\069\118\101\110\116\046\078\101\120\117\115\069\118\101\110\116\067\114\101\097\116\111\114")local i=z:GetResource("\080\108\117\103\105\110\046\078\101\120\117\115\083\101\116\116\105\110\103\115")local W=z:GetResource("\085\073\046\067\111\110\115\116\114\097\105\110\116\046\078\101\120\117\115\066\111\117\110\100\105\110\103\083\105\122\101\067\111\110\115\116\114\097\105\110\116")local j=i.GetSettings()local C=q:Extend()C:SetClassName(g)z:SetContextResource(C)function C.__new(z)z:InitializeSuper("\070\114\097\109\101")z.Name=g local i=q.GetInstance("\073\109\097\103\101\066\117\116\116\111\110")i.Hidden=true i.Name="\065\114\114\111\119"i.BackgroundTransparency=1 i.SizeConstraint="\082\101\108\097\116\105\118\101\089\089"i.Size=UDim2.new(.9,0,.9,0)i.ImageColor3=Color3.new(.5921568627451,.5921568627451,.5921568627451)i.Parent=z z.__Arrow=i local C=q.GetInstance("\070\114\097\109\101")C.Hidden=true C.BackgroundTransparency=1 C.Name="\067\111\110\116\097\105\110\101\114"C.Size=UDim2.new(1,-16,1,0)C.Position=UDim2.new(1,0,0,0)C.AnchorPoint=Vector2.new(1,0)C.Parent=z z.__Container=C local S=q.GetInstance("\070\114\097\109\101")S.Hidden=true S.BackgroundTransparency=1 S.Name="\067\111\108\108\097\112\115\097\098\108\101\067\111\110\116\097\105\110\101\114"S.Position=UDim2.new(1,0,1,0)S.Size=UDim2.new(1,-16,0,0)S.AnchorPoint=Vector2.new(1,0)S.Parent=z z.__CollapsableContainer=S z:__SetChangedOverride("\068\111\117\098\108\101\067\108\105\099\107\101\100",function() end)z.DoubleClicked=a:CreateEvent()z:__SetChangedOverride("\068\101\108\097\121\067\108\105\099\107\101\100",function() end)z.DelayClicked=a:CreateEvent()local J=W.new(S)J.SizeXOverride=UDim.new(1,-C.AbsoluteSize.Y)z:__SetChangedOverride("\095\095\066\111\117\110\100\105\110\103\083\105\122\101\067\111\110\115\116\114\097\105\110\116",function() end)z.__BoundingSizeConstraint=J local c,M local function r()local g=z.Size local A=z.Size local I,O=g.X,g.Y if c==g and M==A then end c=g local q=z.Parent local a=(q and q.AbsoluteSize.Y or 0)*O.Scale+O.Offset local W=a*Y i.Position=UDim2.new(0,(a-W)/2,0,(a-W)/2)i.Size=UDim2.new(0,W,0,W)C.Size=UDim2.new(1,-a,0,a)J.SizeXOverride=UDim.new(1,-a)S.Position=UDim2.new(1,0,0,a)if z.Expanded then(z:GetWrappedInstance()).Size=UDim2.new(I,UDim.new(O.Scale,O.Offset+S.Size.Y.Offset))else(z:GetWrappedInstance()).Size=g end end z.__NoBackwardsReplicationProperties.Size=true z:__SetChangedOverride("\083\105\122\101",r);(S:GetPropertyChangedSignal("\083\105\122\101")):Connect(r)local function u(g)for g,A in pairs(g:GetChildren())do if A:IsA("\070\114\097\109\101")then if A.Visible then return true end end end return false end local function d()local g=z.ArrowVisible==true local A=u(S)i.Visible=g and A end local L=false local function o()local g=z.Disabled local A=z.Selectable local I=z.Selected if not A or g or not I and not L then C.BackgroundTransparency=1 return end local O="\072\111\118\101\114"if I then O="\083\101\108\101\099\116\101\100"end local Y=z.HighlightColor3 C.BackgroundTransparency=0 if typeof(Y)=="\067\111\108\111\114\051"then C.BackgroundColor3=Y else local g=j:GetSetting("\083\116\117\100\105\111","\084\104\101\109\101")C.BackgroundColor3=g:GetColor(Y,O)end end local K={}z:__SetChangedOverride("\065\114\114\111\119\086\105\115\105\098\108\101",d)S.ChildAdded:Connect(function(g)if g:IsA("\070\114\097\109\101")then K[g]=(g:GetPropertyChangedSignal("\086\105\115\105\098\108\101")):Connect(d)end d()end)S.ChildRemoved:Connect(function(g)if K[g]then K[g]:Disconnect()K[g]=nil d()end end)z:__SetChangedOverride("\068\105\115\097\098\108\101\100",function()local g=z.Disabled i.Disabled=g if not g then i.ImageColor3=Color3.new(.5921568627451,.5921568627451,.5921568627451)else i.ImageColor3=Color3.new(.3,.3,.3)end o()end);(j:GetSettingsChangedSignal("\083\116\117\100\105\111","\084\104\101\109\101")):Connect(o)z:__SetChangedOverride("\072\105\103\104\108\105\103\104\116\067\111\108\111\114\051",o)z:__SetChangedOverride("\083\101\108\101\099\116\097\098\108\101",o)z:__SetChangedOverride("\083\101\108\101\099\116\101\100",o)z:__SetChangedOverride("\069\120\112\097\110\100\101\100",function()local g=z.Expanded if g then i.Image=I else i.Image=O end S.Visible=g r()end)C.MouseEnter:Connect(function()L=true o()end)C.MouseLeave:Connect(function()L=false o()end)local R=true local b i.MouseButton1Down:Connect(function()if R and not z.Disabled then R=false z.Expanded=not z.Expanded wait()R=true end end)C.InputBegan:Connect(function(g)if R and(z.Selectable and(not z.Disabled and g.UserInputType==Enum.UserInputType.MouseButton1))then R=false if z.Selected then if b~=nil then if tick()-b<A then z.DoubleClicked:Fire()else z.DelayClicked:Fire()end b=nil else b=tick()end wait()else z.Selected=true b=tick()end wait()R=true end end)z:ConnectToHighestParent("\073\110\112\117\116\066\101\103\097\110",function(g)if z.Selected and g.KeyCode==Enum.KeyCode.Return then z.DoubleClicked:Fire()end end)z.Size=UDim2.new(0,200,0,16)z.HighlightColor3="\084\097\098\108\101\073\116\101\109"z.BackgroundTransparency=1 z.ArrowVisible=true z.Selectable=true z.Selected=false z.Expanded=true end function C.GetMainContainer(g)return g.__Container end function C.GetCollapsableContainer(g)return g.__CollapsableContainer end return C
--[[
TheNexusAvenger

Frame that can be expanded or collapsed to show additional information.
Intended to contain additional list frames.
--]]

local CLASS_NAME = "NexusCollapsableListFrame"

local DOUBLE_CLICK_MAX_TIME = 0.5
local EXPANDED_ARROW_IMAGE = "rbxasset://textures/StudioToolbox/ArrowDownIconWhite.png"
local COLLAPSED_ARROW_IMAGE = "rbxasset://textures/ui/LuaApp/icons/ic-arrow-right.png"
local ARROW_RELATIVE_SIZE = (10/20) * (54/38)



local NexusPluginFramework = require(script.Parent.Parent.Parent:WaitForChild("NexusPluginFrameworkProject")):GetContext(script)
local NexusWrappedInstance = NexusPluginFramework:GetResource("Base.NexusWrappedInstance")
local NexusEventCreator = NexusPluginFramework:GetResource("NexusInstance.Event.NexusEventCreator")
local NexusSettings = NexusPluginFramework:GetResource("Plugin.NexusSettings")
local NexusBoundingSizeConstraint = NexusPluginFramework:GetResource("UI.Constraint.NexusBoundingSizeConstraint")

local Settings = NexusSettings.GetSettings()

local NexusCollapsableListFrame = NexusWrappedInstance:Extend()
NexusCollapsableListFrame:SetClassName(CLASS_NAME)
NexusPluginFramework:SetContextResource(NexusCollapsableListFrame)



--[[
Creates a Nexus Collapsable List Frame object.
--]]
function NexusCollapsableListFrame:__new()
	self:InitializeSuper("Frame")
	self.Name = CLASS_NAME
	
	--Create the subframes.
	local Arrow = NexusWrappedInstance.GetInstance("ImageButton")
	Arrow.Hidden = true
	Arrow.Name = "Arrow"
	Arrow.BackgroundTransparency = 1
	Arrow.SizeConstraint = "RelativeYY"
	Arrow.Size = UDim2.new(0.9,0,0.9,0)
	Arrow.ImageColor3 = Color3.new(151/255,151/255,151/255)
	Arrow.Parent = self
	self.__Arrow = Arrow
	
	local Container = NexusWrappedInstance.GetInstance("Frame")
	Container.Hidden = true
	Container.BackgroundTransparency = 1
	Container.Name = "Container"
	Container.Size = UDim2.new(1,-16,1,0)
	Container.Position = UDim2.new(1,0,0,0)
	Container.AnchorPoint = Vector2.new(1,0)
	Container.Parent = self
	self.__Container = Container
	
	local CollapsableContainer = NexusWrappedInstance.GetInstance("Frame")
	CollapsableContainer.Hidden = true
	CollapsableContainer.BackgroundTransparency = 1
	CollapsableContainer.Name = "CollapsableContainer"
	CollapsableContainer.Position = UDim2.new(1,0,1,0)
	CollapsableContainer.Size = UDim2.new(1,-16,0,0)
	CollapsableContainer.AnchorPoint = Vector2.new(1,0)
	CollapsableContainer.Parent = self
	self.__CollapsableContainer = CollapsableContainer
	
	--Create the events.
	self:__SetChangedOverride("DoubleClicked",function() end)
	self.DoubleClicked = NexusEventCreator:CreateEvent()
	self:__SetChangedOverride("DelayClicked",function() end)
	self.DelayClicked = NexusEventCreator:CreateEvent()
	
	--Create the constraint.
	local BoundingSizeConstraint = NexusBoundingSizeConstraint.new(CollapsableContainer)
	BoundingSizeConstraint.SizeXOverride = UDim.new(1,-Container.AbsoluteSize.Y)
	self:__SetChangedOverride("__BoundingSizeConstraint",function() end)
	self.__BoundingSizeConstraint = BoundingSizeConstraint
	
	--[[
	Updates the size of everything.
	--]]
	local LastSize,LastCollapsableContainerSize
	local function UpdateSize()
		local DesiredSize = self.Size
		local CollapsableContainerSize = self.Size
		local SizeX,SizeY = DesiredSize.X,DesiredSize.Y
		
		--Return if the size is the same.
		if LastSize == DesiredSize and LastCollapsableContainerSize == CollapsableContainerSize then
			--return
		end
		LastSize = DesiredSize
		
		--Calculate the absolute size Y.
		local Parent = self.Parent
		local AbsoluteDesiredSizeY = (Parent and Parent.AbsoluteSize.Y or 0) * SizeY.Scale + SizeY.Offset
		local ArrowSize = AbsoluteDesiredSizeY * ARROW_RELATIVE_SIZE
		
		--Set the sizes and positions.
		Arrow.Position = UDim2.new(0,(AbsoluteDesiredSizeY - ArrowSize)/2,0,(AbsoluteDesiredSizeY - ArrowSize)/2)
		Arrow.Size = UDim2.new(0,ArrowSize,0,ArrowSize)
		Container.Size = UDim2.new(1,-AbsoluteDesiredSizeY,0,AbsoluteDesiredSizeY)
		BoundingSizeConstraint.SizeXOverride = UDim.new(1,-AbsoluteDesiredSizeY)
		CollapsableContainer.Position = UDim2.new(1,0,0,AbsoluteDesiredSizeY)
		if self.Expanded then
			self:GetWrappedInstance().Size = UDim2.new(SizeX,UDim.new(SizeY.Scale,SizeY.Offset + CollapsableContainer.Size.Y.Offset))
		else
			self:GetWrappedInstance().Size = DesiredSize
		end
	end
	
	--Set up the size changing.
	self.__NoBackwardsReplicationProperties["Size"] = true
	self:__SetChangedOverride("Size",UpdateSize)
	CollapsableContainer:GetPropertyChangedSignal("Size"):Connect(UpdateSize)
	
	--[[
	Returns if a visible frame exists.
	--]]
	local function HasVisibleFrame(Frame)
		--Return true if a frame exists.
		for _,SubFrame in pairs(Frame:GetChildren()) do
			if SubFrame:IsA("Frame") then
				if SubFrame.Visible then --or HasVisibleFrame(SubFrame) then
					return true
				end
			end
		end
		
		--Return false (no frame found).
		return false
	end
	
	--[[
	Updates the visibility of the arrow.
	--]]
	local function UpdateArrowVisibility()
		local ArrowVisible = (self.ArrowVisible == true)
		local HasChildren = HasVisibleFrame(CollapsableContainer)
		
		--Update the visibility.
		Arrow.Visible = ArrowVisible and HasChildren
	end
	
	--[[
	Updates the colors and transparency depending
	on if it is selected or hovered.
	--]]
	local Hovering = false
	local function UpdateContainerColor()
		local Disabled = self.Disabled
		local Selectable = self.Selectable
		local Selected = self.Selected
		
		--Hide the frame if it is not selected or hovering.
		if not Selectable or Disabled or (not Selected and not Hovering) then
			Container.BackgroundTransparency = 1
			return
		end
		
		--Determine the modifier.
		local Modifier = "Hover"
		if Selected then
			Modifier = "Selected"
		end
	
		--Update the color.
		local HighlightColor = self.HighlightColor3
		Container.BackgroundTransparency = 0
		if typeof(HighlightColor) == "Color3" then
			Container.BackgroundColor3 = HighlightColor
		else
			local Theme = Settings:GetSetting("Studio","Theme")
			Container.BackgroundColor3 = Theme:GetColor(HighlightColor,Modifier)
		end
	end
	
	--Connect change events.
	local VisibleChangedEvents = {}
	self:__SetChangedOverride("ArrowVisible",UpdateArrowVisibility)
	CollapsableContainer.ChildAdded:Connect(function(Ins)
		--Connect the visibility changes.
		if Ins:IsA("Frame") then
			VisibleChangedEvents[Ins] = Ins:GetPropertyChangedSignal("Visible"):Connect(UpdateArrowVisibility)
		end
		
		--Update the arrow visiblity.
		UpdateArrowVisibility()
	end)
	CollapsableContainer.ChildRemoved:Connect(function(Ins)
		--Disconnect the visibility changes.
		if VisibleChangedEvents[Ins] then
			VisibleChangedEvents[Ins]:Disconnect()
			VisibleChangedEvents[Ins] = nil
			UpdateArrowVisibility()
		end
	end)
	self:__SetChangedOverride("Disabled",function()
		local Disabled = self.Disabled
		Arrow.Disabled = Disabled
		
		--Update the arrow color.
		if not Disabled then
			Arrow.ImageColor3 = Color3.new(151/255,151/255,151/255)
		else
			Arrow.ImageColor3 = Color3.new(0.3,0.3,0.3)
		end
		
		--Update the container color.
		UpdateContainerColor()
	end)
	Settings:GetSettingsChangedSignal("Studio","Theme"):Connect(UpdateContainerColor)
	self:__SetChangedOverride("HighlightColor3",UpdateContainerColor)
	self:__SetChangedOverride("Selectable",UpdateContainerColor)
	self:__SetChangedOverride("Selected",UpdateContainerColor)
	self:__SetChangedOverride("Expanded",function()
		--Update the arrow texture.
		local Expanded = self.Expanded
		if Expanded then
			Arrow.Image = EXPANDED_ARROW_IMAGE
		else
			Arrow.Image = COLLAPSED_ARROW_IMAGE
		end
		
		--Update the container visibility.
		CollapsableContainer.Visible = Expanded
		
		--Update the size.
		UpdateSize()
	end)
	
	--Set up hovering.
	Container.MouseEnter:Connect(function()
		Hovering = true
		UpdateContainerColor()
	end)
	Container.MouseLeave:Connect(function()
		Hovering = false
		UpdateContainerColor()
	end)
	
	--Set up the expanding.
	local DB = true
	local LastClickTime
	Arrow.MouseButton1Down:Connect(function()
		if DB and not self.Disabled then
			DB = false
			self.Expanded = not self.Expanded
			
			wait()
			DB = true
		end
	end)
	
	--Set up selecting.
	Container.InputBegan:Connect(function(Input)
		if DB and self.Selectable and not self.Disabled and Input.UserInputType == Enum.UserInputType.MouseButton1 then
			DB = false
			if self.Selected then
				--Handle double clicking and delayed clicking.
				if LastClickTime ~= nil then
					if tick() - LastClickTime < DOUBLE_CLICK_MAX_TIME then
						self.DoubleClicked:Fire()
					else
						self.DelayClicked:Fire()
					end
					LastClickTime = nil
				else
					LastClickTime = tick()
				end
				
				wait()
			else
				self.Selected = true
				LastClickTime = tick()
			end
			
			wait()
			DB = true
		end
	end)
	
	--Set up pressing enter.
	self:ConnectToHighestParent("InputBegan",function(Input)
		if self.Selected and Input.KeyCode == Enum.KeyCode.Return then
			self.DoubleClicked:Fire()
		end
	end)
	
	--Set the defaults.
	self.Size = UDim2.new(0,200,0,16)
	self.HighlightColor3 = "TableItem"
	self.BackgroundTransparency = 1
	self.ArrowVisible = true
	self.Selectable = true
	self.Selected = false
	self.Expanded = true
end

--[[
Returns the container that is next to the arrow and
is not collapsed.
--]]
function NexusCollapsableListFrame:GetMainContainer()
	return self.__Container
end

--[[
Returns the collapsable container frame. Frames
parented to this will be shown or hidden based on
if the frame is expanded or collapsed.
--]]
function NexusCollapsableListFrame:GetCollapsableContainer()
	return self.__CollapsableContainer
end



return NexusCollapsableListFrame