当前位置: 首页>>代码示例>>C#>>正文


C# MySlimBlock.GetConstructionStockpileItemAmount方法代码示例

本文整理汇总了C#中Sandbox.Game.Entities.Cube.MySlimBlock.GetConstructionStockpileItemAmount方法的典型用法代码示例。如果您正苦于以下问题:C# MySlimBlock.GetConstructionStockpileItemAmount方法的具体用法?C# MySlimBlock.GetConstructionStockpileItemAmount怎么用?C# MySlimBlock.GetConstructionStockpileItemAmount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sandbox.Game.Entities.Cube.MySlimBlock的用法示例。


在下文中一共展示了MySlimBlock.GetConstructionStockpileItemAmount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetBlockComponentsInternal

        // 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);
                        }
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:101,代码来源:MySlimBlock.cs

示例2: SetBlockComponents

		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;
						}
					}
				}
			}
		}
开发者ID:avivbeeri,项目名称:SpaceEngineers,代码行数:46,代码来源:MySlimBlock.cs


注:本文中的Sandbox.Game.Entities.Cube.MySlimBlock.GetConstructionStockpileItemAmount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。