Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. --[[
  2. CineWare V1.0
  3. Author(s): Torje
  4. Required stuff:
  5. 8x3 monitor
  6. Disk drive x2
  7. Advanced computer x1
  8. Cinema [OPTIONAL BUT RECOMMENDED]
  9. --]]
  10.  
  11. -- Variables
  12. local movie1 = "/disk/alongtimeago"
  13. local movie2 = "/movies/nyancat"
  14. local movie3 = "clear"
  15.  
  16. -- Movie selection menu
  17. ocal menu_options = {
  18.   [1] = {text="Star Wars IV: A New Hope", color=colors.red},
  19.   [2] = {text="Nyan Cat the Movie", color=colors.blue},
  20.   [3] = {text="Exit", color=colors.grey}
  21. }
  22. local termX, termY = term.getSize()
  23.  
  24. local function menuDraw(selected)
  25.   local yPos = termY/2 - #menu_options/2
  26.   for index, data in pairs(menu_options) do
  27.     menu_options[index].bounds = {
  28.           x1 = termX/2 - (#data.text+4)/2,
  29.           x2 = termX/2 + (#data.text+4)/2,
  30.           y = yPos
  31.         }
  32.         term.setTextColor(data.color)
  33.         term.setCursorPos(data.bounds.x1, data.bounds.y)
  34.        
  35.         local text =
  36.         index==selected and "["..data.text.."]" or
  37.         " "..data.text.." "
  38.         term.write(text)
  39.         yPos = yPos+1
  40.   end
  41. end
  42. local function checkClick(x,y)
  43.   for index, data in pairs(menu_options) do
  44.     if x>= data.bounds.x1 and x<= data.bounds.x2 and y==data.bounds.y then
  45.           return index
  46.         end
  47.   end
  48.   return false
  49. end
  50. term.clear()
  51. local selector = 1
  52. while true do
  53.   menuDraw(selector)
  54.   local e = {os.pullEvent()}
  55.   if e[1] == "key" then
  56.     if e[2] == keys.down then
  57.           selector = selector < #menu_options and selector+1 or 1
  58.     elseif e[2] == keys.up then
  59.           selector = selector > 1 and selector-1 or 3 or #menu_options
  60.         elseif e[2] == keys.enter then
  61.           break
  62.         end
  63.   elseif e[1] == "mouse_click" then
  64.     local value = checkClick(e[3], e[4])
  65.         if value then
  66.           selector = value
  67.           break
  68.         end
  69.   end
  70. end
  71. if selector == 1 then
  72.   term.clear()
  73.   term.setCursorPos(1,1)
  74.   textutils.slowPrint("Starting movie...", 15)
  75.   sleep(1)
  76.   shell.run(movie1)
  77. end
  78. if selector == 2 then
  79.   term.clear()
  80.   term.setCursorPos(1,1)
  81.   textutils.slowPrint("Starting movie...", 15)
  82.   sleep(1)
  83.   shell.run(movie2)
  84. end
  85. if selector == 3 then
  86.   term.clear()
  87.   term.setCursorPos(1,1)
  88.   textutils.slowPrint("Starting movie...", 15)
  89.   sleep(1)
  90.   shell.run(movie3)
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement