public void Update(MyDebugSystem system, MyGuiInput input) { input.GetPressedKeys(m_pressedKeys); short modifier = 0; if (input.IsAnyAltKeyPressed()) modifier |= (short)MyShortcut.ModifierValue.Alt; if (input.IsAnyShiftKeyPressed()) modifier |= (short)MyShortcut.ModifierValue.Shift; if (input.IsAnyCtrlKeyPressed()) modifier |= (short)MyShortcut.ModifierValue.Control; foreach(Keys k in m_pressedKeys) { var key = (Keys)k; if (key == Keys.LeftAlt || key == Keys.RightAlt || key == Keys.LeftShift || key == Keys.RightShift || key == Keys.LeftControl || key == Keys.RightControl) continue; if (input.IsNewKeyPress(key)) OnKeyPressed(system, key, modifier); } }
// This method is called every update (but only if application has focus) public override void HandleUnhandledInput(MyGuiInput input, bool receivedFocusInThisUpdate) { // This is protection against situation when user clicks on CONTINUE in menu, but don't release the button quickly, so in gameplay screen // it continues with shoting. So in this case he must release buttons and then press again if he want to shot. if (m_handleInputMouseKeysReleased == false) { if ((input.IsLeftMouseReleased()) && (input.IsRightMouseReleased())) { m_handleInputMouseKeysReleased = true; } } //Set if ammo select menu or config menu is enable m_selectAmmoMenu.IsEnabled = !m_wheelControlMenu.Visible && IsControlledPlayerShip; m_wheelControlMenu.IsEnable = !m_selectAmmoMenu.Visible && IsControlledPlayerShip; if (IsControlledPlayerShip && !m_selectAmmoMenu.IsEnabled && !m_wheelControlMenu.IsEnable) { m_selectAmmoMenu.IsEnabled = true; } // Launch main menu if (!m_wheelControlMenu.Visible && !IsSelectAmmoVisible() && input.IsNewKeyPress(Keys.Escape) && !(IsEditorActive() && (EditorControls.TryExitSelected() || EditorControls.TryExitSelectionMode()))) { MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick); //Allow changing video options from game in DX version MyGuiScreenMainMenu.AddMainMenu(true); //MyGuiScreenMainMenu.AddMainMenu(false); DrawHud = false; MySystemTimer.SetMinimalResolution(); } MyHudSectorBorder.SwitchToDraw(); // Switch from player ship to ingame editor and back if (IsGameActive() || IsEditorActive()) { if (!input.IsAnyAltPress()) { if ((input.IsNewKeyPress(Keys.NumPad0) || input.IsNewKeyPress(Keys.D0)) && (GetSessionType() == MyMwcStartSessionRequestTypeEnum.EDITOR_STORY || GetSessionType() == MyMwcStartSessionRequestTypeEnum.EDITOR_SANDBOX || GetSessionType() == MyMwcStartSessionRequestTypeEnum.EDITOR_MMO)) { ReturnControlToPlayerShip(); m_invokeGameEditorSwitch = true; } } } if (CameraAttachedTo == MyCameraAttachedToEnum.PlayerMinerShip_ThirdPersonFollowing) { if (input.PreviousMouseScrollWheelValue() < input.MouseScrollWheelValue()) { ThirdPersonCameraDelta /= 1.1f; } else if (input.PreviousMouseScrollWheelValue() > input.MouseScrollWheelValue()) { ThirdPersonCameraDelta *= 1.1f; } } if (CameraAttachedTo == MyCameraAttachedToEnum.Spectator) { if (input.PreviousMouseScrollWheelValue() < input.MouseScrollWheelValue()) { MySpectator.SpeedMode = Math.Min(MySpectator.SpeedMode * 1.5f, MyEditorConstants.MAX_EDITOR_CAMERA_MOVE_MULTIPLIER); } else if (input.PreviousMouseScrollWheelValue() > input.MouseScrollWheelValue()) { MySpectator.SpeedMode = Math.Max(MySpectator.SpeedMode / 1.5f, MyEditorConstants.MIN_EDITOR_CAMERA_MOVE_MULTIPLIER); } } if (CameraAttachedTo == MyCameraAttachedToEnum.PlayerMinerShip_ThirdPersonDynamic && !m_wheelControlMenu.Visible && !IsSelectAmmoVisible()) // don't zoom if wheel or ammo menu is visible { float distance = MyThirdPersonSpectator.LookAt.Length(); float currentDistance = (MyThirdPersonSpectator.Target - MyThirdPersonSpectator.DesiredPosition).Length(); float newDistance = 0; if (input.PreviousMouseScrollWheelValue() < input.MouseScrollWheelValue()) { newDistance = currentDistance / 1.2f; } else if (input.PreviousMouseScrollWheelValue() > input.MouseScrollWheelValue()) { newDistance = distance * 1.2f; } if (newDistance > 0) { // Limit distance from ship newDistance = MathHelper.Clamp(newDistance, MyThirdPersonSpectator.GetMinDistance(), MyThirdPersonSpectator.MAX_DISTANCE); MyThirdPersonSpectator.LookAt *= newDistance / distance; } //MyThirdPersonSpectator.LookAt = new Vector3(0, 130, 65); } #region Universal developer keys if (MyGuiInput.ENABLE_DEVELOPER_KEYS) { if (input.IsNewKeyPress(Keys.Multiply)) { //MyHudNotification.AddNotification(new MyHudNotification.MyNotification("Searching for most complex region..." , 3000)); //int[] res = MyEntities.getMostComplexCameraView(128); //MyHudNotification.AddNotification(new MyHudNotification.MyNotification("X " + res[0] + " Y" + res[1] + " Z" + res[2], 3000)); //MyEntities.getMostComplexCameraView(128); } //if (MyFakes.ENABLE_MULTIPLAYER && input.IsAnyShiftKeyPressed() && input.IsNewKeyPress(Keys.PageUp)) //{ // MyMultiplayer.HostGame(null); // MyMultiplayer.Static.OnNotification = new Action<MyTextsWrapperEnum, object[]>(Static_OnNotification); //} if (MyMwcFinalBuildConstants.IS_DEVELOP && input.IsNewKeyPress(Keys.F5) && input.IsAnyCtrlKeyPressed()) { MySession.Static.SaveLastCheckpoint(false); } // Show sector border if (MyMwcFinalBuildConstants.IS_DEVELOP && input.IsNewKeyPress(Keys.U)) { if (MyFakes.MWBUILDER) { if (input.IsAnyShiftKeyPressed()) { MyEditorGrid.SwitchGridOrientation(); } else { MyEditorGrid.IsGridActive = !MyEditorGrid.IsGridActive; } } else { MyHudSectorBorder.SwitchSectorBorderVisibility(); } } if (MyMwcFinalBuildConstants.ENABLE_TRAILER_SAVE && (MyGuiScreenGamePlay.Static.IsGameActive() || MyGuiScreenGamePlay.Static.IsEditorActive())) // Trailer controls { //if (input.IsKeyPress(Keys.NumPad5) && input.IsAnyShiftKeyPressed()) // SHIFT + Num5 - Set trailer start position //{ // MyHudNotification.AddNotification(new MyHudNotification.MyNotification("Trailer start set", 5)); // trailerStartPosition = MySession.PlayerShip.WorldMatrix; //} if (input.IsNewKeyPress(Keys.NumPad5) && !input.IsAnyShiftKeyPressed()) // Num5 - Restart & record... { RestartTrailer(false, false); } if (input.IsNewKeyPress(Keys.NumPad7) && !input.IsAnyShiftKeyPressed()) // Num7 - Restart & teleport & record... { RestartTrailer(false, true); //var translation = Matrix.CreateTranslation(MySession.PlayerShip.WorldMatrix.Translation + MyMwcUtils.Normalize(MySession.PlayerShip.WorldMatrix.Backward) * 10); //MySession.PlayerShip.WorldMatrix *= translation; } if (input.IsNewKeyPress(Keys.NumPad9) && !input.IsAnyShiftKeyPressed()) // Num9 - Restart save & record... { RestartTrailer(true, true); } } if (input.IsNewKeyPress(Keys.S) && input.IsAnyAltKeyPressed() && input.IsAnyCtrlKeyPressed()) { MyEditor.SaveSelectedVoxelMap(input.IsAnyShiftKeyPressed()); } if (input.IsNewKeyPress(Keys.Delete) && input.IsAnyCtrlKeyPressed()) { if (MyMissions.ActiveMission != null) { MyObjective.SkipSubmission = true; } } if (input.IsNewKeyPress(Keys.End) && input.IsAnyCtrlKeyPressed()) { if (MyMissions.ActiveMission != null && MyMissions.ActiveMission.ActiveObjectives.Count > 0) { var entityId = MyMissions.ActiveMission.ActiveObjectives[0].Location.LocationEntityIdentifier.LocationEntityId; MyEntity entity; if (entityId.HasValue && MyEntities.TryGetEntityById(entityId.ToEntityId().Value, out entity)) { MySession.PlayerShip.SetPosition(entity.GetPosition()); } } else { MyEntity entity; //if (MyEntities.TryGetEntityByName(MyMissionBase.MyMissionLocation.MADELYN_HANGAR, out entity)) if (MyEntities.TryGetEntityByName("Madelyn", out entity)) { MySession.PlayerShip.SetPosition(entity.GetPosition()); } } } if (input.IsNewKeyPress(Keys.OemTilde) && input.IsAnyCtrlKeyPressed()) { var ship = MySession.Static.Player.Ship as MySmallShip; ship.DoDamage(1000, 1000, 0, MyDamageType.Explosion, MyAmmoType.Unknown, null); MySession.Static.Player.AddHealth(-MySession.Static.Player.Health, null); } if ((input.IsNewKeyPress(Keys.OemBackslash) || input.IsNewKeyPress(Keys.OemPipe)) && input.IsAnyShiftKeyPressed()) { MyLine line = new MyLine(MyCamera.Position, MyCamera.Position + MyCamera.ForwardVector * 25000, false); var intersection = MyEntities.GetIntersectionWithLine(ref line, MySession.Static.Player.Ship, null, true); if (intersection.HasValue) { var target = intersection.Value.IntersectionPointInWorldSpace; target -= MyCamera.ForwardVector * MySession.Static.Player.Ship.LocalVolume.Radius * 20; MySession.Static.Player.Ship.SetPosition(target); } } if (input.IsNewKeyPress(Keys.NumLock)) { var player = MySession.Static.Player; player.RestoreHealth(); var ship = MySession.Static.Player.Ship as MySmallShip; if (ship != null) { ship.AddHealth(ship.MaxHealth); ship.ArmorHealth = ship.MaxArmorHealth; ship.Oxygen = ship.MaxOxygen; ship.Fuel = ship.MaxFuel; ship.AfterburnerStatus = 1; foreach (Inventory.MyInventoryItem item in ship.Weapons.AmmoInventoryItems.GetAmmoInventoryItems()) { item.Amount = item.MaxAmount; } } } if (input.IsAnyControlPress() && input.IsAnyShiftPress() && input.IsNewKeyPress(Keys.F8)) { MyGuiPreviewRenderer renderer = MyGuiManager.GetPreviewRenderer(); renderer.CreatePreviewsToFiles(@"C:\Temp", MyHudConstants.PREFAB_PREVIEW_SIZE); } if (input.IsNewKeyPress(Keys.Space) && input.IsAnyCtrlKeyPressed()) { if (CameraAttachedTo == MyCameraAttachedToEnum.Spectator) { // we try to move ship to the spot, then we check if it colides if yes we move it back. // Vector3 oldPos = MySession.PlayerShip.GetPosition(); MySession.PlayerShip.SetPosition(MySpectator.Position); //Move player ship to camera position MyEntities.CollisionsElements.Clear(); MinerWars.AppCode.Game.Physics.MyPhysicsBody rBody = MySession.PlayerShip.Physics; if (rBody.GetRBElementList().Count > 0) { // we expect only one rigid body (box) MyEntities.GetCollisionListForElement(rBody.GetRBElementList().First()); BoundingSphere bsphere = MySession.PlayerShip.WorldVolume; if (MyEntities.CollisionsElements.Count > 0 || MyVoxelMaps.GetOverlappingWithSphere(ref bsphere) != null) { MySession.PlayerShip.SetPosition(oldPos); //maybe warning here or sound is enough? MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorObjectMoveInvalid); } } else Debug.Assert(false);// no physical box in player ship } } if (input.IsNewKeyPress(Keys.Space) && input.IsAnyShiftKeyPressed()) { if (CameraAttachedTo == MyCameraAttachedToEnum.Spectator) { MySmallShip playerShip = MySession.PlayerShip; //Move Spectator to player ship position MySpectator.Position = playerShip.GetPosition() + ThirdPersonCameraDelta * playerShip.GetWorldRotation().Up + ThirdPersonCameraDelta * -playerShip.GetWorldRotation().Forward; MySpectator.Target = playerShip.GetPosition(); } } // Save check point - allowed only for story editors // DISABLED, now done automatically //if (IsGameActive() && input.IsKeyPress(Keys.RightShift) && input.IsNewKeyPress(Keys.F2) && // MyClientServer.LoggedPlayer != null && MyClientServer.LoggedPlayer.GetCanAccessEditorForStory()) //{ // MyGuiManager.AddScreen(new MyGuiScreenSaveCheckpoint()); //} if (!MyModelsStatisticsConstants.GET_MODEL_STATISTICS_AUTOMATICALLY && input.IsNewKeyPress(Keys.F10) && input.IsAnyShiftKeyPressed()) { MyModels.LogUsageInformation(); } if (!MyModelsStatisticsConstants.GET_MODEL_STATISTICS_AUTOMATICALLY && input.IsNewKeyPress(Keys.F10) && input.IsAnyAltKeyPressed()) { MyModels.CheckAllModels(); //MyModels.MergeLogFiles(); } /*if (input.IsNewKeyPress(Keys.F10) && input.IsAnyCtrlKeyPressed() && !MyModelsStatisticsConstants.GET_MODEL_STATISTICS_AUTOMATICALLY) { MyModelsStatisticsConstants.GET_MODEL_STATISTICS_AUTOMATICALLY = true; if (MyModelsStatisticsConstants.MISSIONS_TO_GET_MODEL_STATISTICS_FROM.Length == 0) { int i = 0; MyModelsStatisticsConstants.MISSIONS_TO_GET_MODEL_STATISTICS_FROM = new Missions.MyMissionID[Missions.MyMissions.Missions.Count]; foreach (var mission in MyMissions.Missions.Values.OfType<MyMission>().OrderBy(x => x.Name.ToString())) { if (i >= 12) MyModelsStatisticsConstants.MISSIONS_TO_GET_MODEL_STATISTICS_FROM[i] = mission.ID; i++; } } GUI.MyGuiScreenMainMenu.StartMission(MyModelsStatisticsConstants.MISSIONS_TO_GET_MODEL_STATISTICS_FROM[0]); }*/ // Voxel import if (MyFakes.VOXEL_IMPORT && input.IsNewKeyPress(Keys.PageUp)) { if (!input.IsAnyShiftKeyPressed()) { MyVoxelMap voxelMap = new MyVoxelMap(); //{ // // TODO: merge // //VoxelMaterial = MyMwcVoxelMaterialsEnum.Stone_01, // Size = MyFakes.VOXEL_IMPORT_SIZE //}; voxelMap.Init(Vector3.Zero, MyFakes.VOXEL_IMPORT_SIZE, MyMwcVoxelMaterialsEnum.Stone_01); MyModel model = new MyModel(MyFakes.VOXEL_IMPORT_MODEL, MyMeshDrawTechnique.MESH, MyModelsEnum.ExplosionDebrisVoxel); model.LoadData(); MyVoxelImport.Run(voxelMap, model, MyVoxelImportOptions.KeepAspectRatio); voxelMap.SaveVoxelContents(Path.Combine(MyMinerGame.Static.RootDirectory, "VoxelMaps", MyVoxelFiles.ExportFile + ".vox")); // Reload sector MyGuiScreenGamePlay.Static.Restart(); } else { int[] sizes = new int[] { 64, 128, 256, 512 }; List<MyMwcVector3Int> voxelSizes = new List<MyMwcVector3Int>(); for (int x = 0; x < sizes.Length; x++) { int lo = Math.Max(x - 1, 0); int hi = Math.Min(x + 2, sizes.Length); for (int y = lo; y < hi; y++) { for (int z = lo; z < hi; z++) { voxelSizes.Add(new MyMwcVector3Int(sizes[x], sizes[y], sizes[z])); } } } foreach (var size in voxelSizes) { MyVoxelMap voxelMap = new MyVoxelMap(); voxelMap.Init(Vector3.Zero, size, MyMwcVoxelMaterialsEnum.Stone_01); MyVoxelImport.Fill(voxelMap); voxelMap.SaveVoxelContents(Path.Combine(MyMinerGame.Static.RootDirectory, "VoxelMaps", String.Format("Cube_{0}x{1}x{2}.vox", size.X, size.Y, size.Z))); MyEntities.Remove(voxelMap); voxelMap.MarkForClose(); GC.Collect(); } // Reload sector MyGuiScreenGamePlay.Static.Restart(); } } if (input.IsNewKeyPress(Keys.L) && input.IsAnyCtrlKeyPressed() && input.IsAnyShiftKeyPressed()) { if (MyMissions.ActiveMission != null && MyMissions.ActiveMission.ActiveObjectives.Count > 0 && MyMissions.ActiveMission.ActiveObjectives[0].Location != null && MyMissions.ActiveMission.ActiveObjectives[0].Location.Entity != null) { MySpectator.Position = MyMissions.ActiveMission.ActiveObjectives[0].Location.Entity.GetPosition(); } } // Start sun wind if (input.IsNewKeyPress(Keys.F3)) { //Multiplayer_EnterGame(new MyEventEnterGame() { PlayerInfo = new MyPlayerInfo() { DisplayName = "Test" } }); //MyDialogues.Play(Audio.Dialogues.MyDialogueEnum.TEST); MyGlobalEvents.StartGlobalEvent(MyGlobalEventEnum.SunWind); //MyGuiManager.AddScreen(new MyGuiScreenMission(MyMissions.ActiveMission)); //MySession.PlayerShip.DoDamage(0, 1000000, 0, MyDamageType.Unknown, MyAmmoType.Unknown, null); //MyInventory.GenerateDebugInventoryItemsInfo(); //MyAmmoConstants.GenerateDebugAmmoTypeInfo(); if (MyFakes.ENABLE_DEBUG_INFLUENCE_SPHERES_SOUNDS) { if (input.IsKeyPress(Keys.LeftAlt)) { MyInfluenceSphere.UpdateMaxVolume(false); } else if (input.IsKeyPress(Keys.RightAlt)) { MyInfluenceSphere.UpdateMaxVolume(true); } else { MyInfluenceSphere.SwitchToNextSound(!input.IsAnyShiftKeyPressed()); } } } //Set camera to player if (input.IsNewKeyPress(Keys.F6)) { TryChangeCameraAttachedTo(MyCameraAttachedToEnum.PlayerMinerShip); } //Set camera to following third person if (input.IsNewKeyPress(Keys.F7)) { TryChangeCameraAttachedTo(MyCameraAttachedToEnum.PlayerMinerShip_ThirdPersonFollowing); } //Set camera to spectator if (input.IsNewKeyPress(Keys.F8))//&& TryChangeCameraAttachedTo(MyCameraAttachedToEnum.Spectator)) { CameraAttachedTo = MyCameraAttachedToEnum.Spectator; if (input.IsAnyCtrlKeyPressed()) { MySpectator.Position = MySession.PlayerShip.GetPosition() + ThirdPersonCameraDelta; MySpectator.Target = MySession.PlayerShip.GetPosition(); } } //Set camera to static third person if (input.IsNewKeyPress(Keys.F9) && TryChangeCameraAttachedTo(MyCameraAttachedToEnum.PlayerMinerShip_ThirdPersonStatic)) { if (input.IsAnyCtrlKeyPressed()) { MySpectator.Position = MySession.PlayerShip.GetPosition() + ThirdPersonCameraDelta; MySpectator.Target = MySession.PlayerShip.GetPosition(); } } if (input.IsNewKeyPress(Keys.F10) /*&& input.IsAnyCtrlKeyPressed()*/ && TryChangeCameraAttachedTo(MyCameraAttachedToEnum.BotMinerShip)) { //Find nearest bot and attach him BoundingFrustum boundingFrustum = MyCamera.GetBoundingFrustum(); List<MyEntity> entities = new List<MyEntity>(); MyEntities.GetAllIntersectionWithBoundingFrustum_UNOPTIMIZED(ref boundingFrustum, entities); MySmallShipBot closestBot = null; foreach (MyEntity entity in entities) { if (entity is MySmallShipBot) { if (closestBot == null) { closestBot = entity as MySmallShipBot; continue; } if (Vector3.Distance(MyCamera.Position, entity.GetPosition()) < Vector3.Distance(MyCamera.Position, closestBot.GetPosition())) { closestBot = entity as MySmallShipBot; } } } MyGuiScreenGamePlay.Static.ShipForSimpleTesting = closestBot; } } #endregion #region Game/editor keys if ((IsGameActive() || IsEditorActive()) && !MyEditorBase.IsEditorActive) { // Turn reflector on/off if (input.IsNewGameControlPressed(MyGameControlEnums.HEADLIGHTS)) { if (IsControlledPlayerShip) { MySession.PlayerShip.Config.ReflectorLight.ChangeValueUp(); } if (IsControlledDrone) { ControlledDrone.Config.ReflectorLight.ChangeValueUp(); } } // Move and rotate player or camera MoveAndRotatePlayerOrCamera(input); } #endregion #region Game keys that work only when player is alive if (IsGameActive() && IsFlyThroughActive() == false && MySession.Static != null && MySession.Static.Player != null && !MySession.Static.Player.IsDead()) { // Open inventory if (input.IsNewGameControlPressed(MyGameControlEnums.INVENTORY)) { if (IsControlledPlayerShip && !MySession.PlayerShip.IsDead() && !MySession.PlayerShip.IsPilotDead()) { MyGuiScreenInventoryType inventoryType; if (IsTypeEditorGodMode(m_previousType) && MySession.PlayerShip.TradeDetector.GetNearestEntity() == null || Static.IsCheatEnabled(MyGameplayCheatsEnum.UNLIMITED_TRADING)) { inventoryType = MyGuiScreenInventoryType.GodEditor; } else { inventoryType = MyGuiScreenInventoryType.Game; } if (!MyMultiplayerGameplay.IsRunning) { var inventoryScreen = MyGuiScreenInventoryManagerForGame.OpenInventory(inventoryType); MyGuiManager.AddScreen(inventoryScreen); } else { OpenInventoryMultiplayer(inventoryType); } } } // Target locking if (input.IsNewGameControlPressed(MyGameControlEnums.PREV_TARGET)) MyEnemyTargeting.SwitchNextTarget(false); if (input.IsNewGameControlPressed(MyGameControlEnums.NEXT_TARGET)) MyEnemyTargeting.SwitchNextTarget(true); // Bot follow / hold position if (input.IsNewGameControlPressed(MyGameControlEnums.CHANGE_DRONE_MODE)) { if (IsControlledDrone) ControlledDrone.HoldPosition = !ControlledDrone.HoldPosition; } if (input.IsNewGameControlPressed(MyGameControlEnums.QUICK_ZOOM) && !MyCamera.Zoom.IsZooming() && MyCamera.Zoom.GetZoomLevel() < 1.0f && !m_wheelControlMenu.Visible) { m_quickZoomOut = true; MyCamera.Zoom.SetZoom(MyCameraZoomOperationType.ZoomOut); } if (!m_quickZoomOut) { if (input.IsGameControlPressed(MyGameControlEnums.QUICK_ZOOM)) { MyCamera.Zoom.SetZoom(MyCameraZoomOperationType.ZoomIn); m_quickZoomWasUsed = true; } else if (m_quickZoomWasUsed) { MyCamera.Zoom.SetZoom(MyCameraZoomOperationType.ZoomOut); } } if (input.IsNewGameControlPressed(MyGameControlEnums.ZOOM_IN) || input.IsNewGameControlPressed(MyGameControlEnums.ZOOM_OUT)) { m_quickZoomOut = false; } if (!input.IsGameControlPressed(MyGameControlEnums.ZOOM_IN)) { if (input.IsGameControlPressed(MyGameControlEnums.ZOOM_OUT)) { MyCamera.Zoom.SetZoom(MyCameraZoomOperationType.ZoomOut); m_quickZoomWasUsed = false; } else if (!m_quickZoomWasUsed && !m_quickZoomOut) { MyCamera.Zoom.SetZoom(MyCameraZoomOperationType.NoZoom); } } else if (input.IsGameControlPressed(MyGameControlEnums.ZOOM_IN)) { MyCamera.Zoom.SetZoom(MyCameraZoomOperationType.ZoomIn); m_quickZoomWasUsed = false; } // Drone manipulation if (input.IsGameControlPressed(MyGameControlEnums.DRONE_DEPLOY)) DroneDeployKeyPressed(); if (input.IsGameControlPressed(MyGameControlEnums.DRONE_CONTROL)) DroneControlKeyPressed(); // Roll callbacks (movement is handled in MoveAndRotatePlayerOrCamera) if (input.IsNewGameControlPressed(MyGameControlEnums.ROLL_LEFT)) { OnRollLeftPressed(); MyScriptWrapper.RollLeftPressed(); } if (input.IsNewGameControlPressed(MyGameControlEnums.ROLL_RIGHT)) { OnRollRightPressed(); MyScriptWrapper.RollRightPressed(); } // Turn deceleration on/off if (input.IsNewGameControlPressed(MyGameControlEnums.MOVEMENT_SLOWDOWN)) { if (IsControlledPlayerShip && MySession.PlayerShip.Config.Engine.On) MySession.PlayerShip.Config.MovementSlowdown.ChangeValueUp(); } // Change headlight distance if (input.IsNewGameControlPressed(MyGameControlEnums.HEADLIGTHS_DISTANCE)) { if (IsControlledPlayerShip) MySession.PlayerShip.Config.ReflectorLongRange.ChangeValueUp(); } // Turn auto-leveling on/off if (input.IsNewGameControlPressed(MyGameControlEnums.AUTO_LEVEL)) { if (IsControlledPlayerShip && MySession.PlayerShip.Config.Engine.On) MySession.PlayerShip.Config.AutoLeveling.ChangeValueUp(); } // Turn secondary camera on/off if (MyFakes.ENABLE_BACK_CAMERA && !DisableBackCamera) { if (input.IsNewGameControlPressed(MyGameControlEnums.REAR_CAM)) { if (IsControlledPlayerShip) ControlledShip.Config.BackCamera.ChangeValueUp(); if (IsControlledDrone) ControlledDrone.Config.BackCamera.ChangeValueUp(); } } else { MySession.PlayerShip.Config.BackCamera.SetOff(); if (IsControlledDrone) ControlledDrone.Config.BackCamera.SetOff(); } // Switch view - cockpit on/off, third person if (input.IsNewGameControlPressed(MyGameControlEnums.VIEW_MODE)) { if (IsControlledPlayerShip) MySession.PlayerShip.Config.ViewMode.ChangeValueUp(); } // Secondary camera and remote camera controls if (input.IsNewGameControlPressed(MyGameControlEnums.PREVIOUS_CAMERA)) { if (IsControlledPlayerShip) MySession.PlayerShip.SelectPreviousSecondaryCamera(); } if (input.IsNewGameControlPressed(MyGameControlEnums.NEXT_CAMERA)) { if (IsControlledPlayerShip) MySession.PlayerShip.SelectNextSecondaryCamera(); } HandleRemoteCameraInput(input); // Show GPS if (input.IsNewGameControlPressed(MyGameControlEnums.GPS) || (MyFakes.GPS_ALWAYS_ON && Math.Abs(MyHud.LastGPS - MyMinerGame.TotalGamePlayTimeInMilliseconds) > 500)) { MyHud.ShowGPSPathToNextObjective(true); if (!m_showGPSNotification.IsDisappeared()) m_showGPSNotification.Disappear(); } // Harvesting and drilling if (input.IsNewGameControlPressed(MyGameControlEnums.HARVEST)) { if (IsControlledPlayerShip && MySession.PlayerShip.IsEngineWorking() && MySession.PlayerShip.Fuel > 0) MySession.PlayerShip.Weapons.FireHarvester(); } if (input.IsGameControlPressed(MyGameControlEnums.DRILL)) { if (IsControlledPlayerShip && MySession.PlayerShip.IsEngineWorking() && MySession.PlayerShip.Fuel > 0) MySession.PlayerShip.Weapons.FireDrill(); } } #endregion #region Game keys that work only when player is alive and action menu is closed (e.g. keys that open a new menu) if (IsGameActive() && !m_wheelControlMenu.Visible && IsFlyThroughActive() == false && MySession.Static != null && MySession.Static.Player != null && !MySession.Static.Player.IsDead()) { // Travel if (input.IsNewGameControlPressed(MyGameControlEnums.TRAVEL)) { bool canTravel = true; if (m_type == MyGuiScreenGamePlayType.GAME_SANDBOX) { if (MyGuiScreenGamePlay.Static.GetPreviousGameType() != MyGuiScreenGamePlayType.EDITOR_STORY) canTravel = false; } else if (m_type == MyGuiScreenGamePlayType.GAME_STORY || m_type == MyGuiScreenGamePlayType.GAME_MMO) { if (MySession.PlayerShip.GetNearMotherShipContainer() == null) canTravel = false; else canTravel = CanTravel; } bool canSave = MyClientServer.LoggedPlayer.GetCanSave(); canTravel |= MyFakes.ENABLE_SOLAR_MAP; canTravel &= canSave; if (canTravel) { MyMwcSectorIdentifier sector = m_sectorIdentifier; this.HideScreen(); MyGuiManager.AddScreen(new MyGuiScreenSolarSystemMap(this, sector)); } else if (m_type == MyGuiScreenGamePlayType.GAME_STORY || m_type == MyGuiScreenGamePlayType.GAME_MMO) { if (!canSave) MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.DemoUserCannotTravel, MyTextsWrapperEnum.SolarSystemMap, MyTextsWrapperEnum.Ok, null)); else if (CanTravel) MyHudNotification.AddNotification(m_notificationYouHaveToBeNearMothership); else MyHudNotification.AddNotification(m_notificationUnableToLeaveSectorMission); } } // Use / Hack / Take if (input.IsNewGameControlPressed(MyGameControlEnums.USE)) { bool isHandled = false; // first handled are notifications if (MyHudNotification.HasNotification(MyHudNotification.GetCurrentScreen())) isHandled = MyHudNotification.HandleInput(input); // second handled is take all event if (!isHandled) isHandled = TakeAllItems(); // third handled is hacking etc if (!isHandled) { MySmallShip hacker = ControlledDrone ?? MySession.PlayerShip; IMyUseableEntity detectedEntityToUse = hacker.UseableEntityDetector.GetNearestEntity() as IMyUseableEntity; if (ControlledLargeWeapon != null && TryChangeCameraAttachedTo(MyCameraAttachedToEnum.PlayerMinerShip)) ReleaseControlOfLargeWeapon(); if (ControlledCamera != null) ReleaseControlOfCamera(); else if (detectedEntityToUse != null) { MySmallShipInteractionActionEnum detectedAction = (MySmallShipInteractionActionEnum)hacker.UseableEntityDetector.GetNearestEntityCriterias(); if (detectedAction == MySmallShipInteractionActionEnum.Use) detectedEntityToUse.Use(hacker); else if (detectedAction == MySmallShipInteractionActionEnum.Hack) hacker.HackingTool.Hack(detectedEntityToUse); } else MyScriptWrapper.UseKeyPressed(); } } /* Journal removed // Journal if (input.IsNewGameControlPressed(MyGameControlEnums.MISSION_DIALOG) && (GetGameType() == MyGuiScreenGamePlayType.GAME_STORY || GetGameType() == MyGuiScreenGamePlayType.GAME_MMO)) { if (!MyMissions.RequestMissionDialog()) MyGuiManager.AddScreen(new MyGuiScreenJournal(MySession.Static.EventLog)); } */ // Chat, multiplayer statistics // TODO: prevent dev keys universally, not based on the default mapping #if !RENDER_PROFILING if (MyGuiManager.IsScreenTopMostNonDebug(this)) { if (input.IsNewGameControlPressed(MyGameControlEnums.CHAT)/* && MyMultiplayerGameplay.IsRunning && (MyMultiplayerGameplay.IsSandBox() || (MyMultiplayerGameplay.IsStory() && MyMultiplayerGameplay.OtherPlayersConnected))*/) //only in deathmatch (all the time) or coop (at least one other player) { MyGuiManager.AddScreen(new MyGuiScreenGameChat(input.IsAnyShiftKeyPressed())); } if (input.IsNewGameControlPressed(MyGameControlEnums.SCORE) && MyMultiplayerGameplay.IsRunning && (MyMultiplayerGameplay.IsSandBox() || (MyMultiplayerGameplay.IsStory() && MyMultiplayerGameplay.OtherPlayersConnected))) //only in deathmatch (all the time) or coop (at least one other player) { MyGuiManager.AddScreen(new MyGuiScreenGameScore()); } } #endif // Shooting // we can be dead in this moment if (MyFakes.CUBE_EDITOR && MySession.PlayerShip != null && input.IsNewGameControlPressed(MyGameControlEnums.QUICK_ZOOM)) MySession.PlayerShip.CubeBuilder.BuilderActive = !MySession.PlayerShip.CubeBuilder.BuilderActive; if (MySession.PlayerShip != null && MySession.PlayerShip.CubeBuilder.BuilderActive) { if (input.IsNewGameControlPressed(MyGameControlEnums.FIRE_PRIMARY)) MySession.PlayerShip.CubeBuilder.Add(); if (input.IsNewGameControlPressed(MyGameControlEnums.FIRE_SECONDARY)) MySession.PlayerShip.CubeBuilder.Remove(); } else if (m_handleInputMouseKeysReleased && (!IsSelectAmmoVisible()) && (!m_wheelControlMenu.Visible) && MySession.PlayerShip != null && !MySession.PlayerShip.IsDead() && IsFireKeyEnabled()) { switch (CameraAttachedTo) { case MyCameraAttachedToEnum.PlayerMinerShip_ThirdPersonDynamic: case MyCameraAttachedToEnum.Spectator: case MyCameraAttachedToEnum.PlayerMinerShip_ThirdPersonStatic: case MyCameraAttachedToEnum.PlayerMinerShip_ThirdPersonFollowing: case MyCameraAttachedToEnum.PlayerMinerShip: if (!input.IsAnyCtrlKeyPressed() || CameraAttachedTo == MyCameraAttachedToEnum.PlayerMinerShip) { MySmallShip playerShip = MySession.PlayerShip; if (playerShip.IsEngineWorking()) { if (input.IsGameControlPressed(MyGameControlEnums.FIRE_PRIMARY)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.Primary); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_SECONDARY)) { // TODO: prevent dev keys universally, not based on the default mapping #if !GPU_PROFILING playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.Secondary); #endif } if (input.IsGameControlPressed(MyGameControlEnums.FIRE_THIRD)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.Third); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FOURTH)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.Fourth); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FIFTH)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.Fifth); if (input.IsNewGameControlPressed(MyGameControlEnums.WEAPON_SPECIAL)) playerShip.InvokeAmmoSpecialFunction(); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_HOLOGRAM_FRONT)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.HologramFront); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_HOLOGRAM_BACK)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.HologramBack); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_BASIC_MINE_FRONT)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.BasicMineFront); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_BASIC_MINE_BACK)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.BasicMineBack); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_SMART_MINE_FRONT)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.SmartMineFront); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_SMART_MINE_BACK)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.SmartMineBack); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FLASH_BOMB_FRONT)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.FlashBombFront); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FLASH_BOMB_BACK)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.FlashBombBack); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_DECOY_FLARE_FRONT)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.DecoyFlareFront); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_DECOY_FLARE_BACK)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.DecoyFlareBack); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_SMOKE_BOMB_FRONT)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.SmokeBombFront); if (input.IsGameControlPressed(MyGameControlEnums.FIRE_SMOKE_BOMB_BACK)) playerShip.Weapons.Fire(MyMwcObjectBuilder_FireKeyEnum.SmokeBombBack); } } break; case MyCameraAttachedToEnum.Drone: if (input.IsGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) || input.IsGameControlPressed(MyGameControlEnums.FIRE_SECONDARY) || input.IsGameControlPressed(MyGameControlEnums.FIRE_THIRD) || input.IsGameControlPressed(MyGameControlEnums.FIRE_FOURTH) || input.IsGameControlPressed(MyGameControlEnums.FIRE_FIFTH)) { ControlledDrone.Fire(); DisableFireKey(new TimeSpan(0, 0, 1)); } break; case MyCameraAttachedToEnum.LargeWeapon: if (input.IsGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) || input.IsGameControlPressed(MyGameControlEnums.FIRE_SECONDARY) || input.IsGameControlPressed(MyGameControlEnums.FIRE_THIRD) || input.IsGameControlPressed(MyGameControlEnums.FIRE_FOURTH) || input.IsGameControlPressed(MyGameControlEnums.FIRE_FIFTH)) { ControlledLargeWeapon.Fire(); } else { ControlledLargeWeapon.StopFire(); } break; } } } #endregion #region Game keys that work all the time (even when player is dead) if (IsGameActive()) { // Open cheat screen if (input.IsNewKeyPress(Keys.F1) && input.IsAnyCtrlKeyPressed()) { MyGuiManager.AddScreen(new MyGuiScreenCheats()); } // Open help screen if (input.IsNewKeyPress(Keys.F1) && !input.IsAnyCtrlKeyPressed()) { MyGuiManager.AddScreen(new MyGuiScreenHelp()); } if (IsControlledPlayerShip) { m_selectAmmoMenu.HandleInput(input, true, true, receivedFocusInThisUpdate); m_wheelControlMenu.HandleInput(input, true, true, receivedFocusInThisUpdate); } // DrawMouseCursor = m_wheelControlMenu.Visible; /* //duplicated in if IsGameReady if (IsGameActive()) // enable cursor drawing if we have ammo selection opened { DrawMouseCursor = m_selectAmmoMenu.IsEnabled && m_selectAmmoMenu.Visible; } */ MyDebugConsole.GetInstance().Update(MyDebugSystem.Game, input); } #endregion #region Editor keys if (IsEditorActive()) { // Open ship customization screen if (input.IsNewGameControlPressed(MyGameControlEnums.INVENTORY) && !input.IsAnyCtrlKeyPressed()) { if (MyFakes.SHOW_NEW_INVENTORY_SCREEN) { MyGuiScreenInventoryType inventoryType = !IsIngameEditorActive() || Static.IsCheatEnabled(MyGameplayCheatsEnum.UNLIMITED_TRADING) ? MyGuiScreenInventoryType.GodEditor : MyGuiScreenInventoryType.InGameEditor; MyGuiManager.AddScreen(MyGuiScreenInventoryManagerForGame.OpenInventory(inventoryType)); } } MyEditor.Static.HandleInput(input, !AnyControlContainsMouse()); MyDebugConsole.GetInstance().Update(MyDebugSystem.Editor, input); } #endregion }
public static void HandleInput(MyGuiInput input) { // -- Select Gizmo Mode -- // if (input.IsEditorControlNewPressed(MyEditorControlEnums.SWITCH_GIZMO_MODE) && !input.IsAnyCtrlKeyPressed()) { SwitchGizmoMode(); } // -- Select Gizmo Mode -- // if (input.IsEditorControlNewPressed(MyEditorControlEnums.SWITCH_GIZMO_MODE) && input.IsAnyCtrlKeyPressed() ) { SwitchRotateSnapping(); } // -- Cycle TransformationSpaces -- // if (input.IsEditorControlNewPressed(MyEditorControlEnums.SWITCH_GIZMO_SPACE)) { if (ActiveSpace == TransformSpace.LOCAL) ActiveSpace = TransformSpace.WORLD; else { ActiveSpace = TransformSpace.LOCAL; } } // Below are options, that we can add later, but gizmo is prepared for them // however, key mappings will be probably changed // -- Cycle PivotTypes -- // //if (input.IsNewKeyPress(Keys.P)) //{ // ActivePivot++; //} // -- Toggle PrecisionMode -- // //if (input.IsKeyPress(Keys.K)) //{ // m_precisionMode = true; //} //else //{ // m_precisionMode = false; //} // -- Toggle Snapping -- // //if (MyEditor.Static.IsEditingPrefabContainer() == false) //{ if (input.IsNewKeyPress(Keys.G)) { SnapEnabled = !SnapEnabled; } //} if (Enabled) { if (input.IsEditorControlNewPressed(MyEditorControlEnums.PRIMARY_ACTION_KEY)) { // reset for intersection (plane vs. ray) m_translationDelta = Vector3.Zero; m_intersectPosition = Vector3.Zero; // reset for snapping m_translationScaleSnapDelta = Vector3.Zero; m_rotationSnapDelta = 0; m_lastCursorPosition = MyGuiManager.MouseCursorPosition; m_oldCursorPosition = MyGuiManager.MouseCursorPosition; m_gizmoDelta = null; m_gizmoStartPosition = null; m_mouseStartPosition = m_lastCursorPosition; m_startCameraForward = MyCamera.ForwardVector; m_startCameraUp = MyCamera.UpVector; m_startObjectPosition = Position; } m_lastIntersectionPosition = m_intersectPosition; TransformationActive = false; if (input.IsEditorControlPressed(MyEditorControlEnums.PRIMARY_ACTION_KEY)) { if (MyEditor.TransformLocked) { ActiveAxis = LastActiveAxis; } if (ActiveAxis != GizmoAxis.NONE) { //this will help to disable rectangular selection of multiple objects during object transformation with mouse TransformationActive = true; if (ActiveMode == GizmoMode.TRANSLATE) { #region Translate if (HasTransformationStarted()) { StartTransformationData(); } //if (input.IsAnyShiftKeyPressed() && input.IsNewLeftMousePressed()) //{ // MyEditor.Static.CopySelected(false); //} //else if (HasTransformationStarted()) //{ // StartTransformationData(); //} Vector3 delta = Vector3.Zero; Vector3 worldPosition = Position; if (ActiveAxis == GizmoAxis.XY) { GizmoTranslation(Vector3.Left, Vector3.Up, ref worldPosition); } else if (ActiveAxis == GizmoAxis.YZ) { GizmoTranslation(Vector3.Up, Vector3.Forward, ref worldPosition); } else if (ActiveAxis == GizmoAxis.ZX) { GizmoTranslation(Vector3.Left, Vector3.Forward, ref worldPosition); } else if (ActiveAxis == GizmoAxis.X) { GizmoTranslation(Vector3.Left, null, ref worldPosition); } else if (ActiveAxis == GizmoAxis.Y) { GizmoTranslation(Vector3.Up, null, ref worldPosition); } else if (ActiveAxis == GizmoAxis.Z) { GizmoTranslation(Vector3.Forward, null, ref worldPosition); } // When object is half distance to far, stop it's movement Plane maxMovePlane = MyCamera.GetBoundingFrustum().Far; maxMovePlane.D *= TRANSLATION_MAX_DISTANCE_FROM_CAMERA / MyCamera.FAR_PLANE_DISTANCE; Vector3 moveVector = worldPosition - Position; Ray moveRay = new Ray(Position, -moveVector); float? intersection = moveRay.Intersects(maxMovePlane); Vector3 cam = MyCamera.Position; // Intersection found and moving object towards far clip plane if (intersection.HasValue && Vector3.Dot(MyCamera.ForwardVector, moveVector) > 0 && (worldPosition - cam).Length() > Math.Abs(maxMovePlane.D)) { Vector3 intersectionPoint = (moveRay.Position + (moveRay.Direction * intersection.Value)); worldPosition = intersectionPoint; } moveVector = worldPosition - Position; // copy selected object only when moved from his original position + LMB + Shift bool copySelected = (moveVector.LengthSquared() >= 0f && input.IsAnyShiftKeyPressed() && input.IsNewLeftMousePressed()); if (copySelected) { MyEditor.Static.CopySelected(false); } bool applyTranslation = true; PrepareSafeSelectedEntitiesIterationHelper(); foreach (var entity in m_safeIterationHelper) { Vector3 newPosition = entity.GetPosition() + moveVector; BoundingSphere sphere = new BoundingSphere(newPosition + entity.LocalVolumeOffset, entity.WorldVolume.Radius); if (!entity.CanMoveAndRotate(newPosition, entity.GetWorldRotation()) || MyMwcSectorConstants.SECTOR_SIZE_FOR_PHYS_OBJECTS_BOUNDING_BOX.Contains(sphere) != MinerWarsMath.ContainmentType.Contains) { applyTranslation = false; break; } } if (applyTranslation) { PrepareSafeSelectedEntitiesIterationHelper(); List<MyEntity> transformedEntities = new List<MyEntity>(); // apply foreach (MyEntity entity in m_safeIterationHelper) { // skip already transformed linked entities if (transformedEntities.Contains(entity)) { continue; } Vector3 newPosition = entity.GetPosition() + moveVector; //snaping after mouse over /* // Snap to grid if (SnapEnabled && ActiveSpace == TransformSpace.WORLD && !MyEditor.Static.IsLinked(entity)) { SnapToGrid(ref newPosition, TranslationSnapValue); } */ MoveAndRotateObject(newPosition, entity.GetWorldRotation(), entity); MyEditor.Static.FixLinkedEntities(entity, transformedEntities, null); transformedEntities.Add(entity); } // test if some entities are intersection //CheckCollisions(m_safeIterationHelper); //MyEditor.Static.CheckAllCollidingObjects(); MyEditor.Static.HighlightCollisions(m_safeIterationHelper); } #endregion } else if (ActiveMode == GizmoMode.ROTATE) { #region Rotate if (HasTransformationStarted()) StartTransformationData(); Vector2 deltaCursorPosition; float delta; if (!MyVideoModeManager.IsHardwareCursorUsed()) { Vector2 minMouseCoord = MyGuiManager.GetMinMouseCoord(); Vector2 maxMouseCoord = MyGuiManager.GetMaxMouseCoord(); Vector2 newCursorPosition = MyGuiManager.MouseCursorPosition; if (MyGuiManager.MouseCursorPosition.X <= minMouseCoord.X) newCursorPosition = new Vector2(maxMouseCoord.X, MyGuiManager.MouseCursorPosition.Y); if (MyGuiManager.MouseCursorPosition.X >= maxMouseCoord.X) newCursorPosition = new Vector2(minMouseCoord.X, MyGuiManager.MouseCursorPosition.Y); if (MyGuiManager.MouseCursorPosition.Y <= minMouseCoord.Y) newCursorPosition = new Vector2(MyGuiManager.MouseCursorPosition.X, maxMouseCoord.Y); if (MyGuiManager.MouseCursorPosition.Y >= maxMouseCoord.Y) newCursorPosition = new Vector2(MyGuiManager.MouseCursorPosition.X, minMouseCoord.Y); MyGuiManager.MouseCursorPosition = newCursorPosition; //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall(MyGuiManager.MouseCursorPosition.ToString() + " " + MyGuiManager.MouseCursorPosition.ToString()); float deltaX = MathHelper.ToRadians(input.GetMouseXForGamePlay() - MyMinerGame.ScreenSizeHalf.X); float deltaY = MathHelper.ToRadians(input.GetMouseYForGamePlay() - MyMinerGame.ScreenSizeHalf.Y); deltaX = MathHelper.Clamp(deltaX, -1, 1); deltaY = MathHelper.Clamp(deltaY, -1, 1); delta = deltaY + deltaX; Vector2 cursorDelta = Vector2.Zero; if (MyGuiManager.MouseCursorPosition.Y != 0.0 && MyGuiManager.MouseCursorPosition.Y != 1.0) { cursorDelta = MyGuiManager.MouseCursorPosition - m_lastCursorPosition; } m_inputScale = MathHelper.Clamp(Math.Abs(cursorDelta.Y) * 100, 0, 1); delta *= m_inputScale; m_oldCursorPosition = MyGuiManager.MouseCursorPosition; } else { Vector2 minMouseCoord = MyGuiManager.GetMinMouseCoord(); Vector2 maxMouseCoord = MyGuiManager.GetMaxMouseCoord(); Vector2 newCursorPosition = MyGuiManager.MouseCursorPosition; deltaCursorPosition = MyGuiManager.MouseCursorPosition - m_oldCursorPosition; if (MyGuiManager.MouseCursorPosition.X - 0.03f <= minMouseCoord.X) { deltaCursorPosition = new Vector2(0, 0); newCursorPosition = new Vector2(maxMouseCoord.X - 0.05f, MyGuiManager.MouseCursorPosition.Y); } if (MyGuiManager.MouseCursorPosition.X + 0.03f >= maxMouseCoord.X * 0.98f) { deltaCursorPosition = new Vector2(0, 0); newCursorPosition = new Vector2(minMouseCoord.X + 0.05f, MyGuiManager.MouseCursorPosition.Y); } if (MyGuiManager.MouseCursorPosition.Y - 0.03f <= minMouseCoord.Y) { deltaCursorPosition = new Vector2(0, 0); newCursorPosition = new Vector2(MyGuiManager.MouseCursorPosition.X, maxMouseCoord.Y - 0.05f); } if (MyGuiManager.MouseCursorPosition.Y + 0.03f >= maxMouseCoord.Y) { deltaCursorPosition = new Vector2(0, 0); newCursorPosition = new Vector2(MyGuiManager.MouseCursorPosition.X, minMouseCoord.Y + 0.05f); } MyGuiManager.MouseCursorPosition = newCursorPosition; delta = (deltaCursorPosition.X + deltaCursorPosition.Y) * 4.0f; delta = MathHelper.Clamp(delta, -2.0f, 2.0f); m_oldCursorPosition = MyGuiManager.MouseCursorPosition; } // Allow snapping of gizmo to make it move depending on the selected grid scale if (ActiveRotateSnapping!=RotateSnapping.NONE) { float snapValue = MathHelper.ToRadians(GetRotateSnapValue()); if (m_precisionMode) { delta *= m_precisionModeScale; snapValue *= m_precisionModeScale; } m_rotationSnapDelta += delta; float snapped = (int)(m_rotationSnapDelta / snapValue) * snapValue; m_rotationSnapDelta -= snapped; delta = snapped; } else if (m_precisionMode) { delta *= m_precisionModeScale; } // rotation matrix to transform - if more than one objects selected, always use world-space. Matrix rot = Matrix.Identity; rot.Forward = m_sceneWorld.Forward; rot.Up = m_sceneWorld.Up; rot.Right = m_sceneWorld.Right; // Create rotation delta matrix if (ActiveAxis == GizmoAxis.X) { rot *= Matrix.CreateFromAxisAngle(Rotation.Right, delta); } else if (ActiveAxis == GizmoAxis.Y) { rot *= Matrix.CreateFromAxisAngle(Rotation.Up, delta); } else if (ActiveAxis == GizmoAxis.Z) { rot *= Matrix.CreateFromAxisAngle(Rotation.Forward, delta); } // store rotation parameters so that we can calculate the difference in rotation of "before" rotation and "after" CalculateYawPitchRollFromRotationDelta(rot); PrepareSafeSelectedEntitiesIterationHelper(); List<MyEntity> transformedEntities = new List<MyEntity>(); // -- Apply rotation -- // foreach (MyEntity entity in m_safeIterationHelper) { // skip already transformed linked entities if (transformedEntities.Contains(entity)) { continue; } // VoxelMaps cannot be rotated if (entity is MyVoxelMap == false) { // use gizmo position for all PivotTypes except for object-center, it should use the entity.position instead. Vector3 newPosition; Matrix newRotation; GetRotationAndPosition(entity, rot, out newPosition, out newRotation); Matrix normalizedMat = new Matrix(); normalizedMat.Right = Vector3.Normalize(newRotation.Right); normalizedMat.Forward = Vector3.Normalize(Vector3.Cross(Vector3.Normalize(newRotation.Up), normalizedMat.Right)); normalizedMat.Up = Vector3.Normalize(Vector3.Cross(normalizedMat.Right, normalizedMat.Forward)); normalizedMat.Translation = newRotation.Translation; normalizedMat.M44 = newRotation.M44; //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall("{"); //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall(normalizedMat.ToString()); //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall(newRotation.ToString()); //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall("}"); MoveAndRotateObject(newPosition, normalizedMat, entity); MyEditor.Static.FixLinkedEntities(entity, transformedEntities, null); transformedEntities.Add(entity); } } SetPosition(); Vector3 moveVector = m_startObjectPosition - Position; PrepareSafeSelectedEntitiesIterationHelper(); transformedEntities = new List<MyEntity>(); // apply foreach (MyEntity entity in m_safeIterationHelper) { // skip already transformed linked entities if (transformedEntities.Contains(entity)) { continue; } Vector3 newPosition = entity.GetPosition() + moveVector; MoveAndRotateObject(newPosition, entity.GetWorldRotation(), entity); MyEditor.Static.FixLinkedEntities(entity, transformedEntities, null); transformedEntities.Add(entity); } #endregion } } } else { PrepareSafeSelectedEntitiesIterationHelper(); foreach (MyEntity entity in m_safeIterationHelper) { float moveObjectDistanceInMeters = MyEditorGrid.GetGridStepInMeters(); float rotationAngleInRadians = MathHelper.ToRadians(GetRotationDelta()); Matrix entityOrientation = entity.GetWorldRotation(); bool isVoxelMap = entity is MyVoxelMap; Vector3 entityPosition = entity.GetPosition(); #region Translate and Rotate with keyboard Vector3 newPosition = entityPosition; Matrix newRotation = entityOrientation; // Keyboard translation if (IsTransformationKeyPressed(input, Keys.NumPad1)) { newPosition = GetTransformInAxis(GizmoAxis.X, entityPosition, Rotation, -moveObjectDistanceInMeters); } if (IsTransformationKeyPressed(input, Keys.NumPad3)) { newPosition = GetTransformInAxis(GizmoAxis.X, entityPosition, Rotation, +moveObjectDistanceInMeters); } if (IsTransformationKeyPressed(input, Keys.NumPad2)) { newPosition = GetTransformInAxis(GizmoAxis.Z, entityPosition, Rotation, +moveObjectDistanceInMeters); } if (IsTransformationKeyPressed(input, Keys.NumPad5)) { newPosition = GetTransformInAxis(GizmoAxis.Z, entityPosition, Rotation, -moveObjectDistanceInMeters); } if (IsTransformationKeyPressed(input, Keys.NumPad9)) { newPosition = GetTransformInAxis(GizmoAxis.Y, entityPosition, Rotation, +moveObjectDistanceInMeters); } if (IsTransformationKeyPressed(input, Keys.NumPad6)) { newPosition = GetTransformInAxis(GizmoAxis.Y, entityPosition, Rotation, -moveObjectDistanceInMeters); } // Keyboard rotation Matrix oneStepRotationDelta = Matrix.Identity; if (IsTransformationKeyPressed(input, Keys.NumPad7) && !isVoxelMap) { oneStepRotationDelta = Matrix.CreateFromAxisAngle(Rotation.Right, rotationAngleInRadians); GetRotationAndPosition(entity, oneStepRotationDelta, out newPosition, out newRotation); } if (IsTransformationKeyPressed(input, Keys.NumPad4) && !isVoxelMap) { oneStepRotationDelta = Matrix.CreateFromAxisAngle(Rotation.Up, rotationAngleInRadians); GetRotationAndPosition(entity, oneStepRotationDelta, out newPosition, out newRotation); } if (IsTransformationKeyPressed(input, Keys.NumPad8) && !isVoxelMap) { oneStepRotationDelta = Matrix.CreateFromAxisAngle(Rotation.Forward, rotationAngleInRadians); GetRotationAndPosition(entity, oneStepRotationDelta, out newPosition, out newRotation); } if (HasTransformationStarted()) StartTransformationData(); // Transform bool translated = newPosition != entityPosition; bool rotated = newRotation != entityOrientation; if (translated || rotated) { if (translated) ActiveMode = GizmoMode.TRANSLATE; if (rotated) { ActiveMode = GizmoMode.ROTATE; if (IsDelayForSmoothMovementReached()) { RotationAmountInDegrees += (int)GetRotationDelta(); } else { RotationAmountInDegrees = (int)GetRotationDelta(); } } MoveAndRotateObject(newPosition, newRotation, entity); } #endregion } UpdateAxisSelection(MyGuiManager.GetScreenCoordinateFromNormalizedCoordinate(MyGuiManager.MouseCursorPosition)); /* if (GetSnapPoint(true) == null) { } else { ActiveAxis = GizmoAxis.NONE; } */ } if (HasTransformationEnded()) EndTransformationData(); // previous is used to detect, when is right time to create undo/redo editor action(start of transform, and end of transform) TransformationActivePrevious = TransformationActive; } else { ActiveAxis = GizmoAxis.NONE; } }
//public static event OnVoxelShapeSizeChanged OnVoxelShapeSize; //public static event OnVoxelShapeDistanceChanged OnVoxelShapeDistance; public static void HandleInput(MyGuiInput input) { // exit voxel hand using this key if (input.IsEditorControlNewPressed(MyEditorControlEnums.VOXEL_HAND)) { SwitchEnabled(); } if (m_Enabled == false || !IsAnyEditorActive()) return; m_applyToVoxelMap = null; //here possible change if ((input.IsEditorControlNewPressed(MyEditorControlEnums.PRIMARY_ACTION_KEY) || input.IsAnyShiftKeyPressed() && input.IsEditorControlPressed(MyEditorControlEnums.PRIMARY_ACTION_KEY)) && (m_timeFromLastShaping >= MyVoxelConstants.VOXEL_HAND_SHAPING_INTERVAL || MyFakes.RAPID_VOXEL_HAND_SHAPING_ENABLED || MyFakes.MWBUILDER)) { m_timeFromLastShaping = 0; if (DetachedVoxelHand != null && !input.IsKeyPress(Keys.Space)) return; MyVoxelMap voxelMap = null; if (VoxelHandShape is MyVoxelHandSphere) { MyVoxelHandSphere sphere = (MyVoxelHandSphere)VoxelHandShape; BoundingSphere vol = sphere.WorldVolume; voxelMap = MyVoxelMaps.GetIntersectionWithSphere(ref vol, SelectedVoxelMap); } else if (VoxelHandShape is MyVoxelHandBox) { MyVoxelHandBox box = (MyVoxelHandBox)VoxelHandShape; BoundingBox localBoundingBox = box.GetLocalBoundingBox(); Vector3 boxWorldPosition = box.GetPosition(); voxelMap = MyVoxelMaps.GetIntersectionWithBox(ref localBoundingBox, ref boxWorldPosition, SelectedVoxelMap); } else if (VoxelHandShape is MyVoxelHandCuboid) { MyVoxelHandCuboid cuboid = (MyVoxelHandCuboid)VoxelHandShape; BoundingBox localBoundingBox = cuboid.GetLocalBoundingBox(); Vector3 boxWorldPosition = cuboid.GetPosition(); voxelMap = MyVoxelMaps.GetIntersectionWithBox(ref localBoundingBox, ref boxWorldPosition, SelectedVoxelMap); } else if (VoxelHandShape is MyVoxelHandCylinder) { MyVoxelHandCylinder cylinder = (MyVoxelHandCylinder)VoxelHandShape; BoundingBox localBoundingBox = cylinder.GetLocalBoundingBox(); Vector3 boxWorldPosition = cylinder.GetPosition(); voxelMap = MyVoxelMaps.GetIntersectionWithBox(ref localBoundingBox, ref boxWorldPosition, SelectedVoxelMap); } else { System.Diagnostics.Debug.Assert(false); } if (voxelMap != null) { m_applyToVoxelMap = voxelMap; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// // Change size of asteroid tool from camera //////////////////////////////////////////////////////////////////////////////////////////////////////////// /* if (input.IsAnyShiftKeyPressed()) { if (input.PreviousMouseScrollWheelValue() > input.MouseScrollWheelValue()) { SetVoxelSize(MyEditorVoxelHand.VoxelHandShape.GetShapeSize() - MyVoxelConstants.VOXEL_HAND_SIZE_STEP); } else if (input.PreviousMouseScrollWheelValue() < input.MouseScrollWheelValue()) { SetVoxelSize(MyEditorVoxelHand.VoxelHandShape.GetShapeSize() + MyVoxelConstants.VOXEL_HAND_SIZE_STEP); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// // Change distance of asteroid tool from camera //////////////////////////////////////////////////////////////////////////////////////////////////////////// if (input.IsAnyControlPress()) { if (input.PreviousMouseScrollWheelValue() > input.MouseScrollWheelValue()) { SetShapeDistance(GetShapeDistance() - MyVoxelConstants.VOXEL_HAND_DISTANCE_STEP); } else if (input.PreviousMouseScrollWheelValue() < input.MouseScrollWheelValue()) { SetShapeDistance(GetShapeDistance() + MyVoxelConstants.VOXEL_HAND_DISTANCE_STEP); } } */ }
/// <summary> /// Selects objects under mouse cursor /// </summary> public static void SelectByIntersectionLine(MyGuiInput input) { List<MyEntity> beforeSelectionObjects = SelectedEntities; MyEntity selectedNow = MyEntities.GetEntityUnderMouseCursor(); //TODO solve better if (selectedNow != null && selectedNow.Parent is MyPrefabBase && !(selectedNow is MyWayPoint)) { selectedNow = selectedNow.Parent; } //while transforming objects with mouse(using gizmo), do not deselect current selection if (TransformationActive == false && ActiveAxis == GizmoAxis.NONE && !(MyGuiScreenGamePlay.Static.IsIngameEditorActive() && MyEditor.Static.GetEditedPrefabContainer() == null)) { //Get selected prefab snap point // IMPORTANT: first assign snap point to local field because setter affects highlighting (ClearSelection clears highlight) var snapPoint = GetSnapPoint(false); if (snapPoint != null) { ClearSelection(); SelectedSnapPoint = snapPoint; return; } else { SelectedSnapPoint = snapPoint; } //if nothing is selected now, clear selection if (selectedNow == null && !input.IsAnyCtrlKeyPressed() && !input.IsAnyShiftKeyPressed()) { ClearSelection(); } else { //if we are in conteiner editing dont allow changes to selection outside the prefab container //allow selection of container if exit is allowed if (MyEditor.Static.IsEditingPrefabContainer()) { if (selectedNow is MyPrefabBase) { if ((selectedNow as MyPrefabBase).Parent != MyEditor.Static.GetEditedPrefabContainer()) { return; } } else if (!(MyEditor.Static.GetEditedPrefabContainer() == selectedNow && !MyGuiScreenGamePlay.Static.IsIngameEditorActive())) { return; } } // if CTRL isn't held, clear selection (otherwise add/remove from selection) if (input.IsAnyControlPress() == false && input.IsAnyShiftPress() == false) { // click a waypoint multiple times: cycle among paths if (selectedNow is MyWayPoint && beforeSelectionObjects.Contains(selectedNow)) { var pathsContainingSelectedWayPoint = (selectedNow as MyWayPoint).Paths(); int indexOfLastPath = pathsContainingSelectedWayPoint.IndexOf(MyWayPointGraph.SelectedPath); ClearSelection(); if (pathsContainingSelectedWayPoint.Count == 0) { MyWayPointGraph.SelectedPath = null; } else { // select next path (or, if it was the last one, select just the vertex) if (indexOfLastPath == pathsContainingSelectedWayPoint.Count - 1) MyWayPointGraph.SelectedPath = null; else if (indexOfLastPath == -1) MyWayPointGraph.SelectedPath = pathsContainingSelectedWayPoint[0]; else MyWayPointGraph.SelectedPath = pathsContainingSelectedWayPoint[indexOfLastPath + 1]; } if (MyWayPointGraph.SelectedPath != null) { // a path is selected: select waypoints from path in the correct order // the clicked waypoint will try to be added again later, but will be prevented from it AddEntitiesToSelection(MyWayPointGraph.SelectedPath.WayPoints); } } else { ClearSelection(); } } //When editing container(selecting prefabs inside it), it should not be possible to select any objects outside container if (MyEditor.Static.IsEditingPrefabContainer()) { //Allow selection of objects inside container, but disallow all outside BoundingSphere vol = selectedNow.WorldVolume; if (MyEditor.Static.GetEditedPrefabContainer().GetIntersectionWithMaximumBoundingBox(ref vol) == false && (selectedNow is MyPrefabBase == false)) { selectedNow = null; } // Allow selection of edited container only if exit editing mode action is allowed if (selectedNow == MyEditor.Static.GetEditedPrefabContainer()) { MyEditor.Static.ExitActivePrefabContainer(); AddEntityToSelection(selectedNow); return; } } // If selected item is child of the prefab and is not a prefab switch selection to the parent prefab: // for weapon case: if (selectedNow is MyLargeShipGunBase || selectedNow is MyLargeShipBarrelBase) { //selectedNow = ((MyLargeShipGunBase)selectedNow).PrefabParent; selectedNow = MySelectionTool.GetSelectableEntity(selectedNow); } // When selected object is prefab, switch to edit mode of prefab container immediately if (selectedNow is MyPrefabBase) { MyPrefabContainer parentContainer = (MyPrefabContainer)selectedNow.Parent; MyEditor.Static.EditPrefabContainer(parentContainer); } // CTRL held: add/remove entities to/from selection if (input.IsAnyControlPress() == true) { if (selectedNow != null) { if (IsEntitySelected(selectedNow)) { RemoveEntityFromSelection(selectedNow); } else { AddEntityToSelection(selectedNow); } // add/remove waypoints from selected waypoint path MyWayPointGraph.UpdateSelectedPath(); } } else if (!input.IsAnyShiftPress()) { if (selectedNow != null) { AddEntityToSelection(selectedNow); /* if (selectedNow is MyPrefabLargeWeapon) { AddEntityToSelection(((MyPrefabLargeWeapon)selectedNow).GetGun()); } */ } } } // play sound: MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorObjectSelect); } //There is new selection made compared to previous selection, reload control buttons if ((beforeSelectionObjects.Count > 0 && beforeSelectionObjects.Contains(selectedNow) == false) || (beforeSelectionObjects.Count == 0 && selectedNow != null) || (beforeSelectionObjects.Count > 0 && selectedNow == null)) { MyEditor.Static.ReloadEditorControls = true; } }