Advertisement
Ezteyh

screenbuttontest6

Aug 5th, 2022 (edited)
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.71 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. init()
  69. for i = 1, 3, 1 do
  70.     column = startColumn[1]
  71.     row = startRow[i]
  72.     label = tlabel[i]
  73.     displayLabel()
  74. end
  75. for i = 4, 6, 1 do
  76.     column = startColumn[3]
  77.     row = startRow[i]
  78.     label = tlabel[i]
  79.     displayLabel()
  80. end
  81. displayLabel0()
  82.  
  83. while (1) do
  84.     local event, button, cx, cy = os.pullEvent("monitor_touch")
  85.         if event == "monitor_touch" then
  86.  
  87.             --Etage 1
  88.             if y ~= 62 and cx >= startColumn[1] and cx < (startColumn[1] + width) and cy >= startRow[1] and cy < (startRow[1] + 1) then
  89.                 if y == 72 then
  90.                     rednet.send(turtleID, "button172")
  91.                 elseif y == 52 then
  92.                     rednet.send(turtleID, "button152")
  93.                 elseif y == 42 then
  94.                     rednet.send(turtleID, "button142")
  95.                 elseif y == 32 then
  96.                     rednet.send(turtleID, "button132")
  97.                 elseif y == 22 then
  98.                     rednet.send(turtleID, "button122")
  99.                 elseif y == 12 then
  100.                     rednet.send(turtleID, "button112")
  101.                 end
  102.             end
  103.  
  104.             --Etage 2
  105.             if y ~= 52 and cx >= startColumn[1] and cx < (startColumn[1] + width) and cy >= startRow[2] and cy < (startRow[2] + 1) then
  106.                 if y == 72 then
  107.                     rednet.send(turtleID, "button272")
  108.                 elseif y == 62 then
  109.                     rednet.send(turtleID, "button262")
  110.                 elseif y == 42 then
  111.                     rednet.send(turtleID, "button242")
  112.                 elseif y == 32 then
  113.                     rednet.send(turtleID, "button232")
  114.                 elseif y == 22 then
  115.                     rednet.send(turtleID, "button222")
  116.                 elseif y == 12 then
  117.                     rednet.send(turtleID, "button212")
  118.                 end
  119.             end
  120.  
  121.             --Etage 3
  122.             if y ~= 42 and cx >= startColumn[1] and cx < (startColumn[1] + width) and cy >= startRow[3] and cy < (startRow[3] + 1) then
  123.                 if y == 72 then
  124.                     rednet.send(turtleID, "button372")
  125.                 elseif y == 62 then
  126.                     rednet.send(turtleID, "button362")
  127.                 elseif y == 52 then
  128.                     rednet.send(turtleID, "button352")
  129.                 elseif y == 32 then
  130.                     rednet.send(turtleID, "button332")
  131.                 elseif y == 22 then
  132.                     rednet.send(turtleID, "button322")
  133.                 elseif y == 12 then
  134.                     rednet.send(turtleID, "button312")
  135.                 end
  136.             end
  137.  
  138.             --Etage 4
  139.             if y ~= 32 and cx >= startColumn[3] and cx < (startColumn[3] + width) and cy >= startRow[1] and cy < (startRow[1] + 1) then
  140.                 if y == 72 then
  141.                     rednet.send(turtleID, "button472")
  142.                 elseif y == 62 then
  143.                     rednet.send(turtleID, "button462")
  144.                 elseif y == 52 then
  145.                     rednet.send(turtleID, "button452")
  146.                 elseif y == 42 then
  147.                     rednet.send(turtleID, "button442")
  148.                 elseif y == 22 then
  149.                     rednet.send(turtleID, "button422")
  150.                 elseif y == 12 then
  151.                     rednet.send(turtleID, "button412")
  152.                 end
  153.             end
  154.  
  155.             --Etage 5
  156.             if y ~= 22 and cx >= startColumn[3] and cx < (startColumn[3] + width) and cy >= startRow[2] and cy < (startRow[2] + 1) then
  157.                 if y == 72 then
  158.                     rednet.send(turtleID, "button572")
  159.                 elseif y == 62 then
  160.                     rednet.send(turtleID, "button562")
  161.                 elseif y == 52 then
  162.                     rednet.send(turtleID, "button552")
  163.                 elseif y == 42 then
  164.                     rednet.send(turtleID, "button542")
  165.                 elseif y == 32 then
  166.                     rednet.send(turtleID, "button532")
  167.                 elseif y == 12 then
  168.                     rednet.send(turtleID, "button512")
  169.                 end
  170.             end
  171.  
  172.             --Etage 6
  173.             if y ~= 12 and cx >= startColumn[3] and cx < (startColumn[3] + width) and cy >= startRow[3] and cy < (startRow[3] + 1) then
  174.                 if y == 72 then
  175.                     rednet.send(turtleID, "button672")
  176.                 elseif y == 62 then
  177.                     rednet.send(turtleID, "button662")
  178.                 elseif y == 52 then
  179.                     rednet.send(turtleID, "button652")
  180.                 elseif y == 42 then
  181.                     rednet.send(turtleID, "button642")
  182.                 elseif y == 32 then
  183.                     rednet.send(turtleID, "button632")
  184.                 elseif y == 22 then
  185.                     rednet.send(turtleID, "button622")
  186.                 end
  187.             end
  188.  
  189.             --Etage 0
  190.             if y ~= 72 and cx >= startColumn[2] and cx < (startColumn[2] + width) and cy >= 1 and cy < (2) then
  191.                 rednet.send(turtleID, "button0")
  192.             end
  193.         end
  194. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement