nickcool9999

Current GUI API

Jul 4th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.55 KB | None | 0 0
  1. local gui = {}
  2.  
  3. function percent(x,y) return UDim2.new(x/100,0,y/100,0) end function gui:percent(x,y) return percent(x,y) end
  4. function scale(x,y) return UDim2.new(x,0,y,0) end           function gui:scale(x,y) return scale(x,y) end
  5. function pixels(x,y) return UDim2.new(0,x,0,y) end          function gui:pixels(x,y) return pixels(x,y) end
  6.  
  7. local recolor = "BackgroundColor3"
  8.  
  9. function color(r,g,b)
  10.     return Color3.fromRGB(r,g,b)
  11. end
  12. function gui:color(...) return color(...) end
  13.  
  14. function gui:Frame()
  15.     local f = Instance.new("Frame")
  16.     f[recolor] = color(255,255,255)
  17.     f.Size = pixels(0,0)
  18.     f.BorderSizePixel = 0
  19.     return f
  20. end
  21.  
  22. function gui:RoundedFrame(color) -- game-specific
  23.     -- Invisible Container Containing the round elements
  24.     local f = gui:Frame()
  25.     f.Name = "StyledFrame"
  26.     f.Size = gui:pixels(150,150)
  27.     f.BackgroundTransparency = 1
  28.     local corners = {}
  29.     -- Load Assets
  30.     local corner = gui:ImageLabel("rbxgameasset://Images/roundcorner")
  31.     corner.Name = "Corner"
  32.     corners[1] = corner
  33.     corners[2] = corner:Clone()
  34.     corners[2].Rotation = 90
  35.     corners[3] = corner:Clone()
  36.     corners[3].Rotation = 270
  37.     corners[4] = corner:Clone()
  38.     corners[4].Rotation = 180
  39.  
  40.     corners[1].Parent = f
  41.     corners[2].Parent = f
  42.     corners[3].Parent = f
  43.     corners[4].Parent = f
  44.  
  45.     local white = gui:Frame()
  46.     white.Name = "Background"
  47.     white.BackgroundColor3 = gui:color(255,255,255)
  48.     white.BackgroundTransparency = 0
  49.     local white2 = white:Clone()
  50.     local white3 = white2:Clone()
  51.  
  52.     white.Parent = f
  53.     white2.Parent = f
  54.     white3.Parent = f
  55.  
  56.     local roundcontrol = {}
  57.  
  58.     --= Functions =--
  59.     function roundcontrol.setTransparency(n) -- default: 0
  60.         for _,image in pairs(corners) do
  61.             image.ImageTransparency = n
  62.         end
  63.         white.BackgroundTransparency = n
  64.         white2.BackgroundTransparency = n
  65.         white3.BackgroundTransparency = n
  66.     end
  67.  
  68.     function roundcontrol.setStyle(i) -- default: "rbxgameasset://Images/roundcorner"
  69.         for _,image in pairs(corners) do
  70.             image.Image = i
  71.         end
  72.     end
  73.  
  74.     function roundcontrol.setRoundSize(n) -- default: 25
  75.         for _,image in pairs(corners) do
  76.             image.Size = gui:pixels(n,n)
  77.         end
  78.         corners[2].Position = gui:percent(100,0) - gui:pixels(n,0)
  79.         corners[3].Position = gui:percent(0,100) - gui:pixels(0,n)
  80.         corners[4].Position = gui:percent(100,100) - gui:pixels(n,n)
  81.         white.Size = gui:percent(100,100) - gui:pixels(0,n*2)
  82.         white.Position = gui:pixels(0,n)
  83.         white2.Size = gui:percent(100,0) + gui:pixels(-n*2,n)
  84.         white2.Position = gui:pixels(n,0)
  85.         white3.Size = gui:percent(100,0) + gui:pixels(-n*2,n)
  86.         white3.Position = gui:percent(0,100) + gui:pixels(n,-n)
  87.     end
  88.  
  89.     function roundcontrol.setColor(c) -- default: white
  90.         for _,image in pairs(corners) do
  91.             image.ImageColor3 = c
  92.         end
  93.         white.BackgroundColor3 = c
  94.         white2.BackgroundColor3 = c
  95.         white3.BackgroundColor3 = c
  96.     end
  97.  
  98.     function roundcontrol.setLayer(c) -- default: 1
  99.         for _,image in pairs(corners) do
  100.             image.ZIndex = c
  101.         end
  102.         white.ZIndex = c
  103.         white2.ZIndex = c
  104.         white3.ZIndex = c
  105.     end
  106.     roundcontrol.setRoundSize(25)
  107.     roundcontrol.setColor(color or gui:color(255,255,255))
  108.     return {Frame=f,Functions=roundcontrol}
  109. end
  110.  
  111. function gui:TextLabel()
  112.     local f = Instance.new("TextLabel")
  113.     f.Size = pixels(0,0)
  114.     f.FontSize = "Size18"
  115.     f.Font = "SourceSans"
  116.     f.Text = ""
  117.     f.TextColor3 = color(255,255,255)
  118.     f.BorderSizePixel = 0
  119.     return f
  120. end
  121.  
  122. function gui:ImageLabel(i)
  123.     local f = Instance.new("ImageLabel")
  124.     f.Size = pixels(0,0)
  125.     f.Image = i
  126.     f.BackgroundTransparency = 1
  127.     f.BorderSizePixel = 0
  128.     return f
  129. end
  130.  
  131. function gui:TextButton(click)
  132.     local f = Instance.new("TextButton")
  133.     f.Size = pixels(0,0)
  134.     f.FontSize = "Size18"
  135.     f.Font = "SourceSans"
  136.     f.Text = ""
  137.  
  138.     f.TextColor3 = color(255,255,255)
  139.     f.BorderSizePixel = 0
  140.     if click then
  141.         f.MouseButton1Click:connect(click)
  142.     end
  143.     return f
  144. end
  145.  
  146. function gui:TextBox(change)
  147.     local f = Instance.new("TextBox")
  148.     f.Size = pixels(0,0)
  149.     f.FontSize = "Size18"
  150.     f.Font = "SourceSans"
  151.     f.Text = ""
  152.  
  153.     f.TextColor3 = color(255,255,255)
  154.     f.BorderSizePixel = 0
  155.     if change then
  156.         f.Changed:connect(function(property)
  157.             if property == "Text" then
  158.                 change(f.Text)
  159.             end
  160.         end)
  161.     end
  162.     return f
  163. end
  164.  
  165. function gui:Shadow(e)
  166.     local f = gui:Frame()
  167.     f[recolor] = color(0,0,0)
  168.     f.Position = pixels(3,3)
  169.     f.Size = percent(100,100)
  170.     f.BackgroundTransparency = 50/100
  171.     if e then
  172.         e.ZIndex = e.ZIndex + 1
  173.         f.Parent = e
  174.     end
  175.     return f
  176. end
  177.  
  178. gui.Help = {}
  179.  
  180. gui.Help.new = function(...)
  181.     local t = {...} -- [action [, yoffset [, parent [, text] ] ] ]
  182.     local fields = {}
  183.     if t[2] then
  184.         fields.y = t[2]
  185.     end
  186.     if t[4] then
  187.         fields.text = t[4]
  188.     end
  189.     if t[3] then
  190.         fields.parent = t[3]
  191.     end
  192.     if t[1] then
  193.         fields.action = t[1]
  194.         if fields.action == "text" then
  195.             local l = gui:TextLabel()
  196.             l.TextXAlignment = "Left"
  197.             l.TextYAlignment = "Top"
  198.             l.TextColor3 = gui:color(255,255,255)
  199.             l.Parent = fields.parent -- or nil
  200.             l.Text = fields.text or ""
  201.             l.Position = gui:pixels(0,fields.y or 0)
  202.             return l
  203.         end
  204.         if fields.action == "title" then
  205.             local l = gui:TextLabel()
  206.             l.TextXAlignment = "Left"
  207.             l.TextYAlignment = "Top"
  208.             l.FontSize = "Size42"
  209.             l.TextColor3 = gui:color(255,255,255)
  210.             l.Parent = fields.parent -- or nil
  211.             l.Text = fields.text or ""
  212.             l.Position = gui:pixels(0,fields.y or 0)
  213.             return l
  214.         end
  215.         if fields.action == "separator" then
  216.             local l = gui:Frame()
  217.             l.Parent = fields.parent -- or nil
  218.             l.Size = gui:scale(1,0) + gui:pixels(-8,2)
  219.             l.BackgroundTransparency = 0.5
  220.             l.Position = gui:pixels(4,fields.y or 0)
  221.             return l
  222.         end
  223.     end
  224. end
  225.  
  226. return gui
Advertisement
Add Comment
Please, Sign In to add comment