public void RemoveScreen(MyGuiScreenBase screen)
 {
     Scheduler.AddScheduledCallback(dt =>
     {
         screen.CloseScreenNow();
         MyGuiSandbox.RemoveScreen(screen);
     }, 0);
     _screens.Remove(screen);
 }
Ejemplo n.º 2
0
        private void MessageBoxCallback(Exception exception, MyGuiScreenMessageBoxCallbackEnum callbackReturn)
        {
            m_retryScreen.CloseScreenNow();
            m_retryScreen = null;

            // retry
            if (callbackReturn == MyGuiScreenMessageBoxCallbackEnum.YES)
            {
                Retry();
            }
            // continue without saving
            else if (callbackReturn == MyGuiScreenMessageBoxCallbackEnum.NO)
            {
                RaiseActionFailed(exception);
                CloseScreen();
            }
        }
        void RenameTemplate(string oldName, string newName, MyGuiScreenBase renameScreen)
        {
            renameScreen.CloseScreenNow();

            Func <IAsyncResult> begin = () =>
            {
                var client = MySectorServiceClient.GetCheckedInstance();
                return(client.BeginRenameTemplateCheckpoint(oldName, newName, null, client));
            };

            Action <IAsyncResult, MyGuiScreenProgressAsync> end = (result, screen) =>
            {
                try
                {
                    var client = (MySectorServiceClient)result.AsyncState;
                    client.EndRenameTemplateCheckpoint(result);
                }
                catch (FaultException <MyCheckpointRenameFault> e)
                {
                    switch (e.Detail.Reason)
                    {
                    case MyCheckpointRenameFaultReason.CheckpointNotFound:
                        MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.SectorNotFound, MyTextsWrapperEnum.MessageBoxTimeoutCaption, MyTextsWrapperEnum.Ok, null));
                        break;

                    case MyCheckpointRenameFaultReason.NameAlreadyExists:
                        MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.CantSaveSectorNameExists, MyTextsWrapperEnum.MessageBoxTimeoutCaption, MyTextsWrapperEnum.Ok, null));
                        break;
                    }
                }
                catch (Exception)
                {
                    MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.PleaseTryAgain, MyTextsWrapperEnum.MessageBoxNetworkErrorCaption, MyTextsWrapperEnum.Ok, null));
                }
                screen.CloseScreenNow();
                FillList();
            };

            var progress = new MyGuiScreenProgressAsync(MyTextsWrapperEnum.LoadSectorIdentifiersPleaseWait, false, begin, end);

            MyGuiManager.AddScreen(progress);
        }
        public void AddResponse(MyMwcStartSessionResponseTypeEnum startSessionResponse, MyMwcSectorIdentifier?sectorIdentifier, MyGameplayDifficultyEnum difficulty)
        {
            MyGuiScreenGamePlayType screenType;

            if (startSessionResponse == MyMwcStartSessionResponseTypeEnum.OK)
            {
                MyMwcSectorTypeEnum   sessionType;
                MyMwcSessionStateEnum sessionStartType;
                int?            userId   = null;
                MyMwcVector3Int?position = null;

                if ((m_sessionType == MyMwcStartSessionRequestTypeEnum.NEW_STORY) || (m_sessionType == MyMwcStartSessionRequestTypeEnum.LOAD_CHECKPOINT))
                {
                    MySession.Static = new MySinglePlayerSession(difficulty);
                    MySession.Static.Init();

                    screenType = MyGuiScreenGamePlayType.GAME_STORY;

                    sessionType      = MyMwcSectorTypeEnum.STORY;
                    sessionStartType = m_sessionType == MyMwcStartSessionRequestTypeEnum.NEW_STORY ? MyMwcSessionStateEnum.NEW_GAME : MyMwcSessionStateEnum.LOAD_CHECKPOINT;
                    userId           = MyClientServer.LoggedPlayer.GetUserId();
                }
                else if (m_sessionType == MyMwcStartSessionRequestTypeEnum.EDITOR_SANDBOX)
                {
                    MySession.Static = new MySandboxSession();
                    MySession.Static.Init();

                    screenType = MyGuiScreenGamePlayType.EDITOR_SANDBOX;

                    Debug.Assert(m_sectorIdentifier.HasValue, "Sector identifier must be set for editor");
                    Debug.Assert(m_sectorIdentifier.Value.UserId == null || m_sectorIdentifier.Value.UserId == MyClientServer.LoggedPlayer.GetUserId(), "Sandbox sector user identifier must be null or same as current user");
                    sessionType      = MyMwcSectorTypeEnum.SANDBOX;
                    sessionStartType = MyMwcSessionStateEnum.EDITOR;
                    userId           = m_sectorIdentifier.Value.UserId;
                    position         = m_sectorIdentifier.Value.Position;
                }
                else if (m_sessionType == MyMwcStartSessionRequestTypeEnum.EDITOR_STORY)
                {
                    MySession.Static = new MySinglePlayerSession(difficulty);
                    MySession.Static.Init();

                    screenType = MyGuiScreenGamePlayType.EDITOR_STORY;

                    Debug.Assert(m_sectorIdentifier.HasValue, "Sector identifier must be set for editor");
                    sessionType      = MyMwcSectorTypeEnum.STORY;
                    sessionStartType = MyMwcSessionStateEnum.EDITOR;
                    userId           = null;
                    position         = m_sectorIdentifier.Value.Position;
                }
                else if (m_sessionType == MyMwcStartSessionRequestTypeEnum.EDITOR_MMO)
                {
                    MySession.Static = new MySinglePlayerSession(difficulty);
                    MySession.Static.Init();

                    screenType = MyGuiScreenGamePlayType.EDITOR_MMO;

                    Debug.Assert(m_sectorIdentifier.HasValue, "Sector identifier must be set for editor");
                    sessionType      = MyMwcSectorTypeEnum.MMO;
                    sessionStartType = MyMwcSessionStateEnum.EDITOR;
                    userId           = null;
                    position         = m_sectorIdentifier.Value.Position;
                }
                else if (
                    (m_sessionType == MyMwcStartSessionRequestTypeEnum.SANDBOX_OWN) ||
                    (m_sessionType == MyMwcStartSessionRequestTypeEnum.SANDBOX_FRIENDS) ||
                    (m_sessionType == MyMwcStartSessionRequestTypeEnum.SANDBOX_RANDOM))
                {
                    MySession.Static = new MySandboxSession();
                    MySession.Static.Init();

                    screenType = MyGuiScreenGamePlayType.GAME_SANDBOX;

                    Debug.Assert(m_sectorIdentifier.HasValue, "Sector identifier must be set for sandbox");
                    sessionType      = MyMwcSectorTypeEnum.SANDBOX;
                    sessionStartType = MyMwcSessionStateEnum.LOAD_CHECKPOINT;
                    userId           = m_sectorIdentifier.Value.UserId;
                    position         = m_sectorIdentifier.Value.Position;
                    //if (m_sessionType != MyMwcStartSessionRequestTypeEnum.SANDBOX_RANDOM)
                    //{
                    //    position = m_sectorIdentifier.Value.Position;
                    //}
                }
                else
                {
                    throw new NotImplementedException();
                }

                Action <MyMwcObjectBuilder_Checkpoint> enterSuccessAction = new Action <MyMwcObjectBuilder_Checkpoint>((checkpoint) =>
                {
                    OnSuccessEnter(screenType, m_sessionType, checkpoint);
                });

                MyGuiManager.AddScreen(new MyGuiScreenLoadCheckpointProgress(sessionType, sessionStartType, userId, position, m_checkpointName, enterSuccessAction));

                if (m_closeAfter != null)
                {
                    m_closeAfter.CloseScreenNow();
                }
            }
            else
            {
                MyMwcLog.WriteLine("Error starting the session: " + startSessionResponse.ToString());
                MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.StartGameFailed,
                                                                 MyTextsWrapperEnum.MessageBoxCaptionError, MyTextsWrapperEnum.Ok, null));
            }

            CloseScreen();
        }