Cavious

turtle_monitor

Jun 8th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.31 KB | None | 0 0
  1. mon = peripheral.wrap("bottom")
  2. mon.clear()
  3. mon.setTextScale(0.5)
  4. keyBreak = false
  5. selected = false
  6. choice = ""
  7.  
  8. function initializeMain()
  9.     term.redirect(mon)
  10.     image = paintutils.loadImage(".background")
  11.     paintutils.drawImage(image, 1,1)
  12.     term.native()
  13.  
  14.     mon.setCursorPos(2,2)
  15.     mon.setBackgroundColor(colors.gray)
  16.     mon.setTextColor(colors.white)
  17.     mon.write("ACTIVE")
  18.  
  19.     mon.setCursorPos(2,7)
  20.     mon.write("ASLEEP")
  21.  
  22.     mon.setCursorPos(9, 9)
  23.     mon.setBackgroundColor(colors.lightBlue)
  24.     mon.setTextColor(colors.black)
  25.     mon.write("SEND OUT")
  26.  
  27.     mon.setCursorPos(29,9)
  28.     mon.write("RETURN")
  29.  
  30.     mon.setCursorPos(20,9)
  31.     mon.setBackgroundColor(colors.orange)
  32.     mon.write("REBOOT")
  33.  
  34.     --temp
  35.     mon.setCursorPos(2,8)
  36.     mon.setBackgroundColor(colors.black)
  37.     mon.setTextColor(colors.red)
  38.     mon.write("t0001a")
  39.  
  40.     mon.setCursorPos(2,9)
  41.     mon.write("t0002b")
  42.     ----------------------
  43. end
  44.  
  45. function buttonReboot()
  46.     os.reboot()
  47. end
  48.  
  49. function buttonSendOut()
  50.     mon.clear()
  51.    
  52.     term.redirect(mon)
  53.     image = paintutils.loadImage(".backgroundSend")
  54.     paintutils.drawImage(image, 1,1)
  55.     term.native()
  56.    
  57.     mon.setCursorPos(30, 8)
  58.     mon.setBackgroundColor(colors.orange)
  59.     mon.setTextColor(colors.black)
  60.     mon.write("BACK")
  61.    
  62.     mon.setCursorPos(2,6)
  63.     mon.setBackgroundColor(colors.lime)
  64.     mon.setTextColor(colors.black)
  65.     mon.write("0")
  66.    
  67.     mon.setCursorPos(6,6)
  68.     mon.setBackgroundColor(colors.lime)
  69.     mon.setTextColor(colors.black)
  70.     mon.write("2")
  71.    
  72.     mon.setCursorPos(10,6)
  73.     mon.setBackgroundColor(colors.lime)
  74.     mon.setTextColor(colors.black)
  75.     mon.write("4")
  76.    
  77.     mon.setCursorPos(2,8)
  78.     mon.setBackgroundColor(colors.lime)
  79.     mon.setTextColor(colors.black)
  80.     mon.write("5")
  81.    
  82.     mon.setCursorPos(6,8)
  83.     mon.setBackgroundColor(colors.lime)
  84.     mon.setTextColor(colors.black)
  85.     mon.write("7")
  86.    
  87.     mon.setCursorPos(10,8)
  88.     mon.setBackgroundColor(colors.lime)
  89.     mon.setTextColor(colors.black)
  90.     mon.write("9")
  91.    
  92.     mon.setCursorPos(4,6)
  93.     mon.setBackgroundColor(colors.green)
  94.     mon.setTextColor(colors.black)
  95.     mon.write("1")
  96.    
  97.     mon.setCursorPos(8,6)
  98.     mon.setBackgroundColor(colors.green)
  99.     mon.setTextColor(colors.black)
  100.     mon.write("3")
  101.    
  102.     mon.setCursorPos(4,8)
  103.     mon.setBackgroundColor(colors.green)
  104.     mon.setTextColor(colors.black)
  105.     mon.write("6")
  106.    
  107.     mon.setCursorPos(8,8)
  108.     mon.setBackgroundColor(colors.green)
  109.     mon.setTextColor(colors.black)
  110.     mon.write("8")
  111.    
  112.     mon.setCursorPos(2,2)
  113.     mon.setBackgroundColor(colors.gray)
  114.     mon.setTextColor(colors.white)
  115.     mon.write("CHOICE")
  116.    
  117.     mon.setCursorPos(2,3)
  118.     mon.setBackgroundColor(colors.black)
  119.     mon.setTextColor(colors.white)
  120.     mon.write(choice)
  121.    
  122.     while(keyBreak == false) do
  123.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  124.    
  125.         --BUTTON EVENTS
  126.         if(yPos == 8 and xPos >= 30 and xPos < 38) then
  127.            
  128.             mon.setCursorPos(30, 8)
  129.             mon.setBackgroundColor(colors.yellow)
  130.             mon.setTextColor(colors.black)
  131.             mon.write("BACK")
  132.            
  133.             os.sleep(1)
  134.             keyBreak = true
  135.            
  136.             run()
  137.         end
  138.     end
  139. end
  140.  
  141. function buttonReturn()
  142.  
  143. end
  144.  
  145. function run()
  146.  
  147.     while(true) do
  148.         initializeMain()
  149.  
  150.         while(true) do
  151.             local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  152.        
  153.             --BUTTON EVENTS
  154.             if(yPos == 9 and xPos >= 9 and xPos < 17) then
  155.                 mon.setCursorPos(9, 9)
  156.                 mon.setBackgroundColor(colors.yellow)
  157.                 mon.setTextColor(colors.black)
  158.                 mon.write("SEND OUT")
  159.                
  160.                 os.sleep(1)
  161.                
  162.                 if(selected == true) then
  163.                     buttonSendOut()
  164.                 end
  165.             end
  166.             if(yPos == 9 and xPos >= 20 and xPos < 26) then
  167.                 mon.setCursorPos(20,9)
  168.                 mon.setTextColor(colors.black)
  169.                 mon.setBackgroundColor(colors.yellow)
  170.                 mon.write("REBOOT")
  171.                
  172.                 os.sleep(1)
  173.                
  174.                 buttonReboot()
  175.             end
  176.             if(yPos == 9 and xPos >= 29 and xPos < 35) then
  177.                 mon.setCursorPos(29,9)
  178.                 mon.setBackgroundColor(colors.yellow)
  179.                 mon.setTextColor(colors.black)
  180.                 mon.write("RETURN")
  181.                
  182.                 os.sleep(1)
  183.                
  184.                 buttonReturn()
  185.                
  186.                 os.sleep(1)
  187.                 mon.setCursorPos(29,9)
  188.                 mon.setBackgroundColor(colors.lightBlue)
  189.                 mon.setTextColor(colors.black)
  190.                 mon.write("RETURN")
  191.             end
  192.             if(yPos == 8 and xPos >= 2 and xPos < 8) then
  193.                 mon.setCursorPos(2,8)
  194.                 mon.setBackgroundColor(colors.white)
  195.                 mon.setTextColor(colors.red)
  196.                 mon.write("t0001a")
  197.                
  198.                 os.sleep(1)
  199.                
  200.                 selected = true
  201.                 choice = "t0001a"
  202.             end
  203.         end
  204.     end
  205. end
  206.  
  207. run()
Advertisement
Add Comment
Please, Sign In to add comment