Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --##Link all chosen peripherals
- mon = peripheral.wrap("monitor_2")
- core = peripheral.wrap("draconic_rf_storage_2")
- reactor = peripheral.wrap("BigReactors-Reactor_1")
- backColor = colors.black
- exitProgram = 0
- --##increase screen resolution to max and ensure all terminal output goes to monitor.
- term.redirect(mon)
- mon.setTextScale(.5)
- local function int(num1)
- num2 = math.ceil(num1)
- if num2 - num1 > .6 then
- num1 = math.floor(num1)
- elseif num2 - num1 <= .5 then
- num1 = math.ceil(num1)
- end
- return num1
- end
- --##Add Chosen Text At Location
- local function label(xPos, yPos, labelText, textColor)
- mon.setBackgroundColor(backColor)
- mon.setTextColor(textColor)
- mon.setCursorPos(xPos, yPos)
- mon.write(labelText)
- end
- --##Create A Button at the location with the chosen text
- local function button(xPos, yPos, bLen, bWid, labelText, textColor, buttonColor)
- paintutils.drawFilledBox(xPos, yPos, xPos + bLen - 1, yPos + bWid - 1, buttonColor)
- mon.setTextColor(textColor)
- mon.setBackgroundColor(buttonColor)
- mon.setCursorPos(xPos + int(bLen / 2) - int(string.len(labelText) / 2), yPos + int(bWid / 2)-1)
- mon.write(labelText)
- end
- --##Create A frame at the location with the chosen text
- local function drawFrame(xPos, yPos, xPos2, yPos2, labelText, textColor, frameColor)
- paintutils.drawBox(xPos, yPos, xPos2, yPos2, frameColor)
- mon.setTextColor(textColor)
- mon.setBackgroundColor(backColor)
- mon.setCursorPos(xPos + ((xPos2 - xPos) / 2) - int(string.len(labelText) / 2) + 1, yPos)
- mon.write(labelText)
- end
- --##Wipe background to chosen color
- local function clean(bColor)
- mon.setBackgroundColor(bColor)
- mon.clear()
- end
- --##Convert number to engineering notation
- local function eng(rawNum)
- tempNum = tostring(rawNum)
- numLen = string.len(tempNum)
- if string.sub(tempNum,1,1) == "-" then
- isNegative = true
- tempNum2 = string.sub(tempNum, 2, numLen)
- tempNum = tempNum2
- else
- isNegative = false
- end
- if numLen == 4 then
- tempNum = string.sub(tempNum, 1, 1) .. "," .. string.sub(tempNum, 2, 3) .. "K"
- elseif numLen == 5 then
- tempNum = string.sub(tempNum, 1, 2) .. "," .. string.sub(tempNum, 3, 4) .. "K"
- elseif numLen == 6 then
- tempNum = string.sub(tempNum, 1, 3) .. "," .. string.sub(tempNum, 4, 5) .. "K"
- elseif numLen == 7 then
- tempNum = string.sub(tempNum, 1, 1) .. "," .. string.sub(tempNum, 2, 3) .. "M"
- elseif numLen == 8 then
- tempNum = string.sub(tempNum, 1, 2) .. "," .. string.sub(tempNum, 3, 4) .. "M"
- elseif numLen == 9 then
- tempNum = string.sub(tempNum, 1, 3) .. "," .. string.sub(tempNum, 4, 5) .. "M"
- elseif numLen == 10 then
- tempNum = string.sub(tempNum, 1, 1) .. "," .. string.sub(tempNum, 2, 3) .. "G"
- elseif numLen == 11 then
- tempNum = string.sub(tempNum, 1, 2) .. "," .. string.sub(tempNum, 3, 4) .. "G"
- elseif numLen == 12 then
- tempNum = string.sub(tempNum, 1, 3) .. "," .. string.sub(tempNum, 4, 5) .. "G"
- elseif numLen == 13 then
- tempNum = string.sub(tempNum, 1, 1) .. "," .. string.sub(tempNum, 2, 3) .. "T"
- elseif numLen == 14 then
- tempNum = string.sub(tempNum, 1, 2) .. "," .. string.sub(tempNum, 3, 4) .. "T"
- elseif numLen == 15 then
- tempNum = string.sub(tempNum, 1, 3) .. "," .. string.sub(tempNum, 4, 5) .. "T"
- end
- if isNegative == true then
- tempNum = "-" .. tempNum
- end
- --tempNum = tonumber(tempNum)
- return tempNum
- end
- --##Figures out the core tier
- local function coreTier()
- if core.getMaxEnergyStored() == 45500000 then
- return "1"
- elseif core.getMaxEnergyStored() == 273000000 then
- return "2"
- elseif core.getMaxEnergyStored() == 1640000000 then
- return "3"
- elseif core.getMaxEnergyStored() == 9880000000 then
- return "4"
- elseif core.getMaxEnergyStored() == 59300000000 then
- return "5"
- elseif core.getMaxEnergyStored() == 356000000000 then
- return "6"
- elseif core.getMaxEnergyStored() == 2140000000000 then
- return "7"
- else
- return "8"
- end
- end
- --##Draws GUI
- local function drawScreen()
- clean(backColor)
- drawFrame(2,2,36,11, "Energy Core", colors.white, colors.gray)
- label(5,5,"Tier: ",colors.white)
- label(5,7,"Stored: ",colors.white)
- label(5,9,"Energy Flow: ",colors.white)
- button(2,13,16,3, "Online", colors.white, colors.green)
- button(21,13,16,3, "Offline", colors.white, colors.red)
- button(2,21,16,3, "End Program", colors.white, colors.blue)
- label(11,5, coreTier(), colors.white)
- label(13,7, eng(core.getEnergyStored()) .. "/" .. eng(core.getMaxEnergyStored()) .. " RF/t", colors.orange)
- if core.getTransferPerTick() ~= nil then
- if core.getTransferPerTick() < 0 then
- label(18,9, core.getTransferPerTick(), colors.red)
- elseif core.getTransferPerTick() > 0 then
- label(18,9, core.getTransferPerTick(), colors.green)
- else
- label(18,9, core.getTransferPerTick(), colors.white)
- end
- end
- drawFrame(38,2,78,15, "Reactor Status", colors.white, colors.gray)
- label(41,5,"Status: ",colors.white)
- label(41,7,"Generating: ",colors.white)
- label(41,9,"Fuel Consumption: ",colors.white)
- label(41,11,"Spent Fuel: ",colors.white)
- label(41,13,"Control Rod Insertion: ",colors.white)
- if reactor.getActive() == true then
- label(49,5,"Online",colors.green)
- else
- label(49,5,"Offline",colors.red)
- end
- label(53,7,eng(int(reactor.getEnergyProducedLastTick())) .. " RF/t",colors.white)
- label(59,9,math.floor(reactor.getFuelConsumedLastTick()*1000)/1000 .. " mB/t",colors.yellow)
- label(53,11,math.floor(reactor.getWasteAmount()*1000) / 1000 .. " mB/t",colors.blue)
- label(64,13,reactor.getControlRodLevel(1) .. "%",colors.white)
- drawFrame(38,17,78,23, "Control Rods", colors.white, colors.gray)
- button(41,19,7,3, "+10", colors.white, colors.gray)
- button(50,19,7,3, "+1", colors.white, colors.gray)
- button(59,19,7,3, "-1", colors.white, colors.gray)
- button(68,19,7,3, "-10", colors.white, colors.gray)
- sleep(1)
- end
- --##Exit Program
- local function shutDown()
- button(1,1,79,25, "Shutting Down. Goodbye.", colors.white, colors.black)
- sleep(3)
- mon.clear()
- end
- --##Waits for touch screen input
- local function touch()
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if xPos >= 2 and xPos <= 18 and yPos >= 21 and yPos <= 23 then
- exitProgram = 1
- elseif xPos >= 2 and xPos <= 17 and yPos >= 13 and yPos <= 15 then
- reactor.setActive(true)
- elseif xPos >= 21 and xPos <= 36 and yPos >= 13 and yPos <= 15 then
- reactor.setActive(false)
- elseif xPos >= 41 and xPos <= 47 and yPos >= 19 and yPos <= 21 then
- if reactor.getControlRodLevel(1) + 10 <= 100 then
- reactor.setAllControlRodLevels(reactor.getControlRodLevel(1) + 10)
- else
- reactor.setAllControlRodLevels(100)
- end
- elseif xPos >= 68 and xPos <= 74 and yPos >= 19 and yPos <= 21 then
- if reactor.getControlRodLevel(1) - 10 >= 0 then
- reactor.setAllControlRodLevels(reactor.getControlRodLevel(1) - 10)
- else
- reactor.setAllControlRodLevels(0)
- end
- elseif xPos >= 50 and xPos <= 56 and yPos >= 19 and yPos <= 21 then
- if reactor.getControlRodLevel(1) + 1 <= 100 then
- reactor.setAllControlRodLevels(reactor.getControlRodLevel(1) + 1)
- else
- reactor.setAllControlRodLevels(100)
- end
- elseif xPos >= 59 and xPos <= 65 and yPos >= 19 and yPos <= 21 then
- if reactor.getControlRodLevel(1) - 1 >= 0 then
- reactor.setAllControlRodLevels(reactor.getControlRodLevel(1) - 1)
- else
- reactor.setAllControlRodLevels(0)
- end
- end
- drawScreen()
- end
- while true do
- parallel.waitForAny(touch, drawScreen)
- if exitProgram == 1 then
- shutDown()
- return
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement