From afef5648ca512d0c151a87becbb85cd14494717b Mon Sep 17 00:00:00 2001 From: ClxS Date: Fri, 4 Mar 2016 14:05:36 +0000 Subject: Refactored all of the events into their own categories --- StardewModdingAPI/Events/Controls.cs | 31 +++++++++ StardewModdingAPI/Events/EventArgs.cs | 126 ++++++++++++++++++++++++++++++++++ StardewModdingAPI/Events/Game.cs | 57 +++++++++++++++ StardewModdingAPI/Events/Graphics.cs | 31 +++++++++ StardewModdingAPI/Events/Location.cs | 32 +++++++++ StardewModdingAPI/Events/Menu.cs | 19 +++++ StardewModdingAPI/Events/Mine.cs | 12 ++++ StardewModdingAPI/Events/Player.cs | 19 +++++ StardewModdingAPI/Events/Time.cs | 36 ++++++++++ 9 files changed, 363 insertions(+) create mode 100644 StardewModdingAPI/Events/Controls.cs create mode 100644 StardewModdingAPI/Events/EventArgs.cs create mode 100644 StardewModdingAPI/Events/Game.cs create mode 100644 StardewModdingAPI/Events/Graphics.cs create mode 100644 StardewModdingAPI/Events/Location.cs create mode 100644 StardewModdingAPI/Events/Menu.cs create mode 100644 StardewModdingAPI/Events/Mine.cs create mode 100644 StardewModdingAPI/Events/Player.cs create mode 100644 StardewModdingAPI/Events/Time.cs (limited to 'StardewModdingAPI/Events') diff --git a/StardewModdingAPI/Events/Controls.cs b/StardewModdingAPI/Events/Controls.cs new file mode 100644 index 00000000..ace890ca --- /dev/null +++ b/StardewModdingAPI/Events/Controls.cs @@ -0,0 +1,31 @@ +using Microsoft.Xna.Framework.Input; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Events +{ + public static class ControlEvents + { + public static event EventHandler KeyboardChanged = delegate { }; + public static event EventHandler KeyPressed = delegate { }; + public static event EventHandler MouseChanged = delegate { }; + + public static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) + { + KeyboardChanged.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); + } + + public static void InvokeMouseChanged(MouseState priorState, MouseState newState) + { + MouseChanged.Invoke(null, new EventArgsMouseStateChanged(priorState, newState)); + } + + public static void InvokeKeyPressed(Keys key) + { + KeyPressed.Invoke(null, new EventArgsKeyPressed(key)); + } + } +} diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs new file mode 100644 index 00000000..c9055f84 --- /dev/null +++ b/StardewModdingAPI/Events/EventArgs.cs @@ -0,0 +1,126 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; +using StardewValley; +using StardewValley.Menus; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Events +{ + public class EventArgsKeyboardStateChanged : EventArgs + { + public EventArgsKeyboardStateChanged(KeyboardState priorState, KeyboardState newState) + { + NewState = newState; + NewState = newState; + } + public KeyboardState NewState { get; private set; } + public KeyboardState PriorState { get; private set; } + } + + public class EventArgsKeyPressed : EventArgs + { + public EventArgsKeyPressed(Keys keyPressed) + { + KeyPressed = keyPressed; + } + public Keys KeyPressed { get; private set; } + } + + public class EventArgsMouseStateChanged : EventArgs + { + public EventArgsMouseStateChanged(MouseState priorState, MouseState newState) + { + NewState = newState; + NewState = newState; + } + public MouseState NewState { get; private set; } + public MouseState PriorState { get; private set; } + } + + public class EventArgsClickableMenuChanged : EventArgs + { + public EventArgsClickableMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + { + NewMenu = newMenu; + PriorMenu = priorMenu; + } + public IClickableMenu NewMenu { get; private set; } + public IClickableMenu PriorMenu { get; private set; } + } + + public class EventArgsGameLocationsChanged : EventArgs + { + public EventArgsGameLocationsChanged(List newLocations) + { + NewLocations = newLocations; + } + public List NewLocations { get; private set; } + } + + public class EventArgsLocationObjectsChanged : EventArgs + { + public EventArgsLocationObjectsChanged(SerializableDictionary newObjects) + { + NewObjects = newObjects; + } + public SerializableDictionary NewObjects { get; private set; } + } + + public class EventArgsCurrentLocationChanged : EventArgs + { + public EventArgsCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + { + NewLocation = newLocation; + PriorLocation = priorLocation; + } + public GameLocation NewLocation { get; private set; } + public GameLocation PriorLocation { get; private set; } + } + + public class EventArgsFarmerChanged : EventArgs + { + public EventArgsFarmerChanged(Farmer priorFarmer, Farmer newFarmer) + { + NewFarmer = NewFarmer; + PriorFarmer = PriorFarmer; + } + public Farmer NewFarmer { get; private set; } + public Farmer PriorFarmer { get; private set; } + } + + public class EventArgsIntChanged : EventArgs + { + public EventArgsIntChanged(Int32 priorInt, Int32 newInt) + { + NewInt = NewInt; + PriorInt = PriorInt; + } + public Int32 NewInt { get; private set; } + public Int32 PriorInt { get; private set; } + } + + public class EventArgsStringChanged : EventArgs + { + public EventArgsStringChanged(String priorString, String newString) + { + NewString = newString; + PriorString = priorString; + } + public String NewString { get; private set; } + public String PriorString { get; private set; } + } + + public class EventArgsCommand : EventArgs + { + public EventArgsCommand(Command command) + { + Command = command; + } + public Command Command { get; private set; } + } +} + diff --git a/StardewModdingAPI/Events/Game.cs b/StardewModdingAPI/Events/Game.cs new file mode 100644 index 00000000..d155ba2e --- /dev/null +++ b/StardewModdingAPI/Events/Game.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Events +{ + public static class GameEvents + { + public static event EventHandler GameLoaded = delegate { }; + public static event EventHandler Initialize = delegate { }; + public static event EventHandler LoadContent = delegate { }; + public static event EventHandler UpdateTick = delegate { }; + + public static void InvokeGameLoaded() + { + GameLoaded.Invoke(null, EventArgs.Empty); + } + + public static void InvokeInitialize() + { + try + { + Initialize.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Program.LogError("An exception occured in XNA Initialize: " + ex.ToString()); + } + } + + public static void InvokeLoadContent() + { + try + { + LoadContent.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Program.LogError("An exception occured in XNA LoadContent: " + ex.ToString()); + } + } + + public static void InvokeUpdateTick() + { + try + { + UpdateTick.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Program.LogError("An exception occured in XNA UpdateTick: " + ex.ToString()); + } + } + } +} diff --git a/StardewModdingAPI/Events/Graphics.cs b/StardewModdingAPI/Events/Graphics.cs new file mode 100644 index 00000000..62bffe82 --- /dev/null +++ b/StardewModdingAPI/Events/Graphics.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Events +{ + public static class GraphicsEvents + { + public static event EventHandler Resize = delegate { }; + public static event EventHandler DrawTick = delegate { }; + + public static void InvokeDrawTick() + { + try + { + DrawTick.Invoke(null, EventArgs.Empty); + } + catch (Exception ex) + { + Program.LogError("An exception occured in XNA DrawTick: " + ex.ToString()); + } + } + + public static void InvokeResize(object sender, EventArgs e) + { + Resize.Invoke(sender, e); + } + } +} diff --git a/StardewModdingAPI/Events/Location.cs b/StardewModdingAPI/Events/Location.cs new file mode 100644 index 00000000..c347659b --- /dev/null +++ b/StardewModdingAPI/Events/Location.cs @@ -0,0 +1,32 @@ +using Microsoft.Xna.Framework; +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Events +{ + public static class LocationEvents + { + public static event EventHandler LocationsChanged = delegate { }; + public static event EventHandler LocationObjectsChanged = delegate { }; + public static event EventHandler CurrentLocationChanged = delegate { }; + + public static void InvokeLocationsChanged(List newLocations) + { + LocationsChanged.Invoke(null, new EventArgsGameLocationsChanged(newLocations)); + } + + public static void InvokeCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + { + CurrentLocationChanged.Invoke(null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); + } + + internal static void InvokeOnNewLocationObject(SerializableDictionary newObjects) + { + LocationObjectsChanged.Invoke(null, new EventArgsLocationObjectsChanged(newObjects)); + } + } +} diff --git a/StardewModdingAPI/Events/Menu.cs b/StardewModdingAPI/Events/Menu.cs new file mode 100644 index 00000000..0819fb20 --- /dev/null +++ b/StardewModdingAPI/Events/Menu.cs @@ -0,0 +1,19 @@ +using StardewValley.Menus; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Events +{ + public static class MenuEvents + { + public static event EventHandler MenuChanged = delegate { }; + + public static void InvokeMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + { + MenuChanged.Invoke(null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); + } + } +} diff --git a/StardewModdingAPI/Events/Mine.cs b/StardewModdingAPI/Events/Mine.cs new file mode 100644 index 00000000..67f1e2c1 --- /dev/null +++ b/StardewModdingAPI/Events/Mine.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Events +{ + public static class MineEvents + { + } +} diff --git a/StardewModdingAPI/Events/Player.cs b/StardewModdingAPI/Events/Player.cs new file mode 100644 index 00000000..3fa5c806 --- /dev/null +++ b/StardewModdingAPI/Events/Player.cs @@ -0,0 +1,19 @@ +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Events +{ + public static class PlayerEvents + { + public static event EventHandler FarmerChanged = delegate { }; + + public static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) + { + FarmerChanged.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); + } + } +} diff --git a/StardewModdingAPI/Events/Time.cs b/StardewModdingAPI/Events/Time.cs new file mode 100644 index 00000000..fcf0b3e5 --- /dev/null +++ b/StardewModdingAPI/Events/Time.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Events +{ + public static class TimeEvents + { + public static event EventHandler TimeOfDayChanged = delegate { }; + public static event EventHandler DayOfMonthChanged = delegate { }; + public static event EventHandler YearOfGameChanged = delegate { }; + public static event EventHandler SeasonOfYearChanged = delegate { }; + + public static void InvokeTimeOfDayChanged(Int32 priorInt, Int32 newInt) + { + TimeOfDayChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } + + public static void InvokeDayOfMonthChanged(Int32 priorInt, Int32 newInt) + { + DayOfMonthChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } + + public static void InvokeYearOfGameChanged(Int32 priorInt, Int32 newInt) + { + YearOfGameChanged.Invoke(null, new EventArgsIntChanged(priorInt, newInt)); + } + + public static void InvokeSeasonOfYearChanged(String priorString, String newString) + { + SeasonOfYearChanged.Invoke(null, new EventArgsStringChanged(priorString, newString)); + } + } +} -- cgit