Advertisement
Tacnuke

reactor ctrl

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