Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Reactor Controller v2.1
- Author: Tankman
- May contain ants
- ]]
- -- Load Libraries
- local component = require("component")
- local sides = require("sides")
- local event = require("event")
- local term = require("term")
- local tt = require("tankTools")
- -- Hook Components
- local screen = component.screen
- local gpu = component.gpu
- local reactor = component.proxy("73d35576-e02c-474c-9b4d-841c9df8df10")
- local inv = component.proxy("1cbde4bf-9ce2-43d2-9548-aad062b1344e")
- local rs = component.proxy("91e053e1-0d60-471c-aec9-7207bd714be5")
- local tank = component.proxy("68c5c9d1-d0fc-4bbc-8419-98a51edbf0ca")
- -- User Settings
- local cSide = sides.south -- Sides are a bit picky
- local rSide = sides.east
- local iSide = sides.west
- -- Internal Variables
- local sidebarState = "Gauges"
- local sidebarGUI = false
- local check = true
- local charging = false
- local depleted = 0
- local overide = false
- local overheat = false
- local radiation = false
- local fuelTimer = 0
- local sw, sh = gpu.getResolution()
- -- Functional Variables
- local active = reactor.getReactorEUOutput()
- local heat = reactor.getHeat()
- local maxHeat = reactor.getMaxHeat()
- local coolent = tank.getFluidInTank(cSide)
- local coolTank = coolent[1].amount
- local coolTankMax = coolent[1].capacity
- local hotTank = coolent[2].amount
- local hotTankMax = coolent[2].capacity
- local fuel = {}
- -- Colors
- local fg = gpu.getForeground()
- local bg = gpu.getBackground()
- local colors = tt.colors()
- -- GUI Elements
- local controlButton = tt.buttonCreate("Start", 47, 5, 11, 3, colors.lime, colors.black)
- local exitButton = tt.buttonCreate("Exit", 47, 11, 11, 3, colors.blue, colors.white)
- local gaugesButton = tt.buttonCreate("Gauges", 2, 2, 12, 1, colors.red, colors.white)
- local fuelButton = tt.buttonCreate(" Fuel ", 14, 2, 10, 1, colors.blue, colors.white)
- local heatBar = tt.barCreate(62, 6, 2, 18, colors.silver, colors.orange)
- local coolentBar = tt.barCreate(69, 6, 2, 18, colors.silver, colors.cyan)
- local hotCoolentBar = tt.barCreate(76, 6, 2, 18, colors.silver, colors.pink)
- function exit()
- rs.setOutput(rSide, 0)
- check = false
- event.ignore('touch',touch)
- term.clear()
- screen.setTouchModeInverted(false)
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- os.exit()
- end
- function fuelCheck()
- local count = 0
- for i = 1, 54 do
- local temp = inv.getStackInSlot(iSide, i)
- if temp ~= nil then
- if string.find(temp.label, "Fuel") then
- count = count + 1
- fuel[count] = temp.label
- end
- end
- end
- gpu.setBackground(colors.blue)
- gpu.setForeground(colors.white)
- if count == 0 and fuel[1] ~= nil then
- fuel = {}
- end
- if fuel[1] ~= nil then
- if tt.fuzzyCount(fuel, "Depleted") > 0 then
- gpu.fill(4, 10, 22, 1, " ")
- gpu.set(4, 10, "Fuel Summary: Depleted")
- rs.setOutput(rSide, 0)
- controlButton.text = "Start"
- controlButton:disable(true)
- else
- gpu.fill(4, 10, 22, 1, " ")
- gpu.set(4, 10, "Fuel Summary: Fissile")
- controlButton:disable(false)
- end
- else
- gpu.fill(4, 10, 22, 1, " ")
- gpu.set(4, 10, "Fuel Summary: Empty")
- rs.setOutput(rSide, 0)
- controlButton.text = "Start"
- controlButton:disable(true)
- end
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- end
- function checkReactor()
- heat = reactor.getHeat()
- active = reactor.getReactorEUOutput()
- local heatPercentage = tt.percent(heat, maxHeat)
- gpu.setBackground(colors.blue)
- gpu.setForeground(colors.white)
- if active == 0 then
- gpu.fill(4, 7, 15, 1, " ")
- gpu.set(4, 7, "Reactor Offline")
- else
- gpu.fill(4, 7, 15, 1, " ")
- gpu.set(4, 7, "Reactor Online")
- end
- gpu.fill(4, 8, 24, 1, " ")
- gpu.set(4, 8, "Reactor Temp: " .. heat)
- gpu.set(4, 9, "Reactor Max Temp: " .. maxHeat)
- if active == 0 and charging == false and overide == false and overheat == false then
- if fuelTimer == 0 then
- fuelCheck()
- fuelTimer = 20
- else
- fuelTimer = fuelTimer - 1
- end
- end
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- if heatPercentage >= 70 then
- radiation = true
- else
- radiation = false
- end
- if sidebarState == "Gauges" then
- if heatPercentage >= 75 then
- overheat = true
- overide = false
- rs.setOutput(rSide, 0)
- controlButton.text = "Start"
- controlButton:disable(true)
- else
- if overheat == true and heatPercentage == 0 then
- overheat = false
- controlButton:disable(false)
- end
- end
- if heatPercentage <= 25 then
- heatBar.fColor = colors.lightBlue
- heatBar:draw(heatPercentage)
- else
- if heatPercentage == 42 then
- heatBar.fColor = colors.green
- heatBar:draw(heatPercentage)
- else
- if heatPercentage <= 50 then
- heatBar.fColor = colors.yellow
- heatBar:draw(heatPercentage)
- else
- if heatPercentage <= 75 then
- heatBar.fColor = colors.orange
- heatBar:draw(heatPercentage)
- else
- if heatPercentage <= 100 then
- heatBar.fColor = colors.red
- heatBar:draw(heatPercentage)
- end
- end
- end
- end
- end
- end
- end
- function sidebar()
- if sidebarState == "Gauges" then
- if sidebarGUI == false then
- tt.label(59, 4, 20, " Gauges ", colors.white, colors.white)
- gpu.setBackground(colors.blue)
- gpu.setForeground(colors.white)
- gpu.fill(59, 5, 20, 20, " ")
- tt.vText(60, 7, "HEAT", colors.white)
- tt.vText(67, 7, "COOLENT", colors.white)
- tt.vText(74, 7, "HOT COOLENT", colors.white)
- tt.vLine(65, 6, 18, colors.white)
- tt.vLine(72, 6, 18, colors.white)
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- sidebarGUI = true
- end
- coolent = tank.getFluidInTank(cSide)
- coolTank = coolent[1].amount
- hotTank = coolent[2].amount
- coolentBar:draw(tt.percent(coolTank, coolTankMax))
- hotCoolentBar:draw(tt.percent(hotTank, hotTankMax))
- else if sidebarState == "Fuel" then
- if sidebarGUI == false then
- tt.label(59, 4, 20, " Fuel ", colors.white, colors.white)
- gpu.setBackground(colors.blue)
- gpu.setForeground(colors.white)
- gpu.fill(59, 5, 20, 20, " ")
- gpu.set(60, 6, "Fuel U: " .. tt.itemCount(fuel, "Fuel Rod (Uranium)"))
- gpu.set(60, 7, "Dual U: " .. tt.itemCount(fuel, "Dual Fuel Rod (Uranium)"))
- gpu.set(60, 8, "Quad U: " .. tt.itemCount(fuel, "Quad Fuel Rod (Uranium)"))
- gpu.set(60, 9, "Fuel MOX: " .. tt.itemCount(fuel, "Fuel Rod (MOX)"))
- gpu.set(60, 10, "Dual MOX: " .. tt.itemCount(fuel, "Dual Fuel Rod (MOX)"))
- gpu.set(60, 11, "Quad MOX: " .. tt.itemCount(fuel, "Quad Fuel Rod (MOX)"))
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- sidebarGUI = true
- end
- end
- end
- end
- function touch(name, address, x, y, button, player)
- if controlButton:press(x, y) then
- active = reactor.getReactorEUOutput()
- if active == 0 then
- overide = false
- controlButton.tColor = colors.white
- controlButton.bColor = colors.red
- controlButton.text = "Stop"
- rs.setOutput(rSide, 15)
- else
- overide = true
- controlButton.tColor = colors.black
- controlButton.bColor = colors.lime
- controlButton.text = "Start"
- rs.setOutput(rSide, 0)
- end
- controlButton:draw()
- else if exitButton:press(x, y) then
- exit()
- else if gaugesButton:press(x, y) and sidebarState ~= "Gauges" then
- sidebarState = "Gauges"
- sidebarGUI = false
- gaugesButton.bColor = colors.red
- fuelButton.bColor = colors.blue
- gaugesButton:draw()
- fuelButton:draw()
- else if fuelButton:press(x, y) and sidebarState ~= "Fuel" then
- fuelCheck()
- sidebarState = "Fuel"
- sidebarGUI = false
- gaugesButton.bColor = colors.blue
- fuelButton.bColor = colors.red
- gaugesButton:draw()
- fuelButton:draw()
- end
- end
- end
- end
- end
- function drawNotifications()
- gpu.setBackground(colors.blue)
- gpu.setForeground(colors.white)
- local center
- gpu.fill(3, 16, 54, 9, " ")
- if overheat == true then
- center = tt.textCenter(3, 16, 54, 9, "Reactor Nearing Meltdown, Console locked")
- gpu.set(center.x, center.y, "Reactor Nearing Meltdown, Console locked")
- else
- if radiation == true then
- center = tt.textCenter(3, 16, 54, 9, "Danger: Radiation Leak")
- gpu.set(center.x, center.y, "Danger: Radiation Leak")
- else
- if depleted > 0 or fuel[1] == nil then
- center = tt.textCenter(3, 16, 54, 9, "Please Replace Fuel")
- gpu.set(center.x, center.y, "Please Replace Fuel")
- else
- if charging == true then
- center = tt.textCenter(3, 16, 54, 9, "Reactor Idle, Batteries Full")
- gpu.set(center.x, center.y, "Reactor Idle, Batteries Full")
- else
- if overide == true then
- center = tt.textCenter(3, 16, 54, 9, "Manual Shutdown Engaged")
- gpu.set(center.x, center.y, "Manual Shutdown Engaged")
- else
- center = tt.textCenter(3, 16, 54, 9, "Everything Nominal")
- gpu.set(center.x, center.y, "Everything Nominal")
- end
- end
- end
- end
- end
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- end
- function drawGUI()
- gpu.setBackground(bg)
- gpu.fill(1, 1, sw, sh, " ")
- tt.frameDraw(1, 1, sw, sh, colors.white)
- tt.frameDraw(1, 1, sw, 3, colors.white)
- tt.label(2, 1, sw - 2, "[ Reactor Control ]", colors.white, colors.white)
- gpu.set(1, 3, "╠")
- gpu.set(sw, 3, "╣")
- tt.frameDraw(3, 4, 43, 11, colors.white)
- tt.label(4, 4, 41, " Status ", colors.white, colors.white)
- tt.label(3, 15, 55, " Notifications ", colors.white, colors.white)
- tt.hLine(47, 9, 11, colors.white)
- gpu.setBackground(colors.blue)
- gpu.fill(2, 2, sw - 2, 1, " ") -- Menu Bar
- gpu.fill(4, 5, 41, 9, " ") -- Status Background
- gpu.fill(3, 16, 55, 9, " ") -- Notifications Area
- gpu.setBackground(bg)
- controlButton:draw()
- exitButton:draw()
- gaugesButton:draw()
- fuelButton:draw()
- end
- function run()
- screen.setTouchModeInverted(true)
- rs.setOutput(rSide, 0)
- drawGUI()
- event.listen("touch", touch)
- fuelCheck()
- while check do
- checkReactor()
- sidebar()
- drawNotifications()
- os.sleep(0.25)
- end
- end
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement