Beispiel #1
0
        public MediumLevelRecordEditor(SubRecord sr, SubrecordStructure ss, dFormIDLookupS formIDLookup,
                                       dFormIDScan formIDScan, dLStringLookup strIDLookup)
        {
            InitializeComponent();
            Icon = Resources.tesv_ico;
            SuspendLayout();
            this.sr           = sr;
            this.ss           = ss;
            this.formIDLookup = formIDLookup;
            this.formIDScan   = formIDScan;
            this.strIDLookup  = strIDLookup;

            int offset = 0;

            byte[] data = sr.GetReadonlyData();
            boxes      = new List <TextBox>(ss.elements.Length);
            valueTypes = new List <ElementValueType>(ss.elements.Length);
            elements   = new List <Panel>();
            int groupOffset  = 0;
            int CurrentGroup = 0;

            try
            {
                for (int i = 0; i < ss.elements.Length; i++)
                {
                    if (ss.elements[i].optional && offset == data.Length)
                    {
                        AddElement(ss.elements[i]);
                    }
                    else
                    {
                        AddElement(ss.elements[i], ref offset, data, ref groupOffset, ref CurrentGroup);
                        if (ss.elements[i].repeat > 0)
                        {
                            repeatcount++;
                            if (offset < data.Length)
                            {
                                i--;
                            }
                        }
                    }
                }
                if (ss.elements[ss.elements.Length - 1].repeat > 0 && repeatcount > 0)
                {
                    AddElement(ss.elements[ss.elements.Length - 1]);
                }
            }
            catch
            {
                MessageBox.Show("The subrecord doesn't appear to conform to the expected structure.\n" +
                                "Saving is disabled, and the formatted information may be incorrect", "Warning");
                bSave.Enabled = false;
            }
            ResumeLayout();
        }
        public MediumLevelRecordEditor(SubRecord sr, SubrecordStructure ss, dFormIDLookupS formIDLookup, dFormIDScan formIDScan, dLStringLookup strIDLookup)
        {
            this.InitializeComponent();
            Icon = Resources.tesv_ico;
            SuspendLayout();
            this.sr = sr;
            this.ss = ss;
            this.formIDLookup = formIDLookup;
            this.formIDScan = formIDScan;
            this.strIDLookup = strIDLookup;

            int offset = 0;
            byte[] data = sr.GetReadonlyData();
            this.boxes = new List<TextBox>(ss.elements.Length);
            this.valueTypes = new List<ElementValueType>(ss.elements.Length);
            this.elements = new List<Panel>();
            int groupOffset = 0;
            int CurrentGroup = 0;
            try
            {
                for (int i = 0; i < ss.elements.Length; i++)
                {
                    if (ss.elements[i].optional > 0 && offset == data.Length)
                    {
                        this.AddElement(ss.elements[i]);
                    }
                    else
                    {
                        this.AddElement(ss.elements[i], ref offset, data, ref groupOffset, ref CurrentGroup);
                        if (ss.elements[i].repeat > 0)
                        {
                            this.repeatcount++;
                            if (offset < data.Length)
                            {
                                i--;
                            }
                        }
                    }
                }

                if (ss.elements[ss.elements.Length - 1].repeat > 0 && this.repeatcount > 0)
                {
                    this.AddElement(ss.elements[ss.elements.Length - 1]);
                }
            }
            catch
            {
                MessageBox.Show("The subrecord doesn't appear to conform to the expected structure.\n" + "Saving is disabled, and the formatted information may be incorrect", "Warning");
                this.bSave.Enabled = false;
            }

            ResumeLayout();
        }
        public void EditSelectedSubrecord()
        {
            var context = Selection;
            var rec     = Selection.Record as Record;

            if (rec == null)
            {
                return;
            }
            var p = GetPluginFromNode(rec);

            if (p == null)
            {
                return;
            }
            var sr = GetSelectedSubrecord();

            if (sr == null)
            {
                return;
            }

            if (OnEditSubrecord != null)
            {
                OnEditSubrecord(sr, false);
                return;
            }

            if (Properties.Settings.Default.UseOldSubRecordEditor)
            {
                new DataEdit(sr.Name, sr.GetData()).ShowDialog();
                if (!DataEdit.Canceled)
                {
                    sr.SetData(DataEdit.result);
                    sr.Name = DataEdit.resultName;
                }
            }
            else if (!Properties.Settings.Default.UseHexSubRecordEditor &&
                     sr.Structure != null &&
                     sr.Structure.elements != null &&
                     sr.Structure.elements.Length > 0 &&
                     sr.Structure.elements[0].type != ElementValueType.Blob && !sr.Structure.UseHexEditor)
            {
                Form re;
                try
                {
                    if (Properties.Settings.Default.UseOldSubRecordEditor)
                    {
                        var r            = context.Record;
                        var formIDLookup = new dFormIDLookupS(p.LookupFormIDS);
                        var formIDScan   = new dFormIDScan(FormIDScan);
                        var strIDLookup  = new dLStringLookup(p.LookupFormStrings);
                        re = new MediumLevelRecordEditor(sr, sr.Structure, formIDLookup, formIDScan, strIDLookup);
                    }
                    else
                    {
                        re = new NewMediumLevelRecordEditor(p, rec, sr, sr.Structure);
                    }
                }
                catch
                {
                    MessageBox.Show("Subrecord doesn't seem to conform to the expected structure.", Resources.ErrorText);
                    re = null;
                }
                if (re != null)
                {
                    if (DialogResult.OK == re.ShowDialog(this))
                    {
                        if (sr.Parent is Record)
                        {
                            sr.Parent.UpdateShortDescription();
                        }
                        listSubrecord.Refresh();
                        FireSubrecordChanged(sr);
                        FireDataChanged();
                    }
                    return;
                }
            }
            else
            {
                EditSelectedSubrecordHex();
            }
        }