Advertisement
Guest User

test

a guest
Jun 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.52 KB | None | 0 0
  1. --connect
  2. rednet.open("left")
  3. m = peripheral.wrap("right")
  4.  
  5. --Clear
  6. m.setTextScale(1)
  7. m.setCursorPos(1,1)
  8. m.setBackgroundColor(colors.black)
  9. m.clear()
  10.  
  11. --ID
  12. print(os.getComputerID())
  13.  
  14. --listes
  15. listes_pc = {}
  16.  
  17. --Variables
  18. pcDraw = 0
  19. page = 1
  20. pageMax = (math.floor(#listes_pc/10))+1
  21. ecran = "ecranMain"
  22. menu = false
  23.  
  24. --Function creer Objet
  25. function creePc(pId, pTable)
  26.   local pc = {}
  27.   pc.id = pId
  28.   pc.job = pTable.job
  29.   pc.etat = pTable.etat
  30.   table.insert(listes_pc, pc)
  31.   print("pc cree")
  32. end
  33.  
  34. --Function draw
  35. function drawRect(pX,pXMax,pY,pYMax,pColor)
  36.   for x = pX, pXMax do
  37.     for y = pY, pYMax do
  38.       m.setCursorPos(x,y)
  39.       m.setBackgroundColor(pColor)
  40.       m.write(" ")
  41.     end
  42.   end
  43. end
  44. function drawBarreNav()
  45.     drawRect(1,82,1,1,colors.gray)
  46.     m.setCursorPos(79,1)
  47.     m.setBackgroundColor(colors.lightGray)
  48.     m.write("home")
  49. end
  50.  
  51. function drawMenu()
  52.  
  53.   local x = 0
  54.   drawRect(1-x,20-x,1,26,colors.gray)
  55.  
  56. end
  57.  
  58. function drawMain()
  59.     drawRect(5,35,4,10,colors.red)
  60.     drawRect(45,80,4,10,colors.red)
  61.     drawRect(5,35,17,23,colors.red)
  62.     drawRect(45,80,17,23,colors.red)
  63.     m.setCursorPos(15,6)
  64.     m.write("PC CONNECTE")
  65. end
  66.  
  67. function drawPcCo()
  68. --    print("page = "..page.." pageMax = ".. pageMax)
  69.     m.setBackgroundColor(colors.black)
  70.     m.setCursorPos(1,2)
  71.     m.write("ID")
  72.     m.setCursorPos(9,2)
  73.     m.write("|")
  74.     m.setCursorPos(10,2)
  75.     m.write("Job")
  76.     m.setCursorPos(20,2)
  77.     m.write("|")
  78.     m.setCursorPos(21,2)
  79.     m.write("Etat")
  80.     m.setCursorPos(30,2)
  81.     m.write("|")
  82.     m.setCursorPos(40,2)
  83.     m.write("|")
  84.     m.setCursorPos(50,2)
  85.     m.write("|")
  86.     m.setCursorPos(60,2)
  87.     m.write("|")
  88.     m.setCursorPos(70,2)
  89.     m.write("|")
  90.     m.setCursorPos(71,2)
  91.     m.write("Delete")
  92.  
  93.     for n = 1,10 do
  94.       m.setCursorPos(1,(n*2)+1)
  95.       m.write("----------------------------------------------------------------------------------")
  96.       m.setCursorPos(9,(n*2)+2)
  97.       m.write("|")
  98.       m.setCursorPos(20,(n*2)+2)
  99.       m.write("|")
  100.       m.setCursorPos(30,(n*2)+2)
  101.       m.write("|")
  102.       m.setCursorPos(40,(n*2)+2)
  103.       m.write("|")
  104.       m.setCursorPos(50,(n*2)+2)
  105.       m.write("|")
  106.       m.setCursorPos(60,(n*2)+2)
  107.       m.write("|")
  108.       m.setCursorPos(70,(n*2)+2)
  109.       m.write("|")
  110.     end
  111.    
  112.     if page == pageMax then
  113.      
  114.       pcDraw = #listes_pc-(page-1)*10
  115.       for n = 1, pcDraw do
  116.         local i = n + (pageMax-1)*10
  117.         m.setCursorPos(1,(n*2)+2)
  118.         m.write(listes_pc[i].id)
  119.         m.setCursorPos(10,(n*2)+2)
  120.         m.write(listes_pc[i].job)
  121.         m.setCursorPos(21,(n*2)+2)
  122.         m.write(listes_pc[i].etat)
  123.         m.setCursorPos(71,(n*2)+2)
  124.         m.setBackgroundColor(colors.red)
  125.         m.write(" x ")
  126.         m.setBackgroundColor(colors.black)
  127.       end
  128.      
  129.     else
  130.      
  131.     end
  132.    
  133.     m.setBackgroundColor(colors.lightGray)
  134.     m.setCursorPos(1,26)
  135.     m.write("<=")
  136.     m.setBackgroundColor(colors.black)
  137.     m.setCursorPos(40,26)
  138.     m.write(page.."/"..pageMax)
  139.     m.setBackgroundColor(colors.lightGray)
  140.     m.setCursorPos(81,26)
  141.     m.write("=>")
  142.     m.setBackgroundColor(colors.black)
  143.    
  144. end
  145.  
  146. local id = os.getComputerID()
  147. local t = {
  148.   job = "Moniteur",
  149.   etat = "actif"
  150. }
  151. creePc(id,t)
  152.  
  153. while true do
  154.    
  155.     --Draw
  156.     m.setBackgroundColor(colors.black)
  157.     m.clear()
  158.     drawBarreNav()
  159.     if menu == true then
  160.       drawMenu()    
  161.     else
  162.       m.setCursorPos(1,1)
  163.       m.setBackgroundColor(colors.lightGray)
  164.       m.write("menu")    
  165.     end
  166.     if ecran == "ecranMain" then
  167.         drawMain()
  168.     end
  169.     if ecran == "ecranPcCo" then
  170.         drawPcCo()
  171.     end
  172.    
  173.     local event, e1, e2, e3 = os.pullEvent()
  174.    
  175.     --event rednet
  176.     if event == "rednet_message" then
  177.         local id,msg = e1, e2
  178.         local table = textutils.unserialize(msg)
  179.         local test = true
  180.        
  181.         for n = 1, #listes_pc do
  182.           print(n .. " " .. listes_pc[n].id)
  183.          
  184.           if id == listes_pc[n].id then
  185.             test = false
  186.             print("test = false")
  187.             break
  188.           end
  189.         end
  190.         if test == true then
  191.           creePc(id, table)
  192.         end
  193.        
  194.     end
  195.     --event monitor
  196.     if event == "monitor_touch" then
  197.         local x,y = e2,e3
  198.         if x >= 79 and x <= 82 then
  199.             if y >= 1 and y <= 1 then
  200.                 ecran = "ecranMain"    
  201.             end
  202.         end
  203.         --MainMenu
  204.         if ecran == "ecranMain" then
  205.             --Bouton Haut Gauche
  206.             if x >= 5 and x <= 35 then
  207.                 if y >= 4 and y <= 10 then
  208.                    ecran = "ecranPcCo"
  209.                 end
  210.             end
  211.             --Bouton Haut Droite
  212.             if x >= 45 and x <=75 then
  213.                 if y >= 4 and y <= 10 then
  214.                    
  215.                 end
  216.             end
  217.             --Bouton bas gauche
  218.             if x >= 5 and x <= 35 then
  219.                 if y >= 17 and y <= 23 then
  220.                    
  221.                 end
  222.             end
  223.             --Bouton bas droite
  224.             if x >= 45 and x <= 75 then
  225.                 if y >= 17 and y <= 23 then
  226.                    
  227.                 end
  228.             end
  229.         end
  230.         if ecran == "ecranPcCo" then
  231.          
  232.           --Boutons delete
  233.           for n = 1, pcDraw do
  234.          
  235.             if x >= 71 and x <= 73 then
  236.               if y >= (n*2)+2 and y <= (n*2)+3 then
  237.                 local i = n + (page-1)*10
  238.                 if i ~= 1 then
  239.                   rednet.send(listes_pc[i].id, "break")
  240.                   table.remove(listes_pc,i)
  241.                 end
  242.               end
  243.             end
  244.          
  245.           end    
  246.          
  247.           --Bouton page-
  248.           if x >= 1 and x <= 2 then
  249.             if y >= 26 and y <= 27 then
  250.               if page ~= 1 then
  251.                 page = page - 1
  252.               end
  253.             end
  254.           end
  255.          
  256.           --Bouton page+
  257.           if x >= 81 and x <= 82 then
  258.             if y >= 26 and y <= 27 then
  259.               if page ~= pageMax then
  260.                 page = page + 1
  261.               end
  262.             end
  263.           end                                            
  264.                                                        
  265.         end
  266.     end
  267.     --event key
  268.     if event == "key" then
  269.       local key = e1
  270.       if ecran == "ecranMain" then
  271.            
  272.       end
  273.       if ecran == "ecranPcCo" then
  274.                    
  275.       end
  276.     end
  277.    
  278.    
  279. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement