Guest User

TechOS

a guest
Sep 29th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. -- -- TechOS -- --
  2.  
  3. -- Local Variables --
  4.  
  5. local nScreenWidth, nScreenHeight = term.getSize()
  6. local nSelection = 1
  7. local menustate = "Boot"
  8.  
  9. -- End Local Variables --
  10.  
  11. -- Local Tables --
  12.  
  13. local tMenus = {
  14.     [ "Boot" ] = {
  15.     options = { "Inventory", "Turtles", "Reactor" },
  16.     draw = drawBoot
  17.     },
  18.     [ "Inventory" ] = {
  19.     options = { "Raw Materials", "Refined Materials" },
  20.     draw = drawInventory
  21.     },
  22.     [ "Turtles" ] = {
  23.     options = { "Mining" },
  24.     draw = drawTurtles  },
  25.     [ "Reactor" ] = {
  26.     options = { "Control" },
  27.     draw = drawReactor
  28.     }
  29. }
  30.  
  31. -- End Local Tables --
  32.  
  33. -- -- Draw Functions -- --
  34.  
  35. -- Base Draw Functios --
  36.  
  37. function ClearScreen()
  38.     term.clear()
  39.     term.setCursorPos( 1, 1 )
  40. end
  41.  
  42. function PrintCentered( nHeight, sString )
  43.     term.setCursorPos( nScreenWidth/2 - #sString/2, nHeight )
  44.     term.write( sString )
  45. end
  46.  
  47. function PrintLeft( nHeight, sString )
  48.     term.setCursorPos( 1, nHeight )
  49.     term.write( sString )
  50. end
  51.  
  52. function PrintRight( nHeight, sString )
  53.     term.setCursorPos( ( nScreenWidth + 1 ) - #sString, nHeight )
  54.     term.write( sString )
  55. end
  56.  
  57. function PrintTitle( sName )
  58.     PrintCentered( 1, string.rep( "-", ( nScreenWidth + 1 ) ) )
  59.     PrintCentered( 2, string.rep( "-", ( nScreenWidth + 1 ) ) )
  60.     PrintLeft( 3, "-" )
  61.     PrintCentered( 3, sName )
  62.     PrintRight( 3, "-" )
  63.     PrintCentered( 4, string.rep( "-", ( nScreenWidth + 1 ) ) )
  64.     PrintCentered( 5, string.rep( "-", ( nScreenWidth + 1 ) ) )
  65.     for i = 6, ( nScreenHeight - 1 ) do
  66.         PrintLeft( i, "-" )
  67.         PrintRight( i, "-" )
  68.     PrintCentered( nScreenHeight, string.rep( "--", ( nScreenWidth + 1 ) ) )
  69. end
  70. end
  71.  
  72. -- End Base Draw Functions
  73.  
  74. -- Menu Draw Functions --
  75.  
  76. function drawBoot()
  77.     PrintTitle( "Boot Menu" )
  78.     for j = 1, 3 do
  79.         if j == nSelection then
  80.             PrintCentered( 11 + ( j - 1 ), "[" .. tMenus["Boot"].options[j] .. "]" )
  81.         else
  82.             PrintCentered( 11 + ( j - 1 ), " " .. tMenus["Boot"].options[j] .. " " )
  83.         end
  84.     end
  85. end
  86.  
  87. function drawInventory()
  88.     PrintTitle( "Inventory Menu" )
  89.     for k = 1, 2 do
  90.         if k == nSelection then
  91.             PrintCentered( 11 + ( k - 1 ), "[" .. tMenus["Inventory"].options[k] .. "]" )
  92.         else
  93.             PrintCentered( 11 + ( k - 1 ), " " .. tMenus["Inventory"].options[k] .. " " )
  94.         end
  95.     end
  96. end
  97.  
  98. -- End Menu Draw Functions --
  99.  
  100. -- -- End Draw Functions -- --
  101.  
  102. while true do
  103.     ClearScreen()
  104.    
  105.     -- -- Problem lies here -- --
  106.  
  107.     -- drawBoot() -- shows changing of selections
  108.     tMenus[menustate].draw() -- doesn't show changing of selections
  109.    
  110.     local id, nKey = os.pullEvent("key")
  111.     if nKey == 200 and nSelection > 1 then
  112.         nSelection = nSelection - 1
  113.     elseif nKey == 208 and nSelection < #tMenus[menustate].options then
  114.         nSelection = nSelection + 1
  115.     elseif nKey == 28 then
  116.         menustate = tMenus[menustate].options[nSelection]
  117.    
  118.     end
  119. end
Advertisement
Add Comment
Please, Sign In to add comment