Advertisement
Redxone

[CC Logsys] - ClientGUI

May 17th, 2016
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.85 KB | None | 0 0
  1. os.loadAPI("ugapi")
  2. os.loadAPI("logapi")
  3. local protocol = ""
  4. rednet.open(logapi.getModemSide())
  5. ugapi.fadecolors(0.1,{"black","lightGray","lightBlue","blue"})
  6. local makelogin = ugapi.newButton(" Create Account",5,8,16,3,colors.white,colors.green,colors.gray)
  7. local remlogin = ugapi.newButton(" Delete Account",31,8,16,3,colors.white,colors.red,colors.gray)
  8. local w,h = term.getSize()
  9. function gui()
  10.     term.setBackgroundColor(colors.blue)
  11.     term.clear()
  12.     makelogin:draw()
  13.     remlogin:draw()
  14.     paintutils.drawLine(1, 1, w, 1, colors.lightBlue)
  15.     term.setCursorPos(1,1)
  16.     write("LogSYS - Client")
  17. end
  18. function getCreds(title)
  19.     paintutils.drawBox(
  20.         (w/2) - 9, (h/2) - 2, (w/2)+12, (h/2)+5,
  21.         colors.black)
  22.     paintutils.drawFilledBox(
  23.         (w/2) - 10, (h/2) - 3, (w/2)+11, (h/2)+4,
  24.         colors.lightBlue)
  25.     term.setBackgroundColor(colors.lightGray)
  26.     term.setTextColor(colors.white)
  27.     paintutils.drawLine((w/2)-10,(h/2)-3,(w/2)+11,(h/2)-3)
  28.     term.setCursorPos((w/2)-10,(h/2)-3)
  29.     write(title)
  30.     term.setBackgroundColor(colors.lightBlue)
  31.     term.setCursorPos((w/2)-10,(h/2)-2)
  32.     write("Press enter twice to")
  33.     ugapi.writexy("skip.",(w/2)-10,(h/2)-1)
  34.     term.setCursorPos((w/2)-10,(h/2)+1)
  35.     write("User: ")
  36.     term.setBackgroundColor(colors.gray)
  37.     write(string.rep(" ",14))
  38.     term.setCursorPos((w/2)-10,(h/2)+3)
  39.     term.setBackgroundColor(colors.lightBlue)
  40.     write("Pass: ")
  41.     term.setBackgroundColor(colors.gray)
  42.     write(string.rep(" ",14))
  43.     term.setCursorPos((w/2)-4,(h/2)+1)
  44.     local uname = read()
  45.     term.setCursorPos((w/2)-4,(h/2)+3)
  46.     local upass = read("*")
  47.     return uname, upass
  48. end
  49. function notify(title,txt,txtone,txttwo)
  50.     paintutils.drawBox(
  51.         (w/2) - 9, (h/2) - 2, (w/2)+12, (h/2)+2,
  52.         colors.black)
  53.     paintutils.drawFilledBox(
  54.         (w/2) - 10, (h/2) - 3, (w/2)+11, (h/2)+1,
  55.         colors.lightBlue)
  56.     term.setBackgroundColor(colors.lightGray)
  57.     term.setTextColor(colors.white)
  58.     paintutils.drawLine((w/2)-10,(h/2)-3,(w/2)+11,(h/2)-3)
  59.     term.setCursorPos((w/2)-10,(h/2)-3)
  60.     write(title)
  61.     term.setBackgroundColor(colors.lightBlue)
  62.     term.setCursorPos((w/2)-10,(h/2)-2)
  63.     write(txt)
  64.     term.setCursorPos((w/2)-10,(h/2)-1)
  65.     write(txtone)
  66.     term.setCursorPos((w/2)-10,(h/2))
  67.     write(txttwo)
  68.     os.pullEvent("key")
  69. end
  70. function areYouSure(title)
  71.     paintutils.drawBox(
  72.         (w/2) - 9, (h/2) - 2, (w/2)+12, (h/2)+2,
  73.         colors.black)
  74.     paintutils.drawFilledBox(
  75.         (w/2) - 10, (h/2) - 3, (w/2)+11, (h/2)+1,
  76.         colors.lightBlue)
  77.     term.setBackgroundColor(colors.lightGray)
  78.     term.setTextColor(colors.white)
  79.     paintutils.drawLine((w/2)-10,(h/2)-3,(w/2)+11,(h/2)-3)
  80.     term.setCursorPos((w/2)-10,(h/2)-3)
  81.     write(title)
  82.     term.setBackgroundColor(colors.lightBlue)
  83.     term.setCursorPos((w/2)-10,(h/2)-2)
  84.     write("Are you sure?")
  85.     local opts = {"Yes","No"}
  86.     local selop = 2
  87.     local function mdraw()
  88.         for i = 1, #opts do
  89.             term.setCursorPos( (w/2)-6 + ((i-1)*7),(h/2))
  90.             if(i == selop)then
  91.                 write("[ " .. opts[i] .. " ]")
  92.             else
  93.                 write("  " .. opts[i] .. "  ")
  94.             end
  95.         end
  96.     end
  97.    
  98.  
  99.     local inmenu = true
  100.     mdraw()
  101.     while inmenu do
  102.         ev = {os.pullEvent()}
  103.         if(ev[1] == "key")then
  104.             if(ev[2] == keys.left and selop > 1)then
  105.                 selop = selop - 1
  106.                 mdraw()
  107.             end
  108.             if(ev[2] == keys.right and selop < #opts)then
  109.                 selop = selop + 1  
  110.                 mdraw()
  111.             end
  112.             if(ev[2] == keys.enter)then
  113.                 inmenu = false
  114.                 return selop
  115.             end
  116.         end
  117.     end
  118. end
  119. local function createLogin()
  120.     local name, pass = getCreds("Create Login")
  121.     gui()
  122.     if(name == "" and pass == "")then gui() return false end
  123.     local make = areYouSure("Create Account")
  124.     if(make == 1)then
  125.         local accres = logapi.createLogin(protocol,name,pass)
  126.         if(accres == "username-taken")then
  127.             notify("Account Creation","Account username","already in use.","")
  128.             gui()
  129.             return false
  130.         elseif(accres == "no-connection")then
  131.             notify("Account Creation","No connection to the","server.","")
  132.             gui()
  133.             return false
  134.         elseif(accres == true)then
  135.             notify("Account Creation","Account created: ",name,"")
  136.             gui()
  137.             return true
  138.         end
  139.     else
  140.         gui()
  141.         return false
  142.     end
  143. end
  144. local function remLogin()
  145.     local name, pass = getCreds("Delete Login")
  146.     gui()
  147.     if(name == "" and pass == "")then gui() return false end
  148.     local make = areYouSure("Delete Account")
  149.     if(make == 1)then
  150.         local accres = logapi.deleteLogin(protocol,name,pass)
  151.         if(accres == false)then
  152.             notify("Account deletion","Failed to delete,","wrong username or","wrong password.")
  153.             gui()
  154.             return false
  155.         elseif(accres == "no-connection")then
  156.             notify("Account deletion","No connection to the","server.","")
  157.             gui()
  158.             return false
  159.         elseif(accres == true)then
  160.             notify("Account deletion","Account deleted: ",name,"")
  161.             gui()
  162.             return true
  163.         end
  164.     else
  165.         gui()
  166.         return false
  167.     end
  168. end
  169.  
  170. gui()
  171. makelogin:onPress(createLogin)
  172. remlogin:onPress(remLogin)
  173. local inprog = true
  174. while inprog do
  175.     ev = {os.pullEvent()}
  176.     makelogin:update(ev)
  177.     remlogin:update(ev)
  178. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement