Advertisement
PolskiWisnia

Eksplorator plików

Jul 20th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.86 KB | None | 0 0
  1. -- Program stworzony przez pilotofsomething. Modyfikacje w Jego kodzie ograniczaja sie do spolszczenia oprogramowania. --
  2. -- This software was made by pilotofsomething. I do not own it. I modified it to include Polish language --
  3. -- Niniejszy eksplorator plików jest używany w tworzeniu NextUI dla systemu MineCore --
  4. local dir = ""
  5. local fileList = {}
  6. local fList = {}
  7. local dList = {}
  8. local offset = 0
  9.  
  10. function drawSquare(x,y,x2,y2,color)
  11.   for xPos=x,x2 do
  12.     for yPos=y,y2 do
  13.       term.setBackgroundColor(color)
  14.       term.setCursorPos(xPos,yPos)
  15.       term.write(" ")
  16.     end
  17.   end
  18.   term.setBackgroundColor(colors.black)
  19. end
  20.  
  21. function drawText(x,y,text,tColor,bColor)
  22.   term.setBackgroundColor(bColor)
  23.   term.setTextColor(tColor)
  24.   term.setCursorPos(x,y)
  25.   term.write(text)
  26. end
  27.  
  28. function makeLists(path)
  29.   fileList = fs.list(path)
  30.   dList = {}
  31.   fList = {}
  32.   if string.len(dir) > 1 then
  33.     table.insert(dList, "..")
  34.   end
  35.   for i=1,#fileList do
  36.     if fs.isDir(path.."/"..fileList[i]) then
  37.       table.insert(dList, fileList[i])
  38.     else
  39.       table.insert(fList, fileList[i])
  40.     end
  41.   end
  42. end
  43.  
  44. while true do
  45.   term.clear()
  46.   drawSquare(1,1,10,19,colors.gray)
  47.   drawSquare(10,1,51,19,colors.white)
  48.   drawSquare(1,1,51,1,colors.lightGray)
  49.   if string.len(dir) > 0 then
  50.     drawText(1,1,dir,colors.black,colors.lightGray)
  51.   else
  52.     drawText(1,1,"/",colors.black,colors.lightGray)
  53.   end
  54.   term.setCursorPos(1,1)
  55.   makeLists(dir)
  56.   for i=1,#dList do
  57.     if dList[i+offset] then
  58.       drawText(1,i+1,dList[i+offset],colors.white,colors.gray)
  59.     end
  60.   end
  61.   local pos = 1
  62.   local offSet = 0
  63.   for i=1,#fList do
  64.     if fList[i+(18*offset)] then
  65.       drawText(10+(offSet*15),i-(18*offSet)+1,fList[i+(18*offset)],colors.black,colors.white)
  66.     end
  67.     pos = pos + 1
  68.     if pos > 18 then
  69.       pos = 1
  70.       offSet = offSet + 1
  71.     end
  72.   end
  73.   local e,b,x,y = os.pullEvent()
  74.   if e == "mouse_click" then
  75.     if x<10 and y>1 then
  76.       if offset < 1 then
  77.         if dList[y-1] then
  78.           if dList[y-1] == ".." then
  79.             dir = fs.getDir(dir)
  80.           else
  81.             dir = dir.."/"..dList[y-1]
  82.           end
  83.           offset = 0
  84.         end
  85.       else
  86.         if dList[(y-1)+offset] then
  87.           if dList[(y-1)+offset] == ".." then
  88.             dir = fs.getDir(dir)
  89.           else
  90.             dir = dir.."/"..dList[(y-1)+offset]
  91.           end
  92.           offset = 0
  93.         end
  94.       end
  95.     elseif x>9 and x<25 and y>1 then
  96.       if offset < 1 then
  97.         if fList[y-1] then
  98.           term.setTextColor(colors.white)
  99.           term.setBackgroundColor(colors.black)
  100.           term.clear()
  101.           term.setCursorPos(1,1)
  102.           shell.run(dir.."/"..fList[y-1])
  103.         end
  104.       else
  105.         if fList[y+(offset*17)] then
  106.           term.setTextColor(colors.white)
  107.           term.setBackgroundColor(colors.black)
  108.           term.clear()
  109.           term.setCursorPos(1,1)
  110.           shell.run(dir.."/"..fList[y+(offset*17)])
  111.         end
  112.       end
  113.     elseif x>25 and x<40 and y>1 then
  114.       if offset < 1 then
  115.         if fList[y+17] then
  116.           term.setTextColor(colors.white)
  117.           term.setBackgroundColor(colors.black)
  118.           term.clear()
  119.           term.setCursorPos(1,1)
  120.           shell.run(dir.."/"..fList[y+17])
  121.         end
  122.       else
  123.         if fList[y+(offset*34)] then
  124.           term.setTextColor(colors.white)
  125.           term.setBackgroundColor(colors.black)
  126.           term.clear()
  127.           term.setCursorPos(1,1)
  128.           shell.run(dir.."/"..fList[y+(offset*34)])
  129.         end
  130.       end
  131.     elseif y == 1 then
  132.       drawSquare(1,1,51,1,colors.lightGray)
  133.       term.setCursorPos(1,1)
  134.       term.setTextColor(colors.black)
  135.       term.setBackgroundColor(colors.lightGray)
  136.       local input = read()
  137.       if fs.exists(input) then
  138.         if fs.isDir(input) then
  139.           dir = input
  140.         else
  141.           shell.run(input)
  142.         end
  143.       else
  144.         drawSquare(1,1,51,1,colors.lightGray)
  145.         drawText(1,1,"Nieznana sciezka lub plik (nie istnieje)", colors.black, colors.lightGray)
  146.         sleep(0.3)
  147.         os.pullEvent()
  148.       end
  149.     else
  150.       if offset < 1 then
  151.         if fList[y+34] then
  152.           term.setTextColor(colors.white)
  153.           term.setBackgroundColor(colors.black)
  154.           term.clear()
  155.           term.setCursorPos(1,1)
  156.           shell.run(dir.."/"..fList[y+34])
  157.         end
  158.       else
  159.         if fList[y+(offset*51)] then
  160.           term.setTextColor(colors.white)
  161.           term.setBackgroundColor(colors.black)
  162.           term.clear()
  163.           term.setCursorPos(1,1)
  164.           shell.run(dir.."/"..fList[y+(offset*51)])
  165.         end
  166.       end
  167.     end
  168.   elseif e == "mouse_scroll" then
  169.     if b == -1 then
  170.       if offset > 0 then
  171.         offset = offset - 1
  172.       end
  173.     elseif b == 1 then
  174.         offset = offset + 1
  175.     end
  176.   end
  177. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement