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"
- buttons = {}
- function baseClick(name)
- btn = buttons[name]
- bg = btn.bg
- fg = btn.fg
- btn.bg = colors.green
- btn.fg = colors.lightGray
- draw()
- os.sleep(0.25)
- btn.bg = bg
- btn.fg = fg
- draw()
- end
- function createButton(name, func, x, y, w, h)
- len = string.len(name)
- bg = colors.red
- fg = colors.white
- buttons[name] = { name = name, func = func, x = x, y = y, w = w, h = h, len = len, bg = bg, fg = fg }
- monitor.setBackgroundColor(bg)
- monitor.setTextColor(fg)
- for i = y, y + h do
- monitor.setCursorPos(x, i)
- for j = 1, w do
- monitor.write(" ")
- end
- end
- monitor.setCursorPos((x + x + w) / 2 - len / 2, (y + y + h) / 2)
- monitor.write(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
- btn.func()
- end
- end
- end
- function draw()
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- monitor.setCursorPos(width / 2 - 7, 1)
- monitor.write(title)
- createButton("Start", test1, 3, 3, 9, 2)
- end
- function test1()
- print("test1 function called")
- end
- while true do
- draw()
- checkEvent()
- os.sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement