Nightmare129

ecran_final

Feb 6th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.67 KB | None | 0 0
  1. --/////////////////////////////////////////////////////////
  2. --//----------- PROGRMAME COMPUTEUR CRAFT ---------------//
  3. --//----------- ************************* ---------------//
  4. --//------- AFFICHAGE DYNAMIQUE ET INTERACTIF -----------//
  5. --//----- DE TUBINE ET REATEUR DE BIGREACTOR ------------//
  6. --/////////////////////////////////////////////////////////
  7.  
  8. --Confguration
  9. rednet.open("left")
  10. local ecran=peripheral.wrap("top")
  11. local idTurbine = "MasterEnergie"
  12. local nbm = 8 --Nombre de turbin afficher
  13. local k=0
  14. parallel.waitForAll(Ecoute,Affichage,Tactille)
  15. --////////////////////////////////////////////////////////
  16. --//-------------------FUNCTION-------------------------//
  17. --////////////////////////////////////////////////////////
  18.  
  19. -- Function de recuperation des infos envoye en wifi
  20. function Ecoute()
  21.     while true do
  22.         local event, id, ID, TablData = os.pullEvent("rednet_message")
  23.         if ID>=1 and  ID<=8 then
  24.             --print(ID)
  25.             data[ID]["PCon"]= false
  26.             data[ID]=textutils.unserialize(TablData)  
  27.         elseif ID==100 then
  28.             data100["PCon"]= false
  29.             data100=textutils.unserialize(TablData)
  30.         end
  31.     end
  32. end
  33.  
  34. -- Function du main d'affichage
  35. function Affichage()
  36.     Init()
  37.     while true do --main
  38.         k=k+1
  39.         AffichageTurbine()
  40.         AffichageReactor()
  41.         os.sleep(0.8)
  42.     end
  43. end
  44.  
  45. -- Tout est dans le nom
  46. function Tactile()
  47.  
  48.     local Mdata={}  
  49.     while true do
  50.         local e, bt, yp, xp = os.pullEvent("monitor_touch")
  51.         --Pour les turbines
  52.         local i=1
  53.         for i=1,nbm do
  54.             local x=1 y=1
  55.             if     i==1 then x=1  y=3
  56.             elseif i==2 then x=1  y=52
  57.             elseif i==3 then x=11 y=3
  58.             elseif i==4 then x=11 y=52
  59.             elseif i==5 then x=21 y=3
  60.             elseif i==6 then x=21 y=52
  61.             elseif i==7 then x=31 y=3
  62.             elseif i==8 then x=31 y=52
  63.             end
  64.             --activee desactiver
  65.             if yp>=y+6 and yp<=y+11  and xp>=x+2 and x<=x+5 then
  66.                 Mdata["numberTurbine"] = i
  67.                 Mdata["sInductor"] = data[i]["gInductor"]
  68.                 Mdata["sActive"] = !data[i]["gActive"]
  69.             end
  70.              --engagement desengagement
  71.             if xp==x+1  and yp>=y+6  and yp<=y+12  then
  72.                 Mdata["numberTurbine"] = i
  73.                 Mdata["sActive"] = data[i]["gActive"]
  74.                 Mdata["sInductor"] =!data[i]["gInductor"]
  75.             end
  76.         end
  77.         --pour le reacteur
  78.         --activee desactiver
  79.         if yp>=25 and yp<=33  and xp>=10 and x<=28 then
  80.             Mdata["numberTurbine"] = i
  81.             Mdata["sInductor"] = data[i]["gInductor"]
  82.             Mdata["sActive"] = !data[i]["gActive"]
  83.         end
  84.         rednet.broadcast(idTurbine,textutils.serialize(Mdata))
  85.         os.sleep(0.4)  
  86.     end
  87. end
  88.  
  89. -- Function d'inisialisation
  90. function Init()
  91.     local cpt=1
  92.     local data={}    --pour les turbins
  93.     local data100={} --pour reactor
  94.     data[1]={}
  95.     data[2]={}
  96.     data[3]={}
  97.     data[4]={}
  98.     data[5]={}
  99.     data[6]={}
  100.     data[7]={}
  101.     data[8]={}
  102.     data[100]={}
  103.    
  104.     windows = {} --pour les images
  105.     windows[1] = window.create(ecran, 9 , 3 , 5, 5, true)--Tubines
  106.     windows[2] = window.create(ecran, 58, 3 , 5, 5, true)
  107.     windows[3] = window.create(ecran, 9 , 13, 5, 5, true)
  108.     windows[4] = window.create(ecran, 58, 13, 5, 5, true)
  109.     windows[5] = window.create(ecran, 9 , 23, 5, 5, true)
  110.     windows[6] = window.create(ecran, 58, 23, 5, 5, true)
  111.     windows[7] = window.create(ecran, 9 , 33, 5, 5, true)
  112.     windows[8] = window.create(ecran, 58, 33, 5, 5, true)
  113.     windows[100] = window.create(ecran, 31, 10, 9, 18, true)--Reactor
  114.     windows[101] = window.create(ecran, 23, 2, 26, 6, true)--Titre
  115.    
  116.     --chargement
  117.     ecran.setBackgroundColor(colors.blue)
  118.     ecran.clear()
  119.     line(10 ,20,50 ,4, colors.black)
  120.    
  121.     for cpt=1, 50 do
  122.         line(10 ,20 ,cpt,4, colors.green)
  123.         os.sleep(0.05)
  124.     end
  125.     os.sleep(0.5)
  126.     ecran.setBackgroundColor(colors.black)
  127.     ecran.clear()
  128.    
  129.     Titre = paintutils.loadImage("Titre")
  130.     windows[101].setBackgroundColor(colors.black)
  131.     windows[101].setTextColor(colors.black)
  132.     windows[101].clear()
  133.     term.redirect(windows[101])
  134.     paintutils.drawImage(Titre, 1, 1)
  135. end
  136.  
  137. -- Function d'affichage les donners des turbines
  138. function AffichageTurbine()
  139.     local turb
  140.     if k == 5 then k = 1 end --pour les images
  141.    
  142.     local i=1
  143.     for i=1,nbm do --data[1] a data[nbm]       
  144.         --chois de la position
  145.         local x=1 y=1
  146.         if     i==1 then x=1  y=3
  147.         elseif i==2 then x=1  y=52
  148.         elseif i==3 then x=11 y=3
  149.         elseif i==4 then x=11 y=52
  150.         elseif i==5 then x=21 y=3
  151.         elseif i==6 then x=21 y=52
  152.         elseif i==7 then x=31 y=3
  153.         elseif i==8 then x=31 y=52
  154.         end
  155.            
  156.         --Debut de l'affiche
  157.         ecran.setTextColor(colors.white)
  158.         ecran.setCursorPos(y+4,x)   --**--
  159.         ecran.write("Turbine "..i)
  160.        
  161.         if data[i]["PCon"] == true then
  162.             --L'activiter
  163.             if data[i]["gActive"] == true then
  164.                 turb = paintutils.loadImage("turb"..k)
  165.             else
  166.                 turb = paintutils.loadImage("turb0")
  167.             end
  168.             windows[i].setBackgroundColor(colors.black)
  169.             windows[i].setTextColor(colors.black)
  170.             windows[i].clear()
  171.             term.redirect(windows[i])
  172.             paintutils.drawImage(turb, 1, 1)
  173.  
  174.             --L'engagement
  175.             if data[i]["gInductor"]==true then
  176.                 ecran.setCursorPos(y+4,x+1)  
  177.                 ecran.setBackgroundColor(colors.black)
  178.                 ecran.write(" ")
  179.                 line(y+5 ,x+1 ,7 ,1, colors.blue)
  180.                 ecran.setCursorPos(y+5,x+1)
  181.                 ecran.write("Engager")
  182.                 ecran.setBackgroundColor(colors.black)
  183.                 ecran.write("   ")
  184.             else
  185.                 line(y+4 ,x+1 ,7 ,1, colors.red)
  186.                 ecran.setCursorPos(y+4,x+1)
  187.                 ecran.write("Desengager")
  188.                 ecran.setBackgroundColor(colors.black)
  189.             end
  190.  
  191.             ecran.setTextColor(colors.white)
  192.             ecran.setCursorPos(y+1,x+7)
  193.             ecran.write("Rotor: ")
  194.    
  195.             if data[i]["gSpeed"]<800 then
  196.                 ecran.setTextColor(colors.red)
  197.             elseif data[i]["gSpeed"]<1000 then
  198.                 ecran.setTextColor(colors.blue)
  199.             elseif data[i]["gSpeed"]<1700 then
  200.                 ecran.setTextColor(colors.red)
  201.             elseif data[i]["gSpeed"]<1900 then
  202.                 ecran.setTextColor(colors.blue)  
  203.             else
  204.                 ecran.setTextColor(colors.red)
  205.             end
  206.             ecran.setCursorPos(y+8,x+7)
  207.             ecran.write(number_format(data[i]["gSpeed"]).." RPM     ")
  208.             ecran.setTextColor(colors.white)
  209.    
  210.             ecran.setCursorPos(y,x+8)
  211.             ecran.write("Prod : "..number_format(data[i]["gProductLastTick"]).." RF/t     ")
  212.            
  213.         else
  214.             --ecran.setCursorPos(y+4,x+4)
  215.             --ecran.write("PC åA9teint")
  216.             Titre = paintutils.loadImage("PCoff")
  217.             windows[i].setBackgroundColor(colors.black)
  218.             windows[i].setTextColor(colors.black)
  219.             windows[i].clear()
  220.             term.redirect(windows[i])
  221.             paintutils.drawImage(turb, 1, 1)
  222.         end
  223.     end
  224. end
  225.  
  226. --Function d'affichage des donners du reactor
  227. function AffichageReactor()
  228.     local reactor
  229.     local y=25 x=9
  230.     --Affichage de l'activiter
  231.     ecran.setCursorPos(y+7,x)
  232.     ecran.write("Reactor")
  233.     if data100["PCon"] == true then
  234.         if data100["gActive"]==true then
  235.             reactor = paintutils.loadImage("reactor")
  236.         else
  237.             reactor = paintutils.loadImage("reactoroff")
  238.         end
  239.         windows[100].setBackgroundColor(colors.black)
  240.         windows[100].setTextColor(colors.black)
  241.         windows[100].clear()
  242.         term.redirect(windows[100])
  243.         paintutils.drawImage(reactor, 1, 1)
  244.         ecran.setBackgroundColor(colors.black)
  245.        
  246.         --Affichage des donnes
  247.         ecran.setTextColor(colors.white)
  248.         ecran.setCursorPos(y,x+20) --le stock de yell en ingot
  249.         ecran.write("Fuel: "..number_format(data100["gFuelAmount"]).." yell  ")
  250.         ecran.setCursorPos(y+1,x+21)
  251.         ecran.write("Decher: "..number_format(data100["gWasteAmount"]).." cyanit  ")
  252.         ecran.setCursorPos(y+5,x+22) --le stock de yell en %
  253.         ecran.write("Stock: "..math.ceil(data100["gFuelAmount"]/data100["gFuelAmountMax"]*100).."%")
  254.         ecran.setCursorPos(y+1,x+23) --production en mb/t
  255.         ecran.write("Prod: "..number_format(data100["gHotFluidProducedLastTick"]).." mb/t   ")
  256.         ecran.setCursorPos(y,x+24) --comsomation de yell en mb
  257.         ecran.write("Conso: "..number_format(data100["gFuelConsumedLastTick"]))
  258.         ecran.setCursorPos(y+9,x+24)
  259.         ecran.write("mb/t de yell")
  260.         ecran.setCursorPos(y+4,x+25) --temperature en C
  261.         ecran.write("Temp: "..number_format(data100["gCasingtemperature"]).." C  ")
  262.         ecran.setCursorPos(y+4,x+26) --reactiviter %
  263.         ecran.write("Reacto: "..number_format(data100["gFuelReactivity"]).." %  ")
  264.     else
  265.         ecran.setCursorPos(y+4,x)
  266.         ecran.write("PC åA9teint")
  267.         --Titre = paintutils.loadImage("")
  268.         --windows[i].setBackgroundColor(colors.black)
  269.         --windows[i].setTextColor(colors.black)
  270.         --windows[i].clear()
  271.         --term.redirect(windows[i])
  272.         --paintutils.drawImage(turb, 1, 1)
  273.     end
  274.     --pour les erreurs
  275.     --Titre = paintutils.loadImage("")
  276.     --windows[i].setBackgroundColor(colors.black)
  277.     --windows[i].setTextColor(colors.black)
  278.     --windows[i].clear()
  279.     --term.redirect(windows[i])
  280.     --paintutils.drawImage(turb, 1, 1)
  281. end
  282.  
  283. -- Crestion de rectangle de couleur
  284. function line(x ,y ,long ,larg, color_font)
  285.     ecran.setBackgroundColor(color_font)
  286.     for yp=y, y+larg-1 do
  287.         ecran.setCursorPos(x,yp)
  288.         ecran.write(string.rep(" ", long))
  289.     end
  290. end
  291.  
  292. -- Bar de progresion
  293. function prog(x ,y ,long ,larg, valmin, valmax ,color_bar ,color_font)
  294.     line(x ,y ,long ,larg, color_font)
  295.     local bar = math.floor((valmin/valmax)*long)
  296.     line(x ,y ,bar ,larg, color_bar)
  297. end
  298.  
  299. -- Function pour transformer 9876543 en 9 876 543
  300. function number_format(n)
  301.   local test=mille(n)
  302.   if test.Mille==0 then
  303.     return math.floor(n)
  304.   else
  305.     test.Mille=mille(test.Mille)
  306.     if test.Mille.Mille==0 then
  307.       return test.Mille.Cent.." "..cent(test.Cent)
  308.     else
  309.       return test.Mille.Mille.." "..cent(test.Mille.Cent).." "..cent(test.Cent)
  310.     end
  311.   end
  312. end
  313.  
  314. -- Function pour etre sur d'avoir trois chiffre (99 devient 099, 9 devient 009)
  315. function cent(n)
  316.   n=math.floor(n)
  317.   if n>99 then
  318.     return n
  319.    elseif n>9 then
  320.     return "0"..n
  321.    else
  322.     return "00"..n
  323.    end
  324. end
  325.  
  326. -- Creer un objet avec les centaine d'un cotåA5A5A9 les millier de l'autre
  327. function mille(n)
  328.   if n<1000 then
  329.     return {Mille=0,Cent=n}
  330.   else
  331.     return {Mille=math.floor(n/1000),Cent=n%1000}
  332.   end
  333. end
Add Comment
Please, Sign In to add comment