Jump to content

[Computercraft] Explorer V0.1


Corona

CC Projekte - Interessant oder Uninteressant?  

6 Stimmen

  1. 1. Wie sehr interessieren euch die Projekte, die ich ins Forum stelle?

    • Garnicht
      0
    • Wenig
      0
    • Meh
      0
    • Recht Interessant
      1
    • Sehr Interessant
      1
    • Unglaublich Interessant
      0
    • Meine Katze hat den Hund gegessen und ich steh ohne Haus da, weswegen ich auf diese Frage eine dämliche Antwort geben will.
      4


Empfohlene Beiträge

So hier bin ich wieder mit einem neuen Schmafu den keiner braucht: dem Computercraft Explorer für Arme in der Version 0.2 (Derzeit), welches die Navigation durch Filesysteme erleichtern soll.

Code:

os.loadAPI("/apis/screen")local ver = 0.24local apiver = 0.35if screen.version() < apiver then error("Your Version of the screen API is too old. Your Version: "..screen.version()..", Least Required Version: "..apiver)endfunction cd(path) local rPath = resolve(path) if fs.exists(rPath) then local bPath = rPath shell.setDir(bPath) return true else return false endendfunction resolve(path) if string.sub(path,1,1) == "/" then return path else return "/"..path endendfunction exec(path,parameters) local rPath = resolve(path) print(rPath) if fs.exists(rPath) and not fs.isDir(rPath) then local cString = rPath.." "..parameters shell.run(cString) return true else return false endendfunction list(path) local rPath = resolve(path) if fs.exists(rPath) then local fTable = fs.list(rPath) if fTable ~= nil then table.sort(fTable) local tFiles = {} local tFilesPath = {} local tDirs = {} local tDirsPath = {} local tDirAndFiles = {} for n, sItem in pairs( fTable ) do if string.sub( sItem, 1, 1 ) ~= "." then local sPath = fs.combine( rPath, sItem ) sPath = "/"..sPath if fs.isDir( sPath ) then table.insert( tDirs, sItem ) table.insert( tDirsPath, sPath ) else table.insert( tFiles, sItem ) table.insert( tFilesPath, sPath ) end end end table.sort( tDirs ) table.sort( tFiles ) tDirAndFiles.directories = tDirs tDirAndFiles.dirpaths = tDirsPath tDirAndFiles.files = tFiles tDirAndFiles.filepaths = tFilesPath tDirAndFiles.all = {} tDirAndFiles.allpaths = {} for i=1, #tDirsPath do table.insert(tDirAndFiles.all,fs.getName(tDirsPath[i])) table.insert(tDirAndFiles.allpaths,tDirsPath[i]) end for i=1, #tFilesPath do table.insert(tDirAndFiles.all,fs.getName(tFilesPath[i])) table.insert(tDirAndFiles.allpaths,tFilesPath[i]) end return tDirAndFiles else print(shell.dir().." is not a directory!") return false end else print("invalid path!") return false endendfunction drawFiles(tDat,offset,highlight) --please only use absolute filepaths! local bckstr = ".." local btnBack = {x1 = 1, x2 = #bckstr, y1 = 2, y2 = 2, path = shell.resolve(".."), name = ".."} local drawnCoords = {} print("Currently in: "..shell.dir()) if shell.dir() ~= "/" then table.insert(drawnCoords,btnBack) local tx,ty = term.getCursorPos() term.setBackgroundColor(colors.lime) write(bckstr) term.setCursorPos(tx,ty+1) else highlight = highlight + 1 end for i=offset, #tDat do local tcpx, tcpy = term.getCursorPos() if fs.isDir(tDat[i]) then if i==highlight then term.setBackgroundColor(colors.purple) else term.setBackgroundColor(colors.blue) end else if i==highlight then term.setBackgroundColor(colors.orange) else term.setBackgroundColor(colors.red) end end write(fs.getName(tDat[i])) local temTable = {x1 = tcpx, x2 = tcpx + #fs.getName(tDat[i])-1, y1 = tcpy, y2 = tcpy, path = tDat[i], name = fs.getName(tDat[i])} table.insert(drawnCoords,temTable) term.setCursorPos(tcpx,tcpy+1) end return drawnCoordsendfunction drawFileMenu(referrer,x,y) local btnWidth = 7 local msgRun = "run " local msgEdit = "edit" local msgOpen = "open" local msgCopy = "copy" local msgDelete = "del " local btnRun = {x1 = x, x2 = x+btnWidth, y1 = y, y2 = y, text = msgRun, color = colors.blue, exec = function(referrer) shell.run("clear") shell.run(referrer.path) sleep(1.5) end} local btnEdit = {x1 = x, x2 = x+btnWidth, y1 = y+1, y2 = y+1, text = msgEdit, color = colors.blue, exec = function(referrer) shell.run("edit "..referrer.path) end} local btnOpen = {x1 = x, x2 = x+btnWidth, y1 = y, y2 = y, text = msgOpen, color = colors.blue, exec = function(referrer) cd(referrer.path) end} --local btnCopy = {x1 = x, x2 = x+btnWidth, y1 = y+2, y2 = y+2, text = msgOpen, color = colors.blue, exec = function(referrer) end} HASN'T GOT A HANDLER YET!!!!!!! local btnDelete = {x1 = x, x2 = x+btnWidth, y1 = y+2, y2 = y+2, text = msgDelete, color = colors.blue, exec = function(referrer) local warning="REALLY DELETE "..referrer.name.."?" local xt,yt = term.getSize() term.setCursorPos(xt/2-#warning/2,yt/2-6) term.write(warning) local yes={x1=xt/2-4,x2=xt/2+4,y1=yt/2-4,y2=yt/2-1,text="YES",color=colors.red} local no={x1=xt/2-4,x2=xt/2+4,y1=yt/2+1,y2=yt/2+4,text="NO",color=colors.red} screen.drawButton(yes) screen.drawButton(no) local evn,btn,px,py = os.pullEvent("mouse_click") if btn==1 and screen.pressed(yes,px,py) then fs.delete(referrer.path) end end} local fileBtn = {btnRun, btnEdit, btnDelete} local dirBtn = {btnOpen,btnDelete} if fs.isDir(referrer.path) then btnDelete.y1 = btnDelete.y1-1 btnDelete.y2 = btnDelete.y2-1 for i=1,#dirBtn do screen.drawButton(dirBtn[i]) end return dirBtn else for i=1,#fileBtn do screen.drawButton(fileBtn[i]) end return fileBtn endendfunction main() local soffset = 1 local active = 0 local pr = 0 local ca = false -- Context Menu Active Variable local cx -- Context Menu last klicked X Coord local cy -- Context Menu last klicked y Coord local lItem -- last clicked Item local ci -- ContectMenu Items local mx,my = term.getSize() local btnQuit = {x1 = mx, x2 = mx, y1 = 1, y2 = 1, color = colors.red, text = "X"} screen.cls() shell.setDir(resolve(shell.dir())) shell.setAlias(fs.getName(shell.getRunningProgram()),"/"..shell.getRunningProgram()) print("Welcome to the CraftOS Explorer Version "..ver..", Written by Coronaxe!") print("") print("o) Leftklick a File (red) or Folder (blue) to highlight it") print("o) Rightklick a File (red) to open the context menu") print("o) Leftklick a highlighted Folder (purple) to switch to it") print("o) To Quit, please click on the \"X\" in the upper right!") print("") print("Please click anywhere to proceed.") os.pullEvent("mouse_click") while true do screen.cls() screen.drawButton(btnQuit) term.setCursorPos(1,1) data = list(shell.dir()) dc = drawFiles(data.allpaths,soffset,active-2) if ca then if lItem.name ~= ".." then ci = drawFileMenu(lItem,cx,cy) else ca = false end end local evn,misc,x,y = os.pullEvent() if evn == "mouse_click" then if screen.pressed(btnQuit,x,y) then screen.cls() print("Thank you for using Explorer Version "..ver.."!") --os.unloadAPI("screen") error() end if ca then for i=1,#ci do if screen.pressed(ci[i],x,y) then ci[i].exec(lItem) pr = 1 ca = false end end end if pr~=1 then for i=1,#dc do if screen.pressed(dc[i],x,y) then pr = 1 if misc == 2 then ca = true cx = x cy = y lItem = dc[i] else if not fs.isDir(dc[i].path) or not dc[i].name == ".." then if active == i + soffset then --shell.run("edit "..dc[i].path) active = 0 else active = i + soffset end else if active == i + soffset or dc[i].name == ".." then cd(dc[i].path) soffset = 1 active = 0 else active = i + soffset end end end end end end if pr == 1 then pr = 0 else active = 0 ca = false end elseif evn == "mouse_scroll" then if misc <= 0 and soffset ~= 1 then ca = false soffset = soffset + misc elseif misc >= 0 and soffset <= #data.all-17 then ca = false soffset = soffset + misc end end endendmain()

Momentan kann das Programm folgendes:

  • Ordner wechseln
  • Bestehende Dateien zum editieren öffnen
  • Programme ohne Parameter ausführen
  • Mit dem Scrollwheel umgehen
  • Dateien löschen

Bedienung sieht wiefolgt aus:

  • Linksklick auf ".." springt einen Ordner zurück
  • Linksklick auf einen Ordner (blau) oder eine Datei (rot) Highlighted diese(n)
  • Linksklick auf eine gehighlightete Datei (orange) öffnet diese im Editor*
  • Linksklick auf einen gehighlighteten Ordner (lila) wechselt zu diesem
  • Linksklick auf den "X" Button beendet das Programm
  • Rechtsklick auf eine Datei führt diese aus*

*Über Das Kontextmenü möglich

Verbesserungen in der Version 0.24:

  • Kontextmenü eingeführt

Verbesserungen in Version 0.2:

  • Scrollen ist jetzt möglich
  • "Doppelklick" eingeführt
  • "X" Button eingeführt
  • Kompatibilität gesteigert

Im Anhang sind die Dateien, die man in computercraft importieren muss, also ungezippt in einen computer (einfach eine neue Datei in minecraft mit "Edit biadbabdkaj" erstellen, speichern und man sieht dann den Computer unter "saves/deinweltenname/computer/id" wobei id ein ordner mit einer Zahl ist, wo die vorher erstellte datei drin ist und deinweltenname der name der welt wo du es testen willst ist.)

dann einfach ausführen (:

Screenshots im Anhang.

TODO:

-Programme mit Parametern ausführen

-OptionBar

-Dateien erstellen

-Kontextmenü

-Scrolling

-CloseButton

post-673-0-43361200-1391452120_thumb.png

post-673-0-26963700-1391452135_thumb.png

expl_v0.2.zip

explorer_0.24.zip

post-673-0-91768900-1392216591_thumb.png

post-673-0-00420600-1392216810_thumb.png

bearbeitet von Corona
Link zu diesem Kommentar
Auf anderen Seiten teilen

  • 2 weeks later...

Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde dich hier an.

Jetzt anmelden
×
×
  • Neu erstellen...
B
B