Advertisement
Alakazard12

Register

Aug 2nd, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 49.45 KB | None | 0 0
  1. os.loadAPI("bapi")
  2. local mag = peripheral.wrap("bottom")
  3.  
  4.  
  5. -- Nova GUI API lightweight edition. By alakazard12
  6. -- Feel free to use this as long as you give me credit, but there's no documentation yet
  7.  
  8. local LGW, LGH = term.getSize()
  9.  
  10. local VColors = {}
  11. local VClasses = {
  12.     ["TextButton"] = true;
  13.     ["TextLabel"] = true;
  14.     ["TextBox"] = true;
  15.     ["ImageButton"] = true;
  16.     ["ImageLabel"] = true;
  17. }
  18.  
  19. for _,Color in pairs(colors) do
  20.     if type(Color) == "number" then
  21.         VColors[Color] = true
  22.     end
  23. end
  24.  
  25. local function Round(Number)
  26.     return math.floor(Number + 0.5)
  27. end
  28.  
  29. local Check
  30. function Check(Object, BG, PX, PY, ChangeP)
  31.     if Object.Visible == true then
  32.         if Object.Class == "TextButton" or Object.Class == "TextBox" or Object.Class == "TextLabel" or Object.Class == "ImageButton" or Object.Class == "ImageLabel" then
  33.             -- if ChangeP ~= true then
  34.                 PX = PX + Object.Position[1] - 1
  35.                 PY = PY + Object.Position[2] - 1
  36.             -- end
  37.             if Object.ShowBackground == true then
  38.                 BG = Object.BackgroundColor
  39.             end
  40.             if Object.Class == "TextBox" and Object.Focused == true then
  41.                 BG = Object.ActiveTextColor
  42.             end
  43.             term.setBackgroundColor(BG)
  44.             for Y = 1, Object.Size[2] do
  45.                 term.setCursorPos(PX, PY + Y - 1)
  46.                 term.write(string.rep(" ", Object.Size[1]))
  47.             end
  48.  
  49.             if Object.Class == "ImageButton" or Object.Class == "ImageLabel" and Object.Image then
  50.                 paintutils.drawImage(Object.Image, PX, PY)
  51.             end
  52.  
  53.             if Object.Class == "TextButton" or Object.Class == "TextBox" or Object.Class == "TextLabel" then
  54.                 if Object.ShowText == true then
  55.                     term.setTextColor(Object.TextColor)
  56.  
  57.                     local Text = Object.Text
  58.                     if Object.TextChar then
  59.                         Text = string.rep(Object.TextChar, #Text)
  60.                     end
  61.  
  62.                     if Object.Focused == true then
  63.                         Text = Text .. " "
  64.                     end
  65.  
  66.                     if Object.MultiLine == true then
  67.                         local LastP = 1
  68.                         local LastS
  69.                         local Lines = {}
  70.                         local DidBreak = false
  71.                         local RPassed = false
  72.                         local ROnLine = false
  73.                         local ROnNum
  74.                         local RLine
  75.                         for On = 1, #Text do
  76.                             if Text:sub(On, On) == " " then
  77.                                 LastS = On
  78.                             end
  79.  
  80.                             if On - LastP + 2 > Object.Size[1] then
  81.                                 if #Lines == Object.Size[2] then
  82.                                     break
  83.                                 end
  84.  
  85.                                 if LastS then
  86.                                     table.insert(Lines, Text:sub(LastP, LastS))
  87.                                     LastP = LastS + 1
  88.                                 else
  89.                                     table.insert(Lines, Text:sub(LastP, On))
  90.                                     LastP = On + 1
  91.                                 end
  92.  
  93.                                 LastS = nil
  94.  
  95.                                 if #Lines == Object.Size[2] then
  96.                                     if Object.Focused == false then
  97.                                         DidBreak = true
  98.                                         break
  99.                                     else
  100.                                         table.remove(Lines, 1)
  101.                                     end
  102.                                 end
  103.                             end
  104.                         end
  105.  
  106.                         if DidBreak == false then
  107.                             table.insert(Lines, Text:sub(LastP))
  108.                         elseif Object.Focused == true then
  109.                             table.remove(Lines, 1)
  110.                             table.insert(Lines, Text:sub(LastP))
  111.                         end
  112.  
  113.                         local TextCount = 0
  114.  
  115.                         for _,Line in pairs(Lines) do
  116.                             local XA = 0
  117.                             local YA = 0
  118.  
  119.                             if Object.TextXAlignment == 0 then
  120.                                 XA = PX
  121.                             elseif Object.TextXAlignment == 1 then
  122.                                 XA = PX + Round((Object.Size[1] - #Line) / 2)
  123.                             else
  124.                                 XA = PX + Round(Object.Size[1] - #Line)
  125.                             end
  126.  
  127.                             if Object.TextYAlignment == 0 then
  128.                                 YA = PY + _ - 1
  129.                             elseif Object.TextYAlignment == 1 then
  130.                                 YA = PY + Round((Object.Size[2] - #Lines) / 2) + _ - 1
  131.                             else
  132.                                 YA = PY + Round(Object.Size[2] - #Lines) + _ - 1
  133.                             end
  134.  
  135.                             term.setCursorPos(XA, YA)
  136.                             term.write(Line)
  137.                         end
  138.                     else
  139.                         if #Text > Object.Size[1] then
  140.                             if Object.Focused == false then
  141.                                 Text = string.sub(Text, 1, Object.Size[1])
  142.                             -- elseif Object.RTextPos then
  143.                             -- Text = string.sub(Text, Object.RTextPos, Object.RTextPos + Object.Size[1] - 1)
  144.                             else
  145.                                 Text = string.sub(Text, #Text - Object.Size[1] + 1, #Text)
  146.                             end
  147.                         end
  148.  
  149.                         local XA = 0
  150.                         local YA = 0
  151.  
  152.                         if Object.TextXAlignment == 0 then
  153.                             XA = PX
  154.                         elseif Object.TextXAlignment == 1 then
  155.                             XA = PX + Round((Object.Size[1] - #Text) / 2)
  156.                         else
  157.                             XA = PX + Round(Object.Size[1] - #Text)
  158.                         end
  159.  
  160.                         if Object.TextYAlignment == 0 then
  161.                             YA = PY
  162.                         elseif Object.TextYAlignment == 1 then
  163.                             YA = PY + Round((Object.Size[2] - 1) / 2)
  164.                         else
  165.                             YA = PY + Round(Object.Size[2] - 1)
  166.                         end
  167.  
  168.                         term.setCursorPos(XA, YA)
  169.                         term.write(Text)
  170.                     end
  171.                     -- if Object.RTextPos == nil then
  172.                         Object.TextPos = {term.getCursorPos()}
  173.                         Object.TextPos[1] = Object.TextPos[1] - 1
  174.                     -- end
  175.                 end
  176.             end
  177.  
  178.             for _,Obj in pairs(Object.Children) do
  179.                 Check(Obj, BG, PX, PY)
  180.             end
  181.         end
  182.     end
  183. end
  184.  
  185. local function SortListen(Tbl)
  186.     local Clone = {}
  187.     for _,Item in pairs(Tbl) do
  188.         Clone[_] = Item
  189.     end
  190.     table.sort(Clone, function(A, B)
  191.         return A.ZIndex > B.ZIndex
  192.     end)
  193.     return Clone
  194. end
  195.  
  196. local function NewClass(Par, Class, Main)
  197.     if type(Class) ~= "string" then
  198.         error("bad argument #1: string expected, got " .. type(Class), 2)
  199.     end
  200.     if not VClasses[Class] then
  201.         error("Invalid class name.", 2)
  202.     end
  203.  
  204.     local PublicTable = {}
  205.     local LocalTable = {}
  206.  
  207.     LocalTable.Parent = Par
  208.     LocalTable.Class = Class
  209.  
  210.     function PublicTable:ClearChildren()
  211.         LocalTable.Children = {}
  212.     end
  213.  
  214.     if Class == "ImageButton" or Class == "ImageLabel" then
  215.         LocalTable.Size = {2, 2}
  216.         LocalTable.Position = {1, 1}
  217.         LocalTable.Visible = true
  218.         LocalTable.Active = true
  219.         LocalTable.Children = {}
  220.         LocalTable.ZIndex = 0
  221.         LocalTable.ShowBackground = true
  222.  
  223.         function PublicTable:Size(X, Y)
  224.             if type(X) ~= "number" then
  225.                 error("bad argument #1: number expected, got " .. type(X), 2)
  226.             end
  227.             if type(Y) ~= "number" then
  228.                 error("bad argument #2: number expected, got " .. type(Y), 2)
  229.             end
  230.  
  231.             LocalTable.Size = {X, Y}
  232.         end
  233.  
  234.         function PublicTable:Image(Image)
  235.             if type(Image) ~= "table" then
  236.                 error("bad argument #1: table expected, got " .. type(Image), 2)
  237.             end
  238.  
  239.             LocalTable.Image = Image
  240.         end
  241.  
  242.         function PublicTable:GetSize()
  243.             return unpack(LocalTable.Size)
  244.         end
  245.  
  246.         function PublicTable:ShowBackground(Bool)
  247.             if type(Bool) ~= "boolean" then
  248.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  249.             end
  250.             LocalTable.ShowBackground = Bool
  251.         end
  252.  
  253.         function PublicTable:GetShowBackground()
  254.             return LocalTable.ShowBackground
  255.         end
  256.  
  257.         function PublicTable:ZIndex(Number)
  258.             if type(Number) ~= "number" then
  259.                 error("bad argument #1: number expected, got " .. type(Number), 2)
  260.             end
  261.             LocalTable.ZIndex = Number
  262.             table.sort(Par.Children, function(A, B)
  263.                 return A.ZIndex < B.ZIndex
  264.             end)
  265.         end
  266.  
  267.         function PublicTable:GetZIndex()
  268.             return LocalTable.ZIndex
  269.         end
  270.  
  271.         function PublicTable:Position(X, Y)
  272.             if type(X) ~= "number" then
  273.                 error("bad argument #1: number expected, got " .. type(X), 2)
  274.             end
  275.             if type(Y) ~= "number" then
  276.                 error("bad argument #2: number expected, got " .. type(Y), 2)
  277.             end
  278.             LocalTable.Position = {X, Y}
  279.         end
  280.  
  281.         function PublicTable:GetPosition()
  282.             return unpack(LocalTable.Position)
  283.         end
  284.  
  285.         function PublicTable:Visible(Bool)
  286.             if type(Bool) ~= "boolean" then
  287.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  288.             end
  289.             LocalTable.Visible = Bool
  290.         end
  291.  
  292.         function PublicTable:GetVisible()
  293.             return LocalTable.Visible
  294.         end
  295.  
  296.         function PublicTable:Active(Bool)
  297.             if type(Bool) ~= "boolean" then
  298.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  299.             end
  300.             LocalTable.Active = Bool
  301.         end
  302.  
  303.         function PublicTable:GetActive()
  304.             return LocalTable.Active
  305.         end
  306.  
  307.         function PublicTable:BackgroundColor(Color)
  308.             if type(Color) ~= "number" then
  309.                 error("bad argument #1: number expected, got " .. type(Color), 2)
  310.             end
  311.             if VColors[Color] ~= true then
  312.                 error("Invalid color.", 2)
  313.             end
  314.             LocalTable.BackgroundColor = Color
  315.         end
  316.  
  317.         function PublicTable:GetBackgroundColor()
  318.             return LocalTable.BackgroundColor
  319.         end
  320.  
  321.         if Class == "ImageButton" then
  322.             function PublicTable:Button1Click(Function)
  323.                 if Function == nil then
  324.                     LocalTable.Button1Click = nil
  325.                 else
  326.                     if type(Function) ~= "function" then
  327.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  328.                     end
  329.                     LocalTable.Button1Click = Function
  330.                 end
  331.             end
  332.  
  333.             function PublicTable:GetButton1Click()
  334.                 return LocalTable.Button1Click
  335.             end
  336.  
  337.             function PublicTable:MouseScroll(Function)
  338.                 if Function == nil then
  339.                     LocalTable.MouseScroll = nil
  340.                 else
  341.                     if type(Function) ~= "function" then
  342.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  343.                     end
  344.                     LocalTable.MouseScroll = Function
  345.                 end
  346.             end
  347.  
  348.             function PublicTable:GetMouseScroll()
  349.                 return LocalTable.MouseScroll
  350.             end
  351.  
  352.             function PublicTable:MouseDrag1(Function)
  353.                 if Function == nil then
  354.                     LocalTable.MouseDrag1 = nil
  355.                 else
  356.                     if type(Function) ~= "function" then
  357.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  358.                     end
  359.                     LocalTable.MouseDrag1 = Function
  360.                 end
  361.             end
  362.  
  363.             function PublicTable:GetMouseDrag1()
  364.                 return LocalTable.MouseDrag1
  365.             end
  366.  
  367.             function PublicTable:MouseDrag2(Function)
  368.                 if Function == nil then
  369.                     LocalTable.MouseDrag2 = nil
  370.                 else
  371.                     if type(Function) ~= "function" then
  372.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  373.                     end
  374.                     LocalTable.MouseDrag2 = Function
  375.                 end
  376.             end
  377.  
  378.             function PublicTable:GetMouseDrag2()
  379.                 return LocalTable.MouseDrag2
  380.             end
  381.  
  382.             function PublicTable:MouseDrag3(Function)
  383.                 if Function == nil then
  384.                     LocalTable.MouseDrag3 = nil
  385.                 else
  386.                     if type(Function) ~= "function" then
  387.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  388.                     end
  389.                     LocalTable.MouseDrag3 = Function
  390.                 end
  391.             end
  392.  
  393.             function PublicTable:GetMouseDrag3()
  394.                 return LocalTable.MouseDrag3
  395.             end
  396.  
  397.             function PublicTable:Button2Click(Function)
  398.                 if Function == nil then
  399.                     LocalTable.Button2Click = nil
  400.                 else
  401.                     if type(Function) ~= "function" then
  402.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  403.                     end
  404.                     LocalTable.Button2Click = Function
  405.                 end
  406.             end
  407.  
  408.             function PublicTable:GetButton2Click()
  409.                 return LocalTable.Button2Click
  410.             end
  411.  
  412.             function PublicTable:Button3Click(Function)
  413.                 if Function == nil then
  414.                     LocalTable.Button3Click = nil
  415.                 else
  416.                     if type(Function) ~= "function" then
  417.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  418.                     end
  419.                     LocalTable.Button3Click = Function
  420.                 end
  421.             end
  422.  
  423.             function PublicTable:GetButton3Click()
  424.                 return LocalTable.Button3Click
  425.             end
  426.         end
  427.  
  428.         function PublicTable:New(Class)
  429.             return NewClass(LocalTable, Class, Main)
  430.         end
  431.  
  432.         function PublicTable:Draw()
  433.             local BG = Main.BackgroundColor
  434.             local FoundBG = false
  435.             local PX, PY = 1, 1
  436.  
  437.             local On = LocalTable.Parent
  438.             while On ~= Main do
  439.                 PX = PX + On.Position[1] - 1
  440.                 PY = PY + On.Position[2] - 1
  441.  
  442.                 if On.ShowBackground and FoundBG == false then
  443.                     BG = On.BackgroundColor
  444.                     FoundBG = true
  445.                 end
  446.                 On = On.Parent
  447.             end
  448.  
  449.             Check(LocalTable, BG, PX, PY)
  450.         end
  451.     elseif Class == "TextButton" or Class == "TextLabel" or Class == "TextBox" then
  452.         LocalTable.Size = {2, 2}
  453.         LocalTable.Position = {1, 1}
  454.         LocalTable.RawText = ""
  455.         LocalTable.Text = ""
  456.         LocalTable.BackgroundColor = colors.cyan
  457.         LocalTable.TextColor = colors.white
  458.         LocalTable.Visible = true
  459.         LocalTable.Active = true
  460.         LocalTable.Children = {}
  461.         LocalTable.ZIndex = 0
  462.         LocalTable.ShowBackground = true
  463.         LocalTable.ShowText = true
  464.         LocalTable.TextXAlignment = 1
  465.         LocalTable.TextYAlignment = 1
  466.         LocalTable.MultiLine = false
  467.  
  468.         if Class == "TextBox" then
  469.             LocalTable.ActiveTextColor = colors.blue
  470.             LocalTable.Overlap = false
  471.             LocalTable.Focused = false
  472.             LocalTable.ClearTextOnFocus = false
  473.             LocalTable.RTextPos = 8
  474.         end
  475.  
  476.         function PublicTable:TextXAlignment(Num)
  477.             if type(Num) == "string" then
  478.                 if Num:lower() == "left" then
  479.                     Num = 0
  480.                 elseif Num:lower() == "center" then
  481.                     Num = 1
  482.                 elseif Num:lower() == "right" then
  483.                     Num = 2
  484.                 else
  485.                     error("bad argument #1: '" .. Num .. "' is not a valid string", 2)
  486.                 end
  487.             end
  488.  
  489.             if type(Num) ~= "number" then
  490.                 error("bad argument #1: number expected, got " .. type(X), 2)
  491.             end
  492.             LocalTable.TextXAlignment = Num
  493.         end
  494.  
  495.         function PublicTable:GetTextXAlignment()
  496.             return LocalTable.TextXAlignment
  497.         end
  498.  
  499.         function PublicTable:TextYAlignment(Num)
  500.             if type(Num) == "string" then
  501.                 if Num:lower() == "top" then
  502.                     Num = 0
  503.                 elseif Num:lower() == "center" then
  504.                     Num = 1
  505.                 elseif Num:lower() == "bottom" then
  506.                     Num = 2
  507.                 else
  508.                     error("bad argument #1: '" .. Num .. "' is not a valid string", 2)
  509.                 end
  510.             end
  511.  
  512.             if type(Num) ~= "number" then
  513.                 error("bad argument #1: number expected, got " .. type(X), 2)
  514.             end
  515.             LocalTable.TextYAlignment = Num
  516.         end
  517.  
  518.         function PublicTable:GetTextYAlignment()
  519.             return LocalTable.TextYAlignment
  520.         end
  521.  
  522.         function PublicTable:Size(X, Y)
  523.             if type(X) ~= "number" then
  524.                 error("bad argument #1: number expected, got " .. type(X), 2)
  525.             end
  526.             if type(Y) ~= "number" then
  527.                 error("bad argument #2: number expected, got " .. type(Y), 2)
  528.             end
  529.  
  530.             LocalTable.Size = {X, Y}
  531.         end
  532.  
  533.         function PublicTable:GetSize()
  534.             return unpack(LocalTable.Size)
  535.         end
  536.  
  537.         function PublicTable:ShowBackground(Bool)
  538.             if type(Bool) ~= "boolean" then
  539.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  540.             end
  541.             LocalTable.ShowBackground = Bool
  542.         end
  543.  
  544.         function PublicTable:GetShowBackground()
  545.             return LocalTable.ShowBackground
  546.         end
  547.  
  548.         function PublicTable:ShowText(Bool)
  549.             if type(Bool) ~= "boolean" then
  550.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  551.             end
  552.             LocalTable.ShowText = Bool
  553.         end
  554.  
  555.         function PublicTable:GetShowText()
  556.             return LocalTable.ShowText
  557.         end
  558.  
  559.         function PublicTable:MultiLine(Bool)
  560.             if type(Bool) ~= "boolean" then
  561.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  562.             end
  563.             LocalTable.MultiLine = Bool
  564.         end
  565.  
  566.         function PublicTable:GetMultiLine()
  567.             return LocalTable.MultiLine
  568.         end
  569.  
  570.         function PublicTable:ZIndex(Number)
  571.             if type(Number) ~= "number" then
  572.                 error("bad argument #1: number expected, got " .. type(Number), 2)
  573.             end
  574.             LocalTable.ZIndex = Number
  575.             table.sort(Par.Children, function(A, B)
  576.                 return A.ZIndex < B.ZIndex
  577.             end)
  578.         end
  579.  
  580.         function PublicTable:GetZIndex()
  581.             return LocalTable.ZIndex
  582.         end
  583.  
  584.         function PublicTable:Position(X, Y)
  585.             if type(X) ~= "number" then
  586.                 error("bad argument #1: number expected, got " .. type(X), 2)
  587.             end
  588.             if type(Y) ~= "number" then
  589.                 error("bad argument #2: number expected, got " .. type(Y), 2)
  590.             end
  591.             LocalTable.Position = {X, Y}
  592.         end
  593.  
  594.         function PublicTable:GetPosition()
  595.             return unpack(LocalTable.Position)
  596.         end
  597.  
  598.         function PublicTable:Visible(Bool)
  599.             if type(Bool) ~= "boolean" then
  600.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  601.             end
  602.             LocalTable.Visible = Bool
  603.         end
  604.  
  605.         function PublicTable:GetVisible()
  606.             return LocalTable.Visible
  607.         end
  608.  
  609.         function PublicTable:Active(Bool)
  610.             if type(Bool) ~= "boolean" then
  611.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  612.             end
  613.             LocalTable.Active = Bool
  614.         end
  615.  
  616.         function PublicTable:GetActive()
  617.             return LocalTable.Active
  618.         end
  619.  
  620.         function PublicTable:Text(Text)
  621.             if Text == nil then
  622.                 Text = ""
  623.             end
  624.             if type(Text) ~= "string" then
  625.                 error("bad argument #1: string expected, got " .. type(Text), 2)
  626.             end
  627.             LocalTable.Text = Text
  628.         end
  629.  
  630.         function PublicTable:GetText()
  631.             return LocalTable.Text
  632.         end
  633.  
  634.         function PublicTable:BackgroundColor(Color)
  635.             if type(Color) ~= "number" then
  636.                 error("bad argument #1: number expected, got " .. type(Color), 2)
  637.             end
  638.             if VColors[Color] ~= true then
  639.                 error("Invalid color.", 2)
  640.             end
  641.             LocalTable.BackgroundColor = Color
  642.         end
  643.  
  644.         function PublicTable:GetBackgroundColor()
  645.             return LocalTable.BackgroundColor
  646.         end
  647.  
  648.         function PublicTable:TextColor(Color)
  649.             if type(Color) ~= "number" then
  650.                 error("bad argument #1: number expected, got " .. type(Color), 2)
  651.             end
  652.             if VColors[Color] ~= true then
  653.                 error("Invalid color.", 2)
  654.             end
  655.             LocalTable.TextColor = Color
  656.         end
  657.  
  658.         function PublicTable:GetTextColor()
  659.             return LocalTable.TextColor
  660.         end
  661.  
  662.         function PublicTable:MouseScroll(Function)
  663.                 if Function == nil then
  664.                     LocalTable.MouseScroll = nil
  665.                 else
  666.                 if type(Function) ~= "function" then
  667.                     error("bad argument #1: function expected, got " .. type(Function), 2)
  668.                 end
  669.                 LocalTable.MouseScroll = Function
  670.             end
  671.         end
  672.  
  673.         if Class == "TextButton" then
  674.             function PublicTable:Button1Click(Function)
  675.                 if Function == nil then
  676.                     LocalTable.Button1Click = nil
  677.                 else
  678.                     if type(Function) ~= "function" then
  679.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  680.                     end
  681.                     LocalTable.Button1Click = Function
  682.                 end
  683.             end
  684.  
  685.             function PublicTable:GetButton1Click()
  686.                 return LocalTable.Button1Click
  687.             end
  688.  
  689.             function PublicTable:GetMouseScroll()
  690.                 return LocalTable.MouseScroll
  691.             end
  692.  
  693.             function PublicTable:MouseDrag1(Function)
  694.                 if Function == nil then
  695.                     LocalTable.MouseDrag1 = nil
  696.                 else
  697.                     if type(Function) ~= "function" then
  698.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  699.                     end
  700.                     LocalTable.MouseDrag1 = Function
  701.                 end
  702.             end
  703.  
  704.             function PublicTable:GetMouseDrag1()
  705.                 return LocalTable.MouseDrag1
  706.             end
  707.  
  708.             function PublicTable:MouseDrag2(Function)
  709.                 if Function == nil then
  710.                     LocalTable.MouseDrag2 = nil
  711.                 else
  712.                     if type(Function) ~= "function" then
  713.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  714.                     end
  715.                     LocalTable.MouseDrag2 = Function
  716.                 end
  717.             end
  718.  
  719.             function PublicTable:GetMouseDrag2()
  720.                 return LocalTable.MouseDrag2
  721.             end
  722.  
  723.             function PublicTable:MouseDrag3(Function)
  724.                 if Function == nil then
  725.                     LocalTable.MouseDrag3 = nil
  726.                 else
  727.                     if type(Function) ~= "function" then
  728.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  729.                     end
  730.                     LocalTable.MouseDrag3 = Function
  731.                 end
  732.             end
  733.  
  734.             function PublicTable:GetMouseDrag3()
  735.                 return LocalTable.MouseDrag3
  736.             end
  737.  
  738.             function PublicTable:Button2Click(Function)
  739.                 if Function == nil then
  740.                     LocalTable.Button2Click = nil
  741.                 else
  742.                     if type(Function) ~= "function" then
  743.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  744.                     end
  745.                     LocalTable.Button2Click = Function
  746.                 end
  747.             end
  748.  
  749.             function PublicTable:GetButton2Click()
  750.                 return LocalTable.Button2Click
  751.             end
  752.  
  753.             function PublicTable:Button3Click(Function)
  754.                 if Function == nil then
  755.                     LocalTable.Button3Click = nil
  756.                 else
  757.                     if type(Function) ~= "function" then
  758.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  759.                     end
  760.                     LocalTable.Button3Click = Function
  761.                 end
  762.             end
  763.  
  764.             function PublicTable:GetButton3Click()
  765.                 return LocalTable.Button3Click
  766.             end
  767.         elseif Class == "TextBox" then
  768.             function PublicTable:ActiveTextColor(Color)
  769.                 if type(Color) ~= "number" then
  770.                     error("bad argument #1: number expected, got " .. type(Color), 2)
  771.                 end
  772.                 if VColors[Color] ~= true then
  773.                     error("Invalid color.", 2)
  774.                 end
  775.                 LocalTable.ActiveTextColor = Color
  776.             end
  777.  
  778.             function PublicTable:EnterPress(Function)
  779.                 if Function == nil then
  780.                     LocalTable.EnterPress = nil
  781.                 else
  782.                     if type(Function) ~= "function" then
  783.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  784.                     end
  785.                     LocalTable.EnterPress = Function
  786.                 end
  787.             end
  788.  
  789.             function PublicTable:GetEnterPress()
  790.                 return LocalTable.EnterPress
  791.             end
  792.  
  793.             function PublicTable:Overlap(Bool)
  794.                 if type(Bool) ~= "boolean" then
  795.                     error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  796.                 end
  797.                 LocalTable.Overlap = Bool
  798.             end
  799.  
  800.             function PublicTable:GetOverlap()
  801.                 return LocalTable.Overlap
  802.             end
  803.  
  804.             function PublicTable:ClearTextOnFocus(Bool)
  805.                 if type(Bool) ~= "boolean" then
  806.                     error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  807.                 end
  808.                 LocalTable.ClearTextOnFocus = Bool
  809.             end
  810.  
  811.             function PublicTable:GetClearTextOnFocus()
  812.                 return LocalTable.ClearTextOnFocus
  813.             end
  814.  
  815.             function PublicTable:Focus()
  816.                 Main.MakeFocus = LocalTable
  817.                 os.queueEvent("")
  818.             end
  819.  
  820.             function PublicTable:StopFocus()
  821.                 Main.StopFocus = true
  822.                 os.queueEvent("")
  823.             end
  824.  
  825.             function PublicTable:TextChar(Char)
  826.                 if Char == nil then
  827.                     LocalTable.TextChar = nil
  828.                 else
  829.                     if type(Char) ~= "string" then
  830.                         error("bad argument #1: string expected, got " .. type(Char), 2)
  831.                     end
  832.                     LocalTable.TextChar = Char
  833.                 end
  834.             end
  835.  
  836.             function PublicTable:GetTextChar()
  837.                 return LocalTable.TextChar
  838.             end
  839.         end
  840.  
  841.         function PublicTable:New(Class)
  842.             return NewClass(LocalTable, Class, Main)
  843.         end
  844.  
  845.         function PublicTable:Draw()
  846.             local BG = Main.BackgroundColor
  847.             local FoundBG = false
  848.             local PX, PY = 1, 1
  849.  
  850.             local On = LocalTable.Parent
  851.             while On ~= Main do
  852.                 PX = PX + On.Position[1] - 1
  853.                 PY = PY + On.Position[2] - 1
  854.  
  855.                 if On.ShowBackground and FoundBG == false then
  856.                     BG = On.BackgroundColor
  857.                     FoundBG = true
  858.                 end
  859.                 On = On.Parent
  860.             end
  861.  
  862.             Check(LocalTable, BG, PX, PY , true)
  863.         end
  864.     end
  865.  
  866.     LocalTable.Pub = PublicTable
  867.  
  868.     table.insert(Par.Children, LocalTable)
  869.  
  870.     function PublicTable:Destroy()
  871.         for _,Object in pairs(Par.Children) do
  872.             if LocalTable == Object then
  873.                 table.remove(Par.Children, _)
  874.                 break
  875.             end
  876.         end
  877.         LocalTable = nil
  878.         PublicTable = nil
  879.     end
  880.  
  881.     return PublicTable
  882. end
  883.  
  884. local function NewUI()
  885.     local LocalTable = {}
  886.     local PublicTable = {}
  887.  
  888.     LocalTable.BackgroundColor = colors.red
  889.     LocalTable.Visible = true
  890.     LocalTable.Active = true
  891.     LocalTable.Children = {}
  892.     LocalTable.Listening = false
  893.  
  894.     function PublicTable:BackgroundColor(Color)
  895.         if type(Color) ~= "number" then
  896.             error("bad argument #1: number expected, got " .. type(Color), 2)
  897.         end
  898.         if not VColors[Color] then
  899.             error("Invalid color.", 2)
  900.         end
  901.         LocalTable.BackgroundColor = Color
  902.     end
  903.  
  904.     function PublicTable:New(Class)
  905.         return NewClass(LocalTable, Class, LocalTable)
  906.     end
  907.  
  908.     function PublicTable:ClearChildren()
  909.         LocalTable.Children = {}
  910.     end
  911.  
  912.     function PublicTable:ErrorHandle(Function)
  913.         if type(Function) ~= "function" and Function ~= nil then
  914.             error("bad argument #1: function expected, got " .. type(Function), 2)
  915.         end
  916.  
  917.         LocalTable.ErrorHandle = Function
  918.     end
  919.  
  920.     function PublicTable:Output(Function)
  921.         if type(Function) ~= "function" and Function ~= nil then
  922.             error("bad argument #1: function expected, got " .. type(Function), 2)
  923.         end
  924.  
  925.         LocalTable.Output = Function
  926.     end
  927.  
  928.     function PublicTable:Listen()
  929.         LocalTable.Listening = true
  930.         local ActiveBox
  931.         local LastClick1
  932.         local LastClick2
  933.         local LastClick3
  934.  
  935.         while LocalTable.Listening == true do
  936.             local Event, P1, P2, P3, P4, P5 = os.pullEventRaw()
  937.             if LocalTable.Listening == false then
  938.                 break
  939.             end
  940.  
  941.             if LocalTable.MakeFocus then
  942.                 if ActiveBox then
  943.                     ActiveBox.Focused = false
  944.                     ActiveBox.StopFocus = nil
  945.                     term.setCursorBlink(false)
  946.                     if ActiveBox.Overlap == true then
  947.                         ActiveBox.Pub:Draw()
  948.                     else
  949.                         PublicTable:Draw()
  950.                     end
  951.                 end
  952.                 ActiveBox = LocalTable.MakeFocus
  953.                 LocalTable.MakeFocus = nil
  954.                 ActiveBox.Focused = true
  955.                 if ActiveBox.Overlap == true then
  956.                     ActiveBox.Pub:Draw()
  957.                 else
  958.                     PublicTable:Draw()
  959.                 end
  960.  
  961.                 term.setCursorBlink(true)
  962.                 term.setTextColor(ActiveBox.TextColor)
  963.                 term.setCursorPos(unpack(ActiveBox.TextPos))
  964.             end
  965.  
  966.             if ActiveBox and ActiveBox.StopFocus then
  967.                 ActiveBox.Focused = false
  968.                 ActiveBox.StopFocus = nil
  969.                 term.setCursorBlink(false)
  970.                 if ActiveBox.Overlap == true then
  971.                     ActiveBox.Pub:Draw()
  972.                 else
  973.                     PublicTable:Draw()
  974.                 end
  975.                 if ActiveBox.EnterPress then
  976.                     ActiveBox.EnterPress()
  977.                 end
  978.                 ActiveBox = nil
  979.             end
  980.  
  981.             if LocalTable.Output then
  982.                 if LocalTable.ErrorHandle then
  983.                     local Success, Err = pcall(LocalTable.Output, Event, P1, P2, P3, P4, P5)
  984.                     if not Success then
  985.                         LocalTable.ErrorHandle(Err)
  986.                     end
  987.                 else
  988.                     LocalTable.Output(Event, P1, P2, P3, P4, P5)
  989.                 end
  990.             end
  991.  
  992.             if Event == "char" then
  993.                 if ActiveBox then
  994.                     ActiveBox.Text = ActiveBox.Text .. P1
  995.                     if ActiveBox.Overlap == true then
  996.                         ActiveBox.Pub:Draw()
  997.                     else
  998.                         PublicTable:Draw()
  999.                     end
  1000.                     term.setTextColor(ActiveBox.TextColor)
  1001.  
  1002.                     term.setCursorPos(unpack(ActiveBox.TextPos))
  1003.                 end
  1004.             elseif Event == "key" then
  1005.                 if ActiveBox then
  1006.                     if P1 == 14 then
  1007.                         if #ActiveBox.Text > 0 then
  1008.                             ActiveBox.Text = string.sub(ActiveBox.Text, 1, #ActiveBox.Text - 1)
  1009.                             if ActiveBox.Overlap == true then
  1010.                                 ActiveBox.Pub:Draw()
  1011.                             else
  1012.                                 PublicTable:Draw()
  1013.                             end
  1014.                             term.setTextColor(ActiveBox.TextColor)
  1015.  
  1016.                             term.setCursorPos(unpack(ActiveBox.TextPos))
  1017.                         end
  1018.                     elseif P1 == 28 then
  1019.                         ActiveBox.Focused = false
  1020.                         term.setCursorBlink(false)
  1021.  
  1022.                         if ActiveBox.Overlap == true then
  1023.                             ActiveBox.Pub:Draw()
  1024.                         else
  1025.                             PublicTable:Draw()
  1026.                         end
  1027.  
  1028.                         if ActiveBox.EnterPress then
  1029.                             if LocalTable.ErrorHandle then
  1030.                                 local Success, Err = pcall(ActiveBox.EnterPress)
  1031.                                 if not Success then
  1032.                                     LocalTable.ErrorHandle(Err)
  1033.                                 end
  1034.                             else
  1035.                                 ActiveBox.EnterPress()
  1036.                             end
  1037.                         end
  1038.                         ActiveBox = nil
  1039.                     end
  1040.                 end
  1041.             elseif Event == "mouse_scroll" then
  1042.                 local PStop = false
  1043.                 local Check
  1044.                 function Check(Object, Par, PX, PY)
  1045.                     if Object.Active == true then
  1046.                         if PStop == true then return end
  1047.                         if Object.Class == "TextLabel" or Object.Class == "TextButton" or Object.Class == "ImageButton" then
  1048.                             if P2 >= Object.Position[1] + PX - 1 and P2 <= Object.Position[1] + Object.Size[1] + PX - 2 and P3 >= Object.Position[2] + PY - 1 and P3 <= Object.Position[2] + Object.Size[2] + PY - 2 then
  1049.                                 if Object.MouseScroll then
  1050.                                     if LocalTable.ErrorHandle then
  1051.                                         local Success, Err = pcall(Object.MouseScroll, P1)
  1052.                                         if not Success then
  1053.                                             LocalTable.ErrorHandle(Err)
  1054.                                         end
  1055.                                     else
  1056.                                         Object.MouseScroll(P1)
  1057.                                     end
  1058.                                     PStop = true
  1059.                                 end
  1060.                             end
  1061.                         end
  1062.  
  1063.                         for _,Object in pairs(SortListen(Object.Children)) do
  1064.                             Check(Object, Object, PX + Object.Position[1] - 1, PY + Object.Position[2] - 1)
  1065.                         end
  1066.                     end
  1067.                 end
  1068.  
  1069.                 for _,Object in pairs(SortListen(LocalTable.Children))  do
  1070.                     Check(Object, LocalTable, 1, 1)
  1071.                 end
  1072.             elseif Event == "mouse_drag" then
  1073.                 if P1 == 1 and LastClick1 then
  1074.                     if LastClick1.MouseDrag1 then
  1075.                         if LocalTable.ErrorHandle then
  1076.                             local Success, Err = pcall(LastClick1.MouseDrag1, P2, P3)
  1077.                             if not Success then
  1078.                                 LocalTable.ErrorHandle(Err)
  1079.                             end
  1080.                         else
  1081.                             LastClick1.MouseDrag1(P2, P3)
  1082.                         end
  1083.                     end
  1084.                 elseif P1 == 2 and LastClick2 then
  1085.                     if LastClick2.MouseDrag2 then
  1086.                         if LocalTable.ErrorHandle then
  1087.                             local Success, Err = pcall(Object.MouseDrag2, P2, P3)
  1088.                             if not Success then
  1089.                                 LocalTable.ErrorHandle(Err)
  1090.                             end
  1091.                         else
  1092.                             Object.MouseDrag2(P2, P3)
  1093.                         end
  1094.                     end
  1095.                 elseif P1 == 3 and LastClick3 then
  1096.                     if LastClick3.MouseDrag3 then
  1097.                         if LocalTable.ErrorHandle then
  1098.                             local Success, Err = pcall(Object.MouseDrag3, P2, P3)
  1099.                             if not Success then
  1100.                                 LocalTable.ErrorHandle(Err)
  1101.                             end
  1102.                         else
  1103.                             Object.MouseDrag3(P2, P3)
  1104.                         end
  1105.                     end
  1106.                 end
  1107.             elseif Event == "mouse_click" then
  1108.                 LastClick1 = nil
  1109.                 LastClick2 = nil
  1110.                 LastClick3 = nil
  1111.                 local PStop = false
  1112.                 local StopFocus = true
  1113.                 local Check
  1114.                 function Check(Object, Par, PX, PY)
  1115.                     if Object.Active == true then
  1116.                         if PStop == true then return end
  1117.                         if Object.Class == "TextButton" or Object.Class == "ImageButton" or Object.Class == "TextBox" then
  1118.                             if P2 >= Object.Position[1] + PX - 1 and P2 <= Object.Position[1] + Object.Size[1] + PX - 2 and P3 >= Object.Position[2] + PY - 1 and P3 <= Object.Position[2] + Object.Size[2] + PY - 2 then
  1119.                                 if ActiveBox and Object ~= ActiveBox then
  1120.                                     ActiveBox.Focused = false
  1121.                                     ActiveBox.StopFocus = nil
  1122.                                     term.setCursorBlink(false)
  1123.                                     if ActiveBox.Overlap == true then
  1124.                                         ActiveBox.Pub:Draw()
  1125.                                     else
  1126.                                         PublicTable:Draw()
  1127.                                     end
  1128.  
  1129.                                     if ActiveBox.EnterPress then
  1130.                                         if LocalTable.ErrorHandle then
  1131.                                             local Success, Err = pcall(ActiveBox.EnterPress)
  1132.                                             if not Success then
  1133.                                                 LocalTable.ErrorHandle(Err)
  1134.                                             end
  1135.                                         else
  1136.                                             ActiveBox.EnterPress()
  1137.                                         end
  1138.                                     end
  1139.                                     ActiveBox = nil
  1140.                                 end
  1141.                                 if P1 == 1 then
  1142.                                     LastClick1 = Object
  1143.                                     if (Object.Class == "TextButton" or Object.Class == "ImageButton") and Object.Button1Click then
  1144.                                         if LocalTable.ErrorHandle then
  1145.                                             local Success, Err = pcall(Object.Button1Click, P2, P3)
  1146.                                             if not Success then
  1147.                                                 LocalTable.ErrorHandle(Err)
  1148.                                             end
  1149.                                         else
  1150.                                             Object.Button1Click(P2, P3)
  1151.                                         end
  1152.                                     elseif Object.Class == "TextBox" then
  1153.                                         ActiveBox = Object
  1154.                                         Object.Focused = true
  1155.  
  1156.                                         if Object.ClearTextOnFocus == true then
  1157.                                             Object.Text = ""
  1158.                                         end
  1159.  
  1160.                                         Object.RawText = ""
  1161.                                         Object.RTextPos = 6
  1162.  
  1163.                                         if Object.Overlap == true then
  1164.                                             Object.Pub:Draw()
  1165.                                         else
  1166.                                             PublicTable:Draw()
  1167.                                         end
  1168.                                         term.setCursorBlink(true)
  1169.                                         term.setTextColor(ActiveBox.TextColor)
  1170.                                         term.setCursorPos(unpack(Object.TextPos))
  1171.                                     end
  1172.                                 elseif P1 == 2 then
  1173.                                     LastClick2 = Object
  1174.                                     if (Object.Class == "TextButton" or Object.Class == "ImageButton") and Object.Button2Click then
  1175.                                         if LocalTable.ErrorHandle then
  1176.                                             local Success, Err = pcall(Object.Button2Click, P2, P3)
  1177.                                             if not Success then
  1178.                                                 LocalTable.ErrorHandle(Err)
  1179.                                             end
  1180.                                         else
  1181.                                             Object.Button2Click(P2, P3)
  1182.                                         end
  1183.                                     end
  1184.                                 elseif P1 == 3 then
  1185.                                     LastClick3 = Object
  1186.                                     if (Object.Class == "TextButton" or Object.Class == "ImageButton") and Object.Button3Click then
  1187.                                         if LocalTable.ErrorHandle then
  1188.                                             local Success, Err = pcall(Object.Button3Click, P2, P3)
  1189.                                             if not Success then
  1190.                                                 LocalTable.ErrorHandle(Err)
  1191.                                             end
  1192.                                         else
  1193.                                             Object.Button3Click(P2, P3)
  1194.                                         end
  1195.                                     end
  1196.                                 end
  1197.  
  1198.                                 PStop = true
  1199.                             end
  1200.                         end
  1201.  
  1202.                         for _,Object2 in pairs(SortListen(Object.Children)) do
  1203.                             Check(Object2, Object, PX + Object.Position[1] - 1, PY + Object.Position[2] - 1)
  1204.                         end
  1205.                     end
  1206.                 end
  1207.  
  1208.                 for _,Object in pairs(SortListen(LocalTable.Children))  do
  1209.                     Check(Object, LocalTable, 1, 1)
  1210.                 end
  1211.             end
  1212.         end
  1213.     end
  1214.  
  1215.     function PublicTable:StopListen()
  1216.         LocalTable.Listening = false
  1217.     end
  1218.  
  1219.     function PublicTable:Draw()
  1220.         term.setBackgroundColor(LocalTable.BackgroundColor)
  1221.         term.clear()
  1222.  
  1223.         for _,Item in ipairs(LocalTable.Children) do
  1224.             Check(Item, LocalTable.BackgroundColor, 1, 1)
  1225.         end
  1226.     end
  1227.     return PublicTable
  1228. end
  1229.  
  1230. -- End of alakazard12's Nova GUI API
  1231.  
  1232. local IsConnected = bapi.connect()
  1233.  
  1234. local W, H = term.getSize()
  1235.  
  1236. local MainUI = NewUI()
  1237. MainUI:BackgroundColor(colors.white)
  1238.  
  1239. local Title = MainUI:New("TextLabel")
  1240. Title:Size(W, 1)
  1241. Title:Text("Register with YeuaBank")
  1242. Title:BackgroundColor(colors.gray)
  1243. Title:TextColor(colors.white)
  1244.  
  1245. local UserText = MainUI:New("TextLabel")
  1246. UserText:ShowBackground(false)
  1247. UserText:Text("Username:")
  1248. UserText:Size(9, 1)
  1249. UserText:TextColor(colors.black)
  1250. UserText:Position(math.floor(W/2 - 13), math.floor(H / 2 - 3))
  1251.  
  1252. local UserInput = MainUI:New("TextBox")
  1253. UserInput:BackgroundColor(colors.gray)
  1254. UserInput:TextColor(colors.white)
  1255. UserInput:ActiveTextColor(colors.lightGray)
  1256. UserInput:Size(16, 1)
  1257. UserInput:Position(math.floor(W/2 - 3), math.floor(H / 2 - 3))
  1258. UserInput:Overlap(true)
  1259. UserInput:TextXAlignment(0)
  1260.  
  1261. local PassText = MainUI:New("TextLabel")
  1262. PassText:ShowBackground(false)
  1263. PassText:Text("Password:")
  1264. PassText:Size(9, 1)
  1265. PassText:TextColor(colors.black)
  1266. PassText:Position(math.floor(W/2 - 13), math.floor(H / 2 - 1))
  1267.  
  1268. local PassInput = MainUI:New("TextBox")
  1269. PassInput:BackgroundColor(colors.gray)
  1270. PassInput:TextColor(colors.white)
  1271. PassInput:ActiveTextColor(colors.lightGray)
  1272. PassInput:Size(16, 1)
  1273. PassInput:Position(math.floor(W/2 - 3), math.floor(H / 2 - 1))
  1274. PassInput:TextChar("*")
  1275. PassInput:Overlap(true)
  1276. PassInput:TextXAlignment(0)
  1277.  
  1278. local Err = MainUI:New("TextLabel")
  1279. Err:ShowBackground(false)
  1280. Err:Text("")
  1281. Err:TextColor(colors.green)
  1282. Err:Size(W, 1)
  1283. Err:Position(0, H / 2 + 3)
  1284.  
  1285. local Submit = MainUI:New("TextButton")
  1286. Submit:BackgroundColor(colors.green)
  1287. Submit:TextColor(colors.black)
  1288. Submit:Text("Submit")
  1289. Submit:Size(8, 1)
  1290. Submit:Position(math.floor(W / 2 - 12), math.floor(H / 2 + 1))
  1291.  
  1292. local RegisterCard = MainUI:New("TextButton")
  1293. RegisterCard:BackgroundColor(colors.green)
  1294. RegisterCard:TextColor(colors.black)
  1295. RegisterCard:Text("Register Card")
  1296. RegisterCard:Size(15, 1)
  1297. RegisterCard:Position(math.floor(W / 2 - 3), math.floor(H / 2 + 1))
  1298.  
  1299. RegisterCard:Button1Click(function()
  1300.     if not IsConnected then
  1301.         IsConnected = bapi.connect()
  1302.         if not isConnected then
  1303.             Err:TextColor(colors.red)
  1304.             Err:Text("Could not connect to database")
  1305.             UserInput:Text("")
  1306.             PassInput:Text("")
  1307.             Err:Draw()
  1308.             UserInput:Draw()
  1309.             PassInput:Draw()
  1310.             sleep(3)
  1311.             Err:Text("")
  1312.             Err:Draw()
  1313.             return
  1314.         end
  1315.     end
  1316.  
  1317.     local Success, Data = bapi.newcard(UserInput:GetText(), PassInput:GetText())
  1318.     if not Success then
  1319.         Err:TextColor(colors.red)
  1320.         Err:Text("Error: " .. Data)
  1321.         Err:Draw()
  1322.         sleep(2)
  1323.         Err:Text()
  1324.         Err:Draw()
  1325.         return
  1326.     end
  1327.  
  1328.     Err:TextColor(colors.green)
  1329.     Err:Text("Swipe your card")
  1330.     Err:Draw()
  1331.  
  1332.     mag.beginWrite(Success, UserInput:GetText())
  1333.     os.pullEventRaw("mag_write_done")
  1334.     Err:Text("")
  1335.     UserInput:Text("")
  1336.     PassInput:Text("")
  1337.     Err:Draw()
  1338.     UserInput:Draw()
  1339.     PassInput:Draw()
  1340. end)
  1341.  
  1342. Submit:Button1Click(function()
  1343.     if UserInput:GetText():find(" ") or UserInput:GetText() == "" then
  1344.         Err:TextColor(colors.red)
  1345.         Err:Text("Invalid username")
  1346.         Err:Draw()
  1347.         sleep(2)
  1348.         Err:Text("")
  1349.         Err:Draw()
  1350.         return
  1351.     end
  1352.     if not IsConnected then
  1353.         IsConnected = bapi.connect()
  1354.         if not isConnected then
  1355.             Err:TextColor(colors.red)
  1356.             Err:Text("Could not connect to database")
  1357.             UserInput:Text("")
  1358.             PassInput:Text("")
  1359.             Err:Draw()
  1360.             UserInput:Draw()
  1361.             PassInput:Draw()
  1362.             sleep(3)
  1363.             Err:Text("")
  1364.             Err:Draw()
  1365.             return
  1366.         end
  1367.     end
  1368.  
  1369.     local Success, Error = bapi.register(UserInput:GetText(), PassInput:GetText())
  1370.     if not Success then
  1371.         Err:TextColor(colors.red)
  1372.         Err:Text("Error: " .. Error)
  1373.         UserInput:Text("")
  1374.         PassInput:Text("")
  1375.         Err:Draw()
  1376.         UserInput:Draw()
  1377.         PassInput:Draw()
  1378.         sleep(3)
  1379.         Err:Text("")
  1380.         Err:Draw()
  1381.     else
  1382.         Err:TextColor(colors.green)
  1383.         Err:Text("Created user for '" .. UserInput:GetText() .. "'")
  1384.         UserInput:Text("")
  1385.         PassInput:Text("")
  1386.         Err:Draw()
  1387.         UserInput:Draw()
  1388.         PassInput:Draw()
  1389.         sleep(3)
  1390.         Err:Text("")
  1391.         Err:Draw()
  1392.     end
  1393. end)
  1394.  
  1395. MainUI:Draw()
  1396. MainUI:Listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement