Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local event = require('event')
- local term = require('term')
- local c = require('component')
- local gpu = c.gpu
- local serialization = require('serialization')
- local unicode=require('unicode')
- local m = c.tunnel
- local shell=require('shell')
- rz=0
- page=1
- local logFile = 'logs.txt'
- fls=io.open(logFile,'w') fls:write('{}') fls:close()
- ------------{settings}-----------
- local exitWord ='Выход'
- local refreshWord='Обн.Кр.'
- color ={back=0x000000 ,button=123123 , ex=0xFF0000, err=0xFF0000,fore=0xFFFFFF,refresh=0xFFA500,tabl=0x898989}
- ----------------------------------
- oldFore=gpu.getForeground() oldBack=gpu.getBackground()
- A,B=gpu.getResolution() gpu.setBackground(color.back) amountButtons={}
- k=B
- k1=1
- local x1,y1,w1,h1=A-15,1,1,3 -- |>|
- local x2,y2,w2,h2=A-20,1,1,3 -- |<|
- local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
- local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
- function clr() gpu.setBackground(color.back) gpu.setForeground(color.fore) term.clear() end
- --buttons=loadTbl('bcr.txt')
- function aut()
- gpu.setBackground(color.tabl)
- gpu.setForeground(0xFFFF00)
- gpu.fill(1,1,A,1,' ')
- gpu.set(40,1,'Авторы [MeXaN1K] & [vah|PandaDoddo72Rus]')
- gpu.setForeground(color.fore)
- gpu.setBackground(color.back)
- gpu.setBackground(color.tabl)
- gpu.set(A-8,1,'Page: '..page)
- gpu.set(x1,y1,'|>|')
- gpu.set(x2,y2,'|<|')
- gpu.setBackground(color.back)
- end
- function rbst()
- aut()
- gpu.fill(A-31,2,1,B,'|')
- gpu.setBackground(color.tabl)
- gpu.setForeground(0xFFFF00)
- gpu.fill(A-30,B,30+1,1,' ')
- gpu.set(A-24,B,'[Robot]: ')
- if rz == 0 then gpu.setForeground(0x00FF00) gpu.set(A-15,B,'Ready!')
- else gpu.setForeground(0xFF0000) gpu.set(A-15,B,' Busy!') end
- gpu.setBackground(color.back)
- gpu.setForeground(color.fore)
- end
- function addLog(mess)
- flg=loadTbl(logFile)
- flg[#flg+1]=mess
- saveTbl(flg,logFile)
- end
- function getxy() key,_,p1,p2,_,message=event.pull() end
- function wait()
- aut()
- rz=1
- rbst()
- me=true
- chi=2
- buttonDraw()
- gpu.setBackground(color.tabl) gpu.setForeground(color.fore)
- gpu.fill(1,2,55,B,' ')
- gpu.fill(55,1,1,B,'|')
- gpu.set(1,chi,'[log]:')
- while me do
- lp=messCatch()
- if lp=='exit' then clr() me=false end
- if lp~=nil then
- chi=chi+1
- gpu.set(1,chi,' > '..lp) end
- if lp == 'finish' then
- os.sleep(1.5)
- rz=0
- me=false
- end
- end
- clr() rbst() buttonDraw()
- end
- function buttonDraw()
- clr()
- aut()
- buttons=loadTbl('bcr.txt')
- term.clear()
- rbst()
- posi=1
- for i=k1,k-2 do
- posi=posi+1
- gpu.setBackground(color.back)
- if buttons[i]~=nil then
- if buttons[i]==exitWord then gpu.setBackground(color.ex) elseif buttons[i]==refreshWord then gpu.setBackground(color.refresh) else gpu.setBackground(color.button) end
- if buttons[i] ~=nil then gpu.fill(A-30,posi,A-(A-30)+1,1,' ') gpu.set(A-30,posi,buttons[i]) end
- end
- end
- gpu.setBackground(color.back)
- end
- function messCatch()
- key,_,p1,p2,_,message=event.pull()
- if key=='modem_message' then
- addLog(message)
- return message
- elseif key=='touch' then
- if p1>55 then buttonDraw() return 'exit' end
- end
- end
- function motionCatch()
- aut()
- a,b=nil,nil
- key,_,p1,p2,_,message=event.pull()
- rbst()
- if key=='modem_message' then
- addLog(message)
- a1=string.sub(message,1,3)
- b1=string.sub(message,4)
- if message=='start' then
- rz=1
- wait()
- elseif message=='finish' then
- rz=0
- buttonDraw()
- elseif a1=='add' then
- buti=loadTbl('bcr.txt')
- buti[#buti+1]=b1
- saveTbl(buti,'bcr.txt')
- clr() rbst() buttonDraw()
- elseif a1=='del' then
- buti=loadTbl('bcr.txt')
- b1=tostring(b1)
- buti2={}
- for i=1,#buti do
- if buti[i]~=b1 then buti2[#buti2+1]=buti[i] end
- end
- saveTbl(buti2,'bcr.txt')
- end
- clr() rbst() buttonDraw()
- elseif key=='touch' then
- if p1 > x1-1 and p1 < x1+w1+1 and p2 > y1-1 and p2 < h1+y1 then
- buttons=loadTbl('bcr.txt')
- mp=math.ceil(#buttons/(B-2))
- page=page+1
- if mp<page then page=mp
- else
- k=k+B
- k1=k1+(B-2)
- end
- clr() rbst() buttonDraw()
- elseif p1 > x2-1 and p1 < x2+w2+1 and p2 > y2-1 and p2 < h2+y2 then
- buttons=loadTbl('bcr.txt')
- k=k-B
- k1=k1-(B-2)
- if k1<1 then k1=1 end
- if k<B then k=B end
- page=page-1
- if page<1 then page=1 end
- clr() rbst() buttonDraw()
- elseif p1>A-30 and p2<B-1 and p2>1 then
- gpu.setBackground(color.back)
- if p2==B-1 then
- b=buttons[(p2-1)*page]
- else
- b=buttons[(p2-1)*page]
- end
- if b==exitWord then gpu.setBackground(oldBack) gpu.setForeground(oldFore) term.clear() os.exit()
- elseif b==refreshWord then clr() rbst() buttonDraw() else
- term.setCursor(10,5)
- io.write("Введите количество: ")
- a=io.read() a=tonumber(a) if a > 64 then a=64 term.setCursor(10,6) gpu.setForeground(color.err) io.write("Недопустимое число! [Больше 64:измененно на 64]") os.sleep(3)
- elseif a==0 then gpu.setForeground(color.err) io.write("Недопустимое число! [Равно нулю]") os.sleep(3)
- elseif a<0 then gpu.setForeground(color.err) io.write("Недопустимое число! [Отрицательное число]") os.sleep(3) end
- gpu.setForeground(color.fore)
- if b~=nil then
- a=tostring(a)
- a=string.gsub(a,'\n','')
- a=tonumber(a)
- if a<10 then mes="0"..a..b else mes=a..b end
- if a~=0 and a>0 then m.send(mes) end
- end
- end
- end
- end
- rbst()
- return message
- end
- getxy()
- buttonDraw()
- while true do
- motionCatch()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement