Guest User

Code.

a guest
Apr 19th, 2015
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.67 KB | None | 0 0
  1. function list(directory)
  2.   local a
  3.   local b = {}
  4.   a = fs.list(directory)
  5.   for i=1, #a do
  6.     if fs.isDir(a[i]) then
  7.         b[i] = "true"
  8.     else
  9.      b[i] = "false"
  10.      end
  11.   end
  12.   return a, b
  13. end
  14. function drawFolderIcon(x, y, text)
  15.   paintutils.drawPixel(x, y, colors.yellow)
  16.   paintutils.drawPixel(x, y-1, colors.yellow)
  17.   paintutils.drawPixel(x-1, y, colors.yellow)
  18.   paintutils.drawPixel(x-1, y-1, colors.yellow)
  19.   term.setCursorPos(x-1, y+1)
  20.   term.setBackgroundColor(colors.white)
  21.   term.setTextColor(colors.black)
  22.   term.write(text)
  23.   local Out = {}
  24.   Out[1] = {}
  25.   Out[1].x = x
  26.   Out[1].y = y
  27.   Out[1].Name = text
  28.   return Out
  29. end
  30.  
  31. function drawProgramIcon(x, y, text)
  32.   paintutils.drawPixel(x, y, colors.gray)
  33.   paintutils.drawPixel(x-1, y, colors.gray)
  34.   paintutils.drawPixel(x, y-1, colors.blue)
  35.   paintutils.drawPixel(x-1, y-1, colors.blue)
  36.   term.setCursorPos(x-1, y+1)
  37.   term.setBackgroundColor(colors.white)
  38.   term.setTextColor(colors.black)
  39.   term.write(text)
  40.     local Out = {}
  41.     Out[1] = {}
  42.     Out[1].x = x
  43.     Out[1].y = y
  44.     Out[1].Name = text
  45.     return Out
  46. end
  47.  
  48. function drawDriveIcon(x, y, text)
  49.   paintutils.drawPixel(x, y, colors.black)
  50.   paintutils.drawPixel(x-1, y, colors.gray)
  51.   paintutils.drawPixel(x, y-1, colors.black)
  52.   paintutils.drawPixel(x-1, y-1, colors.gray)
  53.   term.setCursorPos(x-1, y+1)
  54.   term.setBackgroundColor(colors.white)
  55.   term.setTextColor(colors.black)
  56.   term.write(text)
  57.   local Out = {}
  58.   Out[1] = {}
  59.   Out[1].x = x
  60.   Out[1].y = y
  61.   Out[1].Name = text
  62.   return Out
  63. end
  64.  
  65. function bufferBackground()
  66. term.clear()
  67. paintutils.drawLine(1, 1, 51, 1, colors.lightBlue)
  68. paintutils.drawFilledBox(1, 2, 100, 100, colors.white)
  69. end
  70.  
  71. function drawFileList(y, directory)
  72.     local xPos = 1
  73.     local yPos = 1
  74.     local a = 1
  75.     local b = {}
  76.     local z = 0
  77.     local s = 1
  78.     local list2 = {}
  79.     local bigList = {}
  80.     b, c = list(directory)
  81.     for i=1, #b do
  82.         if b[s] == "rom" then
  83.         if a % 5 == 0 then
  84.         z = z + 1
  85.         a = 1
  86.         end
  87.             list2 = drawDriveIcon(y+(z*10), a*4, b[s])
  88.             bigList[s] = {}
  89.             bigList[s].x = list2[1].x
  90.             bigList[s].y = list2[1].y
  91.             bigList[s].Name = list2[1].Name
  92.         elseif c[s] == "false" then
  93.    if a % 5 == 0 then
  94.      z = z + 1
  95.      a = 1
  96.    end
  97.             list2 = drawProgramIcon(y+(z*10), a*4, b[s])
  98.             bigList[s] = {}
  99.             bigList[s].x = list2[1].x
  100.             bigList[s].y = list2[1].y
  101.             bigList[s].Name = list2[1].Name
  102.         else   
  103.    if a % 5 == 0 then
  104.      z = z + 1
  105.      a = 1
  106.    end
  107.             list2 = drawFolderIcon(y+(z*10), a*4, b[s])
  108.             bigList[s] = {}
  109.             bigList[s].x = list2[1].x
  110.             bigList[s].y = list2[1].y
  111.             bigList[s].Name = list2[1].Name
  112.         end    
  113.     a=a+1
  114.     s=s+1
  115.     end
  116.     return bigList
  117. end
  118.  
  119. function clickIcon(list, x, y, button, directory)
  120.     if button == 1 then
  121.         for i=1, #list do
  122.             if x == list[i].x or x == list[i].x - 1 then
  123.                 if y == list[i].y or y == list[i].y - 1 then
  124.                     if fs.isDir(list[i].Name) then
  125.                         Update(list[i].Name)
  126.                     else
  127.                     term.setBackgroundColor(colors.black)
  128.                     term.setTextColor(colors.white)
  129.                     term.setCursorPos(1, 1)
  130.                     term.clear()
  131.                     print(directory.."/"..list[i].Name)
  132.                     sleep(2)
  133.                     shell.run(directory.."/"..list[i].Name)
  134.                     error()
  135.                     end
  136.                 end
  137.             end
  138.         end
  139.     elseif button == 2 then
  140.         for i=1, #list do
  141.             if x == list[i].x or x == list[i].x + 1 then
  142.                 if y == list[i].y or y == list[i].y - 1 then
  143.                    
  144.                 else
  145.                
  146.                 end
  147.                
  148.             else
  149.            
  150.             end
  151.            
  152.         end
  153.        
  154.     end
  155. end
  156.  
  157. function Update(Name)
  158. local XYList = {}
  159. bufferBackground()
  160. XYList = drawFileList(3, Name)
  161. while true do
  162.   event, button, xPos, yPos = os.pullEvent("mouse_click")
  163.   clickIcon(XYList, xPos, yPos, button, Name)
  164. end
  165. end
  166. Update("")
Advertisement
Add Comment
Please, Sign In to add comment