diff options
Diffstat (limited to 'src/SMAPI/Events')
65 files changed, 891 insertions, 150 deletions
diff --git a/src/SMAPI/Events/WorldBuildingListChangedEventArgs.cs b/src/SMAPI/Events/BuildingListChangedEventArgs.cs index e73b9396..9bc691fc 100644 --- a/src/SMAPI/Events/WorldBuildingListChangedEventArgs.cs +++ b/src/SMAPI/Events/BuildingListChangedEventArgs.cs @@ -7,7 +7,7 @@ using StardewValley.Buildings; namespace StardewModdingAPI.Events { /// <summary>Event arguments for a <see cref="IWorldEvents.BuildingListChanged"/> event.</summary> - public class WorldBuildingListChangedEventArgs : EventArgs + public class BuildingListChangedEventArgs : EventArgs { /********* ** Accessors @@ -29,7 +29,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The buildings added to the location.</param> /// <param name="removed">The buildings removed from the location.</param> - public WorldBuildingListChangedEventArgs(GameLocation location, IEnumerable<Building> added, IEnumerable<Building> removed) + public BuildingListChangedEventArgs(GameLocation location, IEnumerable<Building> added, IEnumerable<Building> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/InputButtonPressedEventArgs.cs b/src/SMAPI/Events/ButtonPressedEventArgs.cs index 8c6844dd..9e6c187f 100644 --- a/src/SMAPI/Events/InputButtonPressedEventArgs.cs +++ b/src/SMAPI/Events/ButtonPressedEventArgs.cs @@ -4,7 +4,7 @@ using StardewModdingAPI.Framework.Input; namespace StardewModdingAPI.Events { /// <summary>Event arguments when a button is pressed.</summary> - public class InputButtonPressedEventArgs : EventArgs + public class ButtonPressedEventArgs : EventArgs { /********* ** Properties @@ -30,7 +30,7 @@ namespace StardewModdingAPI.Events /// <param name="button">The button on the controller, keyboard, or mouse.</param> /// <param name="cursor">The cursor position.</param> /// <param name="inputState">The game's current input state.</param> - internal InputButtonPressedEventArgs(SButton button, ICursorPosition cursor, SInputState inputState) + internal ButtonPressedEventArgs(SButton button, ICursorPosition cursor, SInputState inputState) { this.Button = button; this.Cursor = cursor; diff --git a/src/SMAPI/Events/InputButtonReleasedEventArgs.cs b/src/SMAPI/Events/ButtonReleasedEventArgs.cs index 4b0bc326..2a289bc7 100644 --- a/src/SMAPI/Events/InputButtonReleasedEventArgs.cs +++ b/src/SMAPI/Events/ButtonReleasedEventArgs.cs @@ -4,7 +4,7 @@ using StardewModdingAPI.Framework.Input; namespace StardewModdingAPI.Events { /// <summary>Event arguments when a button is released.</summary> - public class InputButtonReleasedEventArgs : EventArgs + public class ButtonReleasedEventArgs : EventArgs { /********* ** Properties @@ -30,7 +30,7 @@ namespace StardewModdingAPI.Events /// <param name="button">The button on the controller, keyboard, or mouse.</param> /// <param name="cursor">The cursor position.</param> /// <param name="inputState">The game's current input state.</param> - internal InputButtonReleasedEventArgs(SButton button, ICursorPosition cursor, SInputState inputState) + internal ButtonReleasedEventArgs(SButton button, ICursorPosition cursor, SInputState inputState) { this.Button = button; this.Cursor = cursor; diff --git a/src/SMAPI/Events/ContentEvents.cs b/src/SMAPI/Events/ContentEvents.cs index 63645258..3ee0560b 100644 --- a/src/SMAPI/Events/ContentEvents.cs +++ b/src/SMAPI/Events/ContentEvents.cs @@ -19,8 +19,8 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the content language changes.</summary> public static event EventHandler<EventArgsValueChanged<string>> AfterLocaleChanged { - add => ContentEvents.EventManager.Content_LocaleChanged.Add(value); - remove => ContentEvents.EventManager.Content_LocaleChanged.Remove(value); + add => ContentEvents.EventManager.Legacy_LocaleChanged.Add(value); + remove => ContentEvents.EventManager.Legacy_LocaleChanged.Remove(value); } diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs index a3994d1d..56a4fa3f 100644 --- a/src/SMAPI/Events/ControlEvents.cs +++ b/src/SMAPI/Events/ControlEvents.cs @@ -20,57 +20,57 @@ namespace StardewModdingAPI.Events /// <summary>Raised when the <see cref="KeyboardState"/> changes. That happens when the player presses or releases a key.</summary> public static event EventHandler<EventArgsKeyboardStateChanged> KeyboardChanged { - add => ControlEvents.EventManager.Legacy_Control_KeyboardChanged.Add(value); - remove => ControlEvents.EventManager.Legacy_Control_KeyboardChanged.Remove(value); + add => ControlEvents.EventManager.Legacy_KeyboardChanged.Add(value); + remove => ControlEvents.EventManager.Legacy_KeyboardChanged.Remove(value); } /// <summary>Raised after the player presses a keyboard key.</summary> public static event EventHandler<EventArgsKeyPressed> KeyPressed { - add => ControlEvents.EventManager.Legacy_Control_KeyPressed.Add(value); - remove => ControlEvents.EventManager.Legacy_Control_KeyPressed.Remove(value); + add => ControlEvents.EventManager.Legacy_KeyPressed.Add(value); + remove => ControlEvents.EventManager.Legacy_KeyPressed.Remove(value); } /// <summary>Raised after the player releases a keyboard key.</summary> public static event EventHandler<EventArgsKeyPressed> KeyReleased { - add => ControlEvents.EventManager.Legacy_Control_KeyReleased.Add(value); - remove => ControlEvents.EventManager.Legacy_Control_KeyReleased.Remove(value); + add => ControlEvents.EventManager.Legacy_KeyReleased.Add(value); + remove => ControlEvents.EventManager.Legacy_KeyReleased.Remove(value); } /// <summary>Raised when the <see cref="MouseState"/> changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button.</summary> public static event EventHandler<EventArgsMouseStateChanged> MouseChanged { - add => ControlEvents.EventManager.Legacy_Control_MouseChanged.Add(value); - remove => ControlEvents.EventManager.Legacy_Control_MouseChanged.Remove(value); + add => ControlEvents.EventManager.Legacy_MouseChanged.Add(value); + remove => ControlEvents.EventManager.Legacy_MouseChanged.Remove(value); } /// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary> public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed { - add => ControlEvents.EventManager.Legacy_Control_ControllerButtonPressed.Add(value); - remove => ControlEvents.EventManager.Legacy_Control_ControllerButtonPressed.Remove(value); + add => ControlEvents.EventManager.Legacy_ControllerButtonPressed.Add(value); + remove => ControlEvents.EventManager.Legacy_ControllerButtonPressed.Remove(value); } /// <summary>The player released a controller button. This event isn't raised for trigger buttons.</summary> public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased { - add => ControlEvents.EventManager.Legacy_Control_ControllerButtonReleased.Add(value); - remove => ControlEvents.EventManager.Legacy_Control_ControllerButtonReleased.Remove(value); + add => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Add(value); + remove => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Remove(value); } /// <summary>The player pressed a controller trigger button.</summary> public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed { - add => ControlEvents.EventManager.Legacy_Control_ControllerTriggerPressed.Add(value); - remove => ControlEvents.EventManager.Legacy_Control_ControllerTriggerPressed.Remove(value); + add => ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Add(value); + remove => ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Remove(value); } /// <summary>The player released a controller trigger button.</summary> public static event EventHandler<EventArgsControllerTriggerReleased> ControllerTriggerReleased { - add => ControlEvents.EventManager.Legacy_Control_ControllerTriggerReleased.Add(value); - remove => ControlEvents.EventManager.Legacy_Control_ControllerTriggerReleased.Remove(value); + add => ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Add(value); + remove => ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Remove(value); } diff --git a/src/SMAPI/Events/InputCursorMovedEventArgs.cs b/src/SMAPI/Events/CursorMovedEventArgs.cs index 53aac5b3..453743b9 100644 --- a/src/SMAPI/Events/InputCursorMovedEventArgs.cs +++ b/src/SMAPI/Events/CursorMovedEventArgs.cs @@ -3,7 +3,7 @@ using System; namespace StardewModdingAPI.Events { /// <summary>Event arguments when the in-game cursor is moved.</summary> - public class InputCursorMovedEventArgs : EventArgs + public class CursorMovedEventArgs : EventArgs { /********* ** Accessors @@ -21,7 +21,7 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="oldPosition">The previous cursor position.</param> /// <param name="newPosition">The new cursor position.</param> - public InputCursorMovedEventArgs(ICursorPosition oldPosition, ICursorPosition newPosition) + public CursorMovedEventArgs(ICursorPosition oldPosition, ICursorPosition newPosition) { this.OldPosition = oldPosition; this.NewPosition = newPosition; diff --git a/src/SMAPI/Events/GameLoopLaunchedEventArgs.cs b/src/SMAPI/Events/DayEndingEventArgs.cs index 6a42e4f9..5cb433bc 100644 --- a/src/SMAPI/Events/GameLoopLaunchedEventArgs.cs +++ b/src/SMAPI/Events/DayEndingEventArgs.cs @@ -2,6 +2,6 @@ using System; namespace StardewModdingAPI.Events { - /// <summary>Event arguments for an <see cref="IGameLoopEvents.Launched"/> event.</summary> - public class GameLoopLaunchedEventArgs : EventArgs { } + /// <summary>Event arguments for an <see cref="IGameLoopEvents.DayEnding"/> event.</summary> + public class DayEndingEventArgs : EventArgs { } } diff --git a/src/SMAPI/Events/DayStartedEventArgs.cs b/src/SMAPI/Events/DayStartedEventArgs.cs new file mode 100644 index 00000000..45823628 --- /dev/null +++ b/src/SMAPI/Events/DayStartedEventArgs.cs @@ -0,0 +1,7 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.DayStarted"/> event.</summary> + public class DayStartedEventArgs : EventArgs { } +} diff --git a/src/SMAPI/Events/WorldDebrisListChangedEventArgs.cs b/src/SMAPI/Events/DebrisListChangedEventArgs.cs index aad9c24d..1337bd3b 100644 --- a/src/SMAPI/Events/WorldDebrisListChangedEventArgs.cs +++ b/src/SMAPI/Events/DebrisListChangedEventArgs.cs @@ -6,7 +6,7 @@ using StardewValley; namespace StardewModdingAPI.Events { /// <summary>Event arguments for a <see cref="IWorldEvents.DebrisListChanged"/> event.</summary> - public class WorldDebrisListChangedEventArgs : EventArgs + public class DebrisListChangedEventArgs : EventArgs { /********* ** Accessors @@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The debris added to the location.</param> /// <param name="removed">The debris removed from the location.</param> - public WorldDebrisListChangedEventArgs(GameLocation location, IEnumerable<Debris> added, IEnumerable<Debris> removed) + public DebrisListChangedEventArgs(GameLocation location, IEnumerable<Debris> added, IEnumerable<Debris> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/EventArgsInventoryChanged.cs b/src/SMAPI/Events/EventArgsInventoryChanged.cs index 1fdca834..3a2354b6 100644 --- a/src/SMAPI/Events/EventArgsInventoryChanged.cs +++ b/src/SMAPI/Events/EventArgsInventoryChanged.cs @@ -30,7 +30,7 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="inventory">The player's inventory.</param> /// <param name="changedItems">The inventory changes.</param> - public EventArgsInventoryChanged(IList<Item> inventory, List<ItemStackChange> changedItems) + public EventArgsInventoryChanged(IList<Item> inventory, ItemStackChange[] changedItems) { this.Inventory = inventory; this.Added = changedItems.Where(n => n.ChangeType == ChangeType.Added).ToList(); diff --git a/src/SMAPI/Events/EventArgsLevelUp.cs b/src/SMAPI/Events/EventArgsLevelUp.cs index fe6696d4..e9a697e7 100644 --- a/src/SMAPI/Events/EventArgsLevelUp.cs +++ b/src/SMAPI/Events/EventArgsLevelUp.cs @@ -1,4 +1,5 @@ using System; +using StardewModdingAPI.Enums; namespace StardewModdingAPI.Events { @@ -18,22 +19,22 @@ namespace StardewModdingAPI.Events public enum LevelType { /// <summary>The combat skill.</summary> - Combat, + Combat = SkillType.Combat, /// <summary>The farming skill.</summary> - Farming, + Farming = SkillType.Farming, /// <summary>The fishing skill.</summary> - Fishing, + Fishing = SkillType.Fishing, /// <summary>The foraging skill.</summary> - Foraging, + Foraging = SkillType.Foraging, /// <summary>The mining skill.</summary> - Mining, + Mining = SkillType.Mining, /// <summary>The luck skill.</summary> - Luck + Luck = SkillType.Luck } diff --git a/src/SMAPI/Events/GameEvents.cs b/src/SMAPI/Events/GameEvents.cs index 92879280..952b3570 100644 --- a/src/SMAPI/Events/GameEvents.cs +++ b/src/SMAPI/Events/GameEvents.cs @@ -19,57 +19,57 @@ namespace StardewModdingAPI.Events /// <summary>Raised when the game updates its state (≈60 times per second).</summary> public static event EventHandler UpdateTick { - add => GameEvents.EventManager.Game_UpdateTick.Add(value); - remove => GameEvents.EventManager.Game_UpdateTick.Remove(value); + add => GameEvents.EventManager.Legacy_UpdateTick.Add(value); + remove => GameEvents.EventManager.Legacy_UpdateTick.Remove(value); } /// <summary>Raised every other tick (≈30 times per second).</summary> public static event EventHandler SecondUpdateTick { - add => GameEvents.EventManager.Game_SecondUpdateTick.Add(value); - remove => GameEvents.EventManager.Game_SecondUpdateTick.Remove(value); + add => GameEvents.EventManager.Legacy_SecondUpdateTick.Add(value); + remove => GameEvents.EventManager.Legacy_SecondUpdateTick.Remove(value); } /// <summary>Raised every fourth tick (≈15 times per second).</summary> public static event EventHandler FourthUpdateTick { - add => GameEvents.EventManager.Game_FourthUpdateTick.Add(value); - remove => GameEvents.EventManager.Game_FourthUpdateTick.Remove(value); + add => GameEvents.EventManager.Legacy_FourthUpdateTick.Add(value); + remove => GameEvents.EventManager.Legacy_FourthUpdateTick.Remove(value); } /// <summary>Raised every eighth tick (≈8 times per second).</summary> public static event EventHandler EighthUpdateTick { - add => GameEvents.EventManager.Game_EighthUpdateTick.Add(value); - remove => GameEvents.EventManager.Game_EighthUpdateTick.Remove(value); + add => GameEvents.EventManager.Legacy_EighthUpdateTick.Add(value); + remove => GameEvents.EventManager.Legacy_EighthUpdateTick.Remove(value); } /// <summary>Raised every 15th tick (≈4 times per second).</summary> public static event EventHandler QuarterSecondTick { - add => GameEvents.EventManager.Game_QuarterSecondTick.Add(value); - remove => GameEvents.EventManager.Game_QuarterSecondTick.Remove(value); + add => GameEvents.EventManager.Legacy_QuarterSecondTick.Add(value); + remove => GameEvents.EventManager.Legacy_QuarterSecondTick.Remove(value); } /// <summary>Raised every 30th tick (≈twice per second).</summary> public static event EventHandler HalfSecondTick { - add => GameEvents.EventManager.Game_HalfSecondTick.Add(value); - remove => GameEvents.EventManager.Game_HalfSecondTick.Remove(value); + add => GameEvents.EventManager.Legacy_HalfSecondTick.Add(value); + remove => GameEvents.EventManager.Legacy_HalfSecondTick.Remove(value); } /// <summary>Raised every 60th tick (≈once per second).</summary> public static event EventHandler OneSecondTick { - add => GameEvents.EventManager.Game_OneSecondTick.Add(value); - remove => GameEvents.EventManager.Game_OneSecondTick.Remove(value); + add => GameEvents.EventManager.Legacy_OneSecondTick.Add(value); + remove => GameEvents.EventManager.Legacy_OneSecondTick.Remove(value); } /// <summary>Raised once after the game initialises and all <see cref="IMod.Entry"/> methods have been called.</summary> public static event EventHandler FirstUpdateTick { - add => GameEvents.EventManager.Game_FirstUpdateTick.Add(value); - remove => GameEvents.EventManager.Game_FirstUpdateTick.Remove(value); + add => GameEvents.EventManager.Legacy_FirstUpdateTick.Add(value); + remove => GameEvents.EventManager.Legacy_FirstUpdateTick.Remove(value); } diff --git a/src/SMAPI/Events/GameLaunchedEventArgs.cs b/src/SMAPI/Events/GameLaunchedEventArgs.cs new file mode 100644 index 00000000..a4c78754 --- /dev/null +++ b/src/SMAPI/Events/GameLaunchedEventArgs.cs @@ -0,0 +1,7 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.GameLaunched"/> event.</summary> + public class GameLaunchedEventArgs : EventArgs { } +} diff --git a/src/SMAPI/Events/GraphicsEvents.cs b/src/SMAPI/Events/GraphicsEvents.cs index e1ff4ee7..53f04822 100644 --- a/src/SMAPI/Events/GraphicsEvents.cs +++ b/src/SMAPI/Events/GraphicsEvents.cs @@ -19,8 +19,8 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the game window is resized.</summary> public static event EventHandler Resize { - add => GraphicsEvents.EventManager.Graphics_Resize.Add(value); - remove => GraphicsEvents.EventManager.Graphics_Resize.Remove(value); + add => GraphicsEvents.EventManager.Legacy_Resize.Add(value); + remove => GraphicsEvents.EventManager.Legacy_Resize.Remove(value); } /**** @@ -29,15 +29,15 @@ namespace StardewModdingAPI.Events /// <summary>Raised before drawing the world to the screen.</summary> public static event EventHandler OnPreRenderEvent { - add => GraphicsEvents.EventManager.Graphics_OnPreRenderEvent.Add(value); - remove => GraphicsEvents.EventManager.Graphics_OnPreRenderEvent.Remove(value); + add => GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Add(value); + remove => GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Remove(value); } /// <summary>Raised after drawing the world to the screen.</summary> public static event EventHandler OnPostRenderEvent { - add => GraphicsEvents.EventManager.Graphics_OnPostRenderEvent.Add(value); - remove => GraphicsEvents.EventManager.Graphics_OnPostRenderEvent.Remove(value); + add => GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Add(value); + remove => GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Remove(value); } /**** @@ -46,15 +46,15 @@ namespace StardewModdingAPI.Events /// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary> public static event EventHandler OnPreRenderHudEvent { - add => GraphicsEvents.EventManager.Graphics_OnPreRenderHudEvent.Add(value); - remove => GraphicsEvents.EventManager.Graphics_OnPreRenderHudEvent.Remove(value); + add => GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Add(value); + remove => GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Remove(value); } /// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary> public static event EventHandler OnPostRenderHudEvent { - add => GraphicsEvents.EventManager.Graphics_OnPostRenderHudEvent.Add(value); - remove => GraphicsEvents.EventManager.Graphics_OnPostRenderHudEvent.Remove(value); + add => GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Add(value); + remove => GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Remove(value); } /**** @@ -63,15 +63,15 @@ namespace StardewModdingAPI.Events /// <summary>Raised before drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary> public static event EventHandler OnPreRenderGuiEvent { - add => GraphicsEvents.EventManager.Graphics_OnPreRenderGuiEvent.Add(value); - remove => GraphicsEvents.EventManager.Graphics_OnPreRenderGuiEvent.Remove(value); + add => GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Add(value); + remove => GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Remove(value); } /// <summary>Raised after drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary> public static event EventHandler OnPostRenderGuiEvent { - add => GraphicsEvents.EventManager.Graphics_OnPostRenderGuiEvent.Add(value); - remove => GraphicsEvents.EventManager.Graphics_OnPostRenderGuiEvent.Remove(value); + add => GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Add(value); + remove => GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Remove(value); } diff --git a/src/SMAPI/Events/IDisplayEvents.cs b/src/SMAPI/Events/IDisplayEvents.cs new file mode 100644 index 00000000..dbf8d90f --- /dev/null +++ b/src/SMAPI/Events/IDisplayEvents.cs @@ -0,0 +1,39 @@ +using System; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Events related to UI and drawing to the screen.</summary> + public interface IDisplayEvents + { + /// <summary>Raised after a game menu is opened, closed, or replaced.</summary> + event EventHandler<MenuChangedEventArgs> MenuChanged; + + /// <summary>Raised before the game draws anything to the screen in a draw tick, as soon as the sprite batch is opened. The sprite batch may be closed and reopened multiple times after this event is called, but it's only raised once per draw tick. This event isn't useful for drawing to the screen, since the game will draw over it.</summary> + event EventHandler<RenderingEventArgs> Rendering; + + /// <summary>Raised after the game draws to the sprite patch in a draw tick, just before the final sprite batch is rendered to the screen. Since the game may open/close the sprite batch multiple times in a draw tick, the sprite batch may not contain everything being drawn and some things may already be rendered to the screen. Content drawn to the sprite batch at this point will be drawn over all vanilla content (including menus, HUD, and cursor).</summary> + event EventHandler<RenderedEventArgs> Rendered; + + /// <summary>Raised before the game world is drawn to the screen. This event isn't useful for drawing to the screen, since the game will draw over it.</summary> + event EventHandler<RenderingWorldEventArgs> RenderingWorld; + + /// <summary>Raised after the game world is drawn to the sprite patch, before it's rendered to the screen. Content drawn to the sprite batch at this point will be drawn over the world, but under any active menu, HUD elements, or cursor.</summary> + event EventHandler<RenderedWorldEventArgs> RenderedWorld; + + /// <summary>When a menu is open (<see cref="Game1.activeClickableMenu"/> isn't null), raised before that menu is drawn to the screen. This includes the game's internal menus like the title screen. Content drawn to the sprite batch at this point will appear under the menu.</summary> + event EventHandler<RenderingActiveMenuEventArgs> RenderingActiveMenu; + + /// <summary>When a menu is open (<see cref="Game1.activeClickableMenu"/> isn't null), raised after that menu is drawn to the sprite batch but before it's rendered to the screen. Content drawn to the sprite batch at this point will appear over the menu and menu cursor.</summary> + event EventHandler<RenderedActiveMenuEventArgs> RenderedActiveMenu; + + /// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open). Content drawn to the sprite batch at this point will appear under the HUD.</summary> + event EventHandler<RenderingHudEventArgs> RenderingHud; + + /// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen. The vanilla HUD may be hidden at this point (e.g. because a menu is open). Content drawn to the sprite batch at this point will appear over the HUD.</summary> + event EventHandler<RenderedHudEventArgs> RenderedHud; + + /// <summary>Raised after the game window is resized.</summary> + event EventHandler<WindowResizedEventArgs> WindowResized; + } +} diff --git a/src/SMAPI/Events/IGameLoopEvents.cs b/src/SMAPI/Events/IGameLoopEvents.cs index a56b3de3..e1900f79 100644 --- a/src/SMAPI/Events/IGameLoopEvents.cs +++ b/src/SMAPI/Events/IGameLoopEvents.cs @@ -6,12 +6,39 @@ namespace StardewModdingAPI.Events public interface IGameLoopEvents { /// <summary>Raised after the game is launched, right before the first update tick. This happens once per game session (unrelated to loading saves). All mods are loaded and initialised at this point, so this is a good time to set up mod integrations.</summary> - event EventHandler<GameLoopLaunchedEventArgs> Launched; + event EventHandler<GameLaunchedEventArgs> GameLaunched; - /// <summary>Raised before the game performs its overall update tick (≈60 times per second).</summary> - event EventHandler<GameLoopUpdatingEventArgs> Updating; + /// <summary>Raised before the game state is updated (≈60 times per second).</summary> + event EventHandler<UpdateTickingEventArgs> UpdateTicking; - /// <summary>Raised after the game performs its overall update tick (≈60 times per second).</summary> - event EventHandler<GameLoopUpdatedEventArgs> Updated; + /// <summary>Raised after the game state is updated (≈60 times per second).</summary> + event EventHandler<UpdateTickedEventArgs> UpdateTicked; + + /// <summary>Raised before the game creates a new save file.</summary> + event EventHandler<SaveCreatingEventArgs> SaveCreating; + + /// <summary>Raised after the game finishes creating the save file.</summary> + event EventHandler<SaveCreatedEventArgs> SaveCreated; + + /// <summary>Raised before the game begins writes data to the save file (except the initial save creation).</summary> + event EventHandler<SavingEventArgs> Saving; + + /// <summary>Raised after the game finishes writing data to the save file (except the initial save creation).</summary> + event EventHandler<SavedEventArgs> Saved; + + /// <summary>Raised after the player loads a save slot.</summary> + event EventHandler<SaveLoadedEventArgs> SaveLoaded; + + /// <summary>Raised after the game begins a new day (including when the player loads a save).</summary> + 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; + + /// <summary>Raised after the in-game clock time changes.</summary> + event EventHandler<TimeChangedEventArgs> TimeChanged; + + /// <summary>Raised after the game returns to the title screen.</summary> + event EventHandler<ReturnedToTitleEventArgs> ReturnedToTitle; } } diff --git a/src/SMAPI/Events/IInputEvents.cs b/src/SMAPI/Events/IInputEvents.cs index 8e2ef406..5c40a438 100644 --- a/src/SMAPI/Events/IInputEvents.cs +++ b/src/SMAPI/Events/IInputEvents.cs @@ -6,15 +6,15 @@ namespace StardewModdingAPI.Events public interface IInputEvents { /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary> - event EventHandler<InputButtonPressedEventArgs> ButtonPressed; + event EventHandler<ButtonPressedEventArgs> ButtonPressed; /// <summary>Raised after the player releases a button on the keyboard, controller, or mouse.</summary> - event EventHandler<InputButtonReleasedEventArgs> ButtonReleased; + event EventHandler<ButtonReleasedEventArgs> ButtonReleased; /// <summary>Raised after the player moves the in-game cursor.</summary> - event EventHandler<InputCursorMovedEventArgs> CursorMoved; + event EventHandler<CursorMovedEventArgs> CursorMoved; /// <summary>Raised after the player scrolls the mouse wheel.</summary> - event EventHandler<InputMouseWheelScrolledEventArgs> MouseWheelScrolled; + event EventHandler<MouseWheelScrolledEventArgs> MouseWheelScrolled; } } diff --git a/src/SMAPI/Events/IModEvents.cs b/src/SMAPI/Events/IModEvents.cs index cf2f8cb8..bd7ab880 100644 --- a/src/SMAPI/Events/IModEvents.cs +++ b/src/SMAPI/Events/IModEvents.cs @@ -3,13 +3,25 @@ namespace StardewModdingAPI.Events /// <summary>Manages access to events raised by SMAPI.</summary> public interface IModEvents { + /// <summary>Events related to UI and drawing to the screen.</summary> + IDisplayEvents Display { get; } + /// <summary>Events linked to the game's update loop. The update loop runs roughly ≈60 times/second to run game logic like state changes, action handling, etc. These can be useful, but you should consider more semantic events like <see cref="Input"/> if possible.</summary> IGameLoopEvents GameLoop { get; } /// <summary>Events raised when the player provides input using a controller, keyboard, or mouse.</summary> IInputEvents Input { get; } + /// <summary>Events raised for multiplayer messages and connections.</summary> + IMultiplayerEvents Multiplayer { get; } + + /// <summary>Events raised when the player data changes.</summary> + IPlayerEvents Player { get; } + /// <summary>Events raised when something changes in the world.</summary> IWorldEvents World { get; } + + /// <summary>Events serving specialised edge cases that shouldn't be used by most mods.</summary> + ISpecialisedEvents Specialised { get; } } } diff --git a/src/SMAPI/Events/IMultiplayerEvents.cs b/src/SMAPI/Events/IMultiplayerEvents.cs new file mode 100644 index 00000000..4a31f48e --- /dev/null +++ b/src/SMAPI/Events/IMultiplayerEvents.cs @@ -0,0 +1,17 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Events raised for multiplayer messages and connections.</summary> + public interface IMultiplayerEvents + { + /// <summary>Raised after the mod context for a peer is received. This happens before the game approves the connection, so the player doesn't yet exist in the game. This is the earliest point where messages can be sent to the peer via SMAPI.</summary> + event EventHandler<PeerContextReceivedEventArgs> PeerContextReceived; + + /// <summary>Raised after a mod message is received over the network.</summary> + event EventHandler<ModMessageReceivedEventArgs> ModMessageReceived; + + /// <summary>Raised after the connection with a peer is severed.</summary> + event EventHandler<PeerDisconnectedEventArgs> PeerDisconnected; + } +} diff --git a/src/SMAPI/Events/IPlayerEvents.cs b/src/SMAPI/Events/IPlayerEvents.cs new file mode 100644 index 00000000..81e17b1a --- /dev/null +++ b/src/SMAPI/Events/IPlayerEvents.cs @@ -0,0 +1,17 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Events raised when the player data changes.</summary> + public interface IPlayerEvents + { + /// <summary>Raised after items are added or removed to a player's inventory. NOTE: this event is currently only raised for the current player.</summary> + event EventHandler<InventoryChangedEventArgs> InventoryChanged; + + /// <summary>Raised after a player skill level changes. This happens as soon as they level up, not when the game notifies the player after their character goes to bed. NOTE: this event is currently only raised for the current player.</summary> + event EventHandler<LevelChangedEventArgs> LevelChanged; + + /// <summary>Raised after a player warps to a new location. NOTE: this event is currently only raised for the current player.</summary> + event EventHandler<WarpedEventArgs> Warped; + } +} diff --git a/src/SMAPI/Events/ISpecialisedEvents.cs b/src/SMAPI/Events/ISpecialisedEvents.cs new file mode 100644 index 00000000..928cd05d --- /dev/null +++ b/src/SMAPI/Events/ISpecialisedEvents.cs @@ -0,0 +1,14 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Events serving specialised edge cases that shouldn't be used by most mods.</summary> + public interface ISpecialisedEvents + { + /// <summary>Raised before the game state is updated (≈60 times per second), regardless of normal SMAPI validation. This event is not thread-safe and may be invoked while game logic is running asynchronously. Changes to game state in this method may crash the game or corrupt an in-progress save. Do not use this event unless you're fully aware of the context in which your code will be run. Mods using this event will trigger a stability warning in the SMAPI console.</summary> + event EventHandler<UnvalidatedUpdateTickingEventArgs> UnvalidatedUpdateTicking; + + /// <summary>Raised after the game state is updated (≈60 times per second), regardless of normal SMAPI validation. This event is not thread-safe and may be invoked while game logic is running asynchronously. Changes to game state in this method may crash the game or corrupt an in-progress save. Do not use this event unless you're fully aware of the context in which your code will be run. Mods using this event will trigger a stability warning in the SMAPI console.</summary> + event EventHandler<UnvalidatedUpdateTickedEventArgs> UnvalidatedUpdateTicked; + } +} diff --git a/src/SMAPI/Events/IWorldEvents.cs b/src/SMAPI/Events/IWorldEvents.cs index d4efb53b..0ceffcc1 100644 --- a/src/SMAPI/Events/IWorldEvents.cs +++ b/src/SMAPI/Events/IWorldEvents.cs @@ -6,24 +6,24 @@ namespace StardewModdingAPI.Events public interface IWorldEvents { /// <summary>Raised after a game location is added or removed.</summary> - event EventHandler<WorldLocationListChangedEventArgs> LocationListChanged; + event EventHandler<LocationListChangedEventArgs> LocationListChanged; /// <summary>Raised after buildings are added or removed in a location.</summary> - event EventHandler<WorldBuildingListChangedEventArgs> BuildingListChanged; + event EventHandler<BuildingListChangedEventArgs> BuildingListChanged; /// <summary>Raised after debris are added or removed in a location.</summary> - event EventHandler<WorldDebrisListChangedEventArgs> DebrisListChanged; + event EventHandler<DebrisListChangedEventArgs> DebrisListChanged; /// <summary>Raised after large terrain features (like bushes) are added or removed in a location.</summary> - event EventHandler<WorldLargeTerrainFeatureListChangedEventArgs> LargeTerrainFeatureListChanged; + event EventHandler<LargeTerrainFeatureListChangedEventArgs> LargeTerrainFeatureListChanged; /// <summary>Raised after NPCs are added or removed in a location.</summary> - event EventHandler<WorldNpcListChangedEventArgs> NpcListChanged; + event EventHandler<NpcListChangedEventArgs> NpcListChanged; /// <summary>Raised after objects are added or removed in a location.</summary> - event EventHandler<WorldObjectListChangedEventArgs> ObjectListChanged; + event EventHandler<ObjectListChangedEventArgs> ObjectListChanged; /// <summary>Raised after terrain features (like floors and trees) are added or removed in a location.</summary> - event EventHandler<WorldTerrainFeatureListChangedEventArgs> TerrainFeatureListChanged; + event EventHandler<TerrainFeatureListChangedEventArgs> TerrainFeatureListChanged; } } diff --git a/src/SMAPI/Events/InputEvents.cs b/src/SMAPI/Events/InputEvents.cs index e62d6ee6..4c1781a5 100644 --- a/src/SMAPI/Events/InputEvents.cs +++ b/src/SMAPI/Events/InputEvents.cs @@ -19,15 +19,15 @@ namespace StardewModdingAPI.Events /// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary> public static event EventHandler<EventArgsInput> ButtonPressed { - add => InputEvents.EventManager.Legacy_Input_ButtonPressed.Add(value); - remove => InputEvents.EventManager.Legacy_Input_ButtonPressed.Remove(value); + add => InputEvents.EventManager.Legacy_ButtonPressed.Add(value); + remove => InputEvents.EventManager.Legacy_ButtonPressed.Remove(value); } /// <summary>Raised when the player releases a keyboard key on the keyboard, controller, or mouse.</summary> public static event EventHandler<EventArgsInput> ButtonReleased { - add => InputEvents.EventManager.Legacy_Input_ButtonReleased.Add(value); - remove => InputEvents.EventManager.Legacy_Input_ButtonReleased.Remove(value); + add => InputEvents.EventManager.Legacy_ButtonReleased.Add(value); + remove => InputEvents.EventManager.Legacy_ButtonReleased.Remove(value); } diff --git a/src/SMAPI/Events/InventoryChangedEventArgs.cs b/src/SMAPI/Events/InventoryChangedEventArgs.cs new file mode 100644 index 00000000..a081611b --- /dev/null +++ b/src/SMAPI/Events/InventoryChangedEventArgs.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IPlayerEvents.InventoryChanged"/> event.</summary> + public class InventoryChangedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The player whose inventory changed.</summary> + public Farmer Player { get; } + + /// <summary>The added items.</summary> + public IEnumerable<Item> Added { get; } + + /// <summary>The removed items.</summary> + public IEnumerable<Item> Removed { get; } + + /// <summary>The items whose stack sizes changed, with the relative change.</summary> + public IEnumerable<ItemStackSizeChange> QuantityChanged { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="player">The player whose inventory changed.</param> + /// <param name="changedItems">The inventory changes.</param> + public InventoryChangedEventArgs(Farmer player, ItemStackChange[] changedItems) + { + this.Player = player; + this.Added = changedItems + .Where(n => n.ChangeType == ChangeType.Added) + .Select(p => p.Item) + .ToArray(); + + this.Removed = changedItems + .Where(n => n.ChangeType == ChangeType.Removed) + .Select(p => p.Item) + .ToArray(); + + this.QuantityChanged = changedItems + .Where(n => n.ChangeType == ChangeType.StackChange) + .Select(change => new ItemStackSizeChange( + item: change.Item, + oldSize: change.Item.Stack - change.StackChange, + newSize: change.Item.Stack + )) + .ToArray(); + } + } +} diff --git a/src/SMAPI/Events/ItemStackSizeChange.cs b/src/SMAPI/Events/ItemStackSizeChange.cs new file mode 100644 index 00000000..35369be2 --- /dev/null +++ b/src/SMAPI/Events/ItemStackSizeChange.cs @@ -0,0 +1,35 @@ +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>An inventory item stack size change.</summary> + public class ItemStackSizeChange + { + /********* + ** Accessors + *********/ + /// <summary>The item whose stack size changed.</summary> + public Item Item { get; } + + /// <summary>The previous stack size.</summary> + public int OldSize { get; } + + /// <summary>The new stack size.</summary> + public int NewSize { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="item">The item whose stack size changed.</param> + /// <param name="oldSize">The previous stack size.</param> + /// <param name="newSize">The new stack size.</param> + public ItemStackSizeChange(Item item, int oldSize, int newSize) + { + this.Item = item; + this.OldSize = oldSize; + this.NewSize = newSize; + } + } +} diff --git a/src/SMAPI/Events/WorldLargeTerrainFeatureListChangedEventArgs.cs b/src/SMAPI/Events/LargeTerrainFeatureListChangedEventArgs.cs index 053a0e41..63b12687 100644 --- a/src/SMAPI/Events/WorldLargeTerrainFeatureListChangedEventArgs.cs +++ b/src/SMAPI/Events/LargeTerrainFeatureListChangedEventArgs.cs @@ -7,7 +7,7 @@ using StardewValley.TerrainFeatures; namespace StardewModdingAPI.Events { /// <summary>Event arguments for a <see cref="IWorldEvents.LargeTerrainFeatureListChanged"/> event.</summary> - public class WorldLargeTerrainFeatureListChangedEventArgs : EventArgs + public class LargeTerrainFeatureListChangedEventArgs : EventArgs { /********* ** Accessors @@ -29,7 +29,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The large terrain features added to the location.</param> /// <param name="removed">The large terrain features removed from the location.</param> - public WorldLargeTerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<LargeTerrainFeature> added, IEnumerable<LargeTerrainFeature> removed) + public LargeTerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<LargeTerrainFeature> added, IEnumerable<LargeTerrainFeature> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/LevelChangedEventArgs.cs b/src/SMAPI/Events/LevelChangedEventArgs.cs new file mode 100644 index 00000000..174094c7 --- /dev/null +++ b/src/SMAPI/Events/LevelChangedEventArgs.cs @@ -0,0 +1,42 @@ +using System; +using StardewModdingAPI.Enums; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for a <see cref="IPlayerEvents.LevelChanged"/> event.</summary> + public class LevelChangedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The player whose skill level changed.</summary> + public Farmer Player { get; } + + /// <summary>The skill whose level changed.</summary> + public SkillType Skill { get; } + + /// <summary>The previous skill level.</summary> + public int OldLevel { get; } + + /// <summary>The new skill level.</summary> + public int NewLevel { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="player">The player whose skill level changed.</param> + /// <param name="skill">The skill whose level changed.</param> + /// <param name="oldLevel">The previous skill level.</param> + /// <param name="newLevel">The new skill level.</param> + public LevelChangedEventArgs(Farmer player, SkillType skill, int oldLevel, int newLevel) + { + this.Player = player; + this.Skill = skill; + this.OldLevel = oldLevel; + this.NewLevel = newLevel; + } + } +} diff --git a/src/SMAPI/Events/LocationEvents.cs b/src/SMAPI/Events/LocationEvents.cs index e2108de0..81f547ae 100644 --- a/src/SMAPI/Events/LocationEvents.cs +++ b/src/SMAPI/Events/LocationEvents.cs @@ -19,22 +19,22 @@ namespace StardewModdingAPI.Events /// <summary>Raised after a game location is added or removed.</summary> public static event EventHandler<EventArgsLocationsChanged> LocationsChanged { - add => LocationEvents.EventManager.Legacy_Location_LocationsChanged.Add(value); - remove => LocationEvents.EventManager.Legacy_Location_LocationsChanged.Remove(value); + add => LocationEvents.EventManager.Legacy_LocationsChanged.Add(value); + remove => LocationEvents.EventManager.Legacy_LocationsChanged.Remove(value); } /// <summary>Raised after buildings are added or removed in a location.</summary> public static event EventHandler<EventArgsLocationBuildingsChanged> BuildingsChanged { - add => LocationEvents.EventManager.Legacy_Location_BuildingsChanged.Add(value); - remove => LocationEvents.EventManager.Legacy_Location_BuildingsChanged.Remove(value); + add => LocationEvents.EventManager.Legacy_BuildingsChanged.Add(value); + remove => LocationEvents.EventManager.Legacy_BuildingsChanged.Remove(value); } /// <summary>Raised after objects are added or removed in a location.</summary> public static event EventHandler<EventArgsLocationObjectsChanged> ObjectsChanged { - add => LocationEvents.EventManager.Legacy_Location_ObjectsChanged.Add(value); - remove => LocationEvents.EventManager.Legacy_Location_ObjectsChanged.Remove(value); + add => LocationEvents.EventManager.Legacy_ObjectsChanged.Add(value); + remove => LocationEvents.EventManager.Legacy_ObjectsChanged.Remove(value); } diff --git a/src/SMAPI/Events/WorldLocationListChangedEventArgs.cs b/src/SMAPI/Events/LocationListChangedEventArgs.cs index 8bc26a43..e93f0a80 100644 --- a/src/SMAPI/Events/WorldLocationListChangedEventArgs.cs +++ b/src/SMAPI/Events/LocationListChangedEventArgs.cs @@ -6,7 +6,7 @@ using StardewValley; namespace StardewModdingAPI.Events { /// <summary>Event arguments for a <see cref="IWorldEvents.LocationListChanged"/> event.</summary> - public class WorldLocationListChangedEventArgs : EventArgs + public class LocationListChangedEventArgs : EventArgs { /********* ** Accessors @@ -24,7 +24,7 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="added">The added locations.</param> /// <param name="removed">The removed locations.</param> - public WorldLocationListChangedEventArgs(IEnumerable<GameLocation> added, IEnumerable<GameLocation> removed) + public LocationListChangedEventArgs(IEnumerable<GameLocation> added, IEnumerable<GameLocation> removed) { this.Added = added.ToArray(); this.Removed = removed.ToArray(); diff --git a/src/SMAPI/Events/MenuChangedEventArgs.cs b/src/SMAPI/Events/MenuChangedEventArgs.cs new file mode 100644 index 00000000..e1c049a2 --- /dev/null +++ b/src/SMAPI/Events/MenuChangedEventArgs.cs @@ -0,0 +1,31 @@ +using System; +using StardewValley.Menus; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.MenuChanged"/> event.</summary> + public class MenuChangedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The previous menu.</summary> + public IClickableMenu OldMenu { get; } + + /// <summary>The current menu.</summary> + public IClickableMenu NewMenu { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="oldMenu">The previous menu.</param> + /// <param name="newMenu">The current menu.</param> + public MenuChangedEventArgs(IClickableMenu oldMenu, IClickableMenu newMenu) + { + this.OldMenu = oldMenu; + this.NewMenu = newMenu; + } + } +} diff --git a/src/SMAPI/Events/MenuEvents.cs b/src/SMAPI/Events/MenuEvents.cs index 7fcc3844..362b5070 100644 --- a/src/SMAPI/Events/MenuEvents.cs +++ b/src/SMAPI/Events/MenuEvents.cs @@ -19,15 +19,15 @@ namespace StardewModdingAPI.Events /// <summary>Raised after a game menu is opened or replaced with another menu. This event is not invoked when a menu is closed.</summary> public static event EventHandler<EventArgsClickableMenuChanged> MenuChanged { - add => MenuEvents.EventManager.Menu_Changed.Add(value); - remove => MenuEvents.EventManager.Menu_Changed.Remove(value); + add => MenuEvents.EventManager.Legacy_MenuChanged.Add(value); + remove => MenuEvents.EventManager.Legacy_MenuChanged.Remove(value); } /// <summary>Raised after a game menu is closed.</summary> public static event EventHandler<EventArgsClickableMenuClosed> MenuClosed { - add => MenuEvents.EventManager.Menu_Closed.Add(value); - remove => MenuEvents.EventManager.Menu_Closed.Remove(value); + add => MenuEvents.EventManager.Legacy_MenuClosed.Add(value); + remove => MenuEvents.EventManager.Legacy_MenuClosed.Remove(value); } diff --git a/src/SMAPI/Events/MineEvents.cs b/src/SMAPI/Events/MineEvents.cs index 5ee4001b..f5565a76 100644 --- a/src/SMAPI/Events/MineEvents.cs +++ b/src/SMAPI/Events/MineEvents.cs @@ -19,8 +19,8 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the player warps to a new level of the mine.</summary> public static event EventHandler<EventArgsMineLevelChanged> MineLevelChanged { - add => MineEvents.EventManager.Mine_LevelChanged.Add(value); - remove => MineEvents.EventManager.Mine_LevelChanged.Remove(value); + add => MineEvents.EventManager.Legacy_MineLevelChanged.Add(value); + remove => MineEvents.EventManager.Legacy_MineLevelChanged.Remove(value); } diff --git a/src/SMAPI/Events/ModMessageReceivedEventArgs.cs b/src/SMAPI/Events/ModMessageReceivedEventArgs.cs new file mode 100644 index 00000000..49366ec6 --- /dev/null +++ b/src/SMAPI/Events/ModMessageReceivedEventArgs.cs @@ -0,0 +1,46 @@ +using System; +using StardewModdingAPI.Framework.Networking; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IMultiplayerEvents.ModMessageReceived"/> event.</summary> + public class ModMessageReceivedEventArgs : EventArgs + { + /********* + ** Properties + *********/ + /// <summary>The underlying message model.</summary> + private readonly ModMessageModel Message; + + + /********* + ** Accessors + *********/ + /// <summary>The unique ID of the player from whose computer the message was sent.</summary> + public long FromPlayerID => this.Message.FromPlayerID; + + /// <summary>The unique ID of the mod which sent the message.</summary> + public string FromModID => this.Message.FromModID; + + /// <summary>A message type which can be used to decide whether it's the one you want to handle, like <c>SetPlayerLocation</c>. This doesn't need to be globally unique, so mods should check the <see cref="FromModID"/>.</summary> + public string Type => this.Message.Type; + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="message">The received message.</param> + internal ModMessageReceivedEventArgs(ModMessageModel message) + { + this.Message = message; + } + + /// <summary>Read the message data into the given model type.</summary> + /// <typeparam name="TModel">The message model type.</typeparam> + public TModel ReadAs<TModel>() + { + return this.Message.Data.ToObject<TModel>(); + } + } +} diff --git a/src/SMAPI/Events/InputMouseWheelScrolledEventArgs.cs b/src/SMAPI/Events/MouseWheelScrolledEventArgs.cs index 9afab9cc..3ab9d412 100644 --- a/src/SMAPI/Events/InputMouseWheelScrolledEventArgs.cs +++ b/src/SMAPI/Events/MouseWheelScrolledEventArgs.cs @@ -3,7 +3,7 @@ using System; namespace StardewModdingAPI.Events { /// <summary>Event arguments when the player scrolls the mouse wheel.</summary> - public class InputMouseWheelScrolledEventArgs : EventArgs + public class MouseWheelScrolledEventArgs : EventArgs { /********* ** Accessors @@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events /// <param name="position">The cursor position.</param> /// <param name="oldValue">The old scroll value.</param> /// <param name="newValue">The new scroll value.</param> - public InputMouseWheelScrolledEventArgs(ICursorPosition position, int oldValue, int newValue) + public MouseWheelScrolledEventArgs(ICursorPosition position, int oldValue, int newValue) { this.Position = position; this.OldValue = oldValue; diff --git a/src/SMAPI/Events/MultiplayerEvents.cs b/src/SMAPI/Events/MultiplayerEvents.cs index f96ecba5..49de380e 100644 --- a/src/SMAPI/Events/MultiplayerEvents.cs +++ b/src/SMAPI/Events/MultiplayerEvents.cs @@ -19,29 +19,29 @@ namespace StardewModdingAPI.Events /// <summary>Raised before the game syncs changes from other players.</summary> public static event EventHandler BeforeMainSync { - add => MultiplayerEvents.EventManager.Multiplayer_BeforeMainSync.Add(value); - remove => MultiplayerEvents.EventManager.Multiplayer_BeforeMainSync.Remove(value); + add => MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Add(value); + remove => MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Remove(value); } /// <summary>Raised after the game syncs changes from other players.</summary> public static event EventHandler AfterMainSync { - add => MultiplayerEvents.EventManager.Multiplayer_AfterMainSync.Add(value); - remove => MultiplayerEvents.EventManager.Multiplayer_AfterMainSync.Remove(value); + add => MultiplayerEvents.EventManager.Legacy_AfterMainSync.Add(value); + remove => MultiplayerEvents.EventManager.Legacy_AfterMainSync.Remove(value); } /// <summary>Raised before the game broadcasts changes to other players.</summary> public static event EventHandler BeforeMainBroadcast { - add => MultiplayerEvents.EventManager.Multiplayer_BeforeMainBroadcast.Add(value); - remove => MultiplayerEvents.EventManager.Multiplayer_BeforeMainBroadcast.Remove(value); + add => MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Add(value); + remove => MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Remove(value); } /// <summary>Raised after the game broadcasts changes to other players.</summary> public static event EventHandler AfterMainBroadcast { - add => MultiplayerEvents.EventManager.Multiplayer_AfterMainBroadcast.Add(value); - remove => MultiplayerEvents.EventManager.Multiplayer_AfterMainBroadcast.Remove(value); + add => MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Add(value); + remove => MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Remove(value); } diff --git a/src/SMAPI/Events/WorldNpcListChangedEventArgs.cs b/src/SMAPI/Events/NpcListChangedEventArgs.cs index e251f894..eca28244 100644 --- a/src/SMAPI/Events/WorldNpcListChangedEventArgs.cs +++ b/src/SMAPI/Events/NpcListChangedEventArgs.cs @@ -6,7 +6,7 @@ using StardewValley; namespace StardewModdingAPI.Events { /// <summary>Event arguments for a <see cref="IWorldEvents.NpcListChanged"/> event.</summary> - public class WorldNpcListChangedEventArgs : EventArgs + public class NpcListChangedEventArgs : EventArgs { /********* ** Accessors @@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The NPCs added to the location.</param> /// <param name="removed">The NPCs removed from the location.</param> - public WorldNpcListChangedEventArgs(GameLocation location, IEnumerable<NPC> added, IEnumerable<NPC> removed) + public NpcListChangedEventArgs(GameLocation location, IEnumerable<NPC> added, IEnumerable<NPC> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/WorldObjectListChangedEventArgs.cs b/src/SMAPI/Events/ObjectListChangedEventArgs.cs index 5623a49b..55a4034f 100644 --- a/src/SMAPI/Events/WorldObjectListChangedEventArgs.cs +++ b/src/SMAPI/Events/ObjectListChangedEventArgs.cs @@ -8,7 +8,7 @@ using Object = StardewValley.Object; namespace StardewModdingAPI.Events { /// <summary>Event arguments for a <see cref="IWorldEvents.ObjectListChanged"/> event.</summary> - public class WorldObjectListChangedEventArgs : EventArgs + public class ObjectListChangedEventArgs : EventArgs { /********* ** Accessors @@ -30,7 +30,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The objects added to the location.</param> /// <param name="removed">The objects removed from the location.</param> - public WorldObjectListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, Object>> added, IEnumerable<KeyValuePair<Vector2, Object>> removed) + public ObjectListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, Object>> added, IEnumerable<KeyValuePair<Vector2, Object>> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/PeerContextReceivedEventArgs.cs b/src/SMAPI/Events/PeerContextReceivedEventArgs.cs new file mode 100644 index 00000000..151a295c --- /dev/null +++ b/src/SMAPI/Events/PeerContextReceivedEventArgs.cs @@ -0,0 +1,25 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IMultiplayerEvents.PeerContextReceived"/> event.</summary> + public class PeerContextReceivedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The peer whose metadata was received.</summary> + public IMultiplayerPeer Peer { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="peer">The peer whose metadata was received.</param> + internal PeerContextReceivedEventArgs(IMultiplayerPeer peer) + { + this.Peer = peer; + } + } +} diff --git a/src/SMAPI/Events/PeerDisconnectedEventArgs.cs b/src/SMAPI/Events/PeerDisconnectedEventArgs.cs new file mode 100644 index 00000000..8517988a --- /dev/null +++ b/src/SMAPI/Events/PeerDisconnectedEventArgs.cs @@ -0,0 +1,25 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IMultiplayerEvents.PeerDisconnected"/> event.</summary> + public class PeerDisconnectedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The peer who disconnected.</summary> + public IMultiplayerPeer Peer { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="peer">The peer who disconnected.</param> + internal PeerDisconnectedEventArgs(IMultiplayerPeer peer) + { + this.Peer = peer; + } + } +} diff --git a/src/SMAPI/Events/PlayerEvents.cs b/src/SMAPI/Events/PlayerEvents.cs index 6e7050e3..bfc1b569 100644 --- a/src/SMAPI/Events/PlayerEvents.cs +++ b/src/SMAPI/Events/PlayerEvents.cs @@ -19,22 +19,22 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the player's inventory changes in any way (added or removed item, sorted, etc).</summary> public static event EventHandler<EventArgsInventoryChanged> InventoryChanged { - add => PlayerEvents.EventManager.Player_InventoryChanged.Add(value); - remove => PlayerEvents.EventManager.Player_InventoryChanged.Remove(value); + add => PlayerEvents.EventManager.Legacy_InventoryChanged.Add(value); + remove => PlayerEvents.EventManager.Legacy_InventoryChanged.Remove(value); } /// <summary>Raised after the player levels up a skill. This happens as soon as they level up, not when the game notifies the player after their character goes to bed.</summary> public static event EventHandler<EventArgsLevelUp> LeveledUp { - add => PlayerEvents.EventManager.Player_LeveledUp.Add(value); - remove => PlayerEvents.EventManager.Player_LeveledUp.Remove(value); + add => PlayerEvents.EventManager.Legacy_LeveledUp.Add(value); + remove => PlayerEvents.EventManager.Legacy_LeveledUp.Remove(value); } /// <summary>Raised after the player warps to a new location.</summary> public static event EventHandler<EventArgsPlayerWarped> Warped { - add => PlayerEvents.EventManager.Player_Warped.Add(value); - remove => PlayerEvents.EventManager.Player_Warped.Remove(value); + add => PlayerEvents.EventManager.Legacy_PlayerWarped.Add(value); + remove => PlayerEvents.EventManager.Legacy_PlayerWarped.Remove(value); } diff --git a/src/SMAPI/Events/RenderedActiveMenuEventArgs.cs b/src/SMAPI/Events/RenderedActiveMenuEventArgs.cs new file mode 100644 index 00000000..efd4163b --- /dev/null +++ b/src/SMAPI/Events/RenderedActiveMenuEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.RenderedActiveMenu"/> event.</summary> + public class RenderedActiveMenuEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.</summary> + public SpriteBatch SpriteBatch => Game1.spriteBatch; + } +} diff --git a/src/SMAPI/Events/RenderedEventArgs.cs b/src/SMAPI/Events/RenderedEventArgs.cs new file mode 100644 index 00000000..d6341b19 --- /dev/null +++ b/src/SMAPI/Events/RenderedEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.Rendered"/> event.</summary> + public class RenderedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.</summary> + public SpriteBatch SpriteBatch => Game1.spriteBatch; + } +} diff --git a/src/SMAPI/Events/RenderedHudEventArgs.cs b/src/SMAPI/Events/RenderedHudEventArgs.cs new file mode 100644 index 00000000..46e89013 --- /dev/null +++ b/src/SMAPI/Events/RenderedHudEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.RenderedHud"/> event.</summary> + public class RenderedHudEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.</summary> + public SpriteBatch SpriteBatch => Game1.spriteBatch; + } +} diff --git a/src/SMAPI/Events/RenderedWorldEventArgs.cs b/src/SMAPI/Events/RenderedWorldEventArgs.cs new file mode 100644 index 00000000..56145381 --- /dev/null +++ b/src/SMAPI/Events/RenderedWorldEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.RenderedWorld"/> event.</summary> + public class RenderedWorldEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.</summary> + public SpriteBatch SpriteBatch => Game1.spriteBatch; + } +} diff --git a/src/SMAPI/Events/RenderingActiveMenuEventArgs.cs b/src/SMAPI/Events/RenderingActiveMenuEventArgs.cs new file mode 100644 index 00000000..103f56df --- /dev/null +++ b/src/SMAPI/Events/RenderingActiveMenuEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.RenderingActiveMenu"/> event.</summary> + public class RenderingActiveMenuEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.</summary> + public SpriteBatch SpriteBatch => Game1.spriteBatch; + } +} diff --git a/src/SMAPI/Events/RenderingEventArgs.cs b/src/SMAPI/Events/RenderingEventArgs.cs new file mode 100644 index 00000000..5acbef09 --- /dev/null +++ b/src/SMAPI/Events/RenderingEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.Rendering"/> event.</summary> + public class RenderingEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.</summary> + public SpriteBatch SpriteBatch => Game1.spriteBatch; + } +} diff --git a/src/SMAPI/Events/RenderingHudEventArgs.cs b/src/SMAPI/Events/RenderingHudEventArgs.cs new file mode 100644 index 00000000..84c96ecd --- /dev/null +++ b/src/SMAPI/Events/RenderingHudEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.RenderingHud"/> event.</summary> + public class RenderingHudEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.</summary> + public SpriteBatch SpriteBatch => Game1.spriteBatch; + } +} diff --git a/src/SMAPI/Events/RenderingWorldEventArgs.cs b/src/SMAPI/Events/RenderingWorldEventArgs.cs new file mode 100644 index 00000000..d0d44789 --- /dev/null +++ b/src/SMAPI/Events/RenderingWorldEventArgs.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.RenderingWorld"/> event.</summary> + public class RenderingWorldEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.</summary> + public SpriteBatch SpriteBatch => Game1.spriteBatch; + } +} diff --git a/src/SMAPI/Events/ReturnedToTitleEventArgs.cs b/src/SMAPI/Events/ReturnedToTitleEventArgs.cs new file mode 100644 index 00000000..96309cde --- /dev/null +++ b/src/SMAPI/Events/ReturnedToTitleEventArgs.cs @@ -0,0 +1,7 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.ReturnedToTitle"/> event.</summary> + public class ReturnedToTitleEventArgs : EventArgs { } +} diff --git a/src/SMAPI/Events/SaveCreatedEventArgs.cs b/src/SMAPI/Events/SaveCreatedEventArgs.cs new file mode 100644 index 00000000..5ae22531 --- /dev/null +++ b/src/SMAPI/Events/SaveCreatedEventArgs.cs @@ -0,0 +1,7 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.SaveCreated"/> event.</summary> + public class SaveCreatedEventArgs : EventArgs { } +} diff --git a/src/SMAPI/Events/SaveCreatingEventArgs.cs b/src/SMAPI/Events/SaveCreatingEventArgs.cs new file mode 100644 index 00000000..3c83f421 --- /dev/null +++ b/src/SMAPI/Events/SaveCreatingEventArgs.cs @@ -0,0 +1,7 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.SaveCreating"/> event.</summary> + public class SaveCreatingEventArgs : EventArgs { } +} diff --git a/src/SMAPI/Events/SaveEvents.cs b/src/SMAPI/Events/SaveEvents.cs index 62184282..731bf9d1 100644 --- a/src/SMAPI/Events/SaveEvents.cs +++ b/src/SMAPI/Events/SaveEvents.cs @@ -19,43 +19,43 @@ namespace StardewModdingAPI.Events /// <summary>Raised before the game creates the save file.</summary> public static event EventHandler BeforeCreate { - add => SaveEvents.EventManager.Save_BeforeCreate.Add(value); - remove => SaveEvents.EventManager.Save_BeforeCreate.Remove(value); + add => SaveEvents.EventManager.Legacy_BeforeCreateSave.Add(value); + remove => SaveEvents.EventManager.Legacy_BeforeCreateSave.Remove(value); } /// <summary>Raised after the game finishes creating the save file.</summary> public static event EventHandler AfterCreate { - add => SaveEvents.EventManager.Save_AfterCreate.Add(value); - remove => SaveEvents.EventManager.Save_AfterCreate.Remove(value); + add => SaveEvents.EventManager.Legacy_AfterCreateSave.Add(value); + remove => SaveEvents.EventManager.Legacy_AfterCreateSave.Remove(value); } /// <summary>Raised before the game begins writes data to the save file.</summary> public static event EventHandler BeforeSave { - add => SaveEvents.EventManager.Save_BeforeSave.Add(value); - remove => SaveEvents.EventManager.Save_BeforeSave.Remove(value); + add => SaveEvents.EventManager.Legacy_BeforeSave.Add(value); + remove => SaveEvents.EventManager.Legacy_BeforeSave.Remove(value); } /// <summary>Raised after the game finishes writing data to the save file.</summary> public static event EventHandler AfterSave { - add => SaveEvents.EventManager.Save_AfterSave.Add(value); - remove => SaveEvents.EventManager.Save_AfterSave.Remove(value); + add => SaveEvents.EventManager.Legacy_AfterSave.Add(value); + remove => SaveEvents.EventManager.Legacy_AfterSave.Remove(value); } /// <summary>Raised after the player loads a save slot.</summary> public static event EventHandler AfterLoad { - add => SaveEvents.EventManager.Save_AfterLoad.Add(value); - remove => SaveEvents.EventManager.Save_AfterLoad.Remove(value); + add => SaveEvents.EventManager.Legacy_AfterLoad.Add(value); + remove => SaveEvents.EventManager.Legacy_AfterLoad.Remove(value); } /// <summary>Raised after the game returns to the title screen.</summary> public static event EventHandler AfterReturnToTitle { - add => SaveEvents.EventManager.Save_AfterReturnToTitle.Add(value); - remove => SaveEvents.EventManager.Save_AfterReturnToTitle.Remove(value); + add => SaveEvents.EventManager.Legacy_AfterReturnToTitle.Add(value); + remove => SaveEvents.EventManager.Legacy_AfterReturnToTitle.Remove(value); } diff --git a/src/SMAPI/Events/SaveLoadedEventArgs.cs b/src/SMAPI/Events/SaveLoadedEventArgs.cs new file mode 100644 index 00000000..f8aaa7f7 --- /dev/null +++ b/src/SMAPI/Events/SaveLoadedEventArgs.cs @@ -0,0 +1,7 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.SaveLoaded"/> event.</summary> + public class SaveLoadedEventArgs : EventArgs { } +} diff --git a/src/SMAPI/Events/SavedEventArgs.cs b/src/SMAPI/Events/SavedEventArgs.cs new file mode 100644 index 00000000..a4e90729 --- /dev/null +++ b/src/SMAPI/Events/SavedEventArgs.cs @@ -0,0 +1,7 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.Saved"/> event.</summary> + public class SavedEventArgs : EventArgs { } +} diff --git a/src/SMAPI/Events/SavingEventArgs.cs b/src/SMAPI/Events/SavingEventArgs.cs new file mode 100644 index 00000000..f323ca9e --- /dev/null +++ b/src/SMAPI/Events/SavingEventArgs.cs @@ -0,0 +1,7 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.Saving"/> event.</summary> + public class SavingEventArgs : EventArgs { } +} diff --git a/src/SMAPI/Events/SpecialisedEvents.cs b/src/SMAPI/Events/SpecialisedEvents.cs index 33ebf3b2..bdf25ccb 100644 --- a/src/SMAPI/Events/SpecialisedEvents.cs +++ b/src/SMAPI/Events/SpecialisedEvents.cs @@ -3,7 +3,7 @@ using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { - /// <summary>Events serving specialised edge cases that shouldn't be used by most mod.</summary> + /// <summary>Events serving specialised edge cases that shouldn't be used by most mods.</summary> public static class SpecialisedEvents { /********* @@ -19,8 +19,8 @@ namespace StardewModdingAPI.Events /// <summary>Raised when the game updates its state (≈60 times per second), regardless of normal SMAPI validation. This event is not thread-safe and may be invoked while game logic is running asynchronously. Changes to game state in this method may crash the game or corrupt an in-progress save. Do not use this event unless you're fully aware of the context in which your code will be run. Mods using this method will trigger a stability warning in the SMAPI console.</summary> public static event EventHandler UnvalidatedUpdateTick { - add => SpecialisedEvents.EventManager.Specialised_UnvalidatedUpdateTick.Add(value); - remove => SpecialisedEvents.EventManager.Specialised_UnvalidatedUpdateTick.Remove(value); + add => SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Add(value); + remove => SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Remove(value); } diff --git a/src/SMAPI/Events/WorldTerrainFeatureListChangedEventArgs.cs b/src/SMAPI/Events/TerrainFeatureListChangedEventArgs.cs index cb089811..562b1d3c 100644 --- a/src/SMAPI/Events/WorldTerrainFeatureListChangedEventArgs.cs +++ b/src/SMAPI/Events/TerrainFeatureListChangedEventArgs.cs @@ -8,7 +8,7 @@ using StardewValley.TerrainFeatures; namespace StardewModdingAPI.Events { /// <summary>Event arguments for a <see cref="IWorldEvents.TerrainFeatureListChanged"/> event.</summary> - public class WorldTerrainFeatureListChangedEventArgs : EventArgs + public class TerrainFeatureListChangedEventArgs : EventArgs { /********* ** Accessors @@ -30,7 +30,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The terrain features added to the location.</param> /// <param name="removed">The terrain features removed from the location.</param> - public WorldTerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> added, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> removed) + public TerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> added, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/TimeChangedEventArgs.cs b/src/SMAPI/Events/TimeChangedEventArgs.cs new file mode 100644 index 00000000..fd472092 --- /dev/null +++ b/src/SMAPI/Events/TimeChangedEventArgs.cs @@ -0,0 +1,30 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.TimeChanged"/> event.</summary> + public class TimeChangedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The previous time of day in 24-hour notation (like 1600 for 4pm). The clock time resets when the player sleeps, so 2am (before sleeping) is 2600.</summary> + public int OldTime { get; } + + /// <summary>The current time of day in 24-hour notation (like 1600 for 4pm). The clock time resets when the player sleeps, so 2am (before sleeping) is 2600.</summary> + public int NewTime { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="oldTime">The previous time of day in 24-hour notation (like 1600 for 4pm).</param> + /// <param name="newTime">The current time of day in 24-hour notation (like 1600 for 4pm).</param> + public TimeChangedEventArgs(int oldTime, int newTime) + { + this.OldTime = oldTime; + this.NewTime = newTime; + } + } +} diff --git a/src/SMAPI/Events/TimeEvents.cs b/src/SMAPI/Events/TimeEvents.cs index f769fd08..311ffe9e 100644 --- a/src/SMAPI/Events/TimeEvents.cs +++ b/src/SMAPI/Events/TimeEvents.cs @@ -19,15 +19,15 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the game begins a new day, including when loading a save.</summary> public static event EventHandler AfterDayStarted { - add => TimeEvents.EventManager.Time_AfterDayStarted.Add(value); - remove => TimeEvents.EventManager.Time_AfterDayStarted.Remove(value); + add => TimeEvents.EventManager.Legacy_AfterDayStarted.Add(value); + remove => TimeEvents.EventManager.Legacy_AfterDayStarted.Remove(value); } /// <summary>Raised after the in-game clock changes.</summary> public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged { - add => TimeEvents.EventManager.Time_TimeOfDayChanged.Add(value); - remove => TimeEvents.EventManager.Time_TimeOfDayChanged.Remove(value); + add => TimeEvents.EventManager.Legacy_TimeOfDayChanged.Add(value); + remove => TimeEvents.EventManager.Legacy_TimeOfDayChanged.Remove(value); } diff --git a/src/SMAPI/Events/UnvalidatedUpdateTickedEventArgs.cs b/src/SMAPI/Events/UnvalidatedUpdateTickedEventArgs.cs new file mode 100644 index 00000000..5638bdb7 --- /dev/null +++ b/src/SMAPI/Events/UnvalidatedUpdateTickedEventArgs.cs @@ -0,0 +1,36 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="ISpecialisedEvents.UnvalidatedUpdateTicked"/> event.</summary> + public class UnvalidatedUpdateTickedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The number of ticks elapsed since the game started, including the current tick.</summary> + public uint Ticks { get; } + + /// <summary>Whether <see cref="Ticks"/> is a multiple of 60, which happens approximately once per second.</summary> + public bool IsOneSecond { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param> + public UnvalidatedUpdateTickedEventArgs(uint ticks) + { + this.Ticks = ticks; + this.IsOneSecond = this.IsMultipleOf(60); + } + + /// <summary>Get whether <see cref="Ticks"/> is a multiple of the given <paramref name="number"/>. This is mainly useful if you want to run logic intermittently (e.g. <code>e.IsMultipleOf(30)</code> for every half-second).</summary> + /// <param name="number">The factor to check.</param> + public bool IsMultipleOf(uint number) + { + return this.Ticks % number == 0; + } + } +} diff --git a/src/SMAPI/Events/UnvalidatedUpdateTickingEventArgs.cs b/src/SMAPI/Events/UnvalidatedUpdateTickingEventArgs.cs new file mode 100644 index 00000000..ebadbb99 --- /dev/null +++ b/src/SMAPI/Events/UnvalidatedUpdateTickingEventArgs.cs @@ -0,0 +1,36 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="ISpecialisedEvents.UnvalidatedUpdateTicking"/> event.</summary> + public class UnvalidatedUpdateTickingEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The number of ticks elapsed since the game started, including the current tick.</summary> + public uint Ticks { get; } + + /// <summary>Whether <see cref="Ticks"/> is a multiple of 60, which happens approximately once per second.</summary> + public bool IsOneSecond { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param> + public UnvalidatedUpdateTickingEventArgs(uint ticks) + { + this.Ticks = ticks; + this.IsOneSecond = this.IsMultipleOf(60); + } + + /// <summary>Get whether <see cref="Ticks"/> is a multiple of the given <paramref name="number"/>. This is mainly useful if you want to run logic intermittently (e.g. <code>e.IsMultipleOf(30)</code> for every half-second).</summary> + /// <param name="number">The factor to check.</param> + public bool IsMultipleOf(uint number) + { + return this.Ticks % number == 0; + } + } +} diff --git a/src/SMAPI/Events/GameLoopUpdatedEventArgs.cs b/src/SMAPI/Events/UpdateTickedEventArgs.cs index 3ad34b69..56912643 100644 --- a/src/SMAPI/Events/GameLoopUpdatedEventArgs.cs +++ b/src/SMAPI/Events/UpdateTickedEventArgs.cs @@ -2,8 +2,8 @@ using System; namespace StardewModdingAPI.Events { - /// <summary>Event arguments for an <see cref="IGameLoopEvents.Updated"/> event.</summary> - public class GameLoopUpdatedEventArgs : EventArgs + /// <summary>Event arguments for an <see cref="IGameLoopEvents.UpdateTicked"/> event.</summary> + public class UpdateTickedEventArgs : EventArgs { /********* ** Accessors @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Construct an instance.</summary> /// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param> - public GameLoopUpdatedEventArgs(uint ticks) + public UpdateTickedEventArgs(uint ticks) { this.Ticks = ticks; this.IsOneSecond = this.IsMultipleOf(60); diff --git a/src/SMAPI/Events/GameLoopUpdatingEventArgs.cs b/src/SMAPI/Events/UpdateTickingEventArgs.cs index d6a8b5c2..5998fd9b 100644 --- a/src/SMAPI/Events/GameLoopUpdatingEventArgs.cs +++ b/src/SMAPI/Events/UpdateTickingEventArgs.cs @@ -2,8 +2,8 @@ using System; namespace StardewModdingAPI.Events { - /// <summary>Event arguments for an <see cref="IGameLoopEvents.Updating"/> event.</summary> - public class GameLoopUpdatingEventArgs : EventArgs + /// <summary>Event arguments for an <see cref="IGameLoopEvents.UpdateTicking"/> event.</summary> + public class UpdateTickingEventArgs : EventArgs { /********* ** Accessors @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Construct an instance.</summary> /// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param> - public GameLoopUpdatingEventArgs(uint ticks) + public UpdateTickingEventArgs(uint ticks) { this.Ticks = ticks; this.IsOneSecond = this.IsMultipleOf(60); diff --git a/src/SMAPI/Events/WarpedEventArgs.cs b/src/SMAPI/Events/WarpedEventArgs.cs new file mode 100644 index 00000000..1b1c7381 --- /dev/null +++ b/src/SMAPI/Events/WarpedEventArgs.cs @@ -0,0 +1,37 @@ +using System; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IPlayerEvents.Warped"/> event.</summary> + public class WarpedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The player who warped to a new location.</summary> + public Farmer Player { get; } + + /// <summary>The player's previous location.</summary> + public GameLocation OldLocation { get; } + + /// <summary>The player's current location.</summary> + public GameLocation NewLocation { get; } + + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="player">The player who warped to a new location.</param> + /// <param name="oldLocation">The player's previous location.</param> + /// <param name="newLocation">The player's current location.</param> + public WarpedEventArgs(Farmer player, GameLocation oldLocation, GameLocation newLocation) + { + this.Player = player; + this.NewLocation = newLocation; + this.OldLocation = oldLocation; + } + } +} diff --git a/src/SMAPI/Events/WindowResizedEventArgs.cs b/src/SMAPI/Events/WindowResizedEventArgs.cs new file mode 100644 index 00000000..a990ba9d --- /dev/null +++ b/src/SMAPI/Events/WindowResizedEventArgs.cs @@ -0,0 +1,31 @@ +using System; +using Microsoft.Xna.Framework; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IDisplayEvents.WindowResized"/> event.</summary> + public class WindowResizedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The previous window size.</summary> + public Point OldSize { get; } + + /// <summary>The current window size.</summary> + public Point NewSize { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="oldSize">The previous window size.</param> + /// <param name="newSize">The current window size.</param> + public WindowResizedEventArgs(Point oldSize, Point newSize) + { + this.OldSize = oldSize; + this.NewSize = newSize; + } + } +} |