コード例 #1
0
ファイル: Editor.cs プロジェクト: TadCordle/MrGuyXNA
 /// <summary>
 /// Proceeds to the next step of creating a trigger
 /// </summary>
 private void CreateTrigger()
 {
     if (step == 1)
     {
         step++;
         currentBox[0] = camera.CameraToGlobalPos(Mouse.GetState().X, Mouse.GetState().Y);
     }
     else if (step == 2)
     {
         step = 3;
         currentBox[1] = camera.CameraToGlobalPos(Mouse.GetState().X, Mouse.GetState().Y);
         windowOpen = true;
         TriggerEditor editor = new TriggerEditor();
         editor.Location = controls.Location;
         System.Windows.Forms.DialogResult result = editor.ShowDialog();
         TriggerInformation info = new TriggerInformation((int)currentBox[0].X, (int)currentBox[0].Y, (int)currentBox[1].X, (int)currentBox[1].Y, editor.Name, editor.ObjectIDs, editor.WhenTrigger);
         triggerInfo.Add(info);
         windowOpen = false;
         controls.CreatingTrigger = false;
         step = 1;
     }
 }
コード例 #2
0
ファイル: Editor.cs プロジェクト: TadCordle/MrGuyXNA
        /// <summary>
        /// Exports the level into an XML file
        /// </summary>
        private void SaveLevel()
        {
            LevelData level = new LevelData();
            level.size = new Vector2(levelSize.Width, levelSize.Height);
            level.R = controls.R;
            level.G = controls.G;
            level.B = controls.B;

            level.tiles = new List<TileInformation>();
            foreach (TileInformation t in tileInfo)
                TileInformation.AddTile(level.tiles, t.texture, new Vector2(t.X - levelSize.X, t.Y - levelSize.Y), t.Scale, t.Rotation, t.Layer, t.Effect);
            level.staticBodies = new List<StaticBodyInformation>();
            foreach (StaticBodyInformation sb in sbInfo)
            {
                StaticBodyInformation body = new StaticBodyInformation();
                foreach (Vector2 p in sb.Points)
                    body.AddPoint(new Vector2(p.X - levelSize.X, p.Y - levelSize.Y));
                level.staticBodies.Add(body);
            }
            level.objects = new List<ObjectInformation>();
            foreach (ObjectInformation obj in objInfo)
            {
                ObjectInformation moved = new ObjectInformation();
                moved.Index = obj.Index;
                moved.ParameterNames = obj.ParameterNames;
                moved.ParameterValues = obj.ParameterValues;
                moved.Position = obj.Position - new Vector2(levelSize.X, levelSize.Y);
                moved.Texture = obj.Texture;
                moved.Type = obj.Type;
                moved.Scripts = obj.Scripts;
                level.objects.Add(moved);
            }
            level.cameras = new List<CameraBoxInformation>();
            foreach (CameraBoxInformation cam in camInfo)
            {
                CameraBoxInformation moved = new CameraBoxInformation(
                    cam.Bounds.Left - (int)levelSize.X,
                    cam.Bounds.Top - (int)levelSize.Y,
                    cam.Bounds.Right - (int)levelSize.X,
                    cam.Bounds.Bottom - (int)levelSize.Y,
                    cam.Target, cam.Priority);
                level.cameras.Add(moved);
            }
            level.triggers = new List<TriggerInformation>();
            foreach (TriggerInformation trigger in triggerInfo)
            {
                TriggerInformation moved = new TriggerInformation(
                    trigger.Bounds.Left - (int)levelSize.X,
                    trigger.Bounds.Top - (int)levelSize.Y,
                    trigger.Bounds.Right - (int)levelSize.X,
                    trigger.Bounds.Bottom - (int)levelSize.Y,
                    trigger.Name, trigger.ObjID, trigger.WhenTrigger);
                level.triggers.Add(moved);
            }

            controls.Save(level);

            controls.SavePressed = false;
        }
コード例 #3
0
ファイル: Editor.cs プロジェクト: TadCordle/MrGuyXNA
        /// <summary>
        /// Updates mouse-dependent actions
        /// </summary>
        private void UpdateMouseStuff()
        {
            if (windowOpen)
                return;

            #region Mouse left

            if (Mouse.GetState().LeftButton == ButtonState.Pressed && MouseInBounds())
            {
                if (!mleftPressed)
                {
                    if (Keyboard.GetState().IsKeyUp(Keys.LeftShift)) // Make sure not changing bounds
                    {
                        if (!changingBounds)
                        {
                            if (controls.Tab == 0)
                            {
                                if (controls.CreatingMap)
                                    CreateMap();
                                else if (controls.CreatingCam)
                                    CreateCam();
                                else if (controls.CreatingTrigger)
                                    CreateTrigger();
                            }
                            else if (controls.Tab == 1 && selectedTexture != null)
                                CreateTile();
                            else if (controls.Tab == 2 && (selectedTexture != null || movedObject != null))
                                CreateObject();
                        }
                        else
                            FinishChangingBounds();
                    }
                    else
                    {
                        if (!changingBounds)
                            StartChangingBounds();
                        else
                            FinishChangingBounds();
                    }
                }
                mleftPressed = true;
            }
            else
                mleftPressed = false;

            #endregion

            #region Mouse right

            if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                    RemoveThings();
                else if (controls.Tab == 2 && !windowOpen && !mRightPressed && currentObject == null)
                {
                    bool foundObj = false;
                    mRightPressed = true;
                    foreach (ObjectInformation obj in objInfo)
                    {
                        Rectangle boundingBox = new Rectangle((int)camera.GlobalToCameraPos((int)(obj.Position.X - ObjectTextures[obj.Texture].Width * camera.TotalScale / 2), (int)(obj.Position.Y - ObjectTextures[obj.Texture].Height * camera.TotalScale / 2)).X,
                                                              (int)camera.GlobalToCameraPos((int)(obj.Position.X - ObjectTextures[obj.Texture].Width * camera.TotalScale / 2), (int)(obj.Position.Y - ObjectTextures[obj.Texture].Height * camera.TotalScale / 2)).Y,
                                                              (int)(ObjectTextures[obj.Texture].Width * camera.TotalScale),
                                                              (int)(ObjectTextures[obj.Texture].Width * camera.TotalScale));
                        if (boundingBox.Contains(Mouse.GetState().X, Mouse.GetState().Y))
                        {
                            MouseState state = Mouse.GetState();
                            rcMenu = new RightClickMenu(obj, state.X, state.Y, objMenuChoices);
                            foundObj = true;
                            break;
                        }
                    }
                    if (!foundObj)
                        rcMenu = null;
                }
                else if (controls.Tab == 0 && !windowOpen && !mRightPressed)
                {
                    mRightPressed = true;
                    TriggerInformation selected = null;
                    TriggerEditor editor = null;

                    foreach (TriggerInformation trigger in triggerInfo)
                    {
                        Vector2 camToGlob = camera.CameraToGlobalPos(Mouse.GetState().X, Mouse.GetState().Y);
                        Vector2 topleft = new Vector2(trigger.Bounds.Left, trigger.Bounds.Top);
                        Vector2 topright = new Vector2(trigger.Bounds.Right, trigger.Bounds.Top);
                        Vector2 bottomleft = new Vector2(trigger.Bounds.Left, trigger.Bounds.Bottom);
                        Vector2 bottomright = new Vector2(trigger.Bounds.Right, trigger.Bounds.Bottom);
                        if ((camToGlob - topleft).Length() <= 5 || (camToGlob - topright).Length() <= 5 || (camToGlob - bottomleft).Length() <= 5 || (camToGlob - bottomright).Length() <= 5)
                        {
                            selected = trigger;
                            controls.CreatingTrigger = true;
                            windowOpen = true;
                            editor = new TriggerEditor();
                            editor.Location = controls.Location;
                            ((System.Windows.Forms.TextBox)editor.Controls["txtName"]).Text = trigger.Name;
                            ((System.Windows.Forms.TextBox)editor.Controls["txtObjects"]).Text = trigger.ObjID[0].ToString();
                            for (int i = 1; i < trigger.ObjID.Length; i++)
                                ((System.Windows.Forms.TextBox)editor.Controls["txtObjects"]).Text += "," + trigger.ObjID[i].ToString();
                            if (trigger.WhenTrigger == 0)
                                ((System.Windows.Forms.RadioButton)((System.Windows.Forms.GroupBox)editor.Controls["groupBox1"]).Controls["radContinuous"]).Checked = true;
                            else if (trigger.WhenTrigger == 1)
                                ((System.Windows.Forms.RadioButton)((System.Windows.Forms.GroupBox)editor.Controls["groupBox1"]).Controls["radEnter"]).Checked = true;
                            else
                                ((System.Windows.Forms.RadioButton)((System.Windows.Forms.GroupBox)editor.Controls["groupBox1"]).Controls["radLeave"]).Checked = true;
                            System.Windows.Forms.DialogResult result = editor.ShowDialog();
                            TriggerInformation info = new TriggerInformation((int)currentBox[0].X, (int)currentBox[0].Y, (int)currentBox[1].X, (int)currentBox[1].Y, editor.Name, editor.ObjectIDs, editor.WhenTrigger);
                            triggerInfo.Add(info);
                            windowOpen = false;
                            controls.CreatingTrigger = false;
                            break;
                        }
                    }

                    if (selected != null)
                    {
                        selected.Name = editor.Name;
                        selected.ObjID = editor.ObjectIDs;
                        selected.WhenTrigger = editor.WhenTrigger;
                    }
                }
            }
            else
                mRightPressed = false;
            #endregion

            #region Rotating

            // Rotate selection counterclockwise
            if (Keyboard.GetState().IsKeyUp(Keys.LeftShift))
            {
                if (Keyboard.GetState().IsKeyDown(Keys.A))
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                    {
                        if (!rotOnceLeft)
                        {
                            selTexRotation = SnapAngle(true);
                            rotOnceLeft = true;
                        }
                    }
                    else
                        selTexRotation -= 0.05f;
                }
                // Rotate selection clockwise
                else if (Keyboard.GetState().IsKeyDown(Keys.D))
                {
                    rotOnceLeft = false;
                    if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                    {
                        if (!rotOnceRight)
                        {
                            selTexRotation = SnapAngle(false);
                            rotOnceRight = true;
                        }
                    }
                    else
                        selTexRotation += 0.05f;
                }
                else
                {
                    rotOnceLeft = false;
                    rotOnceRight = false;
                }
                while (selTexRotation < 0)
                    selTexRotation += MathHelper.TwoPi;
                while (selTexRotation >= MathHelper.TwoPi)
                    selTexRotation -= MathHelper.TwoPi;
            }

            #endregion

            #region Scaling

            // Scale selection
            if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
            {
                if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                {
                    selTexScale.X = selTexScale.Y = 1f;
                    selTexRotation = 0f;
                    selTexEffect = SpriteEffects.None;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.D))
                    selTexScale.X += 0.1f;
                else if (Keyboard.GetState().IsKeyDown(Keys.A) && selTexScale.Length() > 0.05f)
                    selTexScale.X -= 0.1f;
                if (Keyboard.GetState().IsKeyDown(Keys.W))
                    selTexScale.Y += 0.1f;
                else if (Keyboard.GetState().IsKeyDown(Keys.S) && selTexScale.Length() > 0.05f)
                    selTexScale.Y -= 0.1f;
            }
            else
            {
                if (Keyboard.GetState().IsKeyDown(Keys.W))
                    selTexScale *= 1.03f;
                else if (Keyboard.GetState().IsKeyDown(Keys.S) && selTexScale.Length() > 0.05f)
                    selTexScale /= 1.03f;
            }

            #endregion

            #region Flipping

            // Flip selection
            if (Keyboard.GetState().IsKeyDown(Keys.X))
            {
                if (!xPressed)
                {
                    xPressed = true;
                    selTexEffect = (selTexEffect == SpriteEffects.None ? SpriteEffects.FlipHorizontally : SpriteEffects.None);
                }
            }
            else
                xPressed = false;

            #endregion

            #region Layer

            // Change selected layer
            Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();
            if (pressedKeys.Count() > 0)
                if (pressedKeys[0] >= Keys.D0 && pressedKeys[0] <= Keys.D9)
                    layer = float.Parse(Enum.GetName(typeof(Keys), pressedKeys[0]).Substring(1)) / 9.0f;

            #endregion

            #region Camera controls

            // Zoom
            DScroll = Mouse.GetState().ScrollWheelValue - prevScrollTotal;
            if (DScroll != 0 && Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                camera.Zoom(0.05f * Math.Sign(DScroll) + 1);
            prevScrollTotal = Mouse.GetState().ScrollWheelValue;

            // Pan
            if (Mouse.GetState().MiddleButton == ButtonState.Pressed)
                camera.Pan(Mouse.GetState().X - prevMX, Mouse.GetState().Y - prevMY);
            prevMX = Mouse.GetState().X;
            prevMY = Mouse.GetState().Y;

            #endregion
        }