Advertisement
koki2000

special system

Aug 15th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.86 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2. mon.clear()
  3. w, h = mon.getSize()
  4. print(w, " ", h)
  5. index = 1
  6. pass = ""
  7. password = {}
  8. selecteditem = 1
  9.  
  10. mainmenu1 = {}
  11. mainmenu1[1] = {text = "login", handler = login}
  12. mainmenu1[2] = {text = "demo2", handler = demo2}
  13. mainmenu1[3] = {text = "demo3", handler = demo3}
  14.  
  15. gomb = {}
  16. gomb[1] = {x = w-w+1, y = h-2, x2 = w-w+1, y2 = h-2, color = colors.black, dcolor = colors.black, szoveg = "1"}
  17. gomb[2] = {x = w-w+2, y = h-2, x2 = w-w+2, y2 = h-2, color = colors.black, dcolor = colors.black, szoveg = "2"}
  18. gomb[3] = {x = w-w+3, y = h-2, x2 = w-w+3, y2 = h-2, color = colors.black, dcolor = colors.black, szoveg = "3"}
  19. gomb[4] = {x = w-w+4, y = h-2, x2 = w-w+4, y2 = h-2, color = colors.black, dcolor = colors.black, szoveg = "4"}
  20. gomb[5] = {x = w-w+1, y = h-1, x2 = w-w+1, y2 = h-1, color = colors.black, dcolor = colors.black, szoveg = "5"}
  21. gomb[6] = {x = w-w+2, y = h-1, x2 = w-w+2, y2 = h-1, color = colors.black, dcolor = colors.black, szoveg = "6"}
  22. gomb[7] = {x = w-w+3, y = h-1, x2 = w-w+3, y2 = h-1, color = colors.black, dcolor = colors.black, szoveg = "7"}
  23. gomb[8] = {x = w-w+4, y = h-1, x2 = w-w+4, y2 = h-1, color = colors.black, dcolor = colors.black, szoveg = "8"}
  24. gomb[9] = {x = w-w+1, y = h, x2 = w-w+1, y2 = h, color = colors.black, dcolor = colors.black, szoveg = "9"}
  25. gomb[10] = {x = w-w+3, y = h, x2 = w-w+3, y2 = h, color = colors.black, dcolor = colors.black, szoveg = "0"}
  26. gomb[11] = {x = w-w+2, y = h, x2 = w-w+2, y2 = h, color = colors.black, dcolor = colors.black, szoveg = "*"}
  27. gomb[12] = {x = w-w+4, y = h, x2 = w-w+4, y2 = h, color = colors.black, dcolor = colors.black, szoveg = "#"}
  28. gomb[13] = {x = w-w+6, y = h-1, x2 = w-w+10, y2 = h-1, color = colors.green, dcolor = colors.green, szoveg = "enter"}
  29. gomb[14] = {x = w-w+5, y = h, x2 = w-w+10, y2 = h, color = colors.red, dcolor = colors.red, szoveg = "delete"}
  30. gomb[15] = {x = w-w+12, y = h, x2 = w-w+12, y2 = h, color = colors.gray, dcolor = colors.gray, szoveg = "<"}
  31. gomb[16] = {x = w-w+14, y = h, x2 = w-w+14, y2 = h, color = colors.gray, dcolor = colors.gray, szoveg = "v"}
  32. gomb[17] = {x = w-w+16, y = h, x2 = w-w+16, y2 = h, color = colors.gray, dcolor = colors.gray, szoveg = ">"}
  33. gomb[18] = {x = w-w+14, y = h-1, x2 = w-w+14, y2 = h-1, color = colors.gray, dcolor = colors.gray, szoveg = "^"}
  34.  
  35. function login()
  36.  local event, button, xpos, ypos = os.pullEvent("monitor_touch")
  37.  mon.setCursorPos(1, 1)
  38.  mon.write("login") sleep(2)
  39. end
  40.  
  41. function kirajzol()
  42.  mon.clear()
  43.  for g = 1, 2 do
  44.   for h = 1, w do
  45.    mon.setBackgroundColor(colors.lime)
  46.    mon.setCursorPos(h ,g)
  47.    mon.write(" ")
  48.   end
  49.  end
  50.  for i = 1, #gomb do
  51.   for j = 0 + gomb[i].y, gomb[i].y2 do
  52.    for k = 0 + gomb[i].x, gomb[i].x2 do
  53.     mon.setCursorPos(k, j)
  54.     mon.setBackgroundColor(gomb[i].color)
  55.     mon.write(" ")
  56.    end
  57.   end
  58.   mon.setCursorPos(gomb[i].x, gomb[i].y)
  59.   mon.write(gomb[i].szoveg)
  60.  end
  61.   mon.setBackgroundColor(colors.black)
  62. end
  63.  
  64. function printmenu(menu)
  65.  mon.setBackgroundColor(colors.lime)
  66.  for i = 1, #menu do
  67.   local hossz = string.len(menu[i].text)
  68.   if i == selecteditem then
  69.    mon.setCursorPos(w/2-(hossz/2), 1)
  70.    mon.write("--"..menu[i].text.."--")
  71.   else
  72.    mon.setCursorPos(w/2-(hossz/2), 2)
  73.    if selecteditem < #menu then
  74.     mon.write("  "..menu[selecteditem+1].text.."  ")
  75.    else
  76.     mon.write(" ")
  77.    end
  78.   end
  79.  end
  80.  mon.setBackgroundColor(colors.black)
  81. end
  82.  
  83. function onitemchange(i, menu)
  84.  if i == 15 then -- bal
  85.  
  86.  elseif i == 16 then -- le
  87.   if selecteditem < #menu then
  88.    selecteditem = selecteditem + 1
  89.   end
  90.  elseif i == 17 then -- jobb
  91.   menu[selecteditem].handler()
  92.  elseif i == 18 then -- fel
  93.   if selecteditem > 1 then
  94.    selecteditem = selecteditem - 1
  95.   end
  96.  end
  97. end
  98.  
  99. function click(xpos, ypos, xs, ys, xe, ye)
  100.  if xpos < xs or xpos > xe or ypos < ys or ypos > ye then
  101.   return false
  102.  else
  103.   return true
  104.  end
  105. end
  106.  
  107. function intake(i)
  108.  if i > 0 and i < 11 then
  109.   table.insert(password, #password+1, gomb[i].szoveg)
  110.   for i = 1, #password do
  111.    mon.setCursorPos(i, 1)
  112.    mon.write(password[i])
  113.   end  
  114.   local temporary = password[#password]
  115.   pass = pass..temporary
  116.  elseif i == 10 then
  117.    mon.setCursorPos(1, 1)
  118.    mon.write("reset") sleep(3)
  119.    pass = ""
  120.    password = {}
  121.  elseif i == 12 then
  122.   if pass == "1" then
  123.    mon.setCursorPos(1, 1)
  124.    mon.write("granted")
  125.    password = {}
  126.    pass = ""
  127.    rs.setOutput("bottom", true)
  128.    sleep(1)
  129.    rs.setOutput("bottom", false)
  130.   else
  131.    mon.setCursorPos(1, 1)
  132.    mon.write("denied")
  133.    password = {}
  134.    pass = "" sleep(2)
  135.   end
  136.  elseif i > 14 and i < 19 then
  137.   onitemchange(i, mainmenu1)
  138.  end
  139. end
  140.  
  141. while true do
  142. kirajzol()
  143. printmenu(mainmenu1)
  144. local event, button, xpos, ypos = os.pullEvent("monitor_touch")
  145.  for i=1, #gomb do
  146.   if click(xpos, ypos, gomb[i].x, gomb[i].y, gomb[i].x2, gomb[i].y2) then
  147.    print(gomb[i].szoveg)
  148.    intake(i)
  149.   end
  150.  end
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement