Advertisement
BeloMaximka

SpirtalPistonDoorRemoteControl

Aug 31st, 2020 (edited)
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.82 KB | None | 0 0
  1. local component = require("component")
  2. local gpu = component.gpu
  3. local redstone = component.redstone
  4. local event = require("event")
  5. local term = require("term")
  6. local os = require("os")
  7. local DoorOpened = false
  8. local exit = 0
  9. -----------------------------------
  10. normalx, normaly = gpu.getResolution()
  11. normalFore = gpu.getForeground()
  12. normalBack = gpu.getBackground()
  13. -----------------------------------
  14. function getAllSpecificComponetsAdresses(filter)
  15.     local tableObjects ={}
  16.     for address, componentType in component.list(filter) do
  17.         table.insert(tableObjects, address)
  18.     end
  19.     return tableObjects
  20. end
  21.  
  22. function DrawButton(ButtonType) -- рисует одну из 4 возможных кнопок
  23.     gpu.setResolution(14,7)
  24.     if ButtonType == "Close" then
  25.         gpu.setBackground(0xFF0000) -- красный цвет фона
  26.         gpu.fill(3,4,10,3,' ')
  27.         gpu.set(4,5,"Закрыть")
  28.     elseif ButtonType == "ClosePressed" then
  29.         gpu.setBackground(0xA50000) -- темно-красный цвет фона
  30.         gpu.fill(3,4,10,3,' ')
  31.         gpu.set(4,5,"Закрыть")
  32.     elseif ButtonType == "Open" then
  33.         gpu.setBackground(0x32CD32) -- зеленый цвет фона
  34.         gpu.fill(3,4,10,3,' ')
  35.         gpu.set(4,5,"Открыть")
  36.     elseif ButtonType == "OpenPressed" then
  37.         gpu.setBackground(0x228B22) -- темно-зеленый цвет фона
  38.         gpu.fill(3,4,10,3,' ')
  39.         gpu.set(4,5,"Открыть")
  40.     else
  41.         return false
  42.     end
  43. end
  44.  
  45. function SwitchRedstoneSignal() -- перключает редстоун сигнал над сблоком
  46.     if redstone.getOutput(1) > 0 then
  47.     redstone.setOutput(1,0)
  48.     else
  49.     redstone.setOutput(1,15)
  50.     end
  51. end
  52. -----------------------------------
  53. -- Инициализация
  54. -- Первый экран
  55. screens = getAllSpecificComponetsAdresses("screen")
  56. gpu.bind(screens[1],false)
  57. gpu.setResolution(14,7)
  58. gpu.setBackground(0xc6c6c6) -- серый цвет фона
  59. gpu.setForeground(0x000000) -- черный цвет текста
  60. gpu.fill(1,1,14,7," ") -- заливка экрана
  61. gpu.set(2,2,"Дверной шлюз")
  62. gpu.setBackground(0x32CD32) -- зеленый цвет фона
  63. gpu.fill(3,4,10,3,' ')
  64. gpu.set(4,5,"Открыть")
  65. -- Второй экран
  66. gpu.bind(screens[2],false)
  67. gpu.setResolution(14,7)
  68. gpu.setBackground(0xc6c6c6) -- серый цвет фона
  69. gpu.setForeground(0x000000) -- черный цвет текста
  70. gpu.fill(1,1,14,7," ") -- заливка экрана
  71. gpu.set(2,2,"Дверной шлюз")
  72. gpu.setBackground(0x32CD32) -- зеленый цвет фона
  73. gpu.fill(3,4,10,3,' ')
  74. gpu.set(4,5,"Открыть")
  75. ----------------------------------
  76. while true do
  77.     local _,_,x,y = event.pull("touch")
  78.     if x == 1 and y == 1 and DoorOpened == false then
  79.         if exit == 0 then
  80.             exit = 1
  81.         else
  82.             exit = 0
  83.         end
  84.     elseif x == 14 and y == 1 and exit == 1 then
  85.         break
  86.     elseif x > 2 and x < 13 and y > 3 and y < 7 then
  87.     SwitchRedstoneSignal()
  88.     gpu.bind(screens[1],false)
  89.     if DoorOpened == false then
  90.         DrawButton("OpenPressed")
  91.         gpu.bind(screens[2],false)
  92.         DrawButton("OpenPressed")
  93.         os.sleep(2)
  94.         gpu.bind(screens[1],false)
  95.         DrawButton("Close")
  96.         gpu.bind(screens[2],false)
  97.         DrawButton("Close")
  98.         DoorOpened = true
  99.     else
  100.         DrawButton("ClosePressed")
  101.         gpu.bind(screens[2],false)
  102.         DrawButton("ClosePressed")
  103.         os.sleep(2)
  104.         gpu.bind(screens[1],false)
  105.         DrawButton("Open")
  106.         gpu.bind(screens[2],false)
  107.         DrawButton("Open")
  108.         DoorOpened = false
  109.     end
  110.    
  111.     end
  112.  
  113. end
  114. ----------------------------------
  115. -- Первый экран
  116. gpu.bind(screens[1])
  117. gpu.setResolution(normalx,normaly)
  118. gpu.setForeground(normalFore)
  119. gpu.setBackground(normalBack)
  120. term.clear()
  121. -- Второй экран
  122. gpu.bind(screens[2])
  123. gpu.setResolution(normalx,normaly)
  124. gpu.setForeground(normalFore)
  125. gpu.setBackground(normalBack)
  126. term.clear()
  127. gpu.bind(screens[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement