Posted 27 October 2012 - 05:31 PM
Okay, this is just a simple file browser, it runs programs, I think, and navigates through directories with ease.
You need an advanced computer for this. Also it only supports 30 files/directories. To go back to the root folder put 0 as your selection.
GUI API you need:
The actual program:
You need an advanced computer for this. Also it only supports 30 files/directories. To go back to the root folder put 0 as your selection.
GUI API you need:
Spoiler
function printCentered(per, str, ypos)
pw, pl = per.getSize()
per.setCursorPos(((pw/2) - (#str/2)), ypos)
per.write(str)
end
function drawHeader(per, str)
pw, pl = per.getSize()
printCentered(per, str, 1)
per.setCursorPos(1,2)
write(string.rep("=", pw))
end
function addSpaces(str, len)
str = str .. string.rep(" ", len - #str)
end
function clearScreen(per)
per.clear()
per.setCursorPos(1,1)
end
function fillBackground(per, str, col)
pw, pl = per.getSize()
for x = 1, pw do
for y = 1, pl do
per.setCursorPos(x, y)
per.setBackgroundColour(col)
write(str)
end
end
end
function drawWindow(per, str, col, x1, y1, x2, y2)
per.setCursorPos(x1, y1)
per.setBackgroundColour(col)
for x = x1, x2 do
for y = y1, y2 do
per.setCursorPos(x, y)
per.write(" ")
end
end
per.setCursorPos(x1,y1)
per.write(str)
end
function drawIMG(per, img, x, y)
for i = 1, #img do
per.setCursorPos(x,y-1+i)
per.write(img[i])
end
end
function errMsg(per, str, dtime)
pw, pl = per.getSize()
fillBackground(per, " ", colours.blue)
printCentered(per, str, (pl/2) + 1)
for i = 1, dtime do
printCentered(per, " ", pl/2)
sleep(0.5)
printCentered(per, "SYS.FLR:", pl/2)
sleep(0.5)
end
clearScreen(per)
end
The actual program:
Spoiler
sgui.clearScreen(term)
ver = "1"
files = {}
logo = {
"Sirdabalots Navigator,",
" the file browser.",
" ",
" oooooo ",
" o . o",
" o . o",
" o . o",
" o o",
" XXoooooo ",
" XXX ",
" XXX ",
" XXX ",
" XXX "
}
tw, tl = term.getSize()
files = fs.list(shell.dir())
function drawFiles()
files = fs.list(shell.dir())
sgui.drawWindow(term, "Files:", colours.blue, 1,1, 28, tl - 1)
term.setBackgroundColour(colours.blue)
n = 1
for i = 1, #files do
if i < tl - 3 then
term.setCursorPos(1,2+i)
term.write(i .. ": " .. files[i])
else
n = i - (tl - 4)
term.setCursorPos(17,2+n)
term.write(i .. ": " .. files[i])
end
end
end
function getSel()
term.setBackgroundColour(colours.lime)
sel = tonumber(read())
if sel == 0 then
shell.setDir("")
elseif sel < 0 or sel > #files then
sgui.errMsg(term, "INVALID SELECTION", 2)
elseif fs.isDir(shell.dir() .. "/" .. files[sel]) then
shell.setDir(shell.dir() .. "/" .. files[sel])
else
shell.run(shell.dir() .. "/" .. files[sel])
end
end
while true do
sgui.clearScreen(term)
sgui.fillBackground(term, " ", colours.black)
term.setCursorPos(tw + 1 - #"version: " - #ver, 1)
term.write("Version: " .. ver)
sgui.drawIMG(term, logo, 30, 3)
drawFiles()
sgui.drawWindow(term, "Selection: ", colours.lime, 1, tl, tw, tl)
getSel()
end