Advertisement
Guest User

Bare file selector

a guest
Dec 31st, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. directory="/3ds/"
  2. files = System.listDirectory(directory)
  3.  
  4. pad = Controls.read()
  5. oldpad=pad
  6. --To make oldpad~=nil
  7.  
  8. selected=1
  9.  
  10. while true do
  11. Screen.waitVblankStart()
  12. Screen.refresh()
  13. Screen.clear(TOP_SCREEN)
  14. pad = Controls.read()
  15.  
  16. -- The 3ds's top screen is 400x240. 240/16 is 15. If we try and display some text below 240 then we'll get an
  17. -- error. If #files was 18 or something, the program would try and display some text too low.
  18. -- With this if statement, we make it so that can't happen.
  19. if #files<16 then
  20. --Use Screen.debugPrint to display the name of each file. Uses a for loop so it happens
  21. --once for each file.
  22. for i=1, #files do
  23. -- We need to subtract 16 from i*16 because i starts out at 1 and 1*16 is 16 so the first file would be displayed
  24. -- one place to low. (Although, we could not subtract 16 and instead write something like "Select a file" at the top)
  25. Screen.debugPrint(0, i*16-16, files[i].name, Color.new(255,255,255), TOP_SCREEN)
  26. end
  27. else
  28. for i=1, 15 do
  29. Screen.debugPrint(0, i*16-16, files[i].name, Color.new(255,255,255), TOP_SCREEN)
  30. end
  31. end
  32.  
  33. --Write the name of the file in green if it's the currently selected file.
  34. --We also need to do -16 for the y position because the selected variable starts at 1.
  35. Screen.debugPrint(0, selected*16-16, files[selected].name, Color.new(0,255,0), TOP_SCREEN)
  36.  
  37. if pad~=oldpad then
  38. if Controls.check(pad, KEY_DUP) then
  39. selected=selected-1
  40. -- Check if the number for the selected file isn't a valid number.
  41. -- We need to do this to prevent an error when we do files[selected].name
  42. if selected>#files or selected<1 then
  43. selected=1
  44. end
  45. elseif Controls.check(pad, KEY_DDOWN) then
  46. selected=selected+1
  47. if selected>#files or selected<1 then
  48. selected=1
  49. end
  50. elseif Controls.check(pad,KEY_A) then
  51. -- Break out of the while loop.
  52. break
  53. end
  54. end
  55.  
  56. oldpad=pad
  57. Screen.flip()
  58. end
  59.  
  60.  
  61. while true do
  62. Screen.waitVblankStart()
  63. Screen.refresh()
  64. Screen.clear(TOP_SCREEN)
  65.  
  66. Screen.debugPrint(0, 0, "The selected file is...", Color.new(255,255,255), TOP_SCREEN)
  67. Screen.debugPrint(0, 16, (directory .. files[selected].name), Color.new(255,255,255), TOP_SCREEN)
  68.  
  69. Screen.flip()
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement