Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("buttonAPI")
- -- Define main menu button
- mainMenu = function()
- term.clear()
- for i=1, #buttons do
- buttons[i].create(buttons[i])
- end
- end
- mainBtn = buttonAPI.newButton(1,1,6,2,colors.green,colors.black,"Main",mainMenu)
- -- Define onClick functions
- btn1Click = function()
- term.clear()
- mainBtn.create(mainBtn)
- term.setCursorPos(1,4)
- print("Button 1 menu")
- end
- btn2Click = function()
- term.clear()
- mainBtn.create(mainBtn)
- term.setCursorPos(1,4)
- print("Button 2 menu")
- end
- btn3Click = function()
- term.clear()
- mainBtn.create(mainBtn)
- term.setCursorPos(1,4)
- print("Button 3 menu")
- end
- btn4Click = function()
- term.clear()
- os.reboot()
- end
- -- Define buttons
- btn1 = buttonAPI.newButton(2,2,6,3,colors.white,colors.black,"btn1",btn1Click)
- btn2 = buttonAPI.newButton(9,2,6,3,colors.white,colors.black,"btn2",btn2Click)
- btn3 = buttonAPI.newButton(2,6,6,3,colors.white,colors.black,"btn3",btn3Click)
- btn4 = buttonAPI.newButton(9,6,6,3,colors.white,colors.black,"btn4",btn4Click)
- -- Create buttons array
- buttons = { btn1, btn2, btn3, btn4 }
- -- Build Main Menu
- mainMenu()
- while true do
- event,side,x,y = os.pullEvent("mouse_click")
- for i=1, #buttons do
- if buttons[i].checkClick(buttons[i],x,y) then
- buttons[i].onClick()
- end
- end
- if mainBtn.checkClick(mainBtn,x,y) then
- mainBtn.onClick()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement