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 A,B = gpu.getResolution()
- local oldBac=gpu.getBackground()
- local oldFore = gpu.getForeground()
- --local testFile='../maps/'..MapsName
- local testFile='../test'
- local unicode = require('unicode')
- local shell=require('shell')
- term.clear()
- function colorSelector(txt)
- buttonsSelector={
- {53,20,1,1}, --<settings>
- {54,20,1,1},
- {55,20,1,1},
- {56,20,1,1},
- {57,20,1,1},
- {58,20,1,1},
- {53,22,1,1},
- {54,22,1,1},
- {55,22,1,1},
- {56,22,1,1},
- {57,22,1,1},
- {58,22,1,1},
- {64,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
- drawField(30,15,60,11,' ',0x505050,0x505050)
- drawClound('┌','┐','└','┘','│','─',30,15,60,11,0x505050,0xFFFFFF)
- drawText(40,17,40,txt,0x505050,0xFFFFFF)
- gpu.setBackground(0)
- gpu.set(52,21,'0x')
- gpu.set(54,21,'000000')
- drawField(47,21,2,1,' ',0,0x505050)
- drawClound('┌','┐','└','┘','│','─',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 = 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)
- drawField(47,21,2,1,' ',newColor,0x505050)
- drawClound('┌','┐','└','┘','│','─',40,46,4,3,0x505050,0xFFFFFF)
- gpu.setBackground(0x505050)
- gpu.setBackground(oldBac)
- end
- if posSettingMenu == 13 then
- gpu.setBackground(oldBac)
- term.clear()
- -- map=loadTbl(testFile)
- break
- end
- end
- end
- gpu.setBackground(oldBac)
- return newColor
- end
- local function drawButtonAddMenu(arr,i)
- drawField(arr[i][1],arr[i][2],arr[i][3],1,'▄',arr[i][4],arr[i][5])
- drawField(arr[i][1],arr[i][2]+1,arr[i][3],1,' ',arr[i][5],arr[i][5])
- drawField(arr[i][1],arr[i][2]+2,arr[i][3],1,'▄',arr[i][5],arr[i][4])
- end
- function getRawEvent(arr)
- local N = nil
- local key,_,x,y,clickMouse,name=event.pull()
- for i=1,#arr do
- if x > arr[i][1]-1 and x < arr[i][1]+arr[i][3]+1 and y > arr[i][2]-1 and y < arr[i][2]+arr[i][4]+1 then
- N=i
- break
- end
- end
- if N == nil then
- N = 0
- end
- return key,N,clickMouse,name
- end
- function drawText(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(oldBac)
- gpu.setForeground(oldF)
- end
- function drawClound(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(oldBac)
- gpu.setForeground(oldFore)
- end
- function drawField(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(oldBac)
- gpu.setForeground(oldFore)
- end
- function getxy()
- local key,_,x,y,clickMouse,name=event.pull()
- return key,x,y,clickMouse
- end
- 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
- -------
- map=loadTbl(testFile)
- -------
- function checkBrick(arr,x,y)
- N=nil
- for i=1,#arr do
- if x > arr[i][1]-1 and x < arr[i][1]+arr[i][3]+1 and y > arr[i][2]-1 and y < arr[i][2]+arr[i][4]+1 then
- N=i
- break
- end
- end
- if N == nil then
- N=0
- end
- return N
- end
- function drawAllBrick()
- map=loadTbl(testFile)
- for i=1,#map do
- drawBrick(map,i)
- end
- end
- function drawBrick(arr,N)
- gpu.setBackground(arr[N][5])
- gpu.fill(arr[N][1],arr[N][2],arr[N][3],arr[N][4],' ')
- gpu.setBackground(oldBac)
- end
- map=loadTbl(testFile)
- drawAllBrick()
- arrBonus={'empty','double_damage','freeze_speed_ball','double_ball'}
- function drawObjectSettings(N)
- if map[N] ~= nil then
- durability=map[N][6]
- brickColor=map[N][5]
- bonus=1
- buttonsSetting={
- {32,6,6,0x505050,0}, -- dur field
- {17,9,34,0x505050,0}, -- bonus field
- {25,6,5,0x505050,0xFFAA00}, -- - dur
- {40,6,5,0x505050,0xFFAA00}, -- + dur
- {30,14,24,0x505050,0xAA0000}, -- del
- {30,17,24,0x505050,123123}, -- OK
- }
- buttonsFrameBrickSettings={
- {17,9,34,3}, -- bonus field
- {25,6,5,3}, -- - dur
- {40,6,5,3}, -- + dur
- {30,14,24,3}, -- del
- {30,17,24,3}, -- OK
- {10,14,14,7} -- color selector
- }
- function drawObjSettings(N)
- drawField(3,3,60,20,' ',0x505050,0x505050)
- drawClound('┌','┐','└','┘','│','─',3,3,60,20,0x505050,0xFFFFFF)
- drawText(4,3,58,'[Свойства кирпича]',0x505050,0xFFFFFF)
- for i=1,6 do
- drawButtonAddMenu(buttonsSetting,i)
- end
- drawText(17,10,34,arrBonus[bonus],0,0xFFFFFF)
- drawText(32,7,6,durability,0,0xFFFFFF)
- gpu.setBackground(0x505050)
- gpu.setForeground(0xFFFFFF)
- gpu.set(10,7,'Прочность: ')
- gpu.set(10,10,'Бонус: ')
- drawText(30,15,24,'Удалить кирпич',0xAA0000,0xFFFFFF)
- drawText(30,18,24,'Принять',123123,0xFFFFFF)
- gpu.setBackground(0xFFAA00)
- gpu.set(27,7,'-')
- gpu.set(42,7,'+')
- gpu.setBackground(0x505050)
- drawClound('┌','┐','└','┘','│','─',10,14,14,7,0x505050,0xFFFFFF)
- drawField(11,15,12,5,' ',brickColor,0x505050)
- drawText(10,14,14,'[Цвет]',0x505050,0xFFFFFF)
- gpu.setBackground(oldBac)
- end
- drawObjSettings(N)
- while true do
- local key,buttonInBrickFrame,clickMouse,name = getRawEvent(buttonsFrameBrickSettings)
- if key == 'touch' then
- if buttonInBrickFrame==1 then
- bonus=bonus+1
- if bonus>#arrBonus then
- bonus=bonus-#arrBonus
- end
- drawField(17,10,34,1,' ',0,0x505050)
- drawText(17,10,34,arrBonus[bonus],0,0xFFFFFF)
- elseif buttonInBrickFrame==2 then
- durability=durability-1
- if durability < 0 then
- durability=0
- end
- drawField(32,7,6,1,' ',0,0x505050)
- drawText(32,7,6,durability,0,0xFFFFFF)
- elseif buttonInBrickFrame==3 then
- durability=durability+1
- if durability > 9999 then
- durability=9999
- end
- drawField(32,7,6,1,' ',0,0x505050)
- drawText(32,7,6,durability,0,0xFFFFFF)
- elseif buttonInBrickFrame==4 then
- fakeMap={}
- k=0
- for i=1,#map do
- if i~=N then
- k=k+1
- fakeMap[k]={map[i][1],map[i][2],map[i][3],map[i][4],map[i][5],map[i][6],map[i][7]}
- end
- end
- shell.execute('del '..testFile)
- saveTbl(fakeMap,testFile)
- map=loadTbl(testFile)
- gpu.setBackground(oldBac)
- term.clear()
- drawAllBrick()
- break
- elseif buttonInBrickFrame==5 then
- map[N]={map[N][1],map[N][2],map[N][3],map[N][4],brickColor,durability,arrBonus[bonus]}
- saveTbl(map,testFile)
- gpu.setBackground(oldBac)
- term.clear()
- map=loadTbl(testFile)
- for i=1,#map do
- drawBrick(map,i)
- end
- break
- elseif buttonInBrickFrame==6 then
- brickColor=colorSelector('Выберете цвет для данного кирпича:')
- drawObjSettings(N)
- end
- end
- end
- end
- end
- while true do
- drawAllBrick()
- local key,x,y,mouseClick=getxy()
- if key == 'touch' then
- click=nil
- if #map~=nil then
- click=checkBrick(map,x,y)
- end
- if click~=nil and click > 0 and #map>0 then
- drawObjectSettings(click)
- else
- gpu.setForeground(0xFFFFFF)
- if mouseClick==0 then
- gpu.setForeground(0xAA0000)
- gpu.set(x,y,'•')
- gpu.setForeground(0xFFFFFF)
- if FirstPosition ~= nil then
- gpu.setForeground(0xAA0000)
- gpu.set(FirstPosition[1],FirstPosition[2],'•')
- end
- if FirstPosition~=nil and FirstPosition[1] ~= x and FirstPosition[2] ~= y then
- if FirstPosition ~= nil then
- gpu.set(FirstPosition[1],FirstPosition[2],' ')
- end
- end
- FirstPosition={x,y}
- elseif mouseClick==1 then
- gpu.setForeground(0x00AA00)
- gpu.set(x,y,'•')
- gpu.setForeground(0xFFFFFF)
- if SecondPosition~= nil then
- gpu.setForeground(0x00AA00)
- gpu.set(SecondPosition[1],SecondPosition[2],'•')
- end
- if SecondPosition~=nil and SecondPosition[1]~=x and SecondPosition[2] ~= y then
- if SecondPosition ~= nil then
- gpu.set(SecondPosition[1],SecondPosition[2],' ')
- end
- end
- SecondPosition={x,y}
- end
- end
- elseif key == 'key_up' then
- if FirstPosition~=nil and SecondPosition ~= nil then
- if y == 28 then
- leght=FirstPosition[1]-SecondPosition[1]
- weight=FirstPosition[2]-SecondPosition[2]
- if leght < 0 then
- leght=leght*(-1)
- end
- if weight < 0 then
- weight=weight*(-1)
- end
- if FirstPosition[1] > SecondPosition[1] then
- mapX=SecondPosition[1]
- else
- mapX=FirstPosition[1]
- end
- if FirstPosition[2] > SecondPosition[2] then
- mapY=SecondPosition[2]
- else
- mapY=FirstPosition[2]
- end
- map[#map+1] = {mapX,mapY,leght+1,weight+1,math.random(100000,16000000),1,'empty'}
- shell.execute('del '..testFile)
- saveTbl(map,testFile)
- FirstPosition=nil
- SecondPosition=nil
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement