Advertisement
Guest User

Bara UI

a guest
Aug 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.52 KB | None | 0 0
  1. local Heartbeat = game:GetService("RunService").Heartbeat;
  2. local library = {
  3.     windowcount = 0;
  4. }
  5.  
  6. local defaults = defaults or {
  7.     boxcolor = nil,
  8.     Rainbow = true,
  9.     slidingbarcolor = nil,
  10.     txtcolor = Color3.fromRGB(255, 255, 255),
  11.     underline = Color3.fromRGB(0, 255, 140),
  12.     barcolor = Color3.fromRGB(50, 50, 50),
  13.     bgcolor = Color3.fromRGB(50, 50, 50)
  14. };
  15.  
  16. if game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("Bara's UI") then
  17.     game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("Bara's UI"):Destroy();
  18. end
  19.  
  20. local tweenPosition = function (object, newpos)
  21.     object.Position = newpos
  22. end;
  23.  
  24. local dragger = {};
  25. local resizer = {};
  26. local frames = {};
  27. local Callbacks = {};
  28. local Enabled = {};
  29.  
  30. do
  31.     local mouse = game:GetService("Players").LocalPlayer:GetMouse();
  32.     local inputService = game:GetService('UserInputService');
  33.    
  34.     function dragger.new(frame)
  35.         local s, event = pcall(function()
  36.             return frame.MouseEnter;
  37.         end);
  38.  
  39.         if s then
  40.             frame.Active = true;
  41.  
  42.             event:connect(function()
  43.                 local input = frame.InputBegan:connect(function(key)
  44.                     if key.UserInputType == Enum.UserInputType.MouseButton1 then
  45.                         local objectPosition = Vector2.new(mouse.X - frame.AbsolutePosition.X, mouse.Y - frame.AbsolutePosition.Y);
  46.                         while Heartbeat:wait() and inputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) do
  47.                             frame:TweenPosition(UDim2.new(0, mouse.X - objectPosition.X + (frame.Size.X.Offset * frame.AnchorPoint.X), 0, mouse.Y - objectPosition.Y + (frame.Size.Y.Offset * frame.AnchorPoint.Y)), 'Out', 'Quad', 0, true);
  48.                         end;
  49.                     end;
  50.                 end);
  51.  
  52.                 local leave;
  53.                 leave = frame.MouseLeave:connect(function()
  54.                     input:disconnect();
  55.                     leave:disconnect();
  56.                 end)
  57.             end)
  58.         end
  59.     end
  60.  
  61.     function resizer.new(p, s)
  62.         p:GetPropertyChangedSignal('AbsoluteSize'):connect(function()
  63.             s.Size = UDim2.new(s.Size.X.Scale, s.Size.X.Offset, s.Size.Y.Scale, p.AbsoluteSize.Y);
  64.         end)
  65.     end
  66. end;
  67.  
  68. function library:Create(class, props)
  69.     local object = Instance.new(class);
  70.    
  71.     for i, prop in next, props do
  72.         if i ~= "Parent" then
  73.             object[i] = prop;
  74.         end
  75.     end
  76.  
  77.     object.Parent = props.Parent;
  78.     return object;
  79. end
  80.  
  81.  
  82. function library:CreateWindow(options)
  83.     assert(options.text, "no name");
  84.     local window = {
  85.         count = 0;
  86.         toggles = {},
  87.         closed = false;
  88.     }
  89.  
  90.     local options = options or {};
  91.     setmetatable(options, {__index = defaults})
  92.  
  93.     self.windowcount = self.windowcount + 1;
  94.  
  95.     library.gui = library.gui or self:Create("ScreenGui", {Name = "Bara's UI", Parent = game:GetService("Players").LocalPlayer.PlayerGui})
  96.     library.gui.ResetOnSpawn = false
  97.  
  98.     window.frame = self:Create("Frame", {
  99.         Name = options.text;
  100.         Parent = self.gui,
  101.         Visible = false,
  102.         Active = true,
  103.         BackgroundTransparency = 0,
  104.         Size = UDim2.new(0, 178, 0, 30),
  105.         Position = UDim2.new(0, (5 + ((178 * self.windowcount) - 178)), 0, 5),
  106.         BackgroundColor3 = options.barcolor,
  107.         BorderSizePixel = 0
  108.     });
  109.  
  110.     frames[#frames + 1] = window.frame;
  111.  
  112.     window.background = self:Create('Frame', {
  113.         Name = 'Background';
  114.         Parent = window.frame,
  115.         BorderSizePixel = 0;
  116.         BackgroundColor3 = options.bgcolor,
  117.         Position = UDim2.new(0, 0, 1, 0),
  118.         Size = UDim2.new(1, 0, 0, 25),
  119.         BackgroundTransparency = 0.4,
  120.         ClipsDescendants = true;
  121.     })
  122.  
  123.     window.container = self:Create('ScrollingFrame', {
  124.         Name = 'Container';
  125.         Parent = window.frame,
  126.         BorderSizePixel = 0,
  127.         BorderSizePixel = 0,
  128.         BackgroundColor3 = options.bgcolor,
  129.         CanvasSize = UDim2.new(0, 0, 0, 0),
  130.         BottomImage = "rbxasset://textures/ui/Scroll/scroll-middle.png",
  131.         TopImage = "rbxasset://textures/ui/Scroll/scroll-middle.png",
  132.         Position = UDim2.new(0, 0, 1, 0),
  133.         Size = UDim2.new(1, 0, 0, 25),
  134.         BackgroundTransparency = 0.4,
  135.         ClipsDescendants = true,
  136.         ScrollBarThickness = 10
  137.     })
  138.  
  139.     window.organizer = self:Create('UIListLayout', {
  140.         Name = 'Sorter';
  141.         SortOrder = Enum.SortOrder.LayoutOrder;
  142.         Parent = window.container;
  143.     })
  144.  
  145.     window.padder = self:Create('UIPadding', {
  146.         Name = 'Padding';
  147.         PaddingLeft = UDim.new(0, 10);
  148.         PaddingTop = UDim.new(0, 5);
  149.         Parent = window.container;
  150.     })
  151.  
  152.     local underline = self:Create("Frame", {
  153.         Name = 'Underline';
  154.         Size = UDim2.new(1, 0, 0, 3),
  155.         Position = UDim2.new(0, 0, 1, -1),
  156.         BorderSizePixel = 0;
  157.         BackgroundColor3 = options.underline;
  158.         Parent = window.frame
  159.     })
  160.  
  161.     local togglebutton = self:Create("TextButton", {
  162.         Name = 'Toggle';
  163.         ZIndex = 2,
  164.         BackgroundTransparency = 1;
  165.         Position = UDim2.new(1, -25, 0, 0),
  166.         Size = UDim2.new(0, 25, 1, 0),
  167.         Text = "-",
  168.         TextSize = 17,
  169.         TextColor3 = options.txtcolor,
  170.         Font = Enum.Font.SourceSans,
  171.         Parent = window.frame,
  172.     });
  173.  
  174.     togglebutton.MouseButton1Click:connect(function()
  175.         window.closed = not window.closed;
  176.         togglebutton.Text = (window.closed and "+" or "-");
  177.         if window.closed then
  178.             window:Resize(true, UDim2.new(1, 0, 0, 0));
  179.             wait(0.4)
  180.             window.container.Visible = false
  181.         else
  182.             window.container.Visible = true
  183.             window:Resize(true);
  184.         end;
  185.     end);
  186.  
  187.     self:Create("TextLabel", {
  188.         Size = UDim2.new(1, 0, 1, 0),
  189.         BackgroundTransparency = 1,
  190.         BorderSizePixel = 0,
  191.         TextColor3 = options.txtcolor,
  192.         TextColor3 = (options.bartextcolor or Color3.fromRGB(255, 255, 255)),
  193.         TextSize = 17,
  194.         Font = Enum.Font.SourceSansSemibold,
  195.         Text = options.text or "window",
  196.         Name = "Window",
  197.         Parent = window.frame,
  198.     })
  199.  
  200.     local open = {}
  201.  
  202.     do
  203.         dragger.new(window.frame)
  204.         resizer.new(window.background, window.container);
  205.     end
  206.  
  207.     local function getSize()
  208.         local ySize = 0;
  209.         for i, object in next, window.container:GetChildren() do
  210.             if (not object:IsA('UIListLayout')) and (not object:IsA('UIPadding')) then
  211.                 ySize = ySize + object.AbsoluteSize.Y
  212.             end
  213.         end
  214.        
  215.         if ySize > 400 then
  216.             ySize = 400;
  217.             window.container.CanvasSize = UDim2.new(0, 0, 0, (#window.container:GetChildren() - 1) * 20)
  218.         end;
  219.        
  220.         return UDim2.new(1, 0, 0, ySize + 10)
  221.     end
  222.  
  223.     function window:Resize(tween, change)
  224.         local size = change or getSize()
  225.         self.container.ClipsDescendants = true;
  226.  
  227.         if tween then
  228.             self.background:TweenSize(size, "Out", "Sine", 0.5, true)
  229.         else
  230.             self.background.Size = size
  231.         end
  232.     end
  233.  
  234.     function window:AddSlidingBar(text, minval, maxval, callback)
  235.         self.count = self.count + 1;
  236.         callback = callback or function() end;
  237.         minval = minval or 0;
  238.         maxval = maxval or 100;
  239.  
  240.         maxval = maxval / 8;
  241.        
  242.         local newContainer = library:Create("Frame", {
  243.             Parent = self.container,
  244.             Size = UDim2.new(1, -10, 0, 20),
  245.             BackgroundColor3 = options.slidingbarcolor,
  246.             BackgroundTransparency = 1,
  247.         })
  248.  
  249.         local slidingbar = library:Create("ScrollingFrame", {
  250.             Parent = newContainer,
  251.             Size = UDim2.new(1, -10, 0, 20),
  252.             CanvasSize = UDim2.new(8, 0, 0, 0),
  253.             BackgroundColor3 = options.slidingbarcolor,
  254.             BottomImage = "rbxasset://textures/ui/Scroll/scroll-middle.png",
  255.             TopImage = "rbxasset://textures/ui/Scroll/scroll-middle.png",
  256.             MidImage = "rbxasset://textures/ui/Scroll/scroll-middle.png",
  257.             ScrollBarThickness = 20,
  258.             ScrollBarImageColor3 = Color3.fromRGB(0, 0, 0),
  259.             ScrollBarImageTransparency = 0.3,
  260.         });
  261.  
  262.         local label = library:Create("TextLabel", {
  263.             Size = UDim2.new(1, 0, 1, 0),
  264.             BackgroundTransparency = 1,
  265.             BackgroundColor3 = options.slidingbarcolor,
  266.             TextColor3 = Color3.fromRGB(255, 255, 255),
  267.             TextXAlignment = Enum.TextXAlignment.Center,
  268.             TextSize = 16,
  269.             Text = text .. ": " .. minval,
  270.             Font = Enum.Font.SourceSans,
  271.             LayoutOrder = self.Count,
  272.             BorderSizePixel = 0,
  273.             Parent = newContainer,
  274.         })
  275.  
  276.         slidingbar.Changed:Connect(function(p)
  277.             if p ~= "CanvasPosition" then return end
  278.  
  279.             local Val = minval - math.floor((slidingbar.CanvasPosition.X / (slidingbar.CanvasSize.X.Offset - slidingbar.AbsoluteWindowSize.X)) * maxval)
  280.             label.Text = text .. ": " .. tostring(Val);
  281.             callback(Val);
  282.         end)
  283.  
  284.         self:Resize();
  285.  
  286.     end;
  287.  
  288.     function window:AddToggle(text, callback)
  289.         self.count = self.count + 1;
  290.  
  291.         callback = callback or function() end;
  292.  
  293.         local label = library:Create("TextLabel", {
  294.             Text =  text,
  295.             Size = UDim2.new(1, -10, 0, 20),
  296.             BackgroundTransparency = 1,
  297.             TextColor3 = Color3.fromRGB(255, 255, 255),
  298.             TextXAlignment = Enum.TextXAlignment.Left,
  299.             LayoutOrder = self.Count,
  300.             TextSize = 16,
  301.             Font = Enum.Font.SourceSans,
  302.             Parent = self.container,
  303.         })
  304.  
  305.         local button = library:Create("TextButton", {
  306.             Text = "OFF",
  307.             TextColor3 = Color3.fromRGB(255, 25, 25),
  308.             BackgroundTransparency = 1,
  309.             Position = UDim2.new(1, -25, 0, 0),
  310.             Size = UDim2.new(0, 25, 1, 0),
  311.             TextSize = 17,
  312.             Font = Enum.Font.SourceSansSemibold,
  313.             Parent = label,
  314.         })
  315.  
  316.         Callbacks[text] = function(toggle)
  317.             if not toggle then
  318.                 toggle = not self.toggles[text];
  319.             end;
  320.  
  321.             self.toggles[text] = toggle;
  322.             Enabled[text] = toggle;
  323.             button.TextColor3 = (self.toggles[text] and Color3.fromRGB(0, 255, 140) or Color3.fromRGB(255, 25, 25));
  324.             button.Text = (self.toggles[text] and "ON" or "OFF");
  325.  
  326.             callback(self.toggles[text]);
  327.         end;
  328.  
  329.         button.MouseButton1Click:connect(Callbacks[text]);
  330.  
  331.         self:Resize();
  332.         return button;
  333.     end
  334.  
  335.     function window:AddBox(text, callback)
  336.         self.count = self.count + 1
  337.         callback = callback or function() end
  338.  
  339.         local box = library:Create("TextBox", {
  340.             PlaceholderText = text,
  341.             Size = UDim2.new(1, -10, 0, 20),
  342.             BackgroundTransparency = 0.75,
  343.             BackgroundColor3 = options.boxcolor,
  344.             TextColor3 = Color3.fromRGB(255, 255, 255),
  345.             TextXAlignment = Enum.TextXAlignment.Center,
  346.             TextSize = 16,
  347.             Text = "",
  348.             Font = Enum.Font.SourceSans,
  349.             LayoutOrder = self.Count,
  350.             BorderSizePixel = 0,
  351.             Parent = self.container,
  352.         })
  353.  
  354.         box.FocusLost:connect(function(...)
  355.             callback(box, ...)
  356.         end)
  357.  
  358.         self:Resize()
  359.         return box
  360.     end
  361.  
  362.     function window:AddButton(text, callback)
  363.         self.count = self.count + 1
  364.  
  365.         callback = callback or function() end
  366.        
  367.         local button = library:Create("TextButton", {
  368.             Text = text,
  369.             Size = UDim2.new(1, -10, 0, 20),
  370.             BackgroundTransparency = 1,
  371.             TextColor3 = Color3.fromRGB(255, 255, 255),
  372.             TextXAlignment = Enum.TextXAlignment.Left,
  373.             TextSize = 16,
  374.             Font = Enum.Font.SourceSans,
  375.             LayoutOrder = self.Count,
  376.             Parent = self.container,
  377.         })
  378.  
  379.         button.MouseButton1Click:connect(callback)
  380.         self:Resize()
  381.         return button
  382.     end
  383.  
  384.     function window:AddLabel(text)
  385.         self.count = self.count + 1;
  386.  
  387.         local tSize = game:GetService('TextService'):GetTextSize(text, 16, Enum.Font.SourceSans, Vector2.new(math.huge, math.huge))
  388.  
  389.         local button = library:Create("TextLabel", {
  390.             Text =  text,
  391.             Size = UDim2.new(1, -10, 0, tSize.Y + 5),
  392.             TextScaled = false,
  393.             BackgroundTransparency = 1,
  394.             TextColor3 = Color3.fromRGB(255, 255, 255),
  395.             TextXAlignment = Enum.TextXAlignment.Left,
  396.             TextSize = 16,
  397.             Font = Enum.Font.SourceSans,
  398.             LayoutOrder = self.Count,
  399.             Parent = self.container,
  400.         });
  401.  
  402.         self:Resize();
  403.         return button;
  404.     end;
  405.  
  406.     function window:AddDropdown(options, callback)
  407.         self.count = self.count + 1
  408.         local default = options[1] or "";
  409.  
  410.         callback = callback or function() end
  411.         local dropdown = library:Create("TextLabel", {
  412.             Size = UDim2.new(1, -10, 0, 20),
  413.             BackgroundTransparency = 0.75,
  414.             BackgroundColor3 = options.boxcolor,
  415.             TextColor3 = Color3.fromRGB(255, 255, 255),
  416.             TextXAlignment = Enum.TextXAlignment.Center,
  417.             TextSize = 16,
  418.             Text = default,
  419.             Font = Enum.Font.SourceSans,
  420.             BorderSizePixel = 0;
  421.             LayoutOrder = self.Count,
  422.             Parent = self.container,
  423.         })
  424.  
  425.         local button = library:Create("ImageButton",{
  426.             BackgroundTransparency = 1,
  427.             Image = 'rbxassetid://3234893186',
  428.             Size = UDim2.new(0, 18, 1, 0),
  429.             Position = UDim2.new(1, -20, 0, 0),
  430.             Parent = dropdown,
  431.         })
  432.  
  433.         local frame;
  434.  
  435.         local function isInGui(frame)
  436.             local mloc = game:GetService('UserInputService'):GetMouseLocation();
  437.             local mouse = Vector2.new(mloc.X, mloc.Y - 36);
  438.  
  439.             local x1, x2 = frame.AbsolutePosition.X, frame.AbsolutePosition.X + frame.AbsoluteSize.X;
  440.             local y1, y2 = frame.AbsolutePosition.Y, frame.AbsolutePosition.Y + frame.AbsoluteSize.Y;
  441.  
  442.             return (mouse.X >= x1 and mouse.X <= x2) and (mouse.Y >= y1 and mouse.Y <= y2);
  443.         end;
  444.  
  445.         local function count(t)
  446.             local c = 0;
  447.             for i, v in next, t do
  448.                 c = c + 1;
  449.             end;
  450.             return c;
  451.         end;
  452.  
  453.         button.MouseButton1Click:connect(function()
  454.             if count(options) == 0 then
  455.                 return;
  456.             end;
  457.  
  458.             if frame then
  459.                 frame:Destroy();
  460.                 frame = nil;
  461.             end
  462.  
  463.             self.container.ClipsDescendants = false;
  464.  
  465.             frame = library:Create('Frame', {
  466.                 Position = UDim2.new(0, 0, 1, 0);
  467.                 BackgroundColor3 = Color3.fromRGB(40, 40, 40);
  468.                 Size = UDim2.new(0, dropdown.AbsoluteSize.X, 0, (count(options) * 21));
  469.                 BorderSizePixel = 0;
  470.                 Parent = dropdown;
  471.                 ClipsDescendants = true;
  472.                 ZIndex = 2;
  473.             })
  474.  
  475.             library:Create('UIListLayout', {
  476.                 Name = 'Layout';
  477.                 Parent = frame;
  478.             })
  479.  
  480.             for i, option in next, options do
  481.                 local selection = library:Create('TextButton', {
  482.                     Text = option;
  483.                     BackgroundColor3 = Color3.fromRGB(40, 40, 40);
  484.                     TextColor3 = Color3.fromRGB(255, 255, 255);
  485.                     BorderSizePixel = 0;
  486.                     TextSize = 16;
  487.                     Font = Enum.Font.SourceSans;
  488.                     Size = UDim2.new(1, 0, 0, 21);
  489.                     Parent = frame;
  490.                     ZIndex = 2;
  491.                 })
  492.  
  493.                 selection.MouseButton1Click:connect(function()
  494.                     dropdown.Text = option;
  495.                     callback(option);
  496.                     frame.Size = UDim2.new(1, 0, 0, 0);
  497.                     game:GetService('Debris'):AddItem(frame, 0.1);
  498.                 end);
  499.             end;
  500.         end);
  501.  
  502.         game:GetService('UserInputService').InputBegan:connect(function(m)
  503.             if m.UserInputType == Enum.UserInputType.MouseButton1 then
  504.                 if frame and (not isInGui(frame)) then
  505.                     game:GetService('Debris'):AddItem(frame);
  506.                 end
  507.             end
  508.         end)
  509.  
  510.         callback(default);
  511.         self:Resize();
  512.         return {
  513.             Refresh = function(self, array)
  514.                 game:GetService('Debris'):AddItem(frame);
  515.                 options = array;
  516.                 dropdown.Text = options[1];
  517.             end;
  518.         };
  519.     end;
  520.  
  521.     return window;
  522. end;
  523.  
  524. if defaults.Rainbow then
  525.     Heartbeat:Connect(function()
  526.         for i, v in pairs(frames) do
  527.             if v.Parent ~= nil then
  528.                 local r = (math.sin(workspace.DistributedGameTime/2)/2)+0.5
  529.                 local g = (math.sin(workspace.DistributedGameTime)/2)+0.5
  530.                 local b = (math.sin(workspace.DistributedGameTime*1.5)/2)+0.5
  531.                 local color = Color3.new(r, g, b);
  532.                 v.Underline.BackgroundColor3 = color;
  533.             end;
  534.         end;
  535.     end);
  536. end;
  537.  
  538. return library, frames, Callbacks, Enabled
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement