Advertisement
GauHelldragon

SE - Parts Display

Jan 6th, 2016 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.29 KB | None | 0 0
  1. class part
  2. {
  3.     public string partName;
  4.     public int count;
  5.    
  6.     public part(string name)
  7.     {
  8.         this.partName = name;
  9.         this.count = 0;
  10.     }
  11. }  
  12.  
  13. class partList
  14. {
  15.     public List<part> myParts;
  16.  
  17.     public partList() {
  18.         myParts = new List<part>();
  19.     }
  20.    
  21.     public void addNewPart(string name) {
  22.         myParts.Add(new part(name));
  23.     }
  24.    
  25.     public part getPart(string name) {
  26.         for ( int i = 0; i < myParts.Count ; i++ ) {
  27.             part myPart = myParts[i];
  28.             if ( name.Contains(myPart.partName) ) { return myPart; }
  29.            
  30.         }
  31.         return null;
  32.     }
  33.     public void increaseCount(string name,int count) {
  34.         part myPart = getPart(name);
  35.         if ( myPart != null ) { myPart.count += count; }
  36.     }
  37.     public int getPartCount(string name) {
  38.         part myPart = getPart(name);
  39.         if ( myPart != null ) { return myPart.count; }
  40.         return 0;
  41.     }
  42.  
  43. }
  44. class display
  45. {
  46.     public List<IMyTerminalBlock> panelList;
  47.    
  48.     public display(IMyGridTerminalSystem grid) {
  49.         panelList = new List<IMyTerminalBlock>();
  50.         grid.SearchBlocksOfName("Inv-Panel",panelList);
  51.     }
  52.     public void print(string text,bool append = false)
  53.     {
  54.         for ( int i = 0; i < panelList.Count; i++ ) {
  55.             IMyTextPanel panel = (IMyTextPanel)panelList[i];
  56.             panel.WritePublicText(text,append);
  57.            
  58.         }
  59.        
  60.     }
  61.     public void refresh()
  62.     {
  63.         for ( int i = 0; i < panelList.Count; i++ ) {
  64.             panelList[i].GetActionWithName("IncreaseFontSize").Apply(panelList[i]);
  65.             panelList[i].GetActionWithName("DecreaseFontSize").Apply(panelList[i]);
  66.         }
  67.     }
  68. }
  69. public Program()
  70. {
  71.     Runtime.UpdateFrequency = UpdateFrequency.Update100;
  72.     //This makes the program automatically run every 100 ticks.
  73. }
  74.    
  75. void Main(string argument)
  76. {
  77.    
  78.     display tPanel = new display(GridTerminalSystem);
  79.    
  80.     List<IMyTerminalBlock> containers = new List<IMyTerminalBlock>();
  81.     GridTerminalSystem.GetBlocks(containers);
  82.    
  83.    
  84.  
  85.     partList parts = new partList();
  86.    
  87.     List<string> partNames = new List<string> ( new string[] {
  88.         "SteelPlate",
  89.         "Construction",
  90.         "InteriorPlate",
  91.         "Computer",
  92.         "Motor",
  93.         "SmallTube",
  94.         "LargeTube",
  95.         "MetalGrid",
  96.         "Display",
  97.         "BulletproofGlass",
  98.         "Thrust",
  99.         "Reactor",
  100.         "RadioCommunication",
  101.         "Detector",
  102.         "SolarCell",
  103.         "PowerCell"
  104.     });
  105.    
  106.     for ( int i = 0; i < partNames.Count; i++ ) {
  107.         parts.addNewPart(partNames[i]);
  108.     }
  109.    
  110.     tPanel.print("---System Parts---\n");
  111.    
  112.     for ( int i = 0; i < containers.Count; i++ ) {
  113.         IMyTerminalBlock block = containers[i];
  114.         //Echo("Checking " + i);
  115.         VRage.Game.ModAPI.Ingame.IMyInventory inventory;
  116.         inventory = block.GetInventory(0);
  117.         if ( block is IMyAssembler ) { inventory = block.GetInventory(1); }
  118.  
  119.         if ( inventory != null ) {
  120.             //Echo(" Got an inventory");
  121.             List<VRage.Game.ModAPI.Ingame.MyInventoryItem> items = new List<VRage.Game.ModAPI.Ingame.MyInventoryItem>();
  122.  
  123.             inventory.GetItems(items,null);
  124.             for ( int i3 = 0; i3 < items.Count; i3++ ) {
  125.                 VRage.Game.ModAPI.Ingame.MyInventoryItem item = items[i3];
  126.                 string myName = item.Type.ToString();
  127.                 //Echo("  part name is " + myName);
  128.                 parts.increaseCount(myName, (int)item.Amount);
  129.  
  130.                
  131.             }
  132.         }
  133.  
  134.     }
  135.    
  136.     for ( int i = 0; i < partNames.Count; i++ ) {
  137.         string partName = partNames[i];
  138.         int partCount = parts.getPartCount(partName);
  139.         tPanel.print(partName + " : " + partCount + "\n", true);
  140.        
  141.     }
  142.     tPanel.refresh();
  143.  
  144. }
  145.    
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement