diff --git a/PCK-Studio/Controls/EditorControl.cs b/PCK-Studio/Controls/EditorControl.cs index 6a7259fa..fffacd64 100644 --- a/PCK-Studio/Controls/EditorControl.cs +++ b/PCK-Studio/Controls/EditorControl.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using PckStudio.Interfaces; +using System.IO; namespace PckStudio.Controls { @@ -15,15 +16,18 @@ namespace PckStudio.Controls { public T EditorValue { get; } - public ISaveContext SaveContext { get; } + public ISaveContext SaveContext { get; private set; } + + public string TitleName { get; } public EditorControl() { } - protected EditorControl(T value, ISaveContext saveContext) + protected EditorControl(string titleName, T value, ISaveContext saveContext) { _ = value ?? throw new ArgumentNullException(nameof(value)); + TitleName = titleName; EditorValue = value; SaveContext = saveContext; } @@ -35,9 +39,20 @@ namespace PckStudio.Controls base.OnControlRemoved(e); } - public void Save() => SaveContext.Save(EditorValue); + public void SetSaveContext(ISaveContext saveContext) => SaveContext = saveContext; - public virtual void SaveAs() => throw new NotImplementedException(); + protected virtual void PreSave() + { } + + protected virtual void PostSave() + { } + + public void Save() + { + PreSave(); + SaveContext.Save(EditorValue); + PostSave(); + } public virtual void Close() => throw new NotImplementedException(); diff --git a/PCK-Studio/Controls/PckEditor.cs b/PCK-Studio/Controls/PckEditor.cs index dc461bac..d6f1fac6 100644 --- a/PCK-Studio/Controls/PckEditor.cs +++ b/PCK-Studio/Controls/PckEditor.cs @@ -52,9 +52,6 @@ namespace PckStudio.Controls { internal partial class PckEditor : EditorControl { - - private string _location = string.Empty; - private readonly OMI.ByteOrder _originalEndianness; private OMI.ByteOrder _currentEndianness; private bool __modified = false; @@ -78,8 +75,8 @@ namespace PckStudio.Controls private readonly Dictionary> _pckAssetTypeHandler; - public PckEditor(PackInfo packInfo, ISaveContext saveContext) - : base(packInfo, saveContext) + public PckEditor(string name, PackInfo packInfo, ISaveContext saveContext) + : base(name, packInfo, saveContext) { InitializeComponent(); _onModifiedChangeDelegate = OnModify; @@ -140,26 +137,13 @@ namespace PckStudio.Controls [PckAssetType.MaterialFile] = HandleMaterialFile, }; } - - public new void Save() + + protected override void PostSave() { - base.Save(); _timesSaved++; _wasModified = false; - } - - public override void SaveAs() - { - using SaveFileDialog saveFileDialog = new SaveFileDialog - { - Filter = "PCK (Minecraft Console Package)|*.pck", - DefaultExt = ".pck", - }; - if (saveFileDialog.ShowDialog() == DialogResult.OK) - { - SaveTo(saveFileDialog.FileName); - pckFileLabel.Text = "Current PCK File: " + Path.GetFileName(_location); - } + MessageBox.Show("Pck Saved.", "Saved"); + Debug.WriteLine($"_timesSaved: {_timesSaved}"); } public override void Close() @@ -178,12 +162,6 @@ namespace PckStudio.Controls BuildMainTreeView(); } - private void SaveTo(string filepath) - { - _location = filepath; - Save(); - } - private void HandleInnerPckFile(PckAsset asset) { if (asset.Type != PckAssetType.SkinDataFile && asset.Type != PckAssetType.TexturePackInfoFile || asset.Size <= 0 || !Settings.Default.LoadSubPcks) @@ -199,7 +177,7 @@ namespace PckStudio.Controls }); string caption = Path.GetFileName(asset.Filename); - string identifier = _location + Path.GetFileName(asset.Filename); + string identifier = TitleName + Path.GetFileName(asset.Filename); PckFile pckFile = asset.GetData(new PckFileReader(_originalEndianness)); PackInfo packInfo = PackInfo.Create(pckFile, _originalEndianness, false); @@ -1313,7 +1291,8 @@ namespace PckStudio.Controls return; } - if (string.IsNullOrEmpty(_location)) + // TODO: ! -null + if (true) { MessageBox.Show(this, "You must save your pck before creating or opening a music cues PCK file", "Can't create audio.pck"); return; diff --git a/PCK-Studio/Forms/ContributorsForm.Designer.cs b/PCK-Studio/Forms/ContributorsForm.Designer.cs index 47ae692c..fb7c7e28 100644 --- a/PCK-Studio/Forms/ContributorsForm.Designer.cs +++ b/PCK-Studio/Forms/ContributorsForm.Designer.cs @@ -70,9 +70,9 @@ metroLabel5.Enabled = false; metroLabel5.Location = new System.Drawing.Point(397, 456); metroLabel5.Name = "metroLabel5"; - metroLabel5.Size = new System.Drawing.Size(300, 19); + metroLabel5.Size = new System.Drawing.Size(298, 19); metroLabel5.TabIndex = 5; - metroLabel5.Text = "Additional development by MattNL and Miku-666"; + metroLabel5.Text = "Additional development by Miku-666 and MayNL"; metroLabel5.Theme = MetroFramework.MetroThemeStyle.Dark; // // metroLabel6 diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 197376ac..f3a7045d 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -35,7 +35,8 @@ using PckStudio.Properties; namespace PckStudio { public partial class MainForm : ImmersiveForm - { + { + private const string DEFAULT_PCK_SAVECONTEXT_DESCRIPTION = "PCK (Minecraft Console Package)"; private PckManager PckManager = null; private Dictionary openTabPages = new Dictionary(); @@ -92,7 +93,7 @@ namespace PckStudio private void AddEditorPage(string caption, string identifier, RawAssetDLCPackage packInfo, ISaveContext saveContext = null) { - saveContext ??= GetDefaultSaveContext("./new.pck", "PCK (Minecraft Console Package)"); + saveContext ??= GetDefaultSaveContext("./new.pck", DEFAULT_PCK_SAVECONTEXT_DESCRIPTION); var editor = new RawAssetsEditor(packInfo, saveContext); AddPage(caption, identifier, editor); } @@ -102,7 +103,7 @@ namespace PckStudio switch (dlcPackage.GetDLCPackageType()) { case DLCPackageType.RawAssets: - ISaveContext saveContext = GetDefaultSaveContext("", "PCK (Minecraft Console Package)"); + ISaveContext saveContext = GetDefaultSaveContext("", DEFAULT_PCK_SAVECONTEXT_DESCRIPTION); var editor = new RawAssetsEditor(dlcPackage as RawAssetDLCPackage, saveContext); TabPage page = AddPage(dlcPackage.Name, dlcPackage.Name, editor); break; @@ -126,7 +127,7 @@ namespace PckStudio private static ISaveContext GetDefaultSaveContext(string filepath, string description) { - return new DelegatedFileSaveContext(filepath, false, new FileDialogFilter(description, "*" + Path.GetExtension(filepath)), (packInfo, stream) => new PckFileWriter(packInfo.PckFile, packInfo.ByteOrder).WriteToStream(stream)); + return new DelegatedFileSaveContext(filepath, false, (packInfo, stream) => new PckFileWriter(packInfo.PckFile, packInfo.ByteOrder).WriteToStream(stream)); } private TabPage AddPage(string caption, string identifier, Control control) @@ -139,6 +140,7 @@ namespace PckStudio page.Name = identifier; page.Controls.Add(control); tabControl.TabPages.Add(page); + openTabPages.Add(identifier, page); tabControl.SelectTab(page); return page; } @@ -272,7 +274,7 @@ namespace PckStudio { using var ofd = new OpenFileDialog(); ofd.CheckFileExists = true; - ofd.Filter = "PCK (Minecraft Console Package)|*.pck"; + ofd.Filter = $"{DEFAULT_PCK_SAVECONTEXT_DESCRIPTION}|*.pck"; if (ofd.ShowDialog(this) == DialogResult.OK) { LoadPckFromFile(ofd.FileName); @@ -493,7 +495,17 @@ namespace PckStudio { if (TryGetCurrentEditor(out IEditor editor)) { - editor.SaveAs(); + using SaveFileDialog saveFileDialog = new SaveFileDialog + { + FileName = editor.TitleName, + Filter = "PCK (Minecraft Console Package)|*.pck", + DefaultExt = ".pck", + }; + if (saveFileDialog.ShowDialog() != DialogResult.OK) + return; + + editor.SetSaveContext(GetDefaultSaveContext(saveFileDialog.FileName, DEFAULT_PCK_SAVECONTEXT_DESCRIPTION)); + editor.Save(); } } diff --git a/PCK-Studio/Program.cs b/PCK-Studio/Program.cs index fa71d0b1..51d54c20 100644 --- a/PCK-Studio/Program.cs +++ b/PCK-Studio/Program.cs @@ -50,7 +50,7 @@ namespace PckStudio Updater.SetOwner(MainInstance); if (args.Length > 0) { - MainInstance.LoadPckFromFile(args.Where(arg => File.Exists(arg) && arg.EndsWith(".pck"))); + MainInstance.LoadPckFromFile(args.Where(arg => File.Exists(arg))); } Application.ApplicationExit += (sender, e) => { RPC.Deinitialize(); }; MainInstance.Focus(); diff --git a/PckStudio.Core/DelegatedFileSaveContext.cs b/PckStudio.Core/DelegatedFileSaveContext.cs index 98f78cd6..f1116f9e 100644 --- a/PckStudio.Core/DelegatedFileSaveContext.cs +++ b/PckStudio.Core/DelegatedFileSaveContext.cs @@ -8,6 +8,7 @@ using System.Windows.Forms; using Newtonsoft.Json.Linq; using PckStudio.Interfaces; using PckStudio.Core; +using System.Diagnostics; namespace PckStudio.Core { @@ -18,26 +19,16 @@ namespace PckStudio.Core public bool AutoSave { get; } public string Filepath { get; private set; } private SerializeDataToStreamDelegate _serializeDataDelegate; - private FileDialogFilter _dialogFilter; - public DelegatedFileSaveContext(string filepath, bool autoSave, FileDialogFilter dialogFilter, SerializeDataToStreamDelegate serializeDataDelegate) + public DelegatedFileSaveContext(string filepath, bool autoSave, SerializeDataToStreamDelegate serializeDataDelegate) { AutoSave = autoSave; Filepath = filepath; _serializeDataDelegate = serializeDataDelegate; - _dialogFilter = dialogFilter; } public void Save(T value) { - if (!File.Exists(Filepath)) - { - SaveFileDialog saveFileDialog = new SaveFileDialog(); - saveFileDialog.Filter = _dialogFilter.ToString(); - if (saveFileDialog.ShowDialog() != DialogResult.OK) - return; - Filepath = saveFileDialog.FileName; - } using (Stream stream = File.OpenWrite(Filepath)) { _serializeDataDelegate(value, stream); diff --git a/PckStudio.Core/Interfaces/IEditor.cs b/PckStudio.Core/Interfaces/IEditor.cs index dd19944d..2d6301ea 100644 --- a/PckStudio.Core/Interfaces/IEditor.cs +++ b/PckStudio.Core/Interfaces/IEditor.cs @@ -1,21 +1,23 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; -using OMI.Formats.Pck; namespace PckStudio.Interfaces { - public interface IEditor where T : class + public interface IEditor where T : notnull { + string TitleName { get; } + T EditorValue { get; } ISaveContext SaveContext { get; } - void Save(); + void SetSaveContext(ISaveContext saveContext); - void SaveAs(); + void Save(); void Close(); diff --git a/PckStudio.Rendering/PckStudio.Rendering.csproj b/PckStudio.Rendering/PckStudio.Rendering.csproj index 3e83c5d7..83a2fcf3 100644 --- a/PckStudio.Rendering/PckStudio.Rendering.csproj +++ b/PckStudio.Rendering/PckStudio.Rendering.csproj @@ -6,7 +6,7 @@ AnyCPU {B1E19D0F-6DD5-4D91-9B45-9818759CA8EF} Library - NDEBUG + NDEBUG Properties PckStudio.Rendering PckStudio.Rendering diff --git a/PckStuido.ModelSupport/SkinModelImporter.cs b/PckStuido.ModelSupport/SkinModelImporter.cs index 2cc7c2a8..77ee8199 100644 --- a/PckStuido.ModelSupport/SkinModelImporter.cs +++ b/PckStuido.ModelSupport/SkinModelImporter.cs @@ -70,6 +70,13 @@ namespace PckStudio.ModelSupport if (!blockBenchModel.Format.UseBoxUv) { Trace.TraceError($"[{nameof(SkinModelImporter)}:{nameof(ImportBlockBenchModel)}] Failed to import skin '{blockBenchModel.Name}': Skin does not use box uv."); + MessageBox.Show("Skin does not use box uv.", $"Failed to import skin '{blockBenchModel.Name}'", MessageBoxButtons.OK, MessageBoxIcon.Error); + return null; + } + if (!blockBenchModel.Elements.All(e => e.UseBoxUv)) + { + Trace.TraceError($"[{nameof(SkinModelImporter)}:{nameof(ImportBlockBenchModel)}] Failed to import skin '{blockBenchModel.Name}': Some boxes do not use box uv."); + MessageBox.Show("Some boxes do not use box uv.", $"Failed to import skin '{blockBenchModel.Name}'", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } @@ -443,6 +450,8 @@ namespace PckStudio.ModelSupport private static string TryConvertToSkinBoxType(string name) { + if (name is null) + return string.Empty; if (!SkinBOX.IsValidType(name) && SkinBOX.IsValidType(name.ToUpper())) { return name.ToUpper(); diff --git a/README.md b/README.md index 256c49e1..56590db9 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ $ cd PCK-Studio ## Active Developers: > [PhoenixARC](https://github.com/PhoenixARC)
-> [MattNL](https://github.com/MattN-L)
+> [MayNL](https://github.com/MayN-L)
> [Miku-666](https://github.com/NessieHax)
> [EternalModz](https://github.com/EternalModz)
diff --git a/Version.json b/Version.json index 0711d4f6..4f0f0999 100644 --- a/Version.json +++ b/Version.json @@ -1,6 +1,6 @@ { - "version": "7.0.1.0", - "url": "https://github.com/PhoenixARC/-PCK-Studio/releases/download/v7.0.1.0/PCK-Studio.zip", - "changelog": "https://raw.githubusercontent.com/PhoenixARC/-PCK-Studio/main/CHANGELOG.md", + "version": "7.0.1.1", + "url": "https://github.com/LCERD/PCK-Studio/releases/download/v7.0.1.1/PCK-Studio.zip", + "changelog": "https://raw.githubusercontent.com/LCERD/PCK-Studio/main/CHANGELOG.md", "mandatory": false } \ No newline at end of file