Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local gpu = component.gpu
- local redstone = component.redstone
- local event = require("event")
- local term = require("term")
- local os = require("os")
- local DoorOpened = false
- local exit = 0
- -----------------------------------
- normalx, normaly = gpu.getResolution()
- normalFore = gpu.getForeground()
- normalBack = gpu.getBackground()
- -----------------------------------
- function getAllSpecificComponetsAdresses(filter)
- local tableObjects ={}
- for address, componentType in component.list(filter) do
- table.insert(tableObjects, address)
- end
- return tableObjects
- end
- function DrawButton(ButtonType) -- рисует одну из 4 возможных кнопок
- gpu.setResolution(14,7)
- if ButtonType == "Close" then
- gpu.setBackground(0xFF0000) -- красный цвет фона
- gpu.fill(3,4,10,3,' ')
- gpu.set(4,5,"Закрыть")
- elseif ButtonType == "ClosePressed" then
- gpu.setBackground(0xA50000) -- темно-красный цвет фона
- gpu.fill(3,4,10,3,' ')
- gpu.set(4,5,"Закрыть")
- elseif ButtonType == "Open" then
- gpu.setBackground(0x32CD32) -- зеленый цвет фона
- gpu.fill(3,4,10,3,' ')
- gpu.set(4,5,"Открыть")
- elseif ButtonType == "OpenPressed" then
- gpu.setBackground(0x228B22) -- темно-зеленый цвет фона
- gpu.fill(3,4,10,3,' ')
- gpu.set(4,5,"Открыть")
- else
- return false
- end
- end
- function SwitchRedstoneSignal() -- перключает редстоун сигнал над сблоком
- if redstone.getOutput(1) > 0 then
- redstone.setOutput(1,0)
- else
- redstone.setOutput(1,15)
- end
- end
- -----------------------------------
- -- Инициализация
- -- Первый экран
- screens = getAllSpecificComponetsAdresses("screen")
- gpu.bind(screens[1],false)
- gpu.setResolution(14,7)
- gpu.setBackground(0xc6c6c6) -- серый цвет фона
- gpu.setForeground(0x000000) -- черный цвет текста
- gpu.fill(1,1,14,7," ") -- заливка экрана
- gpu.set(2,2,"Дверной шлюз")
- gpu.setBackground(0x32CD32) -- зеленый цвет фона
- gpu.fill(3,4,10,3,' ')
- gpu.set(4,5,"Открыть")
- -- Второй экран
- gpu.bind(screens[2],false)
- gpu.setResolution(14,7)
- gpu.setBackground(0xc6c6c6) -- серый цвет фона
- gpu.setForeground(0x000000) -- черный цвет текста
- gpu.fill(1,1,14,7," ") -- заливка экрана
- gpu.set(2,2,"Дверной шлюз")
- gpu.setBackground(0x32CD32) -- зеленый цвет фона
- gpu.fill(3,4,10,3,' ')
- gpu.set(4,5,"Открыть")
- ----------------------------------
- while true do
- local _,_,x,y = event.pull("touch")
- if x == 1 and y == 1 and DoorOpened == false then
- if exit == 0 then
- exit = 1
- else
- exit = 0
- end
- elseif x == 14 and y == 1 and exit == 1 then
- break
- elseif x > 2 and x < 13 and y > 3 and y < 7 then
- SwitchRedstoneSignal()
- gpu.bind(screens[1],false)
- if DoorOpened == false then
- DrawButton("OpenPressed")
- gpu.bind(screens[2],false)
- DrawButton("OpenPressed")
- os.sleep(2)
- gpu.bind(screens[1],false)
- DrawButton("Close")
- gpu.bind(screens[2],false)
- DrawButton("Close")
- DoorOpened = true
- else
- DrawButton("ClosePressed")
- gpu.bind(screens[2],false)
- DrawButton("ClosePressed")
- os.sleep(2)
- gpu.bind(screens[1],false)
- DrawButton("Open")
- gpu.bind(screens[2],false)
- DrawButton("Open")
- DoorOpened = false
- end
- end
- end
- ----------------------------------
- -- Первый экран
- gpu.bind(screens[1])
- gpu.setResolution(normalx,normaly)
- gpu.setForeground(normalFore)
- gpu.setBackground(normalBack)
- term.clear()
- -- Второй экран
- gpu.bind(screens[2])
- gpu.setResolution(normalx,normaly)
- gpu.setForeground(normalFore)
- gpu.setBackground(normalBack)
- term.clear()
- gpu.bind(screens[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement