Advertisement
GustavoDestroyer

ScriptUI API

Jul 31st, 2021
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.70 KB | None | 0 0
  1. local ScriptUI = {}
  2.  
  3. function ScriptUI.Frame(Parent)
  4.     local Frame = {}
  5.     Frame.Instance = Instance.new("Frame")
  6.  
  7.     if Parent then
  8.         Frame.Instance.Parent = Parent
  9.     end
  10.  
  11.     function Frame:SetSize(Size)
  12.         self.Instance.Size = Size
  13.  
  14.         return self
  15.     end
  16.  
  17.     function Frame:SetColor(Color)
  18.         self.Instance.BackgroundColor3 = Color
  19.  
  20.         return self
  21.     end
  22.  
  23.     function Frame:SetPosition(Position)
  24.         self.Instance.Position = Position
  25.  
  26.         return self
  27.     end
  28.  
  29.     function Frame:SetAnchorPoint(AnchorPoint)
  30.         self.Instance.AnchorPoint = AnchorPoint
  31.  
  32.         return self
  33.     end
  34.  
  35.     function Frame:AddChild(Element)
  36.         if typeof(Element) == "Instance" then
  37.             Element.Parent = self.Instance
  38.         elseif typeof(Element) == "table" then
  39.             Element.Instance.Parent = self.Instance
  40.         end
  41.  
  42.         return self
  43.     end
  44.  
  45.     function Frame:RemoveChild(Element)
  46.         if typeof(Element) == "Instance" then
  47.             Element:Destroy()
  48.         elseif typeof(Element) == "table" then
  49.             Element.Instance:Destroy()
  50.         end
  51.  
  52.         return self
  53.     end
  54.  
  55.     return Frame
  56. end
  57.  
  58. function ScriptUI.Switcher(Parent)
  59.     local Switcher = {}
  60.     Switcher.Parent = nil
  61.     Switcher.Value = false
  62.     Switcher.__debounce__ = false
  63.     Switcher.__debounceDuration__ = 0
  64.     Switcher.Instance = Instance.new("Frame")
  65.     Switcher.Instance.Size = UDim2.new(0.1, 0, 0.1, 0)
  66.     Switcher.Instance.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  67.  
  68.     if Parent then
  69.         if typeof(Parent) == "Instance" then
  70.             Switcher.Parent = Parent
  71.             Switcher.Instance.Parent = Parent
  72.         elseif typeof(Parent) == "table" then
  73.             Switcher.Parent = Parent
  74.             Switcher.Instance.Parent = Parent.Instance
  75.         end
  76.     end
  77.  
  78.     local _ = Instance.new("UICorner", Switcher.Instance)
  79.     _.CornerRadius = UDim.new(0, 10)
  80.  
  81.     local V1 = Instance.new("TextButton", Switcher.Instance)
  82.     V1.Text = ""
  83.     V1.Size = UDim2.new(0.45, 0, 0.8, 0)
  84.     V1.AnchorPoint = Vector2.new(0.5, 0.5)
  85.     V1.Position = UDim2.new(0.275, 0, 0.5, 0)
  86.     V1.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
  87.  
  88.     V1.MouseButton1Click:Connect(function()
  89.         if not Switcher.__debounce__ then
  90.             Switcher.__debounce__ = true
  91.  
  92.             if V1.Position == UDim2.new(0.275, 0, 0.5, 0) then
  93.                 V1:TweenPosition(UDim2.new(0.725, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.15, true)
  94.                 V1.BackgroundColor3 = Color3.new(0, 255, 0)
  95.  
  96.                 Switcher.Value = true
  97.             else
  98.                 V1:TweenPosition(UDim2.new(0.275, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.15, true)
  99.                 V1.BackgroundColor3 = Color3.new(255, 0, 0)
  100.  
  101.                 Switcher.Value = false
  102.             end
  103.  
  104.             wait(Switcher.__debounceDuration__)
  105.  
  106.             Switcher.__debounce__ = false
  107.         end
  108.     end)
  109.  
  110.     local __ = Instance.new("UICorner", V1)
  111.     __.CornerRadius = UDim.new(0, 10)
  112.  
  113.     function Switcher:SetSize(Size)
  114.         self.Instance.Size = Size
  115.  
  116.         return self
  117.     end
  118.  
  119.     function Switcher:SetPosition(Position)
  120.         self.Instance.Position = Position
  121.  
  122.         return self
  123.     end
  124.  
  125.     function Switcher:SetAnchorPoint(AnchorPoint)
  126.         self.Instance.AnchorPoint = AnchorPoint
  127.  
  128.         return self
  129.     end
  130.  
  131.     function Switcher:SetDebounceDuration(Duration)
  132.         self.__debounceDuration__ = Duration
  133.  
  134.         return self
  135.     end
  136.  
  137.     function Switcher:AddEventListener(Event, Callback)
  138.         if Event == "Switch" then
  139.             local Connection = nil
  140.  
  141.             Connection = V1.MouseButton1Click:Connect(function()
  142.                 Callback(Switcher.Value == false)
  143.             end)
  144.  
  145.             return self, Connection
  146.         else
  147.             local Connection = nil
  148.  
  149.             Connection = V1[Event]:Connect(function(...)
  150.                 Callback(...)
  151.             end)
  152.  
  153.             return self, Connection
  154.         end
  155.     end
  156.  
  157.     return Switcher
  158. end
  159.  
  160. function ScriptUI.TextButton(Text, Parent)
  161.     local Button = {}
  162.     Button.Instance = Instance.new("TextButton")
  163.     Button.Instance.Text = Text
  164.  
  165.     if Parent then
  166.         Button.Instance.Parent = Parent
  167.     end
  168.  
  169.     function Button:SetSize(Size)
  170.         self.Instance.Size = Size
  171.  
  172.         return self
  173.     end
  174.  
  175.     function Button:SetText(Text)
  176.         self.Instance.Text = Text
  177.  
  178.         return self
  179.     end
  180.  
  181.     function Button:SetFont(Font)
  182.         self.Instance.Font = Font
  183.  
  184.         return self
  185.     end
  186.  
  187.     function Button:SetFontSize(FontSize)
  188.         self.Instance.TextSize = FontSize
  189.  
  190.         return self
  191.     end
  192.  
  193.     function Button:SetColor(Color)
  194.         self.Instance.BackgroundColor3 = Color
  195.  
  196.         return self
  197.     end
  198.  
  199.     function Button:SetTextColor(Color)
  200.         self.Instance.TextColor3 = Color
  201.  
  202.         return self
  203.     end
  204.  
  205.     function Button:SetPosition(Position)
  206.         self.Instance.Position = Position
  207.  
  208.         return self
  209.     end
  210.  
  211.     function Button:SetAnchorPoint(AnchorPoint)
  212.         self.Instance.AnchorPoint = AnchorPoint
  213.  
  214.         return self
  215.     end
  216.  
  217.     function Button:AddEventListener(Event, Callback)
  218.         local Connection = nil
  219.  
  220.         Connection = self.Instance[Event]:Connect(function(...)
  221.             Callback(...)
  222.         end)
  223.  
  224.         return self, Connection
  225.     end
  226.  
  227.     return Button
  228. end
  229.  
  230. function ScriptUI.ImageButton(ImageURI, Parent)
  231.     local Button = {}
  232.     Button.Instance = Instance.new("ImageButton")
  233.     Button.Instance.Image = ImageURI
  234.  
  235.     if Parent then
  236.         Button.Instance.Parent = Parent
  237.     end
  238.  
  239.     function Button:SetSize(Size)
  240.         self.Instance.Size = Size
  241.  
  242.         return self
  243.     end
  244.  
  245.     function Button:SetColor(Color)
  246.         self.Instance.BackgroundColor3 = Color
  247.  
  248.         return self
  249.     end
  250.  
  251.     function Button:SetImage(ImageURI)
  252.         self.Instance.Image = ImageURI
  253.  
  254.         return self
  255.     end
  256.  
  257.     function Button:SetTextColor(Color)
  258.         self.Instance.TextColor3 = Color
  259.  
  260.         return self
  261.     end
  262.  
  263.     function Button:SetPosition(Position)
  264.         self.Instance.Position = Position
  265.  
  266.         return self
  267.     end
  268.  
  269.     function Button:SetAnchorPoint(AnchorPoint)
  270.         self.Instance.AnchorPoint = AnchorPoint
  271.  
  272.         return self
  273.     end
  274.  
  275.     function Button:AddEventListener(Event, Callback)
  276.         local Connection = nil
  277.  
  278.         Connection = self.Instance[Event]:Connect(function(...)
  279.             Callback(...)
  280.         end)
  281.  
  282.         return self, Connection
  283.     end
  284.  
  285.     return Button
  286. end
  287.  
  288. return ScriptUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement