summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-02-19 01:02:07 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-02-19 01:02:07 -0500
commitb2efd34fec00a952cd7d2ebdc02a2c2be506380e (patch)
treea5841e829288dd6958fa1d1422b37090fd21da12
parente321362378eaacd0081db44f0db3ef457ef97368 (diff)
downloadSMAPI-b2efd34fec00a952cd7d2ebdc02a2c2be506380e.tar.gz
SMAPI-b2efd34fec00a952cd7d2ebdc02a2c2be506380e.tar.bz2
SMAPI-b2efd34fec00a952cd7d2ebdc02a2c2be506380e.zip
fix on-post-render graphics event being raised after screen is rendered
This causes mods to draw on top of the rendered screen instead of within it, which leads to strange bugs like cursor coordinates not lining up with the cursor and transparency issues.
-rw-r--r--src/StardewModdingAPI/Events/GraphicsEvents.cs6
-rw-r--r--src/StardewModdingAPI/Framework/SGame.cs9
2 files changed, 14 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Events/GraphicsEvents.cs b/src/StardewModdingAPI/Events/GraphicsEvents.cs
index d9d57a8d..25b976f1 100644
--- a/src/StardewModdingAPI/Events/GraphicsEvents.cs
+++ b/src/StardewModdingAPI/Events/GraphicsEvents.cs
@@ -75,6 +75,12 @@ namespace StardewModdingAPI.Events
monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderEvent)}", GraphicsEvents.OnPostRenderEvent?.GetInvocationList());
}
+ /// <summary>Get whether there are any post-render event listeners.</summary>
+ internal static bool HasPostRenderListeners()
+ {
+ return GraphicsEvents.OnPostRenderEvent != null;
+ }
+
/****
** GUI events
****/
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs
index baf74fd4..f64457f8 100644
--- a/src/StardewModdingAPI/Framework/SGame.cs
+++ b/src/StardewModdingAPI/Framework/SGame.cs
@@ -987,13 +987,20 @@ namespace StardewModdingAPI.Framework
Game1.overlayMenu.draw(Game1.spriteBatch);
Game1.spriteBatch.End();
}
+
+ if (GraphicsEvents.HasPostRenderListeners())
+ {
+ Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
+ GraphicsEvents.InvokeOnPostRenderEvent(this.Monitor);
+ Game1.spriteBatch.End();
+ }
+
if ((double)Game1.options.zoomLevel == 1.0)
return;
this.GraphicsDevice.SetRenderTarget((RenderTarget2D)null);
this.GraphicsDevice.Clear(this.bgColor);
Game1.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone);
Game1.spriteBatch.Draw((Texture2D)this.screenWrapper, Vector2.Zero, new Microsoft.Xna.Framework.Rectangle?(this.screenWrapper.Bounds), Color.White, 0.0f, Vector2.Zero, Game1.options.zoomLevel, SpriteEffects.None, 1f);
- GraphicsEvents.InvokeOnPostRenderEvent(this.Monitor);
Game1.spriteBatch.End();
}
}