using System.Diagnostics.CodeAnalysis; using Microsoft.Xna.Framework.Input; using StardewModdingAPI.Events; namespace StardewModdingAPI.Framework.Events { /// Manages SMAPI events. [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Private fields are deliberately named to simplify organisation.")] internal class EventManager { /********* ** Events (new) *********/ /**** ** World ****/ /// Raised after a game location is added or removed. public readonly ManagedEvent World_LocationListChanged; /// Raised after buildings are added or removed in a location. public readonly ManagedEvent World_BuildingListChanged; /// Raised after debris are added or removed in a location. public readonly ManagedEvent World_DebrisListChanged; /// Raised after large terrain features (like bushes) are added or removed in a location. public readonly ManagedEvent World_LargeTerrainFeatureListChanged; /// Raised after NPCs are added or removed in a location. public readonly ManagedEvent World_NpcListChanged; /// Raised after objects are added or removed in a location. public readonly ManagedEvent World_ObjectListChanged; /// Raised after terrain features (like floors and trees) are added or removed in a location. public readonly ManagedEvent World_TerrainFeatureListChanged; /**** ** Input ****/ /// Raised after the player presses a button on the keyboard, controller, or mouse. public readonly ManagedEvent Input_ButtonPressed; /// Raised after the player released a button on the keyboard, controller, or mouse. public readonly ManagedEvent Input_ButtonReleased; /// Raised after the player moves the in-game cursor. public readonly ManagedEvent Input_CursorMoved; /// Raised after the player scrolls the mouse wheel. public readonly ManagedEvent Input_MouseWheelScrolled; /********* ** Events (old) *********/ /**** ** ContentEvents ****/ /// Raised after the content language changes. public readonly ManagedEvent> Content_LocaleChanged; /**** ** ControlEvents ****/ /// Raised when the changes. That happens when the player presses or releases a key. public readonly ManagedEvent Legacy_Control_KeyboardChanged; /// Raised after the player presses a keyboard key. public readonly ManagedEvent Legacy_Control_KeyPressed; /// Raised after the player releases a keyboard key. public readonly ManagedEvent Legacy_Control_KeyReleased; /// Raised when the changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button. public readonly ManagedEvent Legacy_Control_MouseChanged; /// The player pressed a controller button. This event isn't raised for trigger buttons. public readonly ManagedEvent Legacy_Control_ControllerButtonPressed; /// The player released a controller button. This event isn't raised for trigger buttons. public readonly ManagedEvent Legacy_Control_ControllerButtonReleased; /// The player pressed a controller trigger button. public readonly ManagedEvent Legacy_Control_ControllerTriggerPressed; /// The player released a controller trigger button. public readonly ManagedEvent Legacy_Control_ControllerTriggerReleased; /**** ** GameEvents ****/ /// Raised once after the game initialises and all methods have been called. public readonly ManagedEvent Game_FirstUpdateTick; /// Raised when the game updates its state (≈60 times per second). public readonly ManagedEvent Game_UpdateTick; /// Raised every other tick (≈30 times per second). public readonly ManagedEvent Game_SecondUpdateTick; /// Raised every fourth tick (≈15 times per second). public readonly ManagedEvent Game_FourthUpdateTick; /// Raised every eighth tick (≈8 times per second). public readonly ManagedEvent Game_EighthUpdateTick; /// Raised every 15th tick (≈4 times per second). public readonly ManagedEvent Game_QuarterSecondTick; /// Raised every 30th tick (≈twice per second). public readonly ManagedEvent Game_HalfSecondTick; /// Raised every 60th tick (≈once per second). public readonly ManagedEvent Game_OneSecondTick; /**** ** GraphicsEvents ****/ /// Raised after the game window is resized. public readonly ManagedEvent Graphics_Resize; /// Raised before drawing the world to the screen. public readonly ManagedEvent Graphics_OnPreRenderEvent; /// Raised after drawing the world to the screen. public readonly ManagedEvent Graphics_OnPostRenderEvent; /// 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.) public readonly ManagedEvent Graphics_OnPreRenderHudEvent; /// 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.) public readonly ManagedEvent Graphics_OnPostRenderHudEvent; /// Raised before drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen. public readonly ManagedEvent Graphics_OnPreRenderGuiEvent; /// Raised after drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen. public readonly ManagedEvent Graphics_OnPostRenderGuiEvent; /**** ** InputEvents ****/ /// Raised after the player presses a button on the keyboard, controller, or mouse. public readonly ManagedEvent Legacy_Input_ButtonPressed; /// Raised after the player releases a keyboard key on the keyboard, controller, or mouse. public readonly ManagedEvent Legacy_Input_ButtonReleased; /**** ** LocationEvents ****/ /// Raised after a game location is added or removed. public readonly ManagedEvent Legacy_Location_LocationsChanged; /// Raised after buildings are added or removed in a location. public readonly ManagedEvent Legacy_Location_BuildingsChanged; /// Raised after objects are added or removed in a location. public readonly ManagedEvent Legacy_Location_ObjectsChanged; /**** ** MenuEvents ****/ /// Raised after a game menu is opened or replaced with another menu. This event is not invoked when a menu is closed. public readonly ManagedEvent Menu_Changed; /// Raised after a game menu is closed. public readonly ManagedEvent Menu_Closed; /**** ** MultiplayerEvents ****/ /// Raised before the game syncs changes from other players. public readonly ManagedEvent Multiplayer_BeforeMainSync; /// Raised after the game syncs changes from other players. public readonly ManagedEvent Multiplayer_AfterMainSync; /// Raised before the game broadcasts changes to other players. public readonly ManagedEvent Multiplayer_BeforeMainBroadcast; /// Raised after the game broadcasts changes to other players. public readonly ManagedEvent Multiplayer_AfterMainBroadcast; /**** ** MineEvents ****/ /// Raised after the player warps to a new level of the mine. public readonly ManagedEvent Mine_LevelChanged; /**** ** PlayerEvents ****/ /// Raised after the player's inventory changes in any way (added or removed item, sorted, etc). public readonly ManagedEvent Player_InventoryChanged; /// 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. public readonly ManagedEvent Player_LeveledUp; /// Raised after the player warps to a new location. public readonly ManagedEvent Player_Warped; /**** ** SaveEvents ****/ /// Raised before the game creates the save file. public readonly ManagedEvent Save_BeforeCreate; /// Raised after the game finishes creating the save file. public readonly ManagedEvent Save_AfterCreate; /// Raised before the game begins writes data to the save file. public readonly ManagedEvent Save_BeforeSave; /// Raised after the game finishes writing data to the save file. public readonly ManagedEvent Save_AfterSave; /// Raised after the player loads a save slot. public readonly ManagedEvent Save_AfterLoad; /// Raised after the game returns to the title screen. public readonly ManagedEvent Save_AfterReturnToTitle; /**** ** SpecialisedEvents ****/ /// 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. public readonly ManagedEvent Specialised_UnvalidatedUpdateTick; /**** ** TimeEvents ****/ /// Raised after the game begins a new day, including when loading a save. public readonly ManagedEvent Time_AfterDayStarted; /// Raised after the in-game clock changes. public readonly ManagedEvent Time_TimeOfDayChanged; /********* ** Public methods *********/ /// Construct an instance. /// Writes messages to the log. /// The mod registry with which to identify mods. public EventManager(IMonitor monitor, ModRegistry modRegistry) { // create shortcut initialisers ManagedEvent ManageEventOf(string typeName, string eventName) => new ManagedEvent($"{typeName}.{eventName}", monitor, modRegistry); ManagedEvent ManageEvent(string typeName, string eventName) => new ManagedEvent($"{typeName}.{eventName}", monitor, modRegistry); // init events (new) this.Input_ButtonPressed = ManageEventOf(nameof(IModEvents.Input), nameof(IInputEvents.ButtonPressed)); this.Input_ButtonReleased = ManageEventOf(nameof(IModEvents.Input), nameof(IInputEvents.ButtonReleased)); this.Input_CursorMoved = ManageEventOf(nameof(IModEvents.Input), nameof(IInputEvents.CursorMoved)); this.Input_MouseWheelScrolled = ManageEventOf(nameof(IModEvents.Input), nameof(IInputEvents.MouseWheelScrolled)); this.World_BuildingListChanged = ManageEventOf(nameof(IModEvents.World), nameof(IWorldEvents.LocationListChanged)); this.World_DebrisListChanged = ManageEventOf(nameof(IModEvents.World), nameof(IWorldEvents.DebrisListChanged)); this.World_LargeTerrainFeatureListChanged = ManageEventOf(nameof(IModEvents.World), nameof(IWorldEvents.LargeTerrainFeatureListChanged)); this.World_LocationListChanged = ManageEventOf(nameof(IModEvents.World), nameof(IWorldEvents.BuildingListChanged)); this.World_NpcListChanged = ManageEventOf(nameof(IModEvents.World), nameof(IWorldEvents.NpcListChanged)); this.World_ObjectListChanged = ManageEventOf(nameof(IModEvents.World), nameof(IWorldEvents.ObjectListChanged)); this.World_TerrainFeatureListChanged = ManageEventOf(nameof(IModEvents.World), nameof(IWorldEvents.TerrainFeatureListChanged)); // init events (old) this.Content_LocaleChanged = ManageEventOf>(nameof(ContentEvents), nameof(ContentEvents.AfterLocaleChanged)); this.Legacy_Control_ControllerButtonPressed = ManageEventOf(nameof(ControlEvents), nameof(ControlEvents.ControllerButtonPressed)); this.Legacy_Control_ControllerButtonReleased = ManageEventOf(nameof(ControlEvents), nameof(ControlEvents.ControllerButtonReleased)); this.Legacy_Control_ControllerTriggerPressed = ManageEventOf(nameof(ControlEvents), nameof(ControlEvents.ControllerTriggerPressed)); this.Legacy_Control_ControllerTriggerReleased = ManageEventOf(nameof(ControlEvents), nameof(ControlEvents.ControllerTriggerReleased)); this.Legacy_Control_KeyboardChanged = ManageEventOf(nameof(ControlEvents), nameof(ControlEvents.KeyboardChanged)); this.Legacy_Control_KeyPressed = ManageEventOf(nameof(ControlEvents), nameof(ControlEvents.KeyPressed)); this.Legacy_Control_KeyReleased = ManageEventOf(nameof(ControlEvents), nameof(ControlEvents.KeyReleased)); this.Legacy_Control_MouseChanged = ManageEventOf(nameof(ControlEvents), nameof(ControlEvents.MouseChanged)); this.Game_FirstUpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.FirstUpdateTick)); this.Game_UpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.UpdateTick)); this.Game_SecondUpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.SecondUpdateTick)); this.Game_FourthUpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.FourthUpdateTick)); this.Game_EighthUpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.EighthUpdateTick)); this.Game_QuarterSecondTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.QuarterSecondTick)); this.Game_HalfSecondTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.HalfSecondTick)); this.Game_OneSecondTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.OneSecondTick)); this.Graphics_Resize = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.Resize)); this.Graphics_OnPreRenderEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPreRenderEvent)); this.Graphics_OnPostRenderEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPostRenderEvent)); this.Graphics_OnPreRenderHudEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPreRenderHudEvent)); this.Graphics_OnPostRenderHudEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPostRenderHudEvent)); this.Graphics_OnPreRenderGuiEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPreRenderGuiEvent)); this.Graphics_OnPostRenderGuiEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPostRenderGuiEvent)); this.Legacy_Input_ButtonPressed = ManageEventOf(nameof(InputEvents), nameof(InputEvents.ButtonPressed)); this.Legacy_Input_ButtonReleased = ManageEventOf(nameof(InputEvents), nameof(InputEvents.ButtonReleased)); this.Legacy_Location_LocationsChanged = ManageEventOf(nameof(LocationEvents), nameof(LocationEvents.LocationsChanged)); this.Legacy_Location_BuildingsChanged = ManageEventOf(nameof(LocationEvents), nameof(LocationEvents.BuildingsChanged)); this.Legacy_Location_ObjectsChanged = ManageEventOf(nameof(LocationEvents), nameof(LocationEvents.ObjectsChanged)); this.Menu_Changed = ManageEventOf(nameof(MenuEvents), nameof(MenuEvents.MenuChanged)); this.Menu_Closed = ManageEventOf(nameof(MenuEvents), nameof(MenuEvents.MenuClosed)); this.Multiplayer_BeforeMainBroadcast = ManageEvent(nameof(MultiplayerEvents), nameof(MultiplayerEvents.BeforeMainBroadcast)); this.Multiplayer_AfterMainBroadcast = ManageEvent(nameof(MultiplayerEvents), nameof(MultiplayerEvents.AfterMainBroadcast)); this.Multiplayer_BeforeMainSync = ManageEvent(nameof(MultiplayerEvents), nameof(MultiplayerEvents.BeforeMainSync)); this.Multiplayer_AfterMainSync = ManageEvent(nameof(MultiplayerEvents), nameof(MultiplayerEvents.AfterMainSync)); this.Mine_LevelChanged = ManageEventOf(nameof(MineEvents), nameof(MineEvents.MineLevelChanged)); this.Player_InventoryChanged = ManageEventOf(nameof(PlayerEvents), nameof(PlayerEvents.InventoryChanged)); this.Player_LeveledUp = ManageEventOf(nameof(PlayerEvents), nameof(PlayerEvents.LeveledUp)); this.Player_Warped = ManageEventOf(nameof(PlayerEvents), nameof(PlayerEvents.Warped)); this.Save_BeforeCreate = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.BeforeCreate)); this.Save_AfterCreate = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.AfterCreate)); this.Save_BeforeSave = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.BeforeSave)); this.Save_AfterSave = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.AfterSave)); this.Save_AfterLoad = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.AfterLoad)); this.Save_AfterReturnToTitle = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.AfterReturnToTitle)); this.Specialised_UnvalidatedUpdateTick = ManageEvent(nameof(SpecialisedEvents), nameof(SpecialisedEvents.UnvalidatedUpdateTick)); this.Time_AfterDayStarted = ManageEvent(nameof(TimeEvents), nameof(TimeEvents.AfterDayStarted)); this.Time_TimeOfDayChanged = ManageEventOf(nameof(TimeEvents), nameof(TimeEvents.TimeOfDayChanged)); } } }