diff --git a/DataNode.cs b/DataNode.cs deleted file mode 100644 index ef3248d..0000000 --- a/DataNode.cs +++ /dev/null @@ -1,121 +0,0 @@ -using Substrate.Core; -using Substrate.Nbt; -using System.Collections.Generic; -using System; -using System.Windows.Forms; - -namespace NBTExplorer -{ - public class DataNodeOld - { - public DataNodeOld () - { - } - - public DataNodeOld (DataNodeOld parent) - { - Parent = parent; - } - - public DataNodeOld Parent { get; set; } - - private bool _modified; - public bool Modified - { - get { return _modified; } - set - { - if (value && Parent != null) { - Parent.Modified = value; - } - _modified = value; - } - } - - public bool Expanded { get; set; } - } - - public class NbtDataNode : DataNodeOld - { - public NbtDataNode () - { - } - - public NbtDataNode (DataNodeOld parent) - : base(parent) - { - } - - public NbtTree Tree { get; set; } - } - - public class RegionChunkData : NbtDataNode - { - public RegionChunkData (RegionFile file, int x, int z) - : this(null, file, x, z) - { - } - - public RegionChunkData (DataNodeOld parent, RegionFile file, int x, int z) - : base(parent) - { - Region = file; - X = x; - Z = z; - } - - public RegionFile Region { get; private set; } - public int X { get; private set; } - public int Z { get; private set; } - } - - public class RegionData : DataNodeOld - { - public RegionData (string path) - : this(null, path) - { - } - - public RegionData (DataNodeOld parent, string path) - : base(parent) - { - Path = path; - } - - public string Path { get; private set; } - } - - public class NbtFileData : NbtDataNode - { - public NbtFileData (string path, CompressionType cztype) - : this(null, path, cztype) - { - } - - public NbtFileData (DataNodeOld parent, string path, CompressionType cztype) - : base(parent) - { - Path = path; - CompressionType = cztype; - } - - public string Path { get; private set; } - public CompressionType CompressionType { get; private set; } - } - - public class DirectoryData : DataNodeOld - { - public DirectoryData (string path) - : this(null, path) - { - } - - public DirectoryData (DataNodeOld parent, string path) - : base(parent) - { - Path = path; - } - - public string Path { get; private set; } - } -} diff --git a/FormRegistry.cs b/FormRegistry.cs new file mode 100644 index 0000000..770959b --- /dev/null +++ b/FormRegistry.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using Substrate.Nbt; + +namespace NBTExplorer +{ + public static class FormRegistry + { + public delegate bool EditStringAction (StringFormData data); + public delegate bool EditRestrictedStringAction (RestrictedStringFormData data); + public delegate bool EditTagScalarAction (TagScalarFormData data); + public delegate bool EditByteArrayAction (ByteArrayFormData data); + + public static EditStringAction EditString { get; set; } + public static EditRestrictedStringAction RenameTag { get; set; } + public static EditTagScalarAction EditTagScalar { get; set; } + public static EditByteArrayAction EditByteArray { get; set; } + } + + public class TagScalarFormData + { + public TagScalarFormData (TagNode tag) + { + Tag = tag; + } + + public TagNode Tag { get; private set; } + } + + public class StringFormData + { + public StringFormData (String value) + { + Value = value; + } + + public String Value { get; set; } + } + + public class RestrictedStringFormData : StringFormData + { + private List _restricted = new List(); + + public RestrictedStringFormData (String value) + : base(value) + { + } + + public List RestrictedValues + { + get { return _restricted; } + } + } + + public class ByteArrayFormData + { + public string NodeName { get; set; } + public int BytesPerElement { get; set; } + public byte[] Data { get; set; } + } +} \ No newline at end of file diff --git a/Model/TagCompoundDataNode.cs b/Model/TagCompoundDataNode.cs index d4810ae..e6a36d5 100644 --- a/Model/TagCompoundDataNode.cs +++ b/Model/TagCompoundDataNode.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Windows.Forms; +using NBTExplorer.Windows; using Substrate.Nbt; namespace NBTExplorer.Model diff --git a/Model/TagDataNode.cs b/Model/TagDataNode.cs index 9ddc61f..0631752 100644 --- a/Model/TagDataNode.cs +++ b/Model/TagDataNode.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Windows.Forms; +//susing System.Windows.Forms; using Substrate.Nbt; namespace NBTExplorer.Model @@ -221,11 +221,12 @@ namespace NBTExplorer.Model public override bool RenameNode () { - if (CanRenameNode && TagParent.IsNamedContainer) { - EditName form = new EditName(TagParent.NamedTagContainer.GetTagName(Tag)); - form.InvalidNames.AddRange(TagParent.NamedTagContainer.TagNamesInUse); - if (form.ShowDialog() == DialogResult.OK && form.IsModified) { - if (TagParent.NamedTagContainer.RenameTag(Tag, form.TagName)) { + if (CanRenameNode && TagParent.IsNamedContainer && FormRegistry.EditString != null) { + RestrictedStringFormData data = new RestrictedStringFormData(TagParent.NamedTagContainer.GetTagName(Tag)); + data.RestrictedValues.AddRange(TagParent.NamedTagContainer.TagNamesInUse); + + if (FormRegistry.RenameTag(data)) { + if (TagParent.NamedTagContainer.RenameTag(Tag, data.Value)) { IsModified = true; return true; } @@ -284,61 +285,77 @@ namespace NBTExplorer.Model protected bool EditScalarValue (TagNode tag) { - EditValue form = new EditValue(tag); - if (form.ShowDialog() == DialogResult.OK) { - IsModified = true; - return true; + if (FormRegistry.EditTagScalar != null) { + if (FormRegistry.EditTagScalar(new TagScalarFormData(tag))) { + IsModified = true; + return true; + } } - else - return false; + return false; } protected bool EditStringValue (TagNode tag) { - EditString form = new EditString(tag.ToTagString().Data); - if (form.ShowDialog() == DialogResult.OK) { - tag.ToTagString().Data = form.StringValue; - - IsModified = true; - return true; + if (FormRegistry.EditString != null) { + StringFormData data = new StringFormData(tag.ToTagString().Data); + if (FormRegistry.EditString(data)) { + tag.ToTagString().Data = data.Value; + IsModified = true; + return true; + } } - else - return false; + return false; } protected bool EditByteHexValue (TagNode tag) { - HexEditor form = new HexEditor(NodeName, tag.ToTagByteArray().Data, 1); - if (form.ShowDialog() == DialogResult.OK && form.Modified) { - Array.Copy(form.Data, tag.ToTagByteArray().Data, tag.ToTagByteArray().Length); + if (FormRegistry.EditByteArray != null) { + byte[] byteData = new byte[tag.ToTagByteArray().Length]; + Array.Copy(tag.ToTagByteArray().Data, byteData, byteData.Length); - IsModified = true; - return true; + ByteArrayFormData data = new ByteArrayFormData() { + NodeName = NodeName, + BytesPerElement = 1, + Data = byteData, + }; + + if (FormRegistry.EditByteArray(data)) { + Array.Copy(data.Data, tag.ToTagByteArray().Data, tag.ToTagByteArray().Length); + IsModified = true; + return true; + } } - else - return false; + + return false; } protected bool EditIntHexValue (TagNode tag) { - TagNodeIntArray iatag = tag.ToTagIntArray(); - byte[] data = new byte[iatag.Length * 4]; - for (int i = 0; i < iatag.Length; i++) { - byte[] buf = BitConverter.GetBytes(iatag.Data[i]); - Array.Copy(buf, 0, data, 4 * i, 4); - } - - HexEditor form = new HexEditor(NodeName, data, 4); - if (form.ShowDialog() == DialogResult.OK && form.Modified) { + if (FormRegistry.EditByteArray != null) { + TagNodeIntArray iatag = tag.ToTagIntArray(); + byte[] byteData = new byte[iatag.Length * 4]; for (int i = 0; i < iatag.Length; i++) { - iatag.Data[i] = BitConverter.ToInt32(form.Data, i * 4); + byte[] buf = BitConverter.GetBytes(iatag.Data[i]); + Array.Copy(buf, 0, byteData, 4 * i, 4); } - IsModified = true; - return true; + ByteArrayFormData data = new ByteArrayFormData() { + NodeName = NodeName, + BytesPerElement = 4, + Data = byteData, + }; + + if (FormRegistry.EditByteArray(data)) { + for (int i = 0; i < iatag.Length; i++) { + iatag.Data[i] = BitConverter.ToInt32(data.Data, i * 4); + } + + IsModified = true; + return true; + } } - else - return false; + + return false; } } } diff --git a/TagKey.cs b/Model/TagKey.cs similarity index 96% rename from TagKey.cs rename to Model/TagKey.cs index d9279f1..a6f73bb 100644 --- a/TagKey.cs +++ b/Model/TagKey.cs @@ -1,7 +1,7 @@ using System; using Substrate.Nbt; -namespace NBTExplorer +namespace NBTExplorer.Model { public class TagKey : IComparable { diff --git a/NBTExplorer.csproj b/NBTExplorer.csproj index 3b17f28..a68738f 100644 --- a/NBTExplorer.csproj +++ b/NBTExplorer.csproj @@ -80,60 +80,60 @@ - + + Form - + CancelSearchForm.cs - - + + Form - + MainForm.cs - - + Form - + About.cs - + Form - + EditName.cs - + Form - + EditString.cs - + Form - + CreateNode.cs - + Form - + EditValue.cs - + Form - + Find.cs - + Form - + EditHex.cs @@ -170,7 +170,7 @@ Settings.settings - + Component @@ -191,32 +191,33 @@ - + + CancelSearchForm.cs - + MainForm.cs Designer - + About.cs - + EditName.cs - + EditString.cs - + CreateNode.cs - + EditValue.cs - + Find.cs - + EditHex.cs @@ -246,6 +247,7 @@ +