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
- buttons={}
- ------------{settings}-----------
- local exitWord ='Выход'
- local refreshWord='Обн.Кр.'
- color ={back=0x000000 ,button=123123 , ex=0xFF0000, err=0xFF0000,fore=0xFFFFFF,refresh=0xFFA500}
- x={1} y={2} w={1} h=3
- ----------------------------------
- oldFore=gpu.getForeground() oldBack=gpu.getBackground()
- A,B=gpu.getResolution() gpu.setBackground(color.back) amountButtons={}
- 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 check() ba1=loadTbl('bcr.txt') for i=1,#ba1 do buttons[i]=ba1[i] end bf=loadTbl('but.txt') ab=#buttons if bf[1] == ab then else bf[1]=ab saveTbl(bf,'but.txt') reCalc() end saveTbl(bf,'but.txt') end
- function buttonDraw()
- bf=loadTbl('but.txt')
- term.clear()
- for i=2,#buttons do
- nbt=buttons[i]
- nbt1=bf[nbt]
- nx=nbt1[1] ny=nbt1[2] nw=nbt1[3]
- gpu.setBackground(color.back)
- if buttons[i]==exitWord then gpu.setBackground(color.ex) elseif buttons[i]==refreshWord then gpu.setBackground(color.refresh) else gpu.setBackground(color.button) end
- gpu.fill(nx,ny,nw,3,' ') gpu.set(nx+1,ny+1,buttons[i])
- end
- gpu.setBackground(color.back)
- end
- function motionCatch()
- key,_,p1,p2,_,message=event.pull()
- if key=='modem_message' then
- a1=string.sub(message,1,3)
- b1=string.sub(message,4)
- if a1=='add' then
- buti=loadTbl('bcr.txt')
- buti[#buti+1]=b1
- saveTbl(buti,'bcr.txt')
- elseif a1=='del' then
- buti=loadTbl('bcr.txt')
- for i=2,#buti do
- if buti[i]==b1 then buti[i]=del end
- end
- saveTbl(buti,'bcr.txt')
- end
- else
- for i=1,#buttons do
- nbt=buttons[i]
- nbt1=bf[nbt]
- nx=nbt1[1] ny=nbt1[2] nw=nbt1[3]
- if p1 >nx-1 and p1<nx+nw+1 and p2 > ny-1 and p2<ny+h-1 then
- gpu.setBackground(color.back)
- term.clear()
- b=buttons[i]
- if b==exitWord then gpu.setBackground(oldBack) gpu.setForeground(oldFore) term.clear() os.exit() end
- if b==refreshWord then check() break end
- 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)
- 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
- function reCalc()
- bf=loadTbl('but.txt')
- bf={ab}
- saveTbl(bf,'but.txt')
- if x[2] ~= nil then for i=2,#buttons do x[i]=del y[i]=del w[i]=del end end
- for i=1,#buttons do
- bl=unicode.len(buttons[i])
- if i>1 then w[#w+1]=bl+2 else w[i]=bl+2 end
- if i>1 then x[#x+1]=x[i-1]+unicode.len(buttons[i-1])+4 y[i]=y[i-1] end
- if i>1 then if x[i]+w[i] > A then x[i]=x[1] y[i]=y[i-1]+4 end end
- bf1=buttons[i]
- bf[bf1]={x[i],y[i],w[i]}
- saveTbl(bf,'but.txt')
- end
- end
- check()
- while true do
- buttonDraw()
- motionCatch()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement