Advertisement
Leo_Verto

tppad

Feb 12th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. nCursor = 1
  4. defColour = colours.white
  5. defBgColour = colours.black
  6. defBorderColour = colors.white
  7.  
  8. tSize = {term.getSize()}
  9. tMenu = {
  10.   {name="Cruor's building", colour=colours.lightBlue},
  11.   {name="Empty", colour=colours.white},
  12.   {name="Empty", colour=colours.white}
  13. }
  14.  
  15. function clear()
  16.   term.clear()
  17.   term.setCursorPos(1,1)
  18. end
  19.  
  20. function output(text, posX, posY, colour, bgColour)
  21.   if colour then
  22.     term.setTextColour(colour)
  23.   else
  24.     term.setTextColour(defColour)
  25.   end
  26.  
  27.   if bgColour then
  28.     term.setBackgroundColour(bgColour)
  29.   else
  30.     term.setBackgroundColour(defBgColour)
  31.   end
  32.  
  33.   if tostring(posX) == "center" then
  34.     term.setCursorPos((tSize[1]/2)-(#text/2), posY)
  35.   else
  36.     term.setCursorPos(posX, posY)
  37.   end
  38.   term.write(text)
  39. end
  40.  
  41. function clearBackground()
  42.   clear()
  43.   for i=1, tSize[2] do
  44.     for k=1, tSize[1] do
  45.       output(" ", k, i, nil, defBgColour)
  46.     end
  47.   end
  48. end
  49.  
  50. function printBorder()
  51.   clear()
  52.   for i=1, tSize[1] do
  53.     output(" ", i, 1, nil, defBorderColour)
  54.   end
  55.   for i=1, tSize[1] do
  56.     output(" ", i, tSize[2], nil, defBorderColour)
  57.   end
  58.   for i=1, tSize[2] do
  59.     output(" ", 1, i, nil, defBorderColour)
  60.   end
  61.   for i=1, tSize[2] do
  62.     output(" ", tSize[1], i, nil, defBorderColour)
  63.   end
  64.   output("Spawn Teleport Pad", "center", 1, colours.black, colors.white)
  65. end
  66.  
  67. function redraw()
  68.   clearBackground()
  69.   printBorder()
  70.   if #tMenu > tSize[2]-2 then
  71.     -- Scroll bar stuff here
  72.   else
  73.     local nStartY = (tSize[2]/2-2)-(#tMenu/2)+1
  74.     local h = nStartY
  75.    
  76.     for i=1, #tMenu do
  77.       output(tMenu[i].name, "center", h, tMenu[i].colour)
  78.       h = h + 1
  79.     end
  80.     output("[", (tSize[1]/2)-(#tMenu[nCursor].name/2)-1, nStartY+nCursor-1, colours.yellow, nil)
  81.     output("]", (tSize[1]/2)+(#tMenu[nCursor].name/2), nStartY+nCursor-1, colours.yellow, nil)
  82.   end
  83. end
  84.  
  85. function execute(tAble)
  86.   rs.setBundledOutput("bottom", tAble.colour)
  87. end
  88.  
  89. function main()
  90.   redraw()
  91.   while true do
  92.     evt, key = os.pullEvent("key")
  93.    
  94.     if key == 200 and nCursor >= 1 then
  95.       nCursor = nCursor - 1
  96.       execute(tMenu[nCursor])
  97.     elseif key == 208 and nCursor <= #tMenu then
  98.       nCursor = nCursor + 1
  99.       execute(tMenu[nCursor])
  100.     end
  101.     redraw()
  102.   end
  103. end
  104.  
  105. pcall(main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement