Ejemplo n.º 1
0
        public static MyToolbarItem ToItem(ToolbarItem msgItem)
        {
            MyToolbarItem item = null;

            if (msgItem.GunId.HasValue)
            {
                MyObjectBuilder_ToolbarItemWeapon builder = MyToolbarItemFactory.WeaponObjectBuilder();
                builder.defId = msgItem.GunId.Value;
                item          = MyToolbarItemFactory.CreateToolbarItem(builder);
            }
            else if (string.IsNullOrEmpty(msgItem.GroupName))
            {
                MyTerminalBlock block;
                if (MyEntities.TryGetEntityById(msgItem.EntityID, out block))
                {
                    var builder = MyToolbarItemFactory.TerminalBlockObjectBuilderFromBlock(block);
                    builder._Action    = msgItem.Action;
                    builder.Parameters = msgItem.Parameters;
                    item = MyToolbarItemFactory.CreateToolbarItem(builder);
                }
            }
            else
            {
                MyCubeBlock parent;
                if (MyEntities.TryGetEntityById(msgItem.EntityID, out parent))
                {
                    var grid      = parent.CubeGrid;
                    var groupName = msgItem.GroupName;
                    var group     = grid.GridSystems.TerminalSystem.BlockGroups.Find(x => x.Name.ToString() == groupName);
                    if (group != null)
                    {
                        var builder = MyToolbarItemFactory.TerminalGroupObjectBuilderFromGroup(@group);
                        builder._Action       = msgItem.Action;
                        builder.Parameters    = msgItem.Parameters;
                        builder.BlockEntityId = msgItem.EntityID;
                        item = MyToolbarItemFactory.CreateToolbarItem(builder);
                    }
                }
            }
            return(item);
        }
Ejemplo n.º 2
0
        public static MyToolbarItem ToItem(ToolbarItem msgItem)
        {
            MyToolbarItem item = null;

            if (msgItem.GunId != null)
            {
                MyObjectBuilder_ToolbarItemWeapon data = MyToolbarItemFactory.WeaponObjectBuilder();
                data.defId = msgItem.GunId.Value;
                item       = MyToolbarItemFactory.CreateToolbarItem(data);
            }
            else if (string.IsNullOrEmpty(msgItem.GroupName))
            {
                MyTerminalBlock block;
                if (Sandbox.Game.Entities.MyEntities.TryGetEntityById <MyTerminalBlock>(msgItem.EntityID, out block, false))
                {
                    MyObjectBuilder_ToolbarItemTerminalBlock data = MyToolbarItemFactory.TerminalBlockObjectBuilderFromBlock(block);
                    data._Action    = msgItem.Action;
                    data.Parameters = msgItem.Parameters;
                    item            = MyToolbarItemFactory.CreateToolbarItem(data);
                }
            }
            else
            {
                MyCubeBlock block2;
                if (Sandbox.Game.Entities.MyEntities.TryGetEntityById <MyCubeBlock>(msgItem.EntityID, out block2, false))
                {
                    string       groupName = msgItem.GroupName;
                    MyBlockGroup group     = block2.CubeGrid.GridSystems.TerminalSystem.BlockGroups.Find(x => x.Name.ToString() == groupName);
                    if (group != null)
                    {
                        MyObjectBuilder_ToolbarItemTerminalGroup data = MyToolbarItemFactory.TerminalGroupObjectBuilderFromGroup(group);
                        data._Action       = msgItem.Action;
                        data.Parameters    = msgItem.Parameters;
                        data.BlockEntityId = msgItem.EntityID;
                        item = MyToolbarItemFactory.CreateToolbarItem(data);
                    }
                }
            }
            return(item);
        }