Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --== Init ==--
- local monitor = peripheral.wrap("monitor_1")
- local reactor = peripheral.wrap("BigReactors-Reactor_0")
- local echest = peripheral.wrap("ender_chest_1")
- local matrix = peripheral.wrap("back")
- term.redirect(monitor)
- term.setBackgroundColor(colors.black)
- term.clear()
- monitor.setTextScale(.5)
- local mw, mh
- local refreshRate = 0.15
- local refreshTimer = os.startTimer(refreshRate)
- local counter = 0
- local running = true
- local mouseDown = false
- local mouseX = -1
- local mouseY = -1
- local fillBar --object used for drawing fill bars
- local xOffset = 0
- local yOffset = 0
- local rReservesAmount = 0
- local rReservesCapacity = echest.getInventorySize() * 64
- --== Functions ==--
- local function joulesToRF(value)
- return value*0.4
- end
- local function drawFillBar()
- --Uses fillBar object vars to draw a fill bar
- local fb = fillBar
- local ratio = fb.value/fb.valueMax
- local tempvar = -1
- if (fb.x2 < fb.x1) then
- tempvar = fb.x2
- fb.x2 = fb.x1
- fb.x1 = tempvar
- end
- if (fb.y2 < fb.y1) then
- tempvar = fb.y2
- fb.y2 = fb.y1
- fb.y1 = tempvar
- end
- local width = fb.x2 - fb.x1
- local height = fb.y2 - fb.y1
- if (fb.bordered) then
- paintutils.drawBox(fb.x1, fb.y1, fb.x2, fb.y2, fb.colBorder)
- end
- if (fb.dir == 0) then
- if (fb.bordered) then
- paintutils.drawFilledBox(fb.x1+1, fb.y1+1, fb.x2-1, fb.y2-1, fb.colBG)
- if (ratio ~= 0) then
- paintutils.drawFilledBox(fb.x1+1, fb.y1+1, fb.x1+1+math.floor((width-2)*ratio), fb.y2-1, fb.colValue)
- end
- else
- paintutils.drawFilledBox(fb.x1, fb.y1, fb.x2, fb.y2, fb.colBG)
- if (ratio ~= 0) then
- paintutils.drawFilledBox(fb.x1, fb.y1, fb.x1+math.floor(width*ratio), fb.y2, fb.colValue)
- end
- end
- elseif (fb.dir == 1) then
- if (fb.bordered) then
- paintutils.drawFilledBox(fb.x1+1, fb.y2-1, fb.x2-1, fb.y1+1, fb.colBG)
- if (ratio ~= 0) then
- paintutils.drawFilledBox(fb.x1+1, fb.y2-1, fb.x2-1, fb.y2-1-math.floor((height-2)*ratio), fb.colValue)
- end
- else
- paintutils.drawFilledBox(fb.x1, fb.y2, fb.x2, fb.y1, fb.colBG)
- if (ratio ~= 0) then
- paintutils.drawFilledBox(fb.x1, fb.y2, fb.x1, fb.y2-math.floor(height*value), fb.colValue)
- end
- end
- elseif (fb.dir == 2) then
- --not needed
- elseif (fb.dir == 3) then
- --not needed
- end
- end
- local function countItemInInventory(periph, itemName)
- --Returns the amount of a certain item in a peripheral's inventory
- local invSize = periph.getInventorySize()
- local amount = 0
- for i=1,invSize do
- local stack = periph.getStackInSlot(i)
- if (stack ~= nil) then
- if (stack.name == itemName) then
- amount = amount + stack.qty
- end
- end
- end
- return amount
- end
- local function drawMultiText(x, y, strTable)
- for i=1,#strTable do
- term.setCursorPos(x,y+(i-1))
- term.write(strTable[i])
- end
- end
- local function clearTable(t)
- local k = next(t)
- while k do
- t[k] = nil
- k = next(t)
- end
- end
- local function handleInput()
- mouseDown = false
- local event,p1,p2,p3 = os.pullEvent()
- if (event == "key") then
- --stop program
- if (p1 == keys.backspace) then
- running = false
- end
- elseif (event == "monitor_touch") then
- mouseDown = true
- mouseX = p2
- mouseY = p3
- elseif (event == "timer" and p1 == refreshTimer) then
- refreshTimer = os.startTimer(refreshRate)
- end
- end
- --== Main ==--
- while running do
- term.setBackgroundColor(colors.black)
- term.clear()
- mw,mh = term.getSize() --check for resize
- fillBar = {x1, y1, x2, y2, value, valueMin, valueMax, dir, bordered, colBG, colValue, colBorder}
- --x1,y1,x2,y2: coords for drawing
- --value: amount to fill the bar
- --valueMin,valueMax: lower&upper bounds for value to fill
- --dir: (0,1,2,3) direction the bar will fill towards
- --bordered: (true/false) draws a border around the fill bar (inward from the coords given)
- --colBG,colValue,colBorder: which color to draw said element of the fill bar
- --ASCII TEXT FORMATTING--
- local multitext = {}
- multitext[1] = " _ _ _ ___ _ _"
- multitext[2] = "|_) |_ /\\ / | / \\ |_)"
- multitext[3] = "| \\ |_ /--\\ \\_ | \\_/ | \\"
- drawMultiText(1,1,multitext)
- clearTable(multitext)
- xOffset = math.floor(mw/2)
- for i=1,mh do
- term.setCursorPos(xOffset,i)
- term.write("|")
- end
- multitext[1] = " ___ _ ___"
- multitext[2] = "|\\/| /\\ | |_) | \\/"
- multitext[3] = "| | /--\\ | | \\ _|_ /\\"
- drawMultiText(2+xOffset,1,multitext)
- clearTable(multitext)
- --REACTOR--
- --Status
- if (mouseDown and mouseX >= 2 and mouseX <= 6 and mouseY >= 6 and mouseY <= 9) then
- if (reactor.getActive()) then
- reactor.setActive(false)
- else
- reactor.setActive(true)
- end
- end
- xOffset = 0
- term.setCursorPos(8,6)
- term.setTextColor(colors.white)
- term.write("Status:")
- term.setCursorPos(8,7)
- if (reactor.getActive()) then
- term.setTextColor(colors.lime)
- term.write("Active")
- paintutils.drawBox(2,6,6,9,colors.green)
- paintutils.drawFilledBox(3,7,5,8,colors.lime)
- paintutils.drawLine(2,6,6,6,colors.white)
- else
- term.setTextColor(colors.red)
- term.write("Not Active")
- paintutils.drawBox(2,6,6,9,colors.gray)
- paintutils.drawFilledBox(3,7,5,8,colors.red)
- paintutils.drawLine(2,6,6,6,colors.white)
- end
- --Energy Output
- xOffset = 0
- term.setBackgroundColor(colors.black)
- term.setCursorPos(xOffset+2,12)
- term.setTextColor(colors.white)
- term.write("Energy Output:")
- term.setCursorPos(xOffset+17,12)
- term.setTextColor(colors.lime)
- term.write(math.floor(reactor.getEnergyProducedLastTick()).." RF/t")
- --Fuel
- term.setCursorPos(xOffset+2,14)
- term.setTextColor(colors.lightGray)
- term.write("Fuel")
- --Usage
- term.setCursorPos(xOffset+2,15)
- term.setTextColor(colors.white)
- term.write("Consumption:")
- term.setCursorPos(xOffset+15,15)
- term.setTextColor(colors.red)
- term.write((math.floor(reactor.getFuelConsumedLastTick()*100)/100).." mB/t")
- --Reactivity
- term.setCursorPos(xOffset+2,16)
- term.setTextColor(colors.white)
- term.write("Reactivity:")
- term.setCursorPos(xOffset+15,16)
- term.setTextColor(colors.yellow)
- term.write(math.floor(reactor.getFuelReactivity()).."%")
- --Heat
- xOffset = math.floor(mw/2)
- term.setCursorPos(xOffset-20,14)
- term.setTextColor(colors.lightGray)
- term.write("Heat")
- --Casing
- term.setCursorPos(xOffset-20,15)
- term.setTextColor(colors.white)
- term.write("Casing:")
- term.setCursorPos(xOffset-20+8,15)
- term.setTextColor(colors.orange)
- term.write((math.ceil(reactor.getCasingTemperature()*100)/100).." 'C")
- --Core
- term.setCursorPos(xOffset-20,16)
- term.setTextColor(colors.white)
- term.write("Core:")
- term.setCursorPos(xOffset-20+8,16)
- term.setTextColor(colors.orange)
- term.write((math.ceil(reactor.getFuelTemperature()*100)/100).." 'C")
- --Control Rod Insertion
- xOffset = 0
- term.setCursorPos(xOffset+2,19)
- term.setTextColor(colors.white)
- term.write("Control Rod Insertion ("..reactor.getNumberOfControlRods().." in total):")
- term.setCursorPos(xOffset+2,20)
- term.setTextColor(colors.lightGray)
- term.write(tostring(reactor.getControlRodLevel(0)).."%")
- --Fuel Reserves
- xOffset = 0
- if (counter % 10 == 0) then
- --only update reserves every 10 frames; less lag
- rReservesAmount = countItemInInventory(echest, "BRIngot")
- end
- term.setCursorPos(xOffset+2, mh-6)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write("Fuel Reserves:")
- term.setCursorPos(xOffset+15+2, mh-6)
- term.setTextColor(colors.yellow)
- term.write(rReservesAmount.." / "..rReservesCapacity.." Yellorium")
- fillBar = {
- x1 = xOffset + 2,
- y1 = yOffset + mh-5,
- x2 = xOffset + math.floor(mw/2) - 2,
- y2 = yOffset + mh-1,
- value = rReservesAmount,
- valueMin = 0,
- valueMax = rReservesCapacity,
- dir = 0,
- bordered = true,
- colBG = colors.black,
- colValue = colors.yellow,
- colBorder = colors.gray,
- }
- drawFillBar()
- --
- --MATRIX--
- xOffset = math.floor(mw/2)
- --Input
- local matrixInput = matrix.getInput()
- local matrixCap = matrix.getTransferCap()
- term.setCursorPos(xOffset+2, 6)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write("Input:")
- term.setCursorPos(xOffset+9, 6)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- term.write(tostring(joulesToRF(matrixInput)) .." RF/t")
- fillBar = {
- x1 = xOffset + 2,
- y1 = yOffset + 7,
- x2 = xOffset + xOffset - 1,
- y2 = yOffset + 13,
- value = matrixInput,
- valueMin = 0,
- valueMax = matrixCap,
- dir = 0,
- bordered = true,
- colBG = colors.black,
- colValue = colors.blue,
- colBorder = colors.gray,
- }
- drawFillBar()
- --Energy Stored
- term.setCursorPos(xOffset+2, 16)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write("Energy:")
- term.setCursorPos(xOffset+10, 16)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lime)
- term.write(joulesToRF(matrix.getEnergy()) .." / ".. joulesToRF(matrix.getMaxEnergy()) .." RF")
- fillBar = {
- x1 = xOffset + 2,
- y1 = yOffset + 17,
- x2 = xOffset + xOffset - 1,
- y2 = yOffset + 27,
- value = matrix.getEnergy(),
- valueMin = 0,
- valueMax = matrix.getMaxEnergy(),
- dir = 0,
- bordered = true,
- colBG = colors.black,
- colValue = colors.lime,
- colBorder = colors.gray,
- }
- drawFillBar()
- term.setCursorPos(xOffset+math.floor(xOffset/2)-2, 27)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.lightGray)
- term.write(string.sub(math.floor((matrix.getEnergy()/matrix.getMaxEnergy())*100), 1, 4).."%")
- --Output
- local matrixOutput = matrix.getOutput()
- term.setCursorPos(xOffset+2, 30)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write("Output:")
- term.setCursorPos(xOffset+10, 30)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- term.write(tostring(joulesToRF(matrixOutput)) .." RF/t")
- fillBar = {
- x1 = xOffset + 2,
- y1 = yOffset + 31,
- x2 = xOffset + xOffset - 1,
- y2 = yOffset + 37,
- value = matrixOutput,
- valueMin = 0,
- valueMax = matrixCap,
- dir = 0,
- bordered = true,
- colBG = colors.black,
- colValue = colors.red,
- colBorder = colors.gray,
- }
- drawFillBar()
- --REFRESH--
- term.setTextColor(colors.white)
- counter = counter + 1
- handleInput()
- end
- --local energyStr = tostring(fillBar.value)
- --local percent = fillbar.value / fillBar.valueMax
- --local percentStr = tostring(percent*100)
- --percentStr = string.sub(percentStr,1,5).."%"
- --local colPercent = colors.white
- --Energy Text
- --term.setBackgroundColor(colors.black)
- --term.setTextColor(colEnergy)
- --term.setCursorPos(math.ceil(x1+(width/2)-((#energyStr)/2)),mh)
- --term.write(energyStr)
- --Percent Text
- --term.setTextColor(colPercent)
- --term.setCursorPos(math.ceil(x1+(width/2)-((#percentStr)/2)),mh-1)
- --term.write(percentStr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement