Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reader = peripheral.wrap("left")
- m = peripheral.wrap("bottom")
- w,h = m.getSize()
- w = w + 1
- h = h + 1
- col = { ["white"]=1, ["orange"]=2, ["magenta"]=4, ["lightblue"]=8, ["yellow"]=16, ["lime"]=32, ["pink"]=64, ["gray"]=128, ["lightgray"]=256, ["cyan"]=512, ["purple"]=1024, ["blue"]=2048, ["brown"]=4096, ["green"]=8192, ["red"]=16384, ["black"]=32768 }
- id,state,title,data = reader.get(1)
- reactorOn = false
- shutdown = false
- function swrite(str,x,y,color)
- m.setCursorPos(x,y)
- m.setTextColor(col[color])
- m.write(str)
- end
- function swritecenter(str,y,color)
- m.setCursorPos((w/2-#str/2)+1,y)
- m.setTextColor(col[color])
- m.write(str)
- end
- function drawbox(str,x1,x2,y1,y2,strcol,color)
- m.setCursorPos(x1,y1)
- m.setBackgroundColor(col[color])
- m.setTextColor(col[strcol])
- local bw = x2-x1
- local bh = y2-y1
- local bstr = " "
- while #bstr < bw do
- bstr = bstr.." "
- end
- for i=1,bh do
- m.setCursorPos(x1,y1+i-1)
- m.write(bstr)
- end
- m.setCursorPos(x1+bw/2-#str/2,y1+bh/2)
- m.write(str)
- m.setBackgroundColor(col["black"])
- return { [1]=x1, [2]=x2, [3]=y1, [4]=y2 }
- end
- function drawtext(str,x,y,color)
- m.setCursorPos(x,y)
- m.setTextColor(col[color])
- m.write(str)
- return { [1]=x, [2]=x+1, [3]=y, [4]=y+#str }
- end
- function press(but)
- if event == "monitor_touch" then
- if pr2 >= but[1] and pr2 < but[2] and pr3 >= but[3] and pr3 < but[4] then
- return true
- else
- return false
- end
- end
- end
- function drawMenu()
- m.clear()
- drawbox("",1,w,1,h,"white","white")
- drawbox("",2,w-1,2,h-1,"white","black")
- swritecenter("Fair's Reactor Control System",3,"lime")
- swritecenter("Uranium left:",5,"white")
- swrite("Status:",4,11,"white")
- swrite("Heat:",4,13,"white")
- swrite("EU Output:",22,11,"white")
- swrite("Max heat:",22,13,"white")
- swrite("1000",33,13,"red")
- start = drawbox("Activate Reactor",4,w-4,16,19,"white","lime")
- os.startTimer(0.5)
- end
- function drawTimeLeft()
- drawbox("",3,w-3,7,10,"white","white")
- drawbox("",4,w-4,8,9,"white","red")
- local timeLeft = data["timeLeft"]
- if timeLeft > 0 then
- drawbox("",4,timeLeft/(10000/36),8,9,"white","lime")
- else
- drawbox("Out of Uranium",4,w-4,8,9,"black","red")
- end
- end
- function drawStatus()
- local Output = data["output"]
- local On = data["reactorPoweredB"]
- local Heat = data["heat"]
- if Output > 0 then
- swrite(tostring(Output).." ",33,11,"lime")
- else
- swrite(tostring(Output).." ",33,11,"lime")
- end
- if On then
- swrite("ACTIVE ",12,11,"lime")
- else
- swrite("STANDBY ",12,11,"red")
- end
- if Heat > 0 then
- swrite(tostring(Heat).." ",12,13,"red")
- else
- shutdown = false
- toggle()
- drawbox("",4,w-4,21,22,"red","black")
- swrite(tostring(Heat).." ",12,13,"lime")
- end
- if Heat > 1000 then
- shutdown = true
- toggle()
- drawbox("!! EMERGENCY SHUTDOWN !!",4,w-4,21,22,"red","black")
- end
- end
- function toggle()
- if reactorOn then
- redstone.setOutput("right",true)
- start = drawbox("Activate Reactor",4,w-4,1600,1900,"white","lime")
- stop = drawbox("Deactivate Reactor",4,w-4,16,19,"white","red")
- else
- redstone.setOutput("right",false)
- start = drawbox("Activate Reactor",4,w-4,16,19,"white","lime")
- stop = drawbox("Deactivate Reactor",4,w-4,1600,1900,"white","red")
- end
- if shutdown then
- redstone.setOutput("right",false)
- end
- end
- drawMenu()
- while true do
- drawTimeLeft()
- drawStatus()
- event,pr1,pr2,pr3 = os.pullEvent()
- id,state,title,data = reader.get(1)
- if press(start) or press(stop) then
- if reactorOn then
- reactorOn = false
- else
- reactorOn = true
- end
- toggle()
- elseif event == "timer" then
- drawTimeLeft()
- drawStatus()
- os.startTimer(0.5)
- end
- end
- -- data: heat,isSteam,reactorPoweredB,maxHeat,timeLeft,output
Advertisement
Add Comment
Please, Sign In to add comment