Advertisement
Guest User

4 item menu

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