Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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));
     }
 }
Ejemplo n.º 3
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();
            }
        }