Advertisement
Guest User

startup

a guest
Feb 1st, 2013
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.76 KB | None | 0 0
  1. function resetCode()
  2.   one = false
  3.   two = false
  4.   three = false
  5.   four = false
  6.   five = false
  7.   six = false
  8.   seven = false
  9.   eight = false
  10.   nine = false
  11. end
  12. resetCode()
  13. --------------------------------------------
  14. local mon = peripheral.wrap("right")
  15. mon.setTextScale(1)
  16. mon.setTextColor(colors.white)
  17. local button={}
  18. mon.setBackgroundColor(colors.black)
  19.      
  20. function setTable(name, func, xmin, xmax, ymin, ymax)
  21.    button[name] = {}
  22.    button[name]["func"] = func
  23.    button[name]["active"] = false
  24.    button[name]["xmin"] = xmin
  25.    button[name]["ymin"] = ymin
  26.    button[name]["xmax"] = xmax
  27.    button[name]["ymax"] = ymax
  28. end
  29.  
  30. function funcName()
  31.    print("You clicked buttonText")
  32. end
  33.        
  34. function fillTable()
  35.    setTable("1", password1, 1, 1, 1, 1)
  36.    setTable("2", password2, 3, 3, 1, 1)
  37.    setTable("3", password3, 5, 5, 1, 1)
  38.    setTable("4", password4, 1, 1, 3, 3)
  39.    setTable("5", password5, 3, 3, 3, 3)
  40.    setTable("6", password6, 5, 5, 3, 3)
  41.    setTable("7", password7, 1, 1, 5, 5)
  42.    setTable("8", password8, 3, 3, 5, 5)
  43.    setTable("9", password9, 5, 5, 5, 5)
  44.    setTable("*", passwordValid, 7, 7, 5, 5)
  45.    setTable("C", resetCode, 7, 7, 1, 1)
  46.   -- setTable("OtherButton is COOL!", funcName, 5, 35, 10, 12)
  47. end    
  48.  
  49. function password1()
  50.   one = true
  51.   print("ping")
  52. end
  53.  
  54. function password2()
  55.   two = true
  56.   print("ping")
  57. end
  58.  
  59. function password3()
  60.   three = true
  61.   print("ping")
  62. end
  63.  
  64. function password4()
  65.   four = true
  66.   print("ping4")
  67. end
  68.  
  69. function password5()
  70.   five = true
  71.   print("ping5")
  72. end
  73.  
  74. function password6()
  75.   six = true
  76. end
  77.  
  78. function password7()
  79.   seven = true
  80. end
  81.  
  82. function password8()
  83.   eight = true
  84. end
  85.  
  86. function password9()
  87.   nine = true
  88. end
  89.  
  90. function fill(text, color, bData)
  91.    mon.setBackgroundColor(color)
  92.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  93.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  94.    for j = bData["ymin"], bData["ymax"] do
  95.       mon.setCursorPos(bData["xmin"], j)
  96.       if j == yspot then
  97.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  98.             if k == xspot then
  99.                mon.write(text)
  100.             else
  101.                mon.write(" ")
  102.             end
  103.          end
  104.       else
  105.          for i = bData["xmin"], bData["xmax"] do
  106.             mon.write(" ")
  107.          end
  108.       end
  109.    end
  110.    mon.setBackgroundColor(colors.black)
  111. end
  112.      
  113. function screen()
  114.    local currColor
  115.    for name,data in pairs(button) do
  116.       local on = data["active"]
  117.       if on == true then
  118.         currColor = colors.lime
  119.         currColor = colors.red
  120.       else currColor = colors.red
  121.       end
  122.       fill(name, currColor, data)
  123.    end
  124. end
  125.      
  126. function checkxy(x, y)
  127.    for name, data in pairs(button) do
  128.       if y>=data["ymin"] and  y <= data["ymax"] then
  129.          if x>=data["xmin"] and x<= data["xmax"] then
  130.             data["func"]()
  131.             data["active"] = not data["active"]
  132.             print(name)
  133.          end
  134.       end
  135.    end
  136. end
  137.      
  138. function heading(text)
  139.    w, h = mon.getSize()
  140.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  141.    mon.write(text)
  142. end
  143.      
  144. fillTable()
  145.  
  146. function passwordValid()
  147.   if one == true then
  148.     print("test")
  149.    end
  150.   if one == true and two == true and three == true and four == true then
  151.     print("password accepted")
  152.   end
  153.  
  154.   one = false
  155.   two = false
  156.   three = false
  157.   four = false
  158.   five = false
  159.   six = false
  160.   seven = false
  161.   eight = false
  162.   nine = false
  163.   print("code reset")
  164. end
  165.  
  166. passwordValid()
  167. print("PINGALING")
  168.  
  169. while true do
  170.    mon.clear()
  171.    heading(" ")
  172.    screen()
  173.    local e,side,x,y = os.pullEvent("monitor_touch")
  174.    print(x..":"..y)
  175.    checkxy(x,y)
  176.    sleep(.1)
  177. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement