From 863b6cb0448f1dfdca69e14e018c4820f3075b81 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 27 Mar 2016 03:52:43 -0400 Subject: holy fucking shit fuck my life --- StardewModdingAPI/Events/Time.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'StardewModdingAPI/Events') diff --git a/StardewModdingAPI/Events/Time.cs b/StardewModdingAPI/Events/Time.cs index 56b23dc3..339cd560 100644 --- a/StardewModdingAPI/Events/Time.cs +++ b/StardewModdingAPI/Events/Time.cs @@ -8,6 +8,7 @@ namespace StardewModdingAPI.Events public static event EventHandler DayOfMonthChanged = delegate { }; public static event EventHandler YearOfGameChanged = delegate { }; public static event EventHandler SeasonOfYearChanged = delegate { }; + public static event EventHandler OnNewDay = delegate { }; public static void InvokeTimeOfDayChanged(int priorInt, int newInt) { @@ -28,5 +29,10 @@ namespace StardewModdingAPI.Events { SeasonOfYearChanged.Invoke(null, new EventArgsStringChanged(priorString, newString)); } + + public static void InvokeOnNewDay(int priorInt, int newInt) + { + OnNewDay.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } } } \ No newline at end of file -- cgit From 668b6b10b588d2f0fbe98ad75e0d4c256b6b13bb Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 27 Mar 2016 04:30:17 -0400 Subject: fuck you @CJBok --- StardewModdingAPI/Events/Graphics.cs | 93 ++++++++++++++++++++++-- StardewModdingAPI/Inheritance/SGame.cs | 128 ++++++++++++++++++--------------- 2 files changed, 156 insertions(+), 65 deletions(-) (limited to 'StardewModdingAPI/Events') diff --git a/StardewModdingAPI/Events/Graphics.cs b/StardewModdingAPI/Events/Graphics.cs index 2b91144a..79c5b4aa 100644 --- a/StardewModdingAPI/Events/Graphics.cs +++ b/StardewModdingAPI/Events/Graphics.cs @@ -2,11 +2,47 @@ namespace StardewModdingAPI.Events { + /// + /// + /// public static class GraphicsEvents { + /// + /// Occurs when the form (game) is resized. + /// public static event EventHandler Resize = delegate { }; - public static event EventHandler DrawTick = delegate { }; - public static event EventHandler DrawInRenderTargetTick = delegate { }; + + + + /// + /// Occurs before anything is drawn. + /// + public static event EventHandler OnPreRenderEvent = delegate { }; + + /// + /// Occurs before the GUI is drawn. + /// + public static event EventHandler OnPreRenderGuiEvent = delegate { }; + + /// + /// Occurs after the GUI is drawn. + /// + public static event EventHandler OnPostRenderGuiEvent = delegate { }; + + /// + /// Occurs before the HUD is drawn. + /// + public static event EventHandler OnPreRenderHudEvent = delegate { }; + + /// + /// Occurs after the HUD is drawn. + /// + public static event EventHandler OnPostRenderHudEvent = delegate { }; + + /// + /// Occurs after everything is drawn. + /// + public static event EventHandler OnPostRenderEvent = delegate { }; /// /// Draws when SGame.Debug is true. F3 toggles this. @@ -16,6 +52,52 @@ namespace StardewModdingAPI.Events /// public static event EventHandler DrawDebug = delegate { }; + internal static void InvokeDrawDebug(object sender, EventArgs e) + { + DrawDebug.Invoke(sender, e); + } + + internal static void InvokeOnPreRenderEvent(object sender, EventArgs e) + { + OnPreRenderEvent.Invoke(sender, e); + } + + internal static void InvokeOnPreRenderGuiEvent(object sender, EventArgs e) + { + OnPreRenderGuiEvent.Invoke(sender, e); + } + + internal static void InvokeOnPostRenderGuiEvent(object sender, EventArgs e) + { + OnPostRenderGuiEvent.Invoke(sender, e); + } + + internal static void InvokeOnPreRenderHudEvent(object sender, EventArgs e) + { + OnPreRenderHudEvent.Invoke(sender, e); + } + + internal static void InvokeOnPostRenderHudEvent(object sender, EventArgs e) + { + OnPostRenderHudEvent.Invoke(sender, e); + } + + internal static void InvokeOnPostRenderEvent(object sender, EventArgs e) + { + OnPostRenderEvent.Invoke(sender, e); + } + + + + #region To Remove + + [Obsolete("Use the other Pre/Post render events instead.")] + public static event EventHandler DrawTick = delegate { }; + + [Obsolete("Use the other Pre/Post render events instead. All of them will automatically be drawn into the render target if needed.")] + public static event EventHandler DrawInRenderTargetTick = delegate { }; + + [Obsolete("Should not be used.")] public static void InvokeDrawTick() { try @@ -28,19 +110,18 @@ namespace StardewModdingAPI.Events } } + [Obsolete("Should not be used.")] public static void InvokeDrawInRenderTargetTick() { DrawInRenderTargetTick.Invoke(null, EventArgs.Empty); } + [Obsolete("Should not be used.")] public static void InvokeResize(object sender, EventArgs e) { Resize.Invoke(sender, e); } - public static void InvokeDrawDebug(object sender, EventArgs e) - { - DrawDebug.Invoke(sender, e); - } + #endregion } } \ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 8da6cd40..6f13812b 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -479,6 +479,8 @@ namespace StardewModdingAPI.Inheritance if (Constants.EnableCompletelyOverridingBaseDrawCall) { + #region Overridden Draw + // StardewValley.Game1 if (!ZoomLevelIsOne) { @@ -595,6 +597,7 @@ namespace StardewModdingAPI.Inheritance } GraphicsDevice.Clear(BgColour); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + GraphicsEvents.InvokeOnPreRenderEvent(null, EventArgs.Empty); background?.draw(spriteBatch); mapDisplayDevice.BeginScene(spriteBatch); currentLocation.Map.GetLayer("Back").Draw(mapDisplayDevice, viewport, Location.Origin, false, pixelZoom); @@ -837,7 +840,9 @@ namespace StardewModdingAPI.Inheritance } if ((displayHUD || eventUp) && currentBillboard == 0 && gameMode == 3 && !freezeControls && !panMode) { + GraphicsEvents.InvokeOnPreRenderHudEvent(null, EventArgs.Empty); typeof (Game1).GetMethod("drawHUD", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, null); + GraphicsEvents.InvokeOnPostRenderHudEvent(null, EventArgs.Empty); //this.drawHUD(); } else if (activeClickableMenu == null && farmEvent == null) @@ -855,7 +860,7 @@ namespace StardewModdingAPI.Inheritance farmEvent?.draw(spriteBatch); if (dialogueUp && !nameSelectUp && !messagePause && !(activeClickableMenu is DialogueBox)) { - typeof (Game1).GetMethod("drawDialogueBox", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, null); + typeof (Game1).GetMethod("drawDialogueBox", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, null); //this.drawDialogueBox(); } if (progressBar) @@ -885,7 +890,7 @@ namespace StardewModdingAPI.Inheritance } if ((messagePause || globalFade) && dialogueUp) { - typeof (Game1).GetMethod("drawDialogueBox", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, null); + typeof (Game1).GetMethod("drawDialogueBox", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, null); //this.drawDialogueBox(); } foreach (TemporaryAnimatedSprite current8 in screenOverlayTempSprites) @@ -912,12 +917,15 @@ namespace StardewModdingAPI.Inheritance } if (activeClickableMenu != null) { + GraphicsEvents.InvokeOnPreRenderGuiEvent(null, EventArgs.Empty); activeClickableMenu.draw(spriteBatch); + GraphicsEvents.InvokeOnPostRenderGuiEvent(null, EventArgs.Empty); } else { farmEvent?.drawAboveEverything(spriteBatch); } + GraphicsEvents.InvokeOnPostRenderEvent(null, EventArgs.Empty); spriteBatch.End(); if (!ZoomLevelIsOne) { @@ -927,84 +935,86 @@ namespace StardewModdingAPI.Inheritance spriteBatch.Draw(Screen, Vector2.Zero, Screen.Bounds, Color.White, 0f, Vector2.Zero, options.zoomLevel, SpriteEffects.None, 1f); spriteBatch.End(); } - else - { - #region Base Draw Call - try - { - base.Draw(gameTime); - } - catch (Exception ex) - { - Log.AsyncR("An error occured in the base draw loop: " + ex); - Console.ReadKey(); - } + #endregion + } + else + { + #region Base Draw Call - GraphicsEvents.InvokeDrawTick(); + try + { + base.Draw(gameTime); + } + catch (Exception ex) + { + Log.AsyncR("An error occured in the base draw loop: " + ex); + Console.ReadKey(); + } - if (Constants.EnableDrawingIntoRenderTarget) + GraphicsEvents.InvokeDrawTick(); + + if (Constants.EnableDrawingIntoRenderTarget) + { + if (!options.zoomLevel.Equals(1.0f)) { - if (!options.zoomLevel.Equals(1.0f)) + if (Screen.RenderTargetUsage == RenderTargetUsage.DiscardContents) { - if (Screen.RenderTargetUsage == RenderTargetUsage.DiscardContents) - { - Screen = new RenderTarget2D(graphics.GraphicsDevice, Math.Min(4096, (int) (Window.ClientBounds.Width * (1.0 / options.zoomLevel))), - Math.Min(4096, (int) (Window.ClientBounds.Height * (1.0 / options.zoomLevel))), - false, SurfaceFormat.Color, DepthFormat.Depth16, 1, RenderTargetUsage.PreserveContents); - } - GraphicsDevice.SetRenderTarget(Screen); + Screen = new RenderTarget2D(graphics.GraphicsDevice, Math.Min(4096, (int) (Window.ClientBounds.Width * (1.0 / options.zoomLevel))), + Math.Min(4096, (int) (Window.ClientBounds.Height * (1.0 / options.zoomLevel))), + false, SurfaceFormat.Color, DepthFormat.Depth16, 1, RenderTargetUsage.PreserveContents); } + GraphicsDevice.SetRenderTarget(Screen); + } - // Not beginning the batch due to inconsistancies with the standard draw tick... - //spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + // Not beginning the batch due to inconsistancies with the standard draw tick... + //spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); - GraphicsEvents.InvokeDrawInRenderTargetTick(); + GraphicsEvents.InvokeDrawInRenderTargetTick(); - //spriteBatch.End(); + //spriteBatch.End(); - //Re-draw the HUD - spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); - activeClickableMenu?.draw(spriteBatch); - /* + //Re-draw the HUD + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + activeClickableMenu?.draw(spriteBatch); + /* if ((displayHUD || eventUp) && currentBillboard == 0 && gameMode == 3 && !freezeControls && !panMode) typeof (Game1).GetMethod("drawHUD", BindingFlags.NonPublic | BindingFlags.Instance)?.Invoke(Program.gamePtr, null); */ - spriteBatch.Draw(mouseCursors, new Vector2(getOldMouseX(), getOldMouseY()), getSourceRectForStandardTileSheet(mouseCursors, options.gamepadControls ? 44 : 0, 16, 16), Color.White, 0.0f, Vector2.Zero, pixelZoom + dialogueButtonScale / 150f, SpriteEffects.None, 1f); + spriteBatch.Draw(mouseCursors, new Vector2(getOldMouseX(), getOldMouseY()), getSourceRectForStandardTileSheet(mouseCursors, options.gamepadControls ? 44 : 0, 16, 16), Color.White, 0.0f, Vector2.Zero, pixelZoom + dialogueButtonScale / 150f, SpriteEffects.None, 1f); - spriteBatch.End(); - - if (!options.zoomLevel.Equals(1.0f)) - { - GraphicsDevice.SetRenderTarget(null); - spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone); - spriteBatch.Draw(Screen, Vector2.Zero, Screen.Bounds, Color.White, 0.0f, Vector2.Zero, options.zoomLevel, SpriteEffects.None, 1f); - spriteBatch.End(); - } - } + spriteBatch.End(); - if (Debug) + if (!options.zoomLevel.Equals(1.0f)) { - spriteBatch.Begin(); - spriteBatch.DrawString(smoothFont, "FPS: " + FramesPerSecond, Vector2.Zero, BgColour); - - int i = 1; - while (DebugMessageQueue.Any()) - { - string s = DebugMessageQueue.Dequeue(); - spriteBatch.DrawString(smoothFont, s, new Vector2(0, i * 12), BgColour); - i++; - } - GraphicsEvents.InvokeDrawDebug(null, null); + GraphicsDevice.SetRenderTarget(null); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone); + spriteBatch.Draw(Screen, Vector2.Zero, Screen.Bounds, Color.White, 0.0f, Vector2.Zero, options.zoomLevel, SpriteEffects.None, 1f); spriteBatch.End(); } - else + } + + if (Debug) + { + spriteBatch.Begin(); + spriteBatch.DrawString(smoothFont, "FPS: " + FramesPerSecond, Vector2.Zero, BgColour); + + int i = 1; + while (DebugMessageQueue.Any()) { - DebugMessageQueue.Clear(); + string s = DebugMessageQueue.Dequeue(); + spriteBatch.DrawString(smoothFont, s, new Vector2(0, i * 12), BgColour); + i++; } - - #endregion + GraphicsEvents.InvokeDrawDebug(null, null); + spriteBatch.End(); } + else + { + DebugMessageQueue.Clear(); + } + + #endregion } } -- cgit From 2cce7c2d27d0d678563d35c69f6879168bff53e4 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 27 Mar 2016 05:05:36 -0400 Subject: invocations are now internal --- StardewModdingAPI/Events/Controls.cs | 16 +++++++------- StardewModdingAPI/Events/EventArgs.cs | 13 ++++++++++++ StardewModdingAPI/Events/Game.cs | 22 ++++++++++---------- StardewModdingAPI/Events/Location.cs | 4 ++-- StardewModdingAPI/Events/Menu.cs | 2 +- StardewModdingAPI/Events/Mine.cs | 2 +- StardewModdingAPI/Events/Player.cs | 8 +++---- StardewModdingAPI/Events/Time.cs | 14 ++++++------- StardewModdingAPI/Inheritance/SGame.cs | 38 +++++++++++++++++----------------- 9 files changed, 66 insertions(+), 53 deletions(-) (limited to 'StardewModdingAPI/Events') diff --git a/StardewModdingAPI/Events/Controls.cs b/StardewModdingAPI/Events/Controls.cs index 87319f37..6415561a 100644 --- a/StardewModdingAPI/Events/Controls.cs +++ b/StardewModdingAPI/Events/Controls.cs @@ -15,42 +15,42 @@ namespace StardewModdingAPI.Events public static event EventHandler ControllerTriggerPressed = delegate { }; public static event EventHandler ControllerTriggerReleased = delegate { }; - public static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) + internal static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) { KeyboardChanged.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); } - public static void InvokeMouseChanged(MouseState priorState, MouseState newState) + internal static void InvokeMouseChanged(MouseState priorState, MouseState newState) { MouseChanged.Invoke(null, new EventArgsMouseStateChanged(priorState, newState)); } - public static void InvokeKeyPressed(Keys key) + internal static void InvokeKeyPressed(Keys key) { KeyPressed.Invoke(null, new EventArgsKeyPressed(key)); } - public static void InvokeKeyReleased(Keys key) + internal static void InvokeKeyReleased(Keys key) { KeyReleased.Invoke(null, new EventArgsKeyPressed(key)); } - public static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons buttons) + internal static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons buttons) { ControllerButtonPressed.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, buttons)); } - public static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons buttons) + internal static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons buttons) { ControllerButtonReleased.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, buttons)); } - public static void InvokeTriggerPressed(PlayerIndex playerIndex, Buttons buttons, float value) + internal static void InvokeTriggerPressed(PlayerIndex playerIndex, Buttons buttons, float value) { ControllerTriggerPressed.Invoke(null, new EventArgsControllerTriggerPressed(playerIndex, buttons, value)); } - public static void InvokeTriggerReleased(PlayerIndex playerIndex, Buttons buttons, float value) + internal static void InvokeTriggerReleased(PlayerIndex playerIndex, Buttons buttons, float value) { ControllerTriggerReleased.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, buttons, value)); } diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs index 91151e86..d057796a 100644 --- a/StardewModdingAPI/Events/EventArgs.cs +++ b/StardewModdingAPI/Events/EventArgs.cs @@ -236,6 +236,19 @@ namespace StardewModdingAPI.Events public bool LoadedGame { get; private set; } } + public class EventArgsNewDay : EventArgs + { + public EventArgsNewDay(int prevDay, int curDay, bool newDay) + { + PreviousDay = prevDay; + CurrentDay = curDay; + IsNewDay = newDay; + } + + public int PreviousDay { get; private set; } + public int CurrentDay { get; private set; } + public bool IsNewDay { get; private set; } + } public class EventArgsCommand : EventArgs { diff --git a/StardewModdingAPI/Events/Game.cs b/StardewModdingAPI/Events/Game.cs index c8052962..8b8042ed 100644 --- a/StardewModdingAPI/Events/Game.cs +++ b/StardewModdingAPI/Events/Game.cs @@ -44,12 +44,12 @@ namespace StardewModdingAPI.Events /// public static event EventHandler OneSecondTick = delegate { }; - public static void InvokeGameLoaded() + internal static void InvokeGameLoaded() { GameLoaded.Invoke(null, EventArgs.Empty); } - public static void InvokeInitialize() + internal static void InvokeInitialize() { try { @@ -61,7 +61,7 @@ namespace StardewModdingAPI.Events } } - public static void InvokeLoadContent() + internal static void InvokeLoadContent() { try { @@ -73,7 +73,7 @@ namespace StardewModdingAPI.Events } } - public static void InvokeUpdateTick() + internal static void InvokeUpdateTick() { try { @@ -85,37 +85,37 @@ namespace StardewModdingAPI.Events } } - public static void InvokeSecondUpdateTick() + internal static void InvokeSecondUpdateTick() { SecondUpdateTick.Invoke(null, EventArgs.Empty); } - public static void InvokeFourthUpdateTick() + internal static void InvokeFourthUpdateTick() { FourthUpdateTick.Invoke(null, EventArgs.Empty); } - public static void InvokeEighthUpdateTick() + internal static void InvokeEighthUpdateTick() { EighthUpdateTick.Invoke(null, EventArgs.Empty); } - public static void InvokeQuarterSecondTick() + internal static void InvokeQuarterSecondTick() { QuarterSecondTick.Invoke(null, EventArgs.Empty); } - public static void InvokeHalfSecondTick() + internal static void InvokeHalfSecondTick() { HalfSecondTick.Invoke(null, EventArgs.Empty); } - public static void InvokeOneSecondTick() + internal static void InvokeOneSecondTick() { OneSecondTick.Invoke(null, EventArgs.Empty); } - public static void InvokeFirstUpdateTick() + internal static void InvokeFirstUpdateTick() { FirstUpdateTick.Invoke(null, EventArgs.Empty); } diff --git a/StardewModdingAPI/Events/Location.cs b/StardewModdingAPI/Events/Location.cs index d5b6cdec..f951ab95 100644 --- a/StardewModdingAPI/Events/Location.cs +++ b/StardewModdingAPI/Events/Location.cs @@ -12,12 +12,12 @@ namespace StardewModdingAPI.Events public static event EventHandler LocationObjectsChanged = delegate { }; public static event EventHandler CurrentLocationChanged = delegate { }; - public static void InvokeLocationsChanged(List newLocations) + internal static void InvokeLocationsChanged(List newLocations) { LocationsChanged.Invoke(null, new EventArgsGameLocationsChanged(newLocations)); } - public static void InvokeCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + internal static void InvokeCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) { CurrentLocationChanged.Invoke(null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); } diff --git a/StardewModdingAPI/Events/Menu.cs b/StardewModdingAPI/Events/Menu.cs index 8acfc863..466a364e 100644 --- a/StardewModdingAPI/Events/Menu.cs +++ b/StardewModdingAPI/Events/Menu.cs @@ -7,7 +7,7 @@ namespace StardewModdingAPI.Events { public static event EventHandler MenuChanged = delegate { }; - public static void InvokeMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + internal static void InvokeMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) { MenuChanged.Invoke(null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); } diff --git a/StardewModdingAPI/Events/Mine.cs b/StardewModdingAPI/Events/Mine.cs index 2f89c91d..55514d42 100644 --- a/StardewModdingAPI/Events/Mine.cs +++ b/StardewModdingAPI/Events/Mine.cs @@ -6,7 +6,7 @@ namespace StardewModdingAPI.Events { public static event EventHandler MineLevelChanged = delegate { }; - public static void InvokeMineLevelChanged(int previousMinelevel, int currentMineLevel) + internal static void InvokeMineLevelChanged(int previousMinelevel, int currentMineLevel) { MineLevelChanged.Invoke(null, new EventArgsMineLevelChanged(previousMinelevel, currentMineLevel)); } diff --git a/StardewModdingAPI/Events/Player.cs b/StardewModdingAPI/Events/Player.cs index a658259e..22f572b7 100644 --- a/StardewModdingAPI/Events/Player.cs +++ b/StardewModdingAPI/Events/Player.cs @@ -12,22 +12,22 @@ namespace StardewModdingAPI.Events public static event EventHandler LeveledUp = delegate { }; public static event EventHandler LoadedGame = delegate { }; - public static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) + internal static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) { FarmerChanged.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); } - public static void InvokeInventoryChanged(List inventory, List changedItems) + internal static void InvokeInventoryChanged(List inventory, List changedItems) { InventoryChanged.Invoke(null, new EventArgsInventoryChanged(inventory, changedItems)); } - public static void InvokeLeveledUp(EventArgsLevelUp.LevelType type, int newLevel) + internal static void InvokeLeveledUp(EventArgsLevelUp.LevelType type, int newLevel) { LeveledUp.Invoke(null, new EventArgsLevelUp(type, newLevel)); } - public static void InvokeLoadedGame(EventArgsLoadedGameChanged loaded) + internal static void InvokeLoadedGame(EventArgsLoadedGameChanged loaded) { LoadedGame.Invoke(null, loaded); } diff --git a/StardewModdingAPI/Events/Time.cs b/StardewModdingAPI/Events/Time.cs index 339cd560..f60fa0c4 100644 --- a/StardewModdingAPI/Events/Time.cs +++ b/StardewModdingAPI/Events/Time.cs @@ -8,31 +8,31 @@ namespace StardewModdingAPI.Events public static event EventHandler DayOfMonthChanged = delegate { }; public static event EventHandler YearOfGameChanged = delegate { }; public static event EventHandler SeasonOfYearChanged = delegate { }; - public static event EventHandler OnNewDay = delegate { }; + public static event EventHandler OnNewDay = delegate { }; - public static void InvokeTimeOfDayChanged(int priorInt, int newInt) + internal static void InvokeTimeOfDayChanged(int priorInt, int newInt) { TimeOfDayChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); } - public static void InvokeDayOfMonthChanged(int priorInt, int newInt) + internal static void InvokeDayOfMonthChanged(int priorInt, int newInt) { DayOfMonthChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); } - public static void InvokeYearOfGameChanged(int priorInt, int newInt) + internal static void InvokeYearOfGameChanged(int priorInt, int newInt) { YearOfGameChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); } - public static void InvokeSeasonOfYearChanged(string priorString, string newString) + internal static void InvokeSeasonOfYearChanged(string priorString, string newString) { SeasonOfYearChanged.Invoke(null, new EventArgsStringChanged(priorString, newString)); } - public static void InvokeOnNewDay(int priorInt, int newInt) + internal static void InvokeOnNewDay(int priorInt, int newInt, bool newDay) { - OnNewDay.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + OnNewDay.Invoke(null, new EventArgsNewDay(priorInt, newInt, newDay)); } } } \ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 6f13812b..f5e11114 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -994,27 +994,27 @@ namespace StardewModdingAPI.Inheritance } } - if (Debug) - { - spriteBatch.Begin(); - spriteBatch.DrawString(smoothFont, "FPS: " + FramesPerSecond, Vector2.Zero, BgColour); + #endregion + } - int i = 1; - while (DebugMessageQueue.Any()) - { - string s = DebugMessageQueue.Dequeue(); - spriteBatch.DrawString(smoothFont, s, new Vector2(0, i * 12), BgColour); - i++; - } - GraphicsEvents.InvokeDrawDebug(null, null); - spriteBatch.End(); - } - else + if (Debug) + { + spriteBatch.Begin(); + spriteBatch.DrawString(smoothFont, "FPS: " + FramesPerSecond, Vector2.Zero, Color.CornflowerBlue); + + int i = 1; + while (DebugMessageQueue.Any()) { - DebugMessageQueue.Clear(); + string s = DebugMessageQueue.Dequeue(); + spriteBatch.DrawString(smoothFont, s, new Vector2(0, i * 12), Color.CornflowerBlue); + i++; } - - #endregion + GraphicsEvents.InvokeDrawDebug(null, EventArgs.Empty); + spriteBatch.End(); + } + else + { + DebugMessageQueue.Clear(); } } @@ -1231,7 +1231,7 @@ namespace StardewModdingAPI.Inheritance if (PreviousIsNewDay != newDay) { - TimeEvents.InvokeOnNewDay(PreviousDayOfMonth, dayOfMonth); + TimeEvents.InvokeOnNewDay(PreviousDayOfMonth, dayOfMonth, newDay); PreviousIsNewDay = newDay; } } -- cgit From a387d024f074074d61955eb52fb83002d8440bbb Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 27 Mar 2016 06:40:09 -0400 Subject: updates --- StardewModdingAPI/Constants.cs | 2 +- StardewModdingAPI/Events/Time.cs | 4 + StardewModdingAPI/Inheritance/SGame.cs | 360 +++++++++++++++++++++++++++++++-- StardewModdingAPI/Program.cs | 4 +- 4 files changed, 355 insertions(+), 15 deletions(-) (limited to 'StardewModdingAPI/Events') diff --git a/StardewModdingAPI/Constants.cs b/StardewModdingAPI/Constants.cs index 5995028e..4a01c38a 100644 --- a/StardewModdingAPI/Constants.cs +++ b/StardewModdingAPI/Constants.cs @@ -62,6 +62,6 @@ namespace StardewModdingAPI /// /// Completely overrides the base game's draw call to the one is SGame /// - public static bool EnableCompletelyOverridingBaseDrawCall => true; + public static bool EnableCompletelyOverridingBaseCalls => true; } } \ No newline at end of file diff --git a/StardewModdingAPI/Events/Time.cs b/StardewModdingAPI/Events/Time.cs index f60fa0c4..39ca642a 100644 --- a/StardewModdingAPI/Events/Time.cs +++ b/StardewModdingAPI/Events/Time.cs @@ -8,6 +8,10 @@ namespace StardewModdingAPI.Events public static event EventHandler DayOfMonthChanged = delegate { }; public static event EventHandler YearOfGameChanged = delegate { }; public static event EventHandler SeasonOfYearChanged = delegate { }; + + /// + /// Occurs when Game1.newDay changes. True directly before saving, and False directly after. + /// public static event EventHandler OnNewDay = delegate { }; internal static void InvokeTimeOfDayChanged(int priorInt, int newInt) diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index f5e11114..5b05f2e2 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using Microsoft.Xna.Framework; @@ -198,6 +197,15 @@ namespace StardewModdingAPI.Inheritance set { typeof (Game1).SetBaseFieldValue(this, "screen", value); } } + /// + /// + /// + public int ThumbstickMotionMargin + { + get { return (int)typeof(Game1).GetBaseFieldValue(Program.gamePtr, "thumbstickMotionMargin"); } + set { typeof(Game1).SetBaseFieldValue(this, "thumbstickMotionMargin", value); } + } + /// /// The current Colour in Game1 (Private field, uses reflection) /// @@ -414,21 +422,331 @@ namespace StardewModdingAPI.Inheritance /// protected override void Update(GameTime gameTime) { + QueueDebugMessage("FPS: " + FramesPerSecond); UpdateEventCalls(); + if (ZoomLevelIsOne) + options.zoomLevel = 0.99f; + if (FramePressedKeys.Contains(Keys.F3)) { Debug = !Debug; } - try + if (FramePressedKeys.Contains(Keys.F2)) { - base.Update(gameTime); + //Built-in debug mode + debugMode = !debugMode; } - catch (Exception ex) + + if (Constants.EnableCompletelyOverridingBaseCalls) { - Log.AsyncR("An error occured in the base update loop: " + ex); - Console.ReadKey(); + #region Overridden Update Call + + if (Program.BuildType == 0) + SteamHelper.update(); + if ((paused /*|| !this.IsActive*/) && (options == null || options.pauseWhenOutOfFocus || paused)) + return; + if (quit) + Exit(); + currentGameTime = gameTime; + if (gameMode != 11) + { + if (IsMultiplayer && gameMode == 3) + { + if (multiplayerMode == 2) + server.receiveMessages(); + else + client.receiveMessages(); + } + if (IsActive) + InvokeBasePrivateInstancedMethod("checkForEscapeKeys"); + //this.checkForEscapeKeys(); + updateMusic(); + updateRaindropPosition(); + if (bloom != null) + bloom.tick(gameTime); + if (globalFade) + { + if (!dialogueUp) + { + if (fadeIn) + { + fadeToBlackAlpha = Math.Max(0.0f, fadeToBlackAlpha - globalFadeSpeed); + if (fadeToBlackAlpha <= 0.0) + { + globalFade = false; + if (afterFade != null) + { + afterFadeFunction afterFadeFunction = afterFade; + afterFade(); + if (afterFade != null && afterFade.Equals(afterFadeFunction)) + afterFade = null; + if (nonWarpFade) + fadeToBlack = false; + } + } + } + else + { + fadeToBlackAlpha = Math.Min(1f, fadeToBlackAlpha + globalFadeSpeed); + if (fadeToBlackAlpha >= 1.0) + { + globalFade = false; + if (afterFade != null) + { + afterFadeFunction afterFadeFunction = afterFade; + afterFade(); + if (afterFade != null && afterFade.Equals(afterFadeFunction)) + afterFade = null; + if (nonWarpFade) + fadeToBlack = false; + } + } + } + } + else + InvokeBasePrivateInstancedMethod("UpdateControlInput", gameTime); + //this.UpdateControlInput(gameTime); + } + else if (pauseThenDoFunctionTimer > 0) + { + freezeControls = true; + pauseThenDoFunctionTimer -= gameTime.ElapsedGameTime.Milliseconds; + if (pauseThenDoFunctionTimer <= 0) + { + freezeControls = false; + if (afterPause != null) + afterPause(); + } + } + if (gameMode == 3 || gameMode == 2) + { + player.millisecondsPlayed += (uint)gameTime.ElapsedGameTime.Milliseconds; + bool flag = true; + if (currentMinigame != null) + { + if (pauseTime > 0.0) + updatePause(gameTime); + if (fadeToBlack) + { + updateScreenFade(gameTime); + if (fadeToBlackAlpha >= 1.0) + fadeToBlack = false; + } + else + { + if (ThumbstickMotionMargin > 0) + ThumbstickMotionMargin -= gameTime.ElapsedGameTime.Milliseconds; + if (IsActive) + { + KeyboardState state1 = Keyboard.GetState(); + MouseState state2 = Mouse.GetState(); + GamePadState state3 = GamePad.GetState(PlayerIndex.One); + foreach (Keys keys in state1.GetPressedKeys()) + { + if (!oldKBState.IsKeyDown(keys)) + currentMinigame.receiveKeyPress(keys); + } + if (options.gamepadControls) + { + if (currentMinigame == null) + { + oldMouseState = state2; + oldKBState = state1; + oldPadState = state3; + return; + } + foreach (Buttons b in Utility.getPressedButtons(state3, oldPadState)) + currentMinigame.receiveKeyPress(Utility.mapGamePadButtonToKey(b)); + if (currentMinigame == null) + { + oldMouseState = state2; + oldKBState = state1; + oldPadState = state3; + return; + } + if (state3.ThumbSticks.Right.Y < -0.200000002980232 && oldPadState.ThumbSticks.Right.Y >= -0.200000002980232) + currentMinigame.receiveKeyPress(Keys.Down); + if (state3.ThumbSticks.Right.Y > 0.200000002980232 && oldPadState.ThumbSticks.Right.Y <= 0.200000002980232) + currentMinigame.receiveKeyPress(Keys.Up); + if (state3.ThumbSticks.Right.X < -0.200000002980232 && oldPadState.ThumbSticks.Right.X >= -0.200000002980232) + currentMinigame.receiveKeyPress(Keys.Left); + if (state3.ThumbSticks.Right.X > 0.200000002980232 && oldPadState.ThumbSticks.Right.X <= 0.200000002980232) + currentMinigame.receiveKeyPress(Keys.Right); + if (oldPadState.ThumbSticks.Right.Y < -0.200000002980232 && state3.ThumbSticks.Right.Y >= -0.200000002980232) + currentMinigame.receiveKeyRelease(Keys.Down); + if (oldPadState.ThumbSticks.Right.Y > 0.200000002980232 && state3.ThumbSticks.Right.Y <= 0.200000002980232) + currentMinigame.receiveKeyRelease(Keys.Up); + if (oldPadState.ThumbSticks.Right.X < -0.200000002980232 && state3.ThumbSticks.Right.X >= -0.200000002980232) + currentMinigame.receiveKeyRelease(Keys.Left); + if (oldPadState.ThumbSticks.Right.X > 0.200000002980232 && state3.ThumbSticks.Right.X <= 0.200000002980232) + currentMinigame.receiveKeyRelease(Keys.Right); + if (isGamePadThumbstickInMotion()) + { + setMousePosition(getMouseX() + (int)(state3.ThumbSticks.Left.X * 16.0), getMouseY() - (int)(state3.ThumbSticks.Left.Y * 16.0)); + lastCursorMotionWasMouse = false; + } + else if (getMousePosition().X != getOldMouseX() || getMousePosition().Y != getOldMouseY()) + lastCursorMotionWasMouse = true; + } + foreach (Keys keys in oldKBState.GetPressedKeys()) + { + if (!state1.IsKeyDown(keys)) + currentMinigame.receiveKeyRelease(keys); + } + if (options.gamepadControls) + { + if (currentMinigame == null) + { + oldMouseState = state2; + oldKBState = state1; + oldPadState = state3; + return; + } + if (state3.IsConnected && state3.IsButtonDown(Buttons.X) && !oldPadState.IsButtonDown(Buttons.X)) + currentMinigame.receiveRightClick(getMouseX(), getMouseY(), true); + else if (state3.IsConnected && state3.IsButtonDown(Buttons.A) && !oldPadState.IsButtonDown(Buttons.A)) + currentMinigame.receiveLeftClick(getMouseX(), getMouseY(), true); + else if (state3.IsConnected && !state3.IsButtonDown(Buttons.X) && oldPadState.IsButtonDown(Buttons.X)) + currentMinigame.releaseRightClick(getMouseX(), getMouseY()); + else if (state3.IsConnected && !state3.IsButtonDown(Buttons.A) && oldPadState.IsButtonDown(Buttons.A)) + currentMinigame.releaseLeftClick(getMouseX(), getMouseY()); + foreach (Buttons b in Utility.getPressedButtons(oldPadState, state3)) + currentMinigame.receiveKeyRelease(Utility.mapGamePadButtonToKey(b)); + if (state3.IsConnected && state3.IsButtonDown(Buttons.A) && currentMinigame != null) + currentMinigame.leftClickHeld(0, 0); + } + if (currentMinigame == null) + { + oldMouseState = state2; + oldKBState = state1; + oldPadState = state3; + return; + } + if (state2.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton != ButtonState.Pressed) + currentMinigame.receiveLeftClick(getMouseX(), getMouseY(), true); + if (state2.RightButton == ButtonState.Pressed && oldMouseState.RightButton != ButtonState.Pressed) + currentMinigame.receiveRightClick(getMouseX(), getMouseY(), true); + if (state2.LeftButton == ButtonState.Released && oldMouseState.LeftButton == ButtonState.Pressed) + currentMinigame.releaseLeftClick(getMouseX(), getMouseY()); + if (state2.RightButton == ButtonState.Released && oldMouseState.RightButton == ButtonState.Pressed) + currentMinigame.releaseLeftClick(getMouseX(), getMouseY()); + if (state2.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Pressed) + currentMinigame.leftClickHeld(getMouseX(), getMouseY()); + oldMouseState = state2; + oldKBState = state1; + oldPadState = state3; + } + if (currentMinigame != null && currentMinigame.tick(gameTime)) + { + currentMinigame.unload(); + currentMinigame = null; + fadeIn = true; + fadeToBlackAlpha = 1f; + return; + } + } + flag = IsMultiplayer; + } + else if (farmEvent != null && farmEvent.tickUpdate(gameTime)) + { + farmEvent.makeChangesToLocation(); + timeOfDay = 600; + UpdateOther(gameTime); + displayHUD = true; + farmEvent = null; + currentLocation = getLocationFromName("FarmHouse"); + player.position = Utility.PointToVector2(Utility.getHomeOfFarmer(player).getBedSpot()) * tileSize; + player.position.X -= tileSize; + changeMusicTrack("none"); + currentLocation.resetForPlayerEntry(); + player.forceCanMove(); + freezeControls = false; + displayFarmer = true; + outdoorLight = Color.White; + viewportFreeze = false; + fadeToBlackAlpha = 0.0f; + fadeToBlack = false; + globalFadeToClear(null, 0.02f); + player.mailForTomorrow.Clear(); + showEndOfNightStuff(); + } + if (flag) + { + if (endOfNightMenus.Count() > 0 && activeClickableMenu == null) + activeClickableMenu = endOfNightMenus.Pop(); + if (activeClickableMenu != null) + { + updateActiveMenu(gameTime); + } + else + { + if (pauseTime > 0.0) + updatePause(gameTime); + if (!globalFade && !freezeControls && (activeClickableMenu == null && IsActive)) + InvokeBasePrivateInstancedMethod("UpdateControlInput", gameTime); + //this.UpdateControlInput(gameTime); + } + if (showingEndOfNightStuff && endOfNightMenus.Count() == 0 && activeClickableMenu == null) + { + showingEndOfNightStuff = false; + globalFadeToClear(playMorningSong, 0.02f); + } + if (!showingEndOfNightStuff) + { + if (IsMultiplayer || activeClickableMenu == null && currentMinigame == null) + UpdateGameClock(gameTime); + //this.UpdateCharacters(gameTime); + //this.UpdateLocations(gameTime); + InvokeBasePrivateInstancedMethod("UpdateCharacters", gameTime); + InvokeBasePrivateInstancedMethod("UpdateLocations", gameTime); + UpdateViewPort(false, (Point)InvokeBasePrivateInstancedMethod("getViewportCenter")); + } + UpdateOther(gameTime); + if (messagePause) + { + KeyboardState state1 = Keyboard.GetState(); + MouseState state2 = Mouse.GetState(); + GamePadState state3 = GamePad.GetState(PlayerIndex.One); + if (isOneOfTheseKeysDown(state1, options.actionButton) && !isOneOfTheseKeysDown(oldKBState, options.actionButton)) + pressActionButton(state1, state2, state3); + oldKBState = state1; + oldPadState = state3; + } + } + } + else + { + InvokeBasePrivateInstancedMethod("UpdateTitleScreen", gameTime); + //this.UpdateTitleScreen(gameTime); + if (activeClickableMenu != null) + updateActiveMenu(gameTime); + if (gameMode == 10) + UpdateOther(gameTime); + } + if (audioEngine != null) + audioEngine.Update(); + if (multiplayerMode == 2 && gameMode == 3) + server.sendMessages(gameTime); + } + + //typeof (Game).GetMethod("Update", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(this, new object[] {gameTime}); + //base.Update(gameTime); + + #endregion + } + else + { + try + { + base.Update(gameTime); + } + catch (Exception ex) + { + Log.AsyncR("An error occured in the base update loop: " + ex); + Console.ReadKey(); + } } GameEvents.InvokeUpdateTick(); @@ -477,11 +795,10 @@ namespace StardewModdingAPI.Inheritance { FramesPerSecond = 1 / (float) gameTime.ElapsedGameTime.TotalSeconds; - if (Constants.EnableCompletelyOverridingBaseDrawCall) + if (Constants.EnableCompletelyOverridingBaseCalls) { #region Overridden Draw - // StardewValley.Game1 if (!ZoomLevelIsOne) { GraphicsDevice.SetRenderTarget(Screen); @@ -901,7 +1218,7 @@ namespace StardewModdingAPI.Inheritance { spriteBatch.DrawString(smallFont, string.Concat(new object[] { - panMode ? ((getOldMouseX() + viewport.X) / tileSize + "," + (getOldMouseY() + viewport.Y) / tileSize) : string.Concat("player: ", player.getStandingX() / tileSize, ", ", player.getStandingY() / tileSize), + panMode ? ((getOldMouseX() + viewport.X) / tileSize + "," + (getOldMouseY() + viewport.Y) / tileSize) : string.Concat("aplayer: ", player.getStandingX() / tileSize, ", ", player.getStandingY() / tileSize), Environment.NewLine, "debugOutput: ", debugOutput @@ -1000,16 +1317,16 @@ namespace StardewModdingAPI.Inheritance if (Debug) { spriteBatch.Begin(); - spriteBatch.DrawString(smoothFont, "FPS: " + FramesPerSecond, Vector2.Zero, Color.CornflowerBlue); - int i = 1; + int i = 0; while (DebugMessageQueue.Any()) { string s = DebugMessageQueue.Dequeue(); - spriteBatch.DrawString(smoothFont, s, new Vector2(0, i * 12), Color.CornflowerBlue); + spriteBatch.DrawString(smoothFont, s, new Vector2(0, i * 14), Color.CornflowerBlue); i++; } GraphicsEvents.InvokeDrawDebug(null, EventArgs.Empty); + spriteBatch.End(); } else @@ -1264,6 +1581,25 @@ namespace StardewModdingAPI.Inheritance return changedItems.Any(); } + /// + /// Invokes a private, non-static method in Game1 via Reflection + /// + /// The name of the method + /// Any parameters needed + /// Whatever the method normally returns. Null if void. + public static object InvokeBasePrivateInstancedMethod(string name, params object[] parameters) + { + try + { + return typeof (Game1).GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance).Invoke(Program.gamePtr, parameters); + } + catch + { + Log.AsyncR("Failed to call base method: " + name); + return null; + } + } + /// /// Queue's a message to be drawn in Debug mode (F3) /// diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index e6ba103b..fcc247e2 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -35,8 +35,8 @@ namespace StardewModdingAPI public static Texture2D DebugPixel { get; private set; } - public static bool StardewInjectorLoaded { get; private set; } - public static Mod StardewInjectorMod { get; private set; } + // ReSharper disable once PossibleNullReferenceException + public static int BuildType => (int) StardewProgramType.GetField("buildType", BindingFlags.Public | BindingFlags.Static).GetValue(null); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit