Example #1
0
        private void OnControlReleased(MyEntityController controller)
        {
            Static_CameraAttachedToChanged(null, null);
            m_oldController = controller;

            if (MySession.Static.LocalHumanPlayer == controller.Player)
            {
                MyHud.SelectedObjectHighlight.RemoveHighlight();

                RemoveNotifications();

                if (MyGuiScreenGamePlay.Static != null)
                    MySession.Static.CameraAttachedToChanged -= Static_CameraAttachedToChanged;

                m_cameraShake = null;
                m_cameraSpring = null;

                MyHud.GravityIndicator.Hide();
                MyHud.CharacterInfo.Hide();
                m_suitBattery.OwnedByLocalPlayer = false;
                MyHud.LargeTurretTargets.Visible = false;
                MyHud.OreMarkers.Visible = false;
                RadioReceiver.Clear();
                if (MyGuiScreenGamePlay.ActiveGameplayScreen != null)
                    MyGuiScreenGamePlay.ActiveGameplayScreen.CloseScreen();

                ResetMovement();
            }
            else
            {
                if (!MyFakes.ENABLE_RADIO_HUD)
                {
                    MyHud.LocationMarkers.UnregisterMarker(this);
                }
            }

            SoundComp.StopStateSound(true);

            // Note: This event was currently registered in init and never unregistered, when the character control is released, we unregister from the event handler
            {
                MyToolbarComponent.CharacterToolbar.ItemChanged -= Toolbar_ItemChanged;  // OM: The Init can be called on one instance several times (changing color etc.). We need to unregister first, otherwise we get this event registered even more than 11 times for one instance..
            }
        }
Example #2
0
        private void OnControlAcquired(MyEntityController controller)
        {
            if (controller.Player.IsLocalPlayer)
            {
                bool isHuman = controller.Player == MySession.Static.LocalHumanPlayer;
                if (isHuman)
                {
                    MyHud.HideAll();
                    MyHud.Crosshair.ResetToDefault();
                    MyHud.Crosshair.Recenter();

                    if (MyGuiScreenGamePlay.Static != null)
                        MySession.Static.CameraAttachedToChanged += Static_CameraAttachedToChanged;

                    if (MySession.Static.CameraController is MyEntity)
                        MySession.Static.SetCameraController(IsInFirstPersonView ? MyCameraControllerEnum.Entity : MyCameraControllerEnum.ThirdPersonSpectator, this);

                    m_cameraShake = new MyCameraHeadShake();
                    m_cameraSpring = new MyCameraSpring(this.Physics);

                    MyHud.GravityIndicator.Entity = this;
                    MyHud.GravityIndicator.Show(null);
                    MyHud.CharacterInfo.Show(null);
                    MyHud.OreMarkers.Visible = true;
                    MyHud.LargeTurretTargets.Visible = true;
                    if (MySession.Static.IsScenario)
                        MyHud.ScenarioInfo.Show(null);
                }

                //Enable features for local player
                var jetpack = JetpackComp;
                if (jetpack != null)
                    jetpack.TurnOnJetpack(jetpack.TurnedOn);

                m_suitBattery.OwnedByLocalPlayer = true;
                DisplayName = controller.Player.Identity.DisplayName;
            }
            else
            {
                DisplayName = controller.Player.Identity.DisplayName;
                UpdateHudMarker();
            }

            if (StatComp != null && StatComp.Health != null && StatComp.Health.Value <= 0.0f)
            {
                m_dieAfterSimulation = true;
                return;
            }

            if (m_currentWeapon != null)
                m_currentWeapon.OnControlAcquired(this);

            UpdateCharacterPhysics(controller.Player.IsLocalPlayer);

            // Note: This code was part of the init, this event got registered for all characters, and never unregistered..            
            if (this == MySession.Static.ControlledEntity && MyToolbarComponent.CharacterToolbar != null)
            {
                MyToolbarComponent.CharacterToolbar.ItemChanged -= Toolbar_ItemChanged;  // OM: The Init or this can be called on one instance several times (changing color etc.). We need to unregister first, otherwise we get this event registered even more than 11 times for one instance..
                MyToolbarComponent.CharacterToolbar.ItemChanged += Toolbar_ItemChanged;
            }
        }