Guest User

butt

a guest
Aug 1st, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. monSide = "right"
  2.  
  3.  
  4. --button colours = red,lime,blue,gray,magenta
  5. --lime/red will toggle colour
  6. --blue/gray/magenta will NOT change colour.
  7.  
  8. tButtons = {
  9. --name, xmin, xmax, ymin, ymax, ColourButton, colorBoundledCable, BoundledCable.active
  10. {"Control Room",1,12,3,4,"red",1,"active"},
  11. {"Machine Room",1,12,6,7,"red",2,"active"},
  12. {"Generator Rm",1,12,9,10,"red",4,"active"},
  13.  
  14. -- Control room
  15. {"1",17,17,4,4,"red",8,"active"},
  16. {"2",19,19,4,4,"red",16,"active"},
  17. {"3",21,21,4,4,"red"},
  18. {"4",23,23,4,4,"red"},
  19. {"5",25,25,4,4,"red"},
  20.  
  21. -- Machine room
  22. {"1",17,17,7,7,"red"},
  23. {"2",19,19,7,7,"red"},
  24. {"3",21,21,7,7,"red"},
  25. {"4",23,23,7,7,"red"},
  26. {"5",25,25,7,7,"red"},
  27.  
  28. -- titles
  29. {"[Light Control Interface]",1,29,1,1,"blue"},
  30. {"Corridors",17,27,3,3,"blue"},
  31. {"Straircases",17,27,6,6,"blue"},
  32. {"Other",17,27,9,9,"gray"},
  33. }
  34.  
  35. ---------------------
  36.  
  37. colorWhite = 1
  38. colorOrange = 2
  39. colorMagenta = 4
  40. colorLightBlue = 8
  41. colorYellow = 16
  42. colorLime = 32
  43. colorPink = 64
  44. colorGray = 128
  45. colorLightGray = 256
  46. colorCayan = 512
  47. colorPurple = 2014
  48. colorBlue = 2048
  49. colorBrown = 4096
  50. colorGreen = 8192
  51. colorRed = 16384
  52. colorBlack = 32768 
  53.  
  54.  
  55. local num = 0
  56. function userInput(Touch)
  57. if tButtons[Touch][8] == "active" then
  58.     num = num + tButtons[Touch][7]
  59.     tButtons[Touch][8] = "disable"
  60. elseif tButtons[Touch][8] == "disable" then
  61.     tButtons[Touch][8] = "active"
  62.     num = num - tButtons[Touch][7]
  63.         if num < 0 then
  64.             num = 0
  65.         end
  66. elseif tButtons[Touch][7] == nil then
  67.     tButtons[Touch][7] = 0
  68.    
  69. end
  70.  
  71. if rs.setBundledOutput("back",tButtons[Touch][7]) then
  72.     rs.setBundledOutput("back",0)
  73. else
  74.     rs.setBundledOutput("back",num)
  75. end
  76.    
  77.  
  78. end
  79.  
  80.  
  81.  
  82.  
  83. function drawButtons()
  84. mon.setBackgroundColour(colours.black)
  85. mon.clear()
  86.  
  87.  
  88. for i = 1,#tButtons do
  89.     if tButtons[i][6] == "red" then
  90.         mon.setBackgroundColor(colorRed)
  91.     elseif tButtons[i][6] == "lime" then
  92.         mon.setBackgroundColor(colorLime)
  93.     elseif tButtons[i][6] == "blue" then
  94.         mon.setBackgroundColor(colorBlue)
  95.     elseif tButtons[i][6] == "gray" then
  96.         mon.setBackgroundColor(colorLightGray)
  97.     elseif tButtons[i][6] == "magenta" then
  98.         mon.setBackgroundColor(colorMagenta)
  99.    
  100.     end
  101.         for i2 = tButtons[i][4],tButtons[i][5] do
  102.             for i3 = tButtons[i][2],tButtons[i][3] do
  103.                 mon.setCursorPos(i3,i2)
  104.                 mon.write(" ")
  105.             end
  106.         end
  107.     mon.setCursorPos((tButtons[i][2] + tButtons[i][3]) /2 -(#tButtons[i][1]/2 -1 ), (tButtons[i][4] + tButtons[i][5])/2 )
  108.     mon.write(tButtons[i][1])
  109.     end
  110. end
  111.  
  112.  
  113. function miceClick()
  114. event, button, miceX, miceY = os.pullEvent("monitor_touch")
  115.     for i4 = 1,#tButtons do
  116.  
  117.         if miceX >= tButtons[i4][2] and miceX <= tButtons[i4][3] and miceY >= tButtons[i4][4] and miceY <= tButtons[i4][5] then
  118.            
  119.             if tButtons[i4][6] == "lime" then
  120.                 tButtons[i4][6] = "red"
  121.             elseif tButtons[i4][6] == "red" then
  122.                 tButtons[i4][6] = "lime"
  123.             end
  124.                 Touch = i4
  125.                 userInput(Touch)
  126.         end
  127.     end
  128. end
  129.  
  130.  
  131.  
  132. mon = peripheral.wrap(monSide)
  133. mon.setBackgroundColour(colours.black)
  134. mon.clear()
  135.  
  136.  
  137.  
  138. while true do
  139. drawButtons()
  140. miceClick()
  141. end
Advertisement
Add Comment
Please, Sign In to add comment