public override void Run(CommandArgs e)
        {
            if (this.Scene.Mode != EditMode.ModelMode ||
                this.Scene.ActiveModel == null)
            {
                MessageBox.Show(this.ApplicationForm, Util.Bilingual
                (
                    this.Scene.Language,
                    "適用するモデルがありません。\r\nモデルを選択している状態で実行してください。",
                    "No model to apply.\r\nPlease select a model to proceed."
                ), Util.Bilingual(this.Scene.Language, this.Text, this.EnglishText), MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;

                return;
            }

            var mmds = Process.GetProcessesByName("MikuMikuDance")
                              .Where(_ => _.Responding)
                              .Select(_ => new MmdImport(_))
                              .ToArray();

            try
            {
                if (!mmds.Any())
                {
                    MessageBox.Show(this.ApplicationForm, Util.Bilingual
                    (
                        this.Scene.Language,
                        "MikuMikuDance が起動されていません。\r\nMikuMikuDance が起動中であり、モデルが読み込まれている状態で実行してください。",
                        "Cannot find MikuMikuDance.\r\nPlease start MikuMikuDance and load a model to proceed."
                    ), Util.Bilingual(this.Scene.Language, this.Text, this.EnglishText), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }

                mmds = mmds.Where(_ => _.Models.Any()).ToArray();

                if (!mmds.Any())
                {
                    MessageBox.Show(this.ApplicationForm, Util.Bilingual
                    (
                        this.Scene.Language,
                        "MikuMikuDance にモデルが読み込まれていません。\r\nモデルが読み込まれている状態で実行してください。",
                        "No model found on MikuMikuDance.\r\nNeeds at least one model loaded on MikuMikuDance to proceed."
                    ), Util.Bilingual(this.Scene.Language, this.Text, this.EnglishText), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }

                Action reset = null;

                using (var f = new GetMmdTransformationForm(this.Scene.Language, mmds))
                {
                    f.SelectedModelChanged += (sender, e2) => SynchronizeTransformation(f.SelectedModel, ref reset);

                    if (f.ShowDialog(this.ApplicationForm) != DialogResult.OK)
                    {
                        e.Cancel = true;

                        if (reset != null)
                        {
                            reset();
                            reset = null;
                        }

                        return;
                    }

                    SynchronizeTransformation(f.SelectedModel, ref reset);
                }
            }
            finally
            {
                foreach (var i in mmds)
                    i.Dispose();
            }
        }
Ejemplo n.º 2
0
        public override void Run(CommandArgs e)
        {
            if (this.Scene.Mode != EditMode.ModelMode ||
                this.Scene.ActiveModel == null)
            {
                MessageBox.Show(this.ApplicationForm, Util.Bilingual
                                (
                                    this.Scene.Language,
                                    "適用するモデルがありません。\r\nモデルを選択している状態で実行してください。",
                                    "No model to apply.\r\nPlease select a model to proceed."
                                ), Util.Bilingual(this.Scene.Language, this.Text, this.EnglishText), MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;

                return;
            }

            var mmds = Process.GetProcessesByName("MikuMikuDance")
                       .Where(_ => _.Responding)
                       .Select(_ => new MmdImport(_))
                       .ToArray();

            try
            {
                if (!mmds.Any())
                {
                    MessageBox.Show(this.ApplicationForm, Util.Bilingual
                                    (
                                        this.Scene.Language,
                                        "MikuMikuDance が起動されていません。\r\nMikuMikuDance が起動中であり、モデルが読み込まれている状態で実行してください。",
                                        "Cannot find MikuMikuDance.\r\nPlease start MikuMikuDance and load a model to proceed."
                                    ), Util.Bilingual(this.Scene.Language, this.Text, this.EnglishText), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }

                mmds = mmds.Where(_ => _.Models.Any()).ToArray();

                if (!mmds.Any())
                {
                    MessageBox.Show(this.ApplicationForm, Util.Bilingual
                                    (
                                        this.Scene.Language,
                                        "MikuMikuDance にモデルが読み込まれていません。\r\nモデルが読み込まれている状態で実行してください。",
                                        "No model found on MikuMikuDance.\r\nNeeds at least one model loaded on MikuMikuDance to proceed."
                                    ), Util.Bilingual(this.Scene.Language, this.Text, this.EnglishText), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }

                Action reset = null;

                using (var f = new GetMmdTransformationForm(this.Scene.Language, mmds))
                {
                    f.SelectedModelChanged += (sender, e2) => SynchronizeTransformation(f.SelectedModel, ref reset);

                    if (f.ShowDialog(this.ApplicationForm) != DialogResult.OK)
                    {
                        e.Cancel = true;

                        if (reset != null)
                        {
                            reset();
                            reset = null;
                        }

                        return;
                    }

                    SynchronizeTransformation(f.SelectedModel, ref reset);
                }
            }
            finally
            {
                foreach (var i in mmds)
                {
                    i.Dispose();
                }
            }
        }