Advertisement
Guest User

needhelp.lua

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