Morphik08

Space Engineers: Group Cargo Display with Images V.2

Jul 6th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.73 KB | None | 0 0
  1. void Main()    
  2. {    
  3.     // What the cargo cans' custom names need to start with.    
  4.     string groupName = "Cargo";    
  5.      
  6.     // What the graph LCD's custom name needs to be.    
  7.     string lcdName = "LCD";    
  8.      
  9.     // I don't want to type GridTerminalSystem.BlockGroups a lot, so let's save it to a variable.    
  10.     var groups = GridTerminalSystem.BlockGroups;    
  11.      
  12.     // This will be the group we actually want. We don't have a value to start it off with, so we set it to "null".    
  13.     IMyBlockGroup myGroup = null;    
  14.      
  15.     // Find the group we want.    
  16.     for(int i=0; i<groups.Count; i++) {    
  17.         if(groups[i].Name == groupName) {    
  18.         myGroup = groups[i];    
  19.         }    
  20.     }
  21.  
  22.     if (myGroup == null) throw new Exception("Cargo Group not found, check name");    
  23.      
  24.     // This list will hold all the cargo containers we actually want.    
  25.     List<IMyTerminalBlock> blocks = myGroup.Blocks;    
  26.      
  27.     // The total amount of space used    
  28.     float usedVolume = 0.0f;    
  29.      
  30.     // The total capacity of the cargo cans    
  31.     float maxVolume = 0.0f;    
  32.      
  33.     // Count the total space used and the total capacity of the cargo cans    
  34.     for(int i=0; i<blocks.Count; i++) {    
  35.         var b = blocks[i];    
  36.         usedVolume += (float)b.GetInventory(0).CurrentVolume;    
  37.         maxVolume += (float)b.GetInventory(0).MaxVolume;    
  38.     }    
  39.      
  40.     // Find the LCD for the summary graph  
  41.     var lcd = GridTerminalSystem.GetBlockWithName(lcdName) as IMyTextPanel;  
  42.  
  43.     if (lcd == null) throw new Exception("LCD block not found, check name");
  44.      
  45.     if (lcd != null) {      
  46.     int index = (int)(20.0f * usedVolume / maxVolume);
  47.     lcd.ClearImagesFromSelection();
  48.     switch (index) {
  49.         case 0:
  50.             lcd.AddImageToSelection("Percent 000");
  51.             break;
  52.         case 1:
  53.             lcd.AddImageToSelection("Percent 005");
  54.             break;
  55.         case 2:
  56.             lcd.AddImageToSelection("Percent 010");
  57.             break;
  58.         case 3:
  59.             lcd.AddImageToSelection("Percent 015");
  60.             break;
  61.         case 4:
  62.             lcd.AddImageToSelection("Percent 020");
  63.             break;
  64.         case 5:
  65.             lcd.AddImageToSelection("Percent 025");
  66.             break;
  67.         case 6:
  68.             lcd.AddImageToSelection("Percent 030");
  69.             break;
  70.         case 7:
  71.             lcd.AddImageToSelection("Percent 035");
  72.             break;
  73.         case 8:    
  74.             lcd.AddImageToSelection("Percent 040");
  75.             break;
  76.         case 9:
  77.             lcd.AddImageToSelection("Percent 045");
  78.             break;
  79.         case 10:
  80.             lcd.AddImageToSelection("Percent 050");
  81.             break;
  82.         case 11:
  83.             lcd.AddImageToSelection("Percent 055");
  84.             break;
  85.         case 12:
  86.             lcd.AddImageToSelection("Percent 060");
  87.             break;
  88.         case 13:
  89.             lcd.AddImageToSelection("Percent 065");
  90.             break;
  91.         case 14:
  92.             lcd.AddImageToSelection("Percent 070");
  93.             break;
  94.         case 15:
  95.             lcd.AddImageToSelection("Percent 075");
  96.             break;
  97.         case 16:
  98.             lcd.AddImageToSelection("Percent 080");
  99.             break;
  100.         case 17:
  101.             lcd.AddImageToSelection("Percent 085");
  102.             break;
  103.         case 18:
  104.             lcd.AddImageToSelection("Percent 090");
  105.             break;
  106.         case 19:
  107.             lcd.AddImageToSelection("Percent 095");
  108.             break;
  109.         case 20:
  110.             lcd.AddImageToSelection("Percent 100");
  111.             break;
  112.     }
  113.      
  114.     }    
  115. }
Advertisement
Add Comment
Please, Sign In to add comment