mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-22 09:16:09 +00:00
PckStudio - Add SkinsPanel.cs
This commit is contained in:
@@ -78,6 +78,7 @@ namespace PckStudio.Controls
|
||||
|
||||
private readonly ViewPanel _default;
|
||||
private readonly ViewPanel _models;
|
||||
private readonly ViewPanel _skins;
|
||||
|
||||
private int _timesSaved = 0;
|
||||
|
||||
@@ -102,6 +103,7 @@ namespace PckStudio.Controls
|
||||
img = found ? asset.GetTexture() : default;
|
||||
return found;
|
||||
}));
|
||||
_skins = new SkinsPanel(_currentEndianness);
|
||||
}
|
||||
|
||||
treeViewMain.TreeViewNodeSorter = new PckNodeSorter();
|
||||
@@ -918,6 +920,8 @@ namespace PckStudio.Controls
|
||||
{
|
||||
case PckAssetType.ModelsFile:
|
||||
return _models;
|
||||
case PckAssetType.SkinDataFile:
|
||||
return _skins;
|
||||
default:
|
||||
return _default;
|
||||
}
|
||||
|
||||
119
PCK-Studio/Controls/SkinsPanel.Designer.cs
generated
Normal file
119
PCK-Studio/Controls/SkinsPanel.Designer.cs
generated
Normal file
@@ -0,0 +1,119 @@
|
||||
namespace PckStudio.Controls
|
||||
{
|
||||
partial class SkinsPanel
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.skinRenderer1 = new PckStudio.Rendering.SkinRenderer();
|
||||
this.treeView1 = new System.Windows.Forms.TreeView();
|
||||
this.tableLayoutPanel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// tableLayoutPanel1
|
||||
//
|
||||
this.tableLayoutPanel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(18)))), ((int)(((byte)(18)))));
|
||||
this.tableLayoutPanel1.ColumnCount = 2;
|
||||
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tableLayoutPanel1.Controls.Add(this.skinRenderer1, 1, 0);
|
||||
this.tableLayoutPanel1.Controls.Add(this.treeView1, 0, 0);
|
||||
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.tableLayoutPanel1.ForeColor = System.Drawing.SystemColors.Control;
|
||||
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||
this.tableLayoutPanel1.RowCount = 2;
|
||||
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tableLayoutPanel1.Size = new System.Drawing.Size(660, 517);
|
||||
this.tableLayoutPanel1.TabIndex = 0;
|
||||
//
|
||||
// skinRenderer1
|
||||
//
|
||||
this.skinRenderer1.AllowCameraMovement = false;
|
||||
this.skinRenderer1.Animate = true;
|
||||
this.skinRenderer1.ArmorTexture = null;
|
||||
this.skinRenderer1.BackColor = System.Drawing.Color.Black;
|
||||
this.skinRenderer1.CapeTexture = null;
|
||||
this.skinRenderer1.CenterOnSelect = false;
|
||||
this.skinRenderer1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.skinRenderer1.GuideLineColor = System.Drawing.Color.Empty;
|
||||
this.skinRenderer1.HighlightlingColor = System.Drawing.Color.Aqua;
|
||||
this.skinRenderer1.Location = new System.Drawing.Point(333, 3);
|
||||
this.skinRenderer1.MouseSensetivity = 0.01F;
|
||||
this.skinRenderer1.Name = "skinRenderer1";
|
||||
this.skinRenderer1.RefreshRate = 60;
|
||||
this.skinRenderer1.RenderGroundPlane = true;
|
||||
this.skinRenderer1.RenderSkyBox = true;
|
||||
this.skinRenderer1.SelectedIndex = -1;
|
||||
this.skinRenderer1.SelectedIndices = new int[0];
|
||||
this.skinRenderer1.ShowArmor = false;
|
||||
this.skinRenderer1.ShowBoundingBox = false;
|
||||
this.skinRenderer1.ShowGuideLines = false;
|
||||
this.skinRenderer1.Size = new System.Drawing.Size(324, 252);
|
||||
this.skinRenderer1.TabIndex = 0;
|
||||
this.skinRenderer1.Texture = null;
|
||||
this.skinRenderer1.VSync = true;
|
||||
//
|
||||
// treeView1
|
||||
//
|
||||
this.treeView1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(18)))), ((int)(((byte)(18)))));
|
||||
this.treeView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.treeView1.ForeColor = System.Drawing.SystemColors.Window;
|
||||
this.treeView1.HideSelection = false;
|
||||
this.treeView1.Location = new System.Drawing.Point(3, 3);
|
||||
this.treeView1.Name = "treeView1";
|
||||
this.treeView1.PathSeparator = ".";
|
||||
this.tableLayoutPanel1.SetRowSpan(this.treeView1, 2);
|
||||
this.treeView1.ShowLines = false;
|
||||
this.treeView1.ShowPlusMinus = false;
|
||||
this.treeView1.ShowRootLines = false;
|
||||
this.treeView1.Size = new System.Drawing.Size(324, 511);
|
||||
this.treeView1.TabIndex = 1;
|
||||
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
|
||||
//
|
||||
// SkinsPanel
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(18)))), ((int)(((byte)(18)))));
|
||||
this.Controls.Add(this.tableLayoutPanel1);
|
||||
this.Name = "SkinsPanel";
|
||||
this.Size = new System.Drawing.Size(660, 517);
|
||||
this.tableLayoutPanel1.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
|
||||
private Rendering.SkinRenderer skinRenderer1;
|
||||
private System.Windows.Forms.TreeView treeView1;
|
||||
}
|
||||
}
|
||||
63
PCK-Studio/Controls/SkinsPanel.cs
Normal file
63
PCK-Studio/Controls/SkinsPanel.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using OMI.Formats.Pck;
|
||||
using OMI.Workers.Pck;
|
||||
using PckStudio.Core.Extensions;
|
||||
using PckStudio.Core.Skin;
|
||||
|
||||
namespace PckStudio.Controls
|
||||
{
|
||||
public partial class SkinsPanel : ViewPanel
|
||||
{
|
||||
readonly PckFileReader _reader;
|
||||
readonly ImageList _imageList;
|
||||
public SkinsPanel(OMI.ByteOrder byteOrder)
|
||||
{
|
||||
InitializeComponent();
|
||||
_reader = new PckFileReader(byteOrder);
|
||||
_imageList = new ImageList()
|
||||
{
|
||||
ImageSize = new Size(32, 32),
|
||||
ColorDepth = ColorDepth.Depth32Bit,
|
||||
};
|
||||
treeView1.ImageList = _imageList;
|
||||
}
|
||||
|
||||
public override void LoadAsset(PckAsset asset, Action onChange)
|
||||
{
|
||||
Reset();
|
||||
treeView1.Nodes.AddRange(
|
||||
asset.GetData(_reader).GetAssetsByType(PckAssetType.SkinFile)
|
||||
.Select(PckAssetExtensions.GetSkin)
|
||||
.enumerate()
|
||||
.Select(a =>
|
||||
{
|
||||
_imageList.Images.Add(a.value.GetPreviewImage(_imageList.ImageSize));
|
||||
return new TreeNode(a.value.MetaData.Name) { ImageIndex = a.index, SelectedImageIndex = a.index, Tag = a.value };
|
||||
})
|
||||
.ToArray()
|
||||
);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_imageList.Images.Clear();
|
||||
treeView1.Nodes.Clear();
|
||||
}
|
||||
|
||||
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
|
||||
{
|
||||
if (e?.Node.Tag is Skin skin)
|
||||
{
|
||||
skinRenderer1.LoadSkin(skin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
PCK-Studio/Controls/SkinsPanel.resx
Normal file
120
PCK-Studio/Controls/SkinsPanel.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -161,6 +161,12 @@
|
||||
<DependentUpon>ModelsPanel.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\NamedTextureTreeNode.cs" />
|
||||
<Compile Include="Controls\SkinsPanel.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Controls\SkinsPanel.Designer.cs">
|
||||
<DependentUpon>SkinsPanel.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\ViewPanel.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
@@ -423,6 +429,9 @@
|
||||
<EmbeddedResource Include="Controls\PckAssetBrowserEditor.resx">
|
||||
<DependentUpon>PckAssetBrowserEditor.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Controls\SkinsPanel.resx">
|
||||
<DependentUpon>SkinsPanel.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\Additional-Popups\FilterPrompt.resx">
|
||||
<DependentUpon>FilterPrompt.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace PckStudio.Rendering
|
||||
set
|
||||
{
|
||||
base.BackColor = value;
|
||||
if (!DesignMode && Context.IsCurrent)
|
||||
if (!DesignMode)
|
||||
Renderer.SetClearColor(value);
|
||||
}
|
||||
}
|
||||
@@ -149,6 +149,8 @@ namespace PckStudio.Rendering
|
||||
|
||||
Camera = new PerspectiveCamera(fov, camareaPosition);
|
||||
_shaderLibrary = new ShaderLibrary();
|
||||
if (!DesignMode)
|
||||
GetContext();
|
||||
}
|
||||
|
||||
protected virtual void Initialize() { }
|
||||
@@ -171,9 +173,9 @@ namespace PckStudio.Rendering
|
||||
if (DesignMode)
|
||||
return;
|
||||
if (!Visible)
|
||||
_timer.Stop();
|
||||
_timer?.Stop();
|
||||
if (Visible)
|
||||
_timer.Start();
|
||||
_timer?.Start();
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(EventArgs e)
|
||||
|
||||
@@ -16,24 +16,23 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
using System.Diagnostics;
|
||||
using OpenTK;
|
||||
using PckStudio.Internal;
|
||||
using PckStudio.Core.Extensions;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using System.Windows.Forms;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using PckStudio.Properties;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using PckStudio.Properties;
|
||||
using PckStudio.Rendering.Extension;
|
||||
using PckStudio.Rendering.Texture;
|
||||
using PckStudio.Rendering.Shader;
|
||||
using System.Linq;
|
||||
using PckStudio.Core.Extensions;
|
||||
using PckStudio.Core.Skin;
|
||||
using PckStudio.Core;
|
||||
|
||||
@@ -183,7 +182,8 @@ namespace PckStudio.Rendering
|
||||
set
|
||||
{
|
||||
_anim = value;
|
||||
OnANIMUpdate();
|
||||
if (value is not null && !DesignMode)
|
||||
OnANIMUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,6 +290,15 @@ namespace PckStudio.Rendering
|
||||
};
|
||||
|
||||
public SkinRenderer() : base(fov: 60f)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
ANIM ??= new SkinANIM(SkinAnimMask.RESOLUTION_64x64);
|
||||
ModelData = new ObservableCollection<SkinBOX>();
|
||||
ModelData.CollectionChanged += ModelData_CollectionChanged;
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
InitializeSkinData();
|
||||
InitializeCapeData();
|
||||
@@ -312,15 +321,6 @@ namespace PckStudio.Rendering
|
||||
CalculateSkinBounds();
|
||||
InitializeArmorData();
|
||||
InitializeCamera();
|
||||
InitializeComponent();
|
||||
|
||||
ANIM ??= new SkinANIM(SkinAnimMask.RESOLUTION_64x64);
|
||||
ModelData = new ObservableCollection<SkinBOX>();
|
||||
ModelData.CollectionChanged += ModelData_CollectionChanged;
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
InitializeShaders();
|
||||
Renderer.SetClearColor(BackColor);
|
||||
GLErrorCheck();
|
||||
@@ -755,6 +755,8 @@ namespace PckStudio.Rendering
|
||||
|
||||
private void OnANIMUpdate()
|
||||
{
|
||||
if (ANIM is null)
|
||||
return;
|
||||
head.SetVisible(0, !ANIM.GetFlag(SkinAnimFlag.HEAD_DISABLED));
|
||||
head.SetVisible(1, !ANIM.GetFlag(SkinAnimFlag.HEAD_OVERLAY_DISABLED));
|
||||
|
||||
|
||||
@@ -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