From bb2b677f10ac8058b865acc8c5946ffbd2fb5d9c Mon Sep 17 00:00:00 2001 From: Konstantin Grachev Date: Fri, 20 May 2022 18:35:54 +0300 Subject: [PATCH] InventoryListToLcd: add components to second LCD --- InventoryListToLcd.cs | 52 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/InventoryListToLcd.cs b/InventoryListToLcd.cs index f0ad546..c16a3be 100644 --- a/InventoryListToLcd.cs +++ b/InventoryListToLcd.cs @@ -10,12 +10,36 @@ public void Save() public void Main(string argument, UpdateType updateSource) { IMyTextPanel LCD = GridTerminalSystem.GetBlockWithName("Display_1") as IMyTextPanel; + IMyTextPanel LCD2 = GridTerminalSystem.GetBlockWithName("Display_2") as IMyTextPanel; List containers = new List(); GridTerminalSystem.GetBlocksOfType(containers, block => block.HasInventory); // Calculate Count + Dictionary components = new Dictionary() { + { "Construction", 0 }, + { "MetalGrid", 0 }, + { "InteriorPlate", 0 }, + { "SteelPlate", 0 }, + { "Girder", 0 }, + { "SmallTube", 0 }, + { "LargeTube", 0 }, + { "Motor", 0 }, + { "Display", 0 }, + { "BulletproofGlass", 0 }, + { "Superconductor", 0 }, + { "Computer", 0 }, + { "Reactor", 0 }, + { "Thrust", 0 }, + { "GravityGenerator", 0 }, + { "Medical", 0 }, + { "RadioCommunication", 0 }, + { "Detector", 0 }, + { "Explosives", 0 }, + { "SolarCell", 0 }, + { "PowerCell", 0 }, + }; Dictionary ingots = new Dictionary() { { "Nickel", 6 }, { "Cobalt", 5 }, @@ -32,17 +56,21 @@ public void Main(string argument, UpdateType updateSource) foreach (var container in containers) { - foreach (var ingot in ingots.Keys.ToList()) + for (int i = 0; i < container.InventoryCount; i++) { - for (int i = 0; i < container.InventoryCount; i++) + foreach (var ingot in ingots.Keys.ToList()) { ingots[ingot] += (float)container.GetInventory(i).GetItemAmount(new MyItemType("MyObjectBuilder_Ingot", ingot)); ores[ingot] += (float)container.GetInventory(i).GetItemAmount(new MyItemType("MyObjectBuilder_Ore", ingot)); } + foreach (var component in components.Keys.ToList()) + { + components[component] += (int)container.GetInventory(i).GetItemAmount(new MyItemType("MyObjectBuilder_Component", component)); + } } } - // Dispaly + // Dispaly 1 string output = " Ingots Ores\n-----------------------------------\n"; foreach (var ingot in ingots) @@ -52,4 +80,22 @@ public void Main(string argument, UpdateType updateSource) LCD.ContentType = ContentType.TEXT_AND_IMAGE; LCD.WriteText(output); + + // Dispaly 2 + string output2 = ""; + + int index = 0; + foreach (var component in components) + { + index++; + output2 += component.Key.PadRight(18) + " " + component.Value.ToString("N0").PadRight(7); + + if ((index % 2) == 0) + { + output2 += "\n"; + } + } + + LCD2.ContentType = ContentType.TEXT_AND_IMAGE; + LCD2.WriteText(output2); }