Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bg=2
- --Change this to change the background.
- --The current first line MUST remain the first or this will break itself
- --[[
- Welcome to the GameEngine's Personal Painting Program
- This was invented and developed by
- incinirate, http://www.youtube.com/user/guildwarsmem
- You may modify this, however any
- distribution of this must include
- credit to me
- You may use this in your game development,
- but you must give credit to me
- ]]--
- col={
- [1]='0',
- [2]='1',
- [4]='2',
- [8]='3',
- [16]='4',
- [32]='5',
- [64]='6',
- [128]='7',
- [256]='8',
- [512]='9',
- [1024]='a',
- [2048]='b',
- [4096]='c',
- [8192]='d',
- [16384]='e',
- [32768]='f',
- [0]='g', --This one is for transparent blocks
- }
- colt = {
- ['0']=1,
- ['1']=2,
- ['2']=4,
- ['3']=8,
- ['4']=16,
- ['5']=32,
- ['6']=64,
- ['7']=128,
- ['8']=256,
- ['9']=512,
- ['a']=1024,
- ['b']=2048,
- ['c']=4096,
- ['d']=8192,
- ['e']=16384,
- ['f']=32768,
- ['g']=0, --This one is for transparent blocks
- }
- transp=false
- termx,termy = term.getSize()
- tabs={
- [1]={
- ["x1"]=1,
- ["x2"]=6,
- ["New"]=function()
- if not saved then
- if question("Do you want to save this?") then
- local file = fs.open(docname,"w")
- file.write(serial())
- file.close()
- end
- end
- construct()
- docname = getString("File Name:")
- docx = getString("Width:")
- docy = getString("Height:")
- for i=1,docx do
- doc[i]={}
- for j=1,docy do
- doc[i][j]=0
- end
- end
- top=false
- paint()
- end,
- ["Save"]=function()
- if docname==nil then
- docname=getString("Enter a name for this:")
- end
- local file = fs.open(docname,"w")
- file.write(serial())
- file.close()
- top=false
- paint()
- info("Saved!")
- saved=true
- if Timer==nil then
- Timer1=nil
- Timer = os.startTimer(0.2)
- else
- Timer=nil
- Timer1 = os.startTimer(0.2)
- end
- end,
- ["SaveAs"]=function()
- docname=getString("Enter a name for this:")
- local file = fs.open(docname,"w")
- file.write(serial())
- file.close()
- top=false
- paint()
- info("Saved!")
- saved=true
- if Timer==nil then
- Timer1=nil
- Timer = os.startTimer(0.2)
- else
- Timer=nil
- Timer1 = os.startTimer(0.2)
- end
- end,
- ["Close"]=function()
- if not saved then
- if question("Do you want to save this?") then
- local file = fs.open(docname,"w")
- file.write(serial())
- file.close()
- end
- end
- construct()
- repeat
- menu()
- until not ta
- ta=nil
- paint()
- if Timer==nil then
- Timer1=nil
- Timer = os.startTimer(0.2)
- else
- Timer=nil
- Timer1 = os.startTimer(0.2)
- end
- end,
- ["Exit"]=function()
- if not saved then
- if question("Do you want to save this?") then
- local file = fs.open(docname,"w")
- file.write(serial())
- file.close()
- end
- end
- os.reboot()
- end,
- ["Chng B"]=function()
- info("Pick the background on the right")
- while true do
- e,k,x,y=os.pullEvent("mouse_click")
- if x == termx or x == termx-1 then
- if y~= 19 and y~= 1 and y~= 18 then
- bg=2^(y-2)
- local fil=fs.open(shell.dir().."/"..shell.getRunningProgram(),"r")
- local prgm = {}
- while true do
- local ln=fil.readLine()
- if ln==nil then break end
- table.insert(prgm,ln)
- end
- fil.close()
- local fil=fs.open(shell.dir().."/"..shell.getRunningProgram(),"w")
- fil.writeLine("bg="..bg)
- for i=2,#prgm do
- fil.writeLine(prgm[i])
- end
- fil.close()
- break
- elseif y==18 then
- info("Cannot be transparent")
- end
- end
- end
- if Timer==nil then
- Timer1=nil
- Timer = os.startTimer(0.2)
- else
- Timer=nil
- Timer1 = os.startTimer(0.2)
- end
- end,
- },
- [2]={
- ["x1"]=8,
- ["x2"]=15,
- ["Back"]=function()
- top=false
- paint()
- end
- }
- }
- selcol=1
- --Draw Funcs
- function drawBox(x,y,width,height,col)
- col=col or colors.black --Makes the "col" argument optional
- term.setCursorPos(x,y)
- term.setBackgroundColor(col)
- write(string.rep(" ",width))
- for i=1,height-2 do
- term.setCursorPos(x,y+i)
- write(" ")
- term.setCursorPos(x+width-1,y+i)
- write(" ")
- end
- term.setCursorPos(x,y+height-1)
- write(string.rep(" ",width))
- col=nil
- end
- function fillBox(x,y,width,height,col)
- col=col or colors.lightGray --Makes the "col" argument optional
- term.setBackgroundColor(col)
- for i=1,height do
- term.setCursorPos(x,y+i-1)
- write(string.rep(" ",width))
- end
- end
- --End Draw Funcs
- --Dialogs
- function question(str)
- if #str < 7 then
- drawBox(math.floor(termx/2)-3,math.floor(termy/2)-3,7,7)
- fillBox(math.floor(termx/2)-2,math.floor(termy/2)-2,5,5)
- else
- drawBox(math.floor(termx/2-(#str/2)-2),math.floor(termy/2-3),#str+4,7)
- fillBox(math.floor(termx/2-(#str/2)-1),math.floor(termy/2-2),#str+2,5)
- end
- term.setCursorPos(math.floor(termx/2-(#str/2)),math.floor(termy/2)-1)
- write(str)
- term.setCursorPos(math.floor(termx/2-(#str/2)),math.floor(termy/2)+1)
- term.setBackgroundColor(colors.lime)
- write("Yes")
- term.setCursorPos(math.floor(termx/2+(#str/2))-3,math.floor(termy/2)+1)
- write(" No")
- while true do
- e,p,x,y = os.pullEvent("mouse_click")
- if y==math.floor(termy/2)+1 then
- if x>=math.floor(termx/2+(#str/2))-3 and x<=math.floor(termx/2+(#str/2))-1 then
- return false
- elseif x>=math.floor(termx/2-(#str/2)) and x<=math.floor(termx/2-(#str/2))+2 then
- return true
- end
- end
- end
- end
- function getString(str)
- paint()
- drawBox(math.floor(termx/2-14),math.floor(termy/2)-3,28,7)
- fillBox(math.floor(termx/2-13),math.floor(termy/2)-2,26,5)
- term.setCursorPos(math.floor(termx/2-(#str/2)),math.floor(termy/2)-1)
- write(str)
- term.setBackgroundColor(128)
- term.setCursorPos(math.floor(termx/2)-12,math.floor(termy/2)+1)
- write(" ")
- term.setCursorPos(math.floor(termx/2)-12,math.floor(termy/2)+1)
- local stpos = math.floor(termx/2)-12
- local substr = ""
- local tbpos = 0
- local tbs = 0
- local spos = 0 --Limit: 24
- term.setCursorBlink(true)
- while true do
- e,k = os.pullEvent()
- if e=="key" then
- if k==205 then --Right
- if #substr+1>spos then
- spos=spos+1
- if tbs+23<spos then tbs=tbs+1 else
- tbpos=tbpos+1
- end
- end
- elseif k==203 then --Left
- if 0<spos then
- spos=spos-1
- if tbs>spos then tbs=tbs-1 else
- tbpos=tbpos-1
- end
- end
- elseif k==28 then --Enter
- break
- elseif k==14 then --Backspace
- substr=substr:sub(1,spos-1)..substr:sub(spos+1,#substr)
- if 0<spos then
- spos=spos-1
- if tbs>spos then tbs=tbs-1 else
- tbpos=tbpos-1
- end
- end
- end
- elseif e=="char" then
- substr=substr:sub(1,spos)..k..substr:sub(spos+1,#substr)
- spos=spos+1
- if tbs+24 <= spos then
- tbs=tbs+1
- --if tbpos==23 then
- -- tbs=tbs+1
- --end
- else
- tbpos=tbpos+1
- end
- if tbpos>23 then
- tbpos=23
- end
- end
- term.setCursorPos(stpos,math.floor(termy/2)+1)
- write(" ")
- term.setCursorPos(stpos,math.floor(termy/2)+1)
- write(substr:sub(tbs,tbs+24))
- term.setCursorPos(stpos+24,math.floor(termy/2)+1)
- term.setBackgroundColor(colors.lightGray)
- write(" ")
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(stpos+tbpos,math.floor(termy/2)+1)
- end
- term.setCursorBlink(false)
- return substr
- end
- function info(str)
- if #str < 2 then
- drawBox(math.floor(termx/2)-3,math.floor(termy/2)-3,7,7)
- fillBox(math.floor(termx/2)-2,math.floor(termy/2)-2,5,5)
- else
- drawBox(math.floor(termx/2-(#str/2)-2),math.floor(termy/2-3),#str+4,7)
- fillBox(math.floor(termx/2-(#str/2)-1),math.floor(termy/2-2),#str+2,5)
- end
- term.setCursorPos(math.floor(termx/2-(#str/2)),math.floor(termy/2)-1)
- write(str)
- term.setCursorPos(math.floor(termx/2-1),math.floor(termy/2)+1)
- term.setBackgroundColor(colors.lime)
- write("Ok")
- while true do
- local e,p,x,y = os.pullEvent("mouse_click")
- if x==math.floor(termx/2-1) or x==math.floor(termx/2) then
- if y==math.floor(termy/2)+1 then
- break
- end
- end
- end
- paint()
- end
- --End Dialogs
- function getNumInd(tn)
- local itn=0
- for i,v in pairs(tabs[tsel]) do
- itn=itn+1
- end
- return itn
- end
- function uz(num)
- if num==0 then
- return bg
- end
- return num
- end
- function cht(vart)
- if transp then
- return vart+1
- end
- return vart
- end
- function paint()
- term.setBackgroundColor(bg)
- shell.run("clear")
- --Draw Current Picture
- spot=0
- for i=1,docx do
- for j=1,docy do
- spot=spot+1
- term.setCursorPos(i+scrollx,j+scrolly+1)
- if doc[i][j]==0 then
- if cht(i)%2 == 0 then
- term.setBackgroundColor(uz(256*(j%2)))
- else
- term.setBackgroundColor(uz(256*((j+1)%2)))
- end
- write(" ")
- else
- term.setBackgroundColor(doc[i][j])
- write(" ")
- end
- end
- end
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.gray)
- term.clearLine(1)
- term.setCursorPos(1,1)
- term.write(dtt("File",1)--[[.." "..dtt("Colors",2)]])
- if top then
- local x1 = tabs[tsel]["x1"]
- local x2 = tabs[tsel]["x2"]
- local itn = 1
- for i,v in pairs(tabs[tsel]) do
- if i~="x1" and i~="x2" then
- itn=itn+1
- drawBox(x1,itn,x2-x1+1,1,colors.lightGray)
- term.setCursorPos(x1,itn)
- write(i)
- end
- end
- end
- term.setBackgroundColor(128)
- for i=2,19 do
- term.setCursorPos(termx-2,i)
- write(" ")
- end
- for i=1,16 do
- term.setCursorPos(termx-1,i+1)
- term.setBackgroundColor(2^(i-1))
- write(" ")
- end
- term.setCursorPos(termx-1,18)
- write("XX")
- term.setCursorPos(termx-1,19)
- if selcol ~=0 then
- term.setBackgroundColor(selcol)
- write(" ")
- else
- term.setBackgroundColor(1)
- term.setTextColor(2^15)
- write("X")
- term.setTextColor(1)
- end
- term.setBackgroundColor(2^15)
- write("X")
- end
- function dtt(str,id)
- if selsc(id) then
- return "["..str.."]"
- end
- return "|"..str.."|"
- end
- function selsc(n)
- if n==tsel then
- return true
- end
- return false
- end
- function construct()
- docx=0
- docy=0
- doc={}
- cto=false
- tsel=1
- top=false
- saved=false
- docname=nil
- selcol=1
- scrollx=4
- scrolly=4
- end
- function unserial(handle)
- local fil = fs.open(handle,"r")
- local spr=fil.readAll()
- fil.close()
- i=1
- repeat
- i=i+1
- until spr:sub(i,i) == "/"
- x=spr:sub(1,i-1)
- j=i
- repeat
- j=j+1
- until spr:sub(j,j) == "/"
- y=spr:sub(i+1,j-1)
- local k=j
- local kp=j+1
- local newspr = {}
- for a=1,x do
- newspr[a]={}
- for s=1,y do
- repeat
- k=k+1
- until spr:sub(k,k) == "/"
- newspr[a][s]=colt[spr:sub(kp,k-1)]
- kp=k+1
- end
- end
- return x,y,newspr
- end
- function serial()
- str=docx.."/"..docy.."/"
- for i=1,#doc do
- for j=1,#doc[i] do
- str=str..col[doc[i][j]].."/"
- end
- end
- return str
- end
- ---------------------------------------------
- ---------------------------------------------
- ---------------------------------------------
- --Menu Below Here
- function paintMenu(sel)
- local a,b,c = colors.lime,colors.lime,colors.lime
- if sel==0 then
- a = colors.red
- elseif sel==1 then
- b = colors.red
- else
- c = colors.red
- end
- term.setBackgroundColor(colors.lightGray)
- shell.run("clear")
- fillBox(2,2,termx-2,math.floor(termy/3)-1,a)
- fillBox(2,math.floor(termy/3)+2,termx-2,math.floor(termy/3)-1,b)
- fillBox(2,math.floor((termy/3)*2)+2,termx-2,math.floor(termy/3)-1,c)
- term.setBackgroundColor(a)
- term.setCursorPos(termx/2-#"New File"/2,math.floor(termy/3)-2)
- write("New File")
- term.setBackgroundColor(b)
- term.setCursorPos(termx/2-#"Load File"/2,(math.floor(termy/3)+2)+( -(math.floor(termy/3)-1)+(math.floor(termy/3)+2) )/2+1)
- write("Load File")
- term.setBackgroundColor(c)
- term.setCursorPos(termx/2-#"Exit"/2,(math.floor((termy/3)*2)+2)+( -(math.floor(termy/3)-1)+(math.floor((termy/3)*2)+2) )/2-2)
- write("Exit")
- end
- function menu()
- ta=false
- local sel=0 --0=New, 1=Load, 2=Exit
- while true do
- paintMenu(sel)
- e,k = os.pullEvent("key")
- if k==200 then
- if sel==0 then sel=2 else sel=sel-1 end
- elseif k==208 then
- if sel==2 then sel=0 else sel=sel+1 end
- elseif k==28 then
- break
- end
- end
- if sel==0 then
- docname=getString("Enter Document Name:")
- docx=getString("Enter Width")
- docy=getString("Enter Height")
- for i=1,docx do
- doc[i]={}
- for j=1,docy do
- doc[i][j]=0
- end
- end
- Timer1=os.startTimer(1)
- elseif sel==1 then
- docname=getString("Enter Document Name:")
- if not fs.exists(docname) then
- repeat
- docname=getString("Invalid, Try Again:")
- if not fs.exists(docname) then
- if not question("Invalid again, try again?") then
- ta=true
- end
- end
- until fs.exists(docname) or ta
- end
- if not ta then
- docx,docy,doc = unserial(docname)
- saved=true
- end
- elseif sel==2 then
- os.reboot()
- end
- end
- --Menu Stops Here
- -------------------------------------------
- construct()
- repeat
- menu()
- until not ta
- ta=nil
- paint()
- Timer=os.startTimer(0.2)
- while true do
- e,k,p,o=os.pullEvent()
- if e=="mouse_click" or e=="mouse_drag" then
- if o==1 then
- if p<7 then
- tsel=1
- top=not top
- --elseif p>7 and p<16 then
- -- tsel=2
- -- top=not top
- else
- top=false
- end
- else
- if top and p >= tabs[tsel]["x1"] and p <= tabs[tsel]["x2"] then
- if o < getNumInd() then
- itn=1
- for i,v in pairs(tabs[tsel]) do
- if i~="x1" and i~="x2" then
- itn=itn+1
- if o==itn then
- v()
- end
- end
- end
- end
- elseif p < termx-2 then --Painting
- if o>scrolly+1 and o<scrolly+docy+2 then
- if p>scrollx and p<scrollx+docx+1 then
- --X and Y in
- doc[p-scrollx][o-scrolly-1] = selcol
- saved=false
- end
- end
- elseif p == termx or p == termx-1 then --Selecting Color
- if o~= 19 and o~= 1 then
- if o == 18 then
- selcol=0
- else
- selcol=2^(o-2)
- end
- end
- end
- --all stuff b4 here
- top=false
- end
- elseif e=="key" then
- if k==200 then --UP
- scrolly=scrolly-1
- elseif k==208 then --DOWN
- scrolly=scrolly+1
- elseif k==203 then --LEFT
- scrollx=scrollx-1
- elseif k==205 then --RIGHT
- scrollx=scrollx+1
- end
- elseif e=="timer" then
- if k==Timer then
- transp=not transp
- Timer = nil
- Timer1 = os.startTimer(0.2)
- elseif k==Timer1 then
- transp=not transp
- Timer1 = nil
- Timer = os.startTimer(0.2)
- end
- end
- --All Logic Above Here
- paint()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement