コード例 #1
0
        public MyTomasInputComponent()
        {
            AddShortcut(MyKeys.Delete, true, true, false, false,
                        () => "Delete all characters",
                        delegate
            {
                foreach (var obj in MyEntities.GetEntities().OfType <MyCharacter>())
                {
                    if (obj == MySession.ControlledEntity)
                    {
                        MySession.SetCameraController(MyCameraControllerEnum.Spectator);
                    }
                    obj.Close();
                }

                foreach (var obj in MyEntities.GetEntities().OfType <MyCubeGrid>())
                {
                    foreach (var obj2 in obj.GetBlocks())
                    {
                        if (obj2.FatBlock is MyCockpit)
                        {
                            var cockpit = obj2.FatBlock as MyCockpit;
                            if (cockpit.Pilot != null)
                            {
                                cockpit.Pilot.Close();
                            }
                        }
                    }
                }
                return(true);
            });

            AddShortcut(MyKeys.NumPad4, true, false, false, false,
                        () => "Spawn cargo ship or barbarians",
                        delegate
            {
                var theEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "SpawnCargoShip"));
                if (theEvent == null)
                {
                    theEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "SpawnBarbarians"));
                }
                if (theEvent != null)
                {
                    MyGlobalEvents.RemoveGlobalEvent(theEvent);
                    theEvent.SetActivationTime(TimeSpan.FromSeconds(1));
                    MyGlobalEvents.AddGlobalEvent(theEvent);
                }
                return(true);
            });

            AddShortcut(MyKeys.NumPad5, true, false, false, false,
                        () => "Spawn random meteor",
                        delegate
            {
                var camera        = MySector.MainCamera;
                var target        = camera.Position + MySector.MainCamera.ForwardVector * 20.0f;
                var spawnPosition = target + MySector.DirectionToSunNormalized * 1000.0f;

                if (MyUtils.GetRandomFloat(0.0f, 1.0f) < 0.2f)
                {
                    MyMeteor.SpawnRandomLarge(spawnPosition, -MySector.DirectionToSunNormalized);
                }
                else
                {
                    MyMeteor.SpawnRandomSmall(spawnPosition, -MySector.DirectionToSunNormalized);
                }
                return(true);
            });

            AddShortcut(MyKeys.NumPad8, true, false, false, false,
                        () => "Switch control to next entity",
                        delegate
            {
                if (MySession.ControlledEntity != null)
                { //we already are controlling this object
                    var cameraController = MySession.GetCameraControllerEnum();
                    if (cameraController != MyCameraControllerEnum.Entity && cameraController != MyCameraControllerEnum.ThirdPersonSpectator)
                    {
                        MySession.SetCameraController(MyCameraControllerEnum.Entity, MySession.ControlledEntity.Entity);
                    }
                    else
                    {
                        var entities       = MyEntities.GetEntities().ToList();
                        int lastKnownIndex = entities.IndexOf(MySession.ControlledEntity.Entity);

                        var entitiesList = new List <MyEntity>();
                        if (lastKnownIndex + 1 < entities.Count)
                        {
                            entitiesList.AddRange(entities.GetRange(lastKnownIndex + 1, entities.Count - lastKnownIndex - 1));
                        }

                        if (lastKnownIndex != -1)
                        {
                            entitiesList.AddRange(entities.GetRange(0, lastKnownIndex + 1));
                        }

                        MyCharacter newControlledObject = null;

                        for (int i = 0; i < entitiesList.Count; i++)
                        {
                            var character = entitiesList[i] as MyCharacter;
                            if (character != null)
                            {
                                newControlledObject = character;
                                break;
                            }
                        }

                        if (newControlledObject != null)
                        {
                            MySession.LocalHumanPlayer.Controller.TakeControl(newControlledObject);
                        }
                    }
                }

                return(true);
            });


            AddShortcut(MyKeys.NumPad7, true, false, false, false,
                        () => "Use next ship",
                        delegate
            {
                MyCharacterInputComponent.UseNextShip();
                return(true);
            });

            AddShortcut(MyKeys.NumPad9, true, false, false, false,
                        () => "Debug new grid screen",
                        delegate
            {
                MyGuiSandbox.AddScreen(new DebugNewGridScreen());
                return(true);
            });

            AddShortcut(MyKeys.N, true, false, false, false,
                        () => "Refill all batteries",
                        delegate
            {
                foreach (var entity in MyEntities.GetEntities())
                {
                    MyCubeGrid grid = entity as MyCubeGrid;
                    if (grid != null)
                    {
                        foreach (var block in grid.GetBlocks())
                        {
                            MyBatteryBlock battery = block.FatBlock as MyBatteryBlock;
                            if (battery != null)
                            {
                                battery.CurrentStoredPower = battery.MaxStoredPower;
                            }
                        }
                    }
                }
                return(true);
            });

            AddShortcut(MyKeys.U, true, false, false, false,
                        () => "Spawn new character",
                        delegate
            {
                var character = MyCharacterInputComponent.SpawnCharacter();
                return(true);
            });


            AddShortcut(MyKeys.NumPad2, true, false, false, false,
                        () => "Merge static grids",
                        delegate
            {
                // Try to merge all static large grids
                HashSet <MyCubeGrid> ignoredGrids = new HashSet <MyCubeGrid>();
                while (true)
                {
                    // Flag that we need new entities enumeration
                    bool needNewEntitites = false;

                    foreach (var entity in MyEntities.GetEntities())
                    {
                        MyCubeGrid grid = entity as MyCubeGrid;
                        if (grid != null && grid.IsStatic && grid.GridSizeEnum == MyCubeSize.Large)
                        {
                            if (ignoredGrids.Contains(grid))
                            {
                                continue;
                            }

                            List <MySlimBlock> blocks = grid.GetBlocks().ToList();
                            foreach (var block in blocks)
                            {
                                var mergedGrid = grid.DetectMerge(block);
                                if (mergedGrid == null)
                                {
                                    continue;
                                }

                                needNewEntitites = true;
                                // Grid merged to other grid? Then break and loop all entities again.
                                if (mergedGrid != grid)
                                {
                                    break;
                                }
                            }

                            if (!needNewEntitites)
                            {
                                ignoredGrids.Add(grid);
                            }
                        }

                        if (needNewEntitites)
                        {
                            break;
                        }
                    }

                    if (!needNewEntitites)
                    {
                        break;
                    }
                }
                return(true);
            });

            AddShortcut(MyKeys.Add, true, false, false, false,
                        () => "Increase wheel animation speed",
                        delegate
            {
                USE_WHEEL_ANIMATION_SPEED += 0.05f;
                return(true);
            });

            AddShortcut(MyKeys.Subtract, true, false, false, false,
                        () => "Decrease wheel animation speed",
                        delegate
            {
                USE_WHEEL_ANIMATION_SPEED -= 0.05f;
                return(true);
            });

            AddShortcut(MyKeys.Divide, true, false, false, false,
                        () => "Show model texture names",
                        delegate
            {
                MyFakes.ENABLE_DEBUG_DRAW_TEXTURE_NAMES = !MyFakes.ENABLE_DEBUG_DRAW_TEXTURE_NAMES;
                return(true);
            });

            AddShortcut(MyKeys.NumPad1, true, false, false, false,
                        () => "Throw from spectator: " + Sandbox.Game.Components.MySessionComponentThrower.USE_SPECTATOR_FOR_THROW,
                        delegate
            {
                Sandbox.Game.Components.MySessionComponentThrower.USE_SPECTATOR_FOR_THROW = !Sandbox.Game.Components.MySessionComponentThrower.USE_SPECTATOR_FOR_THROW;
                return(true);
            });

            AddShortcut(MyKeys.F2, true, false, false, false, () => "Spectator to next small grid", () => SpectatorToNextGrid(MyCubeSize.Small));
            AddShortcut(MyKeys.F3, true, false, false, false, () => "Spectator to next large grid", () => SpectatorToNextGrid(MyCubeSize.Large));
        }