Kingdaro

os thing

Nov 11th, 2012
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. local options = {'Shutdown', 'Reboot'}
  2. local menuopen = false -- variable for checking if the menu is open, to see if we have to draw it
  3.  
  4. while true do
  5.     -- we're going to draw everything before taking mouse input
  6.     -- clear the screen and prepare for the new screen to be drawn, with the color black
  7.     term.setBackgroundColor(colors.black)
  8.     term.clear()
  9.  
  10.     -- get the width and height of the screen - is more helpful than memorizing numbers
  11.     -- it also makes it adaptable to other monitor sizes.
  12.     local w,h = term.getSize()
  13.  
  14.     -- draw a line on the bottom of the taskbar from right to left
  15.     paintutils.drawLine(1, h, w, h, colors.blue)
  16.  
  17.     -- draw the start button with black text and a lime (light green) background
  18.     term.setTextColor(colors.black)
  19.     term.setBackgroundColor(colors.lime)
  20.     term.setCursorPos(1, h)
  21.     write('Start')
  22.  
  23.     -- draw the start menu, but ONLY if menuopen is true.
  24.     if menuopen then
  25.         term.setBackgroundColor(colors.white)
  26.         term.setTextColor(colors.black)
  27.  
  28.         -- a for loop basically says:
  29.         -- repeat the following, starting at 1 and ending at the number of options (2 in this case)
  30.         for i=1, #options do
  31.             -- set our cursor to the left, and a y position based on i
  32.             -- so the first time, it'll be h (51) - 1, or 50
  33.             -- then h - 2, 49
  34.             term.setCursorPos(1, h - i)
  35.  
  36.             -- print the ith of options
  37.             -- so on the first loop, i will be 1, and this will say print(options[1])
  38.             -- and then options[2]
  39.             print(options[i])
  40.         end
  41.     end
  42.  
  43.     -- here's where we take mouse input.
  44.     -- use os.pullEvent to get the event pulled, the mouse button pressed, then the mouse x and y
  45.     local event, button, mousex, mousey = os.pullEvent('mouse_click')
  46.  
  47.     -- check if we're within bounds of the start button
  48.     if mousey == h and mousex >= 1 and mousex <= 5 then
  49.         -- set menuopen to the oppsite of menuopen
  50.         -- so if menuopen is true, menuopen is now false.
  51.         menuopen = not menuopen
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment