2018-02-24 05:55:51 +08:00
|
|
|
|
using EventSystem.Framework.FunctionEvents;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
using Microsoft.Xna.Framework;
|
2018-02-24 05:55:51 +08:00
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
using StardewValley;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-02-24 05:55:51 +08:00
|
|
|
|
namespace EventSystem.Framework
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-02-24 05:55:51 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Base class used to handle map tile events.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MapEvent
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
/// //MAKE NAME FOR EVENTS
|
2018-02-23 03:43:18 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
2018-02-24 05:55:51 +08:00
|
|
|
|
public string name;
|
|
|
|
|
|
2018-02-23 03:43:18 +08:00
|
|
|
|
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;
|
|
|
|
|
|
2018-02-24 05:55:51 +08:00
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
Constructors
|
|
|
|
|
|
|
|
|
|
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
*/
|
|
|
|
|
#region
|
|
|
|
|
|
2018-02-23 03:43:18 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Empty Constructor
|
|
|
|
|
/// </summary>
|
|
|
|
|
public MapEvent()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-24 05:55:51 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A simple map event that doesn't do anything.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Location"></param>
|
|
|
|
|
/// <param name="Position"></param>
|
|
|
|
|
public MapEvent(string name,GameLocation Location,Vector2 Position)
|
|
|
|
|
{
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.location = Location;
|
|
|
|
|
this.tilePosition = Position;
|
|
|
|
|
}
|
2018-02-23 03:43:18 +08:00
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
|
2018-02-24 05:55:51 +08:00
|
|
|
|
public MapEvent(string name,GameLocation Location,Vector2 position, PlayerEvents PlayerEvents)
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-02-24 05:55:51 +08:00
|
|
|
|
this.name = name;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
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>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
public MapEvent(string name,GameLocation Location, Vector2 Position, MouseEntryLeaveEvent mouseEvents)
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-02-24 05:55:51 +08:00
|
|
|
|
this.name = name;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
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>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
public MapEvent(string name,GameLocation Location, Vector2 Position, MouseButtonEvents mouseEvents)
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-02-24 05:55:51 +08:00
|
|
|
|
this.name = name;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
this.location = Location;
|
|
|
|
|
this.tilePosition = Position;
|
|
|
|
|
this.mouseButtonEvents = mouseEvents;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 07:30:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A constructor encapsulating player, mouse button, and mouse entry events.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Location">The game location for which the event is located. I.E Town, Farm, etc.</param>
|
|
|
|
|
/// <param name="Position">The x,y cordinates for this event to be located at.</param>
|
|
|
|
|
/// <param name="playerEvents">The events that occur associated with the player. I.E player entry, etc.</param>
|
|
|
|
|
/// <param name="mouseButtonEvents">The events associated with clicking a mouse button while on this tile.</param>
|
|
|
|
|
/// <param name="mouseEntryLeaveEvents">The events that occur when the mouse enters or leaves the same tile position as this event.</param>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
public MapEvent(string name,GameLocation Location, Vector2 Position, PlayerEvents playerEvents, MouseButtonEvents mouseButtonEvents, MouseEntryLeaveEvent mouseEntryLeaveEvents)
|
2018-02-23 07:30:35 +08:00
|
|
|
|
{
|
2018-02-24 05:55:51 +08:00
|
|
|
|
this.name = name;
|
2018-02-23 07:30:35 +08:00
|
|
|
|
this.location = Location;
|
|
|
|
|
this.tilePosition = Position;
|
|
|
|
|
this.playerEvents = playerEvents;
|
|
|
|
|
this.mouseButtonEvents = mouseButtonEvents;
|
|
|
|
|
this.mouseEntryLeaveEvents = mouseEntryLeaveEvents;
|
|
|
|
|
}
|
2018-02-24 05:55:51 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2018-02-23 07:30:35 +08:00
|
|
|
|
|
2018-02-24 05:55:51 +08:00
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
Player related functions
|
|
|
|
|
|
|
|
|
|
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
*/
|
|
|
|
|
#region
|
2018-02-23 03:43:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs when the player enters the same tile as this event. The function associated with this event is then ran.
|
|
|
|
|
/// </summary>
|
2018-03-06 15:46:24 +08:00
|
|
|
|
public virtual bool OnPlayerEnter()
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-03-06 15:46:24 +08:00
|
|
|
|
if (this.playerEvents == null) return false;
|
|
|
|
|
if (isPlayerOnTile() == true && this.doesInteractionNeedToRun==true)
|
2018-02-24 05:55:51 +08:00
|
|
|
|
{
|
|
|
|
|
this.playerOnTile = true;
|
2018-03-06 15:46:24 +08:00
|
|
|
|
this.doesInteractionNeedToRun = false;
|
2018-02-24 05:55:51 +08:00
|
|
|
|
if (this.playerEvents.onPlayerEnter != null) this.playerEvents.onPlayerEnter.run();
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return true;
|
2018-02-24 05:55:51 +08:00
|
|
|
|
}
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return false;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs when the player leaves the same tile that this event is on. The function associated with thie event is then ran.
|
|
|
|
|
/// </summary>
|
2018-03-06 15:46:24 +08:00
|
|
|
|
public virtual bool OnPlayerLeave()
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-03-06 15:46:24 +08:00
|
|
|
|
if (this.playerEvents == null) return false;
|
|
|
|
|
if (isPlayerOnTile() == false && this.playerOnTile==true){
|
2018-02-24 05:55:51 +08:00
|
|
|
|
this.playerOnTile = false;
|
2018-03-06 15:46:24 +08:00
|
|
|
|
this.doesInteractionNeedToRun = true;
|
2018-02-24 05:55:51 +08:00
|
|
|
|
if (this.playerEvents.onPlayerLeave != null) this.playerEvents.onPlayerLeave.run();
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return true;
|
2018-02-24 05:55:51 +08:00
|
|
|
|
}
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return false;
|
2018-02-24 05:55:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the player is on the same tile as this event.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public virtual bool isPlayerOnTile()
|
|
|
|
|
{
|
|
|
|
|
if (Game1.player.getTileX() == this.tilePosition.X && Game1.player.getTileY() == this.tilePosition.Y) return true;
|
|
|
|
|
else return false;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
2018-02-24 05:55:51 +08:00
|
|
|
|
#endregion
|
2018-02-23 03:43:18 +08:00
|
|
|
|
|
2018-02-24 05:55:51 +08:00
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
Mouse related functions
|
|
|
|
|
|
|
|
|
|
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
*/
|
|
|
|
|
#region
|
2018-02-23 03:43:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs when the player left clicks the same tile that this event is on.
|
|
|
|
|
/// </summary>
|
2018-03-06 15:46:24 +08:00
|
|
|
|
public virtual bool OnLeftClick()
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-03-06 15:46:24 +08:00
|
|
|
|
if (this.mouseOnTile==false) return false;
|
|
|
|
|
if (this.mouseButtonEvents == null) return false;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
if (this.mouseButtonEvents.onLeftClick != null) this.mouseButtonEvents.onLeftClick.run();
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs when the player right clicks the same tile that this event is on.
|
|
|
|
|
/// </summary>
|
2018-03-06 15:46:24 +08:00
|
|
|
|
public virtual bool OnRightClick()
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-03-06 15:46:24 +08:00
|
|
|
|
if (this.mouseOnTile == false) return false;
|
|
|
|
|
if (this.mouseButtonEvents == null) return false;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
if (this.mouseButtonEvents.onRightClick != null) this.mouseButtonEvents.onRightClick.run();
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return true;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs when the mouse tile position is the same as this event's x,y position.
|
|
|
|
|
/// </summary>
|
2018-03-06 15:46:24 +08:00
|
|
|
|
public virtual bool OnMouseEnter()
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-03-06 15:46:24 +08:00
|
|
|
|
if (this.mouseEntryLeaveEvents == null) return false;
|
2018-02-23 07:30:35 +08:00
|
|
|
|
if (isMouseOnTile())
|
|
|
|
|
{
|
|
|
|
|
this.mouseOnTile = true;
|
|
|
|
|
if (this.mouseEntryLeaveEvents.onMouseEnter != null) this.mouseEntryLeaveEvents.onMouseEnter.run();
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return true;
|
2018-02-23 07:30:35 +08:00
|
|
|
|
}
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return false;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs when the mouse tile position leaves the the same x,y position as this event.
|
|
|
|
|
/// </summary>
|
2018-03-06 15:46:24 +08:00
|
|
|
|
public virtual bool OnMouseLeave()
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-03-06 15:46:24 +08:00
|
|
|
|
if (this.mouseEntryLeaveEvents == null) return false;
|
2018-02-23 07:30:35 +08:00
|
|
|
|
if (isMouseOnTile() == false && this.mouseOnTile == true)
|
|
|
|
|
{
|
|
|
|
|
this.mouseOnTile = false;
|
|
|
|
|
if (this.mouseEntryLeaveEvents.onMouseLeave != null) this.mouseEntryLeaveEvents.onMouseLeave.run();
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return true;
|
2018-02-23 07:30:35 +08:00
|
|
|
|
}
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return false;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
/// UNUSED!!!!
|
2018-02-23 03:43:18 +08:00
|
|
|
|
/// Occurs when the mouse is on the same position as the tile AND the user scrolls the mouse wheel.
|
|
|
|
|
/// </summary>
|
2018-03-06 15:46:24 +08:00
|
|
|
|
public virtual bool OnMouseScroll()
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-03-06 15:46:24 +08:00
|
|
|
|
|
|
|
|
|
if (isMouseOnTile() == false) return false;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
if (this.mouseButtonEvents.onMouseScroll != null) this.mouseButtonEvents.onMouseScroll.run();
|
2018-03-06 15:46:24 +08:00
|
|
|
|
return true;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
/// Checks if the mouse is on the tile.
|
2018-02-23 03:43:18 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
public virtual bool isMouseOnTile()
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-03-06 15:06:39 +08:00
|
|
|
|
Vector2 mousePosition = Game1.currentCursorTile;
|
2018-02-24 05:55:51 +08:00
|
|
|
|
if (mousePosition.X == this.tilePosition.X && mousePosition.Y == this.tilePosition.Y) return true;
|
|
|
|
|
return false;
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
/// Occurs when the tile is clicked. Runs the appropriate event.
|
2018-02-23 03:43:18 +08:00
|
|
|
|
/// </summary>
|
2018-03-06 15:06:39 +08:00
|
|
|
|
public virtual void clickEvent()
|
2018-02-23 03:43:18 +08:00
|
|
|
|
{
|
2018-02-24 05:55:51 +08:00
|
|
|
|
if (this.mouseOnTile == false) return;
|
|
|
|
|
var mouseState=Mouse.GetState();
|
|
|
|
|
if (mouseState.LeftButton == ButtonState.Pressed) OnLeftClick();
|
|
|
|
|
if (mouseState.RightButton == ButtonState.Pressed) OnRightClick();
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
2018-02-24 05:55:51 +08:00
|
|
|
|
#endregion
|
2018-02-23 03:43:18 +08:00
|
|
|
|
|
|
|
|
|
|
2018-02-23 07:30:35 +08:00
|
|
|
|
/// <summary>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
/// Used to check if any sort of events need to run on this tile right now.
|
2018-02-23 07:30:35 +08:00
|
|
|
|
/// </summary>
|
2018-02-24 05:55:51 +08:00
|
|
|
|
public virtual void update()
|
2018-02-23 07:30:35 +08:00
|
|
|
|
{
|
2018-03-06 15:46:24 +08:00
|
|
|
|
if (Game1.activeClickableMenu != null) return;
|
2018-03-06 15:06:39 +08:00
|
|
|
|
clickEvent(); //click events
|
2018-02-24 05:55:51 +08:00
|
|
|
|
OnPlayerEnter(); //player enter events
|
|
|
|
|
OnPlayerLeave(); //player leave events
|
|
|
|
|
OnMouseEnter(); //on mouse enter events
|
|
|
|
|
OnMouseLeave(); //on mouse leave events.
|
2018-02-23 07:30:35 +08:00
|
|
|
|
}
|
2018-02-23 03:43:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|