Guest User

rcver3

a guest
May 20th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.70 KB | None | 0 0
  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 bColor()
  19.  local bColor
  20.  local on = data["active"]
  21.  if on == true then bColor = colors.lime
  22.  else bColor = colors.red
  23. end
  24.  
  25. function breeder()
  26.    if bColor() = colors.lime then
  27.      bundleAPI.on("bottom", "red")
  28.    else
  29.      bundleAPI.off("bottom", "red")
  30.   end
  31. end
  32.  
  33. function reactor()
  34.    if bColor() = colors.lime then
  35.       bundleAPI.on("bottom", "orange")
  36.    else
  37.       bundleAPI.off("bottom", "orange")
  38.   end
  39.  end
  40.  
  41. function stop()
  42.     rs.setBundledOutput("bottom", 0)
  43.  end
  44.  
  45. function fillTable()
  46.   setTable("Reactors", reactor, 5, 20, 4, 8)
  47.   setTable("Breeder", breeder, 5, 20, 10, 14)
  48.   setTable("ALL STOP", stop, 5, 20, 16, 20)
  49. end
  50.  
  51. function fill(text, color, bData)
  52.   mon.setBackgroundColor(color)
  53.   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  54.   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  55.   for j = bData["ymin"], bData["ymax"] do
  56.     mon.setCursorPos(bData["xmin"], j)
  57.       if j == yspot then
  58.         for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  59.          if k == xspot then
  60.            mon.write(text)
  61.          else
  62.           mon.write(" ")
  63.          end
  64.         end
  65.        else
  66.         for i = bData["xmin"], bData["xmax"] do
  67.          mon.write(" ")
  68.         end
  69.        end
  70.       end
  71.       mon.setBackgroundColor(colors.black)
  72.   end
  73.  
  74. function screen()
  75.  local currColor
  76.   for name,data in pairs(button) do
  77.    local on = data["active"]
  78.    if on == true then cuuColor = colors.lime
  79.    else currColor = colors.red
  80.    end
  81.   fill(name, currColor, data)
  82.  end
  83. end
  84.  
  85. function checkxy(x, y)
  86.    for name, data in pairs(button) do
  87.     if y >= data["ymin"] and y <= data["ymax"] then
  88.       if x >= data["xmin"] and x <= data["xmax"] then
  89.        data["func"]()
  90.        data["active"] = not data["active"]
  91.        print(name)
  92.       end
  93.      end
  94.     end
  95.    end
  96.  
  97. function heding(text)
  98.    w, h = mon.getSize()
  99.    mon.setCursorPos((w - string.len(text))/2+1, 1)
  100.    mon.write(text)
  101. end
  102.  
  103. fillTable()
  104.  
  105. while true do
  106.    mon.clear()
  107.    heading("Reactor Controller")
  108.    screen()
  109.    local e, side, x, y = os.pullEvent("monitor_touch")
  110.    checkxy(x,y)
  111.    sleep(0.1)
  112.  end
Advertisement
Add Comment
Please, Sign In to add comment