Advertisement
dezindzer

Kontolor za spawnere 4 komada

Apr 19th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Programm made by Mrswisstobi-redo 51- april 2017 adapted by dezindzer lol
  2.  
  3. local button         = {}
  4. local side           = "bottom"
  5. local mon            = peripheral.wrap("back")
  6. local textScale      = 1.2
  7.  
  8. ------------ color variables ------------
  9.  
  10. local btnTextColor   = colors.white
  11. local defaultBgColor = colors.black
  12. local headerColor    = colors.white
  13.  
  14. -----------------------------------------
  15. function turnAllOff()
  16.   rs.setBundledOutput(side, 0)
  17.   for name, data in pairs(button) do
  18.     data["active"] = true
  19.     if name == "All OFF" then
  20.       button[name]["active"] = false
  21.     end
  22.     mon.clear()
  23.     heading("Spawners Controles on/off:")
  24.     screen()
  25.   end
  26. end
  27.  
  28. function turnAllOn()
  29.   rs.setBundledOutput(side, 65535)
  30.   for name, data in pairs(button) do
  31.     data["active"] = false
  32.     if name == "All ON" then
  33.       button[name]["active"] = true
  34.     end
  35.     mon.clear()
  36.     heading("Spawners Controles on/off:")
  37.     screen()
  38.   end
  39. end
  40.  
  41. rs.setBundledOutput(side, 65535)  
  42. term.clear()
  43. term.setCursorPos(1,1)
  44. mon.setBackgroundColor(defaultBgColor)
  45. mon.setTextScale(textScale)
  46. mon.clear()
  47.        
  48. function fillTable()
  49.    setTable("Yoyo 1",  switchOutput, 3, 13,  3,  5,  colors.red,     colors.red,    colors.lime)
  50.    setTable("Yoyo 2",  switchOutput, 3, 13,  7,  9,  colors.blue,    colors.red,    colors.lime)
  51.    setTable("Yoyo 3",  switchOutput, 17, 27,  3,  5, colors.yellow,    colors.red,    colors.lime)
  52.    setTable("Yoyo 4",  switchOutput, 17, 27,  7,  9, colors.orange,      colors.red,    colors.lime)
  53.      
  54.    setTable("All OFF",  turnAllOn,      3, 13, 11, 17, "" ,           colors.blue,   colors.red)
  55.    setTable("All ON", turnAllOff,     17, 27, 11, 17, "" ,             colors.blue,   colors.lime)
  56.  
  57. end
  58.  
  59. function setTable(name, func, xmin, xmax, ymin, ymax, color, btnOff, btnOn)
  60.    button[name]           = {}
  61.    button[name]["func"]   = func
  62.    button[name]["active"] = false
  63.    button[name]["xmin"]   = xmin
  64.    button[name]["ymin"]   = ymin
  65.    button[name]["xmax"]   = xmax
  66.    button[name]["ymax"]   = ymax
  67.    button[name]["color"]  = color
  68.    button[name]["btnOn"] = btnOn
  69.    button[name]["btnOff"]  = btnOff
  70. end
  71.  
  72. function switchOutput(color)
  73.    if rs.testBundledInput(side, color) then
  74.      rs.setBundledOutput(side, (rs.getBundledInput(side)-color))
  75.    else
  76.      rs.setBundledOutput(side, (rs.getBundledInput(side)+color))
  77.    end  
  78. end  
  79.  
  80. function fill(text, color, bData)
  81.    mon.setBackgroundColor(color)
  82.    mon.setTextColor(btnTextColor)
  83.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  84.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  85.    for j = bData["ymin"], bData["ymax"] do
  86.       mon.setCursorPos(bData["xmin"], j)
  87.       if j == yspot then
  88.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  89.             if k == xspot then
  90.                mon.write(text)
  91.             else
  92.                mon.write(" ")
  93.             end
  94.          end
  95.       else
  96.          for i = bData["xmin"], bData["xmax"] do
  97.             mon.write(" ")
  98.          end
  99.       end
  100.    end
  101.    mon.setBackgroundColor(defaultBgColor)
  102. end
  103.      
  104. function screen()
  105.    local currColor
  106.    for name,data in pairs(button) do
  107.       local on = data["active"]
  108.       if on == true then currColor = data["btnOn"] else currColor = data["btnOff"] end
  109.       fill(name, currColor, data)
  110.    end
  111. end
  112.      
  113. function checkxy(x, y)
  114.    for name, data in pairs(button) do
  115.       if y>=data["ymin"] and  y <= data["ymax"] then
  116.          if x>=data["xmin"] and x<= data["xmax"] then
  117.             data["func"](button[name]["color"])
  118.             data["active"] = not data["active"]
  119.          end
  120.       end
  121.    end
  122. end
  123.      
  124. function heading(text)
  125.    w, h = mon.getSize()
  126.    mon.setTextColor(headerColor)
  127.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  128.    mon.write(text)
  129. end
  130.      
  131. fillTable()
  132. while true do
  133.    mon.clear()
  134.    heading("Spawners Controles On/Off:")
  135.    screen()
  136.    local e,side,x,y = os.pullEvent("monitor_touch")
  137.    checkxy(x,y)
  138.    sleep(.1)
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement