public static void LoadMultiplayerBattleWorld(MyObjectBuilder_World world, MyMultiplayerBase multiplayerSession)
        {
            MyLog.Default.WriteLine("LoadMultiplayerBattleWorld() - Start");

            Debug.Assert(MySession.Static != null);
            if (MySession.Static == null)
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                return;
            }

            if (!MySteamWorkshop.CheckLocalModsAllowed(world.Checkpoint.Mods, false))
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText : MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType : MyMessageBoxButtonsType.OK,
                                           callback : delegate(MyGuiScreenMessageBox.ResultEnum result) { MyGuiScreenMainMenu.ReturnToMainMenu(); }));
                MyLog.Default.WriteLine("LoadMultiplayerBattleWorld() - End");
                return;
            }

            MySteamWorkshop.DownloadModsAsync(world.Checkpoint.Mods,
                                              onFinishedCallback : delegate(bool success)
            {
                if (success)
                {
                    MyScreenManager.CloseAllScreensNowExcept(null);
                    MyGuiSandbox.Update(MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS);

                    MyGuiScreenGamePlay.StartLoading(delegate
                    {
                        MySession.Static.LoadMultiplayerWorld(world, multiplayerSession);
                        Debug.Assert(MySession.Static.Battle);
                        if (BattleWorldLoaded != null)
                        {
                            BattleWorldLoaded();
                        }
                    });
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                               messageText : MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed),
                                               buttonType : MyMessageBoxButtonsType.OK,
                                               callback : delegate(MyGuiScreenMessageBox.ResultEnum result) { MyGuiScreenMainMenu.ReturnToMainMenu(); }));
                }
                MyLog.Default.WriteLine("LoadMultiplayerBattleWorld() - End");
            },
                                              onCancelledCallback : delegate()
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
            });
        }
        private static void OnJoinBattleFailed(MyGuiScreenProgress progress, MyMultiplayerBase multiplayer, string status)
        {
            MyGuiScreenMainMenu.UnloadAndExitToMenu();

            progress.Cancel();
            StringBuilder error = new StringBuilder();
            //error.AppendFormat(MySpaceTexts.DialogTextJoinBattleLobbyFailed, status);

            MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: error, messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError));

            MyGuiSandbox.AddScreen(mb);
        }
Example #3
0
        public static void DownloadBattleWorld(MyMultiplayerBase multiplayer)
        {
            StringBuilder text = MyTexts.Get(MySpaceTexts.MultiplayerStateConnectingToServer);

            MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MySpaceTexts.Cancel);

            MyGuiSandbox.AddScreen(progress);
            // Set focus to different control than Cancel button (because focused Cancel button can be unexpectedly pressed when sending a chat message - in case server has just started game).
            progress.FocusedControl = progress.RotatingWheel;

            progress.ProgressCancelled += () =>
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
            };

            DownloadWorld(progress, multiplayer);
        }
        private void OnLoadException(Exception e, StringBuilder errorText, float heightMultiplier = 1.0f)
        {
            MySandboxGame.Log.WriteLine("ERROR: Loading screen failed");
            MySandboxGame.Log.WriteLine(e);
            m_screenToLoad = null;

            // GamePlayScreen might not have been unloaded, so check this here
            if (MyGuiScreenGamePlay.Static != null)
            {
                MyGuiScreenGamePlay.Static.UnloadData();
                MyGuiScreenGamePlay.Static.UnloadContent();
            }
            // Reset this to true so we have sounds
            MySandboxGame.IsUpdateReady    = true;
            MySandboxGame.AreClipmapsReady = true;

            try
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
            }
            catch (Exception ex)
            {
                MySession.Static = null;
                MySandboxGame.Log.WriteLine("ERROR: failed unload after exception in loading !");
                MySandboxGame.Log.WriteLine(ex);
            }

            var errorScreen = MyGuiSandbox.CreateMessageBox(
                messageText: errorText,
                messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError));

            var size = errorScreen.Size.Value;

            size.Y          *= heightMultiplier;
            errorScreen.Size = size;
            errorScreen.RecreateControls(false);

            MyGuiSandbox.AddScreen(errorScreen);
        }
        public static void LoadMultiplayerSession(MyObjectBuilder_World world, MyMultiplayerBase multiplayerSession)
        {
            MyLog.Default.WriteLine("LoadSession() - Start");

            if (!MySteamWorkshop.CheckLocalModsAllowed(world.Checkpoint.Mods, false))
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            MySteamWorkshop.DownloadModsAsync(world.Checkpoint.Mods,
                                              onFinishedCallback :
                                              delegate(bool success, string mismatchMods)
            {
                if (success)
                {
                    CheckMismatchmods(mismatchMods, delegate(VRage.Game.ModAPI.ResultEnum val)
                    {
                        if (val == VRage.Game.ModAPI.ResultEnum.OK)
                        {
                            //Sandbox.Audio.MyAudio.Static.Mute = true;
                            MyScreenManager.CloseAllScreensNowExcept(null);
                            MyGuiSandbox.Update(VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS);

                            // May be called from gameplay, so we must make sure we unload the current game
                            if (MySession.Static != null)
                            {
                                MySession.Static.Unload();
                                MySession.Static = null;
                            }

                            MyGuiScreenGamePlay.StartLoading(delegate { MySession.LoadMultiplayer(world, multiplayerSession); });
                        }
                        else
                        {
                            MyGuiScreenMainMenu.UnloadAndExitToMenu();
                        }
                    });
                }
                else
                {
                    if (MyMultiplayer.Static != null)
                    {
                        MyMultiplayer.Static.Dispose();
                    }

                    if (MySteam.IsOnline)
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed),
                                                   buttonType: MyMessageBoxButtonsType.OK));
                    }
                    else
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline),
                                                   buttonType: MyMessageBoxButtonsType.OK));
                    }
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            },
                                              onCancelledCallback : delegate()
            {
                multiplayerSession.Dispose();
            });
        }