Advertisement
subzero22

menu

Sep 8th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local termWidth, termHeight = term.getSize()
  2. local selectedItem = 1
  3. local onMainMenu = true
  4. local onNoteMenu = false
  5. local onFileMenu = false
  6. local onAppsMenu = false
  7. local onGameMenu = false
  8. local name = " "
  9.  
  10. function continue()
  11.   term.setCursorPos(1,17)
  12.   print("PRESS ANY KEY TO CONTINUEO.")
  13.   os.pullEvent("key")
  14. end
  15.  
  16. function clear()
  17.   term.clear()
  18.   term.setCursorPos(1,1)
  19. end
  20.  
  21. function Help()
  22.   clear()
  23.   shell.run("readme")
  24.   continue()
  25.   sleep(1)
  26. end
  27.  
  28. function Notes()
  29.   name = "Notes"
  30.   onNoteMenu = true
  31.   selectedItem = 1
  32.  while onNoteMenu do
  33.    menupos()
  34.    printMenu(noteMenu)
  35.    event, key = os.pullEvent("key")
  36.    onKeyPressed(key, noteMenu)
  37.  end
  38. end
  39.  
  40. function noteChoice1()
  41.   shell.run("OS/notepad")
  42.   continue()
  43.   sleep(1)
  44. end
  45.  
  46. function noteChoice2()
  47.   shell.run("OS/noteread")
  48.   continue()
  49.   sleep(1)
  50. end
  51.  
  52. function noteChoice3()
  53.   onNoteMenu = False
  54.   selectedItem = 1
  55. end
  56.  
  57. function Files()
  58.   name = "Files"
  59.   onFileMenu = true
  60.   selectedItem = 1
  61.  while onFileMenu do
  62.    menupos()
  63.    printMenu(fileMenu)
  64.    even, key = os.pullEvent("key")
  65.    onKeyPressed(key, fileMenu)
  66.  end
  67. end
  68.  
  69. function fileChoice1()
  70.   clear()
  71.   shell.run("OS/.search")
  72.   continue()
  73.   sleep(1)
  74. end
  75.  
  76. function fileChoice2()
  77.   clear()
  78.   shell.run("OS/editor")
  79.   continue()
  80.   sleep(1)
  81. end
  82.  
  83. function fileChoice3()
  84.   clear()
  85.   shell.run("OS/createfile")
  86.   continue()
  87.   sleep(1)
  88. end
  89.  
  90. function fileChoice4()
  91.   onFileMenu = False
  92.   selectedItem = 1
  93. end
  94.  
  95. function Apps()
  96.   name = "Programs"
  97.   onAppsMenu = true
  98.   selectedItem = 1
  99.  while onAppsMenu do
  100.    menupos()
  101.    printMenu(appsMenu)
  102.    event, key = os.pullEvent("key")
  103.    onKeyPressed(key, appsMenu)
  104.  end
  105. end
  106.  
  107. function appsChoice1()
  108.   clear()
  109.   shell.run("programs/calculator")
  110.   continue()
  111.   sleep(1)
  112. end
  113.  
  114. function appsChoice2()
  115.   clear()
  116.   shell.run("dj")
  117.   continue()
  118.   sleep(1)
  119. end
  120.  
  121. function appsChoice3()
  122.   clear()
  123.   shell.run("programs/tarnchat")
  124.   continue()
  125.   sleep(1)
  126. end
  127.  
  128. function appsChoice4()
  129.   clear()
  130.   shell.run("OS/run")
  131.   continue()
  132.   sleep(1)
  133. end
  134.  
  135. function appsChoice5()
  136.   onAppsMenu = False
  137.   selectedItem = 1
  138. end
  139.  
  140. function Games()
  141.   name = "Games"
  142.   onGameMenu = true
  143.   selectedItem = 1
  144.  while onGameMenu do
  145.    menupos()
  146.    printMenu(gameMenu)
  147.    event, key = os.pullEvent("key")
  148.    onKeyPressed(key, gameMenu)
  149.  end
  150. end
  151.  
  152. function gameChoice1()
  153.   clear()
  154.   shell.run("programs/slots")
  155.   continue()
  156.   sleep(1)
  157. end
  158.  
  159. function gameChoice2()
  160.   clear()
  161.   shell.run("adventure")
  162.   continue()
  163.   sleep(1)
  164. end
  165.  
  166. function gameChoice3()
  167.   clear()
  168.   shell.run("worm")
  169.   continue()
  170.   sleep(1)
  171. end
  172.  
  173. function gameChoice4()
  174.   onGameMenu = False
  175.   selectedItem = 1
  176. end
  177.  
  178. function Exit()
  179.   clear()
  180.  if fs.exists("OS/.lock") then
  181.    shell.run("OS/.lock")
  182.  else
  183.    onMainMenu = false
  184.  end
  185. end
  186.  
  187. function Shutdown()
  188.   clear()
  189.   os.shutdown()
  190. end
  191.  
  192. function line()
  193. write("-------------------------------------------------")
  194. end
  195.  
  196. local xpos1 = 2
  197.  
  198. function menupos()
  199.   term.clear()
  200.   term.setCursorPos(1,3)
  201.   line()
  202.   term.setCursorPos(1,18)
  203.   line()
  204.   term.setCursorPos(12,1)
  205.   print("Frozen OS Beta 2.1")
  206.   term.setCursorPos(18,2)
  207.   print(name)
  208.   term.setCursorPos(1,6)
  209. end
  210.  
  211. mainMenu = {
  212. [1] = { text = "Help", handler = Help },
  213. [2] = { text = "Notepad", handler = Notes },
  214. [3] = { text = "Files", handler = Files },
  215. [4] = { text = "Programs", handler = Apps },
  216. [5] = { text = "Games", handler = Games },
  217. [6] = { text = "Exit", handler = Exit },
  218. [7] = { text = "Shutdown", handler = Shutdown }
  219. }
  220.  
  221. noteMenu = {
  222. [1] = { text = "Notepad", handler = noteChoice1 },
  223. [2] = { text = "Read Notes", handler = noteChoice2 },
  224. [3] = { text = "Back", handler = noteChoice3 }
  225. }
  226.  
  227. fileMenu = {
  228. [1] = { text = "Search", handler = fileChoice1 },
  229. [2] = { text = "Edit", handler = fileChoice2 },
  230. [3] = { text = "Make Folder", handler = fileChoice3 },
  231. [4] = { text = "Back", handler = fileChoice4 }
  232. }
  233.  
  234. appsMenu = {
  235. [1] = { text = "Calculator", handler = appsChoice1 },
  236. [2] = { text = "DJ", handler = appsChoice2 },
  237. [3] = { text = "TarnChat", handler = appsChoice3 },
  238. [4] = { text = "Run a Program", handler = appsChoice4 },
  239. [5] = { text = "Back", handler = appsChoice5 }
  240. }
  241.  
  242. gameMenu = {
  243. [1] = { text = "Slots", handler = gameChoice1 },
  244. [2] = { text = "Adventure", handler = gameChoice2 },
  245. [3] = { text = "Worms", handler = gameChoice3 },
  246. [4] = { text = "Back", handler = gameChoice4 }
  247. }
  248.  
  249. function printMenu( menu )
  250.  for i=1,#menu do
  251.   if i == selectedItem then
  252.     print("              >> "..menu[i].text)
  253.   else
  254.     print("                 "..menu[i].text)
  255.   end
  256.  end
  257. end
  258.  
  259. function onKeyPressed( key, menu )
  260.  if key == 28 then
  261.    onItemSelected(menu)
  262.  elseif key == 200 then
  263.   if selectedItem > 1 then
  264.     selectedItem = selectedItem - 1
  265.   end
  266.  elseif key == 208 then
  267.   if selectedItem < #menu then
  268.     selectedItem = selectedItem + 1
  269.   end
  270.  end
  271. end
  272.  
  273. function onItemSelected( menu )
  274.   menu[selectedItem].handler()
  275. end
  276.  
  277. function main()
  278.  while onMainMenu do
  279.    name = "                 "
  280.    menupos()
  281.    printMenu(mainMenu)
  282.    event, key = os.pullEvent("key")
  283.    onKeyPressed(key,mainMenu)
  284.  end
  285. end
  286.  
  287. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement