Guest User

startup

a guest
Sep 12th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local w,h = term.getSize()
  2.  
  3. --Some draw functions to get us started
  4.  
  5. local function printCentered(str, ypos)
  6.   term.setCursorPos(w/2 - #str, ypos)
  7.   term.write(str)
  8. end
  9.  
  10. local function printRight(str, ypos)
  11.   term.setCursorPos(w - #str, ypos)
  12.   term.write(str)
  13. end
  14.  
  15. --Add the menus here
  16.  
  17. function drawMain()
  18.   printCentered("Bees", 8)
  19.   printCentered("Bottler", 10)
  20.   printCentered("Credits", 12)
  21.   printCentered("Shutdown", 14)
  22.  
  23.   local ypos = 9
  24.   if select == 2 then ypos = 11
  25.   elseif select == 3 then ypos = 13
  26.   elseif select == 4 then ypos = 15 end
  27.   printCentered("---------", ypos)
  28.  
  29. end
  30.  
  31. function drawHeader()
  32.   printCentered("Auto Bee Mrk 1", 2)
  33.   printCentered(string.rep("-", w), 3)
  34.   printRight("by: superpowers414", h)
  35. end
  36. --Menu state
  37.  
  38. local menustate = "main"
  39. select = 1
  40.  
  41. local mopt = {
  42.   ["main"] = {
  43.     options = {"Bees", "Bottler", "Credits", "quit"},
  44.     draw = drawMain
  45.   }
  46. }
  47.  
  48. --Run Function
  49. loop = true
  50.   while loop==true do
  51.     term.clear()
  52.     drawHeader()
  53.     mopt[menustate].draw()
  54.     local id, key = os.pullEvent("key")
  55.  
  56.     if key == 200 and select > 1 then
  57.       select = select-1
  58.     elseif key == 208 and select < #mopt[menustate].options then
  59.       select = select+1
  60.     elseif key == 28 then
  61.       if #mopt[menustate].options[select] == "quit" then
  62.         loop = false
  63.       else
  64.         menustate = #mopt[menustate].options[select]
  65.       end
  66.     end
  67.   end
Advertisement
Add Comment
Please, Sign In to add comment