Advertisement
balloonanimal

LiftControlL2

May 20th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Pastebin code: 9L63zjmY
  2.  
  3. local bundleSide = "right"
  4. local mon = peripheral.wrap("bottom")
  5. local mX, mY = mon.getSize()
  6. mon.setTextScale(1)
  7. mon.setTextColor(colors.white)
  8. local button={}
  9. mon.setBackgroundColor(colors.black)
  10.  
  11. --moves lift one block
  12. function Move( col )
  13. rs.setBundledOutput(bundleSide, col)
  14. sleep(0.1)
  15. rs.setBundledOutput(bundleSide, 0)
  16. sleep(0.9)
  17. end
  18.  
  19. function checkxy(x, y)
  20.    local activeFunc = "none"
  21.    print(x.."  "..y)
  22.    for name, data in pairs(button) do
  23.       if y>=data["ymin"] and  y <= data["ymax"] then
  24.          if x>=data["xmin"] and x<= data["xmax"] then
  25.             data["active"] = not data["active"]
  26.             activeFunc = name
  27.             print(name)
  28.          end
  29.       end
  30.    end
  31.    if (activeFunc ~= "none") then
  32.         button[activeFunc]["func"]()
  33.    end
  34. end
  35.  
  36. function fill(text, color, bData)
  37.    mon.setBackgroundColor(color)
  38.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  39.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  40.    for j = bData["ymin"], bData["ymax"] do
  41.       mon.setCursorPos(bData["xmin"], j)
  42.       if j == yspot then
  43.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  44.             if k == xspot then
  45.                mon.write(text)
  46.             else
  47.                mon.write(" ")
  48.             end
  49.          end
  50.       else
  51.          for i = bData["xmin"], bData["xmax"] do
  52.             mon.write(" ")
  53.          end
  54.       end
  55.    end
  56.    mon.setBackgroundColor(colors.black)
  57. end
  58.  
  59. function CreateButton(name, func, minX, minY, maxX, maxY)
  60.         button[name] = {}
  61.         button[name]["func"] = func
  62.         button[name]["active"] = false
  63.         button[name]["xmin"] = minX
  64.         button[name]["ymin"] = minY
  65.         button[name]["xmax"] = maxX
  66.         button[name]["ymax"] = maxY
  67. end
  68.  
  69. function SetUpButtons()
  70.         --CreateButton("Sec", Top, 3, 2, 5, 2)
  71.         CreateButton("B", Basement, 2, 11, 3, 11)
  72.         CreateButton("LB", LowerBasement, 5, 11, 6, 11)
  73.  
  74. end
  75.  
  76. function Screen()
  77.     local currColor
  78.         for name,data in pairs(button) do
  79.                 local on = data["active"]
  80.                 if on == true then
  81.                         currColor = colors.lime
  82.                 else currColor = colors.red
  83.         end
  84.        
  85.         fill(name, currColor, data)
  86.         end
  87. end
  88.  
  89. function checkxy(x, y)
  90.        
  91. end
  92.  
  93. SetUpButtons()
  94. while true do
  95.     mon.clear()
  96.     Screen()
  97.     local event, side, x, y = os.pullEvent()
  98.         if event == "monitor_touch" then
  99.                 checkxy(x, y)
  100.         end
  101.         sleep(0.1)      
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement