Advertisement
Guest User

startup

a guest
Mar 26th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1.  
  2. term.clear()
  3. react = peripheral.wrap("back")
  4. term.clear()
  5. local menu_options = {
  6.   [1] = {text="Reactor ON/OFF Toggle", color=colors.blue},
  7.   [2] = {text="Reactor Fuel Level", color=colors.black},
  8.   [3] = {text="Reactor Power Level", color=colors.orange}
  9. }
  10. local termX, termY = term.getSize()
  11. local function menuDraw(selected)
  12.   local yPos = termY/2 - #menu_options/2
  13.   for index, data in pairs(menu_options) do
  14.     menu_options[index].bounds = {
  15.       x1 = termX/2 - (#data.text+4)/2,
  16.       x2 = termX/2 + (#data.text+4)/2,
  17.       y = yPos
  18.     }
  19.     term.setTextColor(data.color)
  20.     term.setCursorPos(data.bounds.x1, data.bounds.y)
  21.    
  22.     local text =
  23.       index==selected and "[ "..data.text.." ]" or
  24.       "  "..data.text.."  "
  25.       term.write(text)
  26.       yPos = yPos+1
  27.     end
  28.   end
  29.  
  30.   local function checkClick(x,y)
  31.     for index, data in pairs(menu_options) do
  32.       if x>= data.bounds.x1 and x<= data.bounds.x2 and y==data.bounds.y then
  33.         return index
  34.       end
  35.     end
  36.     return false
  37.   end
  38.  
  39.   term.setBackgroundColor(colors.white)
  40.   term.clear()
  41.   local selector = 1
  42.   while true do
  43.     menuDraw(selector)
  44.     local e = {os.pullEvent()}
  45.     if e[1] == "keys" then
  46.       if e[2] == keys.down then
  47.          selector = selector < #menu_options and selector+1 or 1
  48.      elseif e[2] == keys.up then
  49.         selector = selector > 1 and selector -1 or #menu_options
  50.       elseif e[2] == keys.enter then
  51.         break
  52.       end
  53.     elseif e[1] == "mouse_click" then
  54.       local value = checkClick(e[3], e[4])
  55.       if value then
  56.         selector = value
  57.         break
  58.       end
  59.     end
  60.  end
  61.  term.clear()
  62.  term.setCursorPos(1,1)
  63.  if selector == 1 then
  64.    if react.getActive() == true then
  65.      react.setActive(false)
  66.      shell.run("startup")
  67.    elseif react.getActive() == false then
  68.      react.setActive(true)
  69.      shell.run("startup")
  70.    end
  71.  elseif selector == 2 then
  72.    write(react.getFuelAmount().."/"..react.getFuelAmountMax())
  73.    sleep(2)
  74.    shell.run("startup")
  75.  elseif selector == 3 then
  76.    write(react.getEnergyStored().."/10,000,000")
  77.    sleep(2)
  78.    shell.run("startup")
  79.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement