Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("top")
- mon.setTextScale(1)
- mon.setTextColor(colors.black)
- backGroundColor = colors.lightBlue
- local button={}
- mon.setBackgroundColor(backGroundColor)
- function clearTable()
- button = {}
- mon.clear()
- end
- function loadingScreen(text,nTime)
- local w,h = mon.getSize()
- xPos = (w-string.len(text)+3)/2
- yPos = h/2
- for i=1,nTime do
- mon.clear()
- mon.setCursorPos(xPos,yPos)
- mon.write(text)
- for j=1,3 do
- mon.write(".")
- sleep(0.2)
- end
- end
- end
- function setTable(name, func, var, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["var"] = var
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- function funcName()
- print("You clicked buttonText")
- end
- function fillTable()
- setTable("ButtonText", funcName, 5, 25, 4, 8)
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- if string.len(text) > bData["xmax"]-bData["xmin"] then
- text = string.sub(text,1,(bData["xmax"]-bData["xmin"]-1))
- end
- 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(backGroundColor)
- end
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then currColor = colors.white else currColor = colors.blue 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 checkButton(name)
- for Oname, data in pairs(button) do
- if data["active"] then
- toggleButton(Oname)
- break
- end
- end
- toggleButton(name)
- return true
- 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"]+1 then
- if data["active"] then return false end
- if checkButton(name) then
- data["func"](data["var"])
- end
- return true
- end
- end
- end
- return false
- end
- function heading(text,colorheader,sizeheader)
- mon.setTextColor(colorheader)
- mon.setTextScale(sizeheader)
- w, h = mon.getSize()
- mon.setCursorPos(math.floor((w-string.len(text)/sizeheader)/2+1), 1)
- mon.write(text)
- mon.setTextColor(colors.black)
- mon.setTextScale(1)
- end
- function label(w, h, text)
- mon.setCursorPos(w, h)
- mon.write(text)
- end
- function checkActive(name)
- return button[name]["active"]
- end
Advertisement
Add Comment
Please, Sign In to add comment