Advertisement
Guest User

test

a guest
Feb 26th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.06 KB | None | 0 0
  1. transparentIcon = "-"
  2.  
  3.  
  4.  
  5. args = {...}
  6. tX, tY = term.getSize()
  7.  
  8.  
  9. -- Table format: painted[x][y] = {bgcolor,text,txtColor}
  10.  
  11. function eventHandler()
  12.  while true do
  13.   event = {os.pullEvent()}
  14.   if event[1] == "key" then
  15.    if event[2] == keys.leftCtrl or event[2] == 157 then
  16.     menuStatus = not menuStatus
  17.     writeMenuBar(menuStatus)
  18.    end
  19.    if menuStatus == true then
  20.     if event[2] == keys.right or event[2] == keys.left then
  21.      if menuItemSelected == 1 then
  22.       menuItemSelected = 2
  23.      else
  24.       menuItemSelected = 1
  25.      end
  26.      writeMenuBar(menuStatus)
  27.     elseif event[2] == keys.enter then
  28.      if menuItemSelected == 1 then
  29.       save()
  30.       writeMenuBar(false)
  31.      else
  32.       term.setTextColor(colors.yellow)
  33.       term.setBackgroundColor(colors.black)
  34.       term.clear()
  35.       term.setCursorPos(1,1)
  36.       error()
  37.      end
  38.     end
  39.    else  
  40.     if event[2] == keys.right then
  41.      drawData(offSetX-1,offSetY)
  42.      drawMenu()
  43.      writeMenuBar()
  44.     elseif event[2] == keys.left then
  45.      drawData(offSetX+1,offSetY)
  46.      drawMenu()
  47.      writeMenuBar()
  48.     elseif event[2] == keys.up then
  49.      drawData(offSetX,offSetY+1)
  50.     elseif event[2] == keys.down then
  51.      drawData(offSetX,offSetY-1)
  52.     end
  53.    end
  54.   end
  55.   if event[1] == "mouse_click" or event[1] == "mouse_drag" then
  56.    if event[3] > 2 and event[4] ~= tY then
  57.     insertItem(event[3],event[4],event[2])
  58.    elseif event[4] < 18 and event[4] > 1 then
  59.     if event[3] == 1 then
  60.      bgSelected = 2^(event[4]-2)
  61.     elseif event[3] == 2 then
  62.      tSelected = 2^(event[4]-2)
  63.     end
  64.     drawMenu()
  65.    elseif event[4] == tY - 1 then
  66.     setLetter()
  67.     drawData(offSetX,offSetY)
  68.     drawMenu()
  69.    end
  70.   end
  71.   if event[1] == "char" then
  72.    textSelected = string.sub(event[2],1,1)
  73.    drawMenu()
  74.   end
  75.   --drawData(offSetX,offSetY)
  76.  end
  77. end
  78.  
  79. function setLetter()
  80.  term.setBackgroundColor(colors.red)
  81.  term.setTextColor(colors.black)
  82.  for i=1,4 do
  83.   term.setCursorPos(tX/2-11,(tY/2-4)+i)
  84.   term.write("                     ")
  85.  end
  86.  term.setCursorPos(tX/2-10,tY/2-2)
  87.  term.write("Change transparancy")
  88.  term.setCursorPos(tX/2-10,tY/2-1)
  89.  term.write("character to: (key)")
  90.  event = {os.pullEvent("char")}
  91.  transparentIcon = event[2]
  92. end
  93.  
  94. function insertItem(xPos,yPos,modeSet)
  95.  if saved == true then
  96.   saved = false
  97.   writeMenuBar(false)
  98.  end
  99. --bgSelected
  100. --tSelected
  101. --textSelected
  102.  if not painted then
  103.   painted = {}
  104.  end
  105.  if not painted[xPos-offSetX] then
  106.   painted[xPos-offSetX] = {}
  107.  end
  108.  if modeSet == 1 then
  109.    if not textSelected then
  110.     textSelected = " "
  111.    end
  112.    TMPtextSelected = textSelected
  113.    painted[xPos-offSetX][yPos-offSetY] = {bgSelected,textSelected,tSelected}
  114.    term.setBackgroundColor(bgSelected)
  115.    term.setTextColor(tSelected)
  116.   else
  117.    TMPtextSelected = transparentIcon
  118.    term.setBackgroundColor(colors.black)
  119.    term.setTextColor(colors.gray)
  120.    painted[xPos-offSetX][yPos-offSetY] = nil
  121.  end
  122.  term.setCursorPos(xPos,yPos)
  123.  term.write(TMPtextSelected)
  124. end
  125.  
  126. if #args ~= 1 then
  127.  print("Usage: "..shell.getRunningProgram().." <path>")
  128.  return
  129. end
  130.  
  131. if fs.exists(args[1]) == true then
  132.  buff = fs.open(args[1],"r")
  133.  previousData = buff.readAll()
  134.  buff.close()
  135.  painted = textutils.unserialize(previousData)
  136.  else
  137.  painted = {}
  138. end
  139.  
  140. function save()
  141.  file = fs.open(args[1],"w")
  142.  file.write(textutils.serialize(painted))
  143.  file.close()
  144.  saved = true
  145. end
  146.  
  147. function drawData(xStart, yStart)
  148.  offSetX = xStart
  149.  offSetY = yStart
  150.  term.setBackgroundColor(colors.black)
  151.  term.setTextColor(colors.gray)
  152.  transparentLine = ""
  153.  for x=1,tX-2 do
  154.   transparentLine = transparentIcon..transparentLine
  155.  end
  156.  for y=1,tY-1 do
  157.   term.setCursorPos(3,y)
  158.   term.write(transparentLine)
  159.  end
  160.  if not painted then
  161.   painted = {}
  162.  end
  163.  for xPos,v in pairs(painted) do
  164.   --if xPos+xStart > 2 and xPos+yStart < tX+1 then
  165.    for yPos in pairs (painted[xPos]) do
  166.     --if yPos+yStart > 0 and yPos+yStart < tY+1 then
  167.     bgColor = painted[xPos][yPos][1]
  168.     text = painted[xPos][yPos][2]
  169.     tColor = painted[xPos][yPos][3]
  170.     if not tColor then
  171.      tColor = colors.white
  172.     end
  173.     if not text then
  174.      text = " "
  175.     end
  176.     term.setCursorPos(xPos+xStart,yPos+yStart)
  177.     term.setBackgroundColor(bgColor)
  178.     term.setTextColor(tColor)
  179.     term.write(text)
  180.    end
  181.    --end
  182.   end
  183. -- end
  184.  term.setCursorPos(1,tY)
  185. end
  186.  
  187. function drawMenu()
  188.  term.setCursorPos(1,1)
  189.  term.setTextColor(colors.white)
  190.  if not bgSelected then
  191.   bgSelected = colors.black
  192.  elseif bgSelected == colors.white then
  193.   term.setTextColor(colors.black)
  194.  end
  195.  if not tSelected then
  196.   tSelected = colors.white
  197.  elseif tSelected == colors.white then
  198.   term.setTextColor(colors.black)
  199.  end
  200.  if not textSelected then
  201.   textSelected = " "
  202.  end
  203.  term.setBackgroundColor(bgSelected)
  204.  term.write("B")
  205.  term.setBackgroundColor(tSelected)
  206.  term.write("T")
  207.  for i=1,16 do
  208.   i=i-1
  209.   term.setCursorPos(1,i+2)
  210.   term.setBackgroundColor(2^i)
  211.   term.write("  ")
  212.  end
  213.  term.setCursorPos(1,18)
  214.  term.setBackgroundColor(colors.black)
  215.  if not textSelected then
  216.   textSelected = " "
  217.  elseif string.len(textSelected) > 1 then
  218.   textSelected = string.sub(textSelected,1,1)
  219.  end
  220.  term.setTextColor(colors.red)
  221.  term.write(">"..textSelected)
  222. end
  223.  
  224. function writeMenuBar(booly)
  225.  menuStatus = booly
  226.  term.setBackgroundColor(colors.black)
  227.  if booly == true then
  228.   term.setCursorPos(1,tY)
  229.   term.clearLine()
  230.   if not menuItemSelected then
  231.    menuItemSelected = 1
  232.   end
  233.   term.setTextColor(colors.white)
  234.   term.write(" Save  Exit ")
  235.   term.setCursorPos(6*menuItemSelected-5,tY)
  236.   term.setTextColor(colors.yellow)
  237.   term.write("[")
  238.   term.setCursorPos(6*menuItemSelected,tY)
  239.   term.write("]")
  240.  elseif booly == false then
  241.   term.setCursorPos(1,tY)
  242.   term.setTextColor(colors.yellow)
  243.   term.clearLine()
  244.   if saved == true then
  245.    term.write("Saved to "..args[1])
  246.   else
  247.    term.write("Press Ctrl to access menu")
  248.   end
  249.  end
  250. end
  251.  
  252. menuStatus = false
  253. saved = false
  254. writeMenuBar(menuStatus)
  255. menuItemSelected = 1
  256. drawData(3,0)
  257. drawMenu()
  258. eventHandler()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement