Morphik08

Space Engineers Corner LCD Cargo Load

Dec 21st, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. public void Main(string argument) {  
  2.     string ScreenName = "HUD1";
  3.    
  4.     string Spacing1 = "    ";
  5.     string Spacing2 = "            ";
  6.     int BarLength = 35;
  7.     string BarFill = "|";
  8.     string BarEmpty = ".";
  9.     string Bar = "[";
  10.  
  11.      
  12.  
  13.     var allCargo = new List<IMyTerminalBlock>();              
  14.     GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(allCargo, b => b.CubeGrid == Me.CubeGrid);
  15.     var PilotScreen = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(ScreenName);
  16.      
  17.     double percentFull;  
  18.     float usedVolume = 0.0f;    
  19.     float maxVolume = 0.0f;  
  20.  
  21.     allCargo.ForEach (cargo =>    
  22.     {              
  23.         usedVolume += (float)cargo.GetInventory(0).CurrentVolume;    
  24.         maxVolume += (float)cargo.GetInventory(0).MaxVolume;              
  25.     });  
  26.  
  27.     float percentUsed = usedVolume / maxVolume;
  28.     int FilledBar = (int)(BarLength * percentUsed);
  29.     percentFull = Math.Round(100 * (usedVolume / maxVolume),2);    
  30.  
  31.     for (int i = FilledBar; i > 0; i--) {
  32.     Bar += BarFill;
  33. }
  34.  
  35.     for (int i = BarLength - FilledBar; i > 0; i--) {  
  36.     Bar += BarEmpty;
  37. }
  38.  
  39.     string TextOutput = Spacing1 + Bar + "]" + "\n" + Spacing2 + "Cargo Load: " + percentFull + "%";
  40.     Echo (Spacing1 + Bar + "]" + "\n" + Spacing2 + "Cargo Load: " + percentFull + "%");
  41.     //Echo("\n    Grid Size: " + Me.CubeGrid.GridSizeEnum.ToString());
  42.  
  43.     if (PilotScreen == null)
  44.     {
  45.         Echo ("\n No LCD with name: " + ScreenName);
  46.         return;
  47.     }
  48.     else
  49.     {
  50.         PilotScreen.WritePublicText(TextOutput);
  51.         PilotScreen.ShowPublicTextOnScreen();
  52.         if (Me.CubeGrid.GridSizeEnum.ToString() == "Large")
  53.         {
  54.             PilotScreen.SetValue("FontSize", 1f);
  55.         }
  56.         if (Me.CubeGrid.GridSizeEnum.ToString() == "Small")
  57.         {
  58.             PilotScreen.SetValue("FontSize", 1.5f);
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment