示例#1
0
        public static void LoadDefinition(this MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition, DictionaryReader <MyDefinitionId, int> materials, bool merge = true)
        {
            InitBlockInfo(blockInfo, definition);

            foreach (var material in materials)
            {
                var componentDefinition = MyDefinitionManager.Static.GetComponentDefinition(material.Key);
                var info = new MyHudBlockInfo.ComponentInfo();
                if (componentDefinition == null)
                {
                    MyPhysicalItemDefinition physicalDefinition = null;
                    if (!MyDefinitionManager.Static.TryGetPhysicalItemDefinition(material.Key, out physicalDefinition))
                    {
                        continue;
                    }
                    info.ComponentName = physicalDefinition.DisplayNameText;
                    info.Icon          = physicalDefinition.Icon;
                    info.DefinitionId  = physicalDefinition.Id;
                    info.TotalCount    = 1;
                }
                else
                {
                    info.DefinitionId  = componentDefinition.Id;
                    info.ComponentName = componentDefinition.DisplayNameText;
                    info.Icon          = componentDefinition.Icon;
                    info.TotalCount    = material.Value;
                }
                blockInfo.Components.Add(info);
            }

            if (merge)
            {
                MergeSameComponents(blockInfo);
            }
        }
示例#2
0
        public static void LoadDefinition(this MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition, bool merge = true)
        {
            InitBlockInfo(blockInfo, definition);

            if (definition.MultiBlock != null)
            {
                MyDefinitionId         defId         = new MyDefinitionId(typeof(MyObjectBuilder_MultiBlockDefinition), definition.MultiBlock);
                MyMultiBlockDefinition multiBlockDef = MyDefinitionManager.Static.TryGetMultiBlockDefinition(defId);
                if (multiBlockDef != null)
                {
                    foreach (var blockPart in multiBlockDef.BlockDefinitions)
                    {
                        MyCubeBlockDefinition cubeBlockDef = null;
                        MyDefinitionManager.Static.TryGetDefinition(blockPart.Id, out cubeBlockDef);
                        if (cubeBlockDef != null)
                        {
                            AddComponentsForBlock(blockInfo, cubeBlockDef);
                        }
                    }
                }
            }
            else
            {
                AddComponentsForBlock(blockInfo, definition);
            }

            if (merge)
            {
                MergeSameComponents(blockInfo);
            }
        }
 public static void InitBlockInfo(this MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition)
 {
     blockInfo.BlockName              = definition.DisplayNameText;
     blockInfo.BlockIcons             = definition.Icons;
     blockInfo.BlockIntegrity         = 0;
     blockInfo.CriticalComponentIndex = definition.CriticalGroup;
     blockInfo.CriticalIntegrity      = definition.CriticalIntegrityRatio;
     blockInfo.OwnershipIntegrity     = definition.OwnershipIntegrityRatio;
     blockInfo.MissingComponentIndex  = -1;
     blockInfo.Components.Clear();
 }
 private static void InitBlockInfo(MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition)
 {
     blockInfo.BlockName = definition.DisplayNameText;
     blockInfo.BlockIcon = definition.Icon;
     blockInfo.BlockIntegrity = 0;
     blockInfo.CriticalComponentIndex = -1;
     blockInfo.CriticalIntegrity = 0;
     blockInfo.OwnershipIntegrity = 0;
     blockInfo.MissingComponentIndex = -1;
     blockInfo.Components.Clear();
 }
示例#5
0
 private static void InitBlockInfo(MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition)
 {
     blockInfo.BlockName              = definition.DisplayNameText;
     blockInfo.BlockIcon              = definition.Icon;
     blockInfo.BlockIntegrity         = 0;
     blockInfo.CriticalComponentIndex = -1;
     blockInfo.CriticalIntegrity      = 0;
     blockInfo.OwnershipIntegrity     = 0;
     blockInfo.MissingComponentIndex  = -1;
     blockInfo.Components.Clear();
 }
示例#6
0
 public static void AddComponentsForBlock(this MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition)
 {
     for (int i = 0; i < definition.Components.Length; ++i)
     {
         var comp = definition.Components[i];
         var info = new MyHudBlockInfo.ComponentInfo();
         info.DefinitionId  = comp.Definition.Id;
         info.ComponentName = comp.Definition.DisplayNameText;
         info.Icon          = comp.Definition.Icon;
         info.TotalCount    = comp.Count;
         blockInfo.Components.Add(info);
     }
 }
 private static void AddComponentsForBlock(MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition)
 {
     for (int i = 0; i < definition.Components.Length; ++i)
     {
         var comp = definition.Components[i];
         var info = new MyHudBlockInfo.ComponentInfo();
         info.DefinitionId = comp.Definition.Id;
         info.ComponentName = comp.Definition.DisplayNameText;
         info.Icon = comp.Definition.Icon;
         info.TotalCount = comp.Count;
         blockInfo.Components.Add(info);
     }
 }
示例#8
0
 private static void MergeSameComponents(MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition)
 {
     for (int i = blockInfo.Components.Count - 1; i >= 0; i--)
     {
         for (int j = i - 1; j >= 0; j--)
         {
             if (blockInfo.Components[i].DefinitionId == blockInfo.Components[j].DefinitionId)
             {
                 var info = blockInfo.Components[j];
                 info.TotalCount        += blockInfo.Components[i].TotalCount;
                 blockInfo.Components[j] = info;
                 blockInfo.Components.RemoveAt(i);
                 break;
             }
         }
     }
 }
示例#9
0
 public static void MergeSameComponents(this MyHudBlockInfo blockInfo)
 {
     for (int i = blockInfo.Components.Count - 1; i >= 0; i--)
     {
         for (int j = i - 1; j >= 0; j--)
         {
             if (blockInfo.Components[i].DefinitionId == blockInfo.Components[j].DefinitionId)
             {
                 var info = blockInfo.Components[j];
                 info.TotalCount        += blockInfo.Components[i].TotalCount;
                 info.MountedCount      += blockInfo.Components[i].MountedCount;
                 info.StockpileCount    += blockInfo.Components[i].StockpileCount;
                 blockInfo.Components[j] = info;
                 blockInfo.Components.RemoveAt(i);
                 break;
             }
         }
     }
 }
示例#10
0
        public static void LoadDefinition(this MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition, DictionaryReader <MyDefinitionId, int> materials, bool merge = true)
        {
            InitBlockInfo(blockInfo, definition);

            foreach (var material in materials)
            {
                var componentDefinition = MyDefinitionManager.Static.GetComponentDefinition(material.Key);
                var info = new MyHudBlockInfo.ComponentInfo();
                info.DefinitionId  = componentDefinition.Id;
                info.ComponentName = componentDefinition.DisplayNameText;
                info.Icon          = componentDefinition.Icon;
                info.TotalCount    = material.Value;
                blockInfo.Components.Add(info);
            }

            if (merge)
            {
                MergeSameComponents(blockInfo, definition);
            }
        }
        public static void LoadDefinition(this MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition, bool merge = true)
        {
            blockInfo.BlockName              = definition.DisplayNameText;
            blockInfo.BlockIcon              = definition.Icon;
            blockInfo.BlockIntegrity         = 0;
            blockInfo.CriticalComponentIndex = -1;
            blockInfo.CriticalIntegrity      = 0;
            blockInfo.OwnershipIntegrity     = 0;
            blockInfo.MissingComponentIndex  = -1;

            blockInfo.Components.Clear();
            for (int i = 0; i < definition.Components.Length; ++i)
            {
                var comp = definition.Components[i];
                var info = new MyHudBlockInfo.ComponentInfo();
                info.ComponentName = comp.Definition.DisplayNameText;
                info.Icon          = comp.Definition.Icon;
                info.TotalCount    = comp.Count;
                blockInfo.Components.Add(info);
            }

            // Merge same components
            if (merge)
            {
                for (int i = definition.Components.Length - 1; i >= 0; i--)
                {
                    for (int j = i - 1; j >= 0; j--)
                    {
                        if (definition.Components[i].Definition == definition.Components[j].Definition)
                        {
                            var info = blockInfo.Components[j];
                            info.TotalCount        += blockInfo.Components[i].TotalCount;
                            blockInfo.Components[j] = info;
                            blockInfo.Components.RemoveAt(i);
                            break;
                        }
                    }
                }
            }
        }
示例#12
0
        private static void AddBlockComponent(MyHudBlockInfo hudInfo, MyComponentStack.GroupInfo groupInfo, MyInventoryBase availableInventory)
        {
            var componentInfo = new MyHudBlockInfo.ComponentInfo();
            componentInfo.DefinitionId = groupInfo.Component.Id;
            componentInfo.ComponentName = groupInfo.Component.DisplayNameText;
            componentInfo.Icons = groupInfo.Component.Icons;
            componentInfo.TotalCount = groupInfo.TotalCount;
            componentInfo.MountedCount = groupInfo.MountedCount;
            if (availableInventory != null)
                componentInfo.AvailableAmount = (int)MyCubeBuilder.BuildComponent.GetItemAmountCombined(availableInventory, groupInfo.Component.Id);

            hudInfo.Components.Add(componentInfo);
        }
示例#13
0
 private static int SetHudInfoComponentAmount(MyHudBlockInfo hudInfo, int amount, int i)
 {
     // Distribute amount in stockpile from bottom to top
     var info = hudInfo.Components[i];
     int space = info.TotalCount - info.MountedCount;
     int movedItems = Math.Min(space, amount);
     info.StockpileCount = movedItems;
     amount -= movedItems;
     hudInfo.Components[i] = info;
     return amount;
 }
示例#14
0
        // CH: TODO: This method actually doesn't have a bad internal structure, but it should be refactored BIG TIME (and put to MyHudBlockInfo)!
        private static void SetBlockComponentsInternal(MyHudBlockInfo hudInfo, MyCubeBlockDefinition blockDefinition, MySlimBlock block, MyInventoryBase availableInventory)
        {
            hudInfo.Components.Clear();

            if (block != null)
            {
                Debug.Assert(block.BlockDefinition == blockDefinition, "The definition given to SetBlockComponnentsInternal was not a definition of the block");
            }

            hudInfo.InitBlockInfo(blockDefinition);
            hudInfo.ShowAvailable = MyPerGameSettings.AlwaysShowAvailableBlocksOnHud;

            if (!MyFakes.ENABLE_SMALL_GRID_BLOCK_COMPONENT_INFO && blockDefinition.CubeSize == MyCubeSize.Small) return;

            if (block != null)
            {
                hudInfo.BlockIntegrity = block.Integrity / block.MaxIntegrity;
            }

            // CH: TODO: Multiblocks
            if (block != null && block.IsMultiBlockPart)
            {
                var multiBlockInfo = block.CubeGrid.GetMultiBlockInfo(block.MultiBlockId);
                Debug.Assert(multiBlockInfo != null);
                if (multiBlockInfo != null)
                {
                    // Load all block definition components
                    foreach (var blockDefId in multiBlockInfo.MultiBlockDefinition.BlockDefinitions) 
                    {
                        MyCubeBlockDefinition blockDef;
                        if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(blockDefId.Id, out blockDef))
                        {
                            hudInfo.AddComponentsForBlock(blockDef);
                        }
                    }

                    // Merge components from all blocks
                    hudInfo.MergeSameComponents();

                    // Add mounted counts to components
                    foreach (var multiBlockPart in multiBlockInfo.Blocks)
                    {
                        for (int j = 0; j < multiBlockPart.BlockDefinition.Components.Length; ++j)
                        {
                            var comp = multiBlockPart.BlockDefinition.Components[j];
                            var groupInfo = multiBlockPart.ComponentStack.GetGroupInfo(j);

                            for (int i = 0; i < hudInfo.Components.Count; i++)
                            {
                                if (hudInfo.Components[i].DefinitionId == comp.Definition.Id)
                                {
                                    var c = hudInfo.Components[i];
                                    c.MountedCount += groupInfo.MountedCount;
                                    hudInfo.Components[i] = c;
                                    break;
                                }
                            }
                        }
                    }

                    // Inventory counts
                    for (int i = 0; i < hudInfo.Components.Count; i++)
                    {
                        if (availableInventory != null)
                        {
                            var c = hudInfo.Components[i];
                            c.AvailableAmount = (int)MyCubeBuilder.BuildComponent.GetItemAmountCombined(availableInventory, c.DefinitionId);
                            hudInfo.Components[i] = c;
                        }

                        // Get amount in stockpile
                        int amount = 0;
                        foreach (var multiBlockPart in multiBlockInfo.Blocks)
                        {
                            if (!multiBlockPart.StockpileEmpty)
                                amount += multiBlockPart.GetConstructionStockpileItemAmount(hudInfo.Components[i].DefinitionId);
                        }

                        if (amount > 0)
                        {
                            //RKTODO: ??? see below code for non multiblocks
                            /*amount =*/ SetHudInfoComponentAmount(hudInfo, amount, i);
                        }
                    }
                }
            }
            else if (block == null && blockDefinition.MultiBlock != null)
            {
                MyDefinitionId defId = new MyDefinitionId(typeof(MyObjectBuilder_MultiBlockDefinition), blockDefinition.MultiBlock);
                var mbDefinition = MyDefinitionManager.Static.TryGetMultiBlockDefinition(defId);
                if (mbDefinition != null)
                {
                    foreach (var blockDefId in mbDefinition.BlockDefinitions)
                    {
                        MyCubeBlockDefinition blockDef;
                        if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(blockDefId.Id, out blockDef))
                        {
                            hudInfo.AddComponentsForBlock(blockDef);
                        }
                    }

                    // Merge components from all blocks
                    hudInfo.MergeSameComponents();

                    for (int i = 0; i < hudInfo.Components.Count; ++i)
                    {
                        var component = hudInfo.Components[i];
                        component.AvailableAmount = (int)MyCubeBuilder.BuildComponent.GetItemAmountCombined(availableInventory, component.DefinitionId);
                        hudInfo.Components[i] = component;
                    }
                }
            }
            else
            {
                for (int i = 0; i < blockDefinition.Components.Length; i++)
                {
                    MyComponentStack.GroupInfo groupInfo = new MyComponentStack.GroupInfo();
                    if (block != null)
                    {
                        groupInfo = block.ComponentStack.GetGroupInfo(i);
                    }
                    else
                    {
                        var component = blockDefinition.Components[i];
                        groupInfo.Component = component.Definition;
                        groupInfo.TotalCount = component.Count;
                        groupInfo.MountedCount = 0;
                        groupInfo.AvailableCount = 0;
                        groupInfo.Integrity = 0.0f;
                        groupInfo.MaxIntegrity = component.Count * component.Definition.MaxIntegrity;
                    }
                    AddBlockComponent(hudInfo, groupInfo, availableInventory);
                }

                if (block != null && !block.StockpileEmpty)
                {
                    // For each component
                    foreach (var comp in block.BlockDefinition.Components)
                    {
                        // Get amount in stockpile
                        int amount = block.GetConstructionStockpileItemAmount(comp.Definition.Id);

                        if (amount > 0)
                        {
                            for (int i = 0; i < hudInfo.Components.Count; i++)
                            {
                                if (block.ComponentStack.GetGroupInfo(i).Component == comp.Definition)
                                {
                                    if (block.ComponentStack.IsFullyDismounted)
                                    {
                                        return;
                                    }

                                    amount = SetHudInfoComponentAmount(hudInfo, amount, i);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#15
0
 public static void SetBlockComponents(MyHudBlockInfo hudInfo, MyCubeBlockDefinition blockDefinition, MyInventoryBase availableInventory = null)
 {
     SetBlockComponentsInternal(hudInfo, blockDefinition, null, availableInventory);
 }
示例#16
0
		public static void SetBlockComponents(MyHudBlockInfo hudInfo, MySlimBlock block, MyInventoryBase availableInventory = null)
		{
			hudInfo.Components.Clear();
			for (int i = 0; i < block.ComponentStack.GroupCount; i++)
			{
				var groupInfo = block.ComponentStack.GetGroupInfo(i);
				var componentInfo = new MyHudBlockInfo.ComponentInfo();
                componentInfo.DefinitionId = groupInfo.Component.Id;
				componentInfo.ComponentName = groupInfo.Component.DisplayNameText;
				componentInfo.Icon = groupInfo.Component.Icon;
				componentInfo.TotalCount = groupInfo.TotalCount;
				componentInfo.MountedCount = groupInfo.MountedCount;
				if (availableInventory != null)
					componentInfo.AvailableAmount = (int)availableInventory.GetItemAmount(groupInfo.Component.Id);

				hudInfo.Components.Add(componentInfo);
			}

			if (!block.StockpileEmpty)
			{
				// For each component
				foreach (var comp in block.BlockDefinition.Components)
				{
					// Get amount in stockpile
					int amount = block.GetConstructionStockpileItemAmount(comp.Definition.Id);

					for (int i = 0; amount > 0 && i < hudInfo.Components.Count; i++)
					{
						if (block.ComponentStack.GetGroupInfo(i).Component == comp.Definition)
						{
							if (block.ComponentStack.IsFullyDismounted)
							{
								return;
							}
							// Distribute amount in stockpile from bottom to top
							var info = hudInfo.Components[i];
							int space = info.TotalCount - info.MountedCount;
							int movedItems = Math.Min(space, amount);
							info.StockpileCount = movedItems;
							amount -= movedItems;
							hudInfo.Components[i] = info;
						}
					}
				}
			}
		}
 private static void MergeSameComponents(MyHudBlockInfo blockInfo, MyCubeBlockDefinition definition)
 {
     for (int i = blockInfo.Components.Count - 1; i >= 0; i--)
     {
         for (int j = i - 1; j >= 0; j--)
         {
             if (blockInfo.Components[i].DefinitionId == blockInfo.Components[j].DefinitionId)
             {
                 var info = blockInfo.Components[j];
                 info.TotalCount += blockInfo.Components[i].TotalCount;
                 blockInfo.Components[j] = info;
                 blockInfo.Components.RemoveAt(i);
                 break;
             }
         }
     }
 }