Last active
January 21, 2023 14:20
-
-
Save Gabys2005/ac873927ffff8eb4c0446f26ac47c812 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local adorner = {} | |
function adorner:Adorn(frame: Frame, surfaces: {SurfaceGui}, topmarker: Vector3 | number, totalFrameSize: UDim2) | |
local topMarkerY = if typeof(topmarker) == "number" then topmarker else topmarker.Y | |
local frames: {[Instance]: {Instance}} = {} | |
local sizeFrames = {} | |
local clipFrames = {} | |
local function addGuiElementToReplicate(parent: Instance, element: Instance, initial: boolean) | |
frames[element] = {} | |
local loopThrough = if initial then sizeFrames else frames[parent] | |
for _, frame in loopThrough do | |
local copy = element:Clone() | |
copy:ClearAllChildren() | |
copy.Parent = frame | |
table.insert(frames[element], copy) | |
end | |
for _, child in element:GetChildren() do | |
addGuiElementToReplicate(element, child, false) | |
end | |
element.Changed:Connect(function(property: string) | |
if frames[element] then | |
local newValue = element[property] | |
pcall(function() | |
for _, el in frames[element] do | |
el[property] = newValue | |
end | |
end) | |
end | |
end) | |
element.ChildAdded:Connect(function(child) | |
task.wait() | |
addGuiElementToReplicate(element, child) | |
end) | |
element.Destroying:Connect(function() | |
for _, frame in frames[element] do | |
frame:Destroy() | |
end | |
frames[element] = nil | |
end) | |
end | |
for _, surfaceGui in surfaces do | |
local clip = Instance.new("Frame") | |
clip.Size = UDim2.new(1,0,1,0) | |
clip.BackgroundTransparency = 1 | |
clip.Name = "AdornerClipFrame" | |
clip.ClipsDescendants = true | |
clip.Parent = surfaceGui | |
local sizeFrame = Instance.new("Frame") | |
sizeFrame.BackgroundTransparency = 1 | |
sizeFrame.Size = totalFrameSize | |
sizeFrame.Name = "AdornerSizeFrame" | |
sizeFrame.Parent = clip | |
local XOffset = surfaceGui:GetAttribute("XOffset") | |
local yOffsetAttribute = surfaceGui:GetAttribute("YOffset") | |
local YOffset = if yOffsetAttribute then yOffsetAttribute else (topMarkerY - (surfaceGui.Parent.Position.Y + surfaceGui.Parent.Size.Y/2)) * surfaceGui.PixelsPerStud | |
sizeFrame.Position = UDim2.fromOffset(-XOffset, -YOffset) | |
table.insert(sizeFrames, sizeFrame) | |
table.insert(clipFrames, clip) | |
end | |
addGuiElementToReplicate(nil, frame, true) | |
local adornedIns = {} | |
function adornedIns:Destroy() | |
for _, frame in sizeFrames do | |
frame:Destroy() | |
end | |
for _, frame in clipFrames do | |
frame:Destroy() | |
end | |
sizeFrames = nil | |
frames = nil | |
end | |
return adornedIns | |
end | |
return adorner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment