Advertisement
Mobble

API

Apr 24th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local bcable = "left"
  2. rs.getBundledInput("left")
  3. local mon = peripheral.wrap("back")
  4. mon.setTextScale(1)
  5. mon.setTextColor(colors.white)
  6. local button={}
  7. mon.setBackgroundColor(colors.black)
  8. local off = 0
  9.      
  10. function setTable(name, func, xmin, xmax, ymin, ymax)
  11.     button[name] = {}
  12.     button[name]["func"] = func
  13.     button[name]["active"] = false
  14.     button[name]["xmin"] = xmin
  15.     button[name]["ymin"] = ymin
  16.     button[name]["xmax"] = xmax
  17.     button[name]["ymax"] = ymax
  18.     button[name]["colour"] = color
  19. end
  20.  
  21. function funcOn()
  22.         off = off + 1
  23.     if off == 1 then
  24.         rs.setBundledOutput("left", colors.white)
  25.     end
  26.     if off == 2 then
  27.         rs.setBundledOutput("left", colors.black)
  28.         off = 0
  29.     end
  30.        
  31. end
  32.        
  33. function fillTable()
  34.     setTable("Boiler ON", funcOn, 3, 15, 5, 7, colours.white)
  35.     setTable("Boiler ON", funcOn, 3, 15, 5, 7, colours.white)
  36. end    
  37.  
  38. function fill(text, color, bData)
  39.    mon.setBackgroundColor(color)
  40.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  41.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  42.    for j = bData["ymin"], bData["ymax"] do
  43.       mon.setCursorPos(bData["xmin"], j)
  44.       if j == yspot then
  45.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  46.             if k == xspot then
  47.                mon.write(text)
  48.             else
  49.                mon.write(" ")
  50.             end
  51.          end
  52.       else
  53.          for i = bData["xmin"], bData["xmax"] do
  54.             mon.write(" ")
  55.          end
  56.       end
  57.    end
  58.    mon.setBackgroundColor(colors.black)
  59. end
  60.      
  61. function screen()
  62.    local currColor
  63.    for name,data in pairs(button) do
  64.       local on = data["active"]
  65.       if on == true then currColor = colors.lime else currColor = colors.red 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["active"] = not data["active"]
  75.         data["func"]()
  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. while true do
  90.    mon.clear()
  91.    heading("Boiler Room Control Console")
  92.    screen()
  93.    local e,side,x,y = os.pullEvent("monitor_touch")
  94.    print(x..":"..y)
  95.    checkxy(x,y)
  96.    sleep(.1)
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement