Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cmp = require('component')
- local event = require('event')
- local serialization = require('serialization')
- local gpu=cmp.gpu
- local filesystem=require('filesystem')
- local term =require('term')
- local computer = require('computer')
- local unicode = require('unicode')
- local draw = {}
- function draw.colorSelector(txt)
- oldBac=gpu.getBackground()
- buttonsSelector={
- {54,20,1,1}, --<settings>
- {55,20,1,1},
- {56,20,1,1},
- {57,20,1,1},
- {58,20,1,1},
- {59,20,1,1},
- {54,22,1,1},
- {55,22,1,1},
- {56,22,1,1},
- {57,22,1,1},
- {58,22,1,1},
- {59,22,1,1},
- {65,21,20,3}, --</settings>
- }
- local colorPos1 = 0
- local colorPos2 = 0
- local colorPos3 = 0
- local colorPos4 = 0
- local colorPos5 = 0
- local colorPos6 = 0
- local function F16(n)
- N=nil
- if n > 9 then
- if n==10 then
- N = 'A'
- elseif n == 11 then
- N = 'B'
- elseif n == 12 then
- N = 'C'
- elseif n == 13 then
- N = 'D'
- elseif n == 14 then
- N = 'E'
- elseif n == 15 then
- N = 'F'
- else N = n
- end
- end
- if N == nil then N=n end
- return N
- end
- draw.field(30,15,60,11,' ',0x505050,0x505050)
- draw.clound('┌','┐','└','┘','│','─',30,15,60,11,0x505050,0xFFFFFF)
- draw.text(40,17,40,txt,0x505050,0xFFFFFF)
- gpu.setBackground(0)
- gpu.set(52,21,'0x')
- gpu.set(54,21,'000000')
- draw.field(47,21,2,1,' ',0,0x505050)
- draw.clound('┌','┐','└','┘','│','─',46,20,4,3,0x505050,0xFFFFFF)
- gpu.setBackground(0x505050)
- gpu.setForeground(0xFFAA00)
- gpu.set(54,20,'▲▲▲▲▲▲')
- gpu.set(54,22,'▼▼▼▼▼▼')
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x898989)
- gpu.fill(64,20,20,3,' ')
- gpu.set(73,21,'OK')
- gpu.setBackground(0x505050)
- gpu.setBackground(oldBac)
- newColor=0
- while true do
- local key,posSettingMenu,clickMouse,name = draw.getRawEvent(buttonsSelector)
- if key == 'touch' then
- if posSettingMenu > 0 and posSettingMenu < 13 then
- if posSettingMenu == 1 then
- colorPos1 = colorPos1+1
- elseif posSettingMenu == 2 then
- colorPos2 = colorPos2+1
- elseif posSettingMenu == 3 then
- colorPos3 = colorPos3 + 1
- elseif posSettingMenu == 4 then
- colorPos4 = colorPos4 + 1
- elseif posSettingMenu == 5 then
- colorPos5 = colorPos5 + 1
- elseif posSettingMenu == 6 then
- colorPos6 = colorPos6 + 1
- elseif posSettingMenu == 7 then
- colorPos1 = colorPos1-1
- elseif posSettingMenu == 8 then
- colorPos2 = colorPos2-1
- elseif posSettingMenu == 9 then
- colorPos3 = colorPos3 - 1
- elseif posSettingMenu == 10 then
- colorPos4 = colorPos4 - 1
- elseif posSettingMenu == 11 then
- colorPos5 = colorPos5 - 1
- elseif posSettingMenu == 12 then
- colorPos6 = colorPos6 - 1
- end
- if colorPos1 > 15 then
- colorPos1 = 15
- elseif colorPos2 > 15 then
- colorPos2 = 15
- elseif colorPos3 > 15 then
- colorPos3 = 15
- elseif colorPos4 > 15 then
- colorPos4 = 15
- elseif colorPos5 > 15 then
- colorPos5 = 15
- elseif colorPos6 > 15 then
- colorPos6 = 15
- end
- if colorPos1 < 0 then
- colorPos1 = 0
- elseif colorPos2 < 0 then
- colorPos2 = 0
- elseif colorPos3 < 0 then
- colorPos3 = 0
- elseif colorPos4 < 0 then
- colorPos4 = 0
- elseif colorPos5 < 0 then
- colorPos5 = 0
- elseif colorPos6 < 0 then
- colorPos6 = 0
- end
- local F1=F16(colorPos1)
- local F2=F16(colorPos2)
- local F3=F16(colorPos3)
- local F4=F16(colorPos4)
- local F5=F16(colorPos5)
- local F6=F16(colorPos6)
- gpu.setBackground(0)
- gpu.set(54,21,tostring(F1..F2..F3..F4..F5..F6))
- newColor=tonumber('0x'..F1..F2..F3..F4..F5..F6)
- draw.field(47,21,2,1,' ',newColor,0x505050)
- draw.clound('┌','┐','└','┘','│','─',40,46,4,3,0x505050,0xFFFFFF)
- gpu.setBackground(0x505050)
- gpu.setBackground(oldBac)
- end
- if posSettingMenu == 13 then
- gpu.setBackground(oldBac)
- term.clear()
- break
- end
- end
- end
- gpu.setBackground(oldBac)
- return newColor
- end
- function draw.enter(x,y,w,h,mode,color_back,color_fore)
- function drawTextInPass(x,y,w,h,txt,col)
- draw.field(x+1,y+1,w-1,1,' ',color_back,color_fore)
- draw.text(x+1,y+1,h-2,txt,color_back,col)
- end
- draw.field(x,y,w,h,' ',color_back,color_fore)
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- local function getKey(s)
- local _, _, _, code, _ = event.pull("key_up")
- return code
- end
- local function enterPass()
- try = ""
- ex=true
- while ex do
- local err, f = pcall(getKey)
- if not err then
- return err, try
- end
- if keyboard.keys[f] == 'grave' then ex=false end
- if f < 60 and f > 0 then
- if keyboard.keys[f] == 'enter' then
- return err, try
- end
- if keyboard.keys[f] == 'back' then
- if unicode.len(try) > 0 then
- try=unicode.sub(try,0,unicode.len(try)-1)
- if mode == 'pass' then
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- end
- drawTextInPass(x,y,w,h,try2,color_fore)
- elseif mode ~= 'pass' then
- drawTextInPass(x,y,w,h,try,color_fore)
- end
- end
- end
- if unicode.len(keyboard.keys[f]) == 1 and unicode.len(try) < 28 then
- try = try..keyboard.keys[f]
- if mode == 'pass' then
- if try ~= nil then
- try2='' for l=1,unicode.len(try) do try2=try2..'*' end
- drawTextInPass(x,y,w,h,try2,color_fore)
- end
- elseif mode ~= 'pass' then
- drawTextInPass(x,y,w,h,try,color_fore)
- end
- end
- end
- end
- end
- while true do
- err, try = enterPass()
- if try == try then -- success
- break
- elseif try == "cancel" then -- admin pass
- break
- end
- end
- return try
- end
- function draw.err(text,mode,SleepTime)
- draw.field(30,13,60,9,' ',0x505050,0x505050)
- if mode == 1 then
- errColor=0xFFFFFF
- elseif mode == 2 then
- errColor = 0xAA0000
- elseif mode == 3 then
- errColor = 0xFFAA00
- end
- draw.clound('┌','┐','└','┘','│','─',30,13,60,9,0x505050,errColor)
- draw.text(32,17,56,text,0x505050,0xFFFFFF)
- if SleepTime ~= 0 then
- os.sleep(SleepTime)
- end
- end
- function draw.fileList(backColor,ForeColor,x,y,w,h,topText,arr,mode,name,page,colorSelectFore,colorSelectBack)
- local oldF=gpu.getForeground()
- local oldB=gpu.getBackground()
- draw.field(x,y,w,h,' ',backColor,ForeColor)
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,backColor,ForeColor)
- draw.text(x,y,w,topText,backColor,ForeColor)
- gpu.setForeground(ForeColor)
- gpu.setBackground(backColor)
- local filesInList=y+h-2
- local filesInListLen=x+w-2
- local p = 1+page
- local k = p+filesInList-4
- local pos = 0
- if mode == 1 then
- for j=p,k-1 do
- if arr[j]~= nil and arr[j]==name then
- gpu.setForeground(colorSelectFore)
- gpu.setBackground(colorSelectBack)
- gpu.fill(x+1,y+pos,w-2,1,' ')
- gpu.set(x+1,y+pos,unicode.sub(arr[j],0,w-2))
- gpu.setForeground(ForeColor)
- gpu.setBackground(backColor)
- pos=pos+1
- elseif arr[j]~= name and arr[j]~= nil then
- gpu.fill(x+1,y+1+pos,w-2,1,' ')
- gpu.set(x+1,y+1+pos,unicode.sub(arr[j],0,w-2))
- pos=pos+1
- end
- end
- elseif mode == 2 then
- for j=p,k-1 do
- if arr[j]~= nil then
- gpu.fill(x+1,y+1+pos,w-2,1,' ')
- gpu.set(x+1,y+1+pos,unicode.sub(arr[j],0,w-2))
- pos=pos+1
- end
- end
- end
- gpu.setForeground(oldF)
- gpu.setBackground(oldB)
- end
- function draw.getRawEvent(arr)
- local N = nil
- local key,_,x,y,clickMouse,name=event.pull()
- if key ~= 'scroll' then
- for i=1,#arr do
- if x > arr[i][1]-1 and x < arr[i][1]+arr[i][3] and y > arr[i][2]-1 and y < arr[i][2]+arr[i][4] then
- N=i
- break
- end
- end
- end
- if N == nil then
- N = 0
- end
- return key,N,clickMouse,name
- end
- function draw.button(buttons,N)
- oldFore=gpu.getForeground()
- oldBack=gpu.getBackground()
- if pos== N then
- gpu.setForeground(buttons[N][11])
- gpu.setBackground(buttons[N][10])
- else
- gpu.setForeground(buttons[N][9])
- gpu.setBackground(buttons[N][8]) end
- gpu.fill(buttons[N][1],buttons[N][2],buttons[N][3],buttons[N][4],' ')
- gpu.setForeground(buttons[N][9])
- gpu.set(buttons[N][6],buttons[N][7],buttons[N][5])
- gpu.setForeground(oldFore)
- gpu.setBackground(oldBack)
- end
- function draw.field(x,y,w,h,s,c1,c2)
- oldBack=gpu.getBackground()
- oldFore=gpu.getForeground()
- gpu.setBackground(c1)
- gpu.setForeground(c2)
- gpu.fill(x,y,w,h,s)
- gpu.setBackground(oldBack)
- gpu.setForeground(oldFore)
- end
- function draw.frame(color,frames,N)
- gpu.setBackground(color)
- gpu.fill(1,1,A,1,' ')
- for i=1,#frames[N] do
- drawButton(frames[N][i])
- end
- end
- function draw.clound(s,s2,s3,s4,s5,s6,x,y,w,h,c1,c2)
- oldFore=gpu.getForeground()
- oldBack=gpu.getBackground()
- gpu.setBackground(c1)
- gpu.setForeground(c2)
- gpu.set(x,y,s)
- gpu.fill(x+1,y,w-1,1,s6)
- gpu.set(x,y+h-1,s3)
- gpu.fill(x,y+1,1,h-2,s5)
- gpu.fill(x+w-1,y+1,1,h-2,s5)
- gpu.set(x+w-1,y,s2)
- gpu.fill(x+1,y+h-1,w-2,1,s6)
- gpu.set(x+w-1,y+h-1,s4)
- gpu.setBackground(oldBack)
- gpu.setForeground(oldFore)
- end
- function draw.exit(C,D,OldResX,OldResY)
- gpu.setBackground(C)
- gpu.setForeground(D)
- gpu.setResolution(OldResX,OldResY)
- term.clear()
- end
- function draw.text(x,y,leght,txt,col_back,col_fore)
- local oldB=gpu.getBackground()
- local oldF=gpu.getForeground()
- local txt = tostring(txt)
- gpu.setBackground(col_back)
- gpu.setForeground(col_fore)
- if unicode.len(txt) > leght then
- txt=unicode.sub(txt,0,leght)
- end
- gpu.set(x+math.floor((leght-unicode.len(txt))/2),y,txt)
- gpu.setBackground(oldB)
- gpu.setForeground(oldF)
- end
- function draw.emptyField(frame,mode,txt)
- gpu.setBackground(0x505050)
- if mode == 1 then
- drawFrame(frame)
- elseif mode == 2 then
- draw.field(1,1,120,1,' ',0x505050,0x505050)
- draw.field(1,2,120,1,'▀',0xDCDCDC,0x505050)
- draw.field(1,3,120,37,' ',0xDCDCDC,0x505050)
- end
- draw.field(1,4,120,38,' ',0xDCDCDC,0x505050)
- draw.field(1,40,120,1,' ',0x505050,0x505050)
- draw.field(1,39,120,1,'▄',0xDCDCDC,0x505050)
- gpu.set(3,40,txt)
- gpu.set(90,40,'Autor: PandaDoddo72Rus (vah)')
- end
- function draw.buttonsCatch(frames,buttons,N,mode)
- if pos~=nil then oldPos=pos end
- pos = nil
- local _,_,p1,p2,_,nick=event.pull('touch')
- for i=1,#frames[N] do
- if p1 > buttons[frames[N][i]][1]-1 and p1 < buttons[frames[N][i]][1]+buttons[frames[N][i]][3] and p2 > buttons[frames[N][i]][2]-1 and p2 < buttons[frames[N][i]][2]+buttons[frames[N][i]][4] then
- pos=i break
- end
- end
- if mode == 1 then
- if pos==nil then pos=oldPos end
- elseif mode == 2 then
- if pos==nil then pos=0 end
- end
- return pos,nick
- end
- return draw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement