2018-12-30 18:00:05 +08:00
|
|
|
using System.IO;
|
|
|
|
using CustomNPCFramework.Framework.Enums;
|
2018-05-01 09:21:31 +08:00
|
|
|
using StardewModdingAPI;
|
|
|
|
using StardustCore.UIUtilities;
|
2018-03-04 23:53:55 +08:00
|
|
|
|
|
|
|
namespace CustomNPCFramework.Framework.Graphics
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>A class that's used to hold textures for different directions.</summary>
|
2018-03-04 23:53:55 +08:00
|
|
|
public class DirectionalTexture
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>The left texture for this group.</summary>
|
2018-05-01 09:21:31 +08:00
|
|
|
public Texture2DExtended leftTexture;
|
2018-12-30 18:00:05 +08:00
|
|
|
|
|
|
|
/// <summary>The right texture for this group.</summary>
|
2018-05-01 09:21:31 +08:00
|
|
|
public Texture2DExtended rightTexture;
|
2018-12-30 18:00:05 +08:00
|
|
|
|
|
|
|
/// <summary>The down textiure for this group.</summary>
|
2018-05-01 09:21:31 +08:00
|
|
|
public Texture2DExtended downTexture;
|
2018-12-30 18:00:05 +08:00
|
|
|
|
|
|
|
/// <summary>The up texture for this group.</summary>
|
2018-05-01 09:21:31 +08:00
|
|
|
public Texture2DExtended upTexture;
|
2018-03-04 23:53:55 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>The current texture for this group.</summary>
|
2018-05-01 09:21:31 +08:00
|
|
|
public Texture2DExtended currentTexture;
|
2018-03-04 23:53:55 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
2018-03-19 18:32:00 +08:00
|
|
|
/// <param name="left">The left texture to use.</param>
|
|
|
|
/// <param name="right">The right texture to use.</param>
|
|
|
|
/// <param name="up">The up texture to use.</param>
|
|
|
|
/// <param name="down">The down texture to use.</param>
|
|
|
|
/// <param name="direction">The direction texture for the sprite to face.</param>
|
2018-12-30 18:00:05 +08:00
|
|
|
public DirectionalTexture(Texture2DExtended left, Texture2DExtended right, Texture2DExtended up, Texture2DExtended down, Direction direction = Direction.down)
|
2018-03-04 23:53:55 +08:00
|
|
|
{
|
|
|
|
this.leftTexture = left;
|
|
|
|
this.rightTexture = right;
|
|
|
|
this.upTexture = up;
|
|
|
|
this.downTexture = down;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case Direction.left:
|
|
|
|
this.currentTexture = this.leftTexture;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Direction.right:
|
|
|
|
this.currentTexture = this.rightTexture;
|
|
|
|
break;
|
2018-03-04 23:53:55 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
case Direction.up:
|
|
|
|
this.currentTexture = this.upTexture;
|
|
|
|
break;
|
2018-03-04 23:53:55 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
case Direction.down:
|
|
|
|
this.currentTexture = this.downTexture;
|
|
|
|
break;
|
|
|
|
}
|
2018-03-04 23:53:55 +08:00
|
|
|
}
|
|
|
|
|
2019-01-06 13:31:40 +08:00
|
|
|
public DirectionalTexture(IModHelper helper, NamePairings info, string relativePath, Direction direction = Direction.down)
|
2018-03-04 23:53:55 +08:00
|
|
|
{
|
2019-01-06 13:31:40 +08:00
|
|
|
this.leftTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.leftString}.png"));
|
|
|
|
this.rightTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.rightString}.png"));
|
|
|
|
this.upTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.upString}.png"));
|
|
|
|
this.downTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.downString}.png"));
|
2018-03-04 23:53:55 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case Direction.left:
|
|
|
|
this.currentTexture = this.leftTexture;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Direction.right:
|
|
|
|
this.currentTexture = this.rightTexture;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Direction.up:
|
|
|
|
this.currentTexture = this.upTexture;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Direction.down:
|
|
|
|
this.currentTexture = this.downTexture;
|
|
|
|
break;
|
|
|
|
}
|
2018-03-04 23:53:55 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Sets the direction of this current texture to left.</summary>
|
2018-03-04 23:53:55 +08:00
|
|
|
public void setLeft()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.currentTexture = this.leftTexture;
|
2018-03-04 23:53:55 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Sets the direction of this current texture to up.</summary>
|
2018-03-04 23:53:55 +08:00
|
|
|
public void setUp()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.currentTexture = this.upTexture;
|
2018-03-04 23:53:55 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Sets the direction of this current texture to down.</summary>
|
2018-03-04 23:53:55 +08:00
|
|
|
public void setDown()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.currentTexture = this.downTexture;
|
2018-03-04 23:53:55 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Sets the direction of this current texture to right.</summary>
|
2018-03-04 23:53:55 +08:00
|
|
|
public void setRight()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.currentTexture = this.rightTexture;
|
2018-03-04 23:53:55 +08:00
|
|
|
}
|
2018-03-05 05:23:40 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Gets the texture from this texture group depending on the direction.</summary>
|
|
|
|
/// <param name="direction">The facing direction.</param>
|
2018-05-01 09:21:31 +08:00
|
|
|
public virtual Texture2DExtended getTextureFromDirection(Direction direction)
|
2018-03-05 05:23:40 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case Direction.left:
|
|
|
|
return this.leftTexture;
|
|
|
|
|
|
|
|
case Direction.right:
|
|
|
|
return this.rightTexture;
|
|
|
|
|
|
|
|
case Direction.up:
|
|
|
|
return this.upTexture;
|
|
|
|
|
|
|
|
case Direction.down:
|
|
|
|
return this.downTexture;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-05 05:23:40 +08:00
|
|
|
}
|
2018-03-04 23:53:55 +08:00
|
|
|
}
|
|
|
|
}
|