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(btn)
- drawButton(btn, colors.lightGray, colors.green)
- -- os.sleep(0.25)
- -- draw()
- end
- function createButton(name, func, x, y, w, h, fg, bg)
- len = string.len(name)
- buttons[name] = { name = name, func = func, x = x, y = y, w = w, h = h, len = len, 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
- baseClick(btn)
- 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, colors.white, colors.red)
- 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