Started work on new mod to add map events with code.

This commit is contained in:
2018-02-22 11:43:18 -08:00
parent aa71ab8ec4
commit bebcefa765
11 changed files with 499 additions and 0 deletions

View File

@ -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)
{
}
}
}

View File

@ -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<object> parameters);
}
}

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MapEvents.Framework.FunctionEvents
{
/// <summary>
/// Used to handle mouse interactions with button clicks and scrolling the mouse wheel.
/// </summary>
class MouseButtonEvents
{
/// <summary>
/// Function that runs when the user left clicks.
/// </summary>
public functionEvent onLeftClick;
/// <summary>
/// Function that runs when the user right clicks.
/// </summary>
public functionEvent onRightClick;
/// <summary>
/// Function that runs when the user scrolls the mouse wheel.
/// </summary>
public functionEvent onMouseScroll;
/// <summary>
/// A constructor used to set a single function to a mouse button.
/// </summary>
/// <param name="clickFunction"></param>
/// <param name="leftClick">If true the function is set to the left click. If false the function is set to the right click.</param>
public MouseButtonEvents(functionEvent clickFunction, bool leftClick)
{
if (leftClick == true) this.onLeftClick = clickFunction;
else this.onRightClick = clickFunction;
}
/// <summary>
/// A constructor used to map functions to mouse clicks.
/// </summary>
/// <param name="OnLeftClick">A function to be ran when the mouse left clicks this position.</param>
/// <param name="OnRightClick">A function to be ran when the mouse right clicks this position.</param>
public MouseButtonEvents(functionEvent OnLeftClick, functionEvent OnRightClick)
{
this.onLeftClick = OnLeftClick;
this.onRightClick = OnRightClick;
}
/// <summary>
/// A constructor used to map functions to mouse clicks and scrolling the mouse wheel.
/// </summary>
/// <param name="OnLeftClick">A function to be ran when the mouse left clicks this position.</param>
/// <param name="OnRightClick">A function to be ran when the mouse right clicks this position.</param>
/// <param name="OnMouseScroll">A function to be ran when the user scrolls the mouse</param>
public MouseButtonEvents(functionEvent OnLeftClick,functionEvent OnRightClick, functionEvent OnMouseScroll)
{
this.onLeftClick = OnLeftClick;
this.onRightClick = OnRightClick;
this.onMouseScroll = OnMouseScroll;
}
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MapEvents.Framework.FunctionEvents
{
/// <summary>
/// Used to handle events that happens when a mouse enters/leaves a specified position.
/// </summary>
class MouseEntryLeaveEvent
{
/// <summary>
/// A function that is called when a mouse enters a certain position.
/// </summary>
public functionEvent onMouseEnter;
/// <summary>
/// A function that is called when a mouse leaves a certain position.
/// </summary>
public functionEvent onMouseLeave;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="OnMouseEnter">The function that occurs when the mouse enters a certain position.</param>
/// <param name="OnMouseLeave">The function that occurs when the mouse leaves a certain position.</param>
public MouseEntryLeaveEvent(functionEvent OnMouseEnter, functionEvent OnMouseLeave)
{
this.onMouseEnter = OnMouseEnter;
this.onMouseLeave = OnMouseLeave;
}
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MapEvents.Framework.FunctionEvents
{
/// <summary>
/// Used to handle various functions that occur on player interaction.
/// </summary>
class PlayerEvents
{
/// <summary>
/// Occurs when the player enters the same tile as this event.
/// </summary>
public functionEvent onPlayerEnter;
/// <summary>
/// Occurs when the player leaves the same tile as this event.
/// </summary>
public functionEvent onPlayerLeave;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="OnPlayerEnter"></param>
/// <param name="OnPlayerLeave"></param>
public PlayerEvents(functionEvent OnPlayerEnter, functionEvent OnPlayerLeave)
{
this.onPlayerEnter = OnPlayerEnter;
this.onPlayerLeave = OnPlayerLeave;
}
}
}

View File

@ -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
{
/// <summary>
/// Used to pair a function and a parameter list using the super object class to run virtually any function for map events.
/// </summary>
class functionEvent
{
public paramFunction function;
public List<object> parameters;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="Function">The function to be called when running an event.</param>
/// <param name="Parameters">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.</param>
public functionEvent(paramFunction Function, List<object> Parameters)
{
if (this.parameters == null) this.parameters = new List<object>();
this.function = Function;
this.parameters = Parameters;
}
/// <summary>
/// Runs the function with the passed in parameters.
/// </summary>
public void run()
{
this.function.Invoke(this.parameters);
}
/// <summary>
/// Simply swaps out the old parameters list for a new one.
/// </summary>
/// <param name="newParameters"></param>
public void updateParameters(List<object> newParameters)
{
this.parameters = newParameters;
}
}
}

View File

@ -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
{
/// <summary>
/// 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<Loc.List<Events>>
/// </summary>
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;
/// <summary>
/// A simple map event that doesn't do anything.
/// </summary>
/// <param name="Location"></param>
/// <param name="Position"></param>
public MapEvent(GameLocation Location,Vector2 Position)
{
this.location = Location;
this.tilePosition = Position;
}
/// <summary>
/// Empty Constructor
/// </summary>
public MapEvent()
{
}
/// <summary>
/// A simple map function that runs when the player enters and leaves a tile. Set values to null for nothing to happen.
/// </summary>
/// <param name="Location">The game location where the event is. I.E Farm, Town, Mine etc.</param>
/// <param name="position">The x,y position on the map the event is.</param>
/// <param name="PlayerEvents">Handles various events that runs when the player enters/leaves a tile, etc.</param>
public MapEvent(GameLocation Location,Vector2 position, PlayerEvents PlayerEvents)
{
this.location = Location;
this.tilePosition = position;
this.playerEvents = PlayerEvents;
}
/// <summary>
/// A constructor that handles when the mouse leaves and enters a tile.
/// </summary>
/// <param name="Location">The game location where the event is.</param>
/// <param name="Position">The x,y position of the tile at the game location.</param>
/// <param name="mouseEvents">A class used to handle mouse entry/leave events.</param>
public MapEvent(GameLocation Location, Vector2 Position, MouseEntryLeaveEvent mouseEvents)
{
this.location = Location;
this.tilePosition = Position;
this.mouseEntryLeaveEvents = mouseEvents;
}
/// <summary>
/// A constructor that handles when the mouse leaves and enters a tile.
/// </summary>
/// <param name="Location">The game location where the event is.</param>
/// <param name="Position">The x,y position of the tile at the game location.</param>
/// <param name="mouseEvents">A class used to handle mouse click/scroll events.</param>
public MapEvent(GameLocation Location, Vector2 Position, MouseButtonEvents mouseEvents)
{
this.location = Location;
this.tilePosition = Position;
this.mouseButtonEvents = mouseEvents;
}
/// <summary>
/// Occurs when the player enters the same tile as this event. The function associated with this event is then ran.
/// </summary>
public void OnPlayerEnter()
{
this.playerOnTile = true;
if (this.playerEvents.onPlayerEnter != null) this.playerEvents.onPlayerEnter.run();
}
/// <summary>
/// Occurs when the player leaves the same tile that this event is on. The function associated with thie event is then ran.
/// </summary>
public void OnPlayerLeave()
{
this.playerOnTile = false;
if (this.playerEvents.onPlayerLeave != null) this.playerEvents.onPlayerEnter.run();
}
/// <summary>
/// Occurs when the player left clicks the same tile that this event is on.
/// </summary>
public void OnLeftClick()
{
if (this.mouseButtonEvents.onLeftClick != null) this.mouseButtonEvents.onLeftClick.run();
}
/// <summary>
/// Occurs when the player right clicks the same tile that this event is on.
/// </summary>
public void OnRightClick()
{
if (this.mouseButtonEvents.onRightClick != null) this.mouseButtonEvents.onRightClick.run();
}
/// <summary>
/// Occurs when the mouse tile position is the same as this event's x,y position.
/// </summary>
public void OnMouseEnter()
{
this.mouseOnTile = true;
if (this.mouseEntryLeaveEvents.onMouseEnter != null) this.mouseEntryLeaveEvents.onMouseEnter.run();
}
/// <summary>
/// Occurs when the mouse tile position leaves the the same x,y position as this event.
/// </summary>
public void OnMouseLeave()
{
this.mouseOnTile = false;
if (this.mouseEntryLeaveEvents.onMouseLeave != null) this.mouseEntryLeaveEvents.onMouseLeave.run();
}
/// <summary>
/// Occurs when the mouse is on the same position as the tile AND the user scrolls the mouse wheel.
/// </summary>
public void OnMouseScroll()
{
if (this.mouseButtonEvents.onMouseScroll != null) this.mouseButtonEvents.onMouseScroll.run();
}
/// <summary>
/// Checks if the player is on the same tile as this event.
/// </summary>
/// <returns></returns>
public bool isPlayerOnTile()
{
if (Game1.player.getTileX() == this.tilePosition.X && Game1.player.getTileY() == this.tilePosition.Y) return true;
else return false;
}
/// <summary>
/// Checks if the player is on the same tile as the event and then runs the associated event.
/// </summary>
public void isPlayerOnTileRunEvent()
{
if (isPlayerOnTile() == true) OnPlayerEnter();
}
/// <summary>
/// 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.
/// </summary>
public void didPlayerLeaveTileRunEvent()
{
if (this.playerOnTile == true && isPlayerOnTile() == false) this.OnPlayerLeave();
}
}
}

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BB737337-2D82-4245-AA46-F3B82FC6F228}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MapEvents</RootNamespace>
<AssemblyName>MapEvents</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.2.0.2\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -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")]

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Pathoschild.Stardew.ModBuildConfig" version="2.0.2" targetFramework="net45" />
</packages>

View File

@ -45,6 +45,8 @@
<Compile Include="Animations\Animation.cs" />
<Compile Include="Animations\AnimationManager.cs" />
<Compile Include="IlluminateFramework\Colors.cs" />
<Compile Include="Math\Hex.cs" />
<Compile Include="Math\Hex32.cs" />
<Compile Include="UIUtilities\LayeredTexture.cs" />
<Compile Include="UIUtilities\SpriteFonts\CharacterSheets\GenericCharacterSheets.cs" />
<Compile Include="UIUtilities\SpriteFonts\CharacterSheets\VanillaCharacterSheet.cs" />