Advertisement
Slaide

Untitled

Mar 31st, 2023
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. monitor = peripheral.find("monitor")
  2. width, height = monitor.getSize()
  3. title = "Ore Processing"
  4.  
  5. buttons = {}
  6.  
  7. function createButton(name, func, x, y, w, h)
  8. nameLen = string.len(name)
  9. buttons[name] = { name = name, func = func, x = x, y = y, w = w, h = h, len = nameLen }
  10. monitor.setBackgroundColor(colors.red)
  11. for i = y, y + h do
  12. monitor.setCursorPos(x, i)
  13. for j = 1, w do
  14. monitor.write(" ")
  15. end
  16. end
  17. monitor.setCursorPos((x + x + w) / 2 - nameLen / 2, (y + y + h) / 2)
  18. monitor.write(name)
  19. end
  20.  
  21. function checkEvent()
  22. _, _, xPos, yPos = os.pullEvent("monitor_touch")
  23. for _, btn in pairs(buttons) do
  24. if (xPos >= btn.x) and (xPos < (btn.x + btn.w)) and (yPos >= btn.y) and (yPos <= (btn.y + btn.h)) then
  25. btn.func()
  26. end
  27. end
  28. end
  29.  
  30. function draw()
  31. monitor.setBackgroundColor(colors.black)
  32. monitor.clear()
  33. monitor.setCursorPos(width / 2 - 7, 1)
  34. monitor.write(title)
  35.  
  36. createButton("Test Button", test1, 5, 3, 13, 2)
  37. end
  38.  
  39. function test1()
  40. print("test1 function called")
  41. end
  42.  
  43. while true do
  44. draw()
  45. checkEvent()
  46. os.sleep(0.5)
  47. end
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement