From bebcefa76517daa7778275af2df2f27f1657815a Mon Sep 17 00:00:00 2001 From: Date: Thu, 22 Feb 2018 11:43:18 -0800 Subject: [PATCH] Started work on new mod to add map events with code. --- GeneralMods/MapEvents/Class1.cs | 17 ++ GeneralMods/MapEvents/Framework/Delegates.cs | 15 ++ .../FunctionEvents/MouseButtonEvents.cs | 62 ++++++ .../FunctionEvents/MouseEntryLeaveEvent.cs | 34 ++++ .../Framework/FunctionEvents/PlayerEvents.cs | 34 ++++ .../Framework/FunctionEvents/functionEvent.cs | 47 +++++ GeneralMods/MapEvents/Framework/MapEvent.cs | 187 ++++++++++++++++++ GeneralMods/MapEvents/MapEvents.csproj | 61 ++++++ .../MapEvents/Properties/AssemblyInfo.cs | 36 ++++ GeneralMods/MapEvents/packages.config | 4 + GeneralMods/StardustCore/StardustCore.csproj | 2 + 11 files changed, 499 insertions(+) create mode 100644 GeneralMods/MapEvents/Class1.cs create mode 100644 GeneralMods/MapEvents/Framework/Delegates.cs create mode 100644 GeneralMods/MapEvents/Framework/FunctionEvents/MouseButtonEvents.cs create mode 100644 GeneralMods/MapEvents/Framework/FunctionEvents/MouseEntryLeaveEvent.cs create mode 100644 GeneralMods/MapEvents/Framework/FunctionEvents/PlayerEvents.cs create mode 100644 GeneralMods/MapEvents/Framework/FunctionEvents/functionEvent.cs create mode 100644 GeneralMods/MapEvents/Framework/MapEvent.cs create mode 100644 GeneralMods/MapEvents/MapEvents.csproj create mode 100644 GeneralMods/MapEvents/Properties/AssemblyInfo.cs create mode 100644 GeneralMods/MapEvents/packages.config diff --git a/GeneralMods/MapEvents/Class1.cs b/GeneralMods/MapEvents/Class1.cs new file mode 100644 index 00000000..7dadf81e --- /dev/null +++ b/GeneralMods/MapEvents/Class1.cs @@ -0,0 +1,17 @@ +using StardewModdingAPI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MapEvents +{ + public class MapEvents: Mod + { + public override void Entry(IModHelper helper) + { + + } + } +} diff --git a/GeneralMods/MapEvents/Framework/Delegates.cs b/GeneralMods/MapEvents/Framework/Delegates.cs new file mode 100644 index 00000000..206d1294 --- /dev/null +++ b/GeneralMods/MapEvents/Framework/Delegates.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MapEvents.Framework +{ + class Delegates + { + public delegate void voidDel(); + public delegate void strDel(string s); + public delegate void paramFunction(List parameters); + } +} diff --git a/GeneralMods/MapEvents/Framework/FunctionEvents/MouseButtonEvents.cs b/GeneralMods/MapEvents/Framework/FunctionEvents/MouseButtonEvents.cs new file mode 100644 index 00000000..e44ae354 --- /dev/null +++ b/GeneralMods/MapEvents/Framework/FunctionEvents/MouseButtonEvents.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MapEvents.Framework.FunctionEvents +{ + /// + /// Used to handle mouse interactions with button clicks and scrolling the mouse wheel. + /// + class MouseButtonEvents + { + /// + /// Function that runs when the user left clicks. + /// + public functionEvent onLeftClick; + /// + /// Function that runs when the user right clicks. + /// + public functionEvent onRightClick; + /// + /// Function that runs when the user scrolls the mouse wheel. + /// + public functionEvent onMouseScroll; + + /// + /// A constructor used to set a single function to a mouse button. + /// + /// + /// If true the function is set to the left click. If false the function is set to the right click. + public MouseButtonEvents(functionEvent clickFunction, bool leftClick) + { + if (leftClick == true) this.onLeftClick = clickFunction; + else this.onRightClick = clickFunction; + } + + /// + /// A constructor used to map functions to mouse clicks. + /// + /// A function to be ran when the mouse left clicks this position. + /// A function to be ran when the mouse right clicks this position. + public MouseButtonEvents(functionEvent OnLeftClick, functionEvent OnRightClick) + { + this.onLeftClick = OnLeftClick; + this.onRightClick = OnRightClick; + } + + /// + /// A constructor used to map functions to mouse clicks and scrolling the mouse wheel. + /// + /// A function to be ran when the mouse left clicks this position. + /// A function to be ran when the mouse right clicks this position. + /// A function to be ran when the user scrolls the mouse + public MouseButtonEvents(functionEvent OnLeftClick,functionEvent OnRightClick, functionEvent OnMouseScroll) + { + this.onLeftClick = OnLeftClick; + this.onRightClick = OnRightClick; + this.onMouseScroll = OnMouseScroll; + } + } +} diff --git a/GeneralMods/MapEvents/Framework/FunctionEvents/MouseEntryLeaveEvent.cs b/GeneralMods/MapEvents/Framework/FunctionEvents/MouseEntryLeaveEvent.cs new file mode 100644 index 00000000..dd8487f7 --- /dev/null +++ b/GeneralMods/MapEvents/Framework/FunctionEvents/MouseEntryLeaveEvent.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MapEvents.Framework.FunctionEvents +{ + /// + /// Used to handle events that happens when a mouse enters/leaves a specified position. + /// + class MouseEntryLeaveEvent + { + /// + /// A function that is called when a mouse enters a certain position. + /// + public functionEvent onMouseEnter; + /// + /// A function that is called when a mouse leaves a certain position. + /// + public functionEvent onMouseLeave; + + /// + /// Constructor. + /// + /// The function that occurs when the mouse enters a certain position. + /// The function that occurs when the mouse leaves a certain position. + public MouseEntryLeaveEvent(functionEvent OnMouseEnter, functionEvent OnMouseLeave) + { + this.onMouseEnter = OnMouseEnter; + this.onMouseLeave = OnMouseLeave; + } + } +} diff --git a/GeneralMods/MapEvents/Framework/FunctionEvents/PlayerEvents.cs b/GeneralMods/MapEvents/Framework/FunctionEvents/PlayerEvents.cs new file mode 100644 index 00000000..382e7bc0 --- /dev/null +++ b/GeneralMods/MapEvents/Framework/FunctionEvents/PlayerEvents.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MapEvents.Framework.FunctionEvents +{ + /// + /// Used to handle various functions that occur on player interaction. + /// + class PlayerEvents + { + /// + /// Occurs when the player enters the same tile as this event. + /// + public functionEvent onPlayerEnter; + /// + /// Occurs when the player leaves the same tile as this event. + /// + public functionEvent onPlayerLeave; + + /// + /// Constructor. + /// + /// + /// + public PlayerEvents(functionEvent OnPlayerEnter, functionEvent OnPlayerLeave) + { + this.onPlayerEnter = OnPlayerEnter; + this.onPlayerLeave = OnPlayerLeave; + } + } +} diff --git a/GeneralMods/MapEvents/Framework/FunctionEvents/functionEvent.cs b/GeneralMods/MapEvents/Framework/FunctionEvents/functionEvent.cs new file mode 100644 index 00000000..d1487719 --- /dev/null +++ b/GeneralMods/MapEvents/Framework/FunctionEvents/functionEvent.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static MapEvents.Framework.Delegates; + +namespace MapEvents.Framework +{ + /// + /// Used to pair a function and a parameter list using the super object class to run virtually any function for map events. + /// + class functionEvent + { + public paramFunction function; + public List parameters; + + /// + /// Constructor. + /// + /// The function to be called when running an event. + /// The list of system.objects to be used in the function. Can include objects,strings, ints, etc. Anything can be passed in as a parameter or can be passed in as empty. Passing in null will just create an empty list. + public functionEvent(paramFunction Function, List Parameters) + { + if (this.parameters == null) this.parameters = new List(); + this.function = Function; + this.parameters = Parameters; + } + + /// + /// Runs the function with the passed in parameters. + /// + public void run() + { + this.function.Invoke(this.parameters); + } + + /// + /// Simply swaps out the old parameters list for a new one. + /// + /// + public void updateParameters(List newParameters) + { + this.parameters = newParameters; + } + } +} diff --git a/GeneralMods/MapEvents/Framework/MapEvent.cs b/GeneralMods/MapEvents/Framework/MapEvent.cs new file mode 100644 index 00000000..38f549a2 --- /dev/null +++ b/GeneralMods/MapEvents/Framework/MapEvent.cs @@ -0,0 +1,187 @@ +using MapEvents.Framework.FunctionEvents; +using Microsoft.Xna.Framework; +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static MapEvents.Framework.Delegates; + +namespace MapEvents.Framework +{ + class MapEvent + { + /// + /// Make constructor that takes all parameters for a function. + /// Make an update function that runs associated functions to check which events need to be ran. + /// + /// //MAKE A MAP EVENT MANAGER TO HOLD GAME LOCATIONS AND A LIST OF MAP EVENTS!!!!!! Dic> + /// + + + public Vector2 tilePosition; + public GameLocation location; + + public PlayerEvents playerEvents; + + public bool playerOnTile; + + + public MouseButtonEvents mouseButtonEvents; + public MouseEntryLeaveEvent mouseEntryLeaveEvents; + public bool mouseOnTile; + + + + public bool doesInteractionNeedToRun; + public bool loopInteraction; + + /// + /// A simple map event that doesn't do anything. + /// + /// + /// + public MapEvent(GameLocation Location,Vector2 Position) + { + this.location = Location; + this.tilePosition = Position; + } + + /// + /// Empty Constructor + /// + public MapEvent() + { + + } + + + /// + /// A simple map function that runs when the player enters and leaves a tile. Set values to null for nothing to happen. + /// + /// The game location where the event is. I.E Farm, Town, Mine etc. + /// The x,y position on the map the event is. + /// Handles various events that runs when the player enters/leaves a tile, etc. + + public MapEvent(GameLocation Location,Vector2 position, PlayerEvents PlayerEvents) + { + this.location = Location; + this.tilePosition = position; + this.playerEvents = PlayerEvents; + } + + /// + /// A constructor that handles when the mouse leaves and enters a tile. + /// + /// The game location where the event is. + /// The x,y position of the tile at the game location. + /// A class used to handle mouse entry/leave events. + public MapEvent(GameLocation Location, Vector2 Position, MouseEntryLeaveEvent mouseEvents) + { + this.location = Location; + this.tilePosition = Position; + this.mouseEntryLeaveEvents = mouseEvents; + } + + /// + /// A constructor that handles when the mouse leaves and enters a tile. + /// + /// The game location where the event is. + /// The x,y position of the tile at the game location. + /// A class used to handle mouse click/scroll events. + public MapEvent(GameLocation Location, Vector2 Position, MouseButtonEvents mouseEvents) + { + this.location = Location; + this.tilePosition = Position; + this.mouseButtonEvents = mouseEvents; + } + + /// + /// Occurs when the player enters the same tile as this event. The function associated with this event is then ran. + /// + public void OnPlayerEnter() + { + this.playerOnTile = true; + if (this.playerEvents.onPlayerEnter != null) this.playerEvents.onPlayerEnter.run(); + } + + /// + /// Occurs when the player leaves the same tile that this event is on. The function associated with thie event is then ran. + /// + public void OnPlayerLeave() + { + this.playerOnTile = false; + if (this.playerEvents.onPlayerLeave != null) this.playerEvents.onPlayerEnter.run(); + } + + /// + /// Occurs when the player left clicks the same tile that this event is on. + /// + public void OnLeftClick() + { + if (this.mouseButtonEvents.onLeftClick != null) this.mouseButtonEvents.onLeftClick.run(); + } + + /// + /// Occurs when the player right clicks the same tile that this event is on. + /// + public void OnRightClick() + { + if (this.mouseButtonEvents.onRightClick != null) this.mouseButtonEvents.onRightClick.run(); + } + + /// + /// Occurs when the mouse tile position is the same as this event's x,y position. + /// + public void OnMouseEnter() + { + this.mouseOnTile = true; + if (this.mouseEntryLeaveEvents.onMouseEnter != null) this.mouseEntryLeaveEvents.onMouseEnter.run(); + } + + /// + /// Occurs when the mouse tile position leaves the the same x,y position as this event. + /// + public void OnMouseLeave() + { + this.mouseOnTile = false; + if (this.mouseEntryLeaveEvents.onMouseLeave != null) this.mouseEntryLeaveEvents.onMouseLeave.run(); + } + + /// + /// Occurs when the mouse is on the same position as the tile AND the user scrolls the mouse wheel. + /// + public void OnMouseScroll() + { + if (this.mouseButtonEvents.onMouseScroll != null) this.mouseButtonEvents.onMouseScroll.run(); + } + + /// + /// Checks if the player is on the same tile as this event. + /// + /// + public bool isPlayerOnTile() + { + if (Game1.player.getTileX() == this.tilePosition.X && Game1.player.getTileY() == this.tilePosition.Y) return true; + else return false; + } + + /// + /// Checks if the player is on the same tile as the event and then runs the associated event. + /// + public void isPlayerOnTileRunEvent() + { + if (isPlayerOnTile() == true) OnPlayerEnter(); + } + + /// + /// If the player recently entered the tile and the player is no longer on this tile then the player left the tile. If that is true then run the leaving function. + /// + public void didPlayerLeaveTileRunEvent() + { + if (this.playerOnTile == true && isPlayerOnTile() == false) this.OnPlayerLeave(); + } + + } +} diff --git a/GeneralMods/MapEvents/MapEvents.csproj b/GeneralMods/MapEvents/MapEvents.csproj new file mode 100644 index 00000000..f01a7780 --- /dev/null +++ b/GeneralMods/MapEvents/MapEvents.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {BB737337-2D82-4245-AA46-F3B82FC6F228} + Library + Properties + MapEvents + MapEvents + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/GeneralMods/MapEvents/Properties/AssemblyInfo.cs b/GeneralMods/MapEvents/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..374e3112 --- /dev/null +++ b/GeneralMods/MapEvents/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MapEvents")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MapEvents")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("bb737337-2d82-4245-aa46-f3b82fc6f228")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GeneralMods/MapEvents/packages.config b/GeneralMods/MapEvents/packages.config new file mode 100644 index 00000000..028670c6 --- /dev/null +++ b/GeneralMods/MapEvents/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/GeneralMods/StardustCore/StardustCore.csproj b/GeneralMods/StardustCore/StardustCore.csproj index a599906b..9d1d2321 100644 --- a/GeneralMods/StardustCore/StardustCore.csproj +++ b/GeneralMods/StardustCore/StardustCore.csproj @@ -45,6 +45,8 @@ + +