Advertisement
william200027

Affichage Geothermal

Jul 22nd, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.47 KB | None | 0 0
  1. ------------------------------
  2. BackgroundColor = colors.gray  -- change la couleur du fond d'écran
  3. LigneColor = colors.white -- change la couleur des lignes
  4. ColorEnergy = colors.green
  5. ColorLave = colors.red
  6. MonitorSide = "top" -- attacher l'écran 3x6
  7. ConnecMax = 10 -- ne pas changer
  8. MaxEnergy = 1000000
  9. MaxTank = 10000
  10. Monitor = peripheral.wrap(MonitorSide)
  11. Machine = {}
  12. Energyy = {}
  13. Tankk = {}
  14. Tank = {}
  15. Energy = {}
  16. EnergyPourcent = {}
  17. TankPourcent = {}
  18. PourcentE = {}
  19. PourcentT = {}
  20. LeftRight = 1
  21. UpDown = 1
  22. PagePrecedente = 0
  23. PageActuelle = 1
  24. PageSuivante = 2
  25. PosY = 0
  26. rednet.open("left")
  27. idRednet = 3
  28. ------------------------------
  29. ------------------------------
  30. function Connexion()
  31.  
  32.   for ConnecMin=1,ConnecMax do
  33.     Machine[ConnecMin] = peripheral.wrap("techreborn:thermal_generator_"..ConnecMin)
  34.   end
  35.  
  36. end
  37. ------------------------------
  38. ------------------------------
  39. function Affichage()
  40.  
  41.     Monitor.setBackgroundColor(BackgroundColor)
  42.     Monitor.clear()
  43.     Monitor.setCursorPos(31,2)
  44.     Monitor.setTextColor(colors.red)
  45.     Monitor.write("Interface !")
  46.     Monitor.setTextColor(LigneColor)
  47.     Monitor.setCursorPos(1,1)  -- gauche = droite ou gauche , droite = hauteur
  48.     Monitor.write("-----------------------------------------------------------------------")
  49.     Monitor.setCursorPos(1,18)
  50.     Monitor.write("-----------------------------------------------------------------------")
  51.     Monitor.setCursorPos(1,19)
  52.     Monitor.write("|")
  53.     Monitor.setCursorPos(3,19)
  54.     Monitor.setTextColor(colors.red)
  55.     Monitor.write(PagePrecedente.."")
  56.     Monitor.setTextColor(LigneColor)
  57.     Monitor.setCursorPos(5,19)
  58.     Monitor.write("|")
  59.  
  60.     Monitor.setCursorPos(31,19)
  61.     Monitor.write("|")
  62.     Monitor.setCursorPos(33,19)
  63.     Monitor.setTextColor(colors.red)
  64.     Monitor.write("Page: "..PageActuelle.."")
  65.     Monitor.setTextColor(LigneColor)
  66.     Monitor.setCursorPos(41,19)
  67.     Monitor.write("|")
  68.  
  69.     Monitor.setCursorPos(67,19)
  70.     Monitor.write("|")
  71.     Monitor.setCursorPos(69,19)
  72.     Monitor.setTextColor(colors.red)
  73.     Monitor.write(PageSuivante.."")
  74.     Monitor.setTextColor(LigneColor)
  75.     Monitor.setCursorPos(71,19)
  76.     Monitor.write("|")
  77.  
  78. end
  79. ------------------------------
  80. ------------------------------
  81. function cadre()
  82. LeftRight = 2
  83.   for n=1,4 do
  84.     UpDown = UpDown + 2
  85.     Monitor.setCursorPos(LeftRight,UpDown)
  86.     Monitor.write("-----------------")
  87.     UpDown = UpDown + 1
  88.     Monitor.setCursorPos(LeftRight,UpDown)
  89.     Monitor.write("|")
  90.     UpDown = UpDown + 1
  91.     Monitor.setCursorPos(LeftRight,UpDown)
  92.     Monitor.write("|")
  93.     UpDown = UpDown + 1
  94.     Monitor.setCursorPos(LeftRight,UpDown)
  95.     Monitor.write("|")
  96.     UpDown = UpDown + 1
  97.     Monitor.setCursorPos(LeftRight,UpDown)
  98.     Monitor.write("|")
  99.     UpDown = UpDown + 1
  100.     Monitor.setCursorPos(LeftRight,UpDown)
  101.     Monitor.write("|")
  102.     UpDown = UpDown + 1
  103.     Monitor.setCursorPos(LeftRight,UpDown)
  104.     Monitor.write("|")
  105.     UpDown = UpDown + 1
  106.     Monitor.setCursorPos(LeftRight,UpDown)
  107.     Monitor.write("|")
  108.     UpDown = UpDown + 1
  109.     Monitor.setCursorPos(LeftRight,UpDown)
  110.     Monitor.write("|")
  111.     UpDown = UpDown + 1
  112.     Monitor.setCursorPos(LeftRight,UpDown)
  113.     Monitor.write("|")
  114.     UpDown = UpDown + 1
  115.     Monitor.setCursorPos(LeftRight,UpDown)
  116.     Monitor.write("|")
  117.     UpDown = UpDown + 1
  118.     Monitor.setCursorPos(LeftRight,UpDown)
  119.     Monitor.write("|")
  120.     UpDown = UpDown + 1
  121.     Monitor.setCursorPos(LeftRight,UpDown)
  122.     Monitor.write("-----------------")
  123.     LeftRight = LeftRight + 8
  124.     UpDown = 3
  125.     Monitor.setTextColor(colors.blue)
  126.     UpDown = UpDown + 1
  127.     Monitor.setCursorPos(LeftRight,UpDown)
  128.     Monitor.write("|")
  129.     UpDown = UpDown + 1
  130.     Monitor.setCursorPos(LeftRight,UpDown)
  131.     Monitor.write("|")
  132.     UpDown = UpDown + 1
  133.     Monitor.setCursorPos(LeftRight,UpDown)
  134.     Monitor.write("|")
  135.     UpDown = UpDown + 1
  136.     Monitor.setCursorPos(LeftRight,UpDown)
  137.     Monitor.write("|")
  138.     UpDown = UpDown + 1
  139.     Monitor.setCursorPos(LeftRight,UpDown)
  140.     Monitor.write("|")
  141.     UpDown = UpDown + 1
  142.     Monitor.setCursorPos(LeftRight,UpDown)
  143.     Monitor.write("|")
  144.     UpDown = UpDown + 1
  145.     Monitor.setCursorPos(LeftRight,UpDown)
  146.     Monitor.write("|")
  147.     UpDown = UpDown + 1
  148.     Monitor.setCursorPos(LeftRight,UpDown)
  149.     Monitor.write("|")
  150.     UpDown = UpDown + 1
  151.     Monitor.setCursorPos(LeftRight,UpDown)
  152.     Monitor.write("|")
  153.     UpDown = UpDown + 1
  154.     Monitor.setCursorPos(LeftRight,UpDown)
  155.     Monitor.write("|")
  156.     UpDown = UpDown + 1
  157.     Monitor.setCursorPos(LeftRight,UpDown)
  158.     Monitor.write("|")
  159.     UpDown = UpDown + 1
  160.     LeftRight = LeftRight + 8
  161.     UpDown = 4
  162.     Monitor.setTextColor(LigneColor)
  163.     Monitor.setCursorPos(LeftRight,UpDown)
  164.     Monitor.write("|")
  165.     UpDown = UpDown + 1
  166.     Monitor.setCursorPos(LeftRight,UpDown)
  167.     Monitor.write("|")
  168.     UpDown = UpDown + 1
  169.     Monitor.setCursorPos(LeftRight,UpDown)
  170.     Monitor.write("|")
  171.     UpDown = UpDown + 1
  172.     Monitor.setCursorPos(LeftRight,UpDown)
  173.     Monitor.write("|")
  174.     UpDown = UpDown + 1
  175.     Monitor.setCursorPos(LeftRight,UpDown)
  176.     Monitor.write("|")
  177.     UpDown = UpDown + 1
  178.     Monitor.setCursorPos(LeftRight,UpDown)
  179.     Monitor.write("|")
  180.     UpDown = UpDown + 1
  181.     Monitor.setCursorPos(LeftRight,UpDown)
  182.     Monitor.write("|")
  183.     UpDown = UpDown + 1
  184.     Monitor.setCursorPos(LeftRight,UpDown)
  185.     Monitor.write("|")
  186.     UpDown = UpDown + 1
  187.     Monitor.setCursorPos(LeftRight,UpDown)
  188.     Monitor.write("|")
  189.     UpDown = UpDown + 1
  190.     Monitor.setCursorPos(LeftRight,UpDown)
  191.     Monitor.write("|")
  192.     UpDown = UpDown + 1
  193.     Monitor.setCursorPos(LeftRight,UpDown)
  194.     Monitor.write("|")
  195.     UpDown = 1
  196.     LeftRight = LeftRight + 1
  197.  
  198.   end
  199.   LeftRight = 3
  200.   UpDown = 1
  201. end
  202. ------------------------------
  203. ------------------------------
  204. function donnee()
  205.  
  206.     for ConnecMin=1,ConnecMax do
  207.         --if Energyy[ConnecMin] == nil then
  208.         --else
  209.             Energyy[ConnecMin] = Machine[ConnecMin].getDemandedEnergy()
  210.             Tankk[ConnecMin] = Machine[ConnecMin].getTanks()
  211.  
  212.             Energy[ConnecMin] = MaxEnergy - Energyy[ConnecMin]
  213.             EnergyPourcent[ConnecMin] = math.floor(Energy[ConnecMin]/MaxEnergy*100)
  214.             PourcentE[ConnecMin] = math.floor(EnergyPourcent[ConnecMin]/10)
  215.         --end
  216.         --if Tankk[ConnecMin] == nil then
  217.         --else
  218.          if Tankk[ConnecMin][1]["amount"] == nil then
  219.             Tank[ConnecMin] = 0
  220.             TankPourcent[ConnecMin] = 0
  221.          else
  222.             Tank[ConnecMin] = Tankk[ConnecMin][1]["amount"]
  223.             TankPourcent[ConnecMin] = math.floor(Tank[ConnecMin]/MaxTank*100)
  224.             PourcentT[ConnecMin] = math.floor(TankPourcent[ConnecMin]/10)
  225.          end
  226.         --end
  227.     end
  228. end
  229. ------------------------------
  230. ------------------------------
  231. function PrintDonne()
  232.     for ConnecMin=1,ConnecMax do
  233.         print(Energy[ConnecMin].."/"..MaxEnergy.." "..EnergyPourcent[ConnecMin].."%")
  234.         print(Tank[ConnecMin].."/"..MaxTank.." "..TankPourcent[ConnecMin].."%")
  235.     end
  236. end
  237. ------------------------------
  238. ------------------------------
  239. function red()
  240.     id, message = rednet.receive((1)) -- TimeOut
  241.         if id == idRednet and message == 0 then
  242.             if PageActuelle == 1 then
  243.             else
  244.                 print("0")
  245.                 PagePrecedente = PagePrecedente - 1
  246.                 PageActuelle = PageActuelle - 1
  247.                 PageSuivante = PageSuivante - 1
  248.                 Affichage()
  249.                 cadre()
  250.             end
  251.         end
  252.         if id == idRednet and message == 1 then
  253.             if PageActuelle == math.floor(ConnecMax/4+.5) then
  254.             else
  255.                 print("1")
  256.                 PagePrecedente = PagePrecedente + 1
  257.                 PageActuelle = PageActuelle + 1
  258.                 PageSuivante = PageSuivante + 1
  259.                 Affichage()
  260.                 cadre()
  261.             end
  262.         end
  263. end
  264. ------------------------------
  265. ------------------------------
  266. function Writedonne()
  267.     Affichage()
  268.     cadre()
  269.  
  270.     function NP()
  271.         if PageActuelle == 1 then
  272.             return 1
  273.         elseif PageActuelle == 2 then
  274.             return 5
  275.         elseif PageActuelle == 3 then
  276.             return 9
  277.         elseif PageActuelle == 4 then
  278.             return 13
  279.         elseif PageActuelle == 5 then
  280.             return 17
  281.         elseif PageActuelle == 6 then
  282.             return 21
  283.         elseif PageActuelle == 7 then
  284.             return 25
  285.         elseif PageActuelle == 8 then
  286.             return 29
  287.         elseif PageActuelle == 9 then
  288.             return 33
  289.         elseif PageActuelle == 10 then
  290.             return 37
  291.         elseif PageActuelle == 11 then
  292.             return 41
  293.         elseif PageActuelle == 12 then
  294.             return 45
  295.         elseif PageActuelle == 13 then
  296.             return 49
  297.         elseif PageActuelle == 14 then
  298.             return 53
  299.         elseif PageActuelle == 15 then
  300.             return 57
  301.         elseif PageActuelle == 16 then
  302.             return 61
  303.         elseif PageActuelle == 17 then
  304.             return 65
  305.         elseif PageActuelle == 18 then
  306.             return 69
  307.         elseif PageActuelle == 19 then
  308.             return 73
  309.         elseif PageActuelle == 20 then
  310.             return 77
  311.         end
  312.     end
  313.  
  314.     local UpDownD = 16
  315.     local LeftRightD = 1
  316.  
  317.     ConnecMin = NP()
  318.     number = 1
  319.     for i=0,3 do
  320.         PosY = 14
  321.         if Energy[ConnecMin] == nil then
  322.         else
  323.             Monitor.setCursorPos(LeftRightD,UpDownD)
  324.             Monitor.setTextColor(ColorEnergy)
  325.             Monitor.write(Energy[ConnecMin].."/1M".." "..EnergyPourcent[ConnecMin].."%")
  326.             local UpDownD = UpDownD + 1
  327.             Monitor.setCursorPos(LeftRightD,UpDownD)
  328.             Monitor.setTextColor(ColorLave)
  329.             Monitor.write(Tank[ConnecMin].."/"..MaxTank.." "..TankPourcent[ConnecMin].."%")
  330.             LeftRightD = LeftRightD + 18
  331.  
  332.             if TankPourcent[ConnecMin] == 0 then
  333.             else
  334.  
  335.                 if number == 1  then
  336.                     PosZ = 3
  337.                 elseif number == 2 then
  338.                     PosZ = 20
  339.                 elseif number == 3 then
  340.                     PosZ = 37
  341.                 elseif number == 4 then
  342.                     PosZ = 54
  343.                 end
  344.  
  345.                 PosY = 14
  346.                 for i=0,PourcentT[ConnecMin] do
  347.                     Monitor.setCursorPos(PosZ,PosY) --X = 3,11,20,28,37,45,54,62,
  348.                     Monitor.setBackgroundColor(colors.red)
  349.                     Monitor.write("       ")
  350.                     Monitor.setBackgroundColor(BackgroundColor)
  351.  
  352.                     PosY = PosY - 1
  353.                     print("Pos de Lave: "..PosY.." Pos "..PosZ)
  354.                 end
  355.             end
  356.             if EnergyPourcent[ConnecMin] == 0 then
  357.             else
  358.  
  359.                 if number == 1  then
  360.                     PosZ = 11
  361.                 elseif number == 2 then
  362.                     PosZ = 28
  363.                 elseif number == 3 then
  364.                     PosZ = 45
  365.                 elseif number == 4 then
  366.                     PosZ = 62
  367.                 end
  368.  
  369.                 PosY = 14
  370.                 for i=0,PourcentE[ConnecMin] do
  371.                     Monitor.setCursorPos(PosZ,PosY) --X = 3,11,20,28,37,45,54,62,
  372.                     Monitor.setBackgroundColor(colors.green)
  373.                     Monitor.write("       ")
  374.                     Monitor.setBackgroundColor(BackgroundColor)
  375.  
  376.                     PosY = PosY - 1
  377.                     print("Pos de Energy: "..PosY.." Pos "..PosZ)
  378.                 end
  379.             end
  380.  
  381.             ConnecMin = ConnecMin + 1
  382.             print("-------------------------")
  383.             print("Connec: "..ConnecMin)
  384.             print("-------------------------")
  385.             number = number + 1
  386.         end
  387.     end
  388. end
  389. ------------------------------
  390. ------------------------------
  391. Connexion()
  392. Affichage()
  393. cadre()
  394. donnee()
  395. while true do
  396.     donnee()
  397.     --PrintDonne()
  398.     red()
  399.     Writedonne()
  400.     --sleep(1)
  401. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement