Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitor = peripheral.find("monitor")
- width, height = monitor.getSize()
- title = "Ore Processing"
- stateIdle = "Idle"
- stateProcess = "Processing"
- running = false
- buttons = {}
- createButton("Start", test1, 3, 3, 9, 2, colors.white, colors.red)
- function createButton(name, func, x, y, w, h, fg, bg)
- buttons[name] = { name = name, func = func, x = x, y = y, w = w, h = h, len = string.len(name), bg = bg, fg = fg }
- drawButton(buttons[name], fg, bg)
- end
- function drawButton(btn, fg, bg)
- monitor.setBackgroundColor(bg)
- monitor.setTextColor(fg)
- for i = btn.y, btn.y + btn.h do
- monitor.setCursorPos(btn.x, i)
- for j = 1, btn.w do
- monitor.write(" ")
- end
- end
- monitor.setCursorPos((btn.x + btn.x + btn.w) / 2 - btn.len / 2, (btn.y + btn.y + btn.h) / 2)
- monitor.write(btn.name)
- end
- function checkEvent()
- _, _, xPos, yPos = os.pullEvent("monitor_touch")
- for _, btn in pairs(buttons) do
- if (xPos >= btn.x) and (xPos < (btn.x + btn.w)) and (yPos >= btn.y) and (yPos <= (btn.y + btn.h)) then
- drawButton(btn, colors.lightGray, colors.green)
- os.sleep(0.1)
- drawButton(btn, btn.fg, btn.bg)
- btn.func()
- end
- end
- end
- function draw()
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- drawHeader()
- drawFooter()
- for k, v in pairs(buttons) do
- if running then
- drawButton(v, colors.lightGray.colors.gray)
- else
- drawButton(v, v.fg, v.bg)
- end
- end
- -- createButton("Start", test1, 3, 3, 9, 2, colors.white, colors.red)
- end
- function drawHeader()
- monitor.setTextColor(colors.white)
- monitor.setBackgroundColor(colors.gray)
- monitor.setCursorPos(width / 2 - 8, 1)
- monitor.write(" " .. title .. " ")
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.lightGray)
- monitor.setCursorPos(1, 2)
- for i = 1, width do
- monitor.write(" ")
- end
- end
- function drawFooter()
- monitor.setBackgroundColor(colors.black)
- stateText = stateIdle
- if running then stateText = stateProcess end
- monitor.setCursorPos(width - string.len(stateText) - 1, height)
- monitor.write(stateText)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.lightGray)
- monitor.setCursorPos(1, height - 1)
- for i = 1, width do
- monitor.write("-")
- end
- end
- function test1()
- if running then print("Processing already running") end
- running = true
- end
- while true do
- draw()
- checkEvent()
- os.sleep(0.25)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement