Advertisement
Slaide

Untitled

Mar 31st, 2023
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. monitor = peripheral.find("monitor")
  2. width, height = monitor.getSize()
  3. title = "Ore Processing"
  4. stateIdle = "Idle"
  5. stateProcess = "Processing"
  6. running = false
  7.  
  8. buttons = {}
  9.  
  10. function baseClick(btn)
  11. drawButton(btn, colors.lightGray, colors.green)
  12. -- os.sleep(0.25)
  13. -- draw()
  14. end
  15.  
  16. function createButton(name, func, x, y, w, h, fg, bg)
  17. len = string.len(name)
  18. buttons[name] = { name = name, func = func, x = x, y = y, w = w, h = h, len = len, bg = bg, fg = fg }
  19. drawButton(buttons[name], fg, bg)
  20. end
  21.  
  22. function drawButton(btn, fg, bg)
  23. monitor.setBackgroundColor(bg)
  24. monitor.setTextColor(fg)
  25. for i = btn.y, btn.y + btn.h do
  26. monitor.setCursorPos(btn.x, i)
  27. for j = 1, btn.w do
  28. monitor.write(" ")
  29. end
  30. end
  31. monitor.setCursorPos((btn.x + btn.x + btn.w) / 2 - btn.len / 2, (btn.y + btn.y + btn.h) / 2)
  32. monitor.write(btn.name)
  33. end
  34.  
  35. function checkEvent()
  36. _, _, xPos, yPos = os.pullEvent("monitor_touch")
  37. for _, btn in pairs(buttons) do
  38. if (xPos >= btn.x) and (xPos < (btn.x + btn.w)) and (yPos >= btn.y) and (yPos <= (btn.y + btn.h)) then
  39. baseClick(btn)
  40. btn.func()
  41. end
  42. end
  43. end
  44.  
  45. function draw()
  46. monitor.setBackgroundColor(colors.black)
  47. monitor.clear()
  48. drawHeader()
  49. drawFooter()
  50.  
  51. createButton("Start", test1, 3, 3, 9, 2, colors.white, colors.red)
  52. end
  53.  
  54. function drawHeader()
  55. monitor.setBackgroundColor(colors.gray)
  56. monitor.setTextColor(colors.white)
  57. monitor.setCursorPos(1, 1)
  58. for i = 1, width do
  59. monitor.write(" ")
  60. end
  61. monitor.setCursorPos(width / 2 - 7, 1)
  62. monitor.write(title)
  63. monitor.setBackgroundColor(colors.black)
  64. monitor.setTextColor(colors.lightGray)
  65. monitor.setCursorPos(1, 2)
  66. for i = 1, width do
  67. monitor.write(" ")
  68. end
  69. end
  70.  
  71. function drawFooter()
  72. monitor.setBackgroundColor(colors.gray)
  73. monitor.setTextColor(colors.white)
  74. monitor.setCursorPos(1, height)
  75. for i = 1, width do
  76. monitor.write(" ")
  77. end
  78.  
  79. stateText = stateIdle
  80. if running then stateText = stateProcess end
  81. monitor.setCursorPos(width - string.len(stateText) - 1, height)
  82. monitor.write(stateText)
  83.  
  84. monitor.setBackgroundColor(colors.black)
  85. monitor.setTextColor(colors.lightGray)
  86. monitor.setCursorPos(1, height - 1)
  87. for i = 1, width do
  88. monitor.write("_")
  89. end
  90. end
  91.  
  92. function test1()
  93. print("test1 function called")
  94. end
  95.  
  96. while true do
  97. draw()
  98. checkEvent()
  99. os.sleep(0.25)
  100. end
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement