Jodo32

FTB Buttons - Refinery

Jul 18th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. local mon = peripheral.wrap("right")
  2. mon.setTextScale(1)
  3. mon.setTextColor(colors.white)
  4. local button={}
  5. mon.setBackgroundColor(colors.black)
  6. os.loadAPI ("bundleAPI")
  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]["ymin"] = ymin
  14.    button[name]["xmax"] = xmax
  15.    button[name]["ymax"] = ymax
  16. end
  17.  
  18. function funcName()
  19.    print("You clicked",text)
  20. end
  21.  
  22. function Magma()
  23.    bundleAPI.toggle("left","white")
  24.    end
  25.  
  26. function Bees()
  27.    bundleAPI.toggle("left","blue")
  28.    end
  29.  
  30.  function Cobble()
  31.    bundleAPI.toggle("left","lightBlue")
  32.    end
  33.  
  34.  function Recycle()
  35.    bundleAPI.toggle("left","green")
  36.    end
  37.  
  38.  
  39. function fillTable()
  40.    setTable("Magma Cruicibles", Magma, 3, 26, 3, 5)
  41.    setTable("Bee Processing", Bees, 3, 26, 7, 9)
  42.    setTable("Cobble Production", Cobble, 3, 26, 11, 13)
  43.    setTable("Recycling Setup", Recycle, 3, 26, 15, 17)
  44. end    
  45.  
  46. function fill(text, color, bData)
  47.    mon.setBackgroundColor(color)
  48.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  49.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  50.    for j = bData["ymin"], bData["ymax"] do
  51.       mon.setCursorPos(bData["xmin"], j)
  52.       if j == yspot then
  53.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  54.             if k == xspot then
  55.                mon.write(text)
  56.             else
  57.                mon.write(" ")
  58.             end
  59.          end
  60.       else
  61.          for i = bData["xmin"], bData["xmax"] do
  62.             mon.write(" ")
  63.          end
  64.       end
  65.    end
  66.    mon.setBackgroundColor(colors.black)
  67. end
  68.      
  69. function screen()
  70.    local currColor
  71.    for name,data in pairs(button) do
  72.       local on = data["active"]
  73.       if on == true then currColor = colors.magenta else currColor = colors.gray end
  74.       fill(name, currColor, data)
  75.    end
  76. end
  77.      
  78. function checkxy(x, y)
  79.    for name, data in pairs(button) do
  80.       if y>=data["ymin"] and  y <= data["ymax"] then
  81.          if x>=data["xmin"] and x<= data["xmax"] then
  82.             data["func"]()
  83.             data["active"] = not data["active"]
  84.             print(name)
  85.          end
  86.       end
  87.    end
  88. end
  89.    
  90. function heading(text)
  91.    w, h = mon.getSize()
  92.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  93.    mon.write(text)
  94. end
  95.      
  96. timeout = os.startTimer(1)  
  97. fillTable()
  98.  
  99. while true do
  100.    mon.clear()
  101.    heading(" ")
  102.    screen()
  103.    local event = {os.pullEvent()}
  104.    if event[1] == "monitor_touch" then
  105.    checkxy(event[3], event[4])
  106.    print(event[4]..":"..event[3])
  107.    elseif event[1] == "timer" and event[2] == timeout then
  108.    timeout = os.startTimer(1)
  109.    end
  110. end
Advertisement
Add Comment
Please, Sign In to add comment