summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-10-08 18:57:09 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-10-08 18:57:09 -0400
commitec6025aad35addab8121a31d1c4abf667fd5210a (patch)
tree5f7ea2836180adc1f26e05110f8f28ab18b61e8e /src/SMAPI
parent79705448f57c962e9331fb802097c24d2424476c (diff)
downloadSMAPI-ec6025aad35addab8121a31d1c4abf667fd5210a.tar.gz
SMAPI-ec6025aad35addab8121a31d1c4abf667fd5210a.tar.bz2
SMAPI-ec6025aad35addab8121a31d1c4abf667fd5210a.zip
add more events (#310)
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Enums/SkillType.cs26
-rw-r--r--src/SMAPI/Events/EventArgsInventoryChanged.cs2
-rw-r--r--src/SMAPI/Events/EventArgsLevelUp.cs13
-rw-r--r--src/SMAPI/Events/IDisplayEvents.cs39
-rw-r--r--src/SMAPI/Events/IGameLoopEvents.cs6
-rw-r--r--src/SMAPI/Events/IModEvents.cs9
-rw-r--r--src/SMAPI/Events/IPlayerEvents.cs17
-rw-r--r--src/SMAPI/Events/ISpecialisedEvents.cs14
-rw-r--r--src/SMAPI/Events/InventoryChangedEventArgs.cs56
-rw-r--r--src/SMAPI/Events/ItemStackSizeChange.cs35
-rw-r--r--src/SMAPI/Events/LevelChangedEventArgs.cs42
-rw-r--r--src/SMAPI/Events/MenuChangedEventArgs.cs31
-rw-r--r--src/SMAPI/Events/RenderedActiveMenuEventArgs.cs16
-rw-r--r--src/SMAPI/Events/RenderedEventArgs.cs16
-rw-r--r--src/SMAPI/Events/RenderedHudEventArgs.cs16
-rw-r--r--src/SMAPI/Events/RenderedWorldEventArgs.cs16
-rw-r--r--src/SMAPI/Events/RenderingActiveMenuEventArgs.cs16
-rw-r--r--src/SMAPI/Events/RenderingEventArgs.cs16
-rw-r--r--src/SMAPI/Events/RenderingHudEventArgs.cs16
-rw-r--r--src/SMAPI/Events/RenderingWorldEventArgs.cs16
-rw-r--r--src/SMAPI/Events/ReturnedToTitleEventArgs.cs7
-rw-r--r--src/SMAPI/Events/SpecialisedEvents.cs2
-rw-r--r--src/SMAPI/Events/TimeChangedEventArgs.cs30
-rw-r--r--src/SMAPI/Events/UnvalidatedUpdateTickedEventArgs.cs36
-rw-r--r--src/SMAPI/Events/UnvalidatedUpdateTickingEventArgs.cs36
-rw-r--r--src/SMAPI/Events/WarpedEventArgs.cs37
-rw-r--r--src/SMAPI/Events/WindowResizedEventArgs.cs31
-rw-r--r--src/SMAPI/Framework/Events/EventManager.cs80
-rw-r--r--src/SMAPI/Framework/Events/ModDisplayEvents.cs93
-rw-r--r--src/SMAPI/Framework/Events/ModEvents.cs12
-rw-r--r--src/SMAPI/Framework/Events/ModGameLoopEvents.cs15
-rw-r--r--src/SMAPI/Framework/Events/ModPlayerEvents.cs43
-rw-r--r--src/SMAPI/Framework/Events/ModSpecialisedEvents.cs36
-rw-r--r--src/SMAPI/Framework/InternalExtensions.cs4
-rw-r--r--src/SMAPI/Framework/SGame.cs81
-rw-r--r--src/SMAPI/Framework/StateTracking/PlayerTracker.cs19
-rw-r--r--src/SMAPI/StardewModdingAPI.csproj128
37 files changed, 1024 insertions, 84 deletions
diff --git a/src/SMAPI/Enums/SkillType.cs b/src/SMAPI/Enums/SkillType.cs
new file mode 100644
index 00000000..10518ec9
--- /dev/null
+++ b/src/SMAPI/Enums/SkillType.cs
@@ -0,0 +1,26 @@
+using StardewValley;
+
+namespace StardewModdingAPI.Enums
+{
+ /// <summary>The player skill types.</summary>
+ public enum SkillType
+ {
+ /// <summary>The combat skill.</summary>
+ Combat = Farmer.combatSkill,
+
+ /// <summary>The farming skill.</summary>
+ Farming = Farmer.farmingSkill,
+
+ /// <summary>The fishing skill.</summary>
+ Fishing = Farmer.fishingSkill,
+
+ /// <summary>The foraging skill.</summary>
+ Foraging = Farmer.foragingSkill,
+
+ /// <summary>The mining skill.</summary>
+ Mining = Farmer.miningSkill,
+
+ /// <summary>The luck skill.</summary>
+ Luck = Farmer.luckSkill
+ }
+}
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/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 5f531ba7..e1900f79 100644
--- a/src/SMAPI/Events/IGameLoopEvents.cs
+++ b/src/SMAPI/Events/IGameLoopEvents.cs
@@ -34,5 +34,11 @@ namespace StardewModdingAPI.Events
/// <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/IModEvents.cs b/src/SMAPI/Events/IModEvents.cs
index cf2f8cb8..76da7751 100644
--- a/src/SMAPI/Events/IModEvents.cs
+++ b/src/SMAPI/Events/IModEvents.cs
@@ -3,13 +3,22 @@ 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 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/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/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/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/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/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/SpecialisedEvents.cs b/src/SMAPI/Events/SpecialisedEvents.cs
index af84b397..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
{
/*********
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/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/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;
+ }
+ }
+}
diff --git a/src/SMAPI/Framework/Events/EventManager.cs b/src/SMAPI/Framework/Events/EventManager.cs
index 616db7d9..31b0346a 100644
--- a/src/SMAPI/Framework/Events/EventManager.cs
+++ b/src/SMAPI/Framework/Events/EventManager.cs
@@ -12,6 +12,39 @@ namespace StardewModdingAPI.Framework.Events
** Events (new)
*********/
/****
+ ** Display
+ ****/
+ /// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
+ public readonly ManagedEvent<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>
+ public readonly ManagedEvent<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>
+ public readonly ManagedEvent<RenderedEventArgs> Rendered;
+
+ /// <summary>Raised before the game world is drawn to the screen.</summary>
+ public readonly ManagedEvent<RenderingWorldEventArgs> RenderingWorld;
+
+ /// <summary>Raised after the game world is drawn to the sprite patch, before it's rendered to the screen.</summary>
+ public readonly ManagedEvent<RenderedWorldEventArgs> RenderedWorld;
+
+ /// <summary>When a menu is open (<see cref="StardewValley.Game1.activeClickableMenu"/> isn't null), raised before that menu is drawn to the screen.</summary>
+ public readonly ManagedEvent<RenderingActiveMenuEventArgs> RenderingActiveMenu;
+
+ /// <summary>When a menu is open (<see cref="StardewValley.Game1.activeClickableMenu"/> isn't null), raised after that menu is drawn to the sprite batch but before it's rendered to the screen.</summary>
+ public readonly ManagedEvent<RenderedActiveMenuEventArgs> RenderedActiveMenu;
+
+ /// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen.</summary>
+ public readonly ManagedEvent<RenderingHudEventArgs> RenderingHud;
+
+ /// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the sprite batch, but before it's rendered to the screen.</summary>
+ public readonly ManagedEvent<RenderedHudEventArgs> RenderedHud;
+
+ /// <summary>Raised after the game window is resized.</summary>
+ public readonly ManagedEvent<WindowResizedEventArgs> WindowResized;
+
+ /****
** Game loop
****/
/// <summary>Raised after the game is launched, right before the first update tick.</summary>
@@ -44,6 +77,12 @@ namespace StardewModdingAPI.Framework.Events
/// <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;
+ /// <summary>Raised after the in-game clock time changes.</summary>
+ public readonly ManagedEvent<TimeChangedEventArgs> TimeChanged;
+
+ /// <summary>Raised after the game returns to the title screen.</summary>
+ public readonly ManagedEvent<ReturnedToTitleEventArgs> ReturnedToTitle;
+
/****
** Input
****/
@@ -60,6 +99,18 @@ namespace StardewModdingAPI.Framework.Events
public readonly ManagedEvent<MouseWheelScrolledEventArgs> MouseWheelScrolled;
/****
+ ** Player
+ ****/
+ /// <summary>Raised after items are added or removed to a player's inventory.</summary>
+ public readonly ManagedEvent<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.</summary>
+ public readonly ManagedEvent<LevelChangedEventArgs> LevelChanged;
+
+ /// <summary>Raised after a player warps to a new location.</summary>
+ public readonly ManagedEvent<WarpedEventArgs> Warped;
+
+ /****
** World
****/
/// <summary>Raised after a game location is added or removed.</summary>
@@ -83,6 +134,15 @@ namespace StardewModdingAPI.Framework.Events
/// <summary>Raised after terrain features (like floors and trees) are added or removed in a location.</summary>
public readonly ManagedEvent<TerrainFeatureListChangedEventArgs> TerrainFeatureListChanged;
+ /****
+ ** Specialised
+ ****/
+ /// <summary>Raised before the game performs its overall update tick (≈60 times per second). See notes on <see cref="ISpecialisedEvents.UnvalidatedUpdateTicking"/>.</summary>
+ public readonly ManagedEvent<UnvalidatedUpdateTickingEventArgs> UnvalidatedUpdateTicking;
+
+ /// <summary>Raised after the game performs its overall update tick (≈60 times per second). See notes on <see cref="ISpecialisedEvents.UnvalidatedUpdateTicked"/>.</summary>
+ public readonly ManagedEvent<UnvalidatedUpdateTickedEventArgs> UnvalidatedUpdateTicked;
+
/*********
** Events (old)
@@ -285,6 +345,17 @@ namespace StardewModdingAPI.Framework.Events
ManagedEvent ManageEvent(string typeName, string eventName) => new ManagedEvent($"{typeName}.{eventName}", monitor, modRegistry);
// init events (new)
+ this.MenuChanged = ManageEventOf<MenuChangedEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.MenuChanged));
+ this.Rendering = ManageEventOf<RenderingEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.Rendering));
+ this.Rendered = ManageEventOf<RenderedEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.Rendered));
+ this.RenderingWorld = ManageEventOf<RenderingWorldEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.RenderingWorld));
+ this.RenderedWorld = ManageEventOf<RenderedWorldEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.RenderedWorld));
+ this.RenderingActiveMenu = ManageEventOf<RenderingActiveMenuEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.RenderingActiveMenu));
+ this.RenderedActiveMenu = ManageEventOf<RenderedActiveMenuEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.RenderedActiveMenu));
+ this.RenderingHud = ManageEventOf<RenderingHudEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.RenderingHud));
+ this.RenderedHud = ManageEventOf<RenderedHudEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.RenderedHud));
+ this.WindowResized = ManageEventOf<WindowResizedEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.WindowResized));
+
this.GameLaunched = ManageEventOf<GameLaunchedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.GameLaunched));
this.UpdateTicking = ManageEventOf<UpdateTickingEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.UpdateTicking));
this.UpdateTicked = ManageEventOf<UpdateTickedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.UpdateTicked));
@@ -295,12 +366,18 @@ namespace StardewModdingAPI.Framework.Events
this.SaveLoaded = ManageEventOf<SaveLoadedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.SaveLoaded));
this.DayStarted = ManageEventOf<DayStartedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.DayStarted));
this.DayEnding = ManageEventOf<DayEndingEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.DayEnding));
+ this.TimeChanged = ManageEventOf<TimeChangedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.TimeChanged));
+ this.ReturnedToTitle = ManageEventOf<ReturnedToTitleEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.ReturnedToTitle));
this.ButtonPressed = ManageEventOf<ButtonPressedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonPressed));
this.ButtonReleased = ManageEventOf<ButtonReleasedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonReleased));
this.CursorMoved = ManageEventOf<CursorMovedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.CursorMoved));
this.MouseWheelScrolled = ManageEventOf<MouseWheelScrolledEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.MouseWheelScrolled));
+ this.InventoryChanged = ManageEventOf<InventoryChangedEventArgs>(nameof(IModEvents.Player), nameof(IPlayerEvents.InventoryChanged));
+ this.LevelChanged = ManageEventOf<LevelChangedEventArgs>(nameof(IModEvents.Player), nameof(IPlayerEvents.LevelChanged));
+ this.Warped = ManageEventOf<WarpedEventArgs>(nameof(IModEvents.Player), nameof(IPlayerEvents.Warped));
+
this.BuildingListChanged = ManageEventOf<BuildingListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.LocationListChanged));
this.DebrisListChanged = ManageEventOf<DebrisListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.DebrisListChanged));
this.LargeTerrainFeatureListChanged = ManageEventOf<LargeTerrainFeatureListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.LargeTerrainFeatureListChanged));
@@ -309,6 +386,9 @@ namespace StardewModdingAPI.Framework.Events
this.ObjectListChanged = ManageEventOf<ObjectListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.ObjectListChanged));
this.TerrainFeatureListChanged = ManageEventOf<TerrainFeatureListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.TerrainFeatureListChanged));
+ this.UnvalidatedUpdateTicking = ManageEventOf<UnvalidatedUpdateTickingEventArgs>(nameof(IModEvents.Specialised), nameof(ISpecialisedEvents.UnvalidatedUpdateTicking));
+ this.UnvalidatedUpdateTicked = ManageEventOf<UnvalidatedUpdateTickedEventArgs>(nameof(IModEvents.Specialised), nameof(ISpecialisedEvents.UnvalidatedUpdateTicked));
+
// init events (old)
this.Legacy_LocaleChanged = ManageEventOf<EventArgsValueChanged<string>>(nameof(ContentEvents), nameof(ContentEvents.AfterLocaleChanged));
diff --git a/src/SMAPI/Framework/Events/ModDisplayEvents.cs b/src/SMAPI/Framework/Events/ModDisplayEvents.cs
new file mode 100644
index 00000000..e383eec6
--- /dev/null
+++ b/src/SMAPI/Framework/Events/ModDisplayEvents.cs
@@ -0,0 +1,93 @@
+using System;
+using StardewModdingAPI.Events;
+using StardewValley;
+
+namespace StardewModdingAPI.Framework.Events
+{
+ /// <summary>Events related to UI and drawing to the screen.</summary>
+ internal class ModDisplayEvents : ModEventsBase, IDisplayEvents
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
+ public event EventHandler<MenuChangedEventArgs> MenuChanged
+ {
+ add => this.EventManager.MenuChanged.Add(value);
+ remove => this.EventManager.MenuChanged.Remove(value);
+ }
+
+ /// <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>
+ public event EventHandler<RenderingEventArgs> Rendering
+ {
+ add => this.EventManager.Rendering.Add(value);
+ remove => this.EventManager.Rendering.Remove(value);
+ }
+
+ /// <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>
+ public event EventHandler<RenderedEventArgs> Rendered
+ {
+ add => this.EventManager.Rendered.Add(value);
+ remove => this.EventManager.Rendered.Remove(value);
+ }
+
+ /// <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>
+ public event EventHandler<RenderingWorldEventArgs> RenderingWorld
+ {
+ add => this.EventManager.RenderingWorld.Add(value);
+ remove => this.EventManager.RenderingWorld.Remove(value);
+ }
+
+ /// <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>
+ public event EventHandler<RenderedWorldEventArgs> RenderedWorld
+ {
+ add => this.EventManager.RenderedWorld.Add(value);
+ remove => this.EventManager.RenderedWorld.Remove(value);
+ }
+
+ /// <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>
+ public event EventHandler<RenderingActiveMenuEventArgs> RenderingActiveMenu
+ {
+ add => this.EventManager.RenderingActiveMenu.Add(value);
+ remove => this.EventManager.RenderingActiveMenu.Remove(value);
+ }
+
+ /// <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>
+ public event EventHandler<RenderedActiveMenuEventArgs> RenderedActiveMenu
+ {
+ add => this.EventManager.RenderedActiveMenu.Add(value);
+ remove => this.EventManager.RenderedActiveMenu.Remove(value);
+ }
+
+ /// <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>
+ public event EventHandler<RenderingHudEventArgs> RenderingHud
+ {
+ add => this.EventManager.RenderingHud.Add(value);
+ remove => this.EventManager.RenderingHud.Remove(value);
+ }
+
+ /// <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>
+ public event EventHandler<RenderedHudEventArgs> RenderedHud
+ {
+ add => this.EventManager.RenderedHud.Add(value);
+ remove => this.EventManager.RenderedHud.Remove(value);
+ }
+
+ /// <summary>Raised after the game window is resized.</summary>
+ public event EventHandler<WindowResizedEventArgs> WindowResized
+ {
+ add => this.EventManager.WindowResized.Add(value);
+ remove => this.EventManager.WindowResized.Remove(value);
+ }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="mod">The mod which uses this instance.</param>
+ /// <param name="eventManager">The underlying event manager.</param>
+ internal ModDisplayEvents(IModMetadata mod, EventManager eventManager)
+ : base(mod, eventManager) { }
+ }
+}
diff --git a/src/SMAPI/Framework/Events/ModEvents.cs b/src/SMAPI/Framework/Events/ModEvents.cs
index 9e474457..7a318e8b 100644
--- a/src/SMAPI/Framework/Events/ModEvents.cs
+++ b/src/SMAPI/Framework/Events/ModEvents.cs
@@ -8,15 +8,24 @@ namespace StardewModdingAPI.Framework.Events
/*********
** Accessors
*********/
+ /// <summary>Events related to UI and drawing to the screen.</summary>
+ public 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="IModEvents.Input"/> if possible.</summary>
public IGameLoopEvents GameLoop { get; }
/// <summary>Events raised when the player provides input using a controller, keyboard, or mouse.</summary>
public IInputEvents Input { get; }
+ /// <summary>Events raised when the player data changes.</summary>
+ public IPlayerEvents Player { get; }
+
/// <summary>Events raised when something changes in the world.</summary>
public IWorldEvents World { get; }
+ /// <summary>Events serving specialised edge cases that shouldn't be used by most mods.</summary>
+ public ISpecialisedEvents Specialised { get; }
+
/*********
** Public methods
@@ -26,9 +35,12 @@ namespace StardewModdingAPI.Framework.Events
/// <param name="eventManager">The underlying event manager.</param>
public ModEvents(IModMetadata mod, EventManager eventManager)
{
+ this.Display = new ModDisplayEvents(mod, eventManager);
this.GameLoop = new ModGameLoopEvents(mod, eventManager);
this.Input = new ModInputEvents(mod, eventManager);
+ this.Player = new ModPlayerEvents(mod, eventManager);
this.World = new ModWorldEvents(mod, eventManager);
+ this.Specialised = new ModSpecialisedEvents(mod, eventManager);
}
}
}
diff --git a/src/SMAPI/Framework/Events/ModGameLoopEvents.cs b/src/SMAPI/Framework/Events/ModGameLoopEvents.cs
index d1def91b..a5beac99 100644
--- a/src/SMAPI/Framework/Events/ModGameLoopEvents.cs
+++ b/src/SMAPI/Framework/Events/ModGameLoopEvents.cs
@@ -79,6 +79,21 @@ namespace StardewModdingAPI.Framework.Events
remove => this.EventManager.DayEnding.Remove(value);
}
+ /// <summary>Raised after the in-game clock time changes.</summary>
+ public event EventHandler<TimeChangedEventArgs> TimeChanged
+ {
+
+ add => this.EventManager.TimeChanged.Add(value);
+ remove => this.EventManager.TimeChanged.Remove(value);
+ }
+
+ /// <summary>Raised after the game returns to the title screen.</summary>
+ public event EventHandler<ReturnedToTitleEventArgs> ReturnedToTitle
+ {
+ add => this.EventManager.ReturnedToTitle.Add(value);
+ remove => this.EventManager.ReturnedToTitle.Remove(value);
+ }
+
/*********
** Public methods
diff --git a/src/SMAPI/Framework/Events/ModPlayerEvents.cs b/src/SMAPI/Framework/Events/ModPlayerEvents.cs
new file mode 100644
index 00000000..ca7cfd96
--- /dev/null
+++ b/src/SMAPI/Framework/Events/ModPlayerEvents.cs
@@ -0,0 +1,43 @@
+using System;
+using StardewModdingAPI.Events;
+
+namespace StardewModdingAPI.Framework.Events
+{
+ /// <summary>Events raised when the player data changes.</summary>
+ internal class ModPlayerEvents : ModEventsBase, IPlayerEvents
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Raised after items are added or removed to a player's inventory. NOTE: this event is currently only raised for the local player.</summary>
+ public event EventHandler<InventoryChangedEventArgs> InventoryChanged
+ {
+ add => this.EventManager.InventoryChanged.Add(value);
+ remove => this.EventManager.InventoryChanged.Remove(value);
+ }
+
+ /// <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 local player.</summary>
+ public event EventHandler<LevelChangedEventArgs> LevelChanged
+ {
+ add => this.EventManager.LevelChanged.Add(value);
+ remove => this.EventManager.LevelChanged.Remove(value);
+ }
+
+ /// <summary>Raised after a player warps to a new location. NOTE: this event is currently only raised for the local player.</summary>
+ public event EventHandler<WarpedEventArgs> Warped
+ {
+ add => this.EventManager.Warped.Add(value);
+ remove => this.EventManager.Warped.Remove(value);
+ }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="mod">The mod which uses this instance.</param>
+ /// <param name="eventManager">The underlying event manager.</param>
+ internal ModPlayerEvents(IModMetadata mod, EventManager eventManager)
+ : base(mod, eventManager) { }
+ }
+}
diff --git a/src/SMAPI/Framework/Events/ModSpecialisedEvents.cs b/src/SMAPI/Framework/Events/ModSpecialisedEvents.cs
new file mode 100644
index 00000000..17c32bb8
--- /dev/null
+++ b/src/SMAPI/Framework/Events/ModSpecialisedEvents.cs
@@ -0,0 +1,36 @@
+using System;
+using StardewModdingAPI.Events;
+
+namespace StardewModdingAPI.Framework.Events
+{
+ /// <summary>Events serving specialised edge cases that shouldn't be used by most mods.</summary>
+ internal class ModSpecialisedEvents : ModEventsBase, ISpecialisedEvents
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <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>
+ public event EventHandler<UnvalidatedUpdateTickingEventArgs> UnvalidatedUpdateTicking
+ {
+ add => this.EventManager.UnvalidatedUpdateTicking.Add(value);
+ remove => this.EventManager.UnvalidatedUpdateTicking.Remove(value);
+ }
+
+ /// <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>
+ public event EventHandler<UnvalidatedUpdateTickedEventArgs> UnvalidatedUpdateTicked
+ {
+ add => this.EventManager.UnvalidatedUpdateTicked.Add(value);
+ remove => this.EventManager.UnvalidatedUpdateTicked.Remove(value);
+ }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="mod">The mod which uses this instance.</param>
+ /// <param name="eventManager">The underlying event manager.</param>
+ internal ModSpecialisedEvents(IModMetadata mod, EventManager eventManager)
+ : base(mod, eventManager) { }
+ }
+}
diff --git a/src/SMAPI/Framework/InternalExtensions.cs b/src/SMAPI/Framework/InternalExtensions.cs
index b51ff6a8..f52bfe2b 100644
--- a/src/SMAPI/Framework/InternalExtensions.cs
+++ b/src/SMAPI/Framework/InternalExtensions.cs
@@ -43,8 +43,8 @@ namespace StardewModdingAPI.Framework
/****
** ManagedEvent
****/
- /// <summary>Raise the event and notify all handlers.</summary>
- /// <typeparam name="TEventArgs">The empty event arguments type to construct.</typeparam>
+ /// <summary>Raise the event using the default event args and notify all handlers.</summary>
+ /// <typeparam name="TEventArgs">The event args type to construct.</typeparam>
/// <param name="event">The event to raise.</param>
public static void RaiseEmpty<TEventArgs>(this ManagedEvent<TEventArgs> @event) where TEventArgs : new()
{
diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs
index bd266ce1..57f48d11 100644
--- a/src/SMAPI/Framework/SGame.cs
+++ b/src/SMAPI/Framework/SGame.cs
@@ -11,6 +11,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Netcode;
+using StardewModdingAPI.Enums;
using StardewModdingAPI.Events;
using StardewModdingAPI.Framework.Events;
using StardewModdingAPI.Framework.Input;
@@ -265,7 +266,9 @@ namespace StardewModdingAPI.Framework
// update tick are neglible and not worth the complications of bypassing Game1.Update.
if (Game1._newDayTask != null || Game1.gameMode == Game1.loadingMode)
{
+ this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
base.Update(gameTime);
+ this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed));
this.Events.Legacy_UnvalidatedUpdateTick.Raise();
return;
}
@@ -344,7 +347,9 @@ namespace StardewModdingAPI.Framework
}
// suppress non-save events
+ this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
base.Update(gameTime);
+ this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed));
this.Events.Legacy_UnvalidatedUpdateTick.Raise();
return;
}
@@ -406,6 +411,7 @@ namespace StardewModdingAPI.Framework
if (wasWorldReady && !Context.IsWorldReady)
{
this.Monitor.Log("Context: returned to title", LogLevel.Trace);
+ this.Events.ReturnedToTitle.RaiseEmpty();
this.Events.Legacy_AfterReturnToTitle.Raise();
}
else if (!this.RaisedAfterLoadEvent && Context.IsWorldReady)
@@ -441,6 +447,11 @@ namespace StardewModdingAPI.Framework
{
if (this.VerboseLogging)
this.Monitor.Log($"Events: window size changed to {this.Watchers.WindowSizeWatcher.CurrentValue}.", LogLevel.Trace);
+
+ Point oldSize = this.Watchers.WindowSizeWatcher.PreviousValue;
+ Point newSize = this.Watchers.WindowSizeWatcher.CurrentValue;
+
+ this.Events.WindowResized.Raise(new WindowResizedEventArgs(oldSize, newSize));
this.Events.Legacy_Resize.Raise();
this.Watchers.WindowSizeWatcher.Reset();
}
@@ -551,6 +562,7 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Context: menu changed from {was?.GetType().FullName ?? "none"} to {now?.GetType().FullName ?? "none"}.", LogLevel.Trace);
// raise menu events
+ this.Events.MenuChanged.Raise(new MenuChangedEventArgs(was, now));
if (now != null)
this.Events.Legacy_MenuChanged.Raise(new EventArgsClickableMenuChanged(was, now));
else
@@ -673,6 +685,7 @@ namespace StardewModdingAPI.Framework
if (this.VerboseLogging)
this.Monitor.Log($"Events: time changed from {was} to {now}.", LogLevel.Trace);
+ this.Events.TimeChanged.Raise(new TimeChangedEventArgs(was, now));
this.Events.Legacy_TimeOfDayChanged.Raise(new EventArgsIntChanged(was, now));
}
else
@@ -681,39 +694,45 @@ namespace StardewModdingAPI.Framework
// raise player events
if (raiseWorldEvents)
{
- PlayerTracker curPlayer = this.Watchers.CurrentPlayerTracker;
+ PlayerTracker playerTracker = this.Watchers.CurrentPlayerTracker;
// raise current location changed
- if (curPlayer.TryGetNewLocation(out GameLocation newLocation))
+ if (playerTracker.TryGetNewLocation(out GameLocation newLocation))
{
if (this.VerboseLogging)
this.Monitor.Log($"Context: set location to {newLocation.Name}.", LogLevel.Trace);
- this.Events.Legacy_PlayerWarped.Raise(new EventArgsPlayerWarped(curPlayer.LocationWatcher.PreviousValue, newLocation));
+
+ GameLocation oldLocation = playerTracker.LocationWatcher.PreviousValue;
+ this.Events.Warped.Raise(new WarpedEventArgs(playerTracker.Player, oldLocation, newLocation));
+ this.Events.Legacy_PlayerWarped.Raise(new EventArgsPlayerWarped(oldLocation, newLocation));
}
// raise player leveled up a skill
- foreach (KeyValuePair<EventArgsLevelUp.LevelType, IValueWatcher<int>> pair in curPlayer.GetChangedSkills())
+ foreach (KeyValuePair<SkillType, IValueWatcher<int>> pair in playerTracker.GetChangedSkills())
{
if (this.VerboseLogging)
this.Monitor.Log($"Events: player skill '{pair.Key}' changed from {pair.Value.PreviousValue} to {pair.Value.CurrentValue}.", LogLevel.Trace);
- this.Events.Legacy_LeveledUp.Raise(new EventArgsLevelUp(pair.Key, pair.Value.CurrentValue));
+
+ this.Events.LevelChanged.Raise(new LevelChangedEventArgs(playerTracker.Player, pair.Key, pair.Value.PreviousValue, pair.Value.CurrentValue));
+ this.Events.Legacy_LeveledUp.Raise(new EventArgsLevelUp((EventArgsLevelUp.LevelType)pair.Key, pair.Value.CurrentValue));
}
// raise player inventory changed
- ItemStackChange[] changedItems = curPlayer.GetInventoryChanges().ToArray();
+ ItemStackChange[] changedItems = playerTracker.GetInventoryChanges().ToArray();
if (changedItems.Any())
{
if (this.VerboseLogging)
this.Monitor.Log("Events: player inventory changed.", LogLevel.Trace);
- this.Events.Legacy_InventoryChanged.Raise(new EventArgsInventoryChanged(Game1.player.Items, changedItems.ToList()));
+ this.Events.InventoryChanged.Raise(new InventoryChangedEventArgs(playerTracker.Player, changedItems));
+ this.Events.Legacy_InventoryChanged.Raise(new EventArgsInventoryChanged(Game1.player.Items, changedItems));
}
// raise mine level changed
- if (curPlayer.TryGetNewMineLevel(out int mineLevel))
+ if (playerTracker.TryGetNewMineLevel(out int mineLevel))
{
if (this.VerboseLogging)
this.Monitor.Log($"Context: mine level changed to {mineLevel}.", LogLevel.Trace);
- this.Events.Legacy_MineLevelChanged.Raise(new EventArgsMineLevelChanged(curPlayer.MineLevelWatcher.PreviousValue, mineLevel));
+ this.Events.Legacy_MineLevelChanged.Raise(new EventArgsMineLevelChanged(playerTracker.MineLevelWatcher.PreviousValue, mineLevel));
}
}
this.Watchers.CurrentPlayerTracker?.Reset();
@@ -728,6 +747,7 @@ namespace StardewModdingAPI.Framework
this.TicksElapsed++;
if (this.TicksElapsed == 1)
this.Events.GameLaunched.Raise(new GameLaunchedEventArgs());
+ this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
this.Events.UpdateTicking.Raise(new UpdateTickingEventArgs(this.TicksElapsed));
try
{
@@ -738,6 +758,7 @@ namespace StardewModdingAPI.Framework
{
this.MonitorForGame.Log($"An error occured in the base update loop: {ex.GetLogSummary()}", LogLevel.Error);
}
+ this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed));
this.Events.UpdateTicked.Raise(new UpdateTickedEventArgs(this.TicksElapsed));
/*********
@@ -844,10 +865,13 @@ namespace StardewModdingAPI.Framework
if (activeClickableMenu != null)
{
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
+ this.Events.Rendering.RaiseEmpty();
try
{
+ this.Events.RenderingActiveMenu.RaiseEmpty();
this.Events.Legacy_OnPreRenderGuiEvent.Raise();
activeClickableMenu.draw(Game1.spriteBatch);
+ this.Events.RenderedActiveMenu.RaiseEmpty();
this.Events.Legacy_OnPostRenderGuiEvent.Raise();
}
catch (Exception ex)
@@ -855,7 +879,9 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"The {activeClickableMenu.GetType().FullName} menu crashed while drawing itself during save. SMAPI will force it to exit to avoid crashing the game.\n{ex.GetLogSummary()}", LogLevel.Error);
activeClickableMenu.exitThisMenu();
}
- this.RaisePostRender();
+ this.Events.Rendered.RaiseEmpty();
+ this.Events.Legacy_OnPostRenderEvent.Raise();
+
Game1.spriteBatch.End();
}
if (Game1.overlayMenu != null)
@@ -872,11 +898,15 @@ namespace StardewModdingAPI.Framework
if (Game1.activeClickableMenu != null && Game1.options.showMenuBackground && Game1.activeClickableMenu.showWithoutTransparencyIfOptionIsSet())
{
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
+
+ this.Events.Rendering.RaiseEmpty();
try
{
Game1.activeClickableMenu.drawBackground(Game1.spriteBatch);
+ this.Events.RenderingActiveMenu.RaiseEmpty();
this.Events.Legacy_OnPreRenderGuiEvent.Raise();
Game1.activeClickableMenu.draw(Game1.spriteBatch);
+ this.Events.RenderedActiveMenu.RaiseEmpty();
this.Events.Legacy_OnPostRenderGuiEvent.Raise();
}
catch (Exception ex)
@@ -884,7 +914,8 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"The {Game1.activeClickableMenu.GetType().FullName} menu crashed while drawing itself. SMAPI will force it to exit to avoid crashing the game.\n{ex.GetLogSummary()}", LogLevel.Error);
Game1.activeClickableMenu.exitThisMenu();
}
- this.RaisePostRender();
+ this.Events.Rendered.RaiseEmpty();
+ this.Events.Legacy_OnPostRenderEvent.Raise();
Game1.spriteBatch.End();
this.drawOverlays(Game1.spriteBatch);
if ((double)Game1.options.zoomLevel != 1.0)
@@ -904,10 +935,12 @@ namespace StardewModdingAPI.Framework
else if (Game1.gameMode == (byte)11)
{
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
+ this.Events.Rendering.RaiseEmpty();
Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3685"), new Vector2(16f, 16f), Color.HotPink);
Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3686"), new Vector2(16f, 32f), new Color(0, (int)byte.MaxValue, 0));
Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.parseText(Game1.errorMessage, Game1.dialogueFont, Game1.graphics.GraphicsDevice.Viewport.Width), new Vector2(16f, 48f), Color.White);
- this.RaisePostRender();
+ this.Events.Rendered.RaiseEmpty();
+ this.Events.Legacy_OnPostRenderEvent.Raise();
Game1.spriteBatch.End();
}
else if (Game1.currentMinigame != null)
@@ -932,12 +965,15 @@ namespace StardewModdingAPI.Framework
else if (Game1.showingEndOfNightStuff)
{
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
+ this.Events.Rendering.RaiseEmpty();
if (Game1.activeClickableMenu != null)
{
try
{
+ this.Events.RenderingActiveMenu.RaiseEmpty();
this.Events.Legacy_OnPreRenderGuiEvent.Raise();
Game1.activeClickableMenu.draw(Game1.spriteBatch);
+ this.Events.RenderedActiveMenu.RaiseEmpty();
this.Events.Legacy_OnPostRenderGuiEvent.Raise();
}
catch (Exception ex)
@@ -946,7 +982,7 @@ namespace StardewModdingAPI.Framework
Game1.activeClickableMenu.exitThisMenu();
}
}
- this.RaisePostRender();
+ this.Events.Rendered.RaiseEmpty();
Game1.spriteBatch.End();
this.drawOverlays(Game1.spriteBatch);
if ((double)Game1.options.zoomLevel == 1.0)
@@ -960,6 +996,7 @@ namespace StardewModdingAPI.Framework
else if (Game1.gameMode == (byte)6 || Game1.gameMode == (byte)3 && Game1.currentLocation == null)
{
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
+ this.Events.Rendering.RaiseEmpty();
string str1 = "";
for (int index = 0; (double)index < gameTime.TotalGameTime.TotalMilliseconds % 999.0 / 333.0; ++index)
str1 += ".";
@@ -971,6 +1008,7 @@ namespace StardewModdingAPI.Framework
int x = 64;
int y = Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Bottom - height;
SpriteText.drawString(Game1.spriteBatch, s, x, y, 999999, widthOfString, height, 1f, 0.88f, false, 0, str3, -1);
+ this.Events.Rendered.RaiseEmpty();
Game1.spriteBatch.End();
this.drawOverlays(Game1.spriteBatch);
if ((double)Game1.options.zoomLevel != 1.0)
@@ -991,11 +1029,15 @@ namespace StardewModdingAPI.Framework
}
else
{
+ byte batchOpens = 0; // used for rendering event
+
Microsoft.Xna.Framework.Rectangle rectangle;
Viewport viewport;
if (Game1.gameMode == (byte)0)
{
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
+ if (++batchOpens == 1)
+ this.Events.Rendering.RaiseEmpty();
}
else
{
@@ -1004,6 +1046,8 @@ namespace StardewModdingAPI.Framework
this.GraphicsDevice.SetRenderTarget(Game1.lightmap);
this.GraphicsDevice.Clear(Color.White * 0.0f);
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
+ if (++batchOpens == 1)
+ this.Events.Rendering.RaiseEmpty();
Game1.spriteBatch.Draw(Game1.staminaRect, Game1.lightmap.Bounds, Game1.currentLocation.Name.StartsWith("UndergroundMine") ? Game1.mine.getLightingColor(gameTime) : (Game1.ambientLight.Equals(Color.White) || Game1.isRaining && (bool)((NetFieldBase<bool, NetBool>)Game1.currentLocation.isOutdoors) ? Game1.outdoorLight : Game1.ambientLight));
for (int index = 0; index < Game1.currentLightSources.Count; ++index)
{
@@ -1017,6 +1061,9 @@ namespace StardewModdingAPI.Framework
Game1.bloom.BeginDraw();
this.GraphicsDevice.Clear(this.bgColor);
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
+ if (++batchOpens == 1)
+ this.Events.Rendering.RaiseEmpty();
+ this.Events.RenderingWorld.RaiseEmpty();
this.Events.Legacy_OnPreRenderEvent.Raise();
if (Game1.background != null)
Game1.background.draw(Game1.spriteBatch);
@@ -1328,8 +1375,10 @@ namespace StardewModdingAPI.Framework
this.drawBillboard();
if ((Game1.displayHUD || Game1.eventUp) && (Game1.currentBillboard == 0 && Game1.gameMode == (byte)3) && (!Game1.freezeControls && !Game1.panMode && !Game1.HostPaused))
{
+ this.Events.RenderingHud.RaiseEmpty();
this.Events.Legacy_OnPreRenderHudEvent.Raise();
this.drawHUD();
+ this.Events.RenderedHud.RaiseEmpty();
this.Events.Legacy_OnPostRenderHudEvent.Raise();
}
else if (Game1.activeClickableMenu == null && Game1.farmEvent == null)
@@ -1438,8 +1487,10 @@ namespace StardewModdingAPI.Framework
{
try
{
+ this.Events.RenderingActiveMenu.RaiseEmpty();
this.Events.Legacy_OnPreRenderGuiEvent.Raise();
Game1.activeClickableMenu.draw(Game1.spriteBatch);
+ this.Events.RenderedActiveMenu.RaiseEmpty();
this.Events.Legacy_OnPostRenderGuiEvent.Raise();
}
catch (Exception ex)
@@ -1455,7 +1506,9 @@ namespace StardewModdingAPI.Framework
string s = Game1.content.LoadString("Strings\\StringsFromCSFiles:DayTimeMoneyBox.cs.10378");
SpriteText.drawStringWithScrollBackground(Game1.spriteBatch, s, 96, 32, "", 1f, -1);
}
- this.RaisePostRender();
+ this.Events.RenderedWorld.RaiseEmpty();
+ this.Events.Rendered.RaiseEmpty();
+ this.Events.Legacy_OnPostRenderEvent.Raise();
Game1.spriteBatch.End();
this.drawOverlays(Game1.spriteBatch);
this.renderScreenBuffer();
diff --git a/src/SMAPI/Framework/StateTracking/PlayerTracker.cs b/src/SMAPI/Framework/StateTracking/PlayerTracker.cs
index 59e80d8a..6a705e50 100644
--- a/src/SMAPI/Framework/StateTracking/PlayerTracker.cs
+++ b/src/SMAPI/Framework/StateTracking/PlayerTracker.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using StardewModdingAPI.Enums;
using StardewModdingAPI.Events;
using StardewModdingAPI.Framework.StateTracking.FieldWatchers;
using StardewValley;
@@ -41,7 +42,7 @@ namespace StardewModdingAPI.Framework.StateTracking
public IValueWatcher<int> MineLevelWatcher { get; }
/// <summary>Tracks changes to the player's skill levels.</summary>
- public IDictionary<EventArgsLevelUp.LevelType, IValueWatcher<int>> SkillWatchers { get; }
+ public IDictionary<SkillType, IValueWatcher<int>> SkillWatchers { get; }
/*********
@@ -58,14 +59,14 @@ namespace StardewModdingAPI.Framework.StateTracking
// init trackers
this.LocationWatcher = WatcherFactory.ForReference(this.GetCurrentLocation);
this.MineLevelWatcher = WatcherFactory.ForEquatable(() => this.LastValidLocation is MineShaft mine ? mine.mineLevel : 0);
- this.SkillWatchers = new Dictionary<EventArgsLevelUp.LevelType, IValueWatcher<int>>
+ this.SkillWatchers = new Dictionary<SkillType, IValueWatcher<int>>
{
- [EventArgsLevelUp.LevelType.Combat] = WatcherFactory.ForNetValue(player.combatLevel),
- [EventArgsLevelUp.LevelType.Farming] = WatcherFactory.ForNetValue(player.farmingLevel),
- [EventArgsLevelUp.LevelType.Fishing] = WatcherFactory.ForNetValue(player.fishingLevel),
- [EventArgsLevelUp.LevelType.Foraging] = WatcherFactory.ForNetValue(player.foragingLevel),
- [EventArgsLevelUp.LevelType.Luck] = WatcherFactory.ForNetValue(player.luckLevel),
- [EventArgsLevelUp.LevelType.Mining] = WatcherFactory.ForNetValue(player.miningLevel)
+ [SkillType.Combat] = WatcherFactory.ForNetValue(player.combatLevel),
+ [SkillType.Farming] = WatcherFactory.ForNetValue(player.farmingLevel),
+ [SkillType.Fishing] = WatcherFactory.ForNetValue(player.fishingLevel),
+ [SkillType.Foraging] = WatcherFactory.ForNetValue(player.foragingLevel),
+ [SkillType.Luck] = WatcherFactory.ForNetValue(player.luckLevel),
+ [SkillType.Mining] = WatcherFactory.ForNetValue(player.miningLevel)
};
// track watchers for convenience
@@ -124,7 +125,7 @@ namespace StardewModdingAPI.Framework.StateTracking
}
/// <summary>Get the player skill levels which changed.</summary>
- public IEnumerable<KeyValuePair<EventArgsLevelUp.LevelType, IValueWatcher<int>>> GetChangedSkills()
+ public IEnumerable<KeyValuePair<SkillType, IValueWatcher<int>>> GetChangedSkills()
{
return this.SkillWatchers.Where(p => p.Value.IsChanged);
}
diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj
index efb85c52..d58aee56 100644
--- a/src/SMAPI/StardewModdingAPI.csproj
+++ b/src/SMAPI/StardewModdingAPI.csproj
@@ -79,32 +79,90 @@
<Compile Include="..\..\build\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
+ <Compile Include="Enums\SkillType.cs" />
+ <Compile Include="Events\BuildingListChangedEventArgs.cs" />
+ <Compile Include="Events\ButtonPressedEventArgs.cs" />
+ <Compile Include="Events\ButtonReleasedEventArgs.cs" />
+ <Compile Include="Events\ChangeType.cs" />
+ <Compile Include="Events\ContentEvents.cs" />
+ <Compile Include="Events\ControlEvents.cs" />
+ <Compile Include="Events\CursorMovedEventArgs.cs" />
<Compile Include="Events\DayEndingEventArgs.cs" />
<Compile Include="Events\DayStartedEventArgs.cs" />
- <Compile Include="Events\SaveCreatingEventArgs.cs" />
- <Compile Include="Events\SavedEventArgs.cs" />
- <Compile Include="Events\SavingEventArgs.cs" />
- <Compile Include="Events\SaveLoadedEventArgs.cs" />
- <Compile Include="Events\SaveCreatedEventArgs.cs" />
- <Compile Include="Events\UpdateTickedEventArgs.cs" />
- <Compile Include="Events\GameLaunchedEventArgs.cs" />
- <Compile Include="Events\MouseWheelScrolledEventArgs.cs" />
- <Compile Include="Events\CursorMovedEventArgs.cs" />
- <Compile Include="Events\ButtonReleasedEventArgs.cs" />
- <Compile Include="Events\ButtonPressedEventArgs.cs" />
+ <Compile Include="Events\DebrisListChangedEventArgs.cs" />
+ <Compile Include="Events\EventArgsClickableMenuChanged.cs" />
+ <Compile Include="Events\EventArgsClickableMenuClosed.cs" />
+ <Compile Include="Events\EventArgsControllerButtonPressed.cs" />
+ <Compile Include="Events\EventArgsControllerButtonReleased.cs" />
+ <Compile Include="Events\EventArgsControllerTriggerPressed.cs" />
+ <Compile Include="Events\EventArgsControllerTriggerReleased.cs" />
+ <Compile Include="Events\EventArgsInput.cs" />
+ <Compile Include="Events\EventArgsIntChanged.cs" />
+ <Compile Include="Events\EventArgsInventoryChanged.cs" />
+ <Compile Include="Events\EventArgsKeyboardStateChanged.cs" />
+ <Compile Include="Events\EventArgsKeyPressed.cs" />
+ <Compile Include="Events\EventArgsLevelUp.cs" />
<Compile Include="Events\EventArgsLocationBuildingsChanged.cs" />
- <Compile Include="Events\IInputEvents.cs" />
+ <Compile Include="Events\EventArgsLocationObjectsChanged.cs" />
+ <Compile Include="Events\EventArgsLocationsChanged.cs" />
+ <Compile Include="Events\EventArgsMineLevelChanged.cs" />
+ <Compile Include="Events\EventArgsMouseStateChanged.cs" />
+ <Compile Include="Events\EventArgsPlayerWarped.cs" />
+ <Compile Include="Events\EventArgsValueChanged.cs" />
+ <Compile Include="Events\GameEvents.cs" />
+ <Compile Include="Events\GameLaunchedEventArgs.cs" />
+ <Compile Include="Events\GraphicsEvents.cs" />
+ <Compile Include="Events\IDisplayEvents.cs" />
<Compile Include="Events\IGameLoopEvents.cs" />
+ <Compile Include="Events\IInputEvents.cs" />
+ <Compile Include="Events\IModEvents.cs" />
+ <Compile Include="Events\InputEvents.cs" />
+ <Compile Include="Events\InventoryChangedEventArgs.cs" />
+ <Compile Include="Events\IPlayerEvents.cs" />
+ <Compile Include="Events\ISpecialisedEvents.cs" />
+ <Compile Include="Events\ItemStackChange.cs" />
+ <Compile Include="Events\ItemStackSizeChange.cs" />
<Compile Include="Events\IWorldEvents.cs" />
- <Compile Include="Events\MultiplayerEvents.cs" />
- <Compile Include="Events\DebrisListChangedEventArgs.cs" />
- <Compile Include="Events\UpdateTickingEventArgs.cs" />
- <Compile Include="Events\NpcListChangedEventArgs.cs" />
<Compile Include="Events\LargeTerrainFeatureListChangedEventArgs.cs" />
- <Compile Include="Events\TerrainFeatureListChangedEventArgs.cs" />
- <Compile Include="Events\BuildingListChangedEventArgs.cs" />
+ <Compile Include="Events\LevelChangedEventArgs.cs" />
+ <Compile Include="Events\LocationEvents.cs" />
<Compile Include="Events\LocationListChangedEventArgs.cs" />
+ <Compile Include="Events\MenuChangedEventArgs.cs" />
+ <Compile Include="Events\MenuEvents.cs" />
+ <Compile Include="Events\MineEvents.cs" />
+ <Compile Include="Events\MouseWheelScrolledEventArgs.cs" />
+ <Compile Include="Events\MultiplayerEvents.cs" />
+ <Compile Include="Events\NpcListChangedEventArgs.cs" />
<Compile Include="Events\ObjectListChangedEventArgs.cs" />
+ <Compile Include="Events\PlayerEvents.cs" />
+ <Compile Include="Events\RenderedActiveMenuEventArgs.cs" />
+ <Compile Include="Events\RenderedEventArgs.cs" />
+ <Compile Include="Events\RenderedHudEventArgs.cs" />
+ <Compile Include="Events\RenderedWorldEventArgs.cs" />
+ <Compile Include="Events\RenderingActiveMenuEventArgs.cs" />
+ <Compile Include="Events\RenderingEventArgs.cs" />
+ <Compile Include="Events\RenderingHudEventArgs.cs" />
+ <Compile Include="Events\RenderingWorldEventArgs.cs" />
+ <Compile Include="Events\ReturnedToTitleEventArgs.cs" />
+ <Compile Include="Events\SaveCreatedEventArgs.cs" />
+ <Compile Include="Events\SaveCreatingEventArgs.cs" />
+ <Compile Include="Events\SavedEventArgs.cs" />
+ <Compile Include="Events\SaveEvents.cs" />
+ <Compile Include="Events\SaveLoadedEventArgs.cs" />
+ <Compile Include="Events\SavingEventArgs.cs" />
+ <Compile Include="Events\SpecialisedEvents.cs" />
+ <Compile Include="Events\TerrainFeatureListChangedEventArgs.cs" />
+ <Compile Include="Events\TimeChangedEventArgs.cs" />
+ <Compile Include="Events\TimeEvents.cs" />
+ <Compile Include="Events\UnvalidatedUpdateTickedEventArgs.cs" />
+ <Compile Include="Events\UnvalidatedUpdateTickingEventArgs.cs" />
+ <Compile Include="Events\UpdateTickedEventArgs.cs" />
+ <Compile Include="Events\UpdateTickingEventArgs.cs" />
+ <Compile Include="Events\WarpedEventArgs.cs" />
+ <Compile Include="Events\WindowResizedEventArgs.cs" />
+ <Compile Include="Framework\Events\ModPlayerEvents.cs" />
+ <Compile Include="Framework\Events\ModDisplayEvents.cs" />
+ <Compile Include="Framework\Events\ModSpecialisedEvents.cs" />
<Compile Include="Framework\ModHelpers\DataHelper.cs" />
<Compile Include="Framework\SCore.cs" />
<Compile Include="Framework\SGameConstructorHack.cs" />
@@ -121,9 +179,7 @@
<Compile Include="Framework\Serialisation\RectangleConverter.cs" />
<Compile Include="Framework\Events\ModEventsBase.cs" />
<Compile Include="Framework\Events\EventManager.cs" />
- <Compile Include="Events\IModEvents.cs" />
<Compile Include="Framework\Events\ManagedEvent.cs" />
- <Compile Include="Events\SpecialisedEvents.cs" />
<Compile Include="Framework\ContentPack.cs" />
<Compile Include="Framework\Content\ContentCache.cs" />
<Compile Include="Framework\Events\ManagedEventBase.cs" />
@@ -132,6 +188,7 @@
<Compile Include="Framework\Events\ModInputEvents.cs" />
<Compile Include="Framework\Input\GamePadStateBuilder.cs" />
<Compile Include="Framework\ModHelpers\InputHelper.cs" />
+ <Compile Include="Framework\SModHooks.cs" />
<Compile Include="Framework\Singleton.cs" />
<Compile Include="Framework\StateTracking\Comparers\GenericEqualsComparer.cs" />
<Compile Include="Framework\WatcherCore.cs" />
@@ -191,33 +248,10 @@
<Compile Include="IReflectedProperty.cs" />
<Compile Include="Metadata\CoreAssetPropagator.cs" />
<Compile Include="ContentSource.cs" />
- <Compile Include="Events\ContentEvents.cs" />
- <Compile Include="Events\EventArgsInput.cs" />
- <Compile Include="Events\EventArgsValueChanged.cs" />
- <Compile Include="Events\InputEvents.cs" />
<Compile Include="Framework\Content\AssetInfo.cs" />
<Compile Include="Framework\Exceptions\SContentLoadException.cs" />
<Compile Include="Framework\Command.cs" />
<Compile Include="Constants.cs" />
- <Compile Include="Events\ControlEvents.cs" />
- <Compile Include="Events\EventArgsClickableMenuChanged.cs" />
- <Compile Include="Events\EventArgsClickableMenuClosed.cs" />
- <Compile Include="Events\EventArgsControllerButtonPressed.cs" />
- <Compile Include="Events\EventArgsControllerButtonReleased.cs" />
- <Compile Include="Events\EventArgsControllerTriggerPressed.cs" />
- <Compile Include="Events\EventArgsControllerTriggerReleased.cs" />
- <Compile Include="Events\EventArgsPlayerWarped.cs" />
- <Compile Include="Events\EventArgsLocationsChanged.cs" />
- <Compile Include="Events\EventArgsIntChanged.cs" />
- <Compile Include="Events\EventArgsInventoryChanged.cs" />
- <Compile Include="Events\EventArgsKeyboardStateChanged.cs" />
- <Compile Include="Events\EventArgsKeyPressed.cs" />
- <Compile Include="Events\EventArgsLevelUp.cs" />
- <Compile Include="Events\EventArgsLocationObjectsChanged.cs" />
- <Compile Include="Events\EventArgsMineLevelChanged.cs" />
- <Compile Include="Events\EventArgsMouseStateChanged.cs" />
- <Compile Include="Events\GameEvents.cs" />
- <Compile Include="Events\GraphicsEvents.cs" />
<Compile Include="Framework\Utilities\Countdown.cs" />
<Compile Include="Framework\GameVersion.cs" />
<Compile Include="Framework\IModMetadata.cs" />
@@ -256,12 +290,6 @@
<Compile Include="IAssetDataForImage.cs" />
<Compile Include="IContentHelper.cs" />
<Compile Include="IModRegistry.cs" />
- <Compile Include="Events\LocationEvents.cs" />
- <Compile Include="Events\MenuEvents.cs" />
- <Compile Include="Events\MineEvents.cs" />
- <Compile Include="Events\PlayerEvents.cs" />
- <Compile Include="Events\SaveEvents.cs" />
- <Compile Include="Events\TimeEvents.cs" />
<Compile Include="Framework\DeprecationLevel.cs" />
<Compile Include="Framework\DeprecationManager.cs" />
<Compile Include="Framework\InternalExtensions.cs" />
@@ -278,8 +306,6 @@
<Compile Include="LogLevel.cs" />
<Compile Include="Framework\ModRegistry.cs" />
<Compile Include="IMonitor.cs" />
- <Compile Include="Events\ChangeType.cs" />
- <Compile Include="Events\ItemStackChange.cs" />
<Compile Include="Framework\Monitor.cs" />
<Compile Include="Metadata\InstructionMetadata.cs" />
<Compile Include="Mod.cs" />