Advertisement
Ezteyh

screen button final

Aug 5th, 2022
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.16 KB | None | 0 0
  1. peripheral.find("modem",rednet.open)
  2. local monitor = peripheral.find("monitor")
  3. peripheral.wrap("monitor")
  4. monitor.setTextScale(1)
  5. monitor.clear()
  6.  
  7. local defaultBackgroundColor = colors.black
  8. local defaultTextColor = colors.white
  9.  
  10. local backgroundColorNormal = colors.blue
  11. local backgroundColorPressed = colors.red
  12.  
  13. local textColorNormal = colors.white
  14. local textColorPressed = colors.yellow
  15.  
  16. local width = 3
  17. local height = 1.75
  18. local startColumn = {2,6,9}
  19. local startRow = {3,5,7, 3,5,7}
  20. local row = 2
  21. local column = 2
  22.  
  23. local tlabel = {"1","2","3","4","5","6"}
  24. local label = "1"
  25. local label0 = "0"
  26.  
  27. local x, y, z = gps.locate(5)
  28. local turtleID = 23
  29.  
  30. function resetScreen()
  31.     monitor.setBackgroundColor(defaultBackgroundColor)
  32.     monitor.setTextColor(defaultTextColor)
  33. end
  34.  
  35. --init
  36. function init()
  37.     resetScreen()
  38.     monitor.setTextScale(1.5)
  39.     monitor.clear()
  40. end
  41.  
  42. --button background
  43. function displayButtonBackground()
  44.     monitor.setBackgroundColor(backgroundColorNormal)
  45.     for roww = row, row + height - 1 do
  46.         monitor.setCursorPos(column, row)
  47.         monitor.write(string.rep(" ", width))
  48.     end
  49. end
  50.  
  51. --display label
  52. function displayLabel()
  53.     monitor.setTextColor(textColorNormal)
  54.     displayButtonBackground()
  55.     monitor.setCursorPos(column + math.floor((width - #label)/2), row + math.floor(height/2))
  56.     monitor.write(label)
  57. end
  58.  
  59. function displayLabel0()
  60.     monitor.setTextColor(textColorNormal)
  61.     monitor.setCursorPos(6, 1)
  62.     monitor.setBackgroundColor(backgroundColorNormal)
  63.     monitor.write(string.rep(" ", width))
  64.     monitor.setCursorPos(6 + math.floor((width - #label0)/2), 1 + math.floor(height/2))
  65.     monitor.write(label0)
  66. end
  67.  
  68. function etage0()
  69.     if y == 62 then
  70.         rednet.send(turtleID, "button062")
  71.     elseif y == 52 then
  72.         rednet.send(turtleID, "button052")
  73.     elseif y == 42 then
  74.         rednet.send(turtleID, "button042")
  75.     elseif y == 32 then
  76.         rednet.send(turtleID, "button032")
  77.     elseif y == 22 then
  78.         rednet.send(turtleID, "button022")
  79.     elseif y == 12 then
  80.         rednet.send(turtleID, "button012")
  81.     end
  82. end
  83.  
  84. function etage1()
  85.     if y == 72 then
  86.         rednet.send(turtleID, "button172")
  87.     elseif y == 52 then
  88.         rednet.send(turtleID, "button152")
  89.     elseif y == 42 then
  90.         rednet.send(turtleID, "button142")
  91.     elseif y == 32 then
  92.         rednet.send(turtleID, "button132")
  93.     elseif y == 22 then
  94.         rednet.send(turtleID, "button122")
  95.     elseif y == 12 then
  96.         rednet.send(turtleID, "button112")
  97.     end
  98. end
  99.  
  100. function etage2()
  101.     if y == 72 then
  102.         rednet.send(turtleID, "button272")
  103.     elseif y == 62 then
  104.         rednet.send(turtleID, "button262")
  105.     elseif y == 42 then
  106.         rednet.send(turtleID, "button242")
  107.     elseif y == 32 then
  108.         rednet.send(turtleID, "button232")
  109.     elseif y == 22 then
  110.         rednet.send(turtleID, "button222")
  111.     elseif y == 12 then
  112.         rednet.send(turtleID, "button212")
  113.     end
  114. end
  115.  
  116. function etage3()
  117.     if y == 72 then
  118.         rednet.send(turtleID, "button372")
  119.     elseif y == 62 then
  120.         rednet.send(turtleID, "button362")
  121.     elseif y == 52 then
  122.         rednet.send(turtleID, "button352")
  123.     elseif y == 32 then
  124.         rednet.send(turtleID, "button332")
  125.     elseif y == 22 then
  126.         rednet.send(turtleID, "button322")
  127.     elseif y == 12 then
  128.         rednet.send(turtleID, "button312")
  129.     end
  130. end
  131.  
  132. function etage4()
  133.     if y == 72 then
  134.         rednet.send(turtleID, "button472")
  135.     elseif y == 62 then
  136.         rednet.send(turtleID, "button462")
  137.     elseif y == 52 then
  138.         rednet.send(turtleID, "button452")
  139.     elseif y == 42 then
  140.         rednet.send(turtleID, "button442")
  141.     elseif y == 22 then
  142.         rednet.send(turtleID, "button422")
  143.     elseif y == 12 then
  144.         rednet.send(turtleID, "button412")
  145.     end
  146. end
  147.  
  148. function etage5()
  149.     if y == 72 then
  150.         rednet.send(turtleID, "button572")
  151.     elseif y == 62 then
  152.         rednet.send(turtleID, "button562")
  153.     elseif y == 52 then
  154.         rednet.send(turtleID, "button552")
  155.     elseif y == 42 then
  156.         rednet.send(turtleID, "button542")
  157.     elseif y == 32 then
  158.         rednet.send(turtleID, "button532")
  159.     elseif y == 12 then
  160.         rednet.send(turtleID, "button512")
  161.     end
  162. end
  163.  
  164. function etage6()
  165.     if y == 72 then
  166.         rednet.send(turtleID, "button672")
  167.     elseif y == 62 then
  168.         rednet.send(turtleID, "button662")
  169.     elseif y == 52 then
  170.         rednet.send(turtleID, "button652")
  171.     elseif y == 42 then
  172.         rednet.send(turtleID, "button642")
  173.     elseif y == 32 then
  174.         rednet.send(turtleID, "button632")
  175.     elseif y == 22 then
  176.         rednet.send(turtleID, "button622")
  177.     end
  178. end
  179.  
  180. init()
  181. for i = 1, 3, 1 do
  182.     column = startColumn[1]
  183.     row = startRow[i]
  184.     label = tlabel[i]
  185.     displayLabel()
  186. end
  187. for i = 4, 6, 1 do
  188.     column = startColumn[3]
  189.     row = startRow[i]
  190.     label = tlabel[i]
  191.     displayLabel()
  192. end
  193. displayLabel0()
  194.  
  195. while (1) do
  196.     local event, button, cx, cy, message = os.pullEvent()
  197.         if event == "rednet_message" then
  198.  
  199.            if message == "call0" then
  200.                 etage0()
  201.             end
  202.  
  203.             if message == "call10" then
  204.                 etage1()
  205.             end
  206.  
  207.             if message == "call20" then
  208.                 etage2()
  209.             end
  210.  
  211.             if message == "call30" then
  212.                 etage3()
  213.             end
  214.  
  215.             if message == "call40" then
  216.                 etage4()
  217.             end
  218.            
  219.             if message == "call50" then
  220.                 etage5()
  221.             end
  222.  
  223.             if message == "call60" then
  224.                 etage6()
  225.             end
  226.  
  227.         end
  228.  
  229.         if event == "monitor_touch" then
  230.  
  231.             --Etage 1
  232.             if y ~= 62 and cx >= startColumn[1] and cx < (startColumn[1] + width) and cy >= startRow[1] and cy < (startRow[1] + 1) then
  233.                 etage1()
  234.             end
  235.  
  236.             --Etage 2
  237.             if y ~= 52 and cx >= startColumn[1] and cx < (startColumn[1] + width) and cy >= startRow[2] and cy < (startRow[2] + 1) then
  238.                 etage2()
  239.             end
  240.  
  241.             --Etage 3
  242.             if y ~= 42 and cx >= startColumn[1] and cx < (startColumn[1] + width) and cy >= startRow[3] and cy < (startRow[3] + 1) then
  243.                 etage3()
  244.             end
  245.  
  246.             --Etage 4
  247.             if y ~= 32 and cx >= startColumn[3] and cx < (startColumn[3] + width) and cy >= startRow[1] and cy < (startRow[1] + 1) then
  248.                 etage4()
  249.             end
  250.  
  251.             --Etage 5
  252.             if y ~= 22 and cx >= startColumn[3] and cx < (startColumn[3] + width) and cy >= startRow[2] and cy < (startRow[2] + 1) then
  253.                 etage5()
  254.             end
  255.  
  256.             --Etage 6
  257.             if y ~= 12 and cx >= startColumn[3] and cx < (startColumn[3] + width) and cy >= startRow[3] and cy < (startRow[3] + 1) then
  258.                 etage6()
  259.             end
  260.  
  261.             --Etage 0
  262.             if y ~= 72 and cx >= startColumn[2] and cx < (startColumn[2] + width) and cy >= 1 and cy < (2) then
  263.                 etage0()
  264.             end
  265.         end
  266. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement