Advertisement
Slaide

Untitled

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