Advertisement
Slaide

Untitled

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