Advertisement
Arc13

Ecran ferme à guardian

Jun 21st, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.23 KB | None | 0 0
  1. rednet.open("top")
  2.  
  3. print("Hosting...")
  4. rednet.host("arcGuard", "arcMonitor")
  5. print("Ready !")
  6.  
  7. print("Guardian Controller v4")
  8.  
  9. term.redirect(peripheral.find("monitor"))
  10.  
  11. monX, monY = term.getSize()
  12. term.setBackgroundColor(colors.lightGray)
  13. term.clear()
  14. term.setCursorPos(1, 1)
  15. paintutils.drawLine(1, 1, monX, 1, colors.gray)
  16. paintutils.drawPixel(1, 1, colors.blue)
  17. paintutils.drawPixel(monX, 1, colors.blue)
  18. term.setCursorPos(1, 1)
  19. term.write("<")
  20. term.setCursorPos(monX, 1)
  21. term.write(">")
  22.  
  23. term.setBackgroundColor(colors.gray)
  24. term.setCursorPos((monX / 2) - (string.len("Prismarine Shard") / 2), 1)
  25. term.write("Prismarine Shard")
  26.  
  27. currentItem = 1
  28. currentSubItem = 0
  29. itemList = {"Prismarine Shard", "Prismarine Crystal", "Fish", "Guardian Pearl"}
  30. currentItemStr = itemList[currentItem]
  31. serverList = {3955, 3953, 3954, 3978}
  32. serverSubList = {4320, 4319}
  33. currentItemQuantity = 64
  34. currentItemQuantity = math.ceil(currentItemQuantity)
  35.  
  36. paintutils.drawFilledBox(1, 2, monX / 3 + 1, monY, colors.lightBlue)
  37. term.setCursorPos(1, 2)
  38. term.write("Arborescence")
  39. term.setCursorPos(3, 3)
  40. term.write(itemList[1])
  41. term.setCursorPos(3, 4)
  42. term.write(itemList[2])
  43. term.setCursorPos(3, 5)
  44. term.write(itemList[3])
  45. term.setCursorPos(3, 6)
  46. term.write(itemList[4])
  47.  
  48. oldColor = term.getTextColor()
  49. term.setTextColor(colors.yellow)
  50. term.setCursorPos(1, 3)
  51. term.write(">")
  52. term.setTextColor(oldColor)
  53.  
  54. paintutils.drawFilledBox(monX / 3 + 3, 3, monX / 3 + 7, 5, colors.red)
  55. term.setCursorPos(monX / 3 + 4, 4)
  56. term.write("-1")
  57. paintutils.drawFilledBox(monX / 3 + 3, monY - 3, monX / 3 + 7, monY - 1, colors.green)
  58. term.setCursorPos(monX / 3 + 4, monY - 2)
  59. term.write("+1")
  60. paintutils.drawFilledBox(monX / 3 + 9, 3, monX / 3 + 13, 5, colors.red)
  61. term.setCursorPos(monX / 3 + 10, 4)
  62. term.write("-16")
  63. paintutils.drawFilledBox(monX / 3 + 9, monY - 3, monX / 3 + 13, monY - 1, colors.green)
  64. term.setCursorPos(monX / 3 + 10, monY - 2)
  65. term.write("+16")
  66. paintutils.drawFilledBox(monX / 3 + 15, 3, monX / 3 + 19, 5, colors.red)
  67. term.setCursorPos(monX / 3 + 16, 4)
  68. term.write("-32")
  69. paintutils.drawFilledBox(monX / 3 + 15, monY - 3, monX / 3 + 19, monY - 1, colors.green)
  70. term.setCursorPos(monX / 3 + 16, monY - 2)
  71. term.write("+32")
  72. paintutils.drawFilledBox(monX / 3 + 21, 3, monX / 3 + 25, 5, colors.red)
  73. term.setCursorPos(monX / 3 + 22, 4)
  74. term.write("-64")
  75. paintutils.drawFilledBox(monX / 3 + 21, monY - 3, monX / 3 + 25, monY - 1, colors.green)
  76. term.setCursorPos(monX / 3 + 22, monY - 2)
  77. term.write("+64")
  78.  
  79. paintutils.drawLine(monX / 3 + 3, monY / 2 + 1, monX, monY / 2 + 1, colors.lightGray)
  80. term.setCursorPos(monX / 3 + 3, monY / 2 + 1)
  81. term.write("Commande : "..tostring(currentItemQuantity))
  82.  
  83. paintutils.drawFilledBox(monX / 3 + 27, monY - 3, monX - 1, monY - 1, colors.yellow)
  84. term.setCursorPos(monX / 3 + 30, monY - 2)
  85. term.write("Commander")
  86.  
  87. term.setBackgroundColor(colors.lightBlue)
  88. term.setCursorPos(1, monY - 1)
  89. term.write("Quantité :")
  90.  
  91. levelServerList = {4098, 4099, 4100, 4101}
  92.  
  93. if currentItem == 1 then
  94.   term.setBackgroundColor(colors.lightBlue)
  95.   term.setCursorPos(3, 8)
  96.   term.setTextColor(colors.yellow)
  97.   term.write("+")
  98.   term.setTextColor(colors.white)
  99.   term.setCursorPos(6, 8)
  100.   term.write("Prismarine")
  101.   term.setCursorPos(6, 9)
  102.   term.write("Pris. Bricks")
  103. else
  104.   paintutils.drawFilledBox(1, 8, monX / 3 + 1, 10, colors.lightBlue)
  105. end
  106.  
  107. function setCursorList(cursorPos)
  108.   paintutils.drawLine(1, 3, 1, 6, colors.lightBlue)
  109.   term.setTextColor(colors.yellow)
  110.   term.setCursorPos(1, cursorPos + 2)
  111.   term.write(">")
  112.   term.setTextColor(oldColor)
  113.   paintutils.drawLine(4, 8, 4, 9, colors.lightBlue)
  114. end
  115.  
  116. function changeItem(itemStr)
  117.   if itemStr == "+" then
  118.     if currentItem >= 4 then
  119.       currentItem = 1
  120.       currentItemStr = itemList[currentItem]
  121.       paintutils.drawLine(2, 1, monX - 1, 1, colors.gray)
  122.       term.setCursorPos((monX / 2) - (string.len(currentItemStr) / 2), 1)
  123.       term.write(currentItemStr)
  124.     else
  125.       currentItem = currentItem + 1
  126.       currentItemStr = itemList[currentItem]
  127.       paintutils.drawLine(2, 1, monX - 1, 1, colors.gray)
  128.       term.setCursorPos((monX / 2) - (string.len(currentItemStr) / 2), 1)
  129.       term.write(currentItemStr)
  130.     end
  131.   elseif itemStr == "-" then
  132.     if currentItem <= 1 then
  133.       currentItem = 4
  134.       currentItemStr = itemList[currentItem]
  135.       paintutils.drawLine(2, 1, monX - 1, 1, colors.gray)
  136.       term.setCursorPos((monX / 2) - (string.len(currentItemStr) / 2), 1)
  137.       term.write(currentItemStr)
  138.     else
  139.       currentItem = currentItem - 1
  140.       currentItemStr = itemList[currentItem]
  141.       paintutils.drawLine(2, 1, monX - 1, 1, colors.gray)
  142.       term.setCursorPos((monX / 2) - (string.len(currentItemStr) / 2), 1)
  143.       term.write(currentItemStr)
  144.     end
  145.   end
  146.  
  147.   setCursorList(currentItem)
  148.  
  149.   if currentItem == 4 and currentItemQuantity > 16 then
  150.     currentItemQuantity = 16
  151.     currentItemQuantity = math.ceil(currentItemQuantity)
  152.     paintutils.drawLine(monX / 3 + 3, monY / 2 + 1, monX, monY / 2 + 1, colors.lightGray)
  153.     term.setCursorPos(monX / 3 + 3, monY / 2 + 1)
  154.     term.write("Commande : "..tostring(currentItemQuantity))
  155.   end
  156.  
  157.   currentSubItem = 0
  158. end
  159.  
  160. function setItem(itemPos)
  161.   itemPos = itemPos - 2
  162.   setCursorList(itemPos)
  163.   currentItem = itemPos
  164.   currentItemStr = itemList[currentItem]
  165.   paintutils.drawLine(2, 1, monX - 1, 1, colors.gray)
  166.   term.setCursorPos((monX / 2) - (string.len(currentItemStr) / 2), 1)
  167.   term.write(currentItemStr)
  168.  
  169.   if currentItem == 4 and currentItemQuantity > 16 then
  170.     currentItemQuantity = 16
  171.     currentItemQuantity = math.ceil(currentItemQuantity)
  172.     paintutils.drawLine(monX / 3 + 3, monY / 2 + 1, monX, monY / 2 + 1, colors.lightGray)
  173.     term.setCursorPos(monX / 3 + 3, monY / 2 + 1)
  174.     term.write("Commande : "..tostring(currentItemQuantity))
  175.   end
  176.  
  177.   currentSubItem = 0
  178. end
  179.  
  180. function changeQuantity(newQuantity)
  181.   if newQuantity == "-1" then
  182.     currentItemQuantity = currentItemQuantity - 1
  183.     if currentItemQuantity < 1 then
  184.       currentItemQuantity = 1
  185.     end
  186.   elseif newQuantity == "+1" then
  187.     currentItemQuantity = currentItemQuantity + 1
  188.     if currentItemQuantity > 64 then
  189.       currentItemQuantity = 64
  190.     end
  191.   elseif newQuantity == "-16" then
  192.     currentItemQuantity = currentItemQuantity - 16
  193.     if currentItemQuantity < 1 then
  194.       currentItemQuantity = 1
  195.     end
  196.   elseif newQuantity == "+16" then
  197.     currentItemQuantity = currentItemQuantity + 16
  198.     if currentItemQuantity > 64 then
  199.       currentItemQuantity = 64
  200.     end
  201.   elseif newQuantity == "-32" then
  202.     currentItemQuantity = currentItemQuantity - 32
  203.     if currentItemQuantity < 1 then
  204.       currentItemQuantity = 1
  205.     end
  206.   elseif newQuantity == "+32" then
  207.     currentItemQuantity = currentItemQuantity + 32
  208.     if currentItemQuantity > 64 then
  209.       currentItemQuantity = 64
  210.     end
  211.   elseif newQuantity == "-64" then
  212.     currentItemQuantity = currentItemQuantity - 64
  213.     if currentItemQuantity < 1 then
  214.       currentItemQuantity = 1
  215.     end
  216.   elseif newQuantity == "+64" then
  217.     currentItemQuantity = currentItemQuantity + 64
  218.     if currentItemQuantity > 64 then
  219.       currentItemQuantity = 64
  220.     end
  221.   end
  222.  
  223.   if currentItem == 4 and currentItemQuantity > 16 then
  224.     currentItemQuantity = 16
  225.   end
  226.  
  227.   currentItemQuantity = math.ceil(currentItemQuantity)
  228.   paintutils.drawLine(monX / 3 + 3, monY / 2 + 1, monX, monY / 2 + 1, colors.lightGray)
  229.   term.setCursorPos(monX / 3 + 3, monY / 2 + 1)
  230.   term.write("Commande : "..tostring(currentItemQuantity))
  231. end
  232.  
  233. function buttonHandler()
  234.   while true do
  235.     event, button, mouseX, mouseY = os.pullEvent("monitor_touch")
  236.  
  237.     if mouseX <= monX / 3 + 1 and mouseY == 8 and currentItem == 1 then
  238.       paintutils.drawLine(1, 3, 1, 6, colors.lightBlue)
  239.       paintutils.drawLine(4, 8, 4, 9, colors.lightBlue)
  240.       term.setTextColor(colors.yellow)
  241.       term.setCursorPos(4, 8)
  242.       term.write(">")
  243.       term.setTextColor(oldColor)
  244.       currentSubItem = 1
  245.     elseif mouseX <= monX / 3 + 1 and mouseY == 9 and currentItem == 1 then
  246.       paintutils.drawLine(1, 3, 1, 6, colors.lightBlue)
  247.       paintutils.drawLine(4, 8, 4, 9, colors.lightBlue)
  248.       term.setTextColor(colors.yellow)
  249.       term.setCursorPos(4, 9)
  250.       term.write(">")
  251.       term.setTextColor(oldColor)
  252.       currentSubItem = 2
  253.     elseif mouseX == 1 and mouseY == 1 then
  254.       changeItem("-")
  255.     elseif mouseX == monX and mouseY == 1 or mouseX == monX - 1 and mouseY == 1 or mouseX == monX and mouseY == 2 or mouseX == monX - 1 and mouseY == 2 then
  256.       changeItem("+")
  257.     elseif mouseX <= monX / 3 + 1 and mouseY <= 6 and mouseY >= 3 then
  258.       setItem(mouseY)
  259.     elseif mouseX <= monX / 3 + 7 and mouseX >= monX / 3 + 3 and mouseY <= 5 and mouseY >= 3 then
  260.       changeQuantity("-1")
  261.     elseif mouseX <= monX / 3 + 7 and mouseX >= monX / 3 + 3 and mouseY <= monY - 1 and mouseY >= monY - 3 then
  262.       changeQuantity("+1")
  263.     elseif mouseX <= monX / 3 + 13 and mouseX >= monX / 3 + 9 and mouseY <= 5 and mouseY >= 3 then
  264.       changeQuantity("-16")
  265.     elseif mouseX <= monX / 3 + 13 and mouseX >= monX / 3 + 9 and mouseY <= monY - 1 and mouseY >= monY - 3 then
  266.       changeQuantity("+16")
  267.     elseif mouseX <= monX / 3 + 19 and mouseX >= monX / 3 + 15 and mouseY <= 5 and mouseY >= 3 then
  268.       changeQuantity("-32")
  269.     elseif mouseX <= monX / 3 + 19 and mouseX >= monX / 3 + 15 and mouseY <= monY - 1 and mouseY >= monY - 3 then
  270.       changeQuantity("+32")
  271.     elseif mouseX <= monX / 3 + 25 and mouseX >= monX / 3 + 21 and mouseY <= 5 and mouseY >= 3 then
  272.       changeQuantity("-64")
  273.     elseif mouseX <= monX / 3 + 25 and mouseX >= monX / 3 + 21 and mouseY <= monY - 1 and mouseY >= monY - 3 then
  274.       changeQuantity("+64")
  275.     elseif mouseX <= monX - 1 and mouseX >= monX / 3 + 27 and mouseY <= monY - 1 and mouseY >= monY - 3 then
  276.       if currentSubItem == 0 then
  277.         rednet.send(serverList[currentItem], tostring(currentItemQuantity))
  278.       else
  279.         rednet.send(serverSubList[currentSubItem], tostring(currentItemQuantity))
  280.       end
  281.     end
  282.  
  283.     if currentItem == 1 then
  284.       term.setBackgroundColor(colors.lightBlue)
  285.       term.setCursorPos(3, 8)
  286.       term.setTextColor(colors.yellow)
  287.       term.write("+")
  288.       term.setTextColor(colors.white)
  289.       term.setCursorPos(6, 8)
  290.       term.write("Prismarine")
  291.       term.setCursorPos(6, 9)
  292.       term.write("Pris. Bricks")
  293.     else
  294.       paintutils.drawFilledBox(1, 8, monX / 3 + 1, 10, colors.lightBlue)
  295.     end
  296.   end
  297. end
  298.  
  299. function levelHandler()
  300.   while true do
  301.     id, msg = rednet.receive("arcGuard")
  302.  
  303.     if id == levelServerList[currentItem] then
  304.       term.setBackgroundColor(colors.lightBlue)
  305.       term.setCursorPos(1, monY)
  306.       pxLine = tonumber(msg)
  307.       pxLine = (pxLine * (monX / 3 + 1)) / 15
  308.       paintutils.drawLine(1, monY, monX / 3 + 1, monY, colors.lightBlue)
  309.       if pxLine == 0 then
  310.         paintutils.drawLine(1, monY, pxLine, monY, colors.red)
  311.         term.setCursorPos(1, monY)
  312.         term.setTextColor(colors.orange)
  313.         term.write("0")
  314.         term.setTextColor(colors.white)
  315.       else
  316.         paintutils.drawLine(1, monY, pxLine, monY, colors.cyan)
  317.       end
  318.     end
  319.   end
  320. end
  321.  
  322. parallel.waitForAny(buttonHandler, levelHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement