Exemplo n.º 1
0
        public CollisionCapsule(NwCollisionCapsule shape)
        {
            InitializeComponent();
            this.shape = shape;

            if (shape != null)
            {
                numericUpDown_height.Value = (decimal)shape.Height;
                numericUpDown_radius.Value = (decimal)shape.Radius;

                numericUpDown_height.ValueChanged += (s, e) => shape.Height = (float)numericUpDown_height.Value;
                numericUpDown_radius.ValueChanged += (s, e) => shape.Radius = (float)numericUpDown_radius.Value;
            }
        }
Exemplo n.º 2
0
        public MainForm_MWC()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
            ShowPreviewWindow();

            menu_exit.Click += (s, e) =>
            {
                var res = MessageBox.Show("終了しますか?", "確認", MessageBoxButtons.YesNo);
                if (res == DialogResult.Yes)
                {
                    Close();
                }
            };

            // general
            textBox_name.TextChanged += (s, e) =>
            {
                if (chara == null)
                {
                    return;
                }
                chara.Name = textBox_name.Text;
            };
            textBox_editor.TextChanged += (s, e) =>
            {
                if (chara == null)
                {
                    return;
                }
                chara.Editor = textBox_editor.Text;
            };
            textBox_url.TextChanged += (s, e) =>
            {
                if (chara == null)
                {
                    return;
                }
                chara.EditorURL = textBox_url.Text;
            };
            textBox_version.TextChanged += (s, e) =>
            {
                if (chara == null)
                {
                    return;
                }
                chara.Version = textBox_version.Text;
            };
            textBox_tags.TextChanged += (s, e) =>
            {
                if (chara == null)
                {
                    return;
                }
                chara.Tags = textBox_tags.Text;
            };
            textBox_desc.TextChanged += (s, e) =>
            {
                if (chara == null)
                {
                    return;
                }
                chara.Description = textBox_desc.Text;
            };


            // material
            colorPanel_albedo.ColorChanged += (s, e) =>
            {
                if (game == null || game.gameObj == null)
                {
                    return;
                }
                var c = new Color4(e.R / 255.0f, e.G / 255.0f, e.B / 255.0f, slider_alpha.Value);
                game.SetMaterialParam <Color4>(listBox_material.SelectedIndex, Resources.Albedo, c);
                ((NwMaterial)listBox_material.SelectedItem).Color4s[Resources.Albedo] = c.ToColor4f();
            };
            colorPanel_emis.ColorChanged += (s, e) =>
            {
                if (game == null || game.gameObj == null)
                {
                    return;
                }
                game.SetMaterialParam <Color4>(listBox_material.SelectedIndex, "emissive", e);
                ((NwMaterial)listBox_material.SelectedItem).Color4s["emissive"] = e.ToColor4f();
            };
            slider_roughness.ValueChanged += (s, e) =>
            {
                if (game == null || game.gameObj == null)
                {
                    return;
                }
                game.SetMaterialParam(listBox_material.SelectedIndex, "roughness", e);
                ((NwMaterial)listBox_material.SelectedItem).Floats["roughness"] = e;
            };
            slider_metallic.ValueChanged += (s, e) =>
            {
                if (game == null || game.gameObj == null)
                {
                    return;
                }
                game.SetMaterialParam(listBox_material.SelectedIndex, "metallic", e);
                ((NwMaterial)listBox_material.SelectedItem).Floats["metallic"] = e;
            };
            slider_reflectance.ValueChanged += (s, e) =>
            {
                if (game == null || game.gameObj == null)
                {
                    return;
                }
                game.SetMaterialParam(listBox_material.SelectedIndex, "reflectance", e);
                ((NwMaterial)listBox_material.SelectedItem).Floats["reflectance"] = e;
            };
            slider_alpha.ValueChanged += (s, e) =>
            {
                if (game == null || game.gameObj == null)
                {
                    return;
                }
                var color = colorPanel_albedo.BackColor;
                var c     = new Color4(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, e);
                game.SetMaterialParam(listBox_material.SelectedIndex, Resources.Albedo, c);
                ((NwMaterial)listBox_material.SelectedItem).Color4s[Resources.Albedo] = c.ToColor4f();
            };

            // physics
            radioButton_capsule.CheckedChanged += (s, e) =>
            {
                if (chara == null || !radioButton_capsule.Checked)
                {
                    return;
                }
                NwCollisionCapsule cc;
                if (chara.CollisionShape is NwCollisionCapsule)
                {
                    cc = chara.CollisionShape as NwCollisionCapsule;
                }
                else
                {
                    cc = new NwCollisionCapsule();
                    chara.CollisionShape = cc;
                }
                var c = new CollisionCapsule(cc)
                {
                    Location = new Point(20, 45)
                };

                groupBox_collisionShape.Controls.Remove(collisionShapeCtrl);
                groupBox_collisionShape.Controls.Add(collisionShapeCtrl = c);
                game.SetPhysics(collisionShapeCtrl as ICollisionShape);
            };
            radioButton_cylinder.CheckedChanged += (s, e) =>
            {
                if (chara == null || !radioButton_cylinder.Checked)
                {
                    return;
                }
                NwCollisionCylinder cc;
                if (chara.CollisionShape is NwCollisionCylinder)
                {
                    cc = chara.CollisionShape as NwCollisionCylinder;
                }
                else
                {
                    cc = new NwCollisionCylinder();
                    chara.CollisionShape = cc;
                }
                var c = new CollisionCylinder(cc)
                {
                    Location = new Point(20, 45)
                };

                groupBox_collisionShape.Controls.Remove(collisionShapeCtrl);
                groupBox_collisionShape.Controls.Add(collisionShapeCtrl = c);
                game.SetPhysics(collisionShapeCtrl as ICollisionShape);
            };
            radioButton_box.CheckedChanged += (s, e) =>
            {
                if (chara == null || !radioButton_box.Checked)
                {
                    return;
                }
                NwCollisionBox cc;
                if (chara.CollisionShape is NwCollisionBox)
                {
                    cc = chara.CollisionShape as NwCollisionBox;
                }
                else
                {
                    cc = new NwCollisionBox();
                    chara.CollisionShape = cc;
                }
                var c = new CollisionBox(cc)
                {
                    Location = new Point(20, 45)
                };

                groupBox_collisionShape.Controls.Remove(collisionShapeCtrl);
                groupBox_collisionShape.Controls.Add(collisionShapeCtrl = c);
                game.SetPhysics(collisionShapeCtrl as ICollisionShape);
            };
            radioButton_sphere.CheckedChanged += (s, e) =>
            {
                if (chara == null || !radioButton_sphere.Checked)
                {
                    return;
                }
                NwCollisionSphere cc;
                if (chara.CollisionShape is NwCollisionSphere)
                {
                    cc = chara.CollisionShape as NwCollisionSphere;
                }
                else
                {
                    cc = new NwCollisionSphere();
                    chara.CollisionShape = cc;
                }
                var c = new CollisionSphere(cc)
                {
                    Location = new Point(20, 45)
                };

                groupBox_collisionShape.Controls.Remove(collisionShapeCtrl);
                groupBox_collisionShape.Controls.Add(collisionShapeCtrl = c);
                game.SetPhysics(collisionShapeCtrl as ICollisionShape);
            };

            numericUpDown_mass.ValueChanged += (s, e) =>
            {
                chara.Mass = (float)numericUpDown_mass.Value;
            };

            tabControl.SelectedIndexChanged += (s, e) =>
            {
                if (tabControl.SelectedTab == tabPage_physics)
                {
                    game.SetPhysics(collisionShapeCtrl as ICollisionShape);

                    if (collisionShapeCtrl is CollisionCapsule)
                    {
                        radioButton_capsule.Checked = true;
                    }
                    else if (collisionShapeCtrl is CollisionCylinder)
                    {
                        radioButton_cylinder.Checked = true;
                    }
                    else if (collisionShapeCtrl is CollisionBox)
                    {
                        radioButton_box.Checked = true;
                    }
                    else if (collisionShapeCtrl is CollisionSphere)
                    {
                        radioButton_sphere.Checked = true;
                    }
                }
                else
                {
                    game.SetPhysics(null);
                }

                if (tabControl.SelectedTab == tabPage_material)
                {
                    listBox_material_SelectedIndexChanged(this, EventArgs.Empty);
                }
            };

            // motion
            menu_motion.Click += (s, e) =>
            {
                if (chara == null)
                {
                    MessageBox.Show("モデルがまだ読み込まれていません。", "Error", MessageBoxButtons.OK);
                    return;
                }

                var ofd = new OpenFileDialog();
                ofd.Filter = "モーションファイル|*.vmd|すべてのファイル|*.*";

                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    var ext      = Path.GetExtension(ofd.FileName);
                    var importer = importers.Find((i) => Array.Exists(i.Extensions, (ex) => ex == ext));

                    var motion = importer.Import(ofd.FileName, ImportType.Full)[0];

                    var mos = ConvertMotion(motion);

                    foreach (var mo in mos)
                    {
                        var idx = dataGridView_motion.Rows.Add("", mo.Name);
                        dataGridView_motion.Rows[idx].Tag = mo;
                    }
                }
                catch
                {
                    MessageBox.Show("ファイルの読み込みに失敗しました。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Cursor.Current = Cursors.Default;
            };

            // sound
            menu_sound.Click += (s, e) =>
            {
                if (chara == null)
                {
                    MessageBox.Show("モデルがまだ読み込まれていません。", "Error", MessageBoxButtons.OK);
                    return;
                }

                var ofd = new OpenFileDialog();
                ofd.Filter = "音楽ファイル|*.wav;*.mp3|すべてのファイル|*.*";
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var r   = dataGridView_sound.Rows.Add();
                var row = dataGridView_sound.Rows[r];

                try
                {
                    AudioFileReader afd    = new AudioFileReader(ofd.FileName);
                    var             bytes  = File.ReadAllBytes(ofd.FileName);
                    var             format = "WAV";
                    if (ofd.FileName.Contains(".mp3"))
                    {
                        format = "MP3";
                    }
                    var waveOut = new WaveOut();
                    waveOut.Init(afd);

                    var name = Path.GetFileNameWithoutExtension(ofd.FileName);
                    row.Cells[0].Value = name;
                    row.Tag            = new Tuple <AudioFileReader, WaveOut, byte[], string>(afd, waveOut, bytes, format);
                }
                catch
                {
                    MessageBox.Show("ファイルの読み込みに失敗しました。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dataGridView_sound.Rows.Remove(row);
                    return;
                }
            };
            dataGridView_sound.CellContentClick += (s, e) =>
            {
                var dgv = (DataGridView)s;
                if (dgv.Columns[e.ColumnIndex].Name == "ColumnPlay")
                {
                    var o = dgv.Rows[e.RowIndex].Tag as Tuple <AudioFileReader, WaveOut, byte[], string>;
                    foreach (DataGridViewRow r in dgv.Rows)
                    {
                        var t = r.Tag as Tuple <AudioFileReader, WaveOut, byte[], string>;
                        if (t != null)
                        {
                            t.Item2.Stop();
                            t.Item1.Position = 0;
                        }
                    }
                    o.Item2.Volume = 0.4f;
                    o.Item2.Play();
                }
            };

            // script
            listBox_scripts.DisplayMember         = "Name";
            listBox_scripts.SelectedIndexChanged += (s, e) =>
            {
                var info = listBox_scripts.SelectedItem as ScriptInfo;
                if (info != null)
                {
                    textBox_scriptName.Text     = info.Script.ScriptName;
                    textBox_scriptDesc.Text     = info.Script.ScriptDesc;
                    button_scriptRemove.Enabled = listBox_scripts.Items.Count > 0;
                    button_scriptUp.Enabled     = listBox_scripts.SelectedIndex > 0;
                    button_scriptDown.Enabled   = listBox_scripts.SelectedIndex < listBox_scripts.Items.Count - 1;
                }
                else
                {
                    textBox_scriptName.Text     = "";
                    textBox_scriptDesc.Text     = "";
                    button_scriptRemove.Enabled = false;
                    button_scriptUp.Enabled     = false;
                    button_scriptDown.Enabled   = false;
                }
            };
            button_scriptDown.Click += (s, e) =>
            {
                var idx  = listBox_scripts.SelectedIndex;
                var item = listBox_scripts.SelectedItem;
                listBox_scripts.Items.RemoveAt(idx);
                listBox_scripts.Items.Insert(idx + 1, item);
            };
            button_scriptDown.Click += (s, e) =>
            {
                var idx  = listBox_scripts.SelectedIndex;
                var item = listBox_scripts.SelectedItem;
                listBox_scripts.Items.RemoveAt(idx);
                listBox_scripts.Items.Insert(idx - 1, item);
            };
            button_scriptRemove.Click += (s, e) =>
            {
                listBox_scripts.Items.RemoveAt(listBox_scripts.SelectedIndex);
            };
            button_scriptImport.Click += (s, e) =>
            {
                var ofd = new OpenFileDialog();
                ofd.Filter = "DLLファイル|*.dll|すべてのファイル|*.*";

                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    var data = File.ReadAllBytes(ofd.FileName);
                    var asm  = Assembly.Load(data);
                    var type = asm.GetExportedTypes().Where(t => t.IsSubclassOf(typeof(GameObjectScript))).ToArray()[0];
                    var inst = asm.CreateInstance(type.FullName) as GameObjectScript;

                    listBox_scripts.Items.Add(new ScriptInfo()
                    {
                        Assembly = data,
                        Script   = inst,
                    });
                }
                catch
                {
                    MessageBox.Show("ファイルの読み込みに失敗しました。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Cursor.Current = Cursors.Default;
            };
        }