Advertisement
Guest User

test1

a guest
Feb 22nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 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.  
  32.  
  33. -- Define buttons
  34. btn1 = buttonAPI.newButton(2,2,6,3,colors.white,colors.black,"btn1",btn1Click)
  35. btn2 = buttonAPI.newButton(9,2,6,3,colors.white,colors.black,"btn2",btn2Click)
  36. btn3 = buttonAPI.newButton(2,6,6,3,colors.white,colors.black,"btn3",btn3Click)
  37.  
  38. -- Create buttons array
  39. buttons = { btn1, btn2, btn3 }
  40.  
  41. -- Build Main Menu
  42. mainMenu()
  43.  
  44. while true do
  45.   event,side,x,y = os.pullEvent("mouse_click")
  46.   for i=1, #buttons do
  47.     if buttons[i].checkClick(buttons[i],x,y) then
  48.       buttons[i].onClick()
  49.     end
  50.   end
  51.   if mainBtn.checkClick(mainBtn,x,y) then
  52.     mainBtn.onClick()
  53.   end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement