Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local reactor = component.br_reactor
- local event = require("event")
- local gpu = component.gpu
- local unicode = require("unicode")
- local term = require("term")
- --function script
- function powerOn()
- reactor.setActive(true)
- end
- function powerOff()
- reactor.setActive(false)
- end
- while true do
- local energyy = reactor.getEnergyStored()
- if energyy == 9000000 then
- reactor.setActive(false)
- else
- reactor.setActive(true)
- end
- if energyy <= 50000 then
- reactor.setActive(true)
- else
- reactor.setActive(false)
- end
- end
- --function script
- --function button
- --function button
- --button
- buttons = { button = {x=16, y=4, text="Вкл", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = powerOn, height=7, cFore = 0xFFFFFF, cBack = 0x0000FF},
- button2 = {x=32, y=4, text="Выкл", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = powerOff, height=7, cFore = 0xFFFFFF, cBack = 0x0000FF},
- button3 = {x=64, y=4, text="debug", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = oninfinity, height=7, cFore = 0xFFFFFF, cBack = 0x0000FF}}
- --button
- --monitor
- function initButtons()
- for k,v in pairs(buttons) do
- v.width = unicode.wlen(v.text) + 2
- end
- end
- initButtons()
- function drawButtons()
- term.clear()
- 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+1, v.y, v.text)
- elseif v.height%2 == 0 then -- если высота кнопки равна четному числу
- gpu.set(v.x+1, v.y + (v.height/2 - 1), v.text)
- elseif v.height%2 == 1 then -- если высота кнопки равна нечетному числу
- gpu.set(v.x+1, 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 searchButton()
- while true do
- 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()--monitor
Add Comment
Please, Sign In to add comment