public void LoadMission(string sessionPath, string name, string description, bool multiplayer)
        {
            MyLog.Default.WriteLine("LoadSession() - Start");
            MyLog.Default.WriteLine(sessionPath);

            ulong checkpointSizeInBytes;
            var   checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out checkpointSizeInBytes);

            checkpoint.Settings.OnlineMode       = (MyOnlineModeEnum)m_onlineMode.GetSelectedKey();
            checkpoint.Settings.MaxPlayers       = (short)m_maxPlayersSlider.Value;
            checkpoint.Settings.Scenario         = true;
            checkpoint.Settings.GameMode         = MyGameModeEnum.Survival;
            checkpoint.Settings.ScenarioEditMode = false;

            if (!MySession.IsCompatibleVersion(checkpoint))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            if (!MySteamWorkshop.CheckLocalModsAllowed(checkpoint.Mods, checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }


            MySteamWorkshop.DownloadModsAsync(checkpoint.Mods, delegate(bool success)
            {
                if (success || (checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(checkpoint.Mods))
                {
                    //Sandbox.Audio.MyAudio.Static.Mute = true;

                    MyScreenManager.CloseAllScreensNowExcept(null);
                    MyGuiSandbox.Update(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;
                    }

                    //seed 0 has special meaning - please randomize at mission start. New seed will be saved and game will run with it ever since.
                    //  if you use this, YOU CANNOT HAVE ANY PROCEDURAL ASTEROIDS ALREADY SAVED
                    if (checkpoint.Settings.ProceduralSeed == 0)
                    {
                        checkpoint.Settings.ProceduralSeed = MyRandom.Instance.Next();
                    }

                    MyGuiScreenGamePlay.StartLoading(delegate
                    {
                        checkpoint.Settings.Scenario = true;
                        MySession.LoadMission(sessionPath, checkpoint, checkpointSizeInBytes, name, description);
                    });
                }
                else
                {
                    MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed).ToString());
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                               messageText : MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed),
                                               buttonType : MyMessageBoxButtonsType.OK, callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                    {
                        if (MyFakes.QUICK_LAUNCH != null)
                        {
                            MyGuiScreenMainMenu.ReturnToMainMenu();
                        }
                    }));
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            });
        }
Beispiel #2
0
        void ChangeName(string name)
        {
            name = MyUtils.StripInvalidChars(name);
            var    deleteName = m_blueprintName;
            string file       = Path.Combine(m_localBlueprintFolder, deleteName);
            string newFile    = Path.Combine(m_localBlueprintFolder, name);

            if (file == newFile)
            {
                return;
            }

            if (Directory.Exists(file))
            {
                if (Directory.Exists(newFile))
                {
                    if (file.ToLower() == newFile.ToLower())
                    {
                        m_loadedPrefab.ShipBlueprints[0].Id.SubtypeId             = name;
                        m_loadedPrefab.ShipBlueprints[0].Id.SubtypeName           = name;
                        m_loadedPrefab.ShipBlueprints[0].CubeGrids[0].DisplayName = name;
                        var tempDir = Path.Combine(m_localBlueprintFolder, "temp");
                        if (Directory.Exists(tempDir))
                        {
                            Directory.Delete(tempDir, true);
                        }
                        Directory.Move(file, tempDir);
                        Directory.Move(tempDir, newFile);
                        m_thumbnailImage.SetTexture(Path.Combine(newFile, "thumb.png"));
                        SavePrefabToFile(m_loadedPrefab, name, true);
                        m_blueprintName = name;
                        RefreshTextField();
                        m_parent.RefreshBlueprintList();
                    }
                    else
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   buttonType : MyMessageBoxButtonsType.YES_NO,
                                                   styleEnum : MyMessageBoxStyleEnum.Info,
                                                   messageCaption : new StringBuilder("Replace"),
                                                   messageText : new StringBuilder("Blueprint with the name \"" + name + "\" already exists. Do you want to replace it?"),
                                                   callback : delegate(MyGuiScreenMessageBox.ResultEnum callbackReturn)
                        {
                            if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
                            {
                                DeleteBlueprint(name);
                                m_loadedPrefab.ShipBlueprints[0].Id.SubtypeId             = name;
                                m_loadedPrefab.ShipBlueprints[0].Id.SubtypeName           = name;
                                m_loadedPrefab.ShipBlueprints[0].CubeGrids[0].DisplayName = name;
                                Directory.Move(file, newFile);
                                VRageRender.MyRenderProxy.UnloadTexture(Path.Combine(newFile, "thumb.png"));
                                m_thumbnailImage.SetTexture(Path.Combine(newFile, "thumb.png"));
                                SavePrefabToFile(m_loadedPrefab, name, true);
                                m_blueprintName = name;
                                RefreshTextField();
                                m_parent.RefreshBlueprintList();
                            }
                            else
                            {
                                return;
                            }
                        }));
                    }
                }
                else
                {
                    m_loadedPrefab.ShipBlueprints[0].Id.SubtypeId             = name;
                    m_loadedPrefab.ShipBlueprints[0].Id.SubtypeName           = name;
                    m_loadedPrefab.ShipBlueprints[0].CubeGrids[0].DisplayName = name;
                    try
                    {
                        Directory.Move(file, newFile);
                    }
                    catch (System.IO.IOException ex)
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   buttonType: MyMessageBoxButtonsType.OK,
                                                   styleEnum: MyMessageBoxStyleEnum.Error,
                                                   messageCaption: new StringBuilder("Delete"),
                                                   messageText: new StringBuilder("Cannot rename blueprint because it is used by another process."))
                                               );

                        return;
                    }

                    VRageRender.MyRenderProxy.UnloadTexture(Path.Combine(newFile, "thumb.png"));
                    m_thumbnailImage.SetTexture(Path.Combine(newFile, "thumb.png"));
                    SavePrefabToFile(m_loadedPrefab, name, true);
                    m_blueprintName = name;
                    RefreshTextField();
                    m_parent.RefreshBlueprintList();
                }
            }
        }
Beispiel #3
0
        //  This method is called every update (but only if application has focus)
        public override void HandleUnhandledInput(bool receivedFocusInThisUpdate)
        {
            if (MyInput.Static.ENABLE_DEVELOPER_KEYS || (MySession.Static != null && MySession.Static.Settings.EnableSpectator) || (MyMultiplayer.Static != null && MySession.LocalHumanPlayer != null && MyMultiplayer.Static.IsAdmin(MySession.LocalHumanPlayer.Id.SteamId)))
            {
                //Set camera to player
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SPECTATOR_NONE))
                {
                    if (MySession.ControlledEntity != null)
                    { //we already are controlling this object
                        if (MyFinalBuildConstants.IS_OFFICIAL)
                        {
                            SetCameraController();
                        }
                        else
                        {
                            var cameraController = MySession.GetCameraControllerEnum();
                            if (cameraController != MyCameraControllerEnum.Entity && cameraController != MyCameraControllerEnum.ThirdPersonSpectator)
                            {
                                SetCameraController();
                            }
                            else
                            {
                                var entities       = MyEntities.GetEntities().ToList();
                                int lastKnownIndex = entities.IndexOf(MySession.ControlledEntity.Entity);

                                var entitiesList = new List <MyEntity>();
                                if (lastKnownIndex + 1 < entities.Count)
                                {
                                    entitiesList.AddRange(entities.GetRange(lastKnownIndex + 1, entities.Count - lastKnownIndex - 1));
                                }

                                if (lastKnownIndex != -1)
                                {
                                    entitiesList.AddRange(entities.GetRange(0, lastKnownIndex + 1));
                                }

                                MyCharacter newControlledObject = null;

                                for (int i = 0; i < entitiesList.Count; i++)
                                {
                                    var character = entitiesList[i] as MyCharacter;
                                    if (character != null && !character.IsDead)
                                    {
                                        newControlledObject = character;
                                        break;
                                    }
                                }

                                if (MySession.LocalHumanPlayer != null && newControlledObject != null)
                                {
                                    MySession.LocalHumanPlayer.Controller.TakeControl(newControlledObject);
                                }
                            }

                            // We could have activated the cube builder in spectator, so deactivate it now
                            if (MyCubeBuilder.Static.IsActivated && !(MySession.ControlledEntity is MyCharacter))
                            {
                                MyCubeBuilder.Static.Deactivate();
                            }
                        }
                    }
                }

                //Set camera to following third person
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SPECTATOR_DELTA))
                {
                    if (MySession.ControlledEntity != null)
                    {
                        MySession.SetCameraController(MyCameraControllerEnum.SpectatorDelta);
                    }
                }

                //Set camera to spectator
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SPECTATOR_FREE))
                {
                    if (!MyFakes.ENABLE_BATTLE_SYSTEM || !MySession.Static.Battle || Sync.IsServer)
                    {
                        if (MySession.GetCameraControllerEnum() != MyCameraControllerEnum.Spectator)
                        {
                            MySession.SetCameraController(MyCameraControllerEnum.Spectator);
                        }
                        else if (MyInput.Static.IsAnyShiftKeyPressed())
                        {
                            MyFakes.ENABLE_DEVELOPER_SPECTATOR_CONTROLS = !MyFakes.ENABLE_DEVELOPER_SPECTATOR_CONTROLS;
                        }

                        if (MyInput.Static.IsAnyCtrlKeyPressed() && MySession.ControlledEntity != null)
                        {
                            MySpectator.Static.Position = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition() + MySpectator.Static.ThirdPersonCameraDelta;
                            MySpectator.Static.Target   = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition();
                        }
                    }
                }

                //Set camera to static spectator, non movable
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SPECTATOR_STATIC))
                {
                    if (MySession.ControlledEntity != null)
                    {
                        MySession.SetCameraController(MyCameraControllerEnum.SpectatorFixed);

                        if (MyInput.Static.IsAnyCtrlKeyPressed())
                        {
                            MySpectator.Static.Position = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition() + MySpectator.Static.ThirdPersonCameraDelta;
                            MySpectator.Static.Target   = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition();
                        }
                    }
                }

                //Open console
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.CONSOLE) && MyInput.Static.IsAnyAltKeyPressed())
                {
                    MyGuiScreenConsole.Show();
                }
            }

            if (MyDefinitionErrors.ShouldShowModErrors)
            {
                MyDefinitionErrors.ShouldShowModErrors = false;
                MyGuiSandbox.ShowModErrors();
            }

            // Switch view - cockpit on/off, third person
            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.CAMERA_MODE) && CanSwitchCamera)
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                SwitchCamera();
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.HELP_SCREEN))
            {
                if (MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    switch (MySandboxGame.Config.DebugComponentsInfo)
                    {
                    case MyDebugComponent.MyDebugComponentInfoState.NoInfo:
                        MySandboxGame.Config.DebugComponentsInfo = MyDebugComponent.MyDebugComponentInfoState.EnabledInfo;
                        break;

                    case MyDebugComponent.MyDebugComponentInfoState.EnabledInfo:
                        MySandboxGame.Config.DebugComponentsInfo = MyDebugComponent.MyDebugComponentInfoState.FullInfo;
                        break;

                    case MyDebugComponent.MyDebugComponentInfoState.FullInfo:
                        MySandboxGame.Config.DebugComponentsInfo = MyDebugComponent.MyDebugComponentInfoState.NoInfo;
                        break;
                    }

                    MySandboxGame.Config.Save();
                }
                else
                if (MyGuiScreenGamePlay.ActiveGameplayScreen == null)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    MyGuiSandbox.AddScreen(MyGuiScreenGamePlay.ActiveGameplayScreen = MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.HelpScreen));
                }
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.TOGGLE_HUD))
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                MyHud.MinimalHud = !MyHud.MinimalHud;
            }

            if (MyPerGameSettings.SimplePlayerNames && MyInput.Static.IsNewGameControlPressed(MyControlsSpace.BROADCASTING))
            {
                MyHud.LocationMarkers.Visible = !MyHud.LocationMarkers.Visible;
            }

            var controlledObject        = MySession.ControlledEntity;
            var currentCameraController = MySession.Static.CameraController;

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.MISSION_SETTINGS) && MyGuiScreenGamePlay.ActiveGameplayScreen == null &&
                MyPerGameSettings.Game == Sandbox.Game.GameEnum.SE_GAME &&
                MyFakes.ENABLE_MISSION_TRIGGERS &&
                MySession.Static.Settings.ScenarioEditMode)
            {
                MyGuiSandbox.AddScreen(new Sandbox.Game.Screens.MyGuiScreenMissionTriggers());
            }

            MyStringId context = controlledObject != null ? controlledObject.ControlContext : MySpaceBindingCreator.CX_BASE;

            bool handledByUseObject = false;

            if (MySession.ControlledEntity is VRage.Game.Entity.UseObject.IMyUseObject)
            {
                handledByUseObject = (MySession.ControlledEntity as VRage.Game.Entity.UseObject.IMyUseObject).HandleInput();
            }

            if (controlledObject != null && !handledByUseObject)
            {
                if (!MySandboxGame.IsPaused)
                {
                    if (context == MySpaceBindingCreator.CX_BUILD_MODE || context == MySpaceBindingCreator.CX_CHARACTER || context == MySpaceBindingCreator.CX_SPACESHIP)
                    {
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED))
                        {
                            if (MyToolbarComponent.CurrentToolbar.ShouldActivateSlot)
                            {
                                MyToolbarComponent.CurrentToolbar.ActivateStagedSelectedItem();
                            }
                            else
                            {
                                controlledObject.BeginShoot(MyShootActionEnum.PrimaryAction);
                            }
                        }

                        if (MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_RELEASED))
                        {
                            controlledObject.EndShoot(MyShootActionEnum.PrimaryAction);
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.SECONDARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED))
                        {
                            controlledObject.BeginShoot(MyShootActionEnum.SecondaryAction);
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.SECONDARY_TOOL_ACTION, MyControlStateType.NEW_RELEASED))
                        {
                            controlledObject.EndShoot(MyShootActionEnum.SecondaryAction);
                        }
                    }

                    if (context == MySpaceBindingCreator.CX_CHARACTER || context == MySpaceBindingCreator.CX_SPACESHIP)
                    {
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.USE, MyControlStateType.NEW_PRESSED))
                        {
                            // Key press
                            if (currentCameraController != null)
                            {
                                if (!currentCameraController.HandleUse())
                                {
                                    controlledObject.Use();
                                }
                            }
                            else
                            {
                                controlledObject.Use();
                            }
                        }
                        else if (MyControllerHelper.IsControl(context, MyControlsSpace.USE, MyControlStateType.PRESSED))
                        {
                            // Key not pressed this frame, holding from previous
                            controlledObject.UseContinues();
                        }
                        else if (MyControllerHelper.IsControl(context, MyControlsSpace.USE, MyControlStateType.NEW_RELEASED))
                        {
                            controlledObject.UseFinished();
                        }

                        //Temp fix until spectators are implemented as entities
                        //Prevents controlled object from getting input while spectator mode is enabled
                        if (!(MySession.Static.CameraController is MySpectatorCameraController && MySpectatorCameraController.Static.SpectatorCameraMovement == MySpectatorCameraMovementEnum.UserControlled))
                        {
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.CROUCH, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.Crouch();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.CROUCH, MyControlStateType.PRESSED))
                            {
                                controlledObject.Down();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.SPRINT, MyControlStateType.PRESSED))
                            {
                                controlledObject.Sprint();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.JUMP, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.Jump();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.JUMP, MyControlStateType.PRESSED))
                            {
                                controlledObject.Up();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.SWITCH_WALK, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.SwitchWalk();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.BROADCASTING, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.SwitchBroadcasting();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.HELMET, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.SwitchHelmet();
                            }
                        }

                        if (MyControllerHelper.IsControl(context, MyControlsSpace.DAMPING, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchDamping();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.THRUSTS, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchThrusts();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.HEADLIGHTS, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchLights();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.TOGGLE_REACTORS, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchReactors();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.LANDING_GEAR, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchLeadingGears();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.SUICIDE, MyControlStateType.NEW_PRESSED))
                        {
                            controlledObject.Die();
                        }
                        if ((controlledObject as MyCockpit) != null && MyControllerHelper.IsControl(context, MyControlsSpace.CUBE_COLOR_CHANGE, MyControlStateType.NEW_PRESSED))
                        {
                            (controlledObject as MyCockpit).SwitchWeaponMode();
                        }
                    }
                }
                if (MyControllerHelper.IsControl(context, MyControlsSpace.TERMINAL, MyControlStateType.NEW_PRESSED) && MyGuiScreenGamePlay.ActiveGameplayScreen == null)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                    controlledObject.ShowTerminal();
                }

                if (MyControllerHelper.IsControl(context, MyControlsSpace.INVENTORY, MyControlStateType.NEW_PRESSED) && MyGuiScreenGamePlay.ActiveGameplayScreen == null)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                    controlledObject.ShowInventory();
                }

                if (MyControllerHelper.IsControl(context, MyControlsSpace.CONTROL_MENU, MyControlStateType.NEW_PRESSED) && MyGuiScreenGamePlay.ActiveGameplayScreen == null)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                    m_controlMenu.OpenControlMenu(controlledObject);
                }

                if (!MyCompilationSymbols.RenderProfiling && MyControllerHelper.IsControl(context, MyControlsSpace.CHAT_SCREEN, MyControlStateType.NEW_PRESSED))
                {
                    if (MyGuiScreenChat.Static == null)
                    {
                        Vector2 chatPos = new Vector2(0.01f, 0.84f);
                        chatPos = MyGuiScreenHudBase.ConvertHudToNormalizedGuiPosition(ref chatPos);
                        MyGuiScreenChat chatScreen = new MyGuiScreenChat(chatPos);
                        MyGuiSandbox.AddScreen(chatScreen);
                    }
                }

                if (MyPerGameSettings.VoiceChatEnabled)
                {
                    if (MyControllerHelper.IsControl(context, MyControlsSpace.VOICE_CHAT, MyControlStateType.NEW_PRESSED))
                    {
                        MyVoiceChatSessionComponent.Static.StartRecording();
                    }
                    //else if (MyControllerHelper.IsControl(context, MyControlsSpace.VOICE_CHAT, MyControlStateType.NEW_RELEASED))
                    // TODO: If other key was pressed during VOIP, NEW_RELEASED will return false even if this key was pressed, is this correct? We don't store key states?
                    else if (MyVoiceChatSessionComponent.Static.IsRecording && !MyControllerHelper.IsControl(context, MyControlsSpace.VOICE_CHAT, MyControlStateType.PRESSED))
                    {
                        MyVoiceChatSessionComponent.Static.StopRecording();
                    }
                }
            }

            MoveAndRotatePlayerOrCamera();

            // Quick save or quick load.
            if (MyInput.Static.IsNewKeyPressed(MyKeys.F5))
            {
                if (!MySession.Static.IsScenario)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    var currentSession = MySession.Static.CurrentPath;

                    if (MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        if (MySession.Static.ClientCanSave || Sync.IsServer)
                        {
                            if (!MyAsyncSaving.InProgress)
                            {
                                var messageBox = MyGuiSandbox.CreateMessageBox(
                                    buttonType : MyMessageBoxButtonsType.YES_NO,
                                    messageText : MyTexts.Get(MySpaceTexts.MessageBoxTextAreYouSureYouWantToQuickSave),
                                    messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionPleaseConfirm),
                                    callback : delegate(MyGuiScreenMessageBox.ResultEnum callbackReturn)
                                {
                                    if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
                                    {
                                        MyAsyncSaving.Start(() => MySector.ResetEyeAdaptation = true);    //black screen after save
                                    }
                                });
                                messageBox.SkipTransition      = true;
                                messageBox.CloseBeforeCallback = true;
                                MyGuiSandbox.AddScreen(messageBox);
                            }
                        }
                        else
                        {
                            MyHud.Notifications.Add(MyNotificationSingletons.ClientCannotSave);
                        }
                    }
                    else if (Sync.IsServer)
                    {
                        ShowLoadMessageBox(currentSession);
                    }
                    else
                    {
                        // Is multiplayer client, reconnect
                        ShowReconnectMessageBox();
                    }
                }
            }

            //  Launch main menu
            if (MyInput.Static.IsNewKeyPressed(MyKeys.Escape) ||
                MyControllerHelper.IsControl(context, MyControlsGUI.MAIN_MENU, MyControlStateType.NEW_PRESSED))
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);

                //Allow changing video options from game in DX version
                MyGuiScreenMainMenu.AddMainMenu();
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.F3))
            {
                if (Sync.MultiplayerActive)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    MyGuiSandbox.AddScreen(new MyGuiScreenPlayers());
                }
                else
                {
                    MyHud.Notifications.Add(MyNotificationSingletons.MultiplayerDisabled);
                }
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.BUILD_SCREEN) && MyGuiScreenGamePlay.ActiveGameplayScreen == null)
            {
                if (MyGuiScreenCubeBuilder.Static == null && (MySession.ControlledEntity is MyShipController || MySession.ControlledEntity is MyCharacter))
                {
                    int offset = 0;
                    if (MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        offset += 6;
                    }
                    if (MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        offset += 12;
                    }
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    MyGuiSandbox.AddScreen(
                        MyGuiScreenGamePlay.ActiveGameplayScreen = MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.ToolbarConfigScreen,
                                                                                             offset,
                                                                                             MySession.ControlledEntity as MyShipController)
                        );
                }
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.PAUSE_GAME))
            {
                MySandboxGame.UserPauseToggle();
            }

            if (MySession.Static != null)
            {
                if (MyInput.Static.IsNewKeyPressed(MyKeys.F10))
                {
                    if (MyPerGameSettings.GUI.VoxelMapEditingScreen != null && MySession.Static.CreativeMode && MyInput.Static.IsAnyShiftKeyPressed())
                    { // Shift+F10
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.VoxelMapEditingScreen));
                    }
                    else
                    { // F10
                        if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static.Battle)
                        {
                            if (MyPerGameSettings.GUI.BattleBlueprintScreen != null)
                            {
                                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.BattleBlueprintScreen));
                            }
                            else
                            {
                                Debug.Fail("No battle blueprint screen");
                            }
                        }
                        else
                        {
                            MyGuiSandbox.AddScreen(new MyGuiBlueprintScreen(MyCubeBuilder.Static.Clipboard));
                        }
                    }
                }
            }

            // F11, mod debug
            if (MyInput.Static.IsNewKeyPressed(MyKeys.F11) && !MyInput.Static.IsAnyShiftKeyPressed() && !MyInput.Static.IsAnyCtrlKeyPressed())
            {
                MyDX9Gui.SwitchModDebugScreen();
            }
        }
Beispiel #4
0
        void OnPublishClick(MyGuiControlButton sender)
        {
            var row = m_sessionsTable.SelectedRow;

            if (row == null)
            {
                return;
            }
            var save = FindSave(row);

            if (save != null)
            {
                if (MyFakes.XBOX_PREVIEW)
                {
                    MyGuiSandbox.Show(MySpaceTexts.MessageBoxTextErrorFeatureNotAvailableYet, MySpaceTexts.MessageBoxCaptionError);
                    return;
                }

                MyStringId textQuestion, captionQuestion;
                if (save.Item2.WorkshopId.HasValue)
                {
                    textQuestion    = MySpaceTexts.MessageBoxTextDoYouWishToUpdateWorld;
                    captionQuestion = MySpaceTexts.MessageBoxCaptionDoYouWishToUpdateWorld;
                }
                else
                {
                    textQuestion    = MySpaceTexts.MessageBoxTextDoYouWishToPublishWorld;
                    captionQuestion = MySpaceTexts.MessageBoxCaptionDoYouWishToPublishWorld;
                }

                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           styleEnum : MyMessageBoxStyleEnum.Info,
                                           buttonType : MyMessageBoxButtonsType.YES_NO,
                                           messageText : MyTexts.Get(textQuestion),
                                           messageCaption : MyTexts.Get(captionQuestion),
                                           callback : delegate(MyGuiScreenMessageBox.ResultEnum val)
                {
                    if (val == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        Action <MyGuiScreenMessageBox.ResultEnum, string[]> onTagsChosen = delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags)
                        {
                            if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES)
                            {
                                MySteamWorkshop.PublishWorldAsync(save.Item1, save.Item2.SessionName, save.Item2.Description, save.Item2.WorkshopId, outTags, SteamSDK.PublishedFileVisibility.Public,
                                                                  callbackOnFinished : delegate(bool success, Result result, ulong publishedFileId)
                                {
                                    if (success)
                                    {
                                        ulong dummy;
                                        var checkpoint        = MyLocalCache.LoadCheckpoint(save.Item1, out dummy);
                                        save.Item2.WorkshopId = publishedFileId;
                                        checkpoint.WorkshopId = publishedFileId;
                                        MyLocalCache.SaveCheckpoint(checkpoint, save.Item1);
                                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                                   styleEnum: MyMessageBoxStyleEnum.Info,
                                                                   messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextWorldPublished),
                                                                   messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionWorldPublished),
                                                                   callback: (a) =>
                                        {
                                            MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId));
                                        }));
                                    }
                                    else
                                    {
                                        MyStringId error;
                                        switch (result)
                                        {
                                        case Result.AccessDenied:
                                            error = MySpaceTexts.MessageBoxTextPublishFailed_AccessDenied;
                                            break;

                                        default:
                                            error = MySpaceTexts.MessageBoxTextWorldPublishFailed;
                                            break;
                                        }

                                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                                   messageText: MyTexts.Get(error),
                                                                   messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionWorldPublishFailed)));
                                    }
                                });
                            }
                        };

                        if (MySteamWorkshop.WorldCategories.Length > 0)
                        {
                            MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_WORLD_TAG, MySteamWorkshop.WorldCategories, null, onTagsChosen));
                        }
                        else
                        {
                            onTagsChosen(MyGuiScreenMessageBox.ResultEnum.YES, new string[] { MySteamWorkshop.WORKSHOP_WORLD_TAG });
                        }
                    }
                }));
            }
        }
        void OnUserJoined(ref JoinResultMsg msg, ulong sender)
        {
            if (msg.JoinResult == JoinResult.OK)
            {
                if (OnJoin != null)
                {
                    OnJoin();
                    OnJoin         = null;
                    m_clientJoined = true;
                }
            }
            else if (msg.JoinResult == JoinResult.NotInGroup)
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                Dispose();

                ulong  groupId   = Server.GetGameTagByPrefixUlong("groupId");
                string groupName = MySteam.API.Friends.GetClanName(groupId);

                var messageBox = MyGuiSandbox.CreateMessageBox(
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                    messageText: new StringBuilder(string.Format(
                                                       MyTexts.GetString(MyCommonTexts.MultiplayerErrorNotInGroup), groupName)),
                    buttonType: MyMessageBoxButtonsType.YES_NO);
                messageBox.ResultCallback = delegate(MyGuiScreenMessageBox.ResultEnum result)
                {
                    if (result == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        MySteam.API.OpenOverlayUser(groupId);
                    }
                    ;
                };
                MyGuiSandbox.AddScreen(messageBox);
            }
            else if (msg.JoinResult == JoinResult.BannedByAdmins)
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                Dispose();

                ulong admin = msg.Admin;

                if (admin != 0)
                {
                    var messageBox = MyGuiSandbox.CreateMessageBox(
                        messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                        messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorBannedByAdminsWithDialog),
                        buttonType: MyMessageBoxButtonsType.YES_NO);
                    messageBox.ResultCallback = delegate(MyGuiScreenMessageBox.ResultEnum result)
                    {
                        if (result == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            MySteam.API.OpenOverlayUser(admin);
                        }
                        ;
                    };
                    MyGuiSandbox.AddScreen(messageBox);
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                               messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorBannedByAdmins)));
                }
            }
            else
            {
                MyStringId resultText = MyCommonTexts.MultiplayerErrorConnectionFailed;

                switch (msg.JoinResult)
                {
                case JoinResult.AlreadyJoined:
                    resultText = MyCommonTexts.MultiplayerErrorAlreadyJoined;
                    break;

                case JoinResult.ServerFull:
                    resultText = MyCommonTexts.MultiplayerErrorServerFull;
                    break;

                case JoinResult.SteamServersOffline:
                    resultText = MyCommonTexts.MultiplayerErrorSteamServersOffline;
                    break;

                case JoinResult.TicketInvalid:
                    resultText = MyCommonTexts.MultiplayerErrorTicketInvalid;
                    break;

                case JoinResult.GroupIdInvalid:
                    resultText = MyCommonTexts.MultiplayerErrorGroupIdInvalid;
                    break;

                case JoinResult.TicketCanceled:
                    resultText = MyCommonTexts.MultiplayerErrorTicketCanceled;
                    break;

                case JoinResult.TicketAlreadyUsed:
                    resultText = MyCommonTexts.MultiplayerErrorTicketAlreadyUsed;
                    break;

                case JoinResult.LoggedInElseWhere:
                    resultText = MyCommonTexts.MultiplayerErrorLoggedInElseWhere;
                    break;

                case JoinResult.NoLicenseOrExpired:
                    resultText = MyCommonTexts.MultiplayerErrorNoLicenseOrExpired;
                    break;

                case JoinResult.UserNotConnected:
                    resultText = MyCommonTexts.MultiplayerErrorUserNotConnected;
                    break;

                case JoinResult.VACBanned:
                    resultText = MyCommonTexts.MultiplayerErrorVACBanned;
                    break;

                case JoinResult.VACCheckTimedOut:
                    resultText = MyCommonTexts.MultiplayerErrorVACCheckTimedOut;
                    break;

                default:
                    System.Diagnostics.Debug.Fail("Unknown JoinResult");
                    break;
                }

                Dispose();
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(resultText)));
                return;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Starts new session and unloads outdated if theres any.
        /// </summary>
        /// <param name="sessionName">Created session name.</param>
        /// <param name="settings">Session settings OB.</param>
        /// <param name="mods">Mod selection.</param>
        /// <param name="scenarioDefinition">World generator argument.</param>
        /// <param name="asteroidAmount">Hostility settings.</param>
        /// <param name="description">Session description.</param>
        /// <param name="passwd">Session password.</param>
        public static void StartNewSession(string sessionName,
                                           MyObjectBuilder_SessionSettings settings,
                                           List <MyObjectBuilder_Checkpoint.ModItem> mods,
                                           MyScenarioDefinition scenarioDefinition = null,
                                           int asteroidAmount = 0,
                                           string description = "",
                                           string passwd      = "")
        {
            MyLog.Default.WriteLine("StartNewSandbox - Start");

            if (!MySteamWorkshop.CheckLocalModsAllowed(mods, settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                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(mods, delegate(bool success, string mismatchMods)
            {
                if (success || (settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(mods))
                {
                    CheckMismatchmods(mismatchMods, callback : delegate(ResultEnum val)
                    {
                        MyScreenManager.RemoveAllScreensExcept(null);

                        if (asteroidAmount < 0)
                        {
                            MyWorldGenerator.SetProceduralSettings(asteroidAmount, settings);
                            asteroidAmount = 0;
                        }

                        MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom);

                        StartLoading(delegate
                        {
                            MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom);

                            MySession.Start(
                                sessionName,
                                description,
                                passwd,
                                settings,
                                mods,
                                new MyWorldGenerator.Args()
                            {
                                AsteroidAmount = asteroidAmount,
                                Scenario       = scenarioDefinition
                            }
                                );
                        });
                    });
                }
                else
                {
                    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("StartNewSandbox - End");
            });
        }
 void OnDetails(MyGuiControlButton button)
 {
     if (m_selectedItem == null)
     {
         if (m_activeDetail)
         {
             MyScreenManager.RemoveScreen(m_detailScreen);
         }
         return;
     }
     else if (m_activeDetail)
     {
         MyScreenManager.RemoveScreen(m_detailScreen);
     }
     else if (!m_activeDetail)
     {
         if ((m_selectedItem.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.LOCAL)
         {
             var path = Path.Combine(m_localBlueprintFolder, m_selectedItem.Text.ToString(), "bp.sbc");
             if (File.Exists(path))
             {
                 m_thumbnailImage.Visible = false;
                 m_detailScreen           = new MyGuiDetailScreenLocal(
                     callBack : delegate(MyGuiControlListbox.Item item)
                 {
                     if (item == null)
                     {
                         m_screenshotButton.Enabled = false;
                         m_detailsButton.Enabled    = false;
                         m_replaceButton.Enabled    = false;
                         m_deleteButton.Enabled     = false;
                     }
                     m_selectedItem = item;
                     m_activeDetail = false;
                     m_detailScreen = null;
                     if (Task.IsComplete)
                     {
                         RefreshBlueprintList();
                     }
                 },
                     selectedItem: m_selectedItem,
                     parent: this,
                     thumbnailTexture: m_selectedImage.BackgroundTexture,
                     textScale: m_textScale
                     );
                 m_activeDetail = true;
                 MyScreenManager.InputToNonFocusedScreens = true;
                 MyScreenManager.AddScreen(m_detailScreen);
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                            buttonType: MyMessageBoxButtonsType.OK,
                                            styleEnum: MyMessageBoxStyleEnum.Error,
                                            messageCaption: new StringBuilder("Error"),
                                            messageText: new StringBuilder("Cannot find the blueprint file.")
                                            ));
             }
         }
         else if ((m_selectedItem.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.DEFAULT)
         {
             var path = Path.Combine(m_defaultBlueprintFolder, m_selectedItem.Text.ToString(), "bp.sbc");
             if (File.Exists(path))
             {
                 m_thumbnailImage.Visible = false;
                 m_detailScreen           = new MyGuiDetailScreenDefault(
                     callBack : delegate(MyGuiControlListbox.Item item)
                 {
                     if (item == null)
                     {
                         m_screenshotButton.Enabled = false;
                         m_detailsButton.Enabled    = false;
                         m_replaceButton.Enabled    = false;
                         m_deleteButton.Enabled     = false;
                     }
                     m_selectedItem = item;
                     m_activeDetail = false;
                     m_detailScreen = null;
                     if (Task.IsComplete)
                     {
                         RefreshBlueprintList();
                     }
                 },
                     selectedItem: m_selectedItem,
                     parent: this,
                     thumbnailTexture: m_selectedImage.BackgroundTexture,
                     textScale: m_textScale
                     );
                 m_activeDetail = true;
                 MyScreenManager.InputToNonFocusedScreens = true;
                 MyScreenManager.AddScreen(m_detailScreen);
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                            buttonType: MyMessageBoxButtonsType.OK,
                                            styleEnum: MyMessageBoxStyleEnum.Error,
                                            messageCaption: new StringBuilder("Error"),
                                            messageText: new StringBuilder("Cannot find the blueprint file.")
                                            ));
             }
         }
         else if ((m_selectedItem.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.STEAM)
         {
             var path2 = Path.Combine(m_workshopBlueprintFolder, (m_selectedItem.UserData as MyBlueprintItemInfo).PublishedItemId.ToString() + m_workshopBlueprintSuffix);
             if (File.Exists(path2))
             {
                 m_thumbnailImage.Visible = false;
                 m_detailScreen           = new MyGuiDetailScreenSteam(
                     callBack : delegate(MyGuiControlListbox.Item item)
                 {
                     m_selectedItem = item;
                     m_activeDetail = false;
                     m_detailScreen = null;
                     if (Task.IsComplete)
                     {
                         RefreshBlueprintList();
                     }
                 },
                     selectedItem: m_selectedItem,
                     parent: this,
                     thumbnailTexture: m_selectedImage.BackgroundTexture,
                     textScale: m_textScale
                     );
                 m_activeDetail = true;
                 MyScreenManager.InputToNonFocusedScreens = true;
                 MyScreenManager.AddScreen(m_detailScreen);
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                            buttonType: MyMessageBoxButtonsType.OK,
                                            styleEnum: MyMessageBoxStyleEnum.Error,
                                            messageCaption: new StringBuilder("Error"),
                                            messageText: new StringBuilder("Cannot find the blueprint file.")
                                            ));
             }
         }
     }
 }
Beispiel #8
0
        private void StartNewSandbox()
        {
            MyLog.Default.WriteLine("StartNewSandbox - Start");

            GetSettingsFromControls();
            if (!MySteamWorkshop.CheckLocalModsAllowed(m_mods, m_settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                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(m_mods, delegate(bool success, string mismatchMods)
            {
                if (success || (m_settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(m_mods))
                {
                    MyGuiScreenLoadSandbox.CheckMismatchmods(mismatchMods, callback : delegate(VRage.Game.ModAPI.ResultEnum val)
                    {
                        MyScreenManager.RemoveAllScreensExcept(null);

                        if (AsteroidAmount < 0)
                        {
                            MyWorldGenerator.SetProceduralSettings(AsteroidAmount, m_settings);
                            m_asteroidAmount = 0;
                        }

                        MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom);

                        MyGuiScreenGamePlay.StartLoading(delegate
                        {
                            MySession.Start(
                                m_nameTextbox.Text,
                                GetDescription(),
                                GetPassword(),
                                m_settings,
                                m_mods,
                                new MyWorldGenerator.Args()
                            {
                                AsteroidAmount = this.AsteroidAmount,
                                Scenario       = (m_scenarioTypesGroup.SelectedButton as MyGuiControlScenarioButton).Scenario
                            }
                                );
                        });
                    });
                }
                else
                {
                    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("StartNewSandbox - End");
            });
        }
 void OnDetails(MyGuiControlButton button)
 {
     if (m_selectedItem == null)
     {
         if (m_activeDetail)
         {
             MyScreenManager.RemoveScreen(m_detailScreen);
         }
         return;
     }
     else if (m_activeDetail)
     {
         MyScreenManager.RemoveScreen(m_detailScreen);
     }
     else if (!m_activeDetail)
     {
         if ((m_selectedItem.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.LOCAL)
         {
             var path = Path.Combine(m_localBlueprintFolder, m_selectedItem.Text.ToString());
             if (Directory.Exists(path))
             {
                 m_detailScreen = new MyGuiDetailScreenScriptLocal(
                     callBack : delegate(MyScriptItemInfo item)
                 {
                     if (item == null)
                     {
                         m_renameButton.Enabled  = false;
                         m_detailsButton.Enabled = false;
                         m_deleteButton.Enabled  = false;
                     }
                     m_activeDetail = false;
                     if (m_task.IsComplete)
                     {
                         RefreshBlueprintList(m_detailScreen.WasPublished);
                     }
                 },
                     selectedItem: (m_selectedItem.UserData  as MyScriptItemInfo),
                     parent: this,
                     textScale: m_textScale
                     );
                 m_activeDetail = true;
                 MyScreenManager.InputToNonFocusedScreens = true;
                 MyScreenManager.AddScreen(m_detailScreen);
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                            buttonType: MyMessageBoxButtonsType.OK,
                                            styleEnum: MyMessageBoxStyleEnum.Error,
                                            messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                            messageText: MyTexts.Get(MySpaceTexts.ProgrammableBlock_ScriptNotFound)
                                            ));
             }
         }
         else if ((m_selectedItem.UserData as MyBlueprintItemInfo).Type == MyBlueprintTypeEnum.STEAM)
         {
             m_detailScreen = new MyGuiDetailScreenScriptLocal(
                 callBack : delegate(MyScriptItemInfo item)
             {
                 m_activeDetail = false;
                 if (m_task.IsComplete)
                 {
                     RefreshBlueprintList();
                 }
             },
                 selectedItem: (m_selectedItem.UserData as MyScriptItemInfo),
                 parent: this,
                 textScale: m_textScale
                 );
             m_activeDetail = true;
             MyScreenManager.InputToNonFocusedScreens = true;
             MyScreenManager.AddScreen(m_detailScreen);
         }
     }
 }
        public static void LoadMission(string sessionPath, bool multiplayer, MyOnlineModeEnum onlineMode, short maxPlayers)
        {
            MyLog.Default.WriteLine("LoadSession() - Start");
            MyLog.Default.WriteLine(sessionPath);

            ulong checkpointSizeInBytes;
            var   checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out checkpointSizeInBytes);

            var persistentEditMode = checkpoint.Settings.ScenarioEditMode;

            checkpoint.Settings.OnlineMode       = onlineMode;
            checkpoint.Settings.MaxPlayers       = maxPlayers;
            checkpoint.Settings.Scenario         = true;
            checkpoint.Settings.GameMode         = MyGameModeEnum.Survival;
            checkpoint.Settings.ScenarioEditMode = false;

            if (!MySession.IsCompatibleVersion(checkpoint))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            if (!MySteamWorkshop.CheckLocalModsAllowed(checkpoint.Mods, checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            m_checkpointData = new CheckpointData()
            {
                Checkpoint         = checkpoint,
                CheckpointSize     = checkpointSizeInBytes,
                PersistentEditMode = persistentEditMode,
                SessionPath        = sessionPath,
            };

            if (checkpoint.BriefingVideo != null && checkpoint.BriefingVideo.Length > 0 && !MyFakes.XBOX_PREVIEW)
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionVideo),
                                           messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextWatchVideo),
                                           buttonType: MyMessageBoxButtonsType.YES_NO,
                                           callback: OnVideoMessageBox));
            }
            else
            {
                var checkpointData = m_checkpointData.Value;
                m_checkpointData = null;
                LoadMission(checkpointData);
            }
        }
Beispiel #11
0
        void OnPublishButtonClick(MyGuiControlButton sender)
        {
            var row = m_scenarioTable.SelectedRow;

            if (row == null)
            {
                return;
            }

            if (row.UserData == null)
            {
                return;
            }

            string      fullPath  = (string)(((Tuple <string, MyWorldInfo>)row.UserData).Item1);
            MyWorldInfo worldInfo = FindSave(m_scenarioTable.SelectedRow).Item2;
            //var mod = (MyObjectBuilder_Checkpoint.ModItem)row.UserData;
            //var nameSB = m_selectedRow.GetCell(1).Text;
            //var name = nameSB.ToString();

            MyStringId textQuestion, captionQuestion;

            if (worldInfo.WorkshopId != null)
            {
                textQuestion    = MySpaceTexts.MessageBoxTextDoYouWishToUpdateScenario;
                captionQuestion = MySpaceTexts.MessageBoxCaptionDoYouWishToUpdateScenario;
            }
            else
            {
                textQuestion    = MySpaceTexts.MessageBoxTextDoYouWishToPublishScenario;
                captionQuestion = MySpaceTexts.MessageBoxCaptionDoYouWishToPublishScenario;
            }

            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                       styleEnum : MyMessageBoxStyleEnum.Info,
                                       buttonType : MyMessageBoxButtonsType.YES_NO,
                                       messageText : MyTexts.Get(textQuestion),
                                       messageCaption : MyTexts.Get(captionQuestion),
                                       callback : delegate(MyGuiScreenMessageBox.ResultEnum val)
            {
                if (val == MyGuiScreenMessageBox.ResultEnum.YES)
                {
                    string[] inTags    = null;
                    var subscribedItem = GetSubscribedItem(worldInfo.WorkshopId);
                    if (subscribedItem != null)
                    {
                        inTags = subscribedItem.Tags;

                        if (subscribedItem.SteamIDOwner != Sync.MyId)
                        {
                            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                       messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextPublishFailed_OwnerMismatchMod),//TODO rename
                                                       messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionModPublishFailed)));
                            return;
                        }
                    }

                    /*MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_SCENARIO_TAG, MySteamWorkshop.ScenarioCategories, inTags, delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags)
                     * {
                     *  if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES)
                     *  {*/
                    MySteamWorkshop.PublishScenarioAsync(fullPath, worldInfo.SessionName, worldInfo.Description, worldInfo.WorkshopId, /*outTags,*/ SteamSDK.PublishedFileVisibility.Public, callbackOnFinished : delegate(bool success, Result result, ulong publishedFileId)           //TODO public visibility!!
                    {
                        if (success)
                        {
                            ulong dummy;
                            var checkpoint        = MyLocalCache.LoadCheckpoint(fullPath, out dummy);
                            worldInfo.WorkshopId  = publishedFileId;
                            checkpoint.WorkshopId = publishedFileId;
                            MyLocalCache.SaveCheckpoint(checkpoint, fullPath);

                            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                       styleEnum: MyMessageBoxStyleEnum.Info,
                                                       messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextScenarioPublished),
                                                       messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionScenarioPublished),
                                                       callback: (a) =>
                            {
                                MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId));
                                FillList();
                            }));
                        }
                        else
                        {
                            MyStringId error;
                            switch (result)
                            {
                            case Result.AccessDenied:
                                error = MyCommonTexts.MessageBoxTextPublishFailed_AccessDenied;
                                break;

                            default:
                                error = MySpaceTexts.MessageBoxTextScenarioPublishFailed;
                                break;
                            }

                            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                       messageText: MyTexts.Get(error),
                                                       messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionModPublishFailed)));
                        }
                    });            /*
                                    * }
                                    * }));*/
                }
            }));
        }
        //loads next mission, SP only
        //id can be workshop ID or save name (in that case official scenarios are searched first, if not found, then user's saves)
        public static void LoadNextScenario(string id)
        {
            if (MySession.Static.OnlineMode != MyOnlineModeEnum.OFFLINE)
            {
                return;
            }
            MyAPIGateway.Utilities.ShowNotification(MyTexts.GetString(MySpaceTexts.NotificationNextScenarioWillLoad), 10000);
            ulong workshopID;

            if (ulong.TryParse(id, out workshopID))
            {
                //scenario from steam, without the user needing to subscribe it first:
                if (!MySteam.IsOnline)
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextWorkshopDownloadFailed),
                                               messageCaption: MyTexts.Get(MySpaceTexts.ScreenCaptionWorkshop)));
                }
                else
                {
                    MySandboxGame.Log.WriteLine(string.Format("Querying details of file " + workshopID));

                    Action <bool, RemoteStorageGetPublishedFileDetailsResult> onGetDetailsCallResult = delegate(bool ioFailure, RemoteStorageGetPublishedFileDetailsResult data)
                    {
                        MySandboxGame.Log.WriteLine(string.Format("Obtained details: Id={4}; Result={0}; ugcHandle={1}; title='{2}'; tags='{3}'", data.Result, data.FileHandle, data.Title, data.Tags, data.PublishedFileId));
                        if (!ioFailure && data.Result == Result.OK && data.Tags.Length != 0)
                        {
                            m_newWorkshopMap.Title           = data.Title;
                            m_newWorkshopMap.PublishedFileId = data.PublishedFileId;
                            m_newWorkshopMap.Description     = data.Description;
                            m_newWorkshopMap.UGCHandle       = data.FileHandle;
                            m_newWorkshopMap.SteamIDOwner    = data.SteamIDOwner;
                            m_newWorkshopMap.TimeUpdated     = data.TimeUpdated;
                            m_newWorkshopMap.Tags            = data.Tags.Split(',');
                            Static.EndAction += EndActionLoadWorkshop;
                        }
                        else
                        {
                            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                       messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextWorkshopDownloadFailed),
                                                       messageCaption: MyTexts.Get(MySpaceTexts.ScreenCaptionWorkshop)));
                        }
                    };
                    MySteam.API.RemoteStorage.GetPublishedFileDetails(workshopID, 0, onGetDetailsCallResult);
                }
            }
            else
            {
                var contentDir = Path.Combine(MyFileSystem.ContentPath, "Missions", id);
                if (Directory.Exists(contentDir))
                {
                    m_newPath         = contentDir;
                    Static.EndAction += EndActionLoadLocal;
                    return;
                }
                var saveDir = Path.Combine(MyFileSystem.SavesPath, id);
                if (Directory.Exists(saveDir))
                {
                    m_newPath         = saveDir;
                    Static.EndAction += EndActionLoadLocal;
                    return;
                }
                //fail msg:
                StringBuilder error = new StringBuilder();
                error.AppendFormat(MyTexts.GetString(MySpaceTexts.MessageBoxTextScenarioNotFound), contentDir, saveDir);
                MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: error, messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError));
                MyGuiSandbox.AddScreen(mb);
            }
        }
        private void OnPublishModClick(MyGuiControlButton sender)
        {
            if (m_selectedRow == null)
            {
                return;
            }

            if (m_selectedRow.UserData == null)
            {
                return;
            }

            var mod         = (MyObjectBuilder_Checkpoint.ModItem)m_selectedRow.UserData;
            var modFullPath = Path.Combine(MyFileSystem.ModsPath, mod.Name);
            var nameSB      = m_selectedRow.GetCell(1).Text;
            var name        = nameSB.ToString();

            mod.PublishedFileId = MySteamWorkshop.GetWorkshopIdFromLocalMod(modFullPath);

            MyStringId textQuestion, captionQuestion;

            if (mod.PublishedFileId != 0)
            {
                textQuestion    = MyCommonTexts.MessageBoxTextDoYouWishToUpdateMod;
                captionQuestion = MyCommonTexts.MessageBoxCaptionDoYouWishToUpdateMod;
            }
            else
            {
                textQuestion    = MyCommonTexts.MessageBoxTextDoYouWishToPublishMod;
                captionQuestion = MyCommonTexts.MessageBoxCaptionDoYouWishToPublishMod;
            }

            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                       styleEnum : MyMessageBoxStyleEnum.Info,
                                       buttonType : MyMessageBoxButtonsType.YES_NO,
                                       messageText : MyTexts.Get(textQuestion),
                                       messageCaption : MyTexts.Get(captionQuestion),
                                       callback : delegate(MyGuiScreenMessageBox.ResultEnum val)
            {
                if (val == MyGuiScreenMessageBox.ResultEnum.YES)
                {
                    string[] inTags    = null;
                    var subscribedItem = GetSubscribedItem(mod.PublishedFileId);
                    if (subscribedItem != null)
                    {
                        inTags = subscribedItem.Tags;

                        if (subscribedItem.SteamIDOwner != Sync.MyId)
                        {
                            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                       messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextPublishFailed_OwnerMismatchMod),
                                                       messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionModPublishFailed)));
                            return;
                        }
                    }

                    MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_MOD_TAG, MySteamWorkshop.ModCategories, inTags, delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags)
                    {
                        if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            MySteamWorkshop.PublishModAsync(modFullPath, name, null, mod.PublishedFileId, outTags, SteamSDK.PublishedFileVisibility.Public, callbackOnFinished : delegate(bool success, Result result, ulong publishedFileId)
                            {
                                if (success)
                                {
                                    MySteamWorkshop.GenerateModInfo(modFullPath, publishedFileId, Sync.MyId);
                                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                               styleEnum: MyMessageBoxStyleEnum.Info,
                                                               messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextModPublished),
                                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionModPublished),
                                                               callback: (a) =>
                                    {
                                        MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId));
                                        FillList();
                                    }));
                                }
                                else
                                {
                                    MyStringId error;
                                    switch (result)
                                    {
                                    case Result.AccessDenied:
                                        error = MyCommonTexts.MessageBoxTextPublishFailed_AccessDenied;
                                        break;

                                    default:
                                        error = MyCommonTexts.MessageBoxTextWorldPublishFailed;
                                        break;
                                    }

                                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                               messageText: MyTexts.Get(error),
                                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionModPublishFailed)));
                                }
                            });
                        }
                    }));
                }
            }));
        }
Beispiel #14
0
        public void RequestJump(string destinationName, Vector3D destination, long userId)
        {
            if (!Vector3.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(m_grid.WorldMatrix.Translation)))
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpFromGravity, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }
            if (!Vector3.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(destination)))
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpIntoGravity, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }

            if (!IsJumpValid(userId))
            {
                return;
            }

            m_selectedDestination = destination;
            double maxJumpDistance = GetMaxJumpDistance(userId);

            m_jumpDirection = destination - m_grid.WorldMatrix.Translation;
            double jumpDistance   = m_jumpDirection.Length();
            double actualDistance = jumpDistance;

            if (jumpDistance > maxJumpDistance)
            {
                double ratio = maxJumpDistance / jumpDistance;
                actualDistance   = maxJumpDistance;
                m_jumpDirection *= ratio;
            }

            if (actualDistance < MIN_JUMP_DISTANCE)
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           buttonType: MyMessageBoxButtonsType.OK,
                                           messageText: GetWarningText(actualDistance),
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWarning)
                                           ));
            }
            else
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           buttonType : MyMessageBoxButtonsType.YES_NO,
                                           messageText : GetConfimationText(destinationName, jumpDistance, actualDistance, userId),
                                           messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm),
                                           size : new Vector2(0.839375f, 0.3675f), callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                {
                    if (result == MyGuiScreenMessageBox.ResultEnum.YES && IsJumpValid(userId))
                    {
                        SyncObject.RequestJump(m_selectedDestination, userId);
                    }
                    else
                    {
                        AbortJump();
                    }
                }
                                           ));
            }
        }
    private void CreateInGameMenuControls()
    {
        MyStringId optionsScreen_Help_Menu = MySpaceTexts.OptionsScreen_Help_Menu;
        Vector2    vector = new Vector2(0.001f, (0f - m_size.Value.Y) / 2f + 0.126f);
        int        num    = 0;

        MyGuiControlButton myGuiControlButton = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonSave), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            base.CanBeHidden = false;
            MyGuiScreenMessageBox myGuiScreenMessageBox = ((!MyAsyncSaving.InProgress) ? MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.YES_NO, MyTexts.Get(MyCommonTexts.MessageBoxTextDoYouWantToSaveYourProgress), MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm), null, null, null, null, OnSaveWorldMessageBoxCallback) : MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, MyTexts.Get(MyCommonTexts.MessageBoxTextSavingInProgress), MyTexts.Get(MyCommonTexts.MessageBoxCaptionError)));
            myGuiScreenMessageBox.SkipTransition        = true;
            myGuiScreenMessageBox.InstantClose          = false;
            MyGuiSandbox.AddScreen(myGuiScreenMessageBox);
        });

        myGuiControlButton.GamepadHelpTextId = optionsScreen_Help_Menu;


        MyGuiControlButton myGuiControlButton2 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.LoadScreenButtonSaveAs), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            MyGuiSandbox.AddScreen(new MyGuiScreenSaveAs(MySession.Static.Name));
        });

        myGuiControlButton2.GamepadHelpTextId = optionsScreen_Help_Menu;


        if (!Sync.IsServer || (MySession.Static != null && !MySession.Static.Settings.EnableSaving))
        {
            MyStringId toolTip = ((!Sync.IsServer) ? MyCommonTexts.NotificationClientCannotSave : MyCommonTexts.NotificationSavingDisabled);
            myGuiControlButton.Enabled = false;
            myGuiControlButton.ShowTooltipWhenDisabled = true;
            myGuiControlButton.SetToolTip(toolTip);
            myGuiControlButton2.Enabled = false;
            myGuiControlButton2.ShowTooltipWhenDisabled = true;
            myGuiControlButton2.SetToolTip(toolTip);
        }
        Controls.Add(myGuiControlButton);
        m_elementGroup.Add(myGuiControlButton);
        Controls.Add(myGuiControlButton2);
        m_elementGroup.Add(myGuiControlButton2);
        MyGuiControlButton myGuiControlButton3;

        if (Sync.MultiplayerActive)
        {
            myGuiControlButton3 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonPlayers), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen <MyGuiScreenPlayers>(Array.Empty <object>()));
            });
            myGuiControlButton3.GamepadHelpTextId = optionsScreen_Help_Menu;
            Controls.Add(myGuiControlButton3);
            m_elementGroup.Add(myGuiControlButton3);
        }


        MyGuiControlButton myGuiControlButton4 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonOptions), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            MyGuiSandbox.AddScreen(new MyGuiScreenOptionsAudio(m_isLimitedMenu));
        });

        myGuiControlButton4.GamepadHelpTextId = optionsScreen_Help_Menu;
        Controls.Add(myGuiControlButton4);
        m_elementGroup.Add(myGuiControlButton4);

        MyGuiControlButton myGuiControlButton5 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonExitToMainMenu), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            base.CanBeHidden = false;
            MyGuiScreenMessageBox myGuiScreenMessageBox = ((!Sync.IsServer) ? MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Info, MyMessageBoxButtonsType.YES_NO, MyTexts.Get(MyCommonTexts.MessageBoxTextAnyWorldBeforeExit), MyTexts.Get(MyCommonTexts.MessageBoxCaptionExit), null, null, null, null, OnExitToMainMenuFromCampaignMessageBoxCallback) : ((MySession.Static.Settings.EnableSaving && Sync.IsServer) ? MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.YES_NO_CANCEL, MyTexts.Get(MyCommonTexts.MessageBoxTextSaveChangesBeforeExit), MyTexts.Get(MyCommonTexts.MessageBoxCaptionExit), null, null, null, null, OnExitToMainMenuMessageBoxCallback) : MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Info, MyMessageBoxButtonsType.YES_NO, MyTexts.Get(MyCommonTexts.MessageBoxTextCampaignBeforeExit), MyTexts.Get(MyCommonTexts.MessageBoxCaptionExit), null, null, null, null, OnExitToMainMenuFromCampaignMessageBoxCallback)));
            myGuiScreenMessageBox.SkipTransition        = true;
            myGuiScreenMessageBox.InstantClose          = false;
            MyGuiSandbox.AddScreen(myGuiScreenMessageBox);
        });

        myGuiControlButton4.GamepadHelpTextId = optionsScreen_Help_Menu;
        Controls.Add(myGuiControlButton5);
        m_elementGroup.Add(myGuiControlButton5);
    }
        public void ChangeName(string newName)
        {
            newName = MyUtils.StripInvalidChars(newName);
            string oldName = m_selectedItem.Text.ToString();

            string file    = Path.Combine(m_localBlueprintFolder, oldName);
            string newFile = Path.Combine(m_localBlueprintFolder, newName);

            if (file == newFile)
            {
                return;
            }

            if (Directory.Exists(file))
            {
                if (Directory.Exists(newFile))
                {
                    if (file.ToLower() == newFile.ToLower())
                    {
                        RenameScript(oldName, newName);
                        RefreshAndReloadScriptsList();
                    }
                    else
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat(MySpaceTexts.ProgrammableBlock_ReplaceScriptNameDialogText, newName);

                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   buttonType : MyMessageBoxButtonsType.YES_NO,
                                                   styleEnum : MyMessageBoxStyleEnum.Info,
                                                   messageCaption : MyTexts.Get(MySpaceTexts.ProgrammableBlock_ReplaceScriptNameDialogTitle),
                                                   messageText : sb,
                                                   callback : delegate(MyGuiScreenMessageBox.ResultEnum callbackReturn)
                        {
                            if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
                            {
                                RenameScript(oldName, newName);
                                RefreshAndReloadScriptsList();
                            }
                            else
                            {
                                return;
                            }
                        }));
                    }
                }
                else
                {
                    try
                    {
                        RenameScript(oldName, newName);
                        RefreshAndReloadScriptsList();
                    }
                    catch (System.IO.IOException)
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   buttonType: MyMessageBoxButtonsType.OK,
                                                   styleEnum: MyMessageBoxStyleEnum.Error,
                                                   messageCaption: MyTexts.Get(MySpaceTexts.LoadScreenButtonDelete),
                                                   messageText: MyTexts.Get(MySpaceTexts.ProgrammableBlock_ReplaceScriptNameUsed))
                                               );

                        return;
                    }
                }
            }
        }
Beispiel #17
0
        public static void LoadSingleplayerSession(MyObjectBuilder_Checkpoint checkpoint, string sessionPath, ulong checkpointSizeInBytes, Action afterLoad = null)
        {
            if (!MySession.IsCompatibleVersion(checkpoint))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextIncompatibleWorldVersion).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MyCommonTexts.DialogTextIncompatibleWorldVersion),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            if (!MySteamWorkshop.CheckLocalModsAllowed(checkpoint.Mods, checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            var customLoadingScreenPath = GetCustomLoadingScreenImagePath(checkpoint.CustomLoadingScreenImage);

            MySteamWorkshop.DownloadModsAsync(checkpoint.Mods, delegate(bool success, string mismatchMods)
            {
                if (success || (checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(checkpoint.Mods))
                {
                    //Sandbox.Audio.MyAudio.Static.Mute = true;
                    MyScreenManager.CloseAllScreensNowExcept(null);
                    MyGuiSandbox.Update(MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS);
                    CheckMismatchmods(mismatchMods, callback : delegate(ResultEnum val)
                    {
                        if (val == ResultEnum.OK)
                        {
                            // 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;
                            }
                            StartLoading(delegate
                            {
                                MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Load);
                                MySession.Load(sessionPath, checkpoint, checkpointSizeInBytes);
                                if (afterLoad != null)
                                {
                                    afterLoad();
                                }
                            }, customLoadingScreenPath, checkpoint.CustomLoadingScreenText);
                        }
                        else
                        {
                            MySessionLoader.UnloadAndExitToMenu();
                        }
                    });
                }
                else
                {
                    MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed).ToString());

                    if (MySteam.IsOnline)
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText : MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed),
                                                   buttonType : MyMessageBoxButtonsType.OK, callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                        {
                            if (MyFakes.QUICK_LAUNCH != null)
                            {
                                MySessionLoader.UnloadAndExitToMenu();
                            }
                        }));
                    }
                    else
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline),
                                                   buttonType: MyMessageBoxButtonsType.OK));
                    }
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            });
        }
Beispiel #18
0
    private void OnExitToMainMenuClick(MyGuiControlButton sender)
    {
        base.CanBeHidden = false;
        MyGuiScreenMessageBox myGuiScreenMessageBox = ((!Sync.IsServer) ? MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Info, MyMessageBoxButtonsType.YES_NO, MyTexts.Get(MyCommonTexts.MessageBoxTextAnyWorldBeforeExit), MyTexts.Get(MyCommonTexts.MessageBoxCaptionExit), null, null, null, null, OnExitToMainMenuFromCampaignMessageBoxCallback) : ((MySession.Static.Settings.EnableSaving && Sync.IsServer) ? MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.YES_NO_CANCEL, MyTexts.Get(MyCommonTexts.MessageBoxTextSaveChangesBeforeExit), MyTexts.Get(MyCommonTexts.MessageBoxCaptionExit), null, null, null, null, OnExitToMainMenuMessageBoxCallback) : MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Info, MyMessageBoxButtonsType.YES_NO, MyTexts.Get(MyCommonTexts.MessageBoxTextCampaignBeforeExit), MyTexts.Get(MyCommonTexts.MessageBoxCaptionExit), null, null, null, null, OnExitToMainMenuFromCampaignMessageBoxCallback)));

        myGuiScreenMessageBox.SkipTransition = true;
        myGuiScreenMessageBox.InstantClose   = false;
        MyGuiSandbox.AddScreen(myGuiScreenMessageBox);
    }
        private bool HandleCutInput()
        {
            if (MyInput.Static.IsNewKeyPressed(MyKeys.X) && MyInput.Static.IsAnyCtrlKeyPressed())
            {
                MyEntity entity = MyCubeGrid.GetTargetEntity();
                if (entity == null)
                {
                    return(false);
                }

                bool handled = false;

                if (entity is MyCubeGrid && m_clipboard.IsActive == false)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);

                    bool cutGroup  = !MyInput.Static.IsAnyShiftKeyPressed();
                    bool cutOverLg = MyInput.Static.IsAnyAltKeyPressed();

                    MyEntities.EnableEntityBoundingBoxDraw(entity, true);

                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               buttonType: MyMessageBoxButtonsType.YES_NO,
                                               messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextAreYouSureToMoveGridToClipboard),
                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm),
                                               callback: (v) =>
                    {
                        if (v == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            OnCutConfirm(entity as MyCubeGrid, cutGroup, cutOverLg);
                        }

                        MyEntities.EnableEntityBoundingBoxDraw(entity, false);
                    }));

                    handled = true;
                }
                else if (entity is MyVoxelMap && m_voxelClipboard.IsActive == false &&
                         MyPerGameSettings.GUI.VoxelMapEditingScreen == typeof(MyGuiScreenDebugSpawnMenu) // hack to disable this in ME
                         )
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               buttonType: MyMessageBoxButtonsType.YES_NO,
                                               messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextAreYouSureToRemoveAsteroid),
                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm),
                                               callback: (v) =>
                    {
                        if (v == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            OnCutAsteroidConfirm(entity as MyVoxelMap);
                        }
                        MyEntities.EnableEntityBoundingBoxDraw(entity, false);
                    }));

                    handled = true;
                }
                else if (entity is MyFloatingObject && !m_floatingObjectClipboard.IsActive)
                {
                    MyEntities.EnableEntityBoundingBoxDraw(entity, true);

                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               buttonType: MyMessageBoxButtonsType.YES_NO,
                                               messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextAreYouSureToMoveGridToClipboard),
                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm),
                                               callback: (v) =>
                    {
                        if (v == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            OnCutFloatingObjectConfirm(entity as MyFloatingObject);
                            handled = true;
                        }

                        MyEntities.EnableEntityBoundingBoxDraw(entity, false);
                    }));

                    handled = true;
                }

                if (handled)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #20
0
 private void OnClickExitToWindows(MyGuiControlButton sender)
 {
     MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.YES_NO, MyTexts.Get(MyCommonTexts.MessageBoxTextAreYouSureYouWantToExit), MyTexts.Get(MyCommonTexts.MessageBoxCaptionExit), null, null, null, null, OnExitToWindowsMessageBoxCallback));
 }
        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)
                    {
                        // CH: Uncomment to display rotating wheel while saving the game in the BG
                        //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;
        }
Beispiel #22
0
    private void OnClickSaveWorld(MyGuiControlButton sender)
    {
        base.CanBeHidden = false;
        MyGuiScreenMessageBox myGuiScreenMessageBox = ((!MyAsyncSaving.InProgress) ? MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.YES_NO, MyTexts.Get(MyCommonTexts.MessageBoxTextDoYouWantToSaveYourProgress), MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm), null, null, null, null, OnSaveWorldMessageBoxCallback) : MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, MyTexts.Get(MyCommonTexts.MessageBoxTextSavingInProgress), MyTexts.Get(MyCommonTexts.MessageBoxCaptionError)));

        myGuiScreenMessageBox.SkipTransition = true;
        myGuiScreenMessageBox.InstantClose   = false;
        MyGuiSandbox.AddScreen(myGuiScreenMessageBox);
    }
Beispiel #23
0
        public static void LoadSingleplayerSession(string sessionPath)
        {
            MyLog.Default.WriteLine("LoadSession() - Start");
            MyLog.Default.WriteLine(sessionPath);

            ulong checkpointSizeInBytes;
            var   checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out checkpointSizeInBytes);

            if (!MySession.IsCompatibleVersion(checkpoint))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            if (!MySteamWorkshop.CheckLocalModsAllowed(checkpoint.Mods, checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }


            MySteamWorkshop.DownloadModsAsync(checkpoint.Mods, delegate(bool success)
            {
                if (success || (checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(checkpoint.Mods))
                {
                    //Sandbox.Audio.MyAudio.Static.Mute = true;

                    MyScreenManager.CloseAllScreensNowExcept(null);
                    MyGuiSandbox.Update(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.Load(sessionPath, checkpoint, checkpointSizeInBytes); });
                }
                else
                {
                    MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed).ToString());
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                               messageText : MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed),
                                               buttonType : MyMessageBoxButtonsType.OK, callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                    {
                        if (MyFakes.QUICK_LAUNCH != null)
                        {
                            MyGuiScreenMainMenu.ReturnToMainMenu();
                        }
                    }));
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            });
        }
        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 (Sync.IsServer && (Battle || Scenario) && changedUser != MySteam.UserId)
                        {
                            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(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 == 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(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);
                    }
                }
            }
        }
 private void ShowControlIsNotValidMessageBox()
 {
     MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                messageText: MyTexts.Get(MyCommonTexts.ControlIsNotValid),
                                messageCaption: MyTexts.Get(MyCommonTexts.CanNotAssignControl)));
 }
        void CheckCodeButtonClicked(MyGuiControlButton button)
        {
            string code = Description.Text.ToString();

            m_compilerErrors.Clear();
            Assembly assembly = null;

            if (CompileProgram(code, m_compilerErrors, ref assembly))
            {
                if (MyFakes.ENABLE_ROSLYN_SCRIPTS && m_compilerErrors.Count > 0)
                {
                    var messageBuilder = new StringBuilder();
                    foreach (var message in m_compilerErrors)
                    {
                        messageBuilder.Append(message);
                        messageBuilder.Append('\n');
                    }
                    var errorListScreen = new MyGuiScreenMission(missionTitle: MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Editor_CompilationOk),
                                                                 currentObjectivePrefix: MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Editor_CompilationOkWarningList),
                                                                 currentObjective: "",
                                                                 description: messageBuilder.ToString(),
                                                                 canHideOthers: false,
                                                                 enableBackgroundFade: true,
                                                                 style: MyMissionScreenStyleEnum.BLUE);

                    MyScreenManager.AddScreen(errorListScreen);
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               styleEnum: MyMessageBoxStyleEnum.Info,
                                               buttonType: MyMessageBoxButtonsType.OK,
                                               messageText: MyTexts.Get(MySpaceTexts.ProgrammableBlock_Editor_CompilationOk),
                                               canHideOthers: false));
                }
            }
            else
            {
                string compilerErrors;
                if (MyFakes.ENABLE_ROSLYN_SCRIPTS && m_compilerErrors.Count > 0)
                {
                    compilerErrors = string.Join("\n", m_compilerErrors);
                }
                else
                {
                    compilerErrors = "";
                    foreach (var error in m_compilerErrors)
                    {
                        compilerErrors += FormatError(error) + "\n";
                    }
                }
                var errorListScreen = new MyGuiScreenMission(missionTitle: MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Editor_CompilationFailed),
                                                             currentObjectivePrefix: MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Editor_CompilationFailedErrorList),
                                                             currentObjective: "",
                                                             description: compilerErrors,
                                                             canHideOthers: false,
                                                             enableBackgroundFade: true,
                                                             style: MyMissionScreenStyleEnum.RED);

                MyScreenManager.AddScreen(errorListScreen);
            }
            FocusedControl = m_descriptionBox;
        }
        public static void Publish(MyObjectBuilder_Definitions prefab, string blueprintName, Action <ulong> publishCallback = null)
        {
            string file        = Path.Combine(m_localBlueprintFolder, blueprintName);
            string title       = prefab.ShipBlueprints[0].CubeGrids[0].DisplayName;
            string description = prefab.ShipBlueprints[0].Description;
            ulong  publishId   = prefab.ShipBlueprints[0].WorkshopId;

            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                       styleEnum : MyMessageBoxStyleEnum.Info,
                                       buttonType : MyMessageBoxButtonsType.YES_NO,
                                       messageCaption : new StringBuilder("Publish"),
                                       messageText : new StringBuilder("Do you want to publish this blueprint?"),
                                       callback : delegate(MyGuiScreenMessageBox.ResultEnum val)
            {
                if (val == MyGuiScreenMessageBox.ResultEnum.YES)
                {
                    Action <MyGuiScreenMessageBox.ResultEnum, string[]> onTagsChosen = delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags)
                    {
                        if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            MySteamWorkshop.PublishBlueprintAsync(file, title, description, publishId, outTags, SteamSDK.PublishedFileVisibility.Public,
                                                                  callbackOnFinished : delegate(bool success, Result result, ulong publishedFileId)
                            {
                                if (success)
                                {
                                    if (publishCallback != null)
                                    {
                                        publishCallback(publishedFileId);
                                    }

                                    prefab.ShipBlueprints[0].WorkshopId = publishedFileId;
                                    SavePrefabToFile(prefab, blueprintName, true);
                                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                               styleEnum: MyMessageBoxStyleEnum.Info,
                                                               messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextWorldPublished),
                                                               messageCaption: new StringBuilder("BLUEPRINT PUBLISHED"),
                                                               callback: (a) =>
                                    {
                                        MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId));
                                    }));
                                }
                                else
                                {
                                    MyStringId error;
                                    switch (result)
                                    {
                                    case Result.AccessDenied:
                                        error = MyCommonTexts.MessageBoxTextPublishFailed_AccessDenied;
                                        break;

                                    default:
                                        error = MyCommonTexts.MessageBoxTextWorldPublishFailed;
                                        break;
                                    }

                                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                               messageText: MyTexts.Get(error),
                                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWorldPublishFailed)));
                                }
                            });
                        }
                    };

                    if (MySteamWorkshop.BlueprintCategories.Length > 0)
                    {
                        MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_BLUEPRINT_TAG, MySteamWorkshop.BlueprintCategories, null, onTagsChosen));
                    }
                    else
                    {
                        onTagsChosen(MyGuiScreenMessageBox.ResultEnum.YES, new string[] { MySteamWorkshop.WORKSHOP_BLUEPRINT_TAG });
                    }
                }
            }));
        }
    private void CreateMainMenuControls()
    {
        MyStringId optionsScreen_Help_Menu = MySpaceTexts.OptionsScreen_Help_Menu;
        Vector2    vector = new Vector2(0.001f, (0f - m_size.Value.Y) / 2f + 0.126f);
        int        num    = 0;
        MyObjectBuilder_LastSession lastSession = MyLocalCache.GetLastSession();

        if (lastSession != null && (lastSession.Path == null || MyPlatformGameSettings.GAME_SAVES_TO_CLOUD || Directory.Exists(lastSession.Path)) && (!lastSession.IsLobby || MyGameService.LobbyDiscovery.ContinueToLobbySupported))
        {
            MyGuiControlButton myGuiControlButton = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonContinueGame), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
            {
                MyObjectBuilder_LastSession mySession = MyLocalCache.GetLastSession();
                if (mySession == null)
                {
                    return;
                }
                if (mySession.IsOnline)
                {
                    if (mySession.IsLobby)
                    {
                        MyJoinGameHelper.JoinGame(ulong.Parse(mySession.ServerIP));
                        return;
                    }
                    MyGameService.Service.RequestPermissions(Permissions.Multiplayer, attemptResolution : true, delegate(PermissionResult granted)
                    {
                        switch (granted)
                        {
                        case PermissionResult.Granted:
                            MyGameService.Service.RequestPermissions(Permissions.CrossMultiplayer, attemptResolution : true, delegate(PermissionResult crossGranted)
                            {
                                switch (crossGranted)
                                {
                                case PermissionResult.Granted:
                                    MyGameService.Service.RequestPermissions(Permissions.UGC, attemptResolution : true, delegate(PermissionResult ugcGranted)
                                    {
                                        switch (ugcGranted)
                                        {
                                        case PermissionResult.Granted:
                                            JoinServer(mySession);
                                            break;

                                        case PermissionResult.Error:
                                            MySandboxGame.Static.Invoke(delegate
                                            {
                                                MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                                            }, "New Game screen");
                                            break;
                                        }
                                    });
                                    break;

                                case PermissionResult.Error:
                                    MySandboxGame.Static.Invoke(delegate
                                    {
                                        MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                                    }, "New Game screen");
                                    break;
                                }
                            });
                            break;

                        case PermissionResult.Error:
                            MySandboxGame.Static.Invoke(delegate
                            {
                                MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                            }, "New Game screen");
                            break;
                        }
                    });
                }
                else if (!m_parallelLoadIsRunning)
                {
                    m_parallelLoadIsRunning            = true;
                    MyGuiScreenProgress progressScreen = new MyGuiScreenProgress(MyTexts.Get(MySpaceTexts.ProgressScreen_LoadingWorld));
                    MyScreenManager.AddScreen(progressScreen);
                    Parallel.StartBackground(delegate
                    {
                        MySessionLoader.LoadLastSession();
                    }, delegate
                    {
                        progressScreen.CloseScreen();
                        m_parallelLoadIsRunning = false;
                    });
                }
            });

            myGuiControlButton.GamepadHelpTextId = optionsScreen_Help_Menu;
            Controls.Add(myGuiControlButton);
            m_elementGroup.Add(myGuiControlButton);
        }
        else
        {
            num--;
        }

        MyGuiControlButton myGuiControlButton2 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonCampaign), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen <MyGuiScreenNewGame>(new object[3] {
                true, true, true
            }));
        });

        myGuiControlButton2.GamepadHelpTextId = optionsScreen_Help_Menu;
        Controls.Add(myGuiControlButton2);
        m_elementGroup.Add(myGuiControlButton2);



        MyGuiControlButton myGuiControlButton3 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonLoadGame), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            MyGuiSandbox.AddScreen(new MyGuiScreenLoadSandbox());
        });

        myGuiControlButton3.GamepadHelpTextId = optionsScreen_Help_Menu;
        Controls.Add(myGuiControlButton3);
        m_elementGroup.Add(myGuiControlButton3);


        if (MyPerGameSettings.MultiplayerEnabled)
        {
            MyGuiControlButton myGuiControlButton4 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonJoinGame), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
            {
                if (MyGameService.IsOnline)
                {
                    MyGameService.Service.RequestPermissions(Permissions.Multiplayer, attemptResolution : true, delegate(PermissionResult granted)
                    {
                        switch (granted)
                        {
                        case PermissionResult.Granted:
                            MyGameService.Service.RequestPermissions(Permissions.UGC, attemptResolution : true, delegate(PermissionResult ugcGranted)
                            {
                                switch (ugcGranted)
                                {
                                case PermissionResult.Granted:
                                    MyGameService.Service.RequestPermissions(Permissions.CrossMultiplayer, attemptResolution : true, delegate(PermissionResult crossGranted)
                                    {
                                        MyGuiScreenJoinGame myGuiScreenJoinGame = new MyGuiScreenJoinGame(crossGranted == PermissionResult.Granted);
                                        myGuiScreenJoinGame.Closed += joinGameScreen_Closed;
                                        MyGuiSandbox.AddScreen(myGuiScreenJoinGame);
                                    });
                                    break;

                                case PermissionResult.Error:
                                    MySandboxGame.Static.Invoke(delegate
                                    {
                                        MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                                    }, "New Game screen");
                                    break;
                                }
                            });
                            break;

                        case PermissionResult.Error:
                            MyGuiSandbox.Show(MyCommonTexts.XBoxPermission_MultiplayerError, default(MyStringId), MyMessageBoxStyleEnum.Info);
                            break;
                        }
                    });
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: new StringBuilder().AppendFormat(MyTexts.GetString(MyGameService.IsActive ? MyCommonTexts.SteamIsOfflinePleaseRestart : MyCommonTexts.ErrorJoinSessionNoUser), MySession.GameServiceName)));
                }
            });
            myGuiControlButton4.GamepadHelpTextId = optionsScreen_Help_Menu;
            Controls.Add(myGuiControlButton4);
            m_elementGroup.Add(myGuiControlButton4);
        }

        MyGuiControlButton myGuiControlButton5 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonOptions), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
        {
            bool flag = !MyPlatformGameSettings.LIMITED_MAIN_MENU;

            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen <MyOldOptionsAccessMenu>(new object[1] {
                !flag
            }));
        });

        myGuiControlButton5.GamepadHelpTextId = optionsScreen_Help_Menu;
        Controls.Add(myGuiControlButton5);
        m_elementGroup.Add(myGuiControlButton5);

        if (MyFakes.ENABLE_MAIN_MENU_INVENTORY_SCENE)
        {
            MyGuiControlButton myGuiControlButton6 = new MyGuiControlButton(vector + num++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenMenuButtonInventory), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, delegate
            {
                if (MyGameService.IsActive)
                {
                    if (MyGameService.Service.GetInstallStatus(out var _))
                    {
                        if (MySession.Static == null)
                        {
                            MyGuiScreenLoadInventory inventory = MyGuiSandbox.CreateScreen <MyGuiScreenLoadInventory>(Array.Empty <object>());
                            MyGuiScreenLoading screen          = new MyGuiScreenLoading(inventory, null);
                            MyGuiScreenLoadInventory myGuiScreenLoadInventory = inventory;
                            myGuiScreenLoadInventory.OnLoadingAction          = (Action)Delegate.Combine(myGuiScreenLoadInventory.OnLoadingAction, (Action) delegate
                            {
                                MySessionLoader.LoadInventoryScene();
                                MySandboxGame.IsUpdateReady = true;
                                inventory.Initialize(inGame: false, null);
                            });
                            MyGuiSandbox.AddScreen(screen);
                        }
                        else
                        {
                            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen <MyGuiScreenLoadInventory>(new object[2] {
                                false, null
                            }));
                        }
                    }
                    else
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionInfo), messageText: MyTexts.Get(MyCommonTexts.InventoryScreen_InstallInProgress)));
                    }
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.OK, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.SteamIsOfflinePleaseRestart)));
                }
            });
Beispiel #29
0
        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;
            }


            var customLoadingScreenPath = GetCustomLoadingScreenImagePath(world.Checkpoint.CustomLoadingScreenImage);

            MySteamWorkshop.DownloadModsAsync(world.Checkpoint.Mods,
                                              onFinishedCallback :
                                              delegate(bool success, string mismatchMods)
            {
                if (success)
                {
                    CheckMismatchmods(mismatchMods, delegate(ResultEnum val)
                    {
                        if (val == ResultEnum.OK)
                        {
                            //Sandbox.Audio.MyAudio.Static.Mute = true;
                            MyScreenManager.CloseAllScreensNowExcept(null);
                            MyGuiSandbox.Update(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;
                            }

                            StartLoading(delegate { MySession.LoadMultiplayer(world, multiplayerSession); }, customLoadingScreenPath, world.Checkpoint.CustomLoadingScreenText);
                        }
                        else
                        {
                            MySessionLoader.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();
            });
        }
Beispiel #30
0
        public void RequestJump(string destinationName, Vector3D destination, long userId)
        {
            if (!Vector3.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(m_grid.WorldMatrix.Translation)))
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpFromGravity, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }
            if (!Vector3.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(destination)))
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpIntoGravity, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }

            if (!IsJumpValid(userId))
            {
                return;
            }

            if (MySession.Static.Settings.WorldSizeKm > 0 && destination.Length() > MySession.Static.Settings.WorldSizeKm * 500)
            {
                var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpOutsideWorld, 1500);
                MyHud.Notifications.Add(notification);
                return;
            }

            m_selectedDestination = destination;
            double maxJumpDistance = GetMaxJumpDistance(userId);

            m_jumpDirection = destination - m_grid.WorldMatrix.Translation;
            double jumpDistance   = m_jumpDirection.Length();
            double actualDistance = jumpDistance;

            if (jumpDistance > maxJumpDistance)
            {
                double ratio = maxJumpDistance / jumpDistance;
                actualDistance   = maxJumpDistance;
                m_jumpDirection *= ratio;
            }

            //By Gregory: Check for obstacle not that fast but happens rarely(on Jump drive enable)
            //TODO: make compatible with GetMaxJumpDistance and refactor to much code checks for actual jump
            var direction = Vector3D.Normalize(destination - m_grid.WorldMatrix.Translation);
            var startPos  = m_grid.WorldMatrix.Translation + m_grid.PositionComp.LocalAABB.Extents.Max() * direction;
            var line      = new LineD(startPos, destination);


            var intersection = MyEntities.GetIntersectionWithLine(ref line, m_grid, null, ignoreObjectsWithoutPhysics: false);

            Vector3D newDestination = Vector3D.Zero;
            Vector3D newDirection   = Vector3D.Zero;

            if (intersection.HasValue)
            {
                MyEntity MyEntity = intersection.Value.Entity as MyEntity;

                var targetPos     = MyEntity.WorldMatrix.Translation;
                var obstaclePoint = MyUtils.GetClosestPointOnLine(ref startPos, ref destination, ref targetPos);

                MyPlanet MyEntityPlanet = intersection.Value.Entity as MyPlanet;
                if (MyEntityPlanet != null)
                {
                    var notification = new MyHudNotification(MySpaceTexts.NotificationCannotJumpIntoGravity, 1500);
                    MyHud.Notifications.Add(notification);
                    return;
                }

                //var Radius = MyEntityPlanet != null ? MyEntityPlanet.MaximumRadius : MyEntity.PositionComp.LocalAABB.Extents.Length();
                var Radius = MyEntity.PositionComp.LocalAABB.Extents.Length();

                destination           = obstaclePoint - direction * (Radius + m_grid.PositionComp.LocalAABB.HalfExtents.Length());
                m_selectedDestination = destination;
                m_jumpDirection       = m_selectedDestination - startPos;
                actualDistance        = m_jumpDirection.Length();
            }

            if (actualDistance < MIN_JUMP_DISTANCE)
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           buttonType: MyMessageBoxButtonsType.OK,
                                           messageText: GetWarningText(actualDistance, intersection.HasValue),
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWarning)
                                           ));
            }
            else
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           buttonType : MyMessageBoxButtonsType.YES_NO,
                                           messageText : GetConfimationText(destinationName, jumpDistance, actualDistance, userId, intersection.HasValue),
                                           messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm),
                                           size : new Vector2(0.839375f, 0.3675f), callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                {
                    if (result == MyGuiScreenMessageBox.ResultEnum.YES && IsJumpValid(userId))
                    {
                        RequestJump(m_selectedDestination, userId);
                    }
                    else
                    {
                        AbortJump();
                    }
                }
                                           ));
            }
        }