Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Library = {}
- -- Services
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local CoreGui = game:GetService("CoreGui")
- -- Main ScreenGui
- local screenGui = Instance.new("ScreenGui")
- screenGui.Name = "AdvancedUILibrary"
- screenGui.ResetOnSpawn = false
- screenGui.Parent = CoreGui
- -- Main draggable frame
- local mainFrame = Instance.new("Frame")
- mainFrame.Name = "MainFrame"
- mainFrame.Size = UDim2.new(0, 300, 0, 400)
- mainFrame.Position = UDim2.new(0, 50, 0, 50)
- mainFrame.BackgroundColor3 = Color3.fromRGB(35, 35, 35)
- mainFrame.BorderSizePixel = 0
- mainFrame.Parent = screenGui
- mainFrame.Active = true
- mainFrame.Draggable = true
- -- UIListLayout container for controls inside mainFrame
- local contentHolder = Instance.new("Frame")
- contentHolder.Name = "ContentHolder"
- contentHolder.BackgroundTransparency = 1
- contentHolder.Size = UDim2.new(1, -20, 1, -40)
- contentHolder.Position = UDim2.new(0, 10, 0, 35)
- contentHolder.Parent = mainFrame
- contentHolder.ClipsDescendants = true
- local layout = Instance.new("UIListLayout")
- layout.SortOrder = Enum.SortOrder.LayoutOrder
- layout.Padding = UDim.new(0, 8)
- layout.Parent = contentHolder
- -- Title Label
- local titleLabel = Instance.new("TextLabel")
- titleLabel.Parent = mainFrame
- titleLabel.Text = "Advanced UI Library"
- titleLabel.Size = UDim2.new(1, 0, 0, 30)
- titleLabel.Position = UDim2.new(0, 0, 0, 0)
- titleLabel.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
- titleLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
- titleLabel.Font = Enum.Font.SourceSansBold
- titleLabel.TextSize = 22
- titleLabel.BorderSizePixel = 0
- -- Helper to create labels for controls
- local function createLabel(text)
- local label = Instance.new("TextLabel")
- label.Size = UDim2.new(1, 0, 0, 20)
- label.BackgroundTransparency = 1
- label.TextColor3 = Color3.fromRGB(255, 255, 255)
- label.Font = Enum.Font.SourceSansSemibold
- label.TextSize = 18
- label.Text = text
- label.TextXAlignment = Enum.TextXAlignment.Left
- return label
- end
- -- Toggle control
- function Library:CreateToggle(name, callback)
- local toggled = false
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(1, 0, 0, 40)
- frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
- frame.Parent = contentHolder
- local label = createLabel(name)
- label.Size = UDim2.new(0.7, 0, 1, 0)
- label.Parent = frame
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(0.28, 0, 0.6, 0)
- button.Position = UDim2.new(0.72, 0, 0.2, 0)
- button.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
- button.TextColor3 = Color3.fromRGB(255, 255, 255)
- button.Font = Enum.Font.SourceSansBold
- button.TextSize = 18
- button.Text = "OFF"
- button.Parent = frame
- button.MouseButton1Click:Connect(function()
- toggled = not toggled
- button.Text = toggled and "ON" or "OFF"
- button.BackgroundColor3 = toggled and Color3.fromRGB(0, 170, 0) or Color3.fromRGB(80, 80, 80)
- if callback then callback(toggled) end
- end)
- return {
- Set = function(value)
- toggled = value
- button.Text = toggled and "ON" or "OFF"
- button.BackgroundColor3 = toggled and Color3.fromRGB(0, 170, 0) or Color3.fromRGB(80, 80, 80)
- if callback then callback(toggled) end
- end,
- Get = function() return toggled end
- }
- end
- -- Input control (TextBox)
- function Library:CreateInput(name, defaultText, callback)
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(1, 0, 0, 40)
- frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
- frame.Parent = contentHolder
- local label = createLabel(name)
- label.Size = UDim2.new(0.35, 0, 1, 0)
- label.Parent = frame
- local textbox = Instance.new("TextBox")
- textbox.Size = UDim2.new(0.6, 0, 0.7, 0)
- textbox.Position = UDim2.new(0.4, 0, 0.15, 0)
- textbox.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
- textbox.TextColor3 = Color3.fromRGB(255, 255, 255)
- textbox.Font = Enum.Font.SourceSans
- textbox.TextSize = 18
- textbox.Text = defaultText or ""
- textbox.ClearTextOnFocus = false
- textbox.Parent = frame
- textbox.FocusLost:Connect(function(enterPressed)
- if enterPressed and callback then
- callback(textbox.Text)
- end
- end)
- return {
- Set = function(value)
- textbox.Text = tostring(value)
- end,
- Get = function()
- return textbox.Text
- end
- }
- end
- -- Slider control
- function Library:CreateSlider(name, min, max, defaultValue, callback)
- local sliderValue = defaultValue or min
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(1, 0, 0, 50)
- frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
- frame.Parent = contentHolder
- local label = createLabel(name)
- label.Size = UDim2.new(1, 0, 0, 20)
- label.Parent = frame
- local sliderBar = Instance.new("Frame")
- sliderBar.Size = UDim2.new(1, -40, 0, 10)
- sliderBar.Position = UDim2.new(0, 10, 0, 30)
- sliderBar.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
- sliderBar.Parent = frame
- local sliderFill = Instance.new("Frame")
- sliderFill.Size = UDim2.new((sliderValue - min) / (max - min), 0, 1, 0)
- sliderFill.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
- sliderFill.Parent = sliderBar
- local sliderBtn = Instance.new("TextButton")
- sliderBtn.Size = UDim2.new(0, 15, 1, 0)
- sliderBtn.Position = UDim2.new((sliderValue - min) / (max - min) - 0.05, 0, 0, 0)
- sliderBtn.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
- sliderBtn.Text = ""
- sliderBtn.Parent = sliderBar
- sliderBtn.AutoButtonColor = false
- local dragging = false
- local function updateSlider(x)
- local relativeX = math.clamp(x - sliderBar.AbsolutePosition.X, 0, sliderBar.AbsoluteSize.X)
- local value = min + ((relativeX / sliderBar.AbsoluteSize.X) * (max - min))
- sliderValue = math.floor(value * 100) / 100 -- round to 2 decimals
- sliderFill.Size = UDim2.new((sliderValue - min) / (max - min), 0, 1, 0)
- sliderBtn.Position = UDim2.new((sliderValue - min) / (max - min) - 0.05, 0, 0, 0)
- if callback then callback(sliderValue) end
- end
- sliderBtn.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 then
- dragging = true
- end
- end)
- sliderBtn.InputEnded:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 then
- dragging = false
- end
- end)
- UserInputService.InputChanged:Connect(function(input)
- if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
- updateSlider(input.Position.X)
- end
- end)
- return {
- Set = function(value)
- sliderValue = math.clamp(value, min, max)
- sliderFill.Size = UDim2.new((sliderValue - min) / (max - min), 0, 1, 0)
- sliderBtn.Position = UDim2.new((sliderValue - min) / (max - min) - 0.05, 0, 0, 0)
- if callback then callback(sliderValue) end
- end,
- Get = function()
- return sliderValue
- end
- }
- end
- -- Dropdown control (updated: dropdown list outside container for top layering)
- function Library:CreateDropdown(name, options, callback)
- local isOpen = false
- local selectedIndex = 1
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(1, 0, 0, 40)
- frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
- frame.Parent = contentHolder
- local label = createLabel(name)
- label.Size = UDim2.new(0.6, 0, 1, 0)
- label.Parent = frame
- local dropdownBtn = Instance.new("TextButton")
- dropdownBtn.Size = UDim2.new(0.35, 0, 0.7, 0)
- dropdownBtn.Position = UDim2.new(0.6, 0, 0.15, 0)
- dropdownBtn.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
- dropdownBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
- dropdownBtn.Font = Enum.Font.SourceSansBold
- dropdownBtn.TextSize = 18
- dropdownBtn.Text = options[selectedIndex]
- dropdownBtn.Parent = frame
- -- Dropdown list outside contentHolder for top layering & no clipping
- local dropdownList = Instance.new("Frame")
- dropdownList.Size = UDim2.new(0, 150, 0, #options * 30)
- dropdownList.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
- dropdownList.Visible = false
- dropdownList.ClipsDescendants = true
- dropdownList.BorderSizePixel = 0
- dropdownList.Parent = screenGui -- Directly parented to ScreenGui for highest z-index
- local listLayout = Instance.new("UIListLayout")
- listLayout.Parent = dropdownList
- for i, option in ipairs(options) do
- local optionBtn = Instance.new("TextButton")
- optionBtn.Size = UDim2.new(1, 0, 0, 30)
- optionBtn.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
- optionBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
- optionBtn.Font = Enum.Font.SourceSans
- optionBtn.TextSize = 18
- optionBtn.Text = option
- optionBtn.Parent = dropdownList
- optionBtn.MouseButton1Click:Connect(function()
- selectedIndex = i
- dropdownBtn.Text = options[selectedIndex]
- dropdownList.Visible = false
- isOpen = false
- if callback then callback(options[selectedIndex]) end
- end)
- end
- local function updateDropdownPosition()
- local absPos = dropdownBtn.AbsolutePosition
- local absSize = dropdownBtn.AbsoluteSize
- -- Position dropdownList below dropdownBtn
- dropdownList.Position = UDim2.new(0, absPos.X, 0, absPos.Y + absSize.Y)
- dropdownList.Size = UDim2.new(0, absSize.X, 0, #options * 30)
- end
- dropdownBtn.MouseButton1Click:Connect(function()
- isOpen = not isOpen
- dropdownList.Visible = isOpen
- if isOpen then
- updateDropdownPosition()
- end
- end)
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if not gameProcessed and isOpen then
- -- Close dropdown if clicked outside dropdownBtn or dropdownList
- local mousePos = UserInputService:GetMouseLocation()
- local dpPos = dropdownList.AbsolutePosition
- local dpSize = dropdownList.AbsoluteSize
- local dbPos = dropdownBtn.AbsolutePosition
- local dbSize = dropdownBtn.AbsoluteSize
- local inDropdownList = mousePos.X >= dpPos.X and mousePos.X <= dpPos.X + dpSize.X and
- mousePos.Y >= dpPos.Y and mousePos.Y <= dpPos.Y + dpSize.Y
- local inDropdownBtn = mousePos.X >= dbPos.X and mousePos.X <= dbPos.X + dbSize.X and
- mousePos.Y >= dbPos.Y and mousePos.Y <= dbPos.Y + dbSize.Y
- if not inDropdownList and not inDropdownBtn then
- dropdownList.Visible = false
- isOpen = false
- end
- end
- end)
- RunService.RenderStepped:Connect(function()
- if isOpen then
- updateDropdownPosition()
- end
- end)
- return {
- Set = function(value)
- for i, option in ipairs(options) do
- if option == value then
- selectedIndex = i
- dropdownBtn.Text = value
- if callback then callback(value) end
- break
- end
- end
- end,
- Get = function()
- return options[selectedIndex]
- end
- }
- end
- -- Button control
- function Library:CreateButton(name, callback)
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(1, 0, 0, 40)
- button.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
- button.TextColor3 = Color3.fromRGB(255, 255, 255)
- button.Font = Enum.Font.SourceSansBold
- button.TextSize = 20
- button.Text = name
- button.Parent = contentHolder
- button.MouseButton1Click:Connect(function()
- if callback then callback() end
- end)
- return button
- end
- return Library
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement