Advertisement
Ezteyh

screen button final

Aug 5th, 2022 (edited)
945
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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, senderId, distance = {os.pullEvent()}
  197.        
  198.         if event[1] == "rednet_message" then
  199.  
  200.             if event[3] == "call0" then
  201.                 etage0()
  202.             end
  203.            
  204.             if event[3] == "call10" then
  205.                 etage1()
  206.             end
  207.  
  208.             if event[3] == "call20" then
  209.                 etage2()
  210.             end
  211.  
  212.             if event[3] == "call30" then
  213.                 etage3()
  214.             end
  215.  
  216.             if event[3] == "call40" then
  217.                 etage4()
  218.             end
  219.            
  220.             if event[3] == "call50" then
  221.                 etage5()
  222.             end
  223.  
  224.             if event[3] == "call60" then
  225.                 etage6()
  226.             end
  227.  
  228.         elseif event[1] == "monitor_touch" then
  229.  
  230.             --Etage 1
  231.             if y ~= 62 and event[3] >= startColumn[1] and event[3] < (startColumn[1] + width) and event[4] >= startRow[1] and event[4] < (startRow[1] + 1) then
  232.                 etage1()
  233.             end
  234.  
  235.             --Etage 2
  236.             if y ~= 52 and event[3] >= startColumn[1] and event[3] < (startColumn[1] + width) and event[4] >= startRow[2] and event[4] < (startRow[2] + 1) then
  237.                 etage2()
  238.             end
  239.  
  240.             --Etage 3
  241.             if y ~= 42 and event[3] >= startColumn[1] and event[3] < (startColumn[1] + width) and event[4] >= startRow[3] and event[4] < (startRow[3] + 1) then
  242.                 etage3()
  243.             end
  244.  
  245.             --Etage 4
  246.             if y ~= 32 and event[3] >= startColumn[3] and event[3] < (startColumn[3] + width) and event[4] >= startRow[1] and event[4] < (startRow[1] + 1) then
  247.                 etage4()
  248.             end
  249.  
  250.             --Etage 5
  251.             if y ~= 22 and event[3] >= startColumn[3] and event[3] < (startColumn[3] + width) and event[4] >= startRow[2] and event[4] < (startRow[2] + 1) then
  252.                 etage5()
  253.             end
  254.  
  255.             --Etage 6
  256.             if y ~= 12 and event[3] >= startColumn[3] and event[3] < (startColumn[3] + width) and event[4] >= startRow[3] and event[4] < (startRow[3] + 1) then
  257.                 etage6()
  258.             end
  259.  
  260.             --Etage 0
  261.             if y ~= 72 and event[3] >= startColumn[2] and event[3] < (startColumn[2] + width) and event[4] >= 1 and event[4] < (2) then
  262.                 etage0()
  263.             end
  264.         end
  265. end
Advertisement
RAW Paste Data Copied
Advertisement