Advertisement
Ezteyh

screenbuttontest5

Aug 5th, 2022
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.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 cx >= startColumn[1] and cx < (startColumn[1] + width) and cy >= startRow[1] and cy < (startRow[1] + 1) then
  89.                 rednet.send(turtleID, "button1")
  90.             end
  91.  
  92.             --Etage 2
  93.             if cx >= startColumn[1] and cx < (startColumn[1] + width) and cy >= startRow[2] and cy < (startRow[2] + 1) then
  94.                 rednet.send(turtleID, "button2")
  95.             end
  96.  
  97.             --Etage 3
  98.             if cx >= startColumn[1] and cx < (startColumn[1] + width) and cy >= startRow[3] and cy < (startRow[3] + 1) then
  99.                 rednet.send(turtleID, "button3")
  100.             end
  101.  
  102.             --Etage 4
  103.             if cx >= startColumn[3] and cx < (startColumn[3] + width) and cy >= startRow[1] and cy < (startRow[1] + 1) then
  104.                 rednet.send(turtleID, "button4")
  105.             end
  106.  
  107.             --Etage 5
  108.             if cx >= startColumn[3] and cx < (startColumn[3] + width) and cy >= startRow[2] and cy < (startRow[2] + 1) then
  109.                 rednet.send(turtleID, "button5")
  110.             end
  111.  
  112.             --Etage 6
  113.             if cx >= startColumn[3] and cx < (startColumn[3] + width) and cy >= startRow[3] and cy < (startRow[3] + 1) then
  114.                 rednet.send(turtleID, "button6")
  115.             end
  116.  
  117.             --Etage 0
  118.             if y < 72 and cx >= startColumn[2] and cx < (startColumn[2] + width) and cy >= 1 and cy < (2) then
  119.                 if y == 62 then
  120.                     rednet.send(turtleID, "button062")
  121.                 elseif y == 52 then
  122.                     rednet.send(turtleID, "button052")
  123.                 end
  124.             end
  125.         end
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement