diff options
-rw-r--r-- | release-notes.md | 5 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/SaveEvents.cs | 10 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/SGame.cs | 16 |
3 files changed, 29 insertions, 2 deletions
diff --git a/release-notes.md b/release-notes.md index b67030e8..61b1d689 100644 --- a/release-notes.md +++ b/release-notes.md @@ -7,9 +7,10 @@ For players: * Updated for Stardew Valley 1.2. For mod developers: +* Added `SaveEvents.AfterReturnToTitle` event. * Added `GetPrivateProperty` to reflection helper. -* Many deprecated APIs have been removed; see [deprecation guide](http://canimod.com/guides/updating-a-smapi-mod) - for more information. +* Many deprecated APIs have been removed; see the + [deprecation guide](http://canimod.com/guides/updating-a-smapi-mod) for more information. ## 1.8 See [log](https://github.com/Pathoschild/SMAPI/compare/1.7...1.8). diff --git a/src/StardewModdingAPI/Events/SaveEvents.cs b/src/StardewModdingAPI/Events/SaveEvents.cs index 2921003a..50e6d729 100644 --- a/src/StardewModdingAPI/Events/SaveEvents.cs +++ b/src/StardewModdingAPI/Events/SaveEvents.cs @@ -18,6 +18,9 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the player loads a save slot.</summary> public static event EventHandler AfterLoad; + /// <summary>Raised after the game returns to the title screen.</summary> + public static event EventHandler AfterReturnToTitle; + /********* ** Internal methods @@ -42,5 +45,12 @@ namespace StardewModdingAPI.Events { monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.AfterLoad)}", SaveEvents.AfterLoad?.GetInvocationList(), null, EventArgs.Empty); } + + /// <summary>Raise a <see cref="AfterReturnToTitle"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeAfterReturnToTitle(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.AfterReturnToTitle)}", SaveEvents.AfterReturnToTitle?.GetInvocationList(), null, EventArgs.Empty); + } } } diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index 24abd4fd..6a751b85 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -37,6 +37,9 @@ namespace StardewModdingAPI.Framework /// <summary>Whether the player has loaded a save and the world has finished initialising.</summary> private bool IsWorldReady => this.AfterLoadTimer < 0; + /// <summary>Whether the game is returning to the menu.</summary> + private bool IsExiting = false; + /// <summary>The debug messages to add to the next debug output.</summary> internal static Queue<string> DebugMessageQueue { get; private set; } @@ -1160,6 +1163,19 @@ namespace StardewModdingAPI.Framework this.AfterLoadTimer--; } + // before exit to title + if (Game1.exitToTitle) + this.IsExiting = true; + + // after exit to title + if (this.IsWorldReady && this.IsExiting && Game1.activeClickableMenu is TitleMenu) + { + Console.WriteLine($"{Game1.currentGameTime.TotalGameTime}: after return to title"); + SaveEvents.InvokeAfterReturnToTitle(this.Monitor); + this.AfterLoadTimer = 5; + this.IsExiting = false; + } + // input events { // get latest state |