diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-08-21 16:39:21 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-08-21 16:39:21 -0400 |
commit | 8ba54a682fd7de3756b6ddd262b232cf40d23ea0 (patch) | |
tree | 7e44d53b733d95b05b232da46306a0d3d57e9231 /src/StardewModdingAPI/Framework/SGame.cs | |
parent | 674ad0d90f8780130a5fcefb3869acfe2315df2a (diff) | |
parent | eea5100acea0bceaf440f9d1bd50ee2b24cf8ebc (diff) | |
download | SMAPI-8ba54a682fd7de3756b6ddd262b232cf40d23ea0.tar.gz SMAPI-8ba54a682fd7de3756b6ddd262b232cf40d23ea0.tar.bz2 SMAPI-8ba54a682fd7de3756b6ddd262b232cf40d23ea0.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/Framework/SGame.cs')
-rw-r--r-- | src/StardewModdingAPI/Framework/SGame.cs | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index d6f1a05b..997e0c8c 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; @@ -11,6 +11,7 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using StardewModdingAPI.Events; using StardewModdingAPI.Framework.Reflection; +using StardewModdingAPI.Framework.Utilities; using StardewModdingAPI.Utilities; using StardewValley; using StardewValley.BellsAndWhistles; @@ -19,7 +20,9 @@ using StardewValley.Menus; using StardewValley.Tools; using xTile.Dimensions; using xTile.Layers; +#if SMAPI_1_x using SFarmer = StardewValley.Farmer; +#endif namespace StardewModdingAPI.Framework { @@ -54,10 +57,6 @@ namespace StardewModdingAPI.Framework /// <summary>Whether the game is saving and SMAPI has already raised <see cref="SaveEvents.BeforeSave"/>.</summary> private bool IsBetweenSaveEvents; - /// <summary>Whether the game's zoom level is at 100% (i.e. nothing should be scaled).</summary> - public bool ZoomLevelIsOne => Game1.options.zoomLevel.Equals(1.0f); - - /**** ** Game state ****/ @@ -76,7 +75,10 @@ namespace StardewModdingAPI.Framework /// <summary>The previous mouse position on the screen adjusted for the zoom level.</summary> private Point PreviousMousePosition; - /// <summary>The previous save ID at last check.</summary> + /// <summary>The window size value at last check.</summary> + private Point PreviousWindowSize; + + /// <summary>The save ID at last check.</summary> private ulong PreviousSaveID; /// <summary>A hash of <see cref="Game1.locations"/> at last check.</summary> @@ -318,6 +320,11 @@ namespace StardewModdingAPI.Framework *********/ if (Context.IsSaveLoaded && !SaveGame.IsProcessing /*still loading save*/ && this.AfterLoadTimer >= 0) { +#if !SMAPI_1_x + if (Game1.dayOfMonth != 0) // wait until new-game intro finishes (world not fully initialised yet) +#endif + this.AfterLoadTimer--; + if (this.AfterLoadTimer == 0) { this.Monitor.Log($"Context: loaded saved game '{Constants.SaveFolderName}', starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace); @@ -329,7 +336,6 @@ namespace StardewModdingAPI.Framework #endif TimeEvents.InvokeAfterDayStarted(this.Monitor); } - this.AfterLoadTimer--; } /********* @@ -350,6 +356,20 @@ namespace StardewModdingAPI.Framework } /********* + ** Window events + *********/ + // Here we depend on the game's viewport instead of listening to the Window.Resize + // event because we need to notify mods after the game handles the resize, so the + // game's metadata (like Game1.viewport) are updated. That's a bit complicated + // since the game adds & removes its own handler on the fly. + if (Game1.viewport.Width != this.PreviousWindowSize.X || Game1.viewport.Height != this.PreviousWindowSize.Y) + { + Point size = new Point(Game1.viewport.Width, Game1.viewport.Height); + GraphicsEvents.InvokeResize(this.Monitor); + this.PreviousWindowSize = size; + } + + /********* ** Input events (if window has focus) *********/ if (Game1.game1.IsActive) |