public static MyObjectBuilder_ToolbarItem ObjectBuilderFromDefinition(MyDefinitionBase defBase)
 {
     if (defBase is MyPhysicalItemDefinition)
     {
         MyObjectBuilder_ToolbarItemWeapon weaponData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemWeapon>();
         weaponData.DefinitionId = defBase.Id;
         return(weaponData);
     }
     else if (defBase is MyCubeBlockDefinition)
     {
         MyCubeBlockDefinition blockDef = defBase as MyCubeBlockDefinition;
         MyObjectBuilder_ToolbarItemCubeBlock cubeData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemCubeBlock>();
         cubeData.DefinitionId = defBase.Id;
         return(cubeData);
     }
     else if (defBase is MyAnimationDefinition)
     {
         var animData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemAnimation>();
         animData.DefinitionId = defBase.Id;
         return(animData);
     }
     else if (defBase is MyVoxelHandDefinition)
     {
         var vhData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemVoxelHand>();
         vhData.DefinitionId = defBase.Id;
         return(vhData);
     }
     else if (defBase is MyPrefabThrowerDefinition)
     {
         var ptData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemPrefabThrower>();
         ptData.DefinitionId = defBase.Id;
         return(ptData);
     }
     else if (defBase is MyBotDefinition)
     {
         var bdData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemBot>();
         bdData.DefinitionId = defBase.Id;
         return(bdData);
     }
     else if (defBase is MyAiCommandDefinition)
     {
         var acData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemAiCommand>();
         acData.DefinitionId = defBase.Id;
         return(acData);
     }
     else if (defBase.Id.TypeId == typeof(MyObjectBuilder_RopeDefinition))
     {
         var ob = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemRope>();
         ob.DefinitionId = defBase.Id;
         return(ob);
     }
     else if (defBase is MyAreaMarkerDefinition)
     {
         var acData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemAreaMarker>();
         acData.DefinitionId = defBase.Id;
         return(acData);
     }
     return(new MyObjectBuilder_ToolbarItemEmpty());
 }
Ejemplo n.º 2
0
        private void OnGridMouseOverIndexChanged(MyGuiControlGrid myGuiControlGrid, MyGuiControlGrid.EventArgs eventArgs)
        {
            if (m_gridBlocks.Visible)
            {
                MyGuiControlGrid.Item gridItem = m_gridBlocks.MouseOverItem ?? m_gridBlocks.SelectedItem;

                if (gridItem == null)
                {
                    m_blockInfoList.InitControls(new MyGuiControlBase[] { });
                    return;
                }

                GridItemUserData userData = gridItem.UserData as GridItemUserData;
                if (userData == null)
                {
                    return;
                }

                MyObjectBuilder_ToolbarItemCubeBlock itemData = userData.ItemData as MyObjectBuilder_ToolbarItemCubeBlock;
                if (itemData == null)
                {
                    return;
                }

                MyDefinitionBase definition;
                if (MyDefinitionManager.Static.TryGetDefinition(itemData.DefinitionId, out definition))
                {
                    var group = MyDefinitionManager.Static.GetDefinitionGroup((definition as MyCubeBlockDefinition).BlockPairName);

                    if (MyCubeBuilder.Static.CubeBuilderState.CubeSizeMode == MyCubeSize.Small &&
                        MyCubeBuilder.Static.IsCubeSizeAvailable(group.Small))
                    {
                        m_blockInfoList.InitControls(GenerateBlockInfos(group.Small, ref m_blockInfoStyle));
                    }
                    else if (MyCubeBuilder.Static.CubeBuilderState.CubeSizeMode == MyCubeSize.Large &&
                             MyCubeBuilder.Static.IsCubeSizeAvailable(group.Large))
                    {
                        m_blockInfoList.InitControls(GenerateBlockInfos(group.Large, ref m_blockInfoStyle));
                    }
                    else
                    {
                        bool blockSizeLarge = MyCubeBuilder.Static.CubeBuilderState.CubeSizeMode == MyCubeSize.Large;
                        m_blockInfoList.InitControls(new MyGuiControlBase[]
                        {
                            GenerateSizeInfoLabel(blockSizeLarge),
                            GenerateSizeNotAvailableText(blockSizeLarge)
                        });
                    }
                }
            }
            else
            {
                m_blockInfoList.InitControls(new MyGuiControlBase[] { });
            }
        }
Ejemplo n.º 3
0
        public static void SelectBlockToToolbar(MySlimBlock block, bool selectToNextSlot = true)
        {
            Debug.Assert(block != null && MyToolbarComponent.CurrentToolbar != null);
            MyDefinitionId blockId = block.BlockDefinition.Id;
            if (block.FatBlock is MyCompoundCubeBlock)
            {
                var compound = block.FatBlock as MyCompoundCubeBlock;
                m_cycle %= compound.GetBlocksCount();
                blockId = compound.GetBlocks()[m_cycle].BlockDefinition.Id;
                m_cycle++;
            }
            if (block.FatBlock is MyFracturedBlock)
            {
                var fracture = block.FatBlock as MyFracturedBlock;
                m_cycle %= fracture.OriginalBlocks.Count;
                blockId = fracture.OriginalBlocks[m_cycle];
                m_cycle++;
            }
            if (MyToolbarComponent.CurrentToolbar.SelectedSlot.HasValue)
            {
                int slot = MyToolbarComponent.CurrentToolbar.SelectedSlot.Value;
                if (selectToNextSlot)
                    slot++;
                if (!MyToolbarComponent.CurrentToolbar.IsValidSlot(slot))
                    slot = 0;
                var builder = new MyObjectBuilder_ToolbarItemCubeBlock();
                builder.DefinitionId = blockId;
                var item = MyToolbarItemFactory.CreateToolbarItem(builder);
                MyToolbarComponent.CurrentToolbar.SetItemAtSlot(slot, item);
            }
            else
            {
                int slot = 0;
                while (MyToolbarComponent.CurrentToolbar.GetSlotItem(slot) != null)
                    slot++;
                if (!MyToolbarComponent.CurrentToolbar.IsValidSlot(slot))
                    slot = 0;

                var builder = new MyObjectBuilder_ToolbarItemCubeBlock();
                builder.DefinitionId = blockId;
                var item = MyToolbarItemFactory.CreateToolbarItem(builder);
                MyToolbarComponent.CurrentToolbar.SetItemAtSlot(slot, item);
            }
        }
 public static MyObjectBuilder_ToolbarItem ObjectBuilderFromDefinition(MyDefinitionBase defBase)
 {
     if (defBase is MyUsableItemDefinition)
     {
         MyObjectBuilder_ToolbarItemUsable usableData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemUsable>();
         usableData.DefinitionId = defBase.Id;
         return(usableData);
     }
     else if ((defBase is MyPhysicalItemDefinition) && (defBase.Id.TypeId == typeof(MyObjectBuilder_PhysicalGunObject)))
     {
         MyObjectBuilder_ToolbarItemWeapon weaponData = null;
         // CH: TODO: This is especially ugly, I know. But it's a quick fix. To do it properly, we will need to
         // remove this whole method and construct the inventory items solely based upon factory tags on toolbar item types
         if (MyPerGameSettings.Game == GameEnum.ME_GAME)
         {
             weaponData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemMedievalWeapon>();
         }
         else
         {
             weaponData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemWeapon>();
         }
         weaponData.DefinitionId = defBase.Id;
         return(weaponData);
     }
     else if (defBase is MyCubeBlockDefinition)
     {
         MyCubeBlockDefinition blockDef = defBase as MyCubeBlockDefinition;
         MyObjectBuilder_ToolbarItemCubeBlock cubeData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemCubeBlock>();
         cubeData.DefinitionId = defBase.Id;
         return(cubeData);
     }
     else if (defBase is MyAnimationDefinition)
     {
         var animData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemAnimation>();
         animData.DefinitionId = defBase.Id;
         return(animData);
     }
     else if (defBase is MyVoxelHandDefinition)
     {
         var vhData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemVoxelHand>();
         vhData.DefinitionId = defBase.Id;
         return(vhData);
     }
     else if (defBase is MyPrefabThrowerDefinition)
     {
         var ptData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemPrefabThrower>();
         ptData.DefinitionId = defBase.Id;
         return(ptData);
     }
     else if (defBase is MyBotDefinition)
     {
         var bdData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemBot>();
         bdData.DefinitionId = defBase.Id;
         return(bdData);
     }
     else if (defBase is MyAiCommandDefinition)
     {
         var acData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemAiCommand>();
         acData.DefinitionId = defBase.Id;
         return(acData);
     }
     else if (defBase.Id.TypeId == typeof(MyObjectBuilder_RopeDefinition))
     {
         var ob = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemRope>();
         ob.DefinitionId = defBase.Id;
         return(ob);
     }
     else if (defBase is MyAreaMarkerDefinition)
     {
         var acData = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemAreaMarker>();
         acData.DefinitionId = defBase.Id;
         return(acData);
     }
     else if (defBase is MyGridCreateToolDefinition)
     {
         var gctool = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ToolbarItemCreateGrid>();
         gctool.DefinitionId = defBase.Id;
         return(gctool);
     }
     return(new MyObjectBuilder_ToolbarItemEmpty());
 }
        private void OnGridMouseOverIndexChanged(MyGuiControlGrid myGuiControlGrid, MyGuiControlGrid.EventArgs eventArgs)
        {
            if (m_gridBlocks.Visible)
            {
                MyGuiControlGrid.Item gridItem = m_gridBlocks.MouseOverItem ?? m_gridBlocks.SelectedItem;

                if (gridItem == null)
                {
                    m_blockInfoList.InitControls(new MyGuiControlBase[] { });
                    return;
                }

                GridItemUserData userData = gridItem.UserData as GridItemUserData;
                if (userData == null)
                {
                    return;
                }

                MyObjectBuilder_ToolbarItemCubeBlock itemData = userData.ItemData as MyObjectBuilder_ToolbarItemCubeBlock;
                if (itemData == null)
                {
                    return;
                }

                MyDefinitionBase definition;
                if (MyDefinitionManager.Static.TryGetDefinition(itemData.DefinitionId, out definition))
                {
                    var group = MyDefinitionManager.Static.GetDefinitionGroup((definition as MyCubeBlockDefinition).BlockPairName);

                    List <MyGuiControlBase> blockInfos = null;

                    if (group.Small != null)
                    {
                        var blockInfosSmall = GenerateBlockInfos(group.Small, ref m_blockInfoStyle);
                        if (blockInfosSmall != null)
                        {
                            if (blockInfos == null)
                            {
                                blockInfos = new List <MyGuiControlBase>();
                            }
                            blockInfos.AddArray(blockInfosSmall);
                        }
                    }

                    if (group.Large != null)
                    {
                        var blockInfosLarge = GenerateBlockInfos(group.Large, ref m_blockInfoStyle);
                        if (blockInfosLarge != null)
                        {
                            if (blockInfos == null)
                            {
                                blockInfos = new List <MyGuiControlBase>();
                            }
                            blockInfos.AddArray(blockInfosLarge);
                        }
                    }

                    if (blockInfos != null)
                    {
                        m_blockInfoList.InitControls(blockInfos);
                    }
                    else
                    {
                        m_blockInfoList.InitControls(new MyGuiControlBase[] { });
                    }

                    //else
                    //{
                    //    bool blockSizeLarge = MyCubeBuilder.Static.CubeBuilderState.CubeSizeMode == MyCubeSize.Large;
                    //    m_blockInfoList.InitControls(new MyGuiControlBase[]
                    //    {
                    //        GenerateSizeInfoLabel(blockSizeLarge),
                    //        GenerateSizeNotAvailableText(blockSizeLarge)
                    //    });
                    //}
                }
            }
            else
            {
                m_blockInfoList.InitControls(new MyGuiControlBase[] { });
            }
        }