Advertisement
Guest User

mob

a guest
Oct 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.23 KB | None | 0 0
  1. local button         = {}
  2. local side           = "top"
  3. local mon            = peripheral.wrap("back")
  4. local textScale      = 1
  5.  
  6. ------------ color variables ------------
  7.  
  8. local btnTextColor   = colors.white
  9. local defaultBgColor = colors.gray
  10. local headerColor    = colors.white
  11.  
  12. -----------------------------------------
  13. function turnAllOff()
  14.   rs.setBundledOutput(side, 0)
  15.   for name, data in pairs(button) do
  16.     data["active"] = false
  17.     if name == "All ON" then
  18.       button[name]["active"] = true
  19.     end
  20.     mon.clear()
  21.     heading("MobFarm Steuertafel")
  22.     screen()
  23.   end
  24. end
  25.  
  26. function turnAllOn()
  27.   rs.setBundledOutput(side, 65535)
  28.   for name, data in pairs(button) do
  29.     data["active"] = true
  30.     if name == "All OFF" then
  31.       button[name]["active"] = false
  32.     end
  33.     mon.clear()
  34.     heading("MobFarm Steuertafel")
  35.     screen()
  36.   end
  37. end
  38.  
  39. rs.setBundledOutput(side, 0)  
  40. term.clear()
  41. term.setCursorPos(1,1)
  42. mon.setBackgroundColor(defaultBgColor)
  43. mon.setTextScale(textScale)
  44. mon.clear()
  45.        
  46. function fillTable()
  47.    setTable("Mfsu",        switchOutput, 17, 32,  3,  3, colors.white,     colors.lime,    colors.red)
  48.    setTable("Zombie",    switchOutput, 34, 47,  3,  3, colors.orange,    colors.lime,    colors.red)    
  49.    setTable("Skeleton",     switchOutput, 17, 32, 5, 5, colors.magenta,   colors.lime,    colors.red)
  50.    setTable("Witch",      switchOutput, 34, 47, 5, 5, colors.lightBlue, colors.lime,    colors.red)      
  51.    setTable("Iron Golem",        switchOutput, 17, 32,  7,  7, colors .yellow,    colors.lime,    colors.red)
  52.    setTable("Ceeper",        switchOutput, 34, 47,  7,  7, colors.lime,      colors.lime,    colors.red)
  53.    setTable("Spider",        switchOutput, 17, 32, 9, 9, colors.pink,      colors.lime,    colors.red)
  54.    setTable("Enderman",        switchOutput, 34, 47, 9, 9, colors.gray,      colors.lime,    colors.red)
  55.    setTable("Blaze",        switchOutput, 17, 32, 11, 11, colors.lightGray,      colors.lime,    colors.red)
  56.    setTable("Zombie Pigman",        switchOutput, 34, 47, 11, 11, colors.cyan,     colors.lime,     colors.red)
  57.    setTable("Angry Zombie",        switchOutput, 17, 32, 13, 13, colors.cyan,     colors.lime,     colors.red)
  58.    setTable("Ghast",        switchOutput, 34, 47, 13, 13, colors.cyan,     colors.lime,     colors.red)
  59.    setTable("Cow",        switchOutput, 17, 32, 15, 15, colors.cyan,     colors.lime,     colors.red)
  60.    setTable("Sheep^",        switchOutput, 34, 47, 15, 15, colors.cyan,     colors.lime,     colors.red)
  61.    setTable("Frei1",        switchOutput, 17, 32, 17, 17, colors.cyan,     colors.lime,     colors.red)
  62.    setTable("frei2",        switchOutput, 34, 47, 17, 17, colors.cyan,     colors.lime,     colors.red)
  63.    
  64.    
  65.    setTable("All OFF",  turnAllOn,      3, 13,  3,  3, "" ,              colors.red, colors.red)
  66.    setTable("All ON", turnAllOff,     3, 13, 5, 5, "" ,              colors.lime, colors.lime)
  67. end
  68.  
  69. function setTable(name, func, xmin, xmax, ymin, ymax, color, btnOff, btnOn)
  70.    button[name]           = {}
  71.    button[name]["func"]   = func
  72.    button[name]["active"] = true
  73.    button[name]["xmin"]   = xmin
  74.    button[name]["ymin"]   = ymin
  75.    button[name]["xmax"]   = xmax
  76.    button[name]["ymax"]   = ymax
  77.    button[name]["color"]  = color
  78.    button[name]["btnOff"] = btnOff
  79.    button[name]["btnOn"]  = btnOn
  80. end
  81.  
  82. function switchOutput(color)
  83.    if rs.testBundledInput(side, color) then
  84.      rs.setBundledOutput(side, (rs.getBundledInput(side)-color))
  85.    else
  86.      rs.setBundledOutput(side, (rs.getBundledInput(side)+color))
  87.    end  
  88. end  
  89.  
  90. function fill(text, color, bData)
  91.    mon.setBackgroundColor(color)
  92.    mon.setTextColor(btnTextColor)
  93.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  94.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  95.    for j = bData["ymin"], bData["ymax"] do
  96.       mon.setCursorPos(bData["xmin"], j)
  97.       if j == yspot then
  98.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  99.             if k == xspot then
  100.                mon.write(text)
  101.             else
  102.                mon.write(" ")
  103.             end
  104.          end
  105.       else
  106.          for i = bData["xmin"], bData["xmax"] do
  107.             mon.write(" ")
  108.          end
  109.       end
  110.    end
  111.    mon.setBackgroundColor(defaultBgColor)
  112. end
  113.      
  114. function screen()
  115.    local currColor
  116.    for name,data in pairs(button) do
  117.       local on = data["active"]
  118.       if on == true then currColor = data["btnOn"] else currColor = data["btnOff"] end
  119.       fill(name, currColor, data)
  120.    end
  121. end
  122.      
  123. function checkxy(x, y)
  124.    for name, data in pairs(button) do
  125.       if y>=data["ymin"] and  y <= data["ymax"] then
  126.          if x>=data["xmin"] and x<= data["xmax"] then
  127.             data["func"](button[name]["color"])
  128.             data["active"] = not data["active"]
  129.          end
  130.       end
  131.    end
  132. end
  133.      
  134. function heading(text)
  135.    w, h = mon.getSize()
  136.    mon.setTextColor(headerColor)
  137.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  138.    mon.write(text)
  139. end
  140.      
  141. fillTable()
  142.  turnAllOn()
  143. while true do
  144.    mon.clear()
  145.    heading("MobFarm Steuertafel")
  146.    screen()
  147.    local e,side,x,y = os.pullEvent("monitor_touch")
  148.    checkxy(x,y)
  149.    sleep(.1)
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement