InventoryListToLcd: add components to second LCD

This commit is contained in:
2022-05-20 18:35:54 +03:00
parent 8ab8624d1a
commit bb2b677f10

View File

@@ -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<IMyTerminalBlock> containers = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyTerminalBlock>(containers, block => block.HasInventory);
// Calculate Count
Dictionary<String,int> components = new Dictionary<String,int>() {
{ "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<String,float> ingots = new Dictionary<String,float>() {
{ "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);
}