local p=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local N=p("\084\097\098\108\101")local q={}q.__index=q q.ClassName="\080\105\108\108\066\097\099\107\105\110\103\066\117\105\108\100\101\114"q.CIRCLE_IMAGE_ID="\114\098\120\097\115\115\101\116\105\100\058\047\047\054\051\051\050\052\052\056\056\056"q.CIRCLE_SIZE=Vector2.new(256,256)q.SHADOW_IMAGE_ID="\114\098\120\097\115\115\101\116\105\100\058\047\047\055\048\055\056\053\050\057\055\051"q.SHADOW_SIZE=Vector2.new(128,128)q.PILL_SHADOW_IMAGE_ID="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\048\052\048\048\052\050\057\048"q.PILL_SHADOW_SIZE=Vector2.new(256,128)q.SHADOW_OFFSET_Y=UDim.new(.05,0)q.SHADOW_TRANSPARENCY=.85 function q.new(p)local N=setmetatable({},q)N._options=p or{}return N end function q.Create(q,p,N)N=q:_configureOptions(p,N)local k=p.Size.Y local a=Instance.new("\070\114\097\109\101")a.AnchorPoint=Vector2.new(.5,.5)a.BackgroundColor3=N.BackgroundColor3 a.BorderSizePixel=0 a.Name="\080\105\108\108\066\097\099\107\105\110\103"a.Position=UDim2.new(.5,0,.5,0)a.Size=UDim2.new(1-k.Scale,-k.Offset,1,0)a.ZIndex=N.ZIndex local Y=Instance.new("\085\073\083\105\122\101\067\111\110\115\116\114\097\105\110\116")Y.MaxSize=Vector2.new(math.huge,math.huge)Y.MinSize=Vector2.new(0,0)Y.Parent=a local E=q:_createLeft(N)local J=q:_createRight(N)J.Parent=a E.Parent=a p.BackgroundTransparency=1 a.Parent=p return a end function q.CreateShadow(q,p,N)N=q:_configureOptions(p,N)local k=p.Size.Y local a=q:_createPillShadow(N)a.SizeConstraint=Enum.SizeConstraint.RelativeXY a.AnchorPoint=Vector2.new(.5,.5)a.Name="\080\105\108\108\083\104\097\100\111\119"a.ImageRectSize=q.PILL_SHADOW_SIZE*Vector2.new(.5,1)a.ImageRectOffset=q.PILL_SHADOW_SIZE*Vector2.new(.25,0)a.Position=UDim2.new(UDim.new(.5,0),UDim.new(.5,0)+q.SHADOW_OFFSET_Y)a.Size=UDim2.new(1-k.Scale,-k.Offset,2,0)a.ZIndex=N.ShadowZIndex local Y=Instance.new("\085\073\083\105\122\101\067\111\110\115\116\114\097\105\110\116")Y.MaxSize=Vector2.new(math.huge,math.huge)Y.MinSize=Vector2.new(0,0)Y.Parent=a local E=q:_createLeftShadow(N)local J=q:_createRightShadow(N)J.Parent=a E.Parent=a a.Parent=p return a end function q.CreateCircle(q,p,N)N=q:_configureOptions(p,N)local k=q:_createCircle(N)k.ImageTransparency=p.BackgroundTransparency p.BackgroundTransparency=1 k.Parent=p return k end function q.CreateCircleShadow(q,p,N)N=q:_configureOptions(p,N)local k=Instance.new("\073\109\097\103\101\076\097\098\101\108")k.AnchorPoint=Vector2.new(.5,.5)k.BackgroundTransparency=1 k.Image=q.SHADOW_IMAGE_ID k.ImageTransparency=q.SHADOW_TRANSPARENCY k.Name="\067\105\114\099\108\101\083\104\097\100\111\119"k.Position=UDim2.new(UDim.new(.5,0),UDim.new(.5,0)+q.SHADOW_OFFSET_Y)k.Size=UDim2.new(2,0,2,0)k.SizeConstraint=Enum.SizeConstraint.RelativeYY k.ZIndex=N.ShadowZIndex k.Parent=p return k end function q.CreateLeft(q,p,N)N=q:_configureOptions(p,N)local k=q:_createLeft(N)k.Parent=p return k end function q.CreateRight(q,p,N)N=q:_configureOptions(p,N)local k=q:_createRight(N)k.Parent=p return k end function q._createLeft(N,p)local q=N:_createCircle(p)q.AnchorPoint=Vector2.new(1,.5)q.ImageRectSize=N.CIRCLE_SIZE*Vector2.new(.5,1)q.Name="\076\101\102\116\072\097\108\102\067\105\114\099\108\101"q.Position=UDim2.new(0,0,.5,0)q.Size=UDim2.new(.5,0,1,0)return q end function q._createRight(N,p)p=N:_configureOptions(p)local q=N:_createCircle(p)q.AnchorPoint=Vector2.new(0,.5)q.ImageRectOffset=N.CIRCLE_SIZE*Vector2.new(.5,0)q.ImageRectSize=N.CIRCLE_SIZE*Vector2.new(.5,1)q.Name="\082\105\103\104\116\072\097\108\102\067\105\114\099\108\101"q.Position=UDim2.new(1,0,.5,0)q.Size=UDim2.new(.5,0,1,0)return q end function q._createLeftShadow(N,p)local q=N:_createPillShadow(p)q.AnchorPoint=Vector2.new(1,.5)q.ImageRectSize=N.PILL_SHADOW_SIZE*Vector2.new(.25,1)q.Name="\076\101\102\116\083\104\097\100\111\119"q.Position=UDim2.new(0,0,.5,0)q.Size=UDim2.new(.5,0,1,0)return q end function q._createRightShadow(N,p)local q=N:_createPillShadow(p)q.AnchorPoint=Vector2.new(0,.5)q.ImageRectOffset=N.PILL_SHADOW_SIZE*Vector2.new(.75,0)q.ImageRectSize=N.PILL_SHADOW_SIZE*Vector2.new(.25,1)q.Name="\082\105\103\104\116\083\104\097\100\111\119"q.Position=UDim2.new(1,0,.5,0)q.Size=UDim2.new(.5,0,1,0)return q end function q._createCircle(N,p)local q=Instance.new("\073\109\097\103\101\076\097\098\101\108")q.BackgroundTransparency=1 q.Image=N.CIRCLE_IMAGE_ID q.Name="\067\105\114\099\108\101"q.Size=UDim2.new(1,0,1,0)q.SizeConstraint=Enum.SizeConstraint.RelativeYY q.ImageColor3=p.BackgroundColor3 q.ZIndex=p.ZIndex return q end function q._createPillShadow(N,p)local q=Instance.new("\073\109\097\103\101\076\097\098\101\108")q.BackgroundTransparency=1 q.Image=N.PILL_SHADOW_IMAGE_ID q.ImageTransparency=N.SHADOW_TRANSPARENCY q.Name="\080\105\108\108\083\104\097\100\111\119"q.Size=UDim2.new(1,0,1,0)q.SizeConstraint=Enum.SizeConstraint.RelativeYY q.ZIndex=p.ShadowZIndex return q end function q._configureOptions(k,p,q)assert(p)q=N.Copy(q or k._options)q.ZIndex=q.ZIndex or p.ZIndex q.ShadowZIndex=q.ShadowZIndex or q.ZIndex-1 q.BackgroundColor3=q.BackgroundColor3 or p.BackgroundColor3 return q end return q
--- Builds a pill backing for Guis
-- @classmod PillBackingBuilder

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local Table = require("Table")

local PillBackingBuilder = {}
PillBackingBuilder.__index = PillBackingBuilder
PillBackingBuilder.ClassName = "PillBackingBuilder"
PillBackingBuilder.CIRCLE_IMAGE_ID = "rbxassetid://633244888" -- White circle
PillBackingBuilder.CIRCLE_SIZE = Vector2.new(256, 256)
PillBackingBuilder.SHADOW_IMAGE_ID = "rbxassetid://707852973"
PillBackingBuilder.SHADOW_SIZE = Vector2.new(128, 128)
PillBackingBuilder.PILL_SHADOW_IMAGE_ID = "rbxassetid://1304004290"
PillBackingBuilder.PILL_SHADOW_SIZE = Vector2.new(256, 128)
PillBackingBuilder.SHADOW_OFFSET_Y = UDim.new(0.05, 0)
PillBackingBuilder.SHADOW_TRANSPARENCY = 0.85

function PillBackingBuilder.new(options)
	local self = setmetatable({}, PillBackingBuilder)

	self._options = options or {}

	return self
end

function PillBackingBuilder:Create(gui, options)
	options = self:_configureOptions(gui, options)
	local diameter = gui.Size.Y

	local pillBacking = Instance.new("Frame")
	pillBacking.AnchorPoint = Vector2.new(0.5, 0.5)
	pillBacking.BackgroundColor3 = options.BackgroundColor3
	pillBacking.BorderSizePixel = 0
	pillBacking.Name = "PillBacking"
	pillBacking.Position = UDim2.new(0.5, 0, 0.5, 0)
	pillBacking.Size = UDim2.new(1 - diameter.Scale, -diameter.Offset, 1, 0)
	pillBacking.ZIndex = options.ZIndex

	-- Prevent negative sizes (for circles)
	local sizeConstraint = Instance.new("UISizeConstraint")
	sizeConstraint.MaxSize = Vector2.new(math.huge, math.huge)
	sizeConstraint.MinSize = Vector2.new(0, 0)
	sizeConstraint.Parent = pillBacking

	local left = self:_createLeft(options)
	local right = self:_createRight(options)
	right.Parent = pillBacking
	left.Parent = pillBacking

	gui.BackgroundTransparency = 1
	pillBacking.Parent = gui

	return pillBacking
end

function PillBackingBuilder:CreateShadow(gui, options)
	options = self:_configureOptions(gui, options)
	local diameter = gui.Size.Y

	local shadow = self:_createPillShadow(options)
	shadow.SizeConstraint = Enum.SizeConstraint.RelativeXY
	shadow.AnchorPoint = Vector2.new(0.5, 0.5)
	shadow.Name = "PillShadow"
	shadow.ImageRectSize = self.PILL_SHADOW_SIZE * Vector2.new(0.5, 1)
	shadow.ImageRectOffset = self.PILL_SHADOW_SIZE * Vector2.new(0.25, 0)
	shadow.Position = UDim2.new(UDim.new(0.5, 0), UDim.new(0.5, 0) + self.SHADOW_OFFSET_Y)
	shadow.Size = UDim2.new(1 - diameter.Scale, -diameter.Offset, 2, 0)
	shadow.ZIndex = options.ShadowZIndex

	-- Prevent negative sizes (for circles)
	local sizeConstraint = Instance.new("UISizeConstraint")
	sizeConstraint.MaxSize = Vector2.new(math.huge, math.huge)
	sizeConstraint.MinSize = Vector2.new(0, 0)
	sizeConstraint.Parent = shadow

	local left = self:_createLeftShadow(options)
	local right = self:_createRightShadow(options)
	right.Parent = shadow
	left.Parent = shadow

	shadow.Parent = gui

	return shadow
end

function PillBackingBuilder:CreateCircle(gui, options)
	options = self:_configureOptions(gui, options)
	local circle = self:_createCircle(options)

	circle.ImageTransparency = gui.BackgroundTransparency
	gui.BackgroundTransparency = 1
	circle.Parent = gui

	return circle
end

function PillBackingBuilder:CreateCircleShadow(gui, options)
	options = self:_configureOptions(gui, options)
	local shadow = Instance.new("ImageLabel")
	shadow.AnchorPoint = Vector2.new(0.5, 0.5)
	shadow.BackgroundTransparency = 1
	shadow.Image = self.SHADOW_IMAGE_ID
	shadow.ImageTransparency = self.SHADOW_TRANSPARENCY
	shadow.Name = "CircleShadow"
	shadow.Position = UDim2.new(UDim.new(0.5, 0), UDim.new(0.5, 0) + self.SHADOW_OFFSET_Y)
	shadow.Size = UDim2.new(2, 0, 2, 0)
	shadow.SizeConstraint = Enum.SizeConstraint.RelativeYY

	shadow.ZIndex = options.ShadowZIndex

	shadow.Parent = gui

	return shadow
end

function PillBackingBuilder:CreateLeft(gui, options)
	options = self:_configureOptions(gui, options)
	local left = self:_createLeft(options)
	left.Parent = gui
	return left
end

function PillBackingBuilder:CreateRight(gui, options)
	options = self:_configureOptions(gui, options)
	local right = self:_createRight(options)
	right.Parent = gui
	return right
end


function PillBackingBuilder:_createLeft(options)
	local left = self:_createCircle(options)
	left.AnchorPoint = Vector2.new(1, 0.5)
	left.ImageRectSize = self.CIRCLE_SIZE * Vector2.new(0.5, 1)
	left.Name = "LeftHalfCircle"
	left.Position = UDim2.new(0, 0, 0.5, 0)
	left.Size = UDim2.new(0.5, 0, 1, 0)

	return left
end

function PillBackingBuilder:_createRight(options)
	options = self:_configureOptions(options)

	local right = self:_createCircle(options)
	right.AnchorPoint = Vector2.new(0, 0.5)
	right.ImageRectOffset = self.CIRCLE_SIZE * Vector2.new(0.5, 0)
	right.ImageRectSize = self.CIRCLE_SIZE * Vector2.new(0.5, 1)
	right.Name = "RightHalfCircle"
	right.Position = UDim2.new(1, 0, 0.5, 0)
	right.Size = UDim2.new(0.5, 0, 1, 0)

	return right
end

function PillBackingBuilder:_createLeftShadow(options)
	local left = self:_createPillShadow(options)
	left.AnchorPoint = Vector2.new(1, 0.5)
	left.ImageRectSize = self.PILL_SHADOW_SIZE * Vector2.new(0.25, 1)
	left.Name = "LeftShadow"
	left.Position = UDim2.new(0, 0, 0.5, 0)
	left.Size = UDim2.new(0.5, 0, 1, 0)

	return left
end

function PillBackingBuilder:_createRightShadow(options)
	local right = self:_createPillShadow(options)
	right.AnchorPoint = Vector2.new(0, 0.5)
	right.ImageRectOffset = self.PILL_SHADOW_SIZE * Vector2.new(0.75, 0)
	right.ImageRectSize = self.PILL_SHADOW_SIZE * Vector2.new(0.25, 1)
	right.Name = "RightShadow"
	right.Position = UDim2.new(1, 0, 0.5, 0)
	right.Size = UDim2.new(0.5, 0, 1, 0)

	return right
end

function PillBackingBuilder:_createCircle(options)
	local circle = Instance.new("ImageLabel")
	circle.BackgroundTransparency = 1
	circle.Image = self.CIRCLE_IMAGE_ID
	circle.Name = "Circle"
	circle.Size = UDim2.new(1, 0, 1, 0)
	circle.SizeConstraint = Enum.SizeConstraint.RelativeYY

	-- set options
	circle.ImageColor3 = options.BackgroundColor3
	circle.ZIndex = options.ZIndex

	return circle
end

function PillBackingBuilder:_createPillShadow(options)
	local shadow = Instance.new("ImageLabel")
	shadow.BackgroundTransparency = 1
	shadow.Image = self.PILL_SHADOW_IMAGE_ID
	shadow.ImageTransparency = self.SHADOW_TRANSPARENCY
	shadow.Name = "PillShadow"
	shadow.Size = UDim2.new(1, 0, 1, 0)
	shadow.SizeConstraint = Enum.SizeConstraint.RelativeYY

	shadow.ZIndex = options.ShadowZIndex

	return shadow
end

function PillBackingBuilder:_configureOptions(gui, options)
	assert(gui)

	options = Table.Copy(options or self._options)
	options.ZIndex = options.ZIndex or gui.ZIndex
	options.ShadowZIndex = options.ShadowZIndex or options.ZIndex - 1
	options.BackgroundColor3 = options.BackgroundColor3 or gui.BackgroundColor3

	return options
end

return PillBackingBuilder