Files
space-engineers/InventoryListToLcd.cs

102 lines
3.1 KiB
C#

public Program()
{
Runtime.UpdateFrequency = UpdateFrequency.Update100;
}
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 },
{ "Stone", 5 },
{ "Magnesium", 10 },
{ "Silver", 5 },
{ "Gold", 4 },
{ "Silicon", 6 },
{ "Uranium", 7},
{ "Platinum", 7 },
{ "Iron", 3 }
};
Dictionary<String,float> ores = new Dictionary<String,float>(ingots);
foreach (var container in containers)
{
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 1
string output = " Ingots Ores\n-----------------------------------\n";
foreach (var ingot in ingots)
{
output += ingot.Key.PadRight(10) + " " + ingot.Value.ToString("n2").PadRight(15) + " " + ores[ingot.Key].ToString("n2") + "\n";
}
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);
}