Advertisement
PaymentOption

GUI for Epic

Aug 28th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.41 KB | None | 0 0
  1.  
  2.  
  3. --Main Code
  4. nSelect = 1
  5. w, h = term.getSize()
  6.  
  7. --Fix Read
  8. shell.run("rom/apis/.fixread")
  9.  
  10. --Functions
  11.  
  12. function fileSelect()
  13. local function getTypes(rootLoc)
  14. rootLoc = rootLoc or "/"
  15. if rootLoc == "" then rootLoc = "/" end
  16. local items = fs.list(rootLoc)
  17.  
  18. local function CheckForHiddenFiles( tFiles )
  19.     for index,value in ipairs( tFiles ) do
  20.         if string.sub( value, 1, 1 ) == "." then
  21.             table.remove( tFiles, index )
  22.             return true, tFiles
  23.         end
  24.     end
  25.    
  26.     return false
  27. end
  28.  
  29. bCount = 0
  30. for b = 1, #items do
  31.     local IsFound, items = CheckForHiddenFiles( items )
  32.    
  33.     if not IsFound then
  34.         break
  35.     end
  36. end
  37. local types = {}
  38. if not rootLock == "/" then
  39. table.insert(items, 1, "..")
  40. table.insert(types, 1, "up")
  41. end
  42. for i = 1, #items do
  43.     if fs.isDir(rootLoc .. items[i]) then
  44.         table.insert(types, "dir")
  45.     else
  46.         table.insert(types, "file")
  47.     end
  48. end
  49. return items, types
  50. end
  51.  
  52. local rootLoc = ""
  53.  
  54. local function drawGUI(items, rootLoc, types)
  55.     local selection = 1
  56.     local scroll = 0
  57.     while true do
  58.         term.clear()
  59.         term.setCursorPos(1,1)
  60.         write(" | File Selection: " .. rootLoc)
  61.         term.setCursorPos(50,1)
  62.         write("|")
  63.         term.setCursorPos(1,2)
  64.         write(" +-----------------------------------------------+")
  65.         for i = 1+scroll, #types do
  66.             term.setCursorPos(45, (i+2)-scroll)
  67.             write(types[i])
  68.         end
  69.         for d = 1+scroll, #items do
  70.             term.setCursorPos(3, (d+2)-scroll)
  71.             write(items[d])
  72.         end
  73.         local length = string.len(items[selection])
  74.         term.setCursorPos(2, (selection+2)-scroll)
  75.         term.write("[")
  76.         term.setCursorPos(3+length, (selection+2)-scroll)
  77.         term.write("]")
  78. event, key = os.pullEvent("key")
  79. if key == 208 then
  80. term.setCursorPos(2, (selection+2)-scroll)
  81. term.write(" ")
  82. term.setCursorPos(3+length, (selection+2)-scroll)
  83. term.write(" ")
  84.     if selection == #items then
  85.     elseif selection == scroll+16 then
  86.         selection = selection+1
  87.         scroll = scroll+1
  88.     else
  89.         selection = selection+1
  90.     end
  91. elseif key == 200 then
  92. term.setCursorPos(2, (selection+2)-scroll)
  93. term.write(" ")
  94. term.setCursorPos(3+length, (selection+2)-scroll)
  95. term.write(" ")
  96.     if selection == 1 then
  97.     elseif selection == scroll+1 then
  98.         selection = selection-1
  99.         scroll = scroll-1
  100.     else
  101.         selection = selection-1
  102.     end
  103. elseif key == 28 then  
  104.     return(items[selection])
  105. else
  106. end
  107. end
  108. end
  109.  
  110. while fs.isDir(rootLoc) or rootLoc == ".." do
  111. if rootLoc == ".." then
  112. local rootPos = string.find(oldRootLoc:reverse(), "/")*-1
  113. rootLoc = oldRootLoc.sub(1, rootPos)
  114. end
  115. rootLoc = (rootLoc .. "/")
  116. local items, types = getTypes(rootLoc)
  117. local oldRootLoc = rootLoc
  118. rootLoc = (rootLoc .. drawGUI(items, rootLoc, types))
  119. end
  120.  
  121. return rootLoc
  122. end
  123.  
  124. function clear() term.clear(); term.setCursorPos(1,1) end
  125.  
  126. function cWrite(textData, yData)
  127.   local h,w = term.getSize()
  128.   local xd,yd = term.getCursorPos()
  129.   term.setCursorPos(math.ceil(w/2 - textData:len()/2), yd)  
  130.   write(textData)
  131.   end
  132.  
  133. function cPrint(height, value)
  134.   local xpos = w/2 - string.len(value)/2
  135.   term.setCursorPos(xpos, height)  
  136.   term.write(value)
  137. end
  138.  
  139. --Main Code/Function
  140. function printMain()
  141.  os.startTimer(1)    
  142.  local nTime = os.time()
  143.  
  144.  print(" |Apache                                         |")
  145.  print(" +-----------------------------------------------+")
  146.  term.setCursorPos(36,1)
  147.  write("Time: "..textutils.formatTime(nTime, false))
  148.  
  149.  term.setCursorPos(1,3)
  150.  print(" ")
  151.                       cPrint(4, "+----------------+")
  152.  if nSelect == 1 then cPrint(5, "| [*] Upload     |")
  153.  else                 cPrint(5, "| [ ] Upload     |") end
  154.                       cPrint(6, "|                |")
  155.  if nSelect == 2 then cPrint(7, "| [*] Delete     |")
  156.  else                 cPrint(7, "| [ ] Delete     |") end
  157.                       cPrint(8, "|                |")
  158.  if nSelect == 3 then cPrint(9, "| [*] Exit       |")
  159.  else                 cPrint(9, "| [ ] Exit       |") end
  160.                       cPrint(10,"+----------------+")
  161. end
  162.  
  163.  function printMain2()
  164.  clear()
  165. file = fileSelect()
  166. end
  167.  
  168.  while true do
  169.  
  170.  clear()
  171.   printMain()
  172.  
  173.  event, key = os.pullEvent()
  174.  if event == "key" then
  175.  if key == keys.up and nSelect > 1 then nSelect = nSelect-1
  176.  elseif key == keys.down and nSelect < 3 then nSelect = nSelect+1
  177.  
  178.  elseif key == keys.enter and nSelect == 3 then clear(); break
  179.  
  180.  elseif key == keys.enter and nSelect == 1 then printMain2() sleep(0.5) nSelect = 1
  181.  
  182.  
  183.            end
  184.                  end
  185.                        end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement