Guest User

Untitled

a guest
Jan 1st, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Int--
  2.  
  3. local w,h = term.getSize()
  4. local running = true
  5.  
  6. local selectedItem = 1
  7.  
  8. --Menu Int--
  9.  
  10. local MainMenu = {
  11. [1] = {text = "Programs", handler = function() selectedMenu = "Programs" end},
  12. [2] = {text = "Control Options", handler = function() selectedMenu = "Control" end},
  13. [3] = {text = "Redstone Options", handler = function() selectedMenu = "Redstone" end},
  14. [4] = {text = "Exit", handler = function() running = false end}
  15. }
  16.  
  17. --Functions--
  18.  
  19. function centerPrint(string,ypos)
  20. term.setCursorPos(w/2-#string/2,ypos)
  21. write(string)
  22. end
  23.  
  24. function PrintMenu(menu)
  25. for i=1,#menu do
  26. if i == selectedItem then
  27. centerPrint("[ "..menu[i].text.." ]",i+5)
  28. else
  29. centerPrint(" "..menu[i].text.." ",i+5)
  30. end
  31. end
  32. end
  33.  
  34. function Input(key, menu)
  35. if key == keys.enter then
  36. menu[selectedItem].handler()
  37. elseif key == keys.down and selectedItem < #menu then
  38. selectedItem = selectedItem + 1
  39. elseif key == keys.up and selectedItem > 1 then
  40. selectedItem = selectedItem - 1
  41. end
  42. end
  43.  
  44. --Main Function--
  45. local selectedMenu = MainMenu
  46. term.clear()
  47. term.setCursorPos(1,1)
  48. while running do
  49. PrintMenu(selectedMenu)
  50. local event, key = os.pullEvent("key")
  51. Input(key, selectedMenu)
  52. end
  53. term.clear()
  54. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment