Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- lock = false
- local term = peripheral.wrap("top")
- tX, tY = term.getSize()
- rednet.open("right")
- term.setTextScale(1.5)
- clear()
- local mob={}
- redout = {}
- sheep = false
- function setTable(name, active, xmin, ymin, actiontype, action)
- --start, Whether it should be on or off when the program starts (true = on, false = off)
- --Modified by SuPeRMiNoR2
- mob[name] = {}
- mob[name]["action"] = action
- mob[name]["actiontype"] = actiontype
- mob[name]["active"] = active
- mob[name]["xmin"] = xmin
- mob[name]["ymin"] = ymin
- templen = xmin + #name - 1
- mob[name]["xmax"] = templen
- mob[name]["ymax"] = ymin
- end
- function fillTable()
- setTable("Reboot", false, 35, 17, "other", "reboot")
- setTable("Steam Engines", true, 1, 3, "other", "steam")
- setTable("Lock", true, 1, 17, "other", "lock")
- setTable("Lights", true, 1, 1, "other", "lights")
- end
- function fill(x,y,color,text)
- term.setBackgroundColor(color)
- term.setCursorPos(x,y)
- term.write(text)
- term.setBackgroundColor(colors.black)
- end
- function screen()
- while true do
- term.clear()
- if lock == false then
- local y = 2
- local currColor
- for name,data in pairs(mob) do
- x = data["xmin"]
- y = data["ymin"]
- local on = data["active"]
- if on == true then currColor = colors.lime else currColor = colors.red end
- fill(x,y,currColor, name)
- end
- fill(36, 1, colors.lime, os.time())
- end
- if lock == true then
- fill(12, 9, colors.red, "Control Panel Locked")
- end
- sleep(0.2)
- end
- end
- function checkxy(x, y)
- for name, data in pairs(mob) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- if lock == false then
- data["active"] = not data["active"]
- print(name..":"..tostring(x)..":"..tostring(y))
- end
- if lock == true then
- if name == "Lock" then
- data["active"] = not data["active"]
- end
- end
- end
- end
- end
- end
- function doStuff()
- local wire = 0
- for name, data in pairs(mob) do
- if data["active"] == true then
- if data["actiontype"] == "other" then
- if data["action"] == "reboot" then
- os.reboot()
- end
- if data["action"] == "sheep" then
- sheep = true
- end
- if data["action"] == "steam" then
- rednet.broadcast("steam_on")
- end
- if data["action"] == "lock" then
- lock = true
- end
- if data["action"] == "lights" then
- rednet.broadcast("lights_on")
- end
- end
- end
- if data["active"] == false then
- if data["actiontype"] == "wire" then
- if data["inver"] == true then
- wire = colors.combine(wire, data["action"])
- end
- end
- if data["actiontype"] == "other" then
- if data["action"] == "sheep" then
- sheep = false
- end
- end
- if data["action"] == "steam" then
- rednet.broadcast("steam_off")
- end
- if data["action"] == "lock" then
- lock = false
- end
- if data["action"] == "lights" then
- rednet.broadcast("lights_off")
- end
- end
- end
- redstone.setBundledOutput("bottom", wire)
- end
- function mainLoop()
- while true do
- local e,side,x,y = os.pullEvent("monitor_touch") --Get event
- print("Click: "..tostring(x)..":"..tostring(y))
- checkxy(x,y) --Check to see if click is on a button, and toggle state if it is
- doStuff() --Reads button state and does actions
- sleep(0.1)
- end
- end
- function main()
- fillTable() --Populate data table
- sleep(2)
- doStuff() --Run once to start autostart things
- parallel.waitForAll(mainLoop, screen)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement