Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("config")
- local m2 = peripheral.wrap(config.Controller) -- Monitor with Controller (same as toggle)
- --------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------
- m2.setTextScale(1)
- m2.setTextColor(colors.white)
- local button={}
- m2.setBackgroundColor(colors.black)
- --------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------
- function clearTable()
- button = {}
- m2.clear()
- end
- --------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------
- function setTable(name, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- --------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------
- function fill(text, color, bData)
- m2.setBackgroundColor(color)
- 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
- m2.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- m2.write(text)
- else
- m2.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- m2.write(" ")
- end
- end
- end
- m2.setBackgroundColor(colors.black)
- end
- --------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then currColor = colors.lime else currColor = colors.cyan end
- fill(name, currColor, data)
- 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 y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["func"]()
- return true
- --data["active"] = not data["active"]
- --print(name)
- end
- end
- end
- return false
- end
- --------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------
- function heading(text)
- w, h = m2.getSize()
- m2.setCursorPos((w-string.len(text))/2+1, 1)
- m2.write(text)
- end
- --------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------
- function label(w, h, text)
- m2.setCursorPos(w, h)
- m2.write(text)
- end
- --------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement