Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- transparentIcon = "-"
- args = {...}
- tX, tY = term.getSize()
- -- Table format: painted[x][y] = {bgcolor,text,txtColor}
- function eventHandler()
- while true do
- event = {os.pullEvent()}
- if event[1] == "key" then
- if event[2] == keys.leftCtrl or event[2] == 157 then
- menuStatus = not menuStatus
- writeMenuBar(menuStatus)
- end
- if menuStatus == true then
- if event[2] == keys.right or event[2] == keys.left then
- if menuItemSelected == 1 then
- menuItemSelected = 2
- else
- menuItemSelected = 1
- end
- writeMenuBar(menuStatus)
- elseif event[2] == keys.enter then
- if menuItemSelected == 1 then
- save()
- writeMenuBar(false)
- else
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- error()
- end
- end
- else
- if event[2] == keys.right then
- drawData(offSetX-1,offSetY)
- drawMenu()
- writeMenuBar()
- elseif event[2] == keys.left then
- drawData(offSetX+1,offSetY)
- drawMenu()
- writeMenuBar()
- elseif event[2] == keys.up then
- drawData(offSetX,offSetY+1)
- elseif event[2] == keys.down then
- drawData(offSetX,offSetY-1)
- end
- end
- end
- if event[1] == "mouse_click" or event[1] == "mouse_drag" then
- if event[3] > 2 and event[4] ~= tY then
- insertItem(event[3],event[4],event[2])
- elseif event[4] < 18 and event[4] > 1 then
- if event[3] == 1 then
- bgSelected = 2^(event[4]-2)
- elseif event[3] == 2 then
- tSelected = 2^(event[4]-2)
- end
- drawMenu()
- elseif event[4] == tY - 1 then
- setLetter()
- drawData(offSetX,offSetY)
- drawMenu()
- end
- end
- if event[1] == "char" then
- textSelected = string.sub(event[2],1,1)
- drawMenu()
- end
- --drawData(offSetX,offSetY)
- end
- end
- function setLetter()
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.black)
- for i=1,4 do
- term.setCursorPos(tX/2-11,(tY/2-4)+i)
- term.write(" ")
- end
- term.setCursorPos(tX/2-10,tY/2-2)
- term.write("Change transparancy")
- term.setCursorPos(tX/2-10,tY/2-1)
- term.write("character to: (key)")
- event = {os.pullEvent("char")}
- transparentIcon = event[2]
- end
- function insertItem(xPos,yPos,modeSet)
- if saved == true then
- saved = false
- writeMenuBar(false)
- end
- --bgSelected
- --tSelected
- --textSelected
- if not painted then
- painted = {}
- end
- if not painted[xPos-offSetX] then
- painted[xPos-offSetX] = {}
- end
- if modeSet == 1 then
- if not textSelected then
- textSelected = " "
- end
- TMPtextSelected = textSelected
- painted[xPos-offSetX][yPos-offSetY] = {bgSelected,textSelected,tSelected}
- term.setBackgroundColor(bgSelected)
- term.setTextColor(tSelected)
- else
- TMPtextSelected = transparentIcon
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.gray)
- painted[xPos-offSetX][yPos-offSetY] = nil
- end
- term.setCursorPos(xPos,yPos)
- term.write(TMPtextSelected)
- end
- if #args ~= 1 then
- print("Usage: "..shell.getRunningProgram().." <path>")
- return
- end
- if fs.exists(args[1]) == true then
- buff = fs.open(args[1],"r")
- previousData = buff.readAll()
- buff.close()
- painted = textutils.unserialize(previousData)
- else
- painted = {}
- end
- function save()
- file = fs.open(args[1],"w")
- file.write(textutils.serialize(painted))
- file.close()
- saved = true
- end
- function drawData(xStart, yStart)
- offSetX = xStart
- offSetY = yStart
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.gray)
- transparentLine = ""
- for x=1,tX-2 do
- transparentLine = transparentIcon..transparentLine
- end
- for y=1,tY-1 do
- term.setCursorPos(3,y)
- term.write(transparentLine)
- end
- if not painted then
- painted = {}
- end
- for xPos,v in pairs(painted) do
- --if xPos+xStart > 2 and xPos+yStart < tX+1 then
- for yPos in pairs (painted[xPos]) do
- --if yPos+yStart > 0 and yPos+yStart < tY+1 then
- bgColor = painted[xPos][yPos][1]
- text = painted[xPos][yPos][2]
- tColor = painted[xPos][yPos][3]
- if not tColor then
- tColor = colors.white
- end
- if not text then
- text = " "
- end
- term.setCursorPos(xPos+xStart,yPos+yStart)
- term.setBackgroundColor(bgColor)
- term.setTextColor(tColor)
- term.write(text)
- end
- --end
- end
- -- end
- term.setCursorPos(1,tY)
- end
- function drawMenu()
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- if not bgSelected then
- bgSelected = colors.black
- elseif bgSelected == colors.white then
- term.setTextColor(colors.black)
- end
- if not tSelected then
- tSelected = colors.white
- elseif tSelected == colors.white then
- term.setTextColor(colors.black)
- end
- if not textSelected then
- textSelected = " "
- end
- term.setBackgroundColor(bgSelected)
- term.write("B")
- term.setBackgroundColor(tSelected)
- term.write("T")
- for i=1,16 do
- i=i-1
- term.setCursorPos(1,i+2)
- term.setBackgroundColor(2^i)
- term.write(" ")
- end
- term.setCursorPos(1,18)
- term.setBackgroundColor(colors.black)
- if not textSelected then
- textSelected = " "
- elseif string.len(textSelected) > 1 then
- textSelected = string.sub(textSelected,1,1)
- end
- term.setTextColor(colors.red)
- term.write(">"..textSelected)
- end
- function writeMenuBar(booly)
- menuStatus = booly
- term.setBackgroundColor(colors.black)
- if booly == true then
- term.setCursorPos(1,tY)
- term.clearLine()
- if not menuItemSelected then
- menuItemSelected = 1
- end
- term.setTextColor(colors.white)
- term.write(" Save Exit ")
- term.setCursorPos(6*menuItemSelected-5,tY)
- term.setTextColor(colors.yellow)
- term.write("[")
- term.setCursorPos(6*menuItemSelected,tY)
- term.write("]")
- elseif booly == false then
- term.setCursorPos(1,tY)
- term.setTextColor(colors.yellow)
- term.clearLine()
- if saved == true then
- term.write("Saved to "..args[1])
- else
- term.write("Press Ctrl to access menu")
- end
- end
- end
- menuStatus = false
- saved = false
- writeMenuBar(menuStatus)
- menuItemSelected = 1
- drawData(3,0)
- drawMenu()
- eventHandler()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement