666WTF666

Scrolable

Jun 4th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. function Menu(...) -- Put the menu text in. User chooses one. The function returns the selection he choose.
  2. --You now need to type in the number the menu starts, and the number it ends. Made by libraryaddict
  3. local MenuStuff = {...}
  4. local first = MenuStuff[1]
  5. local second = MenuStuff[2]
  6. table.remove(MenuStuff, 1)
  7. table.remove(MenuStuff, 1)
  8. local Scrolled = 1
  9. local DownDown = 0
  10. local Mouse = first
  11. local function rewrite()
  12. local i = 0
  13. for n=first, second do
  14. i = i+1
  15. if MenuStuff[i+DownDown] then
  16. term.setCursorPos(4, n)
  17. term.write(string.rep(" ", string.len(MenuStuff[i+DownDown])))
  18. end
  19. end
  20. end
  21. local function Draw()
  22. local i = 0
  23. for n=first,second do
  24. i = i+1
  25. term.setCursorPos(4, n)
  26. term.write(MenuStuff[i+DownDown])
  27. end
  28. term.setCursorPos(1, Mouse)
  29. term.write(">>")
  30. end
  31. Draw()
  32. while true do
  33. event,param1 = os.pullEvent()
  34. if event == "key" then
  35. term.setCursorPos(1, Mouse)
  36. term.write(" ")
  37. rewrite()
  38. if param1 == 200 then -- Up
  39. if Scrolled > 1 then
  40. if Mouse == first and MenuStuff[Scrolled-1] then
  41. DownDown = DownDown-1
  42. else
  43. Mouse = Mouse-1
  44. end
  45. Scrolled = Scrolled-1
  46. end
  47. elseif param1 == 208 then -- Down
  48. if Scrolled < #MenuStuff then
  49. if Mouse == second then
  50. DownDown = DownDown+1
  51. else
  52. Mouse = Mouse+1
  53. end
  54. Scrolled = Scrolled+1
  55. end
  56. elseif param1 == 28 then -- Enter
  57. rewrite()
  58. return MenuStuff[Scrolled]
  59. -- break
  60. end
  61. Draw()
  62. end
  63. end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment