Advertisement
Guest User

Steuerung

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