Exemplo n.º 1
0
        public void FreshLoad()
        {
            DocumentForm doc = mainForm.ActiveDocument;

            if (doc == null)
            {
                return;
            }
            comboBox_ObjId.SelectedIndex    = -1;
            comboBox_DataType.SelectedIndex = -1;
            comboBox_ObjType.SelectedIndex  = -1;
            comboBox_BgId.SelectedIndex     = -1;
            label_Result.Text = "";

            RefreshProcessList();

            switch (doc.DocumentType)
            {
            case DocumentType.ObjectData:
                comboBox_DataType.SelectedIndex = 0;
                comboBox_DataType.Enabled       = true;
                break;

            case DocumentType.StageData:
                comboBox_DataType.SelectedIndex = 1;
                comboBox_DataType.Enabled       = true;
                break;

            case DocumentType.BgData:
                comboBox_DataType.SelectedIndex = 2;
                comboBox_DataType.Enabled       = true;
                break;

            default:
                label_Result.Text         = "Unsupported document type: " + doc.DocumentType.ToString();
                comboBox_ObjId.Enabled    = false;
                comboBox_DataType.Enabled = false;
                comboBox_ObjType.Enabled  = false;
                comboBox_BgId.Enabled     = false;
                break;
            }
            string lfDir = Path.GetDirectoryName(Settings.Current.lfPath), dataTxtFile = lfDir + "\\data\\data.txt";

            if (!File.Exists(dataTxtFile))
            {
                MessageBox.Show("'data.txt' could not found. Make sure you set 'LF2 Path' correct in the settings menu.", Program.Title);
                this.Close();
                return;
            }

            comboBox_BgId.Items.Clear();
            comboBox_ObjId.Items.Clear();

            DateTime modification = File.GetLastWriteTime(dataTxtFile);

            if (modification > dataTxtLastModification)
            {
                dataTxtFile = File.ReadAllText(dataTxtFile);
                if (IDL.ReadDataTxt(dataTxtFile, dataTxtFile.Length, out dataTxt.objects, out dataTxt.objCount, out dataTxt.backgrounds, out dataTxt.bgCount, this.Handle) != 0)
                {
                    return;
                }

                dataTxtLastModification = modification;
            }

            for (int i = 0; i < dataTxt.objCount; i++)
            {
                comboBox_ObjId.Items.Add(string.Format("id: {0}  type: {1}  file: {2}", dataTxt.objects[i].id, (byte)dataTxt.objects[i].type, dataTxt.objects[i].file));
            }

            for (int i = 0; i < dataTxt.bgCount; i++)
            {
                comboBox_BgId.Items.Add(string.Format("id: {0}  file: {1}", dataTxt.backgrounds[i].id, dataTxt.backgrounds[i].file));
            }

            for (int i = 0; i < dataTxt.objCount; i++)
            {
                if (doc.FilePath != null ?
                    doc.FilePath.EndsWith(dataTxt.objects[i].file, StringComparison.InvariantCultureIgnoreCase) :
                    doc.TabText.EndsWith(dataTxt.objects[i].file, StringComparison.InvariantCultureIgnoreCase))
                {
                    comboBox_ObjId.SelectedIndex    = i;
                    comboBox_ObjType.SelectedIndex  = (int)dataTxt.objects[i].type;
                    comboBox_DataType.SelectedIndex = 0;
                    break;
                }
            }

            for (int i = 0; i < dataTxt.bgCount; i++)
            {
                if (doc.FilePath != null ?
                    doc.FilePath.EndsWith(dataTxt.backgrounds[i].file, StringComparison.InvariantCultureIgnoreCase) :
                    doc.TabText.EndsWith(dataTxt.backgrounds[i].file, StringComparison.InvariantCultureIgnoreCase))
                {
                    comboBox_BgId.SelectedIndex     = i;
                    comboBox_DataType.SelectedIndex = 2;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        // 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++;
                        }
                    }
                }
            }
        }