// This is f*****g performance not-wise if slicing was possible I would be so happy private void Merge(object sender, EventArgs e) { DocumentForm doc = mainForm.ActiveDocument as DocumentForm; if (doc == null) { return; } int index = (int)numericUpDown_frameIndex.Value, pic = (int)numericUpDown_pic.Value, next; int.TryParse(textBox_next.Text, out next); using (UndoHandler undoHandler = new UndoHandler(doc.Scintilla)) { for (int i = doc.Scintilla.Text.IndexOf("<frame>"), j = doc.Scintilla.Text.IndexOf("<frame_end>", i + 7); i >= 0 && j >= 0; i = doc.Scintilla.Text.IndexOf("<frame>", i + 7), j = doc.Scintilla.Text.IndexOf("<frame_end>", i + 7)) { var frameRange = doc.Scintilla.GetRange(i, j + 11); string frame = frameRange.Text; GroupCollection match = Regex.Match(frame, LF2DataUtils.Pattern.frame).Groups; int num; try { num = int.Parse(match[1].Value); } catch (Exception ex) { mainForm.formEventLog.Error(new LF2.IDE.LF2DataUtils.DataSyntaxException("Frame index could not be read\r\nFrame starting at line: " + doc.Scintilla.Lines.FromPosition(i).Number, ex), "Data Syntax Error"); return; } if (num >= numericUpDown_rangeStart.Value && num <= numericUpDown_rangeEnd.Value) { LF2DataUtils.Frame frameDat; try { frameDat = LF2DataUtils.ReadFrame(frame); } catch (LF2DataUtils.DataSyntaxException ex) { mainForm.formEventLog.Error(ex, "Data Syntax Error"); return; } if (checkBoxMerge_index.CheckState == CheckState.Checked) { frameDat.index = index; } if (checkBoxMerge_caption.CheckState == CheckState.Checked || checkBoxMerge_caption.CheckState == CheckState.Indeterminate && frameDat.caption != null) { frameDat.caption = comboBox_caption.Text; } if (checkBoxMerge_pic.CheckState == CheckState.Checked || checkBoxMerge_pic.CheckState == CheckState.Indeterminate && frameDat.pic.HasValue) { frameDat.pic = pic; } if (checkBoxMerge_state.CheckState == CheckState.Checked || checkBoxMerge_state.CheckState == CheckState.Indeterminate && frameDat.state.HasValue) { frameDat.state = int.Parse(comboBox_state.Text); } if (checkBoxMerge_wait.CheckState == CheckState.Checked || checkBoxMerge_wait.CheckState == CheckState.Indeterminate && frameDat.wait.HasValue) { frameDat.wait = int.Parse(textBox_wait.Text); } if (checkBoxMerge_next.CheckState == CheckState.Checked || checkBoxMerge_next.CheckState == CheckState.Indeterminate && frameDat.next.HasValue) { frameDat.next = next; } if (checkBoxMerge_dvx.CheckState == CheckState.Checked || checkBoxMerge_dvx.CheckState == CheckState.Indeterminate && frameDat.dvx.HasValue) { frameDat.dvx = int.Parse(textBox_dvx.Text); } if (checkBoxMerge_dvy.CheckState == CheckState.Checked || checkBoxMerge_dvy.CheckState == CheckState.Indeterminate && frameDat.dvy.HasValue) { frameDat.dvy = int.Parse(textBox_dvy.Text); } if (checkBoxMerge_dvz.CheckState == CheckState.Checked || checkBoxMerge_dvz.CheckState == CheckState.Indeterminate && frameDat.dvz.HasValue) { frameDat.dvz = int.Parse(textBox_dvz.Text); } if (checkBoxMerge_centerx.CheckState == CheckState.Checked || checkBoxMerge_centerx.CheckState == CheckState.Indeterminate && frameDat.centerx.HasValue) { frameDat.centerx = int.Parse(textBox_centerx.Text); } if (checkBoxMerge_centery.CheckState == CheckState.Checked || checkBoxMerge_centery.CheckState == CheckState.Indeterminate && frameDat.centery.HasValue) { frameDat.centery = int.Parse(textBox_centery.Text); } if (checkBoxMerge_hit_a.CheckState == CheckState.Checked || checkBoxMerge_hit_a.CheckState == CheckState.Indeterminate && frameDat.hit_a.HasValue) { frameDat.hit_a = int.Parse(textBox_hit_a.Text); } if (checkBoxMerge_hit_d.CheckState == CheckState.Checked || checkBoxMerge_hit_d.CheckState == CheckState.Indeterminate && frameDat.hit_d.HasValue) { frameDat.hit_d = int.Parse(textBox_hit_d.Text); } if (checkBoxMerge_hit_Da.CheckState == CheckState.Checked || checkBoxMerge_hit_Da.CheckState == CheckState.Indeterminate && frameDat.hit_Da.HasValue) { frameDat.hit_Da = int.Parse(textBox_hit_Da.Text); } if (checkBoxMerge_hit_Dj.CheckState == CheckState.Checked || checkBoxMerge_hit_Dj.CheckState == CheckState.Indeterminate && frameDat.hit_Dj.HasValue) { frameDat.hit_Dj = int.Parse(textBox_hit_Dj.Text); } if (checkBoxMerge_hit_Fa.CheckState == CheckState.Checked || checkBoxMerge_hit_Fa.CheckState == CheckState.Indeterminate && frameDat.hit_Fa.HasValue) { frameDat.hit_Fa = int.Parse(textBox_hit_Fa.Text); } if (checkBoxMerge_hit_Fj.CheckState == CheckState.Checked || checkBoxMerge_hit_Fj.CheckState == CheckState.Indeterminate && frameDat.hit_Fj.HasValue) { frameDat.hit_Fj = int.Parse(textBox_hit_Fj.Text); } if (checkBoxMerge_hit_j.CheckState == CheckState.Checked || checkBoxMerge_hit_j.CheckState == CheckState.Indeterminate && frameDat.hit_j.HasValue) { frameDat.hit_j = int.Parse(textBox_hit_j.Text); } if (checkBoxMerge_hit_ja.CheckState == CheckState.Checked || checkBoxMerge_hit_ja.CheckState == CheckState.Indeterminate && frameDat.hit_ja.HasValue) { frameDat.hit_ja = int.Parse(textBox_hit_ja.Text); } if (checkBoxMerge_hit_Ua.CheckState == CheckState.Checked || checkBoxMerge_hit_Ua.CheckState == CheckState.Indeterminate && frameDat.hit_Ua.HasValue) { frameDat.hit_Ua = int.Parse(textBox_hit_Ua.Text); } if (checkBoxMerge_hit_Uj.CheckState == CheckState.Checked || checkBoxMerge_hit_Uj.CheckState == CheckState.Indeterminate && frameDat.hit_Uj.HasValue) { frameDat.hit_Uj = int.Parse(textBox_hit_Uj.Text); } if (checkBoxMerge_sound.CheckState == CheckState.Checked || checkBoxMerge_sound.CheckState == CheckState.Indeterminate && frameDat.sound != null) { frameDat.sound = textBox_sound.Text; } frameRange.Text = frameDat.ToString(); if (checkBoxInc_index.Checked) { index++; } if (checkBoxInc_pic.Checked) { pic++; } if (checkBoxInc_next.Checked) { next++; } } } } }
// God save us from ever needing to write this kind of creepy code public bool SyncToDesign(bool auto = false) { if (documentType != DocumentType.ObjectData || auto && !mainForm.formDesign.checkBoxLinkage.Checked || !Monitor.TryEnter(syncLock)) { return(false); } try { Monitor.Enter(syncLock); int fs = Scintilla.Text.LastIndexOf("<frame>", Scintilla.Lines.Current.EndPosition); if (fs < 0) { return(false); } int fe = Scintilla.Text.IndexOf("<frame_end>", fs + 7); if (fe < 0 || fe + 11 < Scintilla.CurrentPos) { return(false); } var fr = Scintilla.GetRange(fs, fe + 11); { var frame = LF2DataUtils.ReadFrame(fr.Text); mainForm.formDesign.EditIn(); if (frame.pic.HasValue && frame.pic.Value <= mainForm.formDesign.numericUpDown_ImageIndex.Maximum) { mainForm.formDesign.numericUpDown_ImageIndex.Value = frame.pic.Value; } mainForm.formDesign.textBox_caption.Text = frame.caption; if (frame.bdys != null) { var bi = mainForm.formDesign.tagBox.ActiveBdyIndex; mainForm.formDesign.tagBox.BdyTags = new List <TagBox.Bdy>(frame.bdys.Select <LF2DataUtils.Bdy, TagBox.Bdy>((LF2DataUtils.Bdy bdy) => (TagBox.Bdy)bdy)); if (mainForm.formDesign.tagBox.BdyTags.Count == 1) { mainForm.formDesign.tagBox.ActiveBdyIndex = 0; } else if (bi.HasValue && bi.Value < mainForm.formDesign.tagBox.BdyTags.Count) { mainForm.formDesign.tagBox.ActiveBdyIndex = bi; } else { mainForm.formDesign.tagBox.ActiveBdyIndex = null; } if (mainForm.formDesign.tagBox.ActiveBdyIndex.HasValue) { LF2DataUtils.Bdy bdy = frame.bdys[mainForm.formDesign.tagBox.ActiveBdyIndex.Value]; if (bdy != null) { mainForm.formDesign.bdy_h.Text = bdy.h.HasValue ? bdy.h.ToString() : ""; mainForm.formDesign.bdy_kind.Text = bdy.kind.HasValue ? bdy.kind.ToString() : ""; mainForm.formDesign.bdy_w.Text = bdy.w.HasValue ? bdy.w.ToString() : ""; mainForm.formDesign.bdy_x.Text = bdy.x.HasValue ? bdy.x.ToString() : ""; mainForm.formDesign.bdy_y.Text = bdy.y.HasValue ? bdy.y.ToString() : ""; } } } else { mainForm.formDesign.tagBox.ClearBdyList(); mainForm.formDesign.bdy_h.Text = mainForm.formDesign.bdy_kind.Text = mainForm.formDesign.bdy_w.Text = mainForm.formDesign.bdy_x.Text = mainForm.formDesign.bdy_y.Text = ""; } if (frame.itrs != null) { var ti = mainForm.formDesign.tagBox.ActiveItrIndex; mainForm.formDesign.tagBox.ItrTags = new List <TagBox.Itr>(frame.itrs.Select <LF2DataUtils.Itr, TagBox.Itr>((LF2DataUtils.Itr itr) => (TagBox.Itr)itr)); if (mainForm.formDesign.tagBox.ItrTags.Count == 1) { mainForm.formDesign.tagBox.ActiveItrIndex = 0; } else if (ti.HasValue && ti.Value < mainForm.formDesign.tagBox.ItrTags.Count) { mainForm.formDesign.tagBox.ActiveItrIndex = ti; } else { mainForm.formDesign.tagBox.ActiveItrIndex = null; } if (mainForm.formDesign.tagBox.ActiveItrIndex.HasValue) { LF2DataUtils.Itr itr = frame.itrs[mainForm.formDesign.tagBox.ActiveItrIndex.Value]; if (itr != null) { mainForm.formDesign.itr_arest.Text = itr.arest.HasValue ? itr.arest.ToString() : ""; mainForm.formDesign.itr_bdefend.Text = itr.bdefend.HasValue ? itr.bdefend.ToString() : ""; mainForm.formDesign.itr_catchingact1.Text = itr.catchingact1.HasValue ? itr.catchingact1.ToString() : ""; mainForm.formDesign.itr_catchingact2.Text = itr.catchingact2.HasValue ? itr.catchingact2.ToString() : ""; mainForm.formDesign.itr_caughtact1.Text = itr.caughtact1.HasValue ? itr.caughtact1.ToString() : ""; mainForm.formDesign.itr_caughtact2.Text = itr.caughtact2.HasValue ? itr.caughtact2.ToString() : ""; mainForm.formDesign.itr_dvx.Text = itr.dvx.HasValue ? itr.dvx.ToString() : ""; mainForm.formDesign.itr_dvy.Text = itr.dvy.HasValue ? itr.dvy.ToString() : ""; mainForm.formDesign.itr_effect.Text = itr.effect.HasValue ? itr.effect.ToString() : ""; mainForm.formDesign.itr_fall.Text = itr.fall.HasValue ? itr.fall.ToString() : ""; mainForm.formDesign.itr_h.Text = itr.h.HasValue ? itr.h.ToString() : ""; mainForm.formDesign.itr_injury.Text = itr.injury.HasValue ? itr.injury.ToString() : ""; mainForm.formDesign.itr_kind.Text = itr.kind.HasValue ? itr.kind.ToString() : ""; mainForm.formDesign.itr_vrest.Text = itr.vrest.HasValue ? itr.vrest.ToString() : ""; mainForm.formDesign.itr_w.Text = itr.w.HasValue ? itr.w.ToString() : ""; mainForm.formDesign.itr_x.Text = itr.x.HasValue ? itr.x.ToString() : ""; mainForm.formDesign.itr_y.Text = itr.y.HasValue ? itr.y.ToString() : ""; mainForm.formDesign.itr_zwidth.Text = itr.zwidth.HasValue ? itr.zwidth.ToString() : ""; } } } else { mainForm.formDesign.tagBox.ClearItrList(); } if (frame.centerx.HasValue && frame.centery.HasValue) { mainForm.formDesign.tagBox.TagData.center = new Point(frame.centerx.Value, frame.centery.Value); } else { mainForm.formDesign.tagBox.TagData.center = null; } if (frame.bpoint != null) { mainForm.formDesign.tagBox.TagData.bpoint = (Point)frame.bpoint; } else { mainForm.formDesign.tagBox.TagData.bpoint = null; } if (frame.cpoint != null) { mainForm.formDesign.tagBox.TagData.cpoint = (TagBox.CPoint)frame.cpoint; } else { mainForm.formDesign.tagBox.TagData.cpoint = null; } if (frame.opoint != null) { mainForm.formDesign.tagBox.TagData.opoint = (TagBox.OPoint)frame.opoint; } else { mainForm.formDesign.tagBox.TagData.opoint = null; } if (frame.wpoint != null) { mainForm.formDesign.tagBox.TagData.wpoint = (TagBox.WPoint)frame.wpoint; } else { mainForm.formDesign.tagBox.TagData.wpoint = null; } mainForm.formDesign.RefreshAllTextBoxes(); } mainForm.formDesign.EditReset(); mainForm.formDesign.tagBox.Refresh(); return(true); } catch { mainForm.formDesign.EditReset(); mainForm.formDesign.tagBox.Invalidate(); return(false); } finally { Monitor.Exit(syncLock); } }