Files
space-engineers/InventoryListToLcd.cs
2022-10-09 17:05:20 +03:00

121 lines
4.2 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,int> components = new Dictionary<String,int>() {
"Welder", "PhysicalGunObject", "WelderItem"
"Enhanced Welder", "PhysicalGunObject", "Welder2Item"
"Proficient Welder", "PhysicalGunObject", "Welder3Item"
"Elite Welder", "PhysicalGunObject", "Welder4Item"
"Grinder", "PhysicalGunObject", "AngleGrinderItem"
"Enhanced Grinder", "PhysicalGunObject", "AngleGrinder2Item"
"Proficient Grinder", "PhysicalGunObject", "AngleGrinder3Item"
"Elite Grinder", "PhysicalGunObject", "AngleGrinder4Item"
"Drill", "PhysicalGunObject", "HandDrillItem"
"Enhanced Drill", "PhysicalGunObject", "HandDrill2Item"
"Proficient Drill", "PhysicalGunObject", "HandDrill3Item"
"Elite Drill", "PhysicalGunObject", "HandDrill4Item"
"Oxygen Bottle", "OxygenContainerObject", "OxygenBottle"
"Hydrogen Bottle", "GasContainerObject", "HydrogenBottle"
"Missile Container", "AmmoMagazine", "Missile200mm"
"Ammo Container", "AmmoMagazine", "NATO_25x184mm"
"Magazine", "AmmoMagazine", "NATO_5p56x45mm"
};
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);
}