mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-29 10:24:34 +00:00
PckStudio - Add SkinsPanel.cs
This commit is contained in:
@@ -77,5 +77,46 @@ namespace PckStudio.Core.Extensions
|
||||
int index = Array.IndexOf(SkinBOX.OverlayTypes, type);
|
||||
return SkinBOX.BaseTypes.IndexInRange(index) ? SkinBOX.BaseTypes[index] : "";
|
||||
}
|
||||
|
||||
public enum SkinBoxFace
|
||||
{
|
||||
Front,
|
||||
Back,
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
public static Rectangle GetFaceArea(this SkinBOX skinBox, SkinBoxFace face) => new Rectangle(skinBox.GetPoint(face), skinBox.GetSize(face));
|
||||
|
||||
public static Point GetPoint(this SkinBOX skinBox, SkinBoxFace face)
|
||||
{
|
||||
return Point.Truncate((face) switch
|
||||
{
|
||||
SkinBoxFace.Front => new PointF(skinBox.UV.X + skinBox.Size.Z , skinBox.UV.Y + skinBox.Size.Z),
|
||||
SkinBoxFace.Back => new PointF(skinBox.UV.X + skinBox.Size.Z * 2 + skinBox.Size.X, skinBox.UV.Y + skinBox.Size.Z),
|
||||
SkinBoxFace.Top => new PointF(skinBox.UV.X + skinBox.Size.X , skinBox.UV.Y),
|
||||
SkinBoxFace.Bottom => new PointF(skinBox.UV.X + skinBox.Size.X * 2 , skinBox.UV.Y),
|
||||
SkinBoxFace.Left => new PointF(skinBox.UV.X + skinBox.Size.Z + skinBox.Size.X , skinBox.UV.Y + skinBox.Size.Z),
|
||||
SkinBoxFace.Right => new PointF(skinBox.UV.X + skinBox.Size.Z , skinBox.UV.Y + skinBox.Size.Z),
|
||||
_ => PointF.Empty,
|
||||
});
|
||||
}
|
||||
|
||||
public static Size GetSize(this SkinBOX skinBox, SkinBoxFace face)
|
||||
{
|
||||
return Size.Truncate((face) switch
|
||||
{
|
||||
SkinBoxFace.Front => new SizeF(skinBox.Size.X, skinBox.Size.Y),
|
||||
SkinBoxFace.Back => new SizeF(skinBox.Size.X, skinBox.Size.Y),
|
||||
SkinBoxFace.Top => new SizeF(skinBox.Size.X, skinBox.Size.Z),
|
||||
SkinBoxFace.Bottom => new SizeF(skinBox.Size.X, skinBox.Size.Z),
|
||||
SkinBoxFace.Left => new SizeF(skinBox.Size.Z, skinBox.Size.Y),
|
||||
SkinBoxFace.Right => new SizeF(skinBox.Size.Z, skinBox.Size.Y),
|
||||
_ => SizeF.Empty,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
@@ -68,5 +69,30 @@ namespace PckStudio.Core.Extensions
|
||||
capeFile.SetTexture(capeTexture);
|
||||
return capeFile;
|
||||
}
|
||||
|
||||
public static Image GetPreviewImage(this Skin.Skin skin, Size size) => skin.GetPreviewImage(size.Width, size.Height);
|
||||
public static Image GetPreviewImage(this Skin.Skin skin, int width = 16, int height = 16)
|
||||
{
|
||||
Image result = new Bitmap(width, height);
|
||||
using Graphics g = Graphics.FromImage(result);
|
||||
g.ApplyConfig(GraphicsConfig.PixelPerfect());
|
||||
g.Clear(Color.Transparent);
|
||||
|
||||
if (!skin.Anim.GetFlag(SkinAnimFlag.HEAD_DISABLED))
|
||||
{
|
||||
g.DrawImage(skin.Texture.GetArea(new Rectangle(8, 8, 8, 8)), 0, 0, width, height);
|
||||
}
|
||||
else if (!skin.Anim.GetFlag(SkinAnimFlag.HEAD_OVERLAY_DISABLED))
|
||||
{
|
||||
g.DrawImage(skin.Texture.GetArea(new Rectangle(40, 8, 8, 8)), 0, 0, width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rectangle area = skin.Model.AdditionalBoxes.Where(sb => sb.Type == "HEAD" || sb.Type == "HEADWEAR").OrderBy(sb=> sb.Pos.Z - sb.Scale).FirstOrDefault()?.GetFaceArea(SkinBOXExtensions.SkinBoxFace.Front) ?? Rectangle.Empty;
|
||||
Image img = skin.Texture.GetArea(area);
|
||||
g.DrawImage(img, 0, 0, width, height);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user