Advertisement
Guest User

test1

a guest
Feb 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. os.loadAPI("buttonAPI")
  2.  
  3. -- Define main menu button
  4. mainMenu = function()
  5.   term.clear()
  6.   for i=1, #buttons do
  7.     buttons[i].create(buttons[i])
  8.   end
  9. end
  10. mainBtn = buttonAPI.newButton(1,1,6,2,colors.green,colors.black,"Main",mainMenu)
  11.  
  12. -- Define onClick functions
  13. btn1Click = function()
  14.     term.clear()
  15.     mainBtn.create(mainBtn)
  16.     term.setCursorPos(1,4)
  17.     print("Button 1 menu")
  18.   end
  19. btn2Click = function()
  20.     term.clear()
  21.     mainBtn.create(mainBtn)
  22.     term.setCursorPos(1,4)
  23.     print("Button 2 menu")
  24.   end
  25. btn3Click = function()
  26.     term.clear()
  27.     mainBtn.create(mainBtn)
  28.     term.setCursorPos(1,4)
  29.     print("Button 3 menu")
  30.   end
  31. btn4Click = function()
  32.     term.clear()
  33.     os.reboot()
  34.   end
  35.  
  36.  
  37. -- Define buttons
  38. btn1 = buttonAPI.newButton(2,2,6,3,colors.white,colors.black,"btn1",btn1Click)
  39. btn2 = buttonAPI.newButton(9,2,6,3,colors.white,colors.black,"btn2",btn2Click)
  40. btn3 = buttonAPI.newButton(2,6,6,3,colors.white,colors.black,"btn3",btn3Click)
  41. btn4 = buttonAPI.newButton(9,6,6,3,colors.white,colors.black,"btn4",btn4Click)
  42.  
  43. -- Create buttons array
  44. buttons = { btn1, btn2, btn3, btn4 }
  45.  
  46. -- Build Main Menu
  47. mainMenu()
  48.  
  49. while true do
  50.   event,side,x,y = os.pullEvent("mouse_click")
  51.   for i=1, #buttons do
  52.     if buttons[i].checkClick(buttons[i],x,y) then
  53.       buttons[i].onClick()
  54.     end
  55.   end
  56.   if mainBtn.checkClick(mainBtn,x,y) then
  57.     mainBtn.onClick()
  58.   end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement