コード例 #1
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);
        }
コード例 #2
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
            }
        }