Guest User

Untitled

a guest
Feb 9th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. local programOptions = {
  2.     {"Button1", button1},
  3. }
  4.  
  5. local varY = 3
  6. local s = 1
  7. local w,h = term.getSize()
  8. local function center(text, line, col)
  9.     term.setCursorPos(math.floor(w/2)-string.len(text)/2, line)
  10.     term.setBackgroundColour(col)
  11.     term.clearLine()
  12.     print(text)
  13. end
  14.  
  15. local function space()
  16.  print("")
  17. end
  18.  
  19. local function cPrint(str)
  20.     x, _ = term.getSize()
  21.     _, y = term.getCursorPos()
  22.     term.setCursorPos((x-#str)/2, y)
  23.     print(str)
  24. end
  25.  
  26. local function drawTitle()
  27.     term.setTextColor(32)
  28.     term.clear()
  29.     term.setCursorPos(1,1)
  30.     cPrint("[ SelectOS BETA ]")
  31.     space()
  32.     space()
  33. end
  34.  
  35. local function drawMain(_table)
  36.     for i = 1, #_table do
  37.         if s == i then
  38.             center(_table[i][1], varY + i, colours.cyan)
  39.         else
  40.             center(_table[i][1], varY + i, colours.blue)
  41.         end
  42.     end
  43. end
  44.  
  45. local function gui(_table)
  46.     while true do
  47.         term.clear()
  48.         term.setCursorPos(1,1)
  49.         term.setBackgroundColor(colors.blue)
  50.         drawTitle()
  51.         term.setTextColor(colors.white)
  52.         drawMain(_table)
  53.         local event, p1, p2, p3 = os.pullEvent()
  54.         if event == "key" then
  55.             if p1 == keys.down or p1 == 31 then
  56.                 s = s + 1
  57.                 if s >= #_table + 1 then s = 1 end
  58.             elseif p1 == keys.up or p1 == 17 then
  59.                 s = s - 1
  60.                 if s <= 0 then s = #_table end
  61.             elseif p1 == keys.enter then
  62.                 term.setBackgroundColor(colors.black)
  63.                 term.setTextColor(colors.white)
  64.                 print(type(_table[s][2])) sleep(1)
  65.                 _table[s][2]()
  66.             end
  67.         elseif event == "mouse_click" then
  68.             if _table[p3 - 3] ~= nil then
  69.                 start=math.floor(math.floor(51/2)-(string.len(_table[p3-3][1])+4)/2)-1
  70.                 if start <p2 and start+(string.len(_table[p3-3][1])+5)>p2 then
  71.                     term.setBackgroundColor(colors.black)
  72.                     term.setTextColor(colors.white)
  73.                     _table[p3-3][2]()
  74.                 end
  75.             end
  76.         elseif event == "mouse_scroll" then
  77.             s = s + p1
  78.             if s >= #_table + 1 then s = 1 end
  79.             if s <= 0 then s = #_table end
  80.         end
  81.     end
  82. end
  83.  
  84. local function drawPrograms()
  85.     gui(programOptions)
  86. end
  87.  
  88. local mainOptions = {
  89.     {"Programs", drawPrograms},
  90.     {"Control Panal", drawCP},
  91.     {"File Browser", bFile},
  92.     {"Command Prompt", drawCMD},
  93.     {"Exit to CraftOS", function() term.clear() term.setCursorPos(1,1) error();end},
  94.     {"Restart Computer", os.reboot},
  95.     {"Shutdown Computer", os.shutdown},
  96. }
  97.  
  98. gui(mainOptions)
Advertisement
Add Comment
Please, Sign In to add comment