Advertisement
Guest User

startup test 3

a guest
Mar 30th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. --Variables
  2.  
  3. local osVer = "Alpha 1.0"
  4. local w,h = term.getSize()
  5. local brunning = true
  6. local slc = 0
  7. local _mtext = 1
  8. local _mback = 128
  9. --Tables
  10.  
  11. local menu = {
  12.   ["             "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 1; cmd = function() slc = 1 end };
  13.   ["             "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 2; cmd = function() end };
  14.   [" Programs  > "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 3; cmd = function() end };
  15.   [" Settings  > "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 4; cmd = function() end };
  16.   [" Lua Prompt> "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 5; cmd = function() end };
  17.   [" Quit      > "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 6; cmd = function() term.setBackgroundColor(colors.black) term.setCursorPos(1,1) term.clear() brunning = false end };
  18.   [" Shutdown  > "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 7; cmd = function() os.shutdown() end };
  19.   [" Logoff    > "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 8; cmd = function() end };
  20.   [" Reboot    > "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 9; cmd = function() os.reboot() end };
  21.   ["             "] = {tcol = _mtext; bcol = _mback; x = 1; xx = 13; y = 10; cmd = function() end };
  22. }
  23.  
  24. --Functions
  25.  
  26. local function tb_Draw()
  27.   term.setCursorPos(1,1)
  28.   term.setBackgroundColor(8)
  29.   term.setTextColor(1)
  30.   term.clearLine()
  31.   print("[ Begin ]")
  32.   term.setCursorPos(math.floor(w)-# osVer, 1)
  33.   print(osVer)
  34. end
  35.  
  36. local function drawMenu()
  37.   for k,v in pairs(menu) do
  38.     term.setBackgroundColor(v.bcol)
  39.     term.setTextColor(v.tcol)
  40.     term.setCursorPos(v.x, v.y)
  41.     print(k)
  42.   end
  43. end
  44.  
  45. local function menuClick()
  46.   for k,v in pairs(menu) do
  47.     local e = {os.pullEvent()}
  48.     if e[1] == "mouse_cllick" then
  49.       if e[2] == 1 then
  50.         if e[3] >= v.x and e[3]<= v.xx and e[4] == v.y then
  51.           v.cmd()
  52.         else slc = 0
  53.         end
  54.       end
  55.     end  
  56.   end return true
  57. end
  58.  
  59. local function clear(bcol)
  60.   term.setBackgroundColor(bcol)
  61.   term.clear()
  62. end
  63.  
  64. --Main Code
  65.  
  66. clear(colors.black)
  67. tb_Draw()
  68.  
  69. while brunning do
  70. e = {os.pullEvent()}
  71.   if slc == 0 then
  72.     clear(colors.black)
  73.     tb_draw()
  74.     if e[1] == "mouse_cllick" then
  75.       if e[2] == 1 then
  76.         if e[3] >= 1 and e[3]<= 13 and e[4] == 1 then
  77.           slc = 1
  78.           drawMenu()
  79.         end
  80.       end
  81.     end
  82.   elseif slc == 1 then
  83.     drawMenu()
  84.     menuClick()
  85.   end
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement