Alakazard12

Bank Client

Nov 18th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. function clear()
  2.     term.clear()
  3.     term.setCursorPos(1, 1)
  4. end
  5.  
  6. function drawlist(title, list, num)
  7.     clear()
  8.     term.setTextColor(colors.lime)
  9.     print(title.."\n")
  10.     for i,v in pairs(list) do
  11.         if i == num then
  12.             term.setTextColor(colors.white)
  13.             write("[")
  14.             term.setTextColor(colors.lime)
  15.             write("-")
  16.             term.setTextColor(colors.white)
  17.             write("]")
  18.             term.setTextColor(colors.lime)
  19.             print(" "..v)
  20.         else
  21.             term.setTextColor(colors.white)
  22.             print("[ ] "..v)
  23.         end
  24.     end
  25. end
  26.  
  27. function getKey()
  28.     local rt = nil
  29.     function lop()
  30.         local e, a1 = os.pullEvent("key")
  31.         if a1 == 200 then
  32.             rt = "up"
  33.         elseif a1 == 208 then
  34.             rt = "down"
  35.         elseif a1 == 28 then
  36.             rt = "enter"
  37.         else
  38.             lop()
  39.         end
  40.     end
  41.     lop()
  42.     repeat sleep(0) until rt ~= nil
  43.     return rt
  44. end
  45.  
  46. function ch(title, list)
  47.     clear()
  48.     local ind = 1
  49.     drawlist(title, list, ind)
  50.     local rt = nil
  51.     cycle = function()
  52.         local ke = getKey()
  53.         if ke == "up" then
  54.             if ind > 1 then
  55.                 ind = ind - 1
  56.             else
  57.                 ind = #list
  58.             end
  59.             drawlist(title, list, ind)
  60.             cycle()
  61.         elseif ke == "down" then
  62.             if ind < #list then
  63.                 ind = ind + 1
  64.             else
  65.                 ind = 1
  66.             end
  67.             drawlist(title, list, ind)
  68.             cycle()
  69.         elseif ke == "enter" then
  70.             rt = ind
  71.         end
  72.     end
  73.     cycle()
  74.     repeat sleep(0) until rt ~= nil
  75.     return ind
  76. end
  77.  
  78. function main()
  79.     local lts = ch("Main menu", {"Login", "Create account", "Pay user", "Check money"})
  80.     if lts == 1 then
  81.         clear()
  82.         term.setTextColor(colors.lime)
  83.         print("Login:\n")
  84.         term.setTextColor(colors.white)
  85.         write("Username: ")
  86.         term.setTextColor(colors.lime)
  87.         local user = tostring(read())
  88.         term.setTextColor(colors.white)
  89.         write("Password: ")
  90.         term.setTextColor(colors.lime)
  91.         local pass = tostring(read("*"))
  92.         term.setTextColor(colors.white)
  93.         clear()
  94.     elseif lts == 2 then
  95.         clear()
  96.         term.setTextColor(colors.lime)
  97.         print("Create account:\n")
  98.         term.setTextColor(colors.white)
  99.         write("Username: ")
  100.         term.setTextColor(colors.lime)
  101.         local user = tostring(read())
  102.         term.setTextColor(colors.white)
  103.         write("Password: ")
  104.         term.setTextColor(colors.lime)
  105.         local pass = tostring(read("*"))
  106.         term.setTextColor(colors.white)
  107.         write("Confirm password: ")
  108.         term.setTextColor(colors.lime)
  109.         local pass2 = tostring(read("*"))
  110.         term.setTextColor(colors.white)
  111.         if pass == pass2 then
  112.         end
  113.         clear()
  114.     end
  115. end
  116.  
  117. main()
Add Comment
Please, Sign In to add comment