} // end of OnSaveLevelDialogButton() /// <summary> /// OnSelect method used by mini-hub grid. If the level is dirty and needs to /// be saved the SaveChagesDialog will be activated. Upon its deactivation /// the level should no longer be marked dirty and OnSelect() will get called /// again allowing the user's action to be executed. /// </summary> /// <param name="grid"></param> public void OnSelect(ModularMenu menu) { // Prevent the button pressed from leaking into runtime. GamePadInput.IgnoreUntilReleased(Buttons.A); // In every case, we need to reset the level to its starting state. InGame.inGame.ResetSim(preserveScores: false, removeCreatablesFromScene: false, keepPersistentScores: false); // Resetting the sim just started up all game audio, let's pause it down again. // It will be resumed when we go back into sim mode. BokuGame.Audio.PauseGameAudio(); // Flag to let us know if the level needs saving. If the save changes // dialog has already been activated then just set this to false. bool needToSaveLevel = (InGame.IsLevelDirty || InGame.AutoSaved) && !saveChangesActivated; // Does the current world belong to the user. Required to share to community. // Test the genre flag and also special case look at empty world. bool isMyWorld = false; if (InGame.XmlWorldData != null) { bool genreTest = ((int)InGame.XmlWorldData.genres & (int)Genres.MyWorlds) != 0; bool newWorldTest = InGame.XmlWorldData.Filename == emptyWorldFileName; if (genreTest && !newWorldTest) { isMyWorld = true; } } // Normally there would be a switch here but if we compare strings // we proof ourselves against changes in the order of the elements. if (menu.CurString == Strings.Localize("miniHub.reset")) { // Reset. // We've already done a Reset, so force to RunSim mode if we already aren't. Deactivate(); InGame.inGame.Activate(); InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.RunSim; InGame.inGame.RestorePlayModeCamera(); // The ResetSim above doesn't ApplyInlining since it's generally // meant for resetting into the editor. In this case we're going // into RunSim mode so be sure to apply inlining first. InGame.ApplyInlining(); if (InGame.inGame.PreGame != null) { InGame.inGame.PreGame.Active = true; } } else if (menu.CurString == Strings.Localize("miniHub.edit")) { // Edit level. Deactivate(); InGame.inGame.Activate(); InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.ToolMenu; } else if (menu.CurString == Strings.Localize("miniHub.save")) { // Save saveLevelDialog.Activate(); } else if (menu.CurString == Strings.Localize("miniHub.publish")) { // Offer to save first. Need to save if world has changed or is world doesn't belong to user. if (needToSaveLevel || !isMyWorld) { saveChangesActivated = true; saveChangesMessage.Activate(); } else { var level = LevelMetadata.CreateFromXml(InGame.XmlWorldData); shared.communityShareMenu.Activate(level); } } else if (menu.CurString == Strings.Localize("miniHub.load")) { // Load. // If we're back here and saveChangesActivated is true then the // user was given the option to save changes and chose Discard. // So don't offer to save again. if (!saveChangesActivated && needToSaveLevel) { saveChangesActivated = true; saveChangesWithDiscardMessage.Activate(); } else { saveChangesActivated = false; // Deactivate mini-hub and bring up loading menu. Deactivate(); //InGame.inGame.DiscardTerrain(); BokuGame.bokuGame.loadLevelMenu.LocalLevelMode = LoadLevelMenu.LocalLevelModes.General; BokuGame.bokuGame.loadLevelMenu.ReturnToMenu = LoadLevelMenu.ReturnTo.MiniHub; BokuGame.bokuGame.loadLevelMenu.Activate(); } } else if (menu.CurString == Strings.Localize("miniHub.emptyLevel")) { // Empty Level. // If saveChangesActivated is already true then user chose Discard and // we can ignore the needToSaveLevel flag. if (!saveChangesActivated && needToSaveLevel) { saveChangesActivated = true; saveChangesWithDiscardMessage.Activate(); } else { saveChangesActivated = false; // Undo any previous warping. ScreenWarp.FitRtToScreen(BokuGame.ScreenSize); newWorldDialog.Active = true; } } else if (menu.CurString == Strings.Localize("miniHub.print")) { Print.PrintProgramming(); // We don't want to exit the mini-hub so re-activate the menu. shared.menu.Active = true; } else if (menu.CurString == Strings.Localize("miniHub.quit")) { // Exit to main menu. // If we're back here and saveChangesActivated is true then the // user was given the option to save changes and chose Discard. // So don't offer to save again. if (!saveChangesActivated && needToSaveLevel) { saveChangesActivated = true; saveChangesWithDiscardMessage.Activate(); } else { saveChangesActivated = false; // Wave bye, bye. Go back to the main menu Deactivate(); InGame.inGame.StopAllSounds(); BokuGame.bokuGame.mainMenu.Activate(); } } } // end of MiniHub OnSelect()