Advertisement
trollhackerdude

ui lib api

Sep 25th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. local lib = {
  2.     windowcount = 0;
  3.     maxCount = 2;
  4.     maxSideObjects = 2;
  5. }
  6.  
  7.  
  8.  
  9. local plrs = game:GetService("Players")
  10. local plr = plrs.LocalPlayer
  11. local cui = game:GetService("CoreGui")
  12.  
  13.  
  14.  
  15. -- ugly code
  16. function lib:NewWindow(name)
  17.     if not cui:FindFirstChild("ui") then
  18.         local parent = Instance.new("ScreenGui", cui)
  19.         parent.Name = "ui"
  20.     end
  21.     lib.windowcount = lib.windowcount + 1
  22.     if lib.windowcount > lib.maxCount then
  23.         plr:Kick("UI LIBRARY: Maximum window count is "..lib.maxCount)
  24.     end
  25.     local f = Instance.new("Frame")
  26.     f.Name = name
  27.     f.Size = UDim2.new(0,200,0,100)
  28.     f.Parent = cui.ui
  29.     f.Active = true
  30.     f.Draggable = true
  31.     local val = Instance.new("IntValue",f)
  32.     val.Name = "obj"
  33.     val.Value = 0
  34.     local label = Instance.new("TextLabel", f)
  35.     label.Name = "label"
  36.     label.Text = name -- make sure you dont dick off when naming your frames
  37.     label.Position = UDim2.new(0,0,0,0)
  38.     label.Size = UDim2.new(0,200,0,20)
  39.     if lib.windowcount == 1 then
  40.         f.Position = UDim2.new(0,0,0,0)
  41.     elseif lib.windowcount == 2 then
  42.         f.Position = UDim2.new(0.267,0,0,0)
  43.     end
  44.     f.BackgroundColor3 = Color3.new(130,130,130)
  45. end
  46.  
  47. function lib:NewObject(class, name, object)
  48.    
  49.  
  50.  
  51.    
  52.     local parent = cui.ui:FindFirstChild(object)
  53.    
  54.     if not parent:FindFirstChild("obj") then
  55.         plr:Kick("LIBRARY: Invalid Parent for object, parent must be a valid frame created by library and have the obj int value in it")
  56.     end
  57.    
  58.     local val = parent.obj
  59.    
  60.     val.Value = val.Value + 1
  61.    
  62.     if class == "ToggleButton" then
  63.        
  64.         local main = Instance.new("TextButton")
  65.         main.Name = name
  66.         main.Parent = parent
  67.        
  68.         main.Size = UDim2.new(0,180,0,20)
  69.         main.Text = name..": OFF"
  70.        
  71.         if val.Value == 1 then
  72.             main.Position = UDim2.new(0.05, 0,0.25, 0)
  73.    
  74.         elseif val.Value == 2 then
  75.             main.Position = UDim2.new(0.05, 0,0.5, 0)
  76.        
  77.         elseif val.Value == 3 then
  78.             main.Position = UDim2.new(0.05, 0,0.75, 0)
  79.            
  80.            
  81.            
  82.         end
  83.        
  84.         local active = Instance.new("BoolValue", main)
  85.         active.Value = false
  86.         active.Name = "on"
  87.        
  88.    
  89.     function SCRIPT_PFZT74_FAKESCRIPT() -- TextButton.LocalScript
  90.         local script = Instance.new('LocalScript')
  91.         script.Parent = main
  92.         script.Parent.MouseButton1Click:Connect(function()
  93.             if main.on.Value == true then
  94.                 main.on.Value = false
  95.                 script.Parent.Text = script.Parent.Name..": OFF"
  96.             else
  97.                 main.on.Value = true
  98.                 script.Parent.Text = script.Parent.Name..": ON"
  99.             end
  100.         end)
  101.    
  102.     end
  103. coroutine.resume(coroutine.create(SCRIPT_PFZT74_FAKESCRIPT))
  104. end
  105.    
  106.     if val.Value >= 4 then
  107.         plr:Kick("UI LIBRARY: Too many objects in one gui, the max is 3.")
  108.     end
  109.     if class ~= "ToggleButton" then
  110.         local main = Instance.new(class)
  111.         main.Name = name
  112.         main.Parent = parent
  113.        
  114.         main.Size = UDim2.new(0,180,0,20)
  115.         main.Text = name
  116.        
  117.         if val.Value == 1 then
  118.             main.Position = UDim2.new(0.05, 0,0.25, 0)
  119.    
  120.         elseif val.Value == 2 then
  121.             main.Position = UDim2.new(0.05, 0,0.5, 0)
  122.        
  123.         elseif val.Value == 3 then
  124.             main.Position = UDim2.new(0.05, 0,0.75, 0)
  125.            
  126.            
  127.            
  128.         end
  129.        
  130.  
  131.     end
  132.  
  133.    
  134.    
  135. end
  136.  
  137.  
  138.  
  139. return lib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement