Advertisement
Vilsol

Touchscreen

Jan 13th, 2013
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.40 KB | None | 0 0
  1. tArgs = { ... }
  2. sw, sh = term.getSize()
  3. thaum = 0
  4. loggedin = 0
  5. passa = 0
  6. pass = ""
  7. password = "1337"
  8.  
  9. function iB(sx, sy, lx, ly, x, y)
  10.     if x >= sx and x <= lx then
  11.         if y >= sy and y <= ly then
  12.             return true;
  13.         else
  14.             return false;
  15.         end
  16.     else
  17.         return false;
  18.     end
  19. end
  20.  
  21. function on(color, side)
  22.     if side == 0 then side = "back" end
  23.     redstone.setBundledOutput(side, color)
  24. end
  25.  
  26. function off(side)
  27.     if side == 0 then side = "back" end
  28.     redstone.setBundledOutput(side, 0)
  29. end
  30.  
  31. function pulse(color, side)
  32.     on(color, side)
  33.     sleep(0.3)
  34.     off(side)
  35. end
  36.  
  37. function dt(x, y, text, tcolor, bg)
  38.     if tcolor == 0 then tcolor = colors.white end
  39.     if bg == 0 then bg = colors.black end
  40.     term.setCursorPos(x, y)
  41.     term.setTextColor(tcolor)
  42.     term.setBackgroundColor(bg)
  43.     term.write(text)
  44.     term.setTextColor(colors.white)
  45.     term.setBackgroundColor(colors.black)
  46. end
  47.  
  48. function db(x, y, xs, ys, bg)
  49.     for f = x, x+xs do
  50.         for g = y, y+ys do
  51.             term.setCursorPos(f, g)
  52.             term.setBackgroundColor(bg)
  53.             term.write(" ")
  54.         end
  55.     end
  56.     term.setBackgroundColor(colors.black)
  57. end
  58.  
  59. function openthaum()
  60.     thaum = 1
  61.     for times = 1,5 do
  62.         pulse(colors.orange, 0)
  63.         sleep(1.5)
  64.     end
  65.     for times = 1,5 do
  66.         pulse(colors.lightBlue, 0)
  67.         sleep(1.5)
  68.     end
  69. end
  70.  
  71. function togglepiston()
  72.     pulse(colors.pink, 0)
  73. end
  74.  
  75. function hidethaum()
  76.     thaum = 0
  77.     for times = 1,5 do
  78.         pulse(colors.magenta, 0)
  79.         sleep(1.5)
  80.     end
  81.     for times = 1,5 do
  82.         pulse(colors.white, 0)
  83.         sleep(1.5)
  84.     end
  85. end
  86.  
  87. function upelev()
  88.     for times = 1, 27 do
  89.         pulse(colors.lime, 0)
  90.         sleep(1)
  91.     end
  92. end
  93.  
  94. function downelev()
  95.     for times = 1, 27 do
  96.         pulse(colors.yellow, 0)
  97.         sleep(1)
  98.     end
  99. end
  100.  
  101. function writepass(number)
  102.     if passa < 4 then
  103.         pass = pass .. tostring(number)
  104.         passa = passa + 1
  105.     end
  106. end
  107.  
  108. function draw()
  109.     shell.run("clear")
  110.    
  111.     if loggedin == 0 then
  112.    
  113.         if passa >= 1 then db(4,2,4,3,colors.blue) else db(4,2,4,3,colors.white) end
  114.         if passa >= 2 then db(10,2,4,3,colors.blue) else db(10,2,4,3,colors.white) end
  115.         if passa >= 3 then db(16,2,4,3,colors.blue) else db(16,2,4,3,colors.white) end
  116.         if passa >= 4 then db(22,2,4,3,colors.blue) else db(22,2,4,3,colors.white) end
  117.        
  118.         dt(9,7," 1 ",colors.cyan, colors.white)
  119.         dt(14,7," 2 ",colors.cyan, colors.white)
  120.         dt(19,7," 3 ",colors.cyan, colors.white)
  121.        
  122.         dt(9,9," 4 ",colors.cyan, colors.white)
  123.         dt(14,9," 5 ",colors.cyan, colors.white)
  124.         dt(19,9," 6 ",colors.cyan, colors.white)
  125.        
  126.         dt(9,11," 7 ",colors.cyan, colors.white)
  127.         dt(14,11," 8 ",colors.cyan, colors.white)
  128.         dt(19,11," 9 ",colors.cyan, colors.white)
  129.        
  130.         dt(9,13," R ",colors.cyan, colors.white)
  131.         dt(14,13," 0 ",colors.cyan, colors.white)
  132.        
  133.         dt(8, 15, "Enter password!", colors.white, colors.blue)
  134.    
  135.     else
  136.         dt(9, 1, "Control Panel", colors.cyan, colors.black)
  137.         dt(24, 1, "Logout", colors.red, colors.black)
  138.         dt(12, 19, "Update", colors.lime, colors.black)
  139.        
  140.         dt(7,4,"Play \"Still Alive\"",colors.lime, colors.black)
  141.         dt(26,4,"X",colors.lime, colors.black)
  142.        
  143.         dt(6,6,"Play \"Want You Gone\"",colors.lime, colors.black)
  144.         dt(27,6,"X",colors.lime, colors.black)
  145.        
  146.         if thaum == 1 then
  147.             dt(6,8,"Close Thaumcraft Room",colors.lime, colors.black)
  148.         else
  149.             dt(6,8,"Open Thaumcraft Room",colors.lime, colors.black)
  150.         end
  151.        
  152.         dt(9,10,"Ride Elevator",colors.lime, colors.black)
  153.     end
  154. end
  155.  
  156. draw()
  157.  
  158. while true do
  159.     event, button, xPos, yPos = os.pullEvent("mouse_click")
  160.     if(event == "mouse_click")then
  161.         if loggedin == 0 then
  162.             if iB(9, 7, 12, 7, xPos, yPos) then writepass(1) end
  163.             if iB(14, 7, 17, 7, xPos, yPos) then writepass(2) end
  164.             if iB(19, 7, 21, 7, xPos, yPos) then writepass(3) end
  165.             if iB(9, 9, 12, 9, xPos, yPos) then writepass(4) end
  166.             if iB(14, 9, 17, 9, xPos, yPos) then writepass(5) end
  167.             if iB(19, 9, 21, 9, xPos, yPos) then writepass(6) end
  168.             if iB(9, 11, 12, 11, xPos, yPos) then writepass(7) end
  169.             if iB(14, 11, 17, 11, xPos, yPos) then writepass(8) end
  170.             if iB(19, 11, 21, 11, xPos, yPos) then writepass(9) end
  171.             if iB(14, 13, 17, 13, xPos, yPos) then writepass(0) end
  172.             if iB(9, 13, 12, 13, xPos, yPos) then
  173.                 pass = ""
  174.                 passa = 0
  175.             end
  176.             draw()
  177.             if passa == 4 then
  178.                 if pass == password then
  179.                     loggedin = 1
  180.                     pass = ""
  181.                     passa = 0
  182.                     dt(7, 15, "Password correct!", colors.white, colors.lime)
  183.                     sleep(3)
  184.                 else
  185.                     dt(6, 15, "Password incorrect!", colors.white, colors.red)
  186.                     passa = 0
  187.                     pass = ""
  188.                     sleep(3)
  189.                 end
  190.             end
  191.         else
  192.             if iB(24, 1, 29, 1, xPos, yPos) then loggedin = 0 end
  193.            
  194.             if iB(12, 19, 18, 19, xPos, yPos) then shell.run("update") end
  195.            
  196.             if iB(7, 4, 21, 4, xPos, yPos) then disk.playAudio("right") end
  197.             if iB(26, 4, 26, 4, xPos, yPos) then disk.stopAudio("right") end
  198.            
  199.             if iB(6, 6, 22, 6, xPos, yPos) then disk.playAudio("left") end
  200.             if iB(27, 6, 27, 6, xPos, yPos) then disk.stopAudio("left") end
  201.            
  202.             if iB(5, 8, 26, 8, xPos, yPos) then
  203.                 if thaum == 1 then
  204.                     thaum = 0
  205.                     dt(4,16,"Closing Thaumcraft Room",colors.lightBlue, colors.black)
  206.                     hidethaum()
  207.                 else
  208.                     thaum = 1
  209.                     dt(4,16,"Opening Thaumcraft Room",colors.lightBlue, colors.black)
  210.                     openthaum()
  211.                 end
  212.             end
  213.            
  214.             if iB(9, 10, 16, 10, xPos, yPos) then
  215.                 dt(8,16,"Lift operating!",colors.lightBlue, colors.black)
  216.                 togglepiston()
  217.                 sleep(2)
  218.                 downelev()
  219.                 sleep(3)
  220.                 upelev()
  221.                 togglepiston()
  222.             end
  223.         end
  224.         draw()
  225.         sleep(0.2)
  226.     end
  227. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement