Core - Update Skin.cs to use cape id instead of cape texture

This commit is contained in:
miku-666
2025-11-26 09:34:32 +01:00
parent 87fd010ee0
commit dabc177917
6 changed files with 47 additions and 35 deletions

View File

@@ -474,12 +474,14 @@ namespace PckStudio.Controls
private void HandleSkinFile(PckAsset asset)
{
Skin skin = asset.GetSkin();
Image cape = null;
if (asset.HasProperty("CAPEPATH"))
{
string capeAssetPath = asset.GetProperty("CAPEPATH");
if (EditorValue.File.TryGetAsset(capeAssetPath, PckAssetType.CapeFile, out PckAsset capeAsset))
{
skin.CapeTexture = capeAsset.GetTexture();
skin.CapeId = capeAsset.GetId();
cape = capeAsset.GetTexture();
}
}
@@ -490,7 +492,7 @@ namespace PckStudio.Controls
asset.SetSkin(customSkin, locFile);
});
using CustomSkinEditor skinEditor = new CustomSkinEditor(skin, saveContext, EditorValue.File.HasVerionString);
using CustomSkinEditor skinEditor = new CustomSkinEditor(skin, cape, saveContext, EditorValue.File.HasVerionString);
if (skinEditor.ShowDialog() == DialogResult.OK)
{
entryDataTextBox.Text = entryTypeTextBox.Text = string.Empty;
@@ -1276,9 +1278,9 @@ namespace PckStudio.Controls
skinAsset.Filename = skinAsset.Filename.Insert(0, "Skins/"); // Then Skins folder
EditorValue.File.AddAsset(skinAsset);
if (addNewSkinDialog.NewSkin.HasCape)
if (addNewSkinDialog.HasCape)
{
PckAsset capeFile = addNewSkinDialog.NewSkin.CreateCapeFile();
PckAsset capeFile = addNewSkinDialog.NewSkin.CreateCapeFile(addNewSkinDialog.CapeTexture);
if (hasSkinsFolder)
capeFile.Filename = capeFile.Filename.Insert(0, "Skins/"); // Then Skins folder
EditorValue.File.AddAsset(capeFile);

View File

@@ -24,6 +24,9 @@ namespace PckStudio.Forms.Additional_Popups
public partial class AddSkinPrompt : ImmersiveForm
{
public Skin NewSkin => newSkin;
public Image CapeTexture => _capeTexture;
public bool HasCape => _capeTexture is not null;
private Image _capeTexture;
private Skin newSkin;
private Random rng = new Random();
@@ -191,7 +194,7 @@ namespace PckStudio.Forms.Additional_Popups
MessageBox.Show(this, "Not a Valid Cape File");
return;
}
newSkin.CapeTexture = capePictureBox.Image = img;
_capeTexture = capePictureBox.Image = img;
contextMenuCape.Items[0].Text = "Replace";
capeLabel.Visible = false;
contextMenuCape.Visible = true;
@@ -229,7 +232,7 @@ namespace PckStudio.Forms.Additional_Popups
ISaveContext<Skin> saveContext = new DelegatedSaveContext<Skin>(Settings.Default.AutoSaveChanges, (customSkin) => newSkin = customSkin);
using CustomSkinEditor customSkinEditor = new CustomSkinEditor(newSkin, saveContext);
using CustomSkinEditor customSkinEditor = new CustomSkinEditor(newSkin, default, saveContext);
if (customSkinEditor.ShowDialog() == DialogResult.OK)
{

View File

@@ -24,6 +24,7 @@ namespace PckStudio.Forms.Editor
{
private const float MAX_OFFSET = 100_000f;
private Random _rng;
private readonly Image _cape;
private bool _inflateOverlayParts;
private bool _allowInflate;
@@ -34,10 +35,10 @@ namespace PckStudio.Forms.Editor
private static GraphicsConfig _graphicsConfig = GraphicsConfig.PixelPerfect();
private CustomSkinEditor() : this(null, null)
private CustomSkinEditor() : this(null, null, null)
{ }
public CustomSkinEditor(Skin skin, ISaveContext<Skin> saveContext, bool inflateOverlayParts = false, bool allowInflate = false)
public CustomSkinEditor(Skin skin, Image cape, ISaveContext<Skin> saveContext, bool inflateOverlayParts = false, bool allowInflate = false)
: base(skin, saveContext)
{
InitializeComponent();
@@ -47,6 +48,7 @@ namespace PckStudio.Forms.Editor
skinPartListBox.DataSource = _skinPartListBindingSource;
skinPartListBox.DisplayMember = "Type";
_allowInflate = allowInflate;
_cape = cape;
_inflateOverlayParts = inflateOverlayParts;
}
@@ -62,11 +64,13 @@ namespace PckStudio.Forms.Editor
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (DesignMode)
return;
renderer3D1.Initialize(_inflateOverlayParts);
renderer3D1.GuideLineColor = Color.LightCoral;
skinNameLabel.Text = EditorValue.MetaData.Name;
if (EditorValue.HasCape)
renderer3D1.CapeTexture = EditorValue.CapeTexture;
renderer3D1.CapeTexture = _cape;
LoadModelData();
}

View File

@@ -52,28 +52,28 @@ namespace PckStudio.Core.Extensions
/// Tries to get the skin id of the skin <paramref name="asset"/>
/// </summary>
/// <param name="asset"></param>
/// <returns>Non-zero base number on success, otherwise 0</returns>
/// <returns>Positive number on success, otherwise -1</returns>
/// <exception cref="InvalidOperationException"></exception>
public static int GetSkinId(this PckAsset asset)
public static int GetId(this PckAsset asset)
{
if (asset.Type != PckAssetType.SkinFile)
throw new InvalidOperationException("Asset is not a skin.");
if (asset.Type != PckAssetType.SkinFile && asset.Type != PckAssetType.CapeFile)
throw new InvalidOperationException("Asset has no id.");
const string skinAssetnamePrefix = "dlcskin";
string assetnamePrefix = asset.Type == PckAssetType.SkinFile ? "dlcskin" : "dlccpae";
string assetPath = Path.GetFileNameWithoutExtension(asset.Filename);
if (!assetPath.StartsWith(skinAssetnamePrefix))
if (!assetPath.StartsWith(assetnamePrefix))
{
Trace.TraceWarning($"[{nameof(GetSkinId)}] Asset name does not start with '{skinAssetnamePrefix}'");
return 0;
Trace.TraceWarning($"[{nameof(GetId)}] Asset name does not start with '{assetnamePrefix}'");
return -1;
}
int skinId = 0;
if (!int.TryParse(assetPath.Substring(skinAssetnamePrefix.Length), out skinId))
int id = 0;
if (!int.TryParse(assetPath.Substring(assetnamePrefix.Length), out id))
{
Trace.TraceWarning($"[{nameof(GetSkinId)}] Failed to parse Skin Id");
Trace.TraceWarning($"[{nameof(GetId)}] Failed to parse Id");
}
return skinId;
return id;
}
public static Skin.Skin GetSkin(this PckAsset asset)
@@ -81,7 +81,7 @@ namespace PckStudio.Core.Extensions
if (asset.Type != PckAssetType.SkinFile)
throw new InvalidOperationException("Asset is not a skin.");
int skinId = asset.GetSkinId();
int skinId = asset.GetId();
string name = asset.GetProperty("DISPLAYNAME");
Image texture = asset.GetTexture();
@@ -91,7 +91,7 @@ namespace PckStudio.Core.Extensions
return new Skin.Skin(name, skinId, texture, anim, boxes, offsets);
}
public static void SetSkin(this PckAsset asset, Skin.Skin skin, LOCFile localizationFile)
public static void SetSkin(this PckAsset asset, Skin.Skin skin, LOCFile localisation)
{
if (asset.Type != PckAssetType.SkinFile)
throw new InvalidOperationException("Asset is not a skin file");
@@ -105,22 +105,24 @@ namespace PckStudio.Core.Extensions
asset.SetProperty("DISPLAYNAME", skin.MetaData.Name);
if (localizationFile is not null)
bool canLocalize = localisation is not null;
if (canLocalize)
{
string skinLocKey = $"IDS_dlcskin{skinId}_DISPLAYNAME";
asset.SetProperty("DISPLAYNAMEID", skinLocKey);
localizationFile.SetLocEntry(skinLocKey, skin.MetaData.Name);
localisation.SetLocEntry(skinLocKey, skin.MetaData.Name);
}
if (!string.IsNullOrEmpty(skin.MetaData.Theme))
{
asset.SetProperty("THEMENAME", skin.MetaData.Theme);
if (localizationFile is not null)
if (canLocalize)
{
string skinThemeLocKey = $"IDS_dlcskin{skinId}_THEMENAME";
asset.SetProperty("THEMENAMEID", skinThemeLocKey);
localizationFile.SetLocEntry(skinThemeLocKey, skin.MetaData.Theme);
localisation.SetLocEntry(skinThemeLocKey, skin.MetaData.Theme);
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
@@ -58,13 +59,13 @@ namespace PckStudio.Core.Extensions
return skinFile;
}
public static PckAsset CreateCapeFile(this Skin.Skin skin)
public static PckAsset CreateCapeFile(this Skin.Skin skin, Image capeTexture)
{
if (!skin.HasCape)
throw new InvalidOperationException("Skin does not contain a cape.");
string skinId = skin.Identifier.ToString("d08");
PckAsset capeFile = new PckAsset($"dlccape{skinId}.png", PckAssetType.CapeFile);
capeFile.SetTexture(skin.CapeTexture);
PckAsset capeFile = new PckAsset($"dlccape{skin.CapeId}.png", PckAssetType.CapeFile);
capeFile.SetTexture(capeTexture);
return capeFile;
}
}

View File

@@ -18,10 +18,10 @@ namespace PckStudio.Core.Skin
public SkinModel Model { get; set; }
public Image Texture { get; set; }
public Image CapeTexture { get; set; }
public bool HasCape => CapeTexture is not null;
public int CapeId { get; set; } = -1;
public bool HasCape => CapeId != -1;
public Skin(string name, Image texture)
{
@@ -30,10 +30,10 @@ namespace PckStudio.Core.Skin
Model = new SkinModel();
}
public Skin(string name, Image texture, Image capeTexture)
public Skin(string name, Image texture, int capeId)
: this(name, texture)
{
CapeTexture = capeTexture;
CapeId = capeId;
}
public Skin(string name, SkinANIM anim, Image texture, IEnumerable<SkinBOX> additionalBoxes, IEnumerable<SkinPartOffset> partOffsets)