fix GraphicsEvents.Resize being raised before the game updates its window data (#328)

This commit is contained in:
Jesse Plamondon-Willard 2017-07-31 23:48:53 -04:00
parent 7992b52f03
commit 9b22f3e004
4 changed files with 22 additions and 11 deletions

View File

@ -22,7 +22,8 @@ For mod developers:
* Removed support for mods with no `Name`, `Version`, or `UniqueID` in their manifest.
* Removed support for mods with a non-unique `UniqueID` value in their manifest.
* Restrict mods from accessing SMAPI internals using its reflection helper, to discourage fragile mods.
* Fixed issue where `TimeEvents.AfterDayStarted` was raised during the new-game intro.
* Fixed `GraphicsEvents.Resize` being raised before the game updates its window data.
* Fixed `TimeEvents.AfterDayStarted` being raised during the new-game intro.
## 1.15.2
For players:

View File

@ -51,11 +51,9 @@ namespace StardewModdingAPI.Events
****/
/// <summary>Raise a <see cref="Resize"/> event.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
/// <param name="sender">The object which raised the event.</param>
/// <param name="e">The event arguments.</param>
internal static void InvokeResize(IMonitor monitor, object sender, EventArgs e)
internal static void InvokeResize(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.Resize)}", GraphicsEvents.Resize?.GetInvocationList(), sender, e);
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.Resize)}", GraphicsEvents.Resize?.GetInvocationList());
}
/****

View File

@ -53,10 +53,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
****/
@ -75,7 +71,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>
@ -352,6 +351,20 @@ namespace StardewModdingAPI.Framework
SaveEvents.InvokeAfterReturnToTitle(this.Monitor);
}
/*********
** 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)
*********/

View File

@ -185,7 +185,6 @@ namespace StardewModdingAPI
((Form)Control.FromHandle(this.GameInstance.Window.Handle)).FormClosing += (sender, args) => this.Dispose();
#endif
this.GameInstance.Exiting += (sender, e) => this.Dispose();
this.GameInstance.Window.ClientSizeChanged += (sender, e) => GraphicsEvents.InvokeResize(this.Monitor, sender, e);
GameEvents.InitializeInternal += (sender, e) => this.InitialiseAfterGameStart();
GameEvents.GameLoadedInternal += (sender, e) => this.CheckForUpdateAsync();
ContentEvents.AfterLocaleChanged += (sender, e) => this.OnLocaleChanged();