Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local computer = require("computer")
- local event = require("event")
- local colors = require("colors")
- local gpu = component.gpu
- local rs = component.redstone
- local unicode = require("unicode")
- local term = require("term")
- local sides = require("sides")
- a = 0
- term.clear()
- function funcButton()
- os.sleep(1)
- rs.setOutput(1, 255)
- rs.setOutput(2, 255)
- rs.setOutput(3, 255)
- rs.setOutput(4, 255)
- rs.setOutput(5, 255)
- end
- function funcButton1()
- computer.beep(1000, 1)
- os.sleep(1)
- rs.setOutput(1, 0)
- rs.setOutput(2, 0)
- rs.setOutput(3, 0)
- rs.setOutput(4, 0)
- rs.setOutput(5, 0)
- end
- function funcButton2()
- if buttons.button2.buttonPressed == true then
- rs.setOutput(0, 0)
- else
- rs.setOutput(0, 255)
- end
- end
- function funcButton3()
- a = "EXIT"
- end
- buttons = {button = {x=35, y=7, text="ВКЛ_", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton, height=7, cFore = 0xFFFFFF, cBack = 0x00FF00},
- button1 = {x=55, y=7, text="ВЫКЛ", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton1, height=7, cFore = 0xFFFFFF, cBack = 0xFF0000},
- button2 = {x=35, y=17, text="AUTO", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton2, height=7, cFore = 0x000000, cBack = 0x00FF00, cFore1 = 0xFFFFFF, cBack1 = 0xFF0000},
- button3 = {x=55, y=17, text="EXIT", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton3, height=7, cFore = 0xFFFFFF, cBack = 0x0000FF}}
- function initButtons()
- for k,v in pairs(buttons) do
- v.width = unicode.wlen(v.text) + 10
- end
- end
- initButtons()
- function drawButtons()
- for k,v in pairs(buttons) do
- if v.active then
- if not v.buttonPressed then -- если кнопка не нажата
- gpu.setForeground(v.cFore)
- gpu.setBackground(v.cBack)
- else -- в ином случае
- gpu.setForeground(v.cFore1)
- gpu.setBackground(v.cBack1)
- end
- gpu.fill(v.x, v.y, v.width, v.height, " ") -- фон для кнопки
- if v.height == 1 then -- если высота кнопки равна 1
- gpu.set(v.x+4, v.y, v.text)
- elseif v.height%2 == 0 then -- если высота кнопки равна четному числу
- gpu.set(v.x+4, v.y + (v.height/2 - 1), v.text)
- elseif v.height%2 == 1 then -- если высота кнопки равна нечетному числу
- gpu.set(v.x+4, v.y + (math.ceil(v.height/2) - 1), v.text)
- end
- if v.autoSwitch == true and v.buttonPressed == true then
- v.buttonPressed = false
- os.sleep(4)
- drawButtons()
- end
- end
- end
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x000000)
- end
- function spam()
- if component.redstone.getOutput(1) == 255 then
- gpu.set(buttons.button.x + buttons.button.width - 30 - 4 , buttons.button.y, "РЕАКТОРЫ:ВКЛ_")
- os.sleep(1)
- else
- gpu.set(buttons.button.x + buttons.button.width - 30 - 4 , buttons.button.y, "РЕАКТОРЫ:ВЫКЛ")
- os.sleep(1)
- end
- end
- function searchButton()
- while true do
- spam()
- if a == "EXIT" then
- term.clear()
- break
- end
- local _,_,x,y = event.pull("touch")
- for k,v in pairs(buttons) do
- if x >= v.x and x < v.x + v.width+2 and y >= v.y and y < v.y + v.height and v.active then
- if v.switchedButton == true then
- if not v.autoSwitch then
- if v.buttonPressed == false then
- v.buttonPressed = true
- else
- v.buttonPressed = false
- end
- else
- v.buttonPressed = true
- end
- term.clear()
- drawButtons()
- end
- v.func()
- end
- end
- end
- end
- drawButtons()
- searchButton()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement