Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("left")
- mon.setTextScale(0.5)
- mon.setTextColor(colors.white)
- local button={}
- mon.setBackgroundColor(colors.black)
- function setTable(name, xmin, xmax, ymin, ymax, col)
- button[name] = {}
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- button[name]["colour"] = col
- end
- function fillTable()
- setTable("Einschalten", 2, 16, 10, 14, colours.blue)
- setTable("Ausschalten", 21, 35, 10, 14, colours.red)
- end
- function fill(text, color, bData)
- mon.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
- 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)
- 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.lightGray end
- fill(name, currColor, data)
- end
- end
- function checkxy(x, y)
- local new = false
- local newname
- for name, data in pairs(button) do
- data["active"] = false
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- rs.setBundledOutput("bottom", data["colour"])
- new = true
- newname = name
- end
- end
- end
- if new then
- button[newname]["active"] = true
- end
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- function checkRedstone()
- local c = rs.getBundledInput("back")
- if rs.getBundledOutput("bottom") ~= c then
- rs.setBundledOutput("bottom", 0)
- for name, data in pairs(button) do
- if data["colour"] == c then
- data["active"] = true
- else
- data["active"] = false
- end
- end
- end
- end
- fillTable()
- while true do
- mon.clear()
- heading("Please Select Floor")
- screen()
- local e,side,x,y = os.pullEvent()
- if e == "monitor_touch" then
- checkxy(x,y)
- else
- if e == "redstone" then
- checkRedstone()
- else
- end
- end
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment