Advertisement
Nightmare129

ecran_testG2

Feb 3rd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.51 KB | None | 0 0
  1. --config
  2. rednet.open("left")
  3. local ecran=peripheral.wrap("top")
  4. local nbm = 8 --1 a 8
  5.  
  6. local data100={} --pour reactor
  7. local data={}    --pour les turbins
  8. data[1]={}
  9. data[2]={}
  10. data[3]={}
  11. data[4]={}
  12. data[5]={}
  13. data[6]={}
  14. data[7]={}
  15. data[8]={}
  16. windows = {}
  17. windows[1] = window.create(ecran, 1 , 2 , 5, 5, true)
  18. windows[2] = window.create(ecran, 50, 2 , 5, 5, true)
  19. windows[3] = window.create(ecran, 1 , 11, 5, 5, true)
  20. windows[4] = window.create(ecran, 50, 11, 5, 5, true)
  21. windows[5] = window.create(ecran, 1 , 21, 5, 5, true)
  22. windows[6] = window.create(ecran, 50, 21, 5, 5, true)
  23. windows[7] = window.create(ecran, 1 , 31, 5, 5, true)
  24. windows[8] = window.create(ecran, 50, 31, 5, 5, true)
  25.  
  26. local turb
  27. local k=0
  28.  
  29. -- function de recuperation des infos envoye en wifi
  30. function Ecoute()
  31.     while true do
  32.         local event, id, ID, TablData = os.pullEvent("rednet_message")
  33.   if ID>=1 and  ID<=8 then
  34.    --print(ID)
  35.             data[ID]=textutils.unserialize(TablData)  
  36.         elseif ID==100 then
  37.             data100=textutils.unserialize(TablData)
  38.         end
  39.     end
  40. end
  41.  
  42. function Affichage()
  43.     --chargement
  44.     ecran.setBackgroundColor(colors.blue)
  45.     ecran.clear()
  46.     line(10 ,20,50 ,4, colors.black)
  47.     local cpt=1
  48.     for cpt=1, 50 do
  49.         line(10 ,20 ,cpt,4, colors.green)
  50.         os.sleep(0.1)
  51.     end
  52.     os.sleep(0.5)
  53.     ecran.setBackgroundColor(colors.black)
  54.     ecran.clear()
  55.     while true do --main
  56.         k=k+1
  57.         AffichageTurbine()
  58.         AffichageReactor()
  59.         os.sleep(0.25)
  60.     end
  61. end
  62.  
  63. -- function d'affichage les donners des turbines
  64. function AffichageTurbine()
  65.  
  66.     if k == 5 then k = 1 end --pour les images
  67.         local i=1
  68.         for i=1,nbm do --data[1] a data[nbm]
  69.             os.sleep(0.1)
  70.             --print(i)     
  71.             --chois de la position
  72.             local x=1 y=1
  73.             if     i==1 then x=1 y=1
  74.             elseif i==2 then x=1  y=50
  75.             elseif i==3 then x=12 y=1          
  76.             elseif i==4 then x=12 y=50
  77.             elseif i==5 then x=24 y=1      
  78.             elseif i==6 then x=24 y=50
  79.             elseif i==7 then x=36 y=1
  80.             elseif i==8 then x=36 y=50
  81.             end
  82.            
  83.             --debut de l'affiche
  84.             ecran.setTextColor(colors.white)
  85.             ecran.setCursorPos(y,x)   --**--
  86.             ecran.write("Turbine "..i)
  87.             --l'activiter
  88.             if data[i]["gActive"] == true then
  89.                 turb = paintutils.loadImage("turb"..k)
  90.             else
  91.                 turb = paintutils.loadImage("turb0")
  92.             end
  93.             windows[i].setBackgroundColor(colors.black)
  94.             windows[i].setTextColor(colors.black)
  95.             windows[i].clear()
  96.             term.redirect(windows[i])
  97.             paintutils.drawImage(turb, 1, 1)
  98.             --l'engagement
  99.             if data[i]["gInductor"]==true then
  100.                 ecran.setCursorPos(y+10,x+1+5)
  101.                 ecran.write("Engager")
  102.                 ecran.setBackgroundColor(colors.black)
  103.                 ecran.write("   ")
  104.             else
  105.                 ecran.setCursorPos(y+10,x+1+5)
  106.                 ecran.write("Desengager")
  107.                 ecran.setBackgroundColor(colors.black)
  108.             end
  109.         end
  110.     end
  111. end
  112.  
  113. -- function d'affichage des donners du rector
  114. function AffichageReactor()
  115.  
  116.     local y=25 x=10
  117.         --affichage de l'activiter
  118.         ecran.setCursorPos(y,x)
  119.         ecran.write("Reactor")
  120.         if data100["gActive"]==true then
  121.             line(y ,x+1 ,6 ,1, colors.green)
  122.             ecran.setCursorPos(y,x+1)
  123.             ecran.write("Active")
  124.             ecran.setBackgroundColor(colors.black)
  125.             ecran.write("   ")
  126.         else
  127.             line(y+8 ,x+1 ,8 ,1, colors.red)
  128.             ecran.setCursorPos(y,x+1)
  129.             ecran.write("Desactive ")
  130.             ecran.setBackgroundColor(colors.black)
  131.         end
  132.        
  133.         --affichage des donnes
  134.         ecran.setTextColor(colors.white)
  135.         ecran.setCursorPos(y,x+2) --le stock de yell en ingot
  136.         ecran.write("Fuel   : "..number_format(data100["gFuelAmount"]/1000).." yell")
  137.         ecran.setCursorPos(y,x+3) --le stock de yell en %
  138.         ecran.write("Stock  : "..math.ceil(data100["gFuelAmount"]/data100["gFuelAmountMax"]*100).."%")
  139.         ecran.setCursorPos(y,x+4) --production en mb/t
  140.         ecran.write("Prod   : "..number_format(data100["gHotFluidProducedLastTick"]).." mb/t   ")
  141.         ecran.setCursorPos(y,x+5) --comsomation de yell en mb
  142.         ecran.write("Conso  : "..number_format(data100["gFuelConsumedLastTick"]))
  143.         ecran.setCursorPos(y+10,x+5)
  144.         ecran.write(" mb/t de yell")
  145.         ecran.setCursorPos(y,x+6) --temperature en C
  146.         ecran.write("temp   : "..number_format(data100["gCasingtemperature"]).." C  ")
  147.         ecran.setCursorPos(y,x+7) --reactiviter %
  148.         ecran.write("reacti : "..number_format(data100["gFuelReactivity"]).." %  ")
  149. end
  150.  
  151. function onoff()
  152. local type
  153. local a
  154.     while true do
  155.         local e, bt, xp, yp = os.pullEvent("monitor_touch")
  156.         if bt=="top" then
  157.         if (yp<8 and xp==2 ) then
  158.             type ="turbin 1" a="actif"
  159.         elseif xp>10 and xp<18 and yp==2 then
  160.             type ="turbin 1" a="engag"
  161.         elseif xp<8 and yp==9 then
  162.             type ="turbin 2" a="actif"
  163.         elseif xp>10 and xp<18 and yp==9 then
  164.             type ="turbin 1" a="engag"
  165.         --elseif xp<8 and yp==16 then
  166.         --  type ="turbin 3"
  167.         --elseif xp>27 and xp<35 and yp==2 then
  168.         --  type ="turbin 4"
  169.         --elseif xp>27 and xp<35 and yp==9 then
  170.         --  type ="turbin 5"
  171.         --elseif xp>27 and xp<35 and yp==16 then
  172.         --  type ="turbin 6"
  173.         end
  174.         rednet.broadcast(type,a)
  175.         os.sleep(0.5)
  176.         end
  177.     end
  178. end
  179.  
  180. function onoffR()
  181. local type
  182.     while true do
  183.         local e, bt, xp, yp = os.pullEvent("monitor_touch")
  184.         if bt=="monitor_8" then
  185.             if yp==2 then
  186.                 type ="reactor"
  187.             elseif yp==9  then
  188.                 type ="rod 1 +"
  189.             elseif yp==10 then
  190.                 type ="rod 2 +"
  191.             end
  192.             rednet.broadcast(type)
  193.             os.sleep(0.5)
  194.         end
  195.     end
  196. end
  197.  
  198. --crestion de rectangle de couleur
  199. function line(x ,y ,long ,larg, color_font)
  200.     ecran.setBackgroundColor(color_font)
  201.     for yp=y, y+larg-1 do
  202.         ecran.setCursorPos(x,yp)
  203.         ecran.write(string.rep(" ", long))
  204.     end
  205. end
  206.  
  207. --bar de progresion
  208. function prog(x ,y ,long ,larg, valmin, valmax ,color_bar ,color_font)
  209.     line(x ,y ,long ,larg, color_font)
  210.     local bar = math.floor((valmin/valmax)*long)
  211.     line(x ,y ,bar ,larg, color_bar)
  212. end
  213.  
  214. -- function pour transformer 9876543 en 9 876 543
  215. function number_format(n)
  216.   local test=mille(n)
  217.   if test.Mille==0 then
  218.     return math.floor(n)
  219.   else
  220.     test.Mille=mille(test.Mille)
  221.     if test.Mille.Mille==0 then
  222.       return test.Mille.Cent.." "..cent(test.Cent)
  223.     else
  224.       return test.Mille.Mille.." "..cent(test.Mille.Cent).." "..cent(test.Cent)
  225.     end
  226.   end
  227. end
  228.  
  229. -- function pour etre sur d'avoir trois chiffre (99 devient 099, 9 devient 009)
  230. function cent(n)
  231.   n=math.floor(n)
  232.   if n>99 then
  233.     return n
  234.    elseif n>9 then
  235.     return "0"..n
  236.    else
  237.     return "00"..n
  238.    end
  239. end
  240.  
  241. -- creer un objet avec les centaine d'un cotåA5A9 les millier de l'autre
  242. function mille(n)
  243.   if n<1000 then
  244.     return {Mille=0,Cent=n}
  245.   else
  246.     return {Mille=math.floor(n/1000),Cent=n%1000}
  247.   end
  248. end
  249.  
  250. parallel.waitForAll(Ecoute,Affichage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement