add DayEnding event (#310)
This commit is contained in:
parent
14fab29370
commit
79705448f5
|
@ -0,0 +1,7 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace StardewModdingAPI.Events
|
||||||
|
{
|
||||||
|
/// <summary>Event arguments for an <see cref="IGameLoopEvents.DayEnding"/> event.</summary>
|
||||||
|
public class DayEndingEventArgs : EventArgs { }
|
||||||
|
}
|
|
@ -31,5 +31,8 @@ namespace StardewModdingAPI.Events
|
||||||
|
|
||||||
/// <summary>Raised after the game begins a new day (including when the player loads a save).</summary>
|
/// <summary>Raised after the game begins a new day (including when the player loads a save).</summary>
|
||||||
event EventHandler<DayStartedEventArgs> DayStarted;
|
event EventHandler<DayStartedEventArgs> DayStarted;
|
||||||
|
|
||||||
|
/// <summary>Raised before the game ends the current day. This happens before it starts setting up the next day and before <see cref="Saving"/>.</summary>
|
||||||
|
event EventHandler<DayEndingEventArgs> DayEnding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ namespace StardewModdingAPI.Framework.Events
|
||||||
/// <summary>Raised after the game begins a new day, including when loading a save.</summary>
|
/// <summary>Raised after the game begins a new day, including when loading a save.</summary>
|
||||||
public readonly ManagedEvent<DayStartedEventArgs> DayStarted;
|
public readonly ManagedEvent<DayStartedEventArgs> DayStarted;
|
||||||
|
|
||||||
|
/// <summary>Raised before the game ends the current day. This happens before it starts setting up the next day and before <see cref="Saving"/>.</summary>
|
||||||
|
public readonly ManagedEvent<DayEndingEventArgs> DayEnding;
|
||||||
|
|
||||||
/****
|
/****
|
||||||
** Input
|
** Input
|
||||||
****/
|
****/
|
||||||
|
@ -291,6 +294,7 @@ namespace StardewModdingAPI.Framework.Events
|
||||||
this.Saved = ManageEventOf<SavedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.Saved));
|
this.Saved = ManageEventOf<SavedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.Saved));
|
||||||
this.SaveLoaded = ManageEventOf<SaveLoadedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.SaveLoaded));
|
this.SaveLoaded = ManageEventOf<SaveLoadedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.SaveLoaded));
|
||||||
this.DayStarted = ManageEventOf<DayStartedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.DayStarted));
|
this.DayStarted = ManageEventOf<DayStartedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.DayStarted));
|
||||||
|
this.DayEnding = ManageEventOf<DayEndingEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.DayEnding));
|
||||||
|
|
||||||
this.ButtonPressed = ManageEventOf<ButtonPressedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonPressed));
|
this.ButtonPressed = ManageEventOf<ButtonPressedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonPressed));
|
||||||
this.ButtonReleased = ManageEventOf<ButtonReleasedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonReleased));
|
this.ButtonReleased = ManageEventOf<ButtonReleasedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonReleased));
|
||||||
|
|
|
@ -72,6 +72,13 @@ namespace StardewModdingAPI.Framework.Events
|
||||||
remove => this.EventManager.DayStarted.Remove(value);
|
remove => this.EventManager.DayStarted.Remove(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Raised before the game ends the current day. This happens before it starts setting up the next day and before <see cref="IGameLoopEvents.Saving"/>.</summary>
|
||||||
|
public event EventHandler<DayEndingEventArgs> DayEnding
|
||||||
|
{
|
||||||
|
add => this.EventManager.DayEnding.Add(value);
|
||||||
|
remove => this.EventManager.DayEnding.Remove(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
** Public methods
|
** Public methods
|
||||||
|
|
|
@ -151,6 +151,7 @@ namespace StardewModdingAPI.Framework
|
||||||
this.OnGameExiting = onGameExiting;
|
this.OnGameExiting = onGameExiting;
|
||||||
Game1.input = new SInputState();
|
Game1.input = new SInputState();
|
||||||
Game1.multiplayer = new SMultiplayer(monitor, eventManager);
|
Game1.multiplayer = new SMultiplayer(monitor, eventManager);
|
||||||
|
Game1.hooks = new SModHooks(this.OnNewDayAfterFade);
|
||||||
|
|
||||||
// init observables
|
// init observables
|
||||||
Game1.locations = new ObservableCollection<GameLocation>();
|
Game1.locations = new ObservableCollection<GameLocation>();
|
||||||
|
@ -182,6 +183,12 @@ namespace StardewModdingAPI.Framework
|
||||||
/****
|
/****
|
||||||
** Intercepted methods & events
|
** Intercepted methods & events
|
||||||
****/
|
****/
|
||||||
|
/// <summary>A callback invoked before <see cref="Game1.newDayAfterFade"/> runs.</summary>
|
||||||
|
protected void OnNewDayAfterFade()
|
||||||
|
{
|
||||||
|
this.Events.DayEnding.RaiseEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Constructor a content manager to read XNB files.</summary>
|
/// <summary>Constructor a content manager to read XNB files.</summary>
|
||||||
/// <param name="serviceProvider">The service provider to use to locate services.</param>
|
/// <param name="serviceProvider">The service provider to use to locate services.</param>
|
||||||
/// <param name="rootDirectory">The root directory to search for content.</param>
|
/// <param name="rootDirectory">The root directory to search for content.</param>
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
using System;
|
||||||
|
using StardewValley;
|
||||||
|
|
||||||
|
namespace StardewModdingAPI.Framework
|
||||||
|
{
|
||||||
|
/// <summary>Invokes callbacks for mod hooks provided by the game.</summary>
|
||||||
|
internal class SModHooks : ModHooks
|
||||||
|
{
|
||||||
|
/*********
|
||||||
|
** Properties
|
||||||
|
*********/
|
||||||
|
/// <summary>A callback to invoke before <see cref="Game1.newDayAfterFade"/> runs.</summary>
|
||||||
|
private readonly Action BeforeNewDayAfterFade;
|
||||||
|
|
||||||
|
|
||||||
|
/*********
|
||||||
|
** Public methods
|
||||||
|
*********/
|
||||||
|
/// <summary>Construct an instance.</summary>
|
||||||
|
/// <param name="beforeNewDayAfterFade">A callback to invoke before <see cref="Game1.newDayAfterFade"/> runs.</param>
|
||||||
|
public SModHooks(Action beforeNewDayAfterFade)
|
||||||
|
{
|
||||||
|
this.BeforeNewDayAfterFade = beforeNewDayAfterFade;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>A hook invoked when <see cref="Game1.newDayAfterFade"/> is called.</summary>
|
||||||
|
/// <param name="action">The vanilla <see cref="Game1.newDayAfterFade"/> logic.</param>
|
||||||
|
public override void OnGame1_NewDayAfterFade(Action action)
|
||||||
|
{
|
||||||
|
this.BeforeNewDayAfterFade?.Invoke();
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -79,6 +79,7 @@
|
||||||
<Compile Include="..\..\build\GlobalAssemblyInfo.cs">
|
<Compile Include="..\..\build\GlobalAssemblyInfo.cs">
|
||||||
<Link>Properties\GlobalAssemblyInfo.cs</Link>
|
<Link>Properties\GlobalAssemblyInfo.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Events\DayEndingEventArgs.cs" />
|
||||||
<Compile Include="Events\DayStartedEventArgs.cs" />
|
<Compile Include="Events\DayStartedEventArgs.cs" />
|
||||||
<Compile Include="Events\SaveCreatingEventArgs.cs" />
|
<Compile Include="Events\SaveCreatingEventArgs.cs" />
|
||||||
<Compile Include="Events\SavedEventArgs.cs" />
|
<Compile Include="Events\SavedEventArgs.cs" />
|
||||||
|
|
Loading…
Reference in New Issue