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); }
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(); } }
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(); } }