2018-02-06 18:13:21 +08:00
|
|
|
using System.IO;
|
2019-01-05 17:50:48 +08:00
|
|
|
using Microsoft.Xna.Framework;
|
2018-12-30 18:00:05 +08:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using StardewModdingAPI;
|
2018-02-06 18:13:21 +08:00
|
|
|
|
|
|
|
namespace StardustCore.UIUtilities
|
|
|
|
{
|
|
|
|
public class Texture2DExtended
|
|
|
|
{
|
2019-07-16 17:09:42 +08:00
|
|
|
public string Name;
|
|
|
|
public Texture2D texture;
|
|
|
|
public string path;
|
|
|
|
public string modID;
|
|
|
|
public ContentSource source;
|
|
|
|
private readonly IModHelper helper;
|
|
|
|
private readonly IContentPack content;
|
|
|
|
public int Width
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.texture.Width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public int Height
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.texture.Height;
|
|
|
|
}
|
|
|
|
}
|
2019-01-05 17:50:48 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Empty/null constructor.</summary>
|
2018-03-31 16:47:10 +08:00
|
|
|
public Texture2DExtended()
|
|
|
|
{
|
2019-07-16 17:09:42 +08:00
|
|
|
this.Name = "";
|
|
|
|
this.texture = null;
|
|
|
|
this.path = "";
|
|
|
|
this.helper = null;
|
|
|
|
this.modID = "";
|
2018-03-31 16:47:10 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 17:09:42 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
2019-07-16 17:09:42 +08:00
|
|
|
/// <param name="path">The relative path to file on disk. See StardustCore.Utilities.getRelativePath(modname,path);
|
|
|
|
public Texture2DExtended(IModHelper helper, IManifest manifest, string path, ContentSource contentSource = ContentSource.ModFolder)
|
2018-02-06 18:13:21 +08:00
|
|
|
{
|
2019-07-16 17:09:42 +08:00
|
|
|
this.Name = Path.GetFileNameWithoutExtension(path);
|
|
|
|
this.path = path;
|
|
|
|
this.texture = helper.Content.Load<Texture2D>(path, contentSource);
|
|
|
|
this.helper = helper;
|
|
|
|
this.modID = manifest.UniqueID;
|
|
|
|
this.source = contentSource;
|
2018-02-06 18:13:21 +08:00
|
|
|
}
|
2018-08-09 04:18:51 +08:00
|
|
|
|
2019-07-16 17:09:42 +08:00
|
|
|
public Texture2DExtended(IModHelper helper, string modID, string path, ContentSource contentSource = ContentSource.ModFolder)
|
2018-08-09 04:18:51 +08:00
|
|
|
{
|
2019-07-16 17:09:42 +08:00
|
|
|
this.Name = Path.GetFileNameWithoutExtension(path);
|
|
|
|
this.path = path;
|
|
|
|
this.texture = helper.Content.Load<Texture2D>(path, contentSource);
|
|
|
|
this.helper = helper;
|
|
|
|
this.modID = modID;
|
|
|
|
this.source = contentSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Texture2DExtended(IContentPack ContentPack, IManifest manifest, string path)
|
|
|
|
{
|
|
|
|
this.Name = Path.GetFileNameWithoutExtension(path);
|
|
|
|
this.path = path;
|
|
|
|
this.texture = ContentPack.LoadAsset<Texture2D>(path);
|
|
|
|
this.helper = null;
|
|
|
|
this.modID = manifest.UniqueID;
|
|
|
|
this.source = ContentSource.ModFolder;
|
|
|
|
}
|
|
|
|
public Texture2DExtended(IContentPack ContentPack, string modID, string path)
|
|
|
|
{
|
|
|
|
this.Name = Path.GetFileNameWithoutExtension(path);
|
|
|
|
this.path = path;
|
|
|
|
this.texture = ContentPack.LoadAsset<Texture2D>(path);
|
|
|
|
this.helper = null;
|
|
|
|
this.modID = modID;
|
|
|
|
this.source = ContentSource.ModFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Texture2DExtended(IContentPack content, string path)
|
|
|
|
{
|
|
|
|
this.Name = Path.GetFileNameWithoutExtension(path);
|
|
|
|
this.path = path;
|
|
|
|
this.content = content;
|
|
|
|
this.texture = content.LoadAsset<Texture2D>(path);
|
|
|
|
this.helper = null;
|
|
|
|
this.modID = content.Manifest.UniqueID;
|
2018-08-09 04:18:51 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 09:21:31 +08:00
|
|
|
public Texture2DExtended Copy()
|
2018-02-06 18:13:21 +08:00
|
|
|
{
|
2019-07-16 17:09:42 +08:00
|
|
|
if (this.helper != null)
|
|
|
|
{
|
|
|
|
return new Texture2DExtended(this.helper, this.modID, this.path);
|
|
|
|
}
|
|
|
|
else if (this.content != null)
|
|
|
|
{
|
|
|
|
return new Texture2DExtended(this.content, this.path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new System.Exception("Trying to copy a texture that isn't from a mod or a content pack!!!");
|
|
|
|
}
|
|
|
|
}
|
2018-05-01 09:21:31 +08:00
|
|
|
|
2019-07-16 17:09:42 +08:00
|
|
|
public IModHelper getHelper()
|
|
|
|
{
|
|
|
|
return this.helper;
|
2018-05-01 09:21:31 +08:00
|
|
|
}
|
2018-06-13 09:42:31 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Returns the actual 2D texture held by this wrapper class.</summary>
|
2018-06-13 09:42:31 +08:00
|
|
|
public Texture2D getTexture()
|
|
|
|
{
|
2019-07-16 17:09:42 +08:00
|
|
|
return this.texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTexure(Texture2D text)
|
|
|
|
{
|
|
|
|
this.texture = text;
|
2018-08-08 01:07:33 +08:00
|
|
|
}
|
2018-02-06 18:13:21 +08:00
|
|
|
}
|
|
|
|
}
|