Advertisement
Tacnuke

rcver3

May 20th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("bundleAPI") -- api by andrakon of badash games
  2. local mon = peripheral.wrap("top") -- enables the monitor
  3. mon.setTextScale(.5)
  4. mon.setTextColor(colors.white)
  5. local button = {}
  6. mon.setBackgroundColor(colors.black)
  7.  
  8. function setTable(name, func, xmin, xmax, ymin, ymax)
  9.   button[name] = {}
  10.   button[name]["func"] = func
  11.   button[name]["active"] = false
  12.   button[name]["xmin"] = xmin
  13.   button[name]["xmax"] = xmax
  14.   button[name]["ymin"] = ymin
  15.   button[name]["ymax"] = ymax
  16.  end
  17.  
  18. function breeder()
  19.        bundleAPI.on("bottom", "red")
  20.    end
  21.  
  22. function reactor()
  23.        bundleAPI.on("bottom", "orange")
  24.    end
  25.  
  26. function stop()
  27.     rs.setBundledOutput("bottom", 0)
  28.  end
  29.  
  30. function fillTable()
  31.   setTable("Reactors", reactor, 5, 20, 4, 8)
  32.   setTable("Breeder", breeder, 5, 20, 10, 14)
  33.   setTable("ALL STOP", stop, 5, 20, 16, 20)
  34. end
  35.  
  36. function fill(text, color, bData)
  37.   mon.setBackgroundColor(color)
  38.   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  39.   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  40.   for j = bData["ymin"], bData["ymax"] do
  41.     mon.setCursorPos(bData["xmin"], j)
  42.       if j == yspot then
  43.         for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  44.          if k == xspot then
  45.            mon.write(text)
  46.          else
  47.           mon.write(" ")
  48.          end
  49.         end
  50.        else
  51.         for i = bData["xmin"], bData["xmax"] do
  52.          mon.write(" ")
  53.         end
  54.        end
  55.       end
  56.       mon.setBackgroundColor(colors.black)
  57.   end
  58.  
  59. function screen()
  60.  local currColor
  61.   for name,data in pairs(button) do
  62.    local on = data["active"]
  63.    if on == true then currColor = colors.lime
  64.    else currColor = colors.red
  65.    end
  66.   fill(name, currColor, data)
  67.  end
  68. end
  69.  
  70. function checkxy(x, y)
  71.    for name, data in pairs(button) do
  72.     if y >= data["ymin"] and y <= data["ymax"] then
  73.       if x >= data["xmin"] and x <= data["xmax"] then
  74.        data["func"]()
  75.        data["active"] = not data["active"]
  76.        print(name)
  77.       end
  78.      end
  79.     end
  80.    end
  81.  
  82. function heading(text)
  83.    w, h = mon.getSize()
  84.    mon.setCursorPos((w - string.len(text))/2+1, 1)
  85.    mon.write(text)
  86. end
  87.  
  88. fillTable()
  89.  
  90. while true do
  91.    mon.clear()
  92.    heading("Reactor Controller")
  93.    screen()
  94.    local e, side, x, y = os.pullEvent("monitor_touch")
  95.    checkxy(x,y)
  96.    sleep(0.1)
  97.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement