Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Menu.lua, a Latias interface --
- local component = require("component")
- local event = require("event")
- local w = 50
- local h = 16
- local gpu = component.gpu
- local color = {black=0x000000, white=0xFFFFFF}
- local keys = {up=200, down=208, ok=28, back=14, stop=211, ctrl=29, shift=42, left=203, right=205}
- local menu = {
- {"power","Power Menu","Power Storage Statistics",
- function() end,
- function() drawPower() end,
- function() deadEnd() end -- On Listen
- },
- {"reactor","Reactor Overview","Reactor Overview & Management",
- function() end,
- function()
- local reactors = components({"br_reactor"})
- local count = 0
- for c,_ in pairs(reactors) do
- local br = component.proxy(c)
- if br ~= nil then
- if br.getFuelAmount() ~= nil then -- check if reactor is fake
- local y = 4 + 4 * count
- local fuelCurrent = math.floor(br.getFuelAmount())
- local fuelMax = math.floor(br.getFuelAmountMax())
- local fuelWaste = math.floor(br.getWasteAmount())
- local powerCurrent = math.floor(br.getEnergyStored())
- local powerMax = math.floor(10000000)
- local tempFuel = math.floor(br.getFuelTemperature())
- local tempCase = math.floor(br.getCasingTemperature())
- drawLine(y)
- if br.getActive() then drawCenteredText(y, "Online - "..tempFuel.."C - "..tempCase.."C") else drawCenteredText(y, "Offline") end
- drawLine(y+1)
- drawCenteredText(y+1,powerCurrent.."rF / "..powerMax.."rF")
- drawLine(y+2)
- drawCenteredText(y+2,"Fuel "..fuelCurrent.."mb | "..fuelWaste.."mb Waste")
- count = count + 1
- end
- end
- end
- if count == 0 then
- drawLine(4)
- drawCenteredText(4,"No reactors installed")
- end
- end,
- function() leftRight() end
- },
- {"defense","Defense System","Home Security Defense System",
- function() end,
- function()
- drawLine(4)
- drawCenteredText(4,"No turrets mounted")
- end,
- function() deadEnd() end
- },
- {"farm","Farm Manager","Agricultural Management",
- function() end,
- function()
- drawLine(4)
- drawCenteredText(4,"Farm sockets currently not in use")
- end,
- function() deadEnd() end
- },
- {"quarry","Quarry Settings","Excavator Management System",
- function() end,
- function()
- drawLine(4)
- drawText(4,"No excavation site defined")
- end,
- function() deadEnd() end
- },
- {"internet","Internet Browser","Basic Internet Browser",
- function()
- url = "http://ask.hiof.no/~vegardbe/"
- end,
- function()
- drawLine(4)
- drawCenteredText(4,"503 - Service Unavailable")
- drawLine(5)
- drawText(5,"URL: "..url)
- end,
- function() deadEnd() end
- }
- }
- local screen = "menu"
- local screenData = {"menu","Menu","Menu",function() sel = 1 end,function() drawMenu() end,function() listen() end}
- local menuScreenData = screenData
- local selscreen = "menu"
- local seltitle = "Menu"
- local title = "Menu"
- local sel = 1
- local stop = false
- local menuSize = 0
- for k,v in pairs(menu) do
- menuSize = menuSize + 1
- end
- gpu.setResolution(w, h)
- table_whitelist = function(t, side, filter)
- local newTable = {}
- for k,v in pairs(t) do
- for _,f in pairs(filter) do
- if side == "v" and v == f then
- newTable[k] = v
- elseif side == "k" and k == f then
- newTable[k] = v
- end
- end
- end
- return newTable
- end
- components = function(t)
- return table_whitelist(component.list(), "v", t)
- end
- listen = function()
- local id, _, type, key = event.pull(10, "key_down")
- if (id == "key_down") then
- if (key == keys.up) then
- sel = sel - 1
- elseif (key == keys.down) then
- sel = sel + 1
- elseif (key == keys.stop) then
- beep(1)
- stop = true
- elseif (key == keys.ok) then
- beep(2,true)
- setScreen(menu[sel])
- elseif (key == keys.back) then
- beep(2)
- setScreen(menuScreenData)
- else
- listen()
- end
- else
- end
- if (sel < 1) then
- sel = sel + menuSize
- end
- if (sel > menuSize) then
- sel = sel - menuSize
- end
- end
- deadEnd = function()
- invertColor(false)
- drawCenteredText(h-1,"Press BACKSPACE to go back")
- local id, _, type, key = event.pull(10, "key_down")
- if (id == "key_down") then
- if (key == keys.back) then
- beep(2)
- setScreen(menuScreenData)
- else
- deadEnd()
- end
- else
- end
- end
- leftRight = function()
- invertColor(false)
- drawCenteredText(h-2,"Fuel Rod Controls")
- drawCenteredText(h-1,"[<- LOWER] [BACKSPACE] [RISE ->]")
- local id, _, type, key = event.pull(10, "key_down")
- if (id == "key_down") then
- if (key == keys.back) then
- beep(2)
- setScreen(menuScreenData)
- elseif (key == keys.left) then
- elseif (key == keys.right) then
- else
- leftRight()
- end
- else
- end
- end
- beep = function(n,d)
- for i=1, n do
- if d then
- freq = 200 + (1000 / n) * i
- else
- freq = 1800 - (1000 / n) * i
- end
- component.computer.beep(freq, 0.1)
- end
- end
- clear = function()
- for i=1, h do
- drawClear(i)
- end
- end
- invertColor = function(b)
- if (b) then
- setColor(color.white, color.black)
- else
- setColor(color.black, color.white)
- end
- end
- setColor = function(bg, fg)
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- end
- drawLine = function(y)
- setColor(color.white, color.black)
- gpu.fill(1,y,w,1," ")
- end
- drawClear = function(y)
- setColor(color.black, color.white)
- gpu.fill(1,y,w,1," ")
- end
- drawCenteredText = function(y,text)
- local center = w / 2
- local start = center - string.len(text) / 2
- gpu.set(start,y,text)
- end
- drawText = function(y,text)
- gpu.set(2,y,text)
- end
- --local screenData = {"menu","Menu","Menu",function() sel = 0 end,function() drawMenu() end}
- setScreen = function(sD)
- title = sD[3]
- screen = sD[1]
- sD[4]() -- Run the screen function
- screenData = sD
- end
- drawBasis = function()
- drawLine(1)
- drawCenteredText(1,"Ratiasu's Base System")
- drawLine(2)
- drawCenteredText(2,title)
- drawLine(h)
- drawText(h, "version 2.3 - "..screen.." "..gpu.address)
- end
- -- draw menu
- drawMenu = function()
- local c = 1
- for k,v in pairs(menu) do
- if v ~= nil then
- local selected = (sel == c)
- invertColor(selected)
- drawCenteredText(2 + 2 * c, v[2])
- if selected then
- selscreen = v[1]
- seltitle = v[3]
- end
- c = c + 1
- end
- end
- end
- jToRf = function(n)
- return n * ((1/3200) * 1280)
- end
- table_merge = function(a, b)
- for k,v in pairs(b) do
- table.insert(a, v)
- end
- return a
- end
- drawPower = function()
- local count = 0
- local treshold = 25
- local list = components({"basic_energy_cube", "advanced_energy_cube", "elite_energy_cube", "ultimate_energy_cube"})
- for c,_ in pairs(list) do
- local y = 4 + count * 3
- local ec = component.proxy(c)
- if ec ~= nil then
- local powerCurrent = math.floor(jToRf(ec.getEnergy()))
- local powerMax = math.floor(jToRf(ec.getMaxEnergy()))
- local powerOutput = math.floor(jToRf(ec.getOutput()))
- local powerNeeded = math.floor(jToRf(ec.getEnergyNeeded()))
- local percent = math.ceil((100 / powerMax) * powerCurrent)
- drawLine(y)
- if percent < treshold then
- drawCenteredText(y,"CRITICAL POWER LEVEL")
- beep(2)
- else
- drawCenteredText(y,percent.."%")
- end
- drawLine(y+1)
- drawCenteredText(y+1,powerCurrent.."RF / "..powerMax.."RF".."")
- count = count + 1
- end
- end
- if count == 0 then
- drawLine(4)
- drawCenteredText(4,"No power storage device found")
- end
- end
- -- Main Loop!! :ooo
- while (true) do
- beep(1,true)
- clear()
- drawBasis()
- -- Run the idle function for the screen
- screenData[5]()
- -- Run the wait function for the screen
- screenData[6]()
- -- If you can stop the script, do so
- if stop then
- beep(3)
- clear()
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement