Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Programm made by Mrswisstobi - redo 51ing - april 2017
- local button = {}
- local side = "back" -- where your BUNDLED CABLE is
- local mon = peripheral.wrap("bottom") -- where your monitor is
- local textScale = 1.2
- ------------ color variables ------------
- local btnTextColor = colors.white
- local defaultBgColor = colors.black
- local headerColor = colors.white
- -----------------------------------------
- function turnAllOff()
- rs.setBundledOutput(side, 0)
- for name, data in pairs(button) do
- data["active"] = true
- if name == "All OFF" then
- button[name]["active"] = false
- end
- mon.clear()
- heading("Spawners Controles on/off:")
- screen()
- end
- end
- function turnAllOn()
- rs.setBundledOutput(side, 65535)
- for name, data in pairs(button) do
- data["active"] = false
- if name == "All ON" then
- button[name]["active"] = true
- end
- mon.clear()
- heading("Spawners Controles on/off:")
- screen()
- end
- end
- rs.setBundledOutput(side, 65535)
- term.clear()
- term.setCursorPos(1,1)
- mon.setBackgroundColor(defaultBgColor)
- mon.setTextScale(textScale)
- mon.clear()
- function fillTable()
- setTable("free01", switchOutput, 3, 13, 3, 5, colors.white, colors.red, colors.lime)
- setTable("free02", switchOutput, 3, 13, 7, 9, colors.orange, colors.red, colors.lime)
- setTable("free03", switchOutput, 3, 13, 11, 13, colors.magenta, colors.red, colors.lime)
- setTable("free04", switchOutput, 3, 13, 15, 17, colors.lightBlue, colors.red, colors.lime)
- setTable("free05", switchOutput, 17, 27, 3, 5, colors.yellow, colors.red, colors.lime)
- setTable("free06", switchOutput, 17, 27, 7, 9, colors.lime, colors.red, colors.lime)
- setTable("free07", switchOutput, 17, 27, 11, 13, colors.pink, colors.red, colors.lime)
- setTable("free08", switchOutput, 17, 27, 15, 17, colors.gray, colors.red, colors.lime)
- setTable("free09", switchOutput, 45, 55, 3, 5, colors.lightGray, colors.red, colors.lime)
- setTable("free10", switchOutput, 45, 55, 7, 9, colors.cyan, colors.red, colors.lime)
- setTable("free11", switchOutput, 45, 55, 11, 13, colors.purple, colors.red, colors.lime)
- setTable("free12", switchOutput, 45, 55, 15, 17, colors.blue, colors.red, colors.lime)
- setTable("free13", switchOutput, 59, 69, 3, 5, colors.brown, colors.red, colors.lime)
- setTable("free14", switchOutput, 59, 69, 7, 9, colors.green, colors.red, colors.lime)
- setTable("free15", switchOutput, 59, 69, 11, 13, colors.red, colors.red, colors.lime)
- setTable("free16", switchOutput, 59, 69, 15, 17, colors.black, colors.red, colors.lime)
- setTable("All OFF", turnAllOn, 31, 41, 3, 9, "" , colors.blue, colors.red)
- setTable("All ON", turnAllOff, 31, 41, 11, 17, "" , colors.blue, colors.lime)
- end
- function setTable(name, func, xmin, xmax, ymin, ymax, color, btnOff, btnOn)
- 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
- button[name]["color"] = color
- button[name]["btnOn"] = btnOn
- button[name]["btnOff"] = btnOff
- end
- function switchOutput(color)
- if rs.testBundledInput(side, color) then
- rs.setBundledOutput(side, (rs.getBundledInput(side)-color))
- else
- rs.setBundledOutput(side, (rs.getBundledInput(side)+color))
- end
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- mon.setTextColor(btnTextColor)
- 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(defaultBgColor)
- end
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then currColor = data["btnOn"] else currColor = data["btnOff"] end
- fill(name, currColor, data)
- end
- 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"](button[name]["color"])
- data["active"] = not data["active"]
- end
- end
- end
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setTextColor(headerColor)
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- fillTable()
- while true do
- mon.clear()
- heading("Spawners Controles On/Off:")
- screen()
- local e,side,x,y = os.pullEvent("monitor_touch")
- checkxy(x,y)
- sleep(.1)
- end
Add Comment
Please, Sign In to add comment