Guest User

mon

a guest
Feb 2nd, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.51 KB | None | 0 0
  1.  
  2. local state
  3.  
  4. local mon = peripheral.wrap("right")
  5. mon.setTextScale(1)
  6. mon.setTextColor(colors.white)
  7. local button={}
  8. mon.setBackgroundColor(colors.black)
  9.      
  10. function setTable(name, func, xmin, xmax, ymin, ymax)
  11.    button[name] = {}
  12.    button[name]["func"] = func
  13.    button[name]["active"] = false
  14.    button[name]["xmin"] = xmin
  15.    button[name]["ymin"] = ymin
  16.    button[name]["xmax"] = xmax
  17.    button[name]["ymax"] = ymax
  18. end
  19. function leftMon()
  20.   for name, data in pairs(button) do
  21.     if data["active"] == false then
  22.       rednet.open("left")
  23.       rednet.send(154,"LEFT ON")
  24.       rednet.close("left")
  25.       --sleep(1)
  26.     end
  27.     if data["active"] == true then
  28.       rednet.open("left")
  29.       rednet.send(154,"LEFT OFF")
  30.       rednet.close("left")
  31.      
  32.     end
  33.   end
  34. end        
  35.  
  36. function midMon()
  37.   --print("Doing Function")
  38.   for name, data in pairs(button) do
  39.     if data["active"] == false then
  40.       print("sending on")  
  41.       rednet.open("left")
  42.       rednet.send(154, "MID ON")
  43.       rednet.close("left")
  44.     end
  45.     if data["active"] == true then
  46.       print("sending off")
  47.       rednet.open("left")
  48.       rednet.send(154,"MID OFF")
  49.       rednet.close("left")
  50.     end
  51.   end      
  52. end  
  53.  
  54. function rightMon()
  55.   for name, data in pairs(button) do
  56.     if data["active"] == false then
  57.       rednet.open("left")
  58.       rednet.send(154, "RIGHT ON")
  59.       rednet.close("left")
  60.       print("Sent ON")
  61.       --sleep(1)
  62.     end
  63.     if data["active"] == true then
  64.       rednet.open("left")
  65.       rednet.send(154,"RIGHT OFF")
  66.       rednet.close("left")
  67.       print("Sent OFF")
  68.       --sleep(1)
  69.     end
  70.   end
  71. end  
  72.      
  73.  
  74. function funcName()
  75.    print("You clicked buttonText")
  76. end
  77.        
  78. function fillTable()
  79.    setTable("Left Monitor", leftMon, 5, 20, 4, 8)
  80.    setTable("Middle Monitor",midMon, 23, 38, 4, 8)
  81.    setTable("Right Monitor", rightMon, 41 ,56, 4,8)
  82. end    
  83.  
  84. function fill(text, color, bData)
  85.    mon.setBackgroundColor(color)
  86.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  87.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  88.    for j = bData["ymin"], bData["ymax"] do
  89.       mon.setCursorPos(bData["xmin"], j)
  90.       if j == yspot then
  91.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  92.             if k == xspot then
  93.                mon.write(text)
  94.             else
  95.                mon.write(" ")
  96.             end
  97.          end
  98.       else
  99.          for i = bData["xmin"], bData["xmax"] do
  100.             mon.write(" ")
  101.          end
  102.       end
  103.    end
  104.    mon.setBackgroundColor(colors.black)
  105. end
  106.      
  107. function screen()
  108.    local currColor
  109.    for name,data in pairs(button) do
  110.       local on = data["active"]
  111.       if on == true then currColor = colors.lime else currColor = colors.red end
  112.       fill(name, currColor, data)
  113.    end
  114. end
  115.      
  116. function checkxy(x, y)
  117.    for name, data in pairs(button) do
  118.       if y>=data["ymin"] and  y <= data["ymax"] then
  119.          if x>=data["xmin"] and x<= data["xmax"] then
  120.             data["func"]()
  121.             data["active"] = not data["active"]
  122.             --print(name)
  123.          end
  124.       end
  125.    end
  126. end
  127.      
  128. function heading(text)
  129.    w, h = mon.getSize()
  130.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  131.    mon.write(text)
  132. end
  133.      
  134. fillTable()
  135. while true do
  136.    mon.clear()
  137.    heading("Spawn Station Control")
  138.    screen()
  139.    local e,side,x,y = os.pullEvent("monitor_touch")
  140.    --print(x..":"..y)
  141.    checkxy(x,y)
  142.    sleep(.1)
  143. end
Advertisement
Add Comment
Please, Sign In to add comment