Пример #1
0
        public override void HandleInput()
        {
            base.HandleInput();

            if (!(MyScreenManager.GetScreenWithFocus() is MyGuiScreenGamePlay))
            {
                return;
            }

            if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION))
            {
                if (MySession.ControlledEntity != null && BotToSpawn != null)
                {
                    TrySpawnBot();
                }
                if (MySession.ControlledEntity != null && CommandDefinition != null)
                {
                    UseCommand();
                }
                if (MySession.ControlledEntity != null && AreaMarkerDefinition != null)
                {
                    PlaceAreaMarker();
                }
            }
        }
Пример #2
0
        public override void HandleInput()
        {
            ProfilerShort.Begin("MyToolbarComponent.HandleInput");
            try
            {
                var context       = MySession.ControlledEntity != null ? MySession.ControlledEntity.ControlContext : MyStringId.NullOrEmpty;
                var focusedScreen = MyScreenManager.GetScreenWithFocus();
                if ((focusedScreen == MyGuiScreenGamePlay.Static ||
                     focusedScreen is MyGuiScreenCubeBuilder ||
                     focusedScreen is MyGuiScreenToolbarConfigBase) &&
                    CurrentToolbar != null)
                {
                    // if (!(focusedScreen is MyGuiScreenCubeBuilder) || !(focusedScreen.FocusedControl is MyGuiControlTextbox))
                    {
                        for (int i = 0; i < m_slotControls.Length; i++)
                        {
                            if (MyControllerHelper.IsControl(context, m_slotControls[i], MyControlStateType.NEW_PRESSED))
                            {
                                if (!MyInput.Static.IsAnyShiftKeyPressed())
                                {
                                    CurrentToolbar.ActivateItemAtSlot(i);
                                }
                                else if (i < CurrentToolbar.PageCount)
                                {
                                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                                    CurrentToolbar.SwitchToPage(i);
                                }
                            }
                        }
                    }

                    if (MyControllerHelper.IsControl(context, MyControlsSpace.TOOLBAR_UP, MyControlStateType.NEW_PRESSED))
                    {
                        MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                        CurrentToolbar.PageUp();
                    }
                    if (MyControllerHelper.IsControl(context, MyControlsSpace.TOOLBAR_DOWN, MyControlStateType.NEW_PRESSED))
                    {
                        MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                        CurrentToolbar.PageDown();
                    }

                    if (MyControllerHelper.IsControl(context, MyControlsSpace.TOOLBAR_NEXT_ITEM, MyControlStateType.NEW_PRESSED))
                    {
                        CurrentToolbar.SelectNextSlot();
                    }
                    else if (MyControllerHelper.IsControl(context, MyControlsSpace.TOOLBAR_PREV_ITEM, MyControlStateType.NEW_PRESSED))
                    {
                        CurrentToolbar.SelectPreviousSlot();
                    }
                }
            }
            finally
            {
                ProfilerShort.End();
            }

            base.HandleInput();
        }
        /// <summary>
        /// Button callback for the workshop world button, to open the workshop world screen
        /// </summary>
        /// <param name="myGuiControlButton">Clicked button</param>
        private void OnWorkshopButtonClick(MyGuiControlButton myGuiControlButton)
        {
            MyGuiScreenBase screenWithFocus = MyScreenManager.GetScreenWithFocus();

            if (!(screenWithFocus is MyGuiScreenNewWorkshopGame))
            {
                SeamlesslyChangeScreen(screenWithFocus, new PluginGuiScreenWorkshopGame());
            }
        }
        /// <summary>
        /// Button callback for the custom world button, to open the custom world screen
        /// </summary>
        /// <param name="myGuiControlButton">Clicked button</param>
        private void OnCustomWorldButtonClick(MyGuiControlButton myGuiControlButton)
        {
            MyGuiScreenBase screenWithFocus = MyScreenManager.GetScreenWithFocus();

            if (!(screenWithFocus is MyGuiScreenWorldSettings))
            {
                SeamlesslyChangeScreen(screenWithFocus, new PluginWorldSettings());
            }
        }
        private void OnCustomWorldButtonClick(MyGuiControlButton myGuiControlButton)
        {
            var focused = MyScreenManager.GetScreenWithFocus();

            if (focused is MyGuiScreenWorldSettings)
            {
                return;
            }
            SeamlesslyChangeScreen(focused, new MyGuiScreenWorldSettings());
        }
        private void OnCampaignButtonClick(MyGuiControlButton myGuiControlButton)
        {
            var focused = MyScreenManager.GetScreenWithFocus();

            if (focused is MyGuiScreenNewGame)
            {
                return;
            }
            SeamlesslyChangeScreen(focused, new MyGuiScreenNewGame());
        }
        private void OnWorshopButtonClick(MyGuiControlButton myGuiControlButton)
        {
            var focused = MyScreenManager.GetScreenWithFocus();

            if (focused is MyGuiScreenLoadSubscribedWorld)
            {
                return;
            }
            SeamlesslyChangeScreen(focused, new MyGuiScreenLoadSubscribedWorld());
        }
        public static T EnsureFocusedScreen <T>() where T : MyGuiScreenBase
        {
            MyGuiScreenBase baseScreen = MyScreenManager.GetScreenWithFocus();

            if (!(baseScreen is T screen))
            {
                throw new InvalidOperationException(
                          $"Screen of type {typeof(T)} does not have focus, {baseScreen} has.");
            }
            return(screen);
        }
        public override bool HandleInput()
        {
            if (MySession.Static == null)
            {
                return(false);
            }
            if (MyScreenManager.GetScreenWithFocus() is MyGuiScreenDialogInventoryCheat)
            {
                return(false);
            }

            return(base.HandleInput());
        }
Пример #10
0
 public override void HandleInput()
 {
     base.HandleInput();
     if ((MyScreenManager.GetScreenWithFocus() is MyGuiScreenGamePlay) && MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED, false))
     {
         if ((MySession.Static.ControlledEntity != null) && (this.BotToSpawn != null))
         {
             this.TrySpawnBot();
         }
         if ((MySession.Static.ControlledEntity != null) && (this.CommandDefinition != null))
         {
             this.UseCommand();
         }
     }
 }
Пример #11
0
 public override void HandleInput()
 {
     if ((this.m_isActive && (MyScreenManager.GetScreenWithFocus() is MyGuiScreenGamePlay)) && ((MyInput.Static.ENABLE_DEVELOPER_KEYS || !MySession.Static.SurvivalMode) || MySession.Static.IsUserAdmin(Sync.MyId)))
     {
         base.HandleInput();
         if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED, false))
         {
             this.m_startTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
         }
         if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_RELEASED, false))
         {
             MyObjectBuilder_CubeGrid[] gridPrefab = MyPrefabManager.Static.GetGridPrefab(this.CurrentDefinition.PrefabToThrow);
             Vector3D zero    = Vector3D.Zero;
             Vector3D forward = Vector3D.Zero;
             if (USE_SPECTATOR_FOR_THROW)
             {
                 zero    = MySpectator.Static.Position;
                 forward = MySpectator.Static.Orientation.Forward;
             }
             else if ((MySession.Static.GetCameraControllerEnum() != MyCameraControllerEnum.ThirdPersonSpectator) && (MySession.Static.GetCameraControllerEnum() != MyCameraControllerEnum.Entity))
             {
                 zero    = MySector.MainCamera.Position;
                 forward = MySector.MainCamera.WorldMatrix.Forward;
             }
             else
             {
                 if (MySession.Static.ControlledEntity == null)
                 {
                     return;
                 }
                 zero    = MySession.Static.ControlledEntity.GetHeadMatrix(true, true, false, false).Translation;
                 forward = MySession.Static.ControlledEntity.GetHeadMatrix(true, true, false, false).Forward;
             }
             Vector3D vectord3 = zero + forward;
             Vector3D vectord4 = (forward * MathHelper.Clamp(((((float)(MySandboxGame.TotalGamePlayTimeInMilliseconds - this.m_startTime)) / 1000f) / this.CurrentDefinition.PushTime) * this.CurrentDefinition.MaxSpeed, this.CurrentDefinition.MinSpeed, this.CurrentDefinition.MaxSpeed)) + MySession.Static.ControlledEntity.Entity.Physics.LinearVelocity;
             float    num2     = 0f;
             if (this.CurrentDefinition.Mass != null)
             {
                 num2 = MyDestructionHelper.MassToHavok(this.CurrentDefinition.Mass.Value);
             }
             gridPrefab[0].EntityId = MyEntityIdentifier.AllocateId(MyEntityIdentifier.ID_OBJECT_TYPE.ENTITY, MyEntityIdentifier.ID_ALLOCATION_METHOD.RANDOM);
             EndpointId targetEndpoint = new EndpointId();
             Vector3D?  position       = null;
             MyMultiplayer.RaiseStaticEvent <MyObjectBuilder_CubeGrid, Vector3D, Vector3D, float, MyCueId>(s => new Action <MyObjectBuilder_CubeGrid, Vector3D, Vector3D, float, MyCueId>(MySessionComponentThrower.OnThrowMessageSuccess), gridPrefab[0], vectord3, vectord4, num2, this.CurrentDefinition.ThrowSound, targetEndpoint, position);
             this.m_startTime = 0;
         }
     }
 }
Пример #12
0
        public void WaitUntilTheGameLoaded()
        {
            const int timeoutMs     = 60_000;
            const int singleSleepMs = 100;
            const int sleepAfter    = 2000;

            for (var i = 0; i < timeoutMs / singleSleepMs; i++)
            {
                Thread.Sleep(singleSleepMs);
                if (!(MyScreenManager.GetScreenWithFocus() is MyGuiScreenLoading))
                {
                    Thread.Sleep(sleepAfter);
                    return;
                }
            }

            throw new TimeoutException();
        }
Пример #13
0
        public override bool HandleInput()
        {
            if (MySession.Static == null)
            {
                return(false);
            }

            if (MyScreenManager.GetScreenWithFocus() is MyGuiScreenDialogPrefabCheat)
            {
                return(false);
            }
            if (MyScreenManager.GetScreenWithFocus() is MyGuiScreenDialogRemoveTriangle)
            {
                return(false);
            }
            if (MyScreenManager.GetScreenWithFocus() is MyGuiScreenDialogViewEdge)
            {
                return(false);
            }

            return(base.HandleInput());
        }
Пример #14
0
 public string FocusedScreen()
 {
     return(MyScreenManager.GetScreenWithFocus().DisplayName());
 }
Пример #15
0
        private void UpdateManipulation()
        {
            if (m_state != MyState.NONE && SafeConstraint != null)
            {
                const float fixedConstraintMaxValue    = 1000;
                const float fixedConstraintMaxDistance = 2f;
                const float ballAndSocketMaxDistance   = 2f;

                MyTimeSpan constraintPrepareTime = MyTimeSpan.FromSeconds(1.0f);
                MyTimeSpan currentTimeDelta      = MySandboxGame.Static.UpdateTime - m_constraintCreationTime;

                MatrixD headWorldMatrix       = Owner.GetHeadMatrix(false, forceHeadBone: true);
                MatrixD worldHeadPivotMatrix  = m_headLocalPivotMatrix * headWorldMatrix;
                MatrixD worldOtherPivotMatrix = m_otherLocalPivotMatrix * m_otherEntity.PositionComp.WorldMatrix;

                double length   = (worldOtherPivotMatrix.Translation - worldHeadPivotMatrix.Translation).Length();
                double checkDst = m_fixedConstraintData != null ? fixedConstraintMaxDistance : ballAndSocketMaxDistance;

                if (currentTimeDelta > constraintPrepareTime)
                {
                    var  characterMovementState = Owner.GetCurrentMovementState();
                    bool currentCanUseIdle      = CanManipulate(characterMovementState);
                    bool previousCanUseIdle     = CanManipulate(m_previousCharacterMovementState);

                    if ((!m_constraintInitialized && currentCanUseIdle) || (currentCanUseIdle && !previousCanUseIdle))
                    {
                        if (m_state == MyState.HOLD)
                        {
                            Owner.PlayCharacterAnimation("PickLumberIdle", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f);
                        }
                        else
                        {
                            Owner.PlayCharacterAnimation("PullLumberIdle", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f);
                        }
                    }

                    m_previousCharacterMovementState = characterMovementState;

                    m_constraintInitialized = true;

                    if (m_otherRigidBody != null && !MyFakes.MANIPULATION_TOOL_VELOCITY_LIMIT)
                    {
                        m_otherRigidBody.MaxLinearVelocity  = m_otherMaxLinearVelocity;
                        m_otherRigidBody.MaxAngularVelocity = m_otherMaxAngularVelocity;
                    }

                    if (m_fixedConstraintData != null && (MyScreenManager.GetScreenWithFocus() is MyGuiScreenGamePlay))
                    {
                        float rotationSpeed = MyInput.Static.IsAnyShiftKeyPressed() ? -0.01f : 0.01f;
                        var   tran          = m_otherLocalPivotMatrix.Translation;
                        if (MyInput.Static.IsKeyPress(MyKeys.E))
                        {
                            m_otherLocalPivotMatrix             = m_otherLocalPivotMatrix * Matrix.CreateFromAxisAngle(Vector3.Up, rotationSpeed);
                            m_otherLocalPivotMatrix.Translation = tran;
                            m_fixedConstraintData.SetInBodySpace(m_otherLocalPivotMatrix, m_headLocalPivotMatrix, m_otherPhysicsBody, OwnerVirtualPhysics);
                        }
                        if (MyInput.Static.IsKeyPress(MyKeys.Q))
                        {
                            m_otherLocalPivotMatrix             = m_otherLocalPivotMatrix * Matrix.CreateFromAxisAngle(Vector3.Forward, rotationSpeed);
                            m_otherLocalPivotMatrix.Translation = tran;
                            m_fixedConstraintData.SetInBodySpace(m_otherLocalPivotMatrix, m_headLocalPivotMatrix, m_otherPhysicsBody, OwnerVirtualPhysics);
                        }
                        if (MyInput.Static.IsKeyPress(MyKeys.R))
                        {
                            m_otherLocalPivotMatrix             = m_otherLocalPivotMatrix * Matrix.CreateFromAxisAngle(Vector3.Right, rotationSpeed);
                            m_otherLocalPivotMatrix.Translation = tran;
                            m_fixedConstraintData.SetInBodySpace(m_otherLocalPivotMatrix, m_headLocalPivotMatrix, m_otherPhysicsBody, OwnerVirtualPhysics);
                        }
                    }

                    if (m_fixedConstraintData != null && !MyFakes.MANIPULATION_TOOL_VELOCITY_LIMIT)
                    {
                        m_fixedConstraintData.MaximumAngularImpulse = fixedConstraintMaxValue;
                        m_fixedConstraintData.MaximumLinearImpulse  = fixedConstraintMaxValue;

                        // Check angle between pivots
                        float upDot    = Math.Abs(Vector3.Dot(worldHeadPivotMatrix.Up, worldOtherPivotMatrix.Up));
                        float rightDot = Math.Abs(Vector3.Dot(worldHeadPivotMatrix.Right, worldOtherPivotMatrix.Right));
                        if (upDot < 0.5f || rightDot < 0.5f)
                        {
                            // Synced from local player because lagged server can drop manipulated items with fast moves
                            if (!(m_otherEntity is MyCharacter) && IsOwnerLocalPlayer())
                            {
                                SyncTool.StopManipulation();
                            }

                            return;
                        }
                    }

                    // Check length between pivots
                    if (length > checkDst)
                    {
                        // Synced from local player because lagged server can drop manipulated items with fast moves
                        if (!(m_otherEntity is MyCharacter) && IsOwnerLocalPlayer())
                        {
                            SyncTool.StopManipulation();
                        }

                        return;
                    }
                }
                else
                {
                    if (m_fixedConstraintData != null && !MyFakes.MANIPULATION_TOOL_VELOCITY_LIMIT)
                    {
                        float t = (float)(currentTimeDelta.Miliseconds / constraintPrepareTime.Miliseconds);
                        t *= t;
                        t *= t; //pow4
                        float value = t * fixedConstraintMaxValue;
                        m_fixedConstraintData.MaximumAngularImpulse = value;
                        m_fixedConstraintData.MaximumLinearImpulse  = value;

                        if (length > checkDst)
                        {
                            var characterMovementState = Owner.GetCurrentMovementState();
                            if (!CanManipulate(characterMovementState))
                            {
                                // Synced from local player because lagged server can drop manipulated items with fast moves
                                if (!(m_otherEntity is MyCharacter) && IsOwnerLocalPlayer())
                                {
                                    SyncTool.StopManipulation();
                                }

                                return;
                            }
                        }
                    }
                }
            }
        }
Пример #16
0
        public override void Draw()
        {
            base.Draw();

            if (MySector.MainCamera != null)
            {
                var pos = MySector.MainCamera.Position;
                var dir = MySector.MainCamera.ForwardVector;
                var hit = MyPhysics.CastRay(pos, pos + 500 * dir);
                if (hit.HasValue)
                {
                    var entity = hit.Value.HkHitInfo.GetHitEntity();
                    if (entity != null)
                    {
                        var voxel = entity.GetTopMostParent() as MyVoxelPhysics;
                        if (voxel != null)
                        {
                            var planet = voxel.Parent;
                            var grav   = planet as IMyGravityProvider;
                            if (grav != null)
                            {
                                var gravity = grav.GetWorldGravity(hit.Value.Position);
                                gravity.Normalize();
                                var point = planet.PositionComp.GetPosition() - gravity * 9503;
                                MyRenderProxy.DebugDrawSphere(point, 0.5f, Color.Red, 1, false);
                                MyRenderProxy.DebugDrawSphere(point, 5.5f, Color.Yellow, 1, false);
                                hit = MyPhysics.CastRay(point, point + gravity * 500);
                                if (hit.HasValue)
                                {
                                    MyRenderProxy.DebugDrawText2D(new Vector2(10, 10), (hit.Value.HkHitInfo.HitFraction * 500).ToString(), Color.White, 0.8f);
                                }
                            }
                        }
                    }
                }
            }
            if (!MyDebugDrawSettings.ENABLE_DEBUG_DRAW)
            {
                return;
            }

            if (MyCubeBuilder.Static == null)
            {
                return;
            }

            if (m_smartPath != null)
            {
                m_smartPath.DebugDraw();
                VRageRender.MyRenderProxy.DebugDrawSphere(m_currentTarget, 2.0f, Color.HotPink, 1.0f, false);
                for (int i = 1; i < m_pastTargets.Count; ++i)
                {
                    VRageRender.MyRenderProxy.DebugDrawLine3D(m_pastTargets[i], m_pastTargets[i - 1], Color.Blue, Color.Blue, false);
                }
            }

            var bb = MyCubeBuilder.Static.GetBuildBoundingBox();

            VRageRender.MyRenderProxy.DebugDrawOBB(bb, Color.Red, 0.25f, false, false);

            var src = MyScreenManager.GetScreenWithFocus();

            if (MyScreenManager.GetScreenWithFocus() == null || MyScreenManager.GetScreenWithFocus().DebugNamePath != "MyGuiScreenGamePlay")
            {
                return;
            }

            if (m_drawSphere)
            {
                VRageRender.MyRenderProxy.DebugDrawSphere(m_sphere.Center, m_sphere.Radius, Color.Red, 1.0f, false, cull: true);
                VRageRender.MyRenderProxy.DebugDrawAxis(m_sphereMatrix, 50.0f, false);
                VRageRender.MyRenderProxy.DebugDrawText2D(new Vector2(200.0f, 0.0f), m_string, Color.Red, 0.5f);
            }


            VRageRender.MyRenderProxy.DebugDrawSphere(m_point1, 0.5f, Color.Orange.ToVector3(), 1.0f, true);
            VRageRender.MyRenderProxy.DebugDrawSphere(m_point2, 0.5f, Color.Orange.ToVector3(), 1.0f, true);

            foreach (var point in DebugDrawPoints)
            {
                //VRageRender.MyRenderProxy.DebugDrawSphere(point.Position, 0.05f, point.Color.ToVector3(), 1.0f, false);
                VRageRender.MyRenderProxy.DebugDrawSphere(point.Position, 0.03f, point.Color, 1.0f, false);
            }

            foreach (var sphere in DebugDrawSpheres)
            {
                VRageRender.MyRenderProxy.DebugDrawSphere(sphere.Position, sphere.Radius, sphere.Color, 1.0f, false);
            }

            foreach (var box in DebugDrawBoxes)
            {
                VRageRender.MyRenderProxy.DebugDrawAABB(box.Box, box.Color, 1.0f, 1.0f, false);
            }

            if (DebugDrawMesh != null)
            {
                Matrix identity = Matrix.Identity;
                DebugDrawMesh.DebugDraw(ref identity, MyDebugDrawSettings.DEBUG_DRAW_NAVMESHES);
            }

            foreach (var poly in DebugDrawPolys)
            {
                MatrixD identity = MatrixD.Identity;
                poly.DebugDraw(ref identity);
            }

            MyPolygonBoolOps.Static.DebugDraw(MatrixD.Identity);

            if (Boxes != null)
            {
                foreach (var box in Boxes)
                {
                    VRageRender.MyRenderProxy.DebugDrawAABB(box, Color.Red, 1.0f, 1.0f, true);
                }
            }
        }
Пример #17
0
        public override void HandleInput()
        {
            ProfilerShort.Begin("MyToolbarComponent.HandleInput");
            try
            {
                var context       = MySession.Static.ControlledEntity != null ? MySession.Static.ControlledEntity.ControlContext : MyStringId.NullOrEmpty;
                var focusedScreen = MyScreenManager.GetScreenWithFocus();
                if ((focusedScreen == MyGuiScreenGamePlay.Static ||
                     IsToolbarControlShown) &&
                    CurrentToolbar != null && !MyGuiScreenGamePlay.DisableInput)
                {
                    {
                        for (int i = 0; i < m_slotControls.Length; i++)
                        {
                            if (MyControllerHelper.IsControl(context, m_slotControls[i], MyControlStateType.NEW_PRESSED))
                            {
                                if (!MyInput.Static.IsAnyCtrlKeyPressed())
                                {
                                    if ((focusedScreen is MyGuiScreenScriptingTools || focusedScreen == MyGuiScreenGamePlay.Static ||
                                         (focusedScreen is MyGuiScreenCubeBuilder || focusedScreen is MyGuiScreenToolbarConfigBase) && ((MyGuiScreenToolbarConfigBase)focusedScreen).AllowToolbarKeys()) &&
                                        CurrentToolbar != null)
                                    {
                                        CurrentToolbar.ActivateItemAtSlot(i);
                                    }
                                }
                                else if (i < CurrentToolbar.PageCount)
                                {
                                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                                    CurrentToolbar.SwitchToPage(i);
                                }
                            }
                        }
                    }

                    if ((focusedScreen == MyGuiScreenGamePlay.Static ||
                         (focusedScreen is MyGuiScreenCubeBuilder || focusedScreen is MyGuiScreenToolbarConfigBase) && ((MyGuiScreenToolbarConfigBase)focusedScreen).AllowToolbarKeys()) &&
                        CurrentToolbar != null)
                    {
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.TOOLBAR_NEXT_ITEM, MyControlStateType.NEW_PRESSED))
                        {
                            CurrentToolbar.SelectNextSlot();
                        }
                        else if (MyControllerHelper.IsControl(context, MyControlsSpace.TOOLBAR_PREV_ITEM, MyControlStateType.NEW_PRESSED))
                        {
                            CurrentToolbar.SelectPreviousSlot();
                        }
                        if (MySpectator.Static.SpectatorCameraMovement != MySpectatorCameraMovementEnum.ConstantDelta)
                        {
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.TOOLBAR_UP, MyControlStateType.NEW_PRESSED))
                            {
                                MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                                CurrentToolbar.PageUp();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.TOOLBAR_DOWN, MyControlStateType.NEW_PRESSED))
                            {
                                MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                                CurrentToolbar.PageDown();
                            }
                        }
                    }
                }
            }
            finally
            {
                ProfilerShort.End();
            }

            base.HandleInput();
        }
        public override void HandleInput()
        {
            if (!m_isActive)
            {
                return;
            }
            if (!(MyScreenManager.GetScreenWithFocus() is MyGuiScreenGamePlay))
            {
                return;
            }

            if (!
                (VRage.Input.MyInput.Static.ENABLE_DEVELOPER_KEYS || !MySession.Static.SurvivalMode || (MyMultiplayer.Static != null && MyMultiplayer.Static.IsAdmin(MySession.Static.LocalHumanPlayer.Id.SteamId)))
                )
            {
                return;
            }


            base.HandleInput();

            if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED))
            {
                m_startTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            }

            if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_RELEASED))
            {
                var gridBuilders = MyPrefabManager.Static.GetGridPrefab(CurrentDefinition.PrefabToThrow);

                Vector3D cameraPos = Vector3D.Zero;
                Vector3D cameraDir = Vector3D.Zero;

                if (USE_SPECTATOR_FOR_THROW)
                {
                    cameraPos = MySpectator.Static.Position;
                    cameraDir = MySpectator.Static.Orientation.Forward;
                }
                else
                {
                    if (MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator || MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Entity)
                    {
                        if (MySession.Static.ControlledEntity == null)
                        {
                            return;
                        }

                        cameraPos = MySession.Static.ControlledEntity.GetHeadMatrix(true, true).Translation;
                        cameraDir = MySession.Static.ControlledEntity.GetHeadMatrix(true, true).Forward;
                    }
                    else
                    {
                        cameraPos = MySector.MainCamera.Position;
                        cameraDir = MySector.MainCamera.WorldMatrix.Forward;
                    }
                }

                var position = cameraPos + cameraDir;

                float deltaSeconds = (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_startTime) / 1000.0f;
                float velocity     = deltaSeconds / CurrentDefinition.PushTime * CurrentDefinition.MaxSpeed;
                velocity = MathHelper.Clamp(velocity, CurrentDefinition.MinSpeed, CurrentDefinition.MaxSpeed);
                var   linearVelocity = cameraDir * velocity + MySession.Static.ControlledEntity.Entity.Physics.LinearVelocity;
                float mass           = 0;
                if (CurrentDefinition.Mass.HasValue)
                {
                    mass = Sandbox.Engine.Physics.MyDestructionHelper.MassToHavok(CurrentDefinition.Mass.Value);
                }

                gridBuilders[0].EntityId = MyEntityIdentifier.AllocateId();
                MyMultiplayer.RaiseStaticEvent(s => MySessionComponentThrower.OnThrowMessageSuccess, gridBuilders[0], position, linearVelocity, mass, CurrentDefinition.ThrowSound);

                m_startTime = 0;
            }
        }
Пример #19
0
        //Game and editor shares this method
        public void MoveAndRotatePlayerOrCamera()
        {
            MyCameraControllerEnum cce  = MySession.GetCameraControllerEnum();
            bool movementAllowedInPause = cce == MyCameraControllerEnum.Spectator;
            bool rotationAllowedInPause = movementAllowedInPause ||
                                          (cce == MyCameraControllerEnum.ThirdPersonSpectator && MyInput.Static.IsAnyAltKeyPressed());
            bool devScreenFlag = MyScreenManager.GetScreenWithFocus() is MyGuiScreenDebugBase && !MyInput.Static.IsAnyAltKeyPressed();

            bool    allowRoll         = !MySessionComponentVoxelHand.Static.BuildMode;
            bool    allowMove         = !MySessionComponentVoxelHand.Static.BuildMode && !MyCubeBuilder.Static.IsBuildMode;
            float   rollIndicator     = allowRoll ? MyInput.Static.GetRoll() : 0;
            Vector2 rotationIndicator = MyInput.Static.GetRotation();

            VRageMath.Vector3 moveIndicator = allowMove ? MyInput.Static.GetPositionDelta() : Vector3.Zero;

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////  Decide who is moving
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //First move control objects
            if (MySession.ControlledEntity != null)// && MySession.ControlledObject != MySession.Static.CameraController)
            {
                if (MySandboxGame.IsPaused)
                {
                    if (!movementAllowedInPause && !rotationAllowedInPause)
                    {
                        return;
                    }

                    if (!rotationAllowedInPause || devScreenFlag)
                    {
                        rotationIndicator = Vector2.Zero;
                    }
                    rollIndicator = 0.0f;
                }
                if (MySession.Static.CameraController is MySpectatorCameraController && MySpectatorCameraController.Static.SpectatorCameraMovement == MySpectatorCameraMovementEnum.UserControlled)
                {
                    MySpectatorCameraController.Static.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
                }
                else
                {
                    if (!MySession.Static.CameraController.IsInFirstPersonView)
                    {
                        MyThirdPersonSpectator.Static.UpdateZoom();
                    }

                    if (!MyInput.Static.IsGameControlPressed(MyControlsSpace.LOOKAROUND))
                    {
                        MySession.ControlledEntity.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
                    }
                    else
                    {
                        if (MySession.ControlledEntity is MyRemoteControl)                         // Stop the remotely controlled entity from rolling when the character tries to in freelook mode
                        {
                            rollIndicator = 0f;
                        }

                        MySession.ControlledEntity.MoveAndRotate(moveIndicator, Vector2.Zero, rollIndicator);
                        if (!MySession.Static.CameraController.IsInFirstPersonView)
                        {
                            MyThirdPersonSpectator.Static.SaveSettings();
                        }
                    }
                }
            }
        }