コード例 #1
0
 private Image GetImage(INode node)
 {
     if (IconSource is null)
     {
         return(null);
     }
     if (node is NbtFileNode)
     {
         return(IconSource.GetImage(IconType.File).Image);
     }
     if (node is FolderNode)
     {
         return(IconSource.GetImage(IconType.Folder).Image);
     }
     if (node is RegionFileNode)
     {
         return(IconSource.GetImage(IconType.Region).Image);
     }
     if (node is ChunkNode)
     {
         return(IconSource.GetImage(IconType.Chunk).Image);
     }
     if (node is NbtTagNode tag)
     {
         return(NbtUtil.TagTypeImage(IconSource, tag.Tag.TagType).Image);
     }
     return(null);
 }
コード例 #2
0
ファイル: ExportWindow.cs プロジェクト: tryashtar/nbt-studio
 public ExportWindow(IconSource source, ExportSettings template, string destination_path)
 {
     InitializeComponent();
     this.Icon = source.GetImage(IconType.Save).Icon;
     CompressionBox.Items.Add(new CompressionDisplay("Uncompressed", NbtCompression.None));
     CompressionBox.Items.Add(new CompressionDisplay("G-Zip", NbtCompression.GZip));
     CompressionBox.Items.Add(new CompressionDisplay("ZLib", NbtCompression.ZLib));
     CompressionBox.SelectedIndex = 0;
     if (template is not null)
     {
         RadioSnbt.Checked           = template.Snbt;
         RadioNbt.Checked            = !template.Snbt;
         CompressionBox.SelectedItem = CompressionBox.Items.Cast <CompressionDisplay>().FirstOrDefault(x => x.Compression == template.Compression);
         CheckMinify.Checked         = template.Minified;
         CheckJson.Checked           = template.Json;
         CheckLittleEndian.Checked   = !template.BigEndian;
         CheckBedrockHeader.Checked  = template.BedrockHeader;
     }
     else
     {
         string extension = Path.GetExtension(destination_path);
         bool?  binary    = NbtUtil.BinaryExtension(extension);
         RadioSnbt.Checked         = binary == false;
         RadioNbt.Checked          = binary == true;
         CheckLittleEndian.Checked = extension == ".mcstructure";
         CheckJson.Checked         = extension == ".json";
     }
     SetEnables();
     Tooltips.SetToolTip(CheckLittleEndian, "Required for all Bedrock Edition files");
     Tooltips.SetToolTip(CheckBedrockHeader, "Required for Bedrock Edition level.dat files");
     Tooltips.SetToolTip(CheckJson, "Quotes all keys, removes type suffixes and list indicators");
 }
コード例 #3
0
        private object GetValue()
        {
            var text = GetValueText();

            if (text == "")
            {
                return(null);
            }
            return(NbtUtil.ParseValue(text, NbtTag.TagType));
        }
コード例 #4
0
        private EditHexWindow(IconSource source, NbtTag tag, NbtContainerTag parent, bool set_name, EditPurpose purpose)
        {
            InitializeComponent();
            TabView.Size = new Size(0, 0);

            WorkingTag = tag;
            TagParent  = parent;
            NameBox.SetTags(tag, parent);

            SettingName       = set_name;
            NameLabel.Visible = SettingName;
            NameBox.Visible   = SettingName;

            Provider                     = ByteProviders.GetByteProvider(tag);
            HexBox.ByteProvider          = Provider;
            HexBox.GroupSize             = Provider.BytesPerValue;
            HexBox.GroupSeparatorVisible = Provider.BytesPerValue > 1;
            HexBox.SelectionBackColor    = Constants.SelectionColor;
            HexBox.SelectionForeColor    = HexBox.ForeColor;

            string tagname;

            if (tag is NbtList list)
            {
                tagname   = NbtUtil.TagTypeName(list.ListType) + " List";
                this.Icon = NbtUtil.TagTypeImage(source, list.ListType).Icon;
            }
            else
            {
                tagname   = NbtUtil.TagTypeName(tag.TagType);
                this.Icon = NbtUtil.TagTypeImage(source, tag.TagType).Icon;
            }
            if (purpose == EditPurpose.Create)
            {
                this.Text = $"Create {tagname} Tag";
            }
            else if (purpose == EditPurpose.EditValue || purpose == EditPurpose.Rename)
            {
                this.Text = $"Edit {tagname} Tag";
            }

            if (SettingName && purpose != EditPurpose.EditValue)
            {
                NameBox.Select();
                NameBox.SelectAll();
            }
            else
            {
                HexBox.Select();
            }
        }
コード例 #5
0
 public static string PreviewValue(INode node)
 {
     if (node is NbtFileNode file)
     {
         return(NbtUtil.PreviewNbtValue(file.File.RootTag));
     }
     if (node is FolderNode folder_node)
     {
         var folder = folder_node.Folder;
         if (folder.HasScanned)
         {
             if (folder.Subfolders.Any())
             {
                 return($"[{StringUtils.Pluralize(folder.Subfolders.Count, "folder")}, {StringUtils.Pluralize(folder.Files.Count, "file")}]");
             }
             else
             {
                 return($"[{StringUtils.Pluralize(folder.Files.Count, "file")}]");
             }
         }
         else
         {
             return("(open to load)");
         }
     }
     if (node is RegionFileNode region)
     {
         return($"[{StringUtils.Pluralize(region.Region.ChunkCount, "chunk")}]");
     }
     if (node is ChunkNode chunk_node)
     {
         var chunk = chunk_node.Chunk;
         if (chunk.IsLoaded)
         {
             return(NbtUtil.PreviewNbtValue(chunk.Data));
         }
         else if (chunk.IsExternal)
         {
             return("(saved externally)");
         }
         else
         {
             return("(open to load)");
         }
     }
     if (node is NbtTagNode tag)
     {
         return(NbtUtil.PreviewNbtValue(tag.Tag));
     }
     return(null);
 }
コード例 #6
0
        public static NbtTag CreateTag(IconSource source, NbtTagType type, NbtContainerTag parent, bool bypass_window = false)
        {
            bool has_name = parent is NbtCompound;
            var  tag      = NbtUtil.CreateTag(type);

            if (bypass_window)
            {
                tag.Name = NbtUtil.GetAutomaticName(tag, parent);
                return(tag);
            }
            var window = new EditHexWindow(source, tag, parent, has_name, EditPurpose.Create);

            return(window.ShowDialog() == DialogResult.OK ? tag : null);
        }
コード例 #7
0
 public void ApplyValue(object value)
 {
     if (value is null)
     {
         NbtUtil.ResetValue(NbtTag);
     }
     else
     {
         var current = NbtUtil.GetValue(NbtTag);
         if (!current.Equals(value))
         {
             NbtUtil.SetValue(NbtTag, value);
         }
     }
 }
コード例 #8
0
 private void ShowTooltip(ValueCheckResult result)
 {
     if (result == ValueCheckResult.InvalidFormat)
     {
         ShowTooltip("Invalid Format", $"The value is formatted incorrectly for a {NbtUtil.TagTypeName(NbtTag.TagType).ToLower()}", TimeSpan.FromSeconds(2));
     }
     else if (result == ValueCheckResult.InvalidOutOfRange)
     {
         var(min, max) = NbtUtil.MinMaxFor(NbtTag.TagType);
         ShowTooltip("Out of Range", $"The value for {NbtUtil.TagTypeName(NbtTag.TagType).ToLower()}s must be between {min} and {max}", TimeSpan.FromSeconds(4));
     }
     else if (result == ValueCheckResult.InvalidUnknown)
     {
         ShowTooltip("Unknown Error", "There was an unknown error attempting to parse the value", TimeSpan.FromSeconds(2));
     }
 }
コード例 #9
0
        public static bool ModifyTag(IconSource source, NbtTag existing, EditPurpose purpose)
        {
            if (purpose == EditPurpose.Create)
            {
                throw new ArgumentException("Use CreateTag to create tags");
            }
            var  parent    = existing.Parent;
            bool has_name  = parent is NbtCompound;
            bool has_value = NbtUtil.IsValueType(existing.TagType);

            if (has_name || has_value)
            {
                var window = new EditTagWindow(source, existing, parent, has_name, has_value, purpose);
                return(window.ShowDialog() == DialogResult.OK); // window modifies the tag by itself
            }
            return(false);
        }
コード例 #10
0
        public static NbtTag CreateTag(IconSource source, NbtTagType type, NbtContainerTag parent, bool bypass_window = false)
        {
            bool has_name  = parent is NbtCompound;
            bool has_value = NbtUtil.IsValueType(type);

            var tag = NbtUtil.CreateTag(type);

            if (bypass_window)
            {
                tag.Name = NbtUtil.GetAutomaticName(tag, parent);
                return(tag);
            }
            else if (has_name || has_value)
            {
                var window = new EditTagWindow(source, tag, parent, has_name, has_value, EditPurpose.Create);
                return(window.ShowDialog() == DialogResult.OK ? tag : null);
            }
            else
            {
                return(tag); // no customization required, example: adding a compound to a list
            }
        }
コード例 #11
0
        public void MoveAfter()
        {
            var compound = new NbtCompound
            {
                new NbtByte("a", 0),
                new NbtByte("b", 1),
                new NbtByte("c", 2),
                new NbtByte("d", 3),
                new NbtByte("e", 4),
                new NbtByte("f", 5),
                new NbtByte("g", 6),
            };
            var tags   = compound.Tags.ToList();
            var moving = new List <NbtTag> {
                tags[1], tags[3], tags[5]
            };
            var correct_order = new List <NbtTag> {
                tags[0], tags[2], tags[4], /**/ tags[1], tags[3], tags[5], /**/ tags[6]
            };

            NbtUtil.TransformInsert(moving, compound, 6);

            Assert.IsTrue(compound.Tags.SequenceEqual(correct_order));
        }
コード例 #12
0
        private EditTagWindow(IconSource source, NbtTag tag, NbtContainerTag parent, bool set_name, bool set_value, EditPurpose purpose)
        {
            InitializeComponent();

            NameBox.SetTags(tag, parent);
            ValueBox.SetTags(tag, parent, fill_current_value: purpose != EditPurpose.Create);

            SettingName = set_name;
            if (!SettingName)
            {
                this.MinimumSize = new Size(MinimumSize.Width, MinimumSize.Height - MainTable.GetRowHeights()[0]);
                this.Height     -= MainTable.GetRowHeights()[0];
                MainTable.RowStyles[0].Height = 0;
                NameLabel.Visible             = false;
                NameBox.Visible = false;
            }

            SettingValue = set_value;
            if (!SettingValue)
            {
                this.MinimumSize   = new Size(MinimumSize.Width, MinimumSize.Height - MainTable.GetRowHeights()[1]);
                this.Height       -= MainTable.GetRowHeights()[1];
                ValueLabel.Visible = false;
                ValueBox.Visible   = false;
            }

            if (tag.TagType == NbtTagType.String)
            {
                ValueBox.Multiline     = true;
                ValueBox.AcceptsReturn = true;
                ValueBox.Anchor        = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right;
                this.AutoSize          = false;
                this.Width             = (int)(this.Width * 1.5);
                this.Height            = (int)(this.Height * 1.5);
                this.FormBorderStyle   = FormBorderStyle.Sizable;
                WordWrapCheck.Visible  = true;
                WordWrapCheck_CheckedChanged(this, EventArgs.Empty);
            }
            else if (NbtUtil.IsNumericType(tag.TagType))
            {
                ValueBox.PlaceholderText = "0";
            }
            this.Icon = NbtUtil.TagTypeImage(source, tag.TagType).Icon;
            if (purpose == EditPurpose.Create)
            {
                this.Text = $"Create {NbtUtil.TagTypeName(tag.TagType)} Tag";
            }
            else if (purpose == EditPurpose.EditValue || purpose == EditPurpose.Rename)
            {
                this.Text = $"Edit {NbtUtil.TagTypeName(tag.TagType)} Tag";
            }

            if (SettingName && (!SettingValue || purpose != EditPurpose.EditValue))
            {
                NameBox.Select();
                NameBox.SelectAll();
            }
            else if (SettingValue)
            {
                ValueBox.Select();
                ValueBox.SelectAll();
            }
        }