Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local button = {}
- local side = "top"
- local mon = peripheral.wrap("back")
- local textScale = 1
- ------------ color variables ------------
- local btnTextColor = colors.white
- local defaultBgColor = colors.gray
- local headerColor = colors.white
- -----------------------------------------
- function turnAllOff()
- rs.setBundledOutput(side, 0)
- for name, data in pairs(button) do
- data["active"] = false
- if name == "All ON" then
- button[name]["active"] = true
- end
- mon.clear()
- heading("MobFarm Steuertafel")
- screen()
- end
- end
- function turnAllOn()
- rs.setBundledOutput(side, 65535)
- for name, data in pairs(button) do
- data["active"] = true
- if name == "All OFF" then
- button[name]["active"] = false
- end
- mon.clear()
- heading("MobFarm Steuertafel")
- screen()
- end
- end
- rs.setBundledOutput(side, 0)
- term.clear()
- term.setCursorPos(1,1)
- mon.setBackgroundColor(defaultBgColor)
- mon.setTextScale(textScale)
- mon.clear()
- function fillTable()
- setTable("Mfsu", switchOutput, 17, 32, 3, 3, colors.white, colors.lime, colors.red)
- setTable("Zombie", switchOutput, 34, 47, 3, 3, colors.orange, colors.lime, colors.red)
- setTable("Skeleton", switchOutput, 17, 32, 5, 5, colors.magenta, colors.lime, colors.red)
- setTable("Witch", switchOutput, 34, 47, 5, 5, colors.lightBlue, colors.lime, colors.red)
- setTable("Iron Golem", switchOutput, 17, 32, 7, 7, colors .yellow, colors.lime, colors.red)
- setTable("Ceeper", switchOutput, 34, 47, 7, 7, colors.lime, colors.lime, colors.red)
- setTable("Spider", switchOutput, 17, 32, 9, 9, colors.pink, colors.lime, colors.red)
- setTable("Enderman", switchOutput, 34, 47, 9, 9, colors.gray, colors.lime, colors.red)
- setTable("Blaze", switchOutput, 17, 32, 11, 11, colors.lightGray, colors.lime, colors.red)
- setTable("Zombie Pigman", switchOutput, 34, 47, 11, 11, colors.cyan, colors.lime, colors.red)
- setTable("Angry Zombie", switchOutput, 17, 32, 13, 13, colors.cyan, colors.lime, colors.red)
- setTable("Ghast", switchOutput, 34, 47, 13, 13, colors.cyan, colors.lime, colors.red)
- setTable("Cow", switchOutput, 17, 32, 15, 15, colors.cyan, colors.lime, colors.red)
- setTable("Sheep^", switchOutput, 34, 47, 15, 15, colors.cyan, colors.lime, colors.red)
- setTable("Frei1", switchOutput, 17, 32, 17, 17, colors.cyan, colors.lime, colors.red)
- setTable("frei2", switchOutput, 34, 47, 17, 17, colors.cyan, colors.lime, colors.red)
- setTable("All OFF", turnAllOn, 3, 13, 3, 3, "" , colors.red, colors.red)
- setTable("All ON", turnAllOff, 3, 13, 5, 5, "" , colors.lime, colors.lime)
- end
- function setTable(name, func, xmin, xmax, ymin, ymax, color, btnOff, btnOn)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = true
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- button[name]["color"] = color
- button[name]["btnOff"] = btnOff
- button[name]["btnOn"] = btnOn
- 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()
- turnAllOn()
- while true do
- mon.clear()
- heading("MobFarm Steuertafel")
- screen()
- local e,side,x,y = os.pullEvent("monitor_touch")
- checkxy(x,y)
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement