Advertisement
bobmarley12345

quantumlinks

Oct 16th, 2020 (edited)
2,421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.05 KB | None | 0 0
  1. MonitorSide = "right"
  2. RedstoneInputSide = "back"
  3. Monitor = peripheral.wrap(MonitorSide)
  4.  
  5. TouchX = 0
  6. TouchY = 0
  7. StopFunction = ""
  8.  
  9. function ClearMonitor()
  10.     Monitor.setTextColor(colours.black)
  11.     Monitor.setBackgroundColor(colours.black)
  12.     Monitor.clear()
  13.     Monitor.setCursorPos(1,1)
  14. end
  15.  
  16. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  17.     Monitor.setBackgroundColor(backgroundColour)
  18.     Monitor.setTextColor(textColour)
  19.     Monitor.setCursorPos(xPos,yPos)
  20.     Monitor.write(text)
  21. end
  22.  
  23. function DrawCenteredHorizontal(xPos, yPos, width, text, textColour, backgroundColour)
  24.     -- width could be the size of your monitor, or anything else. this means it
  25.     -- doesn't have to stretch your entire monitor's if you want. imagine
  26.     -- it as a rectangle and the text is in the center.
  27.     local textLength = string.len(text)
  28.     local centerX = (width / 2) - (textLength / 2)
  29.     DrawText(xPos + centerX, yPos, text, textColour, backgroundColour)
  30. end
  31.  
  32. function GroupBoxHeader(xPos, yPos, width, header, textColour, backgroundColour)
  33.     local headerLength = string.len(header)
  34.     local repeatChars = width - 4 - headerLength
  35.  
  36.     if (repeatChars < 0) then
  37.         repeatChars = 0
  38.     end
  39.  
  40.     local head = "--- " .. header .. " " .. string.rep("-", repeatChars)
  41.     DrawText(xPos, yPos, head, textColour, backgroundColour)
  42. end
  43.  
  44. function GroupBoxFooter(xPos, yPos, width, textColour, backgroundColour)
  45.     if (width < 0) then
  46.         width = 0
  47.     end
  48.     local head = string.rep("-", width)
  49.     DrawText(xPos, yPos, head, textColour, backgroundColour)
  50. end
  51.  
  52. function GroupBox(xPos, yPos, width, height, header, textColour, headerBackgroundColour)
  53.     GroupBoxHeader(xPos, yPos, width, header, textColour, headerBackgroundColour)
  54.     GroupBoxFooter(xPos, yPos + height + 1, width, textColour, headerBackgroundColour)
  55. end
  56.  
  57. function DrawStatus(xPos, yPos, isActive)
  58.     if (isActive) then
  59.         DrawText(xPos, yPos, "ONLINE", colours.white, colours.green)
  60.     else
  61.         DrawText(xPos, yPos, "OFFLINE", colours.white, colours.red)
  62.     end
  63. end
  64.  
  65. function Draw()
  66.     while true do
  67.         local inputColours = redstone.getBundledInput(RedstoneInputSide)
  68.        
  69.         local moon = colours.test(inputColours, colours.white)
  70.         local base2 = colours.test(inputColours, colours.orange)
  71.         local bridge = colours.test(inputColours, colours.magenta)
  72.         local mars = colours.test(inputColours, colours.lightBlue)
  73.  
  74.         local w, h = Monitor.getSize()
  75.         ClearMonitor()
  76.         GroupBox(2, 2, w, 9, "Quantum Links Info", colours.green, colours.black)
  77.         DrawText(2, 4,  "Moon Link:", colours.white, colours.black)
  78.         DrawText(2, 6,  "2nd Base Link:", colours.orange, colours.black)
  79.         DrawText(2, 8,  "Bridge Link:", colours.magenta, colours.black)
  80.         DrawText(2, 10, "Mars Link:", colours.lightBlue, colours.black)
  81.  
  82.         DrawStatus(18, 4, moon)
  83.         DrawStatus(18, 6, base2)
  84.         DrawStatus(18, 8, bridge)
  85.         DrawStatus(18, 10, mars)
  86.  
  87.         sleep(0.5)
  88.     end
  89. end
  90.  
  91. function WaitForMonitorTouch()
  92.     local event, side, x, y = os.pullEvent("monitor_touch")
  93.     TouchX = x
  94.     TouchY = y
  95.     StopFunction = "monTouch"
  96. end
  97.  
  98. function MonitorTouched()
  99.     local x = TouchX
  100.     local y = TouchY
  101.  
  102.     if (x >= 18 and x <= 25) then
  103.         local outputColours = redstone.getBundledOutput(RedstoneInputSide)
  104.  
  105.         if (y == 4) then
  106.             if (colours.test(outputColours, colours.white)) then
  107.                 redstone.setBundledOutput(RedstoneInputSide, outputColours - colours.white)
  108.             else
  109.                 redstone.setBundledOutput(RedstoneInputSide, outputColours + colours.white)
  110.             end
  111.  
  112.             return
  113.         end
  114.  
  115.         if (y == 6) then
  116.             if (colours.test(outputColours, colours.orange)) then
  117.                 redstone.setBundledOutput(RedstoneInputSide, outputColours - colours.orange)
  118.             else
  119.                 redstone.setBundledOutput(RedstoneInputSide, outputColours + colours.orange)
  120.             end
  121.            
  122.             return
  123.         end
  124.  
  125.         if (y == 8) then
  126.             if (colours.test(outputColours, colours.magenta)) then
  127.                 redstone.setBundledOutput(RedstoneInputSide, outputColours - colours.magenta)
  128.             else
  129.                 redstone.setBundledOutput(RedstoneInputSide, outputColours + colours.magenta)
  130.             end
  131.  
  132.             return
  133.         end
  134.  
  135.         if (y == 10) then
  136.             if (colours.test(outputColours, colours.lightBlue)) then
  137.                 redstone.setBundledOutput(RedstoneInputSide, outputColours - colours.lightBlue)
  138.             else
  139.                 redstone.setBundledOutput(RedstoneInputSide, outputColours + colours.lightBlue)
  140.             end
  141.  
  142.             return
  143.         end
  144.     end
  145. end
  146.  
  147. function Main()
  148.     while true do
  149.         parallel.waitForAny(Draw, WaitForMonitorTouch)
  150.  
  151.         if (StopFunction == "monTouch") then
  152.             StopFunction = "none"
  153.             MonitorTouched()
  154.         end
  155.     end
  156. end
  157.  
  158. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement