private void ReturnToMainMenu(object sender, EventArgs eventArgs) { mDirector.GetStoryManager.Level.GameScreen.Unload(); mDirector.GetClock = new Clock(); mDirector.GetIdGenerator = new IdGenerator(); mDirector.GetInputManager.RemoveEverythingFromInputManager(); mDirector.GetStoryManager = new StoryManager(mDirector); mDirector.GetStoryManager.SetScreenManager(mScreenManager); mDirector.GetPathManager = new PathManager(); mDirector.GetDistributionDirector = new DistributionDirector(mDirector); mDirector.GetMilitaryManager = new MilitaryManager(mDirector); mDirector.GetDeathManager = new DeathManager(); mDirector.GetActionManager = new ActionManager(); for (var i = 0; i < mScreenManager.GetScreenCount() - 1; i++) { mScreenManager.RemoveScreen(); } LoadGameManagerScreen.OnReturnToMainMenuClicked(sender, eventArgs); }
/// <summary> /// Updates the state of the LoadGameManager and changes to the game if the conditions are met. /// by the stack screen manager /// </summary> /// <param name="gametime"></param> public void Update(GameTime gametime) { if (mGameLoaded) { mGameLoaded = false; } if (sResolutionChanged) { sResolutionChanged = false; } switch (sPressed) { case "None": return; case "Skirmish": mLevel = new Skirmish(mGraphics, ref mDirector, mContent, mScreenManager, LevelType.Skirmish); mGameScreen = mLevel.GameScreen; mUi = mLevel.Ui; mNewGame = true; break; case "TechDemo": mLevel = new TechDemo(mGraphics, ref mDirector, mContent, mScreenManager, LevelType.Techdemo); mGameScreen = mLevel.GameScreen; mUi = mLevel.Ui; mNewGame = true; break; case "Tutorial": mLevel = new Tutorial(mGraphics, ref mDirector, mContent, mScreenManager, LevelType.Tutorial); mGameScreen = mLevel.GameScreen; mUi = mLevel.Ui; mNewGame = true; break; case "Save1": mName = XSerializer.GetSaveNames()[0]; break; case "Save2": mName = XSerializer.GetSaveNames()[1]; break; case "Save3": mName = XSerializer.GetSaveNames()[2]; break; case "Save4": mName = XSerializer.GetSaveNames()[3]; break; case "Save5": mName = XSerializer.GetSaveNames()[4]; break; case "ReturnToMainMenu": int width; int height; if (GlobalVariables.IsFullScreen) { width = mGame.mGraphicsAdapter.CurrentDisplayMode.Width; height = mGame.mGraphicsAdapter.CurrentDisplayMode.Height; } else { width = GlobalVariables.ResolutionList[GlobalVariables.ChosenResolution].Item1; height = GlobalVariables.ResolutionList[GlobalVariables.ChosenResolution].Item2; } mScreenManager.AddScreen(new MainMenuManagerScreen(screenResolution: new Vector2(width, height), screenManager: mScreenManager, director: ref mDirector, showSplash: false, game: mGame)); break; default: throw new InvalidGenericArgumentException( "Somehow the LoadGameManagerScreen was assigned to a button that he should not have been assigned to. Cannot handle" + "this State"); } //This means a save has to be loaded if (mName != "") { var levelToBe = XSerializer.Load(mName, false); if (levelToBe.IsPresent()) { mLevel = (ILevel)levelToBe.Get(); mLevel.ReloadContent(mContent, mGraphics, ref mDirector, mScreenManager); mGameScreen = mLevel.GameScreen; mUi = mLevel.Ui; //Remove all screens above this screen, of course this only works if this screen is really on the bottom of the stack for (var i = mScreenManager.GetScreenCount() - 1; i > 1; i--) { mScreenManager.RemoveScreen(); } mScreenManager.AddScreen(mGameScreen); mScreenManager.AddScreen(mUi); mDirector.GetStoryManager.SetScreenManager(mScreenManager); mGameLoaded = true; mName = ""; GlobalVariables.mGameIsPaused = false; } } else if (mNewGame) { //Remove all screens above this screen, of course this only works if this screen is really on the bottom of the stack for (var i = mScreenManager.GetScreenCount() - 1; i > 0; i--) { mScreenManager.RemoveScreen(); } mScreenManager.AddScreen(mGameScreen); mScreenManager.AddScreen(mUi); mGameLoaded = true; mNewGame = false; GlobalVariables.mGameIsPaused = false; } sPressed = "None"; }
/// <summary> /// Updates the state of the pause menu and changes the screen that is currently being displayed /// by the stack screen manager. /// </summary> /// <param name="gametime"></param> public void Update(GameTime gametime) { if (sPausedAgain) { mScreenManager.AddScreen(mGamePauseScreen); sPausedAgain = false; } if (sSaved) { mSaveGameScreen = new SaveGameScreen(mScreenResolution) { mMenuOpacity = 1f }; sPressed = "Save Game"; Console.WriteLine("Save Screen Updated"); sSaved = false; } switch (mScreenState) { case EScreen.GameScreen: break; case EScreen.GamePauseScreen: if (sPressed == "Resume") { mScreenManager.RemoveScreen(); mScreenManager.RemoveScreen(); sPressed = "None"; sPausedAgain = true; } if (sPressed == "Save Game") { SwitchScreen(EScreen.SaveGameScreen, mGamePauseScreen, mSaveGameScreen, gametime); } if (sPressed == "Statistics") { SwitchScreen(EScreen.StatisticsScreen, mGamePauseScreen, mStatisticsScreen, gametime); } if (sPressed == "Main Menu") { mDirector.GetStoryManager.Level.GameScreen.Unload(); mDirector.GetClock = new Clock(); mDirector.GetIdGenerator = new IdGenerator(); mDirector.GetInputManager.RemoveEverythingFromInputManager(); mDirector.GetStoryManager = new StoryManager(mDirector); mDirector.GetStoryManager.SetScreenManager(mScreenManager); mDirector.GetPathManager = new PathManager(); mDirector.GetDistributionDirector = new DistributionDirector(mDirector); mDirector.GetMilitaryManager = new MilitaryManager(mDirector); mDirector.GetDeathManager = new DeathManager(); mDirector.GetActionManager = new ActionManager(); for (var i = 0; i < mScreenManager.GetScreenCount() - 1; i++) { mScreenManager.RemoveScreen(); } } break; case EScreen.SaveGameScreen: if (sPressed == "Back") { SwitchScreen(EScreen.GamePauseScreen, mSaveGameScreen, mGamePauseScreen, gametime); } if (sPressed == "Save Game") { mScreenManager.RemoveScreen(); mScreenManager.AddScreen(mSaveGameScreen); // SwitchScreen(EScreen.SaveGameScreen, mSaveGameScreen, mSaveGameScreen, gametime); // SwitchScreen(EScreen.SaveGameScreen, mGamePauseScreen, mSaveGameScreen, gametime); sPressed = "None"; } if (sPressed == "Save1") { mGameSaveStrings = XSerializer.GetSaveNames(); var path = @"%USERPROFILE%\Saved Games\Singularity\Saves"; if (mGameSaveStrings.Length >= 1) { path = Environment.ExpandEnvironmentVariables(path); path = path + @"\" + mGameSaveStrings[0]; } if (File.Exists(path)) { File.Delete(path); } SaveGame(); } if (sPressed == "Save2") { mGameSaveStrings = XSerializer.GetSaveNames(); var path = @"%USERPROFILE%\Saved Games\Singularity\Saves"; if (mGameSaveStrings.Length >= 2) { path = Environment.ExpandEnvironmentVariables(path); path = path + @"\" + mGameSaveStrings[1]; } if (File.Exists(path)) { File.Delete(path); } SaveGame(); } if (sPressed == "Save3") { mGameSaveStrings = XSerializer.GetSaveNames(); var path = @"%USERPROFILE%\Saved Games\Singularity\Saves"; if (mGameSaveStrings.Length >= 3) { path = Environment.ExpandEnvironmentVariables(path); path = path + @"\" + mGameSaveStrings[2]; } if (File.Exists(path)) { File.Delete(path); } SaveGame(); } if (sPressed == "Save4") { mGameSaveStrings = XSerializer.GetSaveNames(); var path = @"%USERPROFILE%\Saved Games\Singularity\Saves"; if (mGameSaveStrings.Length >= 4) { path = Environment.ExpandEnvironmentVariables(path); path = path + @"\" + mGameSaveStrings[3]; } if (File.Exists(path)) { File.Delete(path); } SaveGame(); } if (sPressed == "Save5") { mGameSaveStrings = XSerializer.GetSaveNames(); var path = @"%USERPROFILE%\Saved Games\Singularity\Saves"; if (mGameSaveStrings.Length >= 5) { path = Environment.ExpandEnvironmentVariables(path); path = path + @"\" + mGameSaveStrings[4]; } if (File.Exists(path)) { File.Delete(path); } SaveGame(); } break; case EScreen.StatisticsScreen: if (sPressed == "Back") { SwitchScreen(EScreen.GamePauseScreen, mStatisticsScreen, mGamePauseScreen, gametime); } break; default: throw new ArgumentOutOfRangeException(); } }