Advertisement
Slaide

Untitled

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