public void Update()
        {
            if (MySession.Static.ControlledEntity != null)
            {
                float maxDistance = MyEntities.WorldHalfExtent();

                var dist = MySession.Static.ControlledEntity.Entity != null?MySession.Static.ControlledEntity.Entity.PositionComp.GetPosition().AbsMax() : 0.0f;

                if (maxDistance != 0.0f && MySession.Static.ControlledEntity.Entity != null && maxDistance - dist < WARNING_DISTANCE)
                {
                    var d = maxDistance - dist > 0.0f ? maxDistance - dist : 0.0f;
                    if (MySession.Static.SurvivalMode)
                    {
                        m_notification.SetTextFormatArguments(d);
                        MyHud.Notifications.Add(m_notification);
                    }
                    else
                    {
                        m_notificationCreative.SetTextFormatArguments(d);
                        MyHud.Notifications.Add(m_notificationCreative);
                    }
                    WorldCenterHintVisible = true;
                }
                else
                {
                    MyHud.Notifications.Remove(m_notification);
                    MyHud.Notifications.Remove(m_notificationCreative);
                    WorldCenterHintVisible = false;
                }
            }
        }
예제 #2
0
        public static MyHudNotification CreateControlNotification(MyStringId textId, params object[] args)
        {
            var notification = new MyHudNotification(text: textId, disappearTimeMs: 0, level: MyNotificationLevel.Control);

            notification.SetTextFormatArguments(args);
            return(notification);
        }
예제 #3
0
        static MyCameraBlock()
        {
            var viewBtn = new MyTerminalControlButton<MyCameraBlock>("View", MySpaceTexts.BlockActionTitle_View, MySpaceTexts.Blank, (b) => b.RequestSetView());
            viewBtn.Enabled = (b) => b.CanUse();
            viewBtn.SupportsMultipleBlocks = false;
            var action = viewBtn.EnableAction(MyTerminalActionIcons.TOGGLE);
            if (action != null)
            {
                action.InvalidToolbarTypes = new List<MyToolbarType> { MyToolbarType.ButtonPanel };
                action.ValidForGroups = false;
            }
            MyTerminalControlFactory.AddControl(viewBtn);

            var controlName = MyInput.Static.GetGameControl(MyControlsSpace.USE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard);
            m_hudNotification = new MyHudNotification(MySpaceTexts.NotificationHintPressToExitCamera);
            m_hudNotification.SetTextFormatArguments(controlName);
        }
            public MyGuiControlStat(MyEntityStat stat, Vector2 position, Vector2 size, MyGuiDrawAlignEnum originAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER)
				: base(position: position, size: size, originAlign: originAlign)
            {
				Debug.Assert(stat != null);
				m_stat = stat;
                var vecColor = m_stat.StatDefinition.GuiDef.CriticalColorFrom;
                m_criticalValueColorFrom = new Color(vecColor.X, vecColor.Y, vecColor.Z);
                vecColor = m_stat.StatDefinition.GuiDef.CriticalColorTo;
                m_criticalValueColorTo = new Color(vecColor.X, vecColor.Y, vecColor.Z);
				if(m_stat != null)
				{
					m_stat.OnStatChanged += UpdateStatControl;
                    m_stat.OnStatChanged += DisplayStatNotification;
                    m_outOfStatNotification = new MyHudNotification(MyCommonTexts.NotificationStatZero, disappearTimeMs: 1000, font: MyFontEnum.Red, level: MyNotificationLevel.Important);
                    m_outOfStatNotification.SetTextFormatArguments(m_stat.StatId.ToString());
				}
            }
예제 #5
0
        public MyAngleGrinder()
            : base(MyDefinitionManager.Static.TryGetHandItemForPhysicalItem(m_physicalItemId), 0.5f, 250)
        {
            SecondaryLightIntensityLower = 0.4f;
            SecondaryLightIntensityUpper = 0.4f;
            EffectId = MyParticleEffectsIDEnum.AngleGrinder;

            HasCubeHighlight = true;
            HighlightColor = Color.Red * 0.3f;

            m_grindingNotification = new MyHudNotification(MySpaceTexts.AngleGrinderPrimaryAction, MyHudNotification.INFINITE, level: MyNotificationLevel.Control);
            m_grindingNotification.SetTextFormatArguments(MyInput.Static.GetGameControl(MyControlsSpace.PRIMARY_TOOL_ACTION));

            m_rotationSpeed = 0.0f;

            PhysicalObject = (MyObjectBuilder_PhysicalGunObject)MyObjectBuilderSerializer.CreateNewObject(m_physicalItemId);
        }
예제 #6
0
 public static MyHudNotification CreateControlNotification(MyStringId textId, params object[] args)
 {
     var notification = new MyHudNotification(text: textId, disappearTimeMs: 0, level: MyNotificationLevel.Control);
     notification.SetTextFormatArguments(args);
     return notification;
 }
예제 #7
0
        private void RefreshControlNotifications()
        {
            RemoveControlNotifications();

            if (m_notificationReactorsOn == null)
            {
                var controlName = MyInput.Static.GetGameControl(MyControlsSpace.TOGGLE_REACTORS).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard);
                m_notificationReactorsOn = new MyHudNotification(MySpaceTexts.NotificationHintTurnAllReactorsOn, 0);
                if (!MyInput.Static.IsJoystickConnected())
                    m_notificationReactorsOn.SetTextFormatArguments(controlName);
                else
                    m_notificationReactorsOn.SetTextFormatArguments(MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_SPACESHIP, MyControlsSpace.TOGGLE_REACTORS));
                m_notificationReactorsOn.Level = MyNotificationLevel.Control;
            }

            if (m_notificationReactorsOff == null)
            {
                var controlName = MyInput.Static.GetGameControl(MyControlsSpace.TOGGLE_REACTORS).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard);
                m_notificationReactorsOff = new MyHudNotification(MySpaceTexts.NotificationHintTurnAllReactorsOff, 0);
                if (!MyInput.Static.IsJoystickConnected())
                    m_notificationReactorsOff.SetTextFormatArguments(controlName);
                else
                    m_notificationReactorsOff.SetTextFormatArguments(MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_SPACESHIP, MyControlsSpace.TOGGLE_REACTORS));
                m_notificationReactorsOff.Level = MyNotificationLevel.Control;
            }

            if (m_notificationLeave == null)
            {
                var controlName = MyInput.Static.GetGameControl(MyControlsSpace.USE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard);
                m_notificationLeave = new MyHudNotification(LeaveNotificationHintText, 0);
                if (!MyInput.Static.IsJoystickConnected())
                    m_notificationLeave.SetTextFormatArguments(controlName);
                else
                    m_notificationLeave.SetTextFormatArguments(MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_SPACESHIP, MyControlsSpace.USE));
                m_notificationLeave.Level = MyNotificationLevel.Control;
            }

            if (m_notificationTerminal == null)
            {
                var controlName = MyInput.Static.GetGameControl(MyControlsSpace.TERMINAL).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard);
                if (!MyInput.Static.IsJoystickConnected())
                {
                    m_notificationTerminal = new MyHudNotification(MySpaceTexts.NotificationHintOpenShipControlPanel, 0);
                    m_notificationTerminal.SetTextFormatArguments(controlName);
                    m_notificationTerminal.Level = MyNotificationLevel.Control;
                }
                else
                {
                    m_notificationTerminal = null;
                }
            }

            if (m_notificationWeaponMode == null)
            {
                var controlName = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_COLOR_CHANGE).GetControlButtonName(MyGuiInputDeviceEnum.Mouse);
                if (!MyInput.Static.IsJoystickConnected())
                {
                    m_notificationWeaponMode = new MyHudNotification(MySpaceTexts.NotificationHintSwitchWeaponMode, 0);
                    m_notificationWeaponMode.SetTextFormatArguments(controlName);
                    m_notificationWeaponMode.Level = MyNotificationLevel.Control;
                }
                else
                {
                    m_notificationWeaponMode = null;
                }
            }

            MyHud.Notifications.Add(m_notificationLeave);
            if (m_notificationTerminal != null)
                MyHud.Notifications.Add(m_notificationTerminal);
            if (m_notificationWeaponMode != null)
                MyHud.Notifications.Add(m_notificationWeaponMode);
        }
        void MyMultiplayerClient_ClientLeft(ulong user, ChatMemberStateChangeEnum stateChange)
        {
            if (user == ServerId)
            {
                RaiseHostLeft();
                return;
            }

            if (m_members.Contains(user))
            {
                m_members.Remove(user);

                MySandboxGame.Log.WriteLineAndConsole("Player disconnected: " + MySteam.API.Friends.GetPersonaName(user) + " (" + user + ")");

                MyTrace.Send(TraceWindow.Multiplayer, "Player disconnected: " + stateChange.ToString());

                if (MySandboxGame.IsGameReady && MySteam.UserId != user)
                {
                    var clientLeft = new MyHudNotification(MySpaceTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                    clientLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(user));
                    MyHud.Notifications.Add(clientLeft);
                }

                Peer2Peer.CloseSession(user);
            }

            m_memberData.Remove(user);
        }                             
        public void OnConnectedClient(ref ConnectedClientDataMsg msg, MyNetworkClient sender)
        {
            MySandboxGame.Log.WriteLineAndConsole("Client connected: " + msg.Name + " (" + msg.SteamID.ToString() + ")");
            MyTrace.Send(TraceWindow.Multiplayer, "Client connected");

            if (MySandboxGame.IsGameReady && msg.SteamID != ServerId && MySteam.UserId != msg.SteamID && msg.Join)
            {
                var clientConnected = new MyHudNotification(MySpaceTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                clientConnected.SetTextFormatArguments(msg.Name);
                MyHud.Notifications.Add(clientConnected);
            }

            m_memberData[msg.SteamID] = new MyConnectedClientData()
                {
                    Name = msg.Name,
                    IsAdmin = msg.IsAdmin
                };

            RaiseClientJoined(msg.SteamID);
        }
        private void UpdateJumpDriveSystem()
        {
            // Using this instead of game time because it cannot be affected by sim speed
            float jumpTime = (float)(TimeUtil.LocalTime - m_jumpStartTime).TotalMilliseconds;

            float warmupTime = 10000f;
            float startJumpTime = 1500f;
            float endJumpTime = 500f;

            if (m_isJumping)
            {
                if (jumpTime < warmupTime)
                {
                    int prevTimeInt = (int)(m_prevJumpTime / 1000);
                    int timeInt = (int)(jumpTime / 1000);
                    if (prevTimeInt != timeInt)
                    {
                        if (IsLocalCharacterAffectedByJump())
                        {
                            var notification = new MyHudNotification(MySpaceTexts.NotificationJumpWarmupTime, 500);
                            int secondsRemaining = (int)(Math.Round((warmupTime - jumpTime) / 1000));
                            notification.SetTextFormatArguments(secondsRemaining);
                            MyHud.Notifications.Add(notification);
                        }
                    }
                } 
                else if (jumpTime < startJumpTime + warmupTime)
                {
                    if (m_soundEmitter.SoundId != m_jumpOutSound.SoundId)
                    {
                        m_soundEmitter.PlaySound(m_jumpOutSound);
                    }
                    UpdateJumpEffect(MathHelper.SmoothStep(1f, 0f, (jumpTime - warmupTime) / startJumpTime));
                }
                else if (!m_jumped)
                {
                    MyParticleEffect effect;
                    if (MyParticlesManager.TryCreateParticleEffect(53, out effect))
                    {
                        effect.WorldMatrix = MatrixD.CreateFromTransformScale(Quaternion.Identity, m_grid.WorldMatrix.Translation, Vector3D.One);
                        effect.UserScale = (float)m_grid.PositionComp.WorldAABB.HalfExtents.AbsMax() / 25f;
                        effect.AutoDelete = true;
                    }

                    MyThirdPersonSpectator.Static.ResetPosition(0.0, null);
                    MyThirdPersonSpectator.Static.ResetDistance();
                    MyThirdPersonSpectator.Static.RecalibrateCameraPosition();

                    m_jumped = true;
                    
                    var keys = m_shipInfo.Keys.ToList();
                    foreach (var key in keys)
                    {
                        MatrixD gridMatrix = key.WorldMatrix;
                        gridMatrix.Translation = m_shipInfo[key];
                        key.WorldMatrix = gridMatrix;
                    }

                    UpdateJumpEffect(0f);
                    MyThirdPersonSpectator.Static.ResetPosition(0.0, null);
                    MyThirdPersonSpectator.Static.ResetDistance();
                    MyThirdPersonSpectator.Static.RecalibrateCameraPosition();

                }
                else if (jumpTime < startJumpTime + endJumpTime + warmupTime)
                {
                    if (m_soundEmitter.SoundId != m_jumpInSound.SoundId)
                    {
                        m_soundEmitter.PlaySound(m_jumpInSound);
                    }
                    UpdateJumpEffect(MathHelper.SmoothStep(0f, 1f, (jumpTime - startJumpTime - warmupTime) / (endJumpTime)));
                }
                else
                {
                    UpdateJumpEffect(1f);
                    m_jumped = false;
                    m_isJumping = false;
                }
            }
            m_prevJumpTime = jumpTime;
        }
 void GetNotification(IMyUseObject useObject, UseActionEnum actionType, ref MyHudNotification notification)
 {
     if ((useObject.SupportedActions & actionType) != 0)
     {
         var actionInfo = useObject.GetActionInfo(actionType);
         Character.RemoveNotification(ref notification);
         notification = new MyHudNotification(actionInfo.Text, 0, level: actionInfo.IsTextControlHint ? MyNotificationLevel.Control : MyNotificationLevel.Normal);
         if (!MyInput.Static.IsJoystickConnected())
         {
             notification.SetTextFormatArguments(actionInfo.FormatParams);
         }
         else
         {
             if (actionInfo.JoystickText.HasValue)
                 notification.Text = actionInfo.JoystickText.Value;
             if (actionInfo.JoystickFormatParams != null)
                 notification.SetTextFormatArguments(actionInfo.JoystickFormatParams);
         }
     }
 }
예제 #12
0
 private void ShowDebugNotification(string notificationText)
 {
     var debugNotification = new MyHudNotification(MySpaceTexts.CustomText, 5000, level: MyNotificationLevel.Important);
     debugNotification.SetTextFormatArguments("DEBUG: " + notificationText);
     MyHud.Notifications.Add(debugNotification);
 }
예제 #13
0
        private void StartRespawn(float respawnTime)
        {
            if (ControllerInfo.Controller != null && ControllerInfo.Controller.Player != null)
            {
                MySessionComponentMissionTriggers.PlayerDied(this.ControllerInfo.Controller.Player);
                if (!MySessionComponentMissionTriggers.CanRespawn(this.ControllerInfo.Controller.Player.Id))
                {
                    m_currentRespawnCounter = -1;
                    return;
                }
            }

            if (this == MySession.Static.ControlledEntity)
            {
                MyGuiScreenTerminal.Hide();

                m_respawnNotification = new MyHudNotification(MyCommonTexts.NotificationRespawn, (int)(RESPAWN_TIME * 1000), priority: 5);
                m_respawnNotification.Level = MyNotificationLevel.Important;
                m_respawnNotification.SetTextFormatArguments((int)m_currentRespawnCounter);
                MyHud.Notifications.Add(m_respawnNotification);
            }

            m_currentRespawnCounter = respawnTime;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
        }
예제 #14
0
        /// <summary>
        /// Creates new Steam lobby
        /// </summary>
        private static void StartServerRequest()
        {
            if (MySteam.IsOnline)
            {
                // Later it will be by some dialog
                Static.UnloadMultiplayer();
                var result = MyMultiplayer.HostLobby(GetLobbyType(Static.OnlineMode), Static.MaxPlayers, Static.SyncLayer);
                result.Done += OnMultiplayerHost;

                // We have to wait, because MyMultiplayerLobby must be created before loading entities.
                // MyMultiplayerLobby is created in reaction to steam lobby callback creation. Maybe it's time to change that and create MyMultiplayerLobby before.
                result.Wait();
            }
            else
            {
                var notification = new MyHudNotification(MyCommonTexts.MultiplayerErrorStartingServer, 10000, MyFontEnum.Red);
                notification.SetTextFormatArguments("SteamOffline - try restarting Steam");
                MyHud.Notifications.Add(notification);
            }
        }
예제 #15
0
 private static void OnMultiplayerHost(Result hostResult, MyMultiplayerBase multiplayer)
 {
     if (hostResult == Result.OK)
     {
         Static.StartServer(multiplayer);
     }
     else
     {
         var notification = new MyHudNotification(MyCommonTexts.MultiplayerErrorStartingServer, 10000, MyFontEnum.Red);
         notification.SetTextFormatArguments(hostResult.ToString());
         MyHud.Notifications.Add(notification);
     }
 }
예제 #16
0
        // TODO: OP! Should be on different place, somewhere in the game where we handle game data
        /// <summary>
        /// Safe to anytime from update thread, synchronized internally
        /// </summary>
        public static void ProcessRenderOutput()
        {
            VRageRender.IMyRenderMessage message;
            while (VRageRender.MyRenderProxy.OutputQueue.TryDequeue(out message))
            {
                //devicelost
                if (message == null)
                    continue;

                switch (message.MessageType)
                {
                    case VRageRender.MyRenderMessageEnum.RequireClipmapCell:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (VRageRender.MyRenderMessageRequireClipmapCell)message;
                            MyRenderComponentVoxelMap render;
                            if (MySession.Static.VoxelMaps.TryGetRenderComponent(rMessage.ClipmapId, out render))
                            {
                                render.OnCellRequest(rMessage.Cell, rMessage.HighPriority);
                            }

                            break;
                        }

                    case VRageRender.MyRenderMessageEnum.CancelClipmapCell:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (VRageRender.MyRenderMessageCancelClipmapCell)message;
                            MyRenderComponentVoxelMap render;
                            if (MySession.Static.VoxelMaps.TryGetRenderComponent(rMessage.ClipmapId, out render))
                            {
                                render.OnCellRequestCancelled(rMessage.Cell);
                            }

                            break;
                        }

                    case VRageRender.MyRenderMessageEnum.ScreenshotTaken:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (VRageRender.MyRenderMessageScreenshotTaken)message;

                            if (rMessage.ShowNotification)
                            {
                                var screenshotNotification = new MyHudNotification(rMessage.Success ? MySpaceTexts.ScreenshotSaved : MySpaceTexts.ScreenshotFailed, 2000);
                                if (rMessage.Success)
                                    screenshotNotification.SetTextFormatArguments(System.IO.Path.GetFileName(rMessage.Filename));
                                MyHud.Notifications.Add(screenshotNotification);
                            }
                            break;
                        }
                    case VRageRender.MyRenderMessageEnum.TextNotDrawnToTexture:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (VRageRender.MyRenderMessageTextNotDrawnToTexture)message;
                            MyTextPanel panel = MyEntities.GetEntityById(rMessage.EntityId) as MyTextPanel;
                            if (panel != null)
                            {
                                panel.FailedToRenderTexture = true;
                            }

                            break;
                        }

                    case VRageRender.MyRenderMessageEnum.RenderTextureFreed:
                        {
                            if (MySession.Static == null || MySession.LocalCharacter == null)
                                break;

                            var rMessage = (VRageRender.MyRenderMessageRenderTextureFreed)message;
                            var camera = MySector.MainCamera;
                            if (camera == null)
                                return;
                            BoundingSphereD sphere = new BoundingSphereD(camera.Position + camera.ForwardVector * new Vector3D(MyTextPanel.MAX_DRAW_DISTANCE / 2), MyTextPanel.MAX_DRAW_DISTANCE / 2.0);
                            List<MyEntity> entities = MyEntities.GetEntitiesInSphere(ref sphere);
                            MyTextPanel closestPanel = null;
                            double minDistance = MyTextPanel.MAX_DRAW_DISTANCE;
                            foreach (MyEntity entity in entities)
                            {
                                MyTextPanel panel = entity as MyTextPanel;
                                if (panel != null && panel.FailedToRenderTexture && panel.IsInRange() && panel.ShowTextOnScreen)
                                {
                                    double distanceToPanel = Vector3D.Distance(panel.PositionComp.GetPosition(), camera.Position);
                                    if (distanceToPanel < minDistance)
                                    {
                                        minDistance = distanceToPanel;
                                        closestPanel = panel;
                                    }
                                }
                            }

                            if (closestPanel != null)
                            {
                                closestPanel.RefreshRenderText(rMessage.FreeResources);
                            }
                            entities.Clear();
                            break;
                        }
                    case VRageRender.MyRenderMessageEnum.ExportToObjComplete:
                        {
                            var rMessage = (VRageRender.MyRenderMessageExportToObjComplete)message;

                            break;
                        }

                    case MyRenderMessageEnum.CreatedDeviceSettings:
                        {
                            var rMessage = (VRageRender.MyRenderMessageCreatedDeviceSettings)message;
                            MyVideoSettingsManager.OnCreatedDeviceSettings(rMessage);
                            break;
                        }

                    case MyRenderMessageEnum.VideoAdaptersResponse:
                        {
                            var rMessage = (VRageRender.MyRenderMessageVideoAdaptersResponse)message;
                            MyVideoSettingsManager.OnVideoAdaptersResponse(rMessage);
                            break;
                        }

                    case MyRenderMessageEnum.ClipmapsReady:
                        {
                            AreClipmapsReady = true;
                            break;
                        }
                }

                VRageRender.MyRenderProxy.MessagePool.Return(message);
            }

            if (m_makeClipmapsReady)
            {
                m_makeClipmapsReady = false;
                AreClipmapsReady = true;
            }
        }
예제 #17
0
        private void UpdateJumpDriveSystem()
        {
            if (m_isJumping)
            {
                float jumpTime = m_jumpTimeLeft;
                const float startJumpTime = 1.2f;
                const float particleTime = 0.3f;
                const float endJumpTime = -0.3f;

                PlayParticleEffect();
                m_jumpTimeLeft -= VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
                if (jumpTime > startJumpTime)
                {
                    double roundTime = Math.Round(jumpTime);
                    if (roundTime != m_prevJumpTime)
                        if (IsLocalCharacterAffectedByJump(true))
                        {
                            var notification = new MyHudNotification(MySpaceTexts.NotificationJumpWarmupTime, 500, priority : 3);
                            notification.SetTextFormatArguments(roundTime);
                            MyHud.Notifications.Add(notification);
                        }
                }
                else if (jumpTime > 0)
                {
                    IsLocalCharacterAffectedByJump(true);
                    if (m_soundEmitter.SoundId != m_jumpOutSound.Arcade && m_soundEmitter.SoundId != m_jumpOutSound.Realistic)
                    {
                        m_soundEmitter.PlaySound(m_jumpOutSound);
                    }
                    UpdateJumpEffect(jumpTime / startJumpTime);

                    if (jumpTime < particleTime)
                    {
                        //PlayParticleEffect();
                    }
                }
                else if (!m_jumped)
                {
                    if (Sync.IsServer)
                    {
                        if (m_shipInfo.ContainsKey(m_grid))
                        {
                            Vector3? suitableLocation = FindSuitableJumpLocation(m_shipInfo[m_grid]);
                            if (suitableLocation.HasValue)
                            {
                                SendPerformJump(suitableLocation.Value);
                                PerformJump(suitableLocation.Value);
                            }
                            else
                            {
                                SendAbortJump();
                                AbortJump();
                            }
                        }
                        else
                        {
                            SendAbortJump();
                            AbortJump();
                        }
                    }
                }
                else if (jumpTime > endJumpTime)
                {
                    UpdateJumpEffect(jumpTime / endJumpTime);
                }
                else
                {
                    CleanupAfterJump();
                    if (m_soundEmitter.SoundId != m_jumpInSound.Arcade && m_soundEmitter.SoundId != m_jumpInSound.Realistic)
                    {
                        m_soundEmitter.PlaySound(m_jumpInSound);
                    }
                }
                m_prevJumpTime = (float)Math.Round(jumpTime);
            }
        }
예제 #18
0
        // TODO: OP! Should be on different place, somewhere in the game where we handle game data
        /// <summary>
        /// Safe to anytime from update thread, synchronized internally
        /// </summary>
        public static void ProcessRenderOutput()
        {
            MyRenderMessageBase message;
            while (VRageRender.MyRenderProxy.OutputQueue.TryDequeue(out message))
            {
                //devicelost
                if (message == null)
                    continue;

                switch (message.MessageType)
                {
                    case MyRenderMessageEnum.RequireClipmapCell:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (MyRenderMessageRequireClipmapCell)message;
                            MyRenderComponentVoxelMap render;
                            if (MySession.Static.VoxelMaps.TryGetRenderComponent(rMessage.ClipmapId, out render))
                            {
                                render.OnCellRequest(rMessage.Cell, rMessage.Priority, rMessage.DebugDraw);
                            }
                            break;
                        }

                    case MyRenderMessageEnum.CancelClipmapCell:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (MyRenderMessageCancelClipmapCell)message;
                            MyRenderComponentVoxelMap render;
                            if (MySession.Static.VoxelMaps.TryGetRenderComponent(rMessage.ClipmapId, out render))
                            {
                                render.OnCellRequestCancelled(rMessage.Cell);
                            }

                            break;
                        }

                    case MyRenderMessageEnum.MergeVoxelMeshes:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (MyRenderMessageMergeVoxelMeshes)message;
                            MyRenderComponentVoxelMap render;
                            if (MySession.Static.VoxelMaps.TryGetRenderComponent(rMessage.ClipmapId, out render))
                            {
                                render.OnMeshMergeRequest(rMessage.ClipmapId, rMessage.LodMeshMetadata, rMessage.CellCoord, rMessage.Priority, rMessage.WorkId, rMessage.BatchesToMerge);
                            }

                            break;
                        }

                    case MyRenderMessageEnum.CancelVoxelMeshMerge:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (MyRenderMessageCancelVoxelMeshMerge)message;
                            MyRenderComponentVoxelMap render;
                            if (MySession.Static.VoxelMaps.TryGetRenderComponent(rMessage.ClipmapId, out render))
                            {
                                render.OnMeshMergeCancelled(rMessage.ClipmapId, rMessage.WorkId);
                            }

                            break;
                        }

                    case MyRenderMessageEnum.Error:
                        {
                            var rMessage = (MyRenderMessageError)message;
                            ErrorConsumer.OnError("Renderer error", rMessage.Message, rMessage.Callstack);
                            break;
                        }
                    case MyRenderMessageEnum.ScreenshotTaken:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (MyRenderMessageScreenshotTaken)message;

                            if (rMessage.ShowNotification)
                            {
                                var screenshotNotification = new MyHudNotification(rMessage.Success ? MyCommonTexts.ScreenshotSaved : MyCommonTexts.ScreenshotFailed, 2000);
                                if (rMessage.Success)
                                    screenshotNotification.SetTextFormatArguments(System.IO.Path.GetFileName(rMessage.Filename));
                                MyHud.Notifications.Add(screenshotNotification);
                            }

                            if (MySandboxGame.Static != null && MySandboxGame.Static.OnScreenshotTaken != null)
                            {
                                MySandboxGame.Static.OnScreenshotTaken(MySandboxGame.Static, null);
                            }
                            break;
                        }
                    case MyRenderMessageEnum.TextNotDrawnToTexture:
                        {
                            if (MySession.Static == null)
                                break;

                            var rMessage = (MyRenderMessageTextNotDrawnToTexture)message;
                            MyTextPanel panel = MyEntities.GetEntityById(rMessage.EntityId) as MyTextPanel;
                            if (panel != null)
                            {
                                panel.FailedToRenderTexture = true;
                            }

                            break;
                        }

                    case MyRenderMessageEnum.RenderTextureFreed:
                        {
                            if (MySession.Static == null || MySession.Static.LocalCharacter == null)
                                break;

                            var rMessage = (MyRenderMessageRenderTextureFreed)message;
                            var camera = MySector.MainCamera;
                            if (camera == null)
                                return;
                            BoundingSphereD sphere = new BoundingSphereD(camera.Position + camera.ForwardVector * new Vector3D(MyTextPanel.MAX_DRAW_DISTANCE / 2), MyTextPanel.MAX_DRAW_DISTANCE / 2.0);
                            List<MyEntity> entities = MyEntities.GetEntitiesInSphere(ref sphere);
                            MyTextPanel closestPanel = null;
                            double minDistance = MyTextPanel.MAX_DRAW_DISTANCE;
                            foreach (MyEntity entity in entities)
                            {
                                MyTextPanel panel = entity as MyTextPanel;
                                if (panel != null && panel.FailedToRenderTexture && panel.IsInRange() && panel.ShowTextOnScreen)
                                {
                                    double distanceToPanel = Vector3D.Distance(panel.PositionComp.GetPosition(), camera.Position);
                                    if (distanceToPanel < minDistance)
                                    {
                                        minDistance = distanceToPanel;
                                        closestPanel = panel;
                                    }
                                }
                            }

                            if (closestPanel != null)
                            {
                                closestPanel.RefreshRenderText(rMessage.FreeResources);
                            }
                            entities.Clear();
                            break;
                        }
                    case MyRenderMessageEnum.ExportToObjComplete:
                        {
                            var rMessage = (MyRenderMessageExportToObjComplete)message;

                            break;
                        }

                    case MyRenderMessageEnum.CreatedDeviceSettings:
                        {
                            var rMessage = (MyRenderMessageCreatedDeviceSettings)message;
                            MyVideoSettingsManager.OnCreatedDeviceSettings(rMessage);
                            break;
                        }

                    case MyRenderMessageEnum.VideoAdaptersResponse:
                        {
                            var rMessage = (MyRenderMessageVideoAdaptersResponse)message;
                            MyVideoSettingsManager.OnVideoAdaptersResponse(rMessage);
                            Static.CheckGraphicsCard(rMessage);
                            // All hardware info is gathered now, send the app start analytics.
                            var firstTimeRun = Config.FirstTimeRun;
                            if (firstTimeRun)
                            {
                                Config.FirstTimeRun = false;
                                Config.Save();
                            }
                            MyAnalyticsHelper.ReportProcessStart(firstTimeRun);
                            break;
                        }

                    case MyRenderMessageEnum.ClipmapsReady:
                        {
                            AreClipmapsReady = true;
                            break;
                        }
                }

                VRageRender.MyRenderProxy.MessagePool.Return(message);
            }

            if (m_makeClipmapsReady)
            {
                m_makeClipmapsReady = false;
                AreClipmapsReady = true;
            }
        }
예제 #19
0
        private void UpdateSymmetryNotification(MyStringId myTextsWrapperEnum)
        {
            RemoveSymmetryNotification();

            m_symmetryNotification = new MyHudNotification(myTextsWrapperEnum, 0, level: MyNotificationLevel.Control);
            if (!MyInput.Static.IsJoystickConnected())
            {
                m_symmetryNotification.SetTextFormatArguments(
                    MyInput.Static.GetGameControl(MyControlsSpace.PRIMARY_TOOL_ACTION),
                    MyInput.Static.GetGameControl(MyControlsSpace.SECONDARY_TOOL_ACTION));
            }
            else
            {
                m_symmetryNotification.SetTextFormatArguments(
                    MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.PRIMARY_TOOL_ACTION),
                    MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.SECONDARY_BUILD_ACTION));
            }

            MyHud.Notifications.Add(m_symmetryNotification);
        }
예제 #20
0
        private void RequestJump()
        {
            if (CanJump)
            {
                if (MySession.Static.LocalCharacter != null)
                {
                    var shipController = MySession.Static.LocalCharacter.Parent as MyShipController;
                    if (shipController == null && MySession.Static.ControlledEntity != null)
                    {
                        shipController = MySession.Static.ControlledEntity.Entity as MyShipController;
                    }


                    if (shipController != null && (shipController.IsMainCockpit || !CubeGrid.HasMainCockpit()))
                    {
                        if (m_jumpTarget != null)
                        {
                            CubeGrid.GridSystems.JumpSystem.RequestJump(m_jumpTarget.Name, m_jumpTarget.Coords, shipController.OwnerId);
                        }
                        else
                        {
                            Vector3 localForward = Base6Directions.GetVector(shipController.Orientation.Forward);
                            Vector3D forward = Vector3D.Transform(localForward, shipController.CubeGrid.WorldMatrix.GetOrientation());

                            forward.Normalize();

                            Vector3D jumpCoords = CubeGrid.WorldMatrix.Translation + forward * ComputeMaxDistance();
                            CubeGrid.GridSystems.JumpSystem.RequestJump("Blind Jump", jumpCoords, shipController.OwnerId);
                        }
                    }
                }
            }
            else if (!IsJumping && !IsFull)
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationJumpDriveNotFullyCharged, 1500);
                notification.SetTextFormatArguments((m_storedPower / BlockDefinition.PowerNeededForJump).ToString("P"));
                MyHud.Notifications.Add(notification);
            }
        }
예제 #21
0
        private void EquipWeapon(IMyHandheldGunObject<MyDeviceBase> newWeapon, bool showNotification = false)
        {
          //  Debug.Assert(newWeapon != null);
            if (newWeapon == null)
                return;

            MyEntity gunEntity = (MyEntity)newWeapon;
            gunEntity.Render.CastShadows = true;
            gunEntity.Render.NeedsResolveCastShadow = false;
            gunEntity.Save = false;
            gunEntity.OnClose += gunEntity_OnClose;

            MyEntities.Add(gunEntity);

            m_handItemDefinition = null;
            m_currentWeapon = newWeapon;
            m_currentWeapon.OnControlAcquired(this);

            UseAnimationForWeapon |= m_currentWeapon.ForceAnimationInsteadOfIK;

            if (WeaponEquiped != null)
                WeaponEquiped(m_currentWeapon);

            MyAnalyticsHelper.ReportActivityStart(this, "item_equip", "character", "toolbar_item_usage", m_currentWeapon.GetType().Name);

            // CH:TODO: The hand item definitions should be changed to handheld gun object definitions and should be taken according to m_currentWeapon typeId
            if (m_currentWeapon.PhysicalObject != null)
            {
                var handItemId = m_currentWeapon.PhysicalObject.GetId();

                m_handItemDefinition = MyDefinitionManager.Static.TryGetHandItemForPhysicalItem(handItemId);
                System.Diagnostics.Debug.Assert(m_handItemDefinition != null, "Create definition for this hand item!");
            }
            else if (m_currentWeapon.DefinitionId.TypeId == typeof(MyObjectBuilder_CubePlacer))
            {
                var gunID = new MyDefinitionId(typeof(MyObjectBuilder_CubePlacer));

                m_handItemDefinition = MyDefinitionManager.Static.TryGetHandItemDefinition(ref gunID);
                System.Diagnostics.Debug.Assert(m_handItemDefinition != null, "Create definition for this hand item!");
            }

            //Setup correct worldmatrix to weapon
            //CalculateDependentMatrices();

            if (m_handItemDefinition != null && !string.IsNullOrEmpty(m_handItemDefinition.FingersAnimation))
            {
                string animationSubtype;
                if (!m_characterDefinition.AnimationNameToSubtypeName.TryGetValue(m_handItemDefinition.FingersAnimation, out animationSubtype))
                {
                    animationSubtype = m_handItemDefinition.FingersAnimation;
                }
                var def = MyDefinitionManager.Static.TryGetAnimationDefinition(animationSubtype);
                if (!def.LeftHandItem.TypeId.IsNull)
                {
                    m_currentWeapon.OnControlReleased();
                    (m_currentWeapon as MyEntity).Close(); //no dual wielding now
                    m_currentWeapon = null;
                }

                PlayCharacterAnimation(m_handItemDefinition.FingersAnimation, MyBlendOption.Immediate, def.Loop ? MyFrameOption.Loop : MyFrameOption.PlayOnce, 1.0f, 1, false, null);
                if (UseNewAnimationSystem)
                {
                    TriggerCharacterAnimationEvent("equip_left_tool", true);
                    TriggerCharacterAnimationEvent("equip_right_tool", true);
                    TriggerCharacterAnimationEvent(m_handItemDefinition.Id.SubtypeName.ToLower(), true);
                    TriggerCharacterAnimationEvent(m_handItemDefinition.FingersAnimation.ToLower(), true);
                }

                if (!def.LeftHandItem.TypeId.IsNull)
                {
                    if (m_leftHandItem != null)
                    {
                        (m_leftHandItem as IMyHandheldGunObject<Sandbox.Game.Weapons.MyDeviceBase>).OnControlReleased();
                        m_leftHandItem.Close();
                    }

                    // CH: TODO: The entity id is not synced, but it never was in this place. It should be fixed later
                    long handItemId = MyEntityIdentifier.AllocateId();
                    uint? inventoryItemId = null;
                    var builder = GetObjectBuilderForWeapon(def.LeftHandItem, ref inventoryItemId, handItemId);
                    var leftHandItem = CreateGun(builder, inventoryItemId);

                    if (leftHandItem != null)
                    {
                        m_leftHandItem = leftHandItem as MyEntity;
                        leftHandItem.OnControlAcquired(this);
                        UpdateLeftHandItemPosition();

                        MyEntities.Add(m_leftHandItem);
                    }
                }
            }
            else if (m_handItemDefinition != null)
            {
                if (UseNewAnimationSystem)
                {
                    TriggerCharacterAnimationEvent("equip_left_tool", true);
                    TriggerCharacterAnimationEvent("equip_right_tool", true);
                    TriggerCharacterAnimationEvent(m_handItemDefinition.Id.SubtypeName.ToLower(), true);
                }
            }
            else
            {
                StopFingersAnimation(0);
            }

            var consumer = gunEntity.Components.Get<MyResourceSinkComponent>();
            if (consumer != null && SuitRechargeDistributor != null)
                SuitRechargeDistributor.AddSink(consumer);

            if (showNotification)
            {
                var notificationUse = new MyHudNotification(MySpaceTexts.NotificationUsingWeaponType, 2000);
                notificationUse.SetTextFormatArguments(MyDeviceBase.GetGunNotificationName(newWeapon.DefinitionId));
                MyHud.Notifications.Add(notificationUse);
            }

            Static_CameraAttachedToChanged(null, null);
            if (!(IsUsing is MyCockpit))
                MyHud.Crosshair.ResetToDefault(clear: false);

        }
예제 #22
0
        private void ShowStationRotationNotification()
        {
            if (MyPerGameSettings.Game == GameEnum.ME_GAME)
                return;

            if (m_stationRotationNotification == null && m_shipCreationClipboard.EnableStationRotation)
            {
                m_stationRotationNotification = new MyHudNotification(MySpaceTexts.NotificationStationRotation, 0, priority: 1);
                m_stationRotationNotification.SetTextFormatArguments(MyInput.Static.GetGameControl(MyControlsSpace.STATION_ROTATION));
            }
            if (m_stationRotationNotificationOff == null && !m_shipCreationClipboard.EnableStationRotation)
            {
                m_stationRotationNotificationOff = new MyHudNotification(MySpaceTexts.NotificationStationRotationOff, 0, priority: 1);
                m_stationRotationNotificationOff.SetTextFormatArguments(MyInput.Static.GetGameControl(MyControlsSpace.STATION_ROTATION));
            }

            if (m_shipCreationClipboard.EnableStationRotation)
            {
                MyHud.Notifications.Remove(m_stationRotationNotificationOff);
                MyHud.Notifications.Add(m_stationRotationNotification);
            }
            else
            {
                MyHud.Notifications.Remove(m_stationRotationNotification);
                MyHud.Notifications.Add(m_stationRotationNotificationOff);
            }
        }
예제 #23
0
        private static void OnSnapshotDone(bool snapshotSuccess, MySessionSnapshot snapshot)
        {
            if (snapshotSuccess)
            {
                if (!MySandboxGame.IsDedicated)
                {
                    var thumbPath = MySession.Static.ThumbPath;
                    try
                    {
                        if (File.Exists(thumbPath))
                            File.Delete(thumbPath);
                        MyGuiSandbox.TakeScreenshot(1200, 672, saveToPath: thumbPath, ignoreSprites: true, showNotification: false);
                    }
                    catch (Exception ex)
                    {
                        MySandboxGame.Log.WriteLine("Could not take session thumb screenshot. Exception:");
                        MySandboxGame.Log.WriteLine(ex);
                    }
                }

                snapshot.SaveParallel(completionCallback: () =>
                {
                    if (!MySandboxGame.IsDedicated)
                    {
                        MyHud.PopRotatingWheelVisible();

                        if (MySession.Static != null)
                        {
                            if (snapshot.SavingSuccess)
                            {
                                var notification = new MyHudNotification(MyCommonTexts.WorldSaved, 2500);
                                notification.SetTextFormatArguments(MySession.Static.Name);
                                MyHud.Notifications.Add(notification);
                            }
                            else
                            {
                                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                    messageText: new StringBuilder().AppendFormat(MyTexts.GetString(MyCommonTexts.WorldNotSaved), MySession.Static.Name),
                                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError)));
                            }
                        }
                    }

                    PopInProgress();
                });
            }
            else
            {
                if (!MySandboxGame.IsDedicated)
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                        messageText: new StringBuilder().AppendFormat(MyTexts.GetString(MyCommonTexts.WorldNotSaved), MySession.Static.Name),
                        messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError)));
                }

                PopInProgress();
            }

            if (m_callbackOnFinished != null)
                m_callbackOnFinished();

            m_callbackOnFinished = null;

            MyAudio.Static.Mute = false;
        }
            void ShrinkVMap()
            {
                Vector3I min, max;

                m_selectedVoxel.GetFilledStorageBounds(out min, out max);

                MyVoxelMapStorageDefinition def = null;
                if (m_selectedVoxel.AsteroidName != null)
                    MyDefinitionManager.Static.TryGetVoxelMapStorageDefinition(m_selectedVoxel.AsteroidName, out def);

                var origSize = m_selectedVoxel.Size;

                var tightSize = max - min + 1;

                var storage = new MyOctreeStorage(null, tightSize);

                var offset = (storage.Size - tightSize)/2 + 1;

                MyStorageData data = new MyStorageData();
                data.Resize(tightSize);

                m_selectedVoxel.Storage.ReadRange(data, MyStorageDataTypeFlags.ContentAndMaterial, 0, min, max);

                min = offset;
                max = offset + tightSize - 1;
                storage.WriteRange(data, MyStorageDataTypeFlags.ContentAndMaterial, ref min, ref max);

                var newMap = MyWorldGenerator.AddVoxelMap(m_selectedVoxel.StorageName, storage, m_selectedVoxel.WorldMatrix);

                m_selectedVoxel.Close();

                newMap.Save = true;

                if (def == null)
                {
                    ShowAlert("Voxel map {0} does not have a definition, the shrunk voxel map will be saved with the world instead.", m_selectedVoxel.StorageName);
                }
                else
                {
                    byte[] cVmapData;
                    newMap.Storage.Save(out cVmapData);

                    using (var ostream = MyFileSystem.OpenWrite(Path.Combine(MyFileSystem.ContentPath, def.StorageFile), FileMode.Open))
                    {
                        ostream.Write(cVmapData, 0, cVmapData.Length);
                    }
                    var notification = new MyHudNotification(MyStringId.GetOrCompute("Voxel prefab {0} updated succesfuly (size changed from {1} to {2})."), 4000);
                    notification.SetTextFormatArguments(def.Id.SubtypeName, origSize, storage.Size);
                    MyHud.Notifications.Add(notification);
                }
            }
예제 #25
0
        private void UpdateJumpDriveSystem()
        {
            // Using this instead of game time because it cannot be affected by sim speed
            float jumpTime = (float)(TimeUtil.LocalTime - m_jumpStartTime).TotalMilliseconds;

            float warmupTime = 10000f;
            float startJumpTime = 1500f;
            float endJumpTime = 500f;

            if (m_isJumping)
            {
                if (jumpTime < warmupTime)
                {
                    int prevTimeInt = (int)(m_prevJumpTime / 1000);
                    int timeInt = (int)(jumpTime / 1000);
                    if (prevTimeInt != timeInt)
                    {
                        if (IsLocalCharacterAffectedByJump())
                        {
                            var notification = new MyHudNotification(MySpaceTexts.NotificationJumpWarmupTime, 500);
                            int secondsRemaining = (int)(Math.Round((warmupTime - jumpTime) / 1000));
                            notification.SetTextFormatArguments(secondsRemaining);
                            MyHud.Notifications.Add(notification);
                        }
                    }
                } 
                else if (jumpTime < startJumpTime + warmupTime)
                {
                    if (m_soundEmitter.SoundId != m_jumpOutSound.SoundId)
                    {
                        m_soundEmitter.PlaySound(m_jumpOutSound);
                    }
                    UpdateJumpEffect(MathHelper.SmoothStep(1f, 0f, (jumpTime - warmupTime) / startJumpTime));
                }
                else if (!m_jumped)
                {
                    if (Sync.IsServer)
                    {
                        Vector3? suitableLocation = FindSuitableJumpLocation(m_shipInfo[m_grid]);
                        if (suitableLocation.HasValue)
                        {
                            SyncObject.SendPerformJump(suitableLocation.Value);
                            PerformJump(suitableLocation.Value);
                        }
                        else
                        {
                            SyncObject.SendAbortJump();
                            AbortJump();
                        }
                    }
                }
                else if (jumpTime < startJumpTime + endJumpTime + warmupTime)
                {
                    if (m_soundEmitter.SoundId != m_jumpInSound.SoundId)
                    {
                        m_soundEmitter.PlaySound(m_jumpInSound);
                    }
                    UpdateJumpEffect(MathHelper.SmoothStep(0f, 1f, (jumpTime - startJumpTime - warmupTime) / (endJumpTime)));
                }
                else
                {
                    CleanupAfterJump();
                }
            }
            m_prevJumpTime = jumpTime;
        }
예제 #26
0
        void Matchmaking_LobbyChatUpdate(Lobby lobby, ulong changedUser, ulong makingChangeUser, ChatMemberStateChangeEnum stateChange)
        {
            //System.Diagnostics.Debug.Assert(MySession.Static != null);

            if (lobby.LobbyId == Lobby.LobbyId)
            {
                if (stateChange == ChatMemberStateChangeEnum.Entered)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Player entered: " + MySteam.API.Friends.GetPersonaName(changedUser) + " (" + changedUser + ")");
                    MyTrace.Send(TraceWindow.Multiplayer, "Player entered");
                    Peer2Peer.AcceptSession(changedUser);

                    RaiseClientJoined(changedUser);

                    if (MySandboxGame.IsGameReady && changedUser != ServerId)
                    {
                        var playerJoined = new MyHudNotification(MySpaceTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                        playerJoined.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerJoined);
                    }
                }
                else
                {
                    // Kicked client can be already removed from Clients
                    if (Sync.Clients.HasClient(changedUser))
                        RaiseClientLeft(changedUser, stateChange);

                    if (changedUser == ServerId)
                    {
                        MyTrace.Send(TraceWindow.Multiplayer, "Host left: " + stateChange.ToString());
                        RaiseHostLeft();

                        MyGuiScreenMainMenu.UnloadAndExitToMenu();
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                            messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                            messageText: MyTexts.Get(MySpaceTexts.MultiplayerErrorServerHasLeft)));

                        // Set new server
                        //ServerId = Lobby.GetOwner();

                        //if (ServerId == Sync.MyId)
                        //{
                        //    Lobby.SetLobbyData(HostNameTag, Sync.MyName);
                        //}
                    }
                    else if (MySandboxGame.IsGameReady)
                    {
                        var playerLeft = new MyHudNotification(MySpaceTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                        playerLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerLeft);
                    }
                }
            }
        }
예제 #27
0
        void Matchmaking_LobbyChatUpdate(Lobby lobby, ulong changedUser, ulong makingChangeUser, ChatMemberStateChangeEnum stateChange)
        {
            //System.Diagnostics.Debug.Assert(MySession.Static != null);

            if (lobby.LobbyId == Lobby.LobbyId)
            {
                if (stateChange == ChatMemberStateChangeEnum.Entered)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Player entered: " + MySteam.API.Friends.GetPersonaName(changedUser) + " (" + changedUser + ")");
                    MyTrace.Send(TraceWindow.Multiplayer, "Player entered");
                    Peer2Peer.AcceptSession(changedUser);

                    // When some clients connect at the same time then some of them can have already added clients 
                    // (see function MySyncLayer.RegisterClientEvents which registers all Members in Lobby).
                    if (Sync.Clients == null || !Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientJoined(changedUser);

                        // Battles - send all clients, identities, players, factions as first message to client
                        if ((Battle || Scenario) && changedUser != Sync.MyId)
                        {
                            SendAllMembersDataToClient(changedUser);
                        }
                    }

                    if (MySandboxGame.IsGameReady && changedUser != ServerId)
                    {
                        // Player is able to connect to the battle which already started - player is then kicked and we do not want to show connected message in HUD.
                        bool showMsg = true;
                        if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static != null && MySession.Static.Battle && !BattleCanBeJoined)
                            showMsg = false;

                        if (showMsg)
                        {
                            var playerJoined = new MyHudNotification(MyCommonTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                            playerJoined.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                            MyHud.Notifications.Add(playerJoined);
                        }
                    }
                }
                else
                {
                    // Kicked client can be already removed from Clients
                    if (Sync.Clients == null || Sync.Clients.HasClient(changedUser))
                        RaiseClientLeft(changedUser, stateChange);

                    if (changedUser == ServerId)
                    {
                        MyTrace.Send(TraceWindow.Multiplayer, "Host left: " + stateChange.ToString());
                        RaiseHostLeft();

                        MyGuiScreenMainMenu.UnloadAndExitToMenu();
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                            messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                            messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorServerHasLeft)));

                        // Set new server
                        //ServerId = Lobby.GetOwner();

                        //if (ServerId == Sync.MyId)
                        //{
                        //    Lobby.SetLobbyData(HostNameTag, Sync.MyName);
                        //}
                    }
                    else if (MySandboxGame.IsGameReady)
                    {
                        var playerLeft = new MyHudNotification(MyCommonTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                        playerLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerLeft);
                    }
                }
            }
        }
예제 #28
0
        private void UpdateSymmetryNotification(MyStringId myTextsWrapperEnum)
        {
            RemoveSymmetryNotification();

            m_symmetryNotification = new MyHudNotification(myTextsWrapperEnum, 0, level: MyNotificationLevel.Control);
            m_symmetryNotification.SetTextFormatArguments(
                MyInput.Static.GetGameControl(MyControlsSpace.PRIMARY_TOOL_ACTION),
                MyInput.Static.GetGameControl(MyControlsSpace.SECONDARY_TOOL_ACTION));

            MyHud.Notifications.Add(m_symmetryNotification);
        }