Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class part
- {
- public string partName;
- public int count;
- public part(string name)
- {
- this.partName = name;
- this.count = 0;
- }
- }
- class partList
- {
- public List<part> myParts;
- public partList() {
- myParts = new List<part>();
- }
- public void addNewPart(string name) {
- myParts.Add(new part(name));
- }
- public part getPart(string name) {
- for ( int i = 0; i < myParts.Count ; i++ ) {
- part myPart = myParts[i];
- if ( name.Contains(myPart.partName) ) { return myPart; }
- }
- return null;
- }
- public void increaseCount(string name,int count) {
- part myPart = getPart(name);
- if ( myPart != null ) { myPart.count += count; }
- }
- public int getPartCount(string name) {
- part myPart = getPart(name);
- if ( myPart != null ) { return myPart.count; }
- return 0;
- }
- }
- class display
- {
- public List<IMyTerminalBlock> panelList;
- public display(IMyGridTerminalSystem grid) {
- panelList = new List<IMyTerminalBlock>();
- grid.SearchBlocksOfName("Inv-Panel",panelList);
- }
- public void print(string text,bool append = false)
- {
- for ( int i = 0; i < panelList.Count; i++ ) {
- IMyTextPanel panel = (IMyTextPanel)panelList[i];
- panel.WritePublicText(text,append);
- }
- }
- public void refresh()
- {
- for ( int i = 0; i < panelList.Count; i++ ) {
- panelList[i].GetActionWithName("IncreaseFontSize").Apply(panelList[i]);
- panelList[i].GetActionWithName("DecreaseFontSize").Apply(panelList[i]);
- }
- }
- }
- public Program()
- {
- Runtime.UpdateFrequency = UpdateFrequency.Update100;
- //This makes the program automatically run every 100 ticks.
- }
- void Main(string argument)
- {
- display tPanel = new display(GridTerminalSystem);
- List<IMyTerminalBlock> containers = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocks(containers);
- partList parts = new partList();
- List<string> partNames = new List<string> ( new string[] {
- "SteelPlate",
- "Construction",
- "InteriorPlate",
- "Computer",
- "Motor",
- "SmallTube",
- "LargeTube",
- "MetalGrid",
- "Display",
- "BulletproofGlass",
- "Thrust",
- "Reactor",
- "RadioCommunication",
- "Detector",
- "SolarCell",
- "PowerCell"
- });
- for ( int i = 0; i < partNames.Count; i++ ) {
- parts.addNewPart(partNames[i]);
- }
- tPanel.print("---System Parts---\n");
- for ( int i = 0; i < containers.Count; i++ ) {
- IMyTerminalBlock block = containers[i];
- //Echo("Checking " + i);
- VRage.Game.ModAPI.Ingame.IMyInventory inventory;
- inventory = block.GetInventory(0);
- if ( block is IMyAssembler ) { inventory = block.GetInventory(1); }
- if ( inventory != null ) {
- //Echo(" Got an inventory");
- List<VRage.Game.ModAPI.Ingame.MyInventoryItem> items = new List<VRage.Game.ModAPI.Ingame.MyInventoryItem>();
- inventory.GetItems(items,null);
- for ( int i3 = 0; i3 < items.Count; i3++ ) {
- VRage.Game.ModAPI.Ingame.MyInventoryItem item = items[i3];
- string myName = item.Type.ToString();
- //Echo(" part name is " + myName);
- parts.increaseCount(myName, (int)item.Amount);
- }
- }
- }
- for ( int i = 0; i < partNames.Count; i++ ) {
- string partName = partNames[i];
- int partCount = parts.getPartCount(partName);
- tPanel.print(partName + " : " + partCount + "\n", true);
- }
- tPanel.refresh();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement