public listBoxForm(ParameterSet ps, Actor a, Manipulator m, MainForm ma)
        {
            InitializeComponent();
            int index = 0;

            selectedActor = a;
            parms = ps;
            man = m;
            main = ma;
            if (man != null)
                man.enableRayCast = false;

            if (selectedActor.Name.Contains("Trigger"))
                triggerFlag = true;

            string agents = "";
            if (selectedActor.Parm.HasParm("Agents"))
                agents = selectedActor.Parm.GetString("Agents");

            foreach (KeyValuePair<string, string> s in ps)
            {
                if (index++ != 0)
                {
                    this.listBox.Items.Add(s.Key);
                    foreach (string str in agents.Split(','))
                    {
                        if (str == s.Key)
                            listBox.SelectedIndices.Add(index - 2);
                    }
                }
            }
        }
Beispiel #2
0
        //SB change. This is super hacky and super gross
        public void AddProperties(Actor actor)
        {
            bool agentFlag = false;
            string agents = "";
            //if (!actor.Equals(currentActor) && actor.Parm.GetCount() > 0)

            if (!actor.Equals(currentActor) || propertiesChanged)
            {
                propertiesChanged = false;
                this.currentActor = actor;
                this.PropertiesPanel.Controls.Clear();

                if (currentActor.Parm.HasParm("Agents"))
                    agents = currentActor.Parm.GetString("Agents");
                else
                    agents = "";

                var enumerator = actor.Parm.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ExpandedTextBox textbox = new ExpandedTextBox(actor);
                    Label label = new Label();
                    label.Text = enumerator.Current.Key;
                    if (label.Text == "Agents")
                    {
                        agentFlag = true;
                        textbox.DoubleClick += new EventHandler(this.agentTextBox_DoubleClick);
                    }
                    label.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
                    string[] values = isAgentValue(agents, label.Text);
                    /*if (values != null && agents != "")
                    {
                        ComboBox combo = new ComboBox();
                        combo.Name = label.Text;
                        foreach (string value in values)
                        {
                            if (value == enumerator.Current.Value)
                                combo.SelectedIndex = combo.Items.Add(value);
                            else
                                combo.Items.Add(value);

                        }
                        combo.SelectedIndexChanged += new EventHandler(this.PropertyChangedCombo);

                        PropertiesPanel.Controls.Add(label);
                        PropertiesPanel.Controls.Add(combo);

                    }
                    else
                    {*/
                        textbox.Name = label.Text;
                        textbox.Text = enumerator.Current.Value;
                        textbox.LeaveWithChangedText += new EventHandler(this.PropertyChangedTextBox);

                        PropertiesPanel.Controls.Add(label);
                        PropertiesPanel.Controls.Add(textbox);
                    //}
                }

                //Add agents field if there wasn't one already
                if (!agentFlag)
                {
                    ExpandedTextBox textbox = new ExpandedTextBox(actor);
                    Label label = new Label();
                    label.Text = "Agents";
                    textbox.DoubleClick += new EventHandler(this.agentTextBox_DoubleClick);
                    label.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
                    textbox.Name = label.Text;
                    textbox.TextChanged += new EventHandler(this.PropertyChangedTextBox);
                    PropertiesPanel.Controls.Add(label);
                    PropertiesPanel.Controls.Add(textbox);
                }

                //position
                Vector3 pos = actor.PhysicsObject.Position;

                Label labelPos = new Label();
                labelPos.Text = "Position";
                ExpandedTextBox textBoxPos = new ExpandedTextBox(actor);
                textBoxPos.Name = labelPos.Text;
                textBoxPos.Text = pos.X.ToString() + ' ' + pos.Y.ToString() + ' ' + pos.Z.ToString();
                textBoxPos.TextChanged += new EventHandler(this.PropertyChangedTextBox);
                PropertiesPanel.Controls.Add(labelPos);
                PropertiesPanel.Controls.Add(textBoxPos);
                /*
                labelPos = new Label();
                labelPos.Text = "Position.Y";
                textBoxPos = new ExpandedTextBox(actor);
                textBoxPos.Name = labelPos.Text;
                textBoxPos.Text = pos.Y.ToString();
                textBoxPos.TextChanged += new EventHandler(this.PropertyChangedTextBox);
                PropertiesPanel.Controls.Add(labelPos);
                PropertiesPanel.Controls.Add(textBoxPos);

                labelPos = new Label();
                labelPos.Text = "Position.Z";
                textBoxPos = new ExpandedTextBox(actor);
                textBoxPos.Name = labelPos.Text;
                textBoxPos.Text = pos.Z.ToString();
                textBoxPos.TextChanged += new EventHandler(this.PropertyChangedTextBox);
                PropertiesPanel.Controls.Add(labelPos);
                PropertiesPanel.Controls.Add(textBoxPos);
                */
                //rotation
                Vector3 r;
                Quaternion q = actor.PhysicsObject.Orientation;
                PhysicsHelpers.QuaternionToEuler(ref q, out r);
                Label labelRot = new Label();
                labelRot.Text = "Rotation";
                ExpandedTextBox textBoxRot = new ExpandedTextBox(actor);
                textBoxRot.Name = labelRot.Text;
                textBoxRot.Text = r.X.ToString() + ' ' + r.Y.ToString() + ' ' + r.Z.ToString();
                textBoxRot.TextChanged += new EventHandler(this.PropertyChangedTextBox);
                PropertiesPanel.Controls.Add(labelRot);
                PropertiesPanel.Controls.Add(textBoxRot);

                /*
                labelRot = new Label();
                labelRot.Text = "Rotation.Y";
                textBoxRot = new ExpandedTextBox(actor);
                textBoxRot.Name = labelRot.Text;
                textBoxRot.Text = r.Y.ToString();
                textBoxRot.TextChanged += new EventHandler(this.PropertyChangedTextBox);
                PropertiesPanel.Controls.Add(labelRot);
                PropertiesPanel.Controls.Add(textBoxRot);

                labelRot = new Label();
                labelRot.Text = "Rotation.Z";
                textBoxRot = new ExpandedTextBox(actor);
                textBoxRot.Name = labelRot.Text;
                textBoxRot.Text = r.Z.ToString();
                textBoxRot.TextChanged += new EventHandler(this.PropertyChangedTextBox);
                PropertiesPanel.Controls.Add(labelRot);
                PropertiesPanel.Controls.Add(textBoxRot);
                */
            }
        }
Beispiel #3
0
        private void ReadLevel()
        {
            this.updating = true;

             var d = new OpenFileDialog();
             if (d.ShowDialog() == DialogResult.OK)
             {
            this.ClearLevel();

            var level = new Level();
            level.SetFileName(d.FileName);
            this.lstLevel.Items.Add(level);

            XmlDocument xml = new XmlDocument();
            xml.Load(d.FileName);
            level.Read(xml["level"]);
            foreach (XmlElement el in xml["level"]["actors"])
            {
               Actor actor = new Actor();
               actor.Read(el);
            }
            foreach (XmlElement el in xml["level"]["physics"])
            {
               Physic p;
               if (el.Name == "circle")
                  p = new Circle();
               else if (el.Name == "polygon")
                  p = new Polygon();
               else
               {
                  MessageBox.Show(string.Format("unsupported physic '{0}'. Element skipped.", el.Name));
                  continue;
               }
               p.Read(el);
            }
             }

             this.updating = false;
             this.UpdateControls();
             this.GetCurrent().SelectedItem = this.GetCurrent().Items[0];
        }
 public listBoxForm()
 {
     InitializeComponent();
     selectedActor = null;
 }
        public void Rotate()
        {
            // check if the user is grabbing and arrow and moving it, if so then move that actor!

            if (rotating)
            {
                if (Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.LeftButton == ButtonState.Released)
                {
                    selectedCircle = null;
                    rotating = false;
                    return;
                }

                Vector2 lastMouse = new Vector2(Stage.ActiveStage.GetQB<ControlsQB>().LastMouseState.X, Stage.ActiveStage.GetQB<ControlsQB>().LastMouseState.Y);
                Vector2 currentMouse = new Vector2(Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.X, Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.Y);
                if (lastMouse != currentMouse)
                {
                    Quaternion RotChange = Quaternion.Identity;
                    Vector2 change = currentMouse - lastMouse;
                    change.Y = -change.Y;

                    CameraQB cameraQB = Stage.ActiveStage.GetQB<CameraQB>();
                    switch (selectedCircle.Name)
                    {
                        case "RotatePitch":
                            RotChange = Quaternion.CreateFromAxisAngle(Vector3.Forward, .1f * (-change.Y * (float)Math.Cos(cameraQB.EditorCamera.Yaw) + -change.X * (float)Math.Sin(cameraQB.EditorCamera.Yaw))); ;
                            break;
                        case "RotateYaw":
                            RotChange = Quaternion.CreateFromAxisAngle(Vector3.Up, (.1f * change.X));
                            break;
                        case "RotateRoll":
                            RotChange = Quaternion.CreateFromAxisAngle(Vector3.Right, .1f * (change.Y * (float)Math.Sin(cameraQB.EditorCamera.Yaw) + -change.X * (float)Math.Cos(cameraQB.EditorCamera.Yaw))); ;
                            break;
                    }

                    string key = getParmKey() + "Rotation";

                    selectedActor.PhysicsObject.Orientation *= RotChange;
                    Vector3 r;
                    Quaternion q = selectedActor.PhysicsObject.Orientation;
                    PhysicsHelpers.QuaternionToEuler(ref q, out r);
                    Stage.ActiveStage.Parm.SetParm(key, r);

                }
            }
        }
        protected override bool CanSelect()
        {
            // called when the user clicked in the world and the manipulator wants to respond
            // return whether or not the manipulator should try to select an object
            // in this case if we clicked on an arrow, start moving an return false
            // not on an arrow or not moving, then true
            if (rotating == false)
            {
                if (Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    selectedCircle = Pick(circles);

                    if (selectedCircle != null)
                        rotating = true;
                }
            }

            return rotating == false;
        }
 public void DrawCircle(Actor circle)
 {
     foreach (ModelMesh mesh in circle.modelInstance.model.Model.Meshes)
     {
         foreach (BasicEffect effect in mesh.Effects)
         {
             effect.World = Matrix.CreateScale(distFromActor * rotateModelScalingConst) * circle.PhysicsObject.TransformMatrix;
             effect.View = CameraQB.ViewMatrix;
             effect.Projection = CameraQB.ProjectionMatrix;
             effect.EnableDefaultLighting();
         }
         mesh.Draw();
     }
 }
        public void Move()
        {
            // check if the user is grabbing and arrow and moving it, if so then move that actor!

            if (moving)
            {
                if (Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.LeftButton == ButtonState.Released)
                {
                    selectedArrow = null;
                    moving = false;
                    return;
                }

                Vector2 lastMouse = new Vector2(Stage.ActiveStage.GetQB<ControlsQB>().LastMouseState.X, Stage.ActiveStage.GetQB<ControlsQB>().LastMouseState.Y);
                Vector2 currentMouse = new Vector2(Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.X, Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.Y);
                if (lastMouse != currentMouse)
                {
                    Vector3 positionChange = Vector3.Zero;
                    Vector2 change = currentMouse - lastMouse;
                    change.Y = -change.Y;

                    // direction we move should be based on the camera
                    // not hard coded as below

                    CameraQB cameraQB = Stage.ActiveStage.GetQB<CameraQB>();

                    switch (selectedArrow.Name)
                    {
                        case "ForwardArrow":
                            positionChange += (change.Y * (float)Math.Cos(cameraQB.EditorCamera.Yaw) + change.X * (float)Math.Sin(cameraQB.EditorCamera.Yaw)) * Vector3.Forward;
                            break;
                        case "RightArrow":
                            positionChange += (-change.Y * (float)Math.Sin(cameraQB.EditorCamera.Yaw) + change.X * (float)Math.Cos(cameraQB.EditorCamera.Yaw)) * Vector3.Right;
                            break;
                        case "UpArrow":
                            positionChange += change.Y * Vector3.Up;
                            break;
                    }
                    string key = getParmKey() + "Position";

                    positionChange *= 0.1f;
                    selectedActor.PhysicsObject.Position += positionChange;
                    Stage.ActiveStage.Parm.SetParm(key, selectedActor.PhysicsObject.Position);

                }
            }
        }
        public void DrawArrow(Actor arrow)
        {
            Vector3 drawOffset = Vector3.Zero;

            switch (arrow.Name)
            {
                case "ForwardArrow":
                    drawOffset = Vector3.Forward * (distFromActor * moveModelScalingConst - 1);
                    break;
                case "RightArrow":
                    drawOffset = Vector3.Right * (distFromActor * moveModelScalingConst - 1);
                    break;
                case "UpArrow":
                    drawOffset = Vector3.Up * (distFromActor * moveModelScalingConst - 1);
                    break;
            }

            foreach (ModelMesh mesh in arrow.modelInstance.model.Model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World = Matrix.CreateScale(distFromActor * moveModelScalingConst) * Matrix.CreateTranslation(drawOffset) * arrow.PhysicsObject.TransformMatrix;
                    effect.View = CameraQB.ViewMatrix;
                    effect.Projection = CameraQB.ProjectionMatrix;
                    effect.EnableDefaultLighting();
                }
                mesh.Draw();
            }
        }
        private void Pick()
        {
            Ray mouseRay = PhysicsHelpers.MouseClickToRay(new Vector2(Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.X, Stage.ActiveStage.GetQB<ControlsQB>().CurrentMouseState.Y), CameraQB.ProjectionMatrix, CameraQB.ViewMatrix, viewport);

            RayCastResult result;

            if (enableRayCast)
            {
                if (Stage.ActiveStage.GetQB<PhysicsQB>().Space.RayCast(mouseRay, 1000.0f, out result))
                {
                    selectedActor = result.HitObject.OwningActor as Actor;
                }
                else
                {
                    selectedActor = null;
                }
            }
        }
 public ExpandedTextBox(Actor actor)
 {
     this.actor = actor;
 }