Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = false
- local mon
- if monitor then
- for i,name in pairs(peripheral.getNames()) do
- for j,method in pairs(peripheral.getMethods(name)) do
- if (method == 'isColor') then
- mon = peripheral.wrap(name)
- mon.clear()
- mon.setTextScale(1)
- local x, y = mon.getSize()
- if x < 40 or y < 27 then
- mon.setTextScale(0.5)
- else
- mon.setTextScale(1)
- end
- end
- end
- end
- else
- mon = term
- end
- local button={}
- local color = {
- normale = {
- text = colors.black,
- background = colors.red
- },
- clicked = {
- text = colors.black,
- background = colors.lime
- }
- }
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- function clearTable()
- button = {}
- end
- function setShow(name, data)
- button[name]["show"] = data
- end
- function setTable(name, func, xmin, xmax, ymin, ymax, extra)
- button[name] = {}
- button[name]["func"] = func
- button[name]["extra"] = extra
- button[name]["active"] = false
- button[name]["show"] = true
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- function fill(text, backgroundcolor, textcolor, bData)
- mon.setBackgroundColor(backgroundcolor)
- mon.setTextColor(textcolor)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- end
- function screen()
- local background
- local text
- for name,data in pairs(button) do
- local on = data["active"]
- if mon.isColor then
- if on == true then
- background = color.clicked.background
- text = color.clicked.text
- else
- background = color.normale.background
- text = color.normale.text
- end
- else
- if on == true then
- background = colors.white
- text = colors.black
- else
- background = colors.black
- text = colors.white
- end
- end
- if data["show"] then
- fill(name, background, text, data)
- end
- end
- end
- function toggleButton(name)
- button[name]["active"] = not button[name]["active"]
- screen()
- end
- function flash(name)
- toggleButton(name)
- screen()
- sleep(0.15)
- toggleButton(name)
- screen()
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if data["show"] then
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- flash(name)
- if data["extra"] then
- data["func"](data["extra"])
- else
- data["func"]()
- end
- return true
- end
- end
- end
- end
- return false
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- function label(w, h, text)
- mon.setCursorPos(w, h)
- mon.write(text)
- end
Advertisement
Add Comment
Please, Sign In to add comment