Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GPU Tier 2, Interner card, Wifi card, Tablet Tier 2
- local component = require("component")
- local computer = require("computer")
- local event = require("event")
- local colors = require("colors")
- local unicode = require("unicode")
- local term = require("term")
- local sides = require("sides")
- local gpu = component.gpu
- local modem = component.modem
- local lastResponse = ""
- a = 0
- term.clear()
- function fixedLengthRandom(digits)
- digits = 10 ^ (digits - 1)
- return math.random(digits, digits * 10 - 1)
- end
- ports = math.floor(fixedLengthRandom(4))
- modem.open(ports)
- modem.broadcast(ports, "nanomachines", "setResponsePort", ports)
- function printResponse()
- w, h = component.gpu.getResolution()
- gpu.fill(1, h, w, h, " ")
- gpu.set(1, h, lastResponse)
- end
- function handleModemMessage(_, _, _, _, _, header, command, ...)
- if header ~= "nanomachines" then return end
- lastResponse = "последний ответ: " .. command
- for _, v in ipairs({...}) do
- lastResponse = lastResponse .. ", " .. tostring(v)
- end
- printResponse()
- end
- function funcButton()
- for i = 1, 18 do
- modem.broadcast(ports,"nanomachines","setInput",i,false)
- os.sleep(1)
- end
- end
- function funcButton1()
- if buttons.button1.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",1,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",1,false)
- end
- end
- function funcButton2()
- if buttons.button2.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",2,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",2,false)
- end
- end
- function funcButton3()
- if buttons.button3.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",3,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",3,false)
- end
- end
- function funcButton4()
- if buttons.button4.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",4,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",4,false)
- end
- end
- function funcButton5()
- if buttons.button5.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",5,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",5,false)
- end
- end
- function funcButton6()
- if buttons.button6.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",6,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",6,false)
- end
- end
- function funcButton7()
- if buttons.button7.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",7,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",7,false)
- end
- end
- function funcButton8()
- if buttons.button8.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",8,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",8,false)
- end
- end
- function funcButton9()
- if buttons.button9.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",9,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",9,false)
- end
- end
- function funcButton10()
- if buttons.button10.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",10,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",10,false)
- end
- end
- function funcButton11()
- if buttons.button11.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",11,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",11,false)
- end
- end
- function funcButton12()
- if buttons.button12.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",12,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",12,false)
- end
- end
- function funcButton13()
- if buttons.button13.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",13,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",13,false)
- end
- end
- function funcButton14()
- if buttons.button14.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",14,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",14,false)
- end
- end
- function funcButton15()
- if buttons.button15.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",15,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",15,false)
- end
- end
- function funcButton16()
- if buttons.button16.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",16,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",16,false)
- end
- end
- function funcButton17()
- if buttons.button17.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",17,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",17,false)
- end
- end
- function funcButton18()
- if buttons.button18.buttonPressed == true then
- modem.broadcast(ports,"nanomachines","setInput",18,true)
- else
- modem.broadcast(ports,"nanomachines","setInput",18,false)
- end
- end
- function funcButton19()
- a = 1
- end
- function funcButton20()
- modem.broadcast(ports, "nanomachines","getActiveEffects")
- end
- function funcButton21()
- term.clear()
- drawButtons()
- end
- function funcButton22()
- for v = 1, 18 do
- modem.broadcast(ports,"nanomachines","setInput",v,true)
- os.sleep(1)
- end
- end
- buttons = {button = {x=15, y=20, text="OFF", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton, height=3, cFore = 0xFFFFFF, cBack = 0x0000FF},
- button1 = {x=18, y=4, text=".1", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton1, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button2 = {x=26, y=4, text=".2", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton2, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button3 = {x=34, y=4, text=".3", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton3, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button4 = {x=42, y=4, text=".4", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton4, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button5 = {x=50, y=4, text=".5", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton5, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button6 = {x=58, y=4, text=".6", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton6, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button7 = {x=10, y=10, text=".7", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton7, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button8 = {x=18, y=10, text=".8", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton8, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button9 = {x=26, y=10, text=".9", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton9, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button10 = {x=34, y=10, text="10", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton10, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button11 = {x=42, y=10, text="11", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton11, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button12 = {x=50, y=10, text="12", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton12, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button13 = {x=58, y=10, text="13", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton13, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button14 = {x=66, y=10, text="14", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton14, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button15 = {x=26, y=16, text="15", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton15, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button16 = {x=34, y=16, text="16", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton16, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button17 = {x=42, y=16, text="17", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton17, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button18 = {x=50, y=16, text="18", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton18, height=3, cFore = 0xFFFFFF, cBack = 0xFF0000, cFore1 = 0x000000, cBack1 = 0x00FF00},
- button19 = {x=24, y=20, text="EXIT", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton19, height=3, cFore = 0xFFFFFF, cBack = 0x0000FF},
- button20 = {x=34, y=20, text="GRAPHI", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton20, height=3, cFore = 0xFFFFFF, cBack = 0x0000FF},
- button21 = {x=46, y=20, text="UPDATE", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton21, height=3, cFore = 0xFFFFFF, cBack = 0x0000FF},
- button22 = {x=58, y=20, text="ON", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton22, height=3, cFore = 0xFFFFFF, cBack = 0x0000FF}}
- function initButtons()
- for k,v in pairs(buttons) do
- v.width = unicode.wlen(v.text) + 2
- 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+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(2)
- drawButtons()
- end
- end
- end
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x000000)
- end
- function searchButton()
- while true do
- event.listen("modem_message", handleModemMessage)
- if a == 1 then
- event.ignore("modem_message", handleModemMessage)
- 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