Advertisement
Vzurxy

Untitled

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