Esempio n. 1
0
        internal void Add(Sprite sprite)
        {
            if (sprite.mOrdered)
            {
#if DEBUG
                if (mSprites.Contains(sprite))
                {
                    throw new InvalidOperationException("Can't add the Sprite to this layer because it's already added");
                }
#endif
                mSprites.Add(sprite);
            }
            else
            {
#if DEBUG
                if (mZBufferedSprites.Contains(sprite))
                {
                    throw new InvalidOperationException("Can't add the Sprite to this layer because it's already added");
                }
#endif
                mZBufferedSprites.Add(sprite);
            }
        }
        private void saveButtonClick(Window callingWindow)
        {
            // If a user thinks he's funny and selects AllNotJoint for BodySprites
            // and AllNotBodySprites for Joints, let the user know he has to
            // specify some criteria.
            if (this.bodySpriteSelectionMethod.Text == "All Not Joint" &&
                this.jointSpriteSelectionMethod.Text == "All Not Body")
            {
                GuiManager.ShowMessageBox(
                    "Cannot select All Not Body for Joint Selection when " +
                    "All Not Joint is selected for Body Sprite Selection.  " +
                    "Change one of the criteria and try to save again.", "Selection Error");
                return;

            }



            double error = 0;
            SpriteList possibleSprites = new SpriteList();

            if (this.sceneOrGroup.Text == "Entire Scene")
            {
                possibleSprites = GameData.Scene.Sprites;
            }
            else if (GameData.EditorLogic.CurrentSprites.Count != 0)
            {
                ((Sprite)GameData.EditorLogic.CurrentSprites[0].TopParent).GetAllDescendantsOneWay(possibleSprites);
            }

            #region Get rid of the Axes from the possibleSprites

            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.xAxis))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.xAxis);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.yAxis))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.yAxis);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.zAxis))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.zAxis);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.xRot))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.xRot);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.yRot))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.yRot);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.xScale))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.xScale);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.yScale))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.yScale);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.origin))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.origin);
            }
            #endregion

            if (this.bodySpriteSelectionMethod.Text == "Name Includes")
            {
                this.bodySprites = possibleSprites.FindSpritesWithNameContaining(this.bodyNameToInclude.Text);
            }
            else if (this.bodySpriteSelectionMethod.Text == "By Texture")
            {
                this.bodySprites = possibleSprites.FindSpritesWithTexture(
                    FlatRedBallServices.Load<Texture2D>(this.bodyAvailableTextures.Text, GameData.SceneContentManager));
            }
            else if (this.bodySpriteSelectionMethod.Text == "All")
            {
                this.bodySprites = possibleSprites;
            }

            if (this.jointSpriteSelectionMethod.Text == "Name Includes")
            {
                this.joints = possibleSprites.FindSpritesWithNameContaining(this.jointNameToInclude.Text);
            }
            else if (this.jointSpriteSelectionMethod.Text == "By Texture")
            {
                this.joints = possibleSprites.FindSpritesWithTexture(
                    FlatRedBallServices.Load<Texture2D>(this.jointAvailableTextures.Text, GameData.SceneContentManager));
            }
            else if (this.jointSpriteSelectionMethod.Text == "All")
            {
                this.joints = possibleSprites;
            }

            try
            {
                if (bodySpriteSelectionMethod == null) System.Windows.Forms.MessageBox.Show("a");

                if (this.bodySpriteSelectionMethod.Text == "All Not Joint")
                {
                    this.bodySprites = new SpriteList();

                    if (possibleSprites == null) System.Windows.Forms.MessageBox.Show("b");


                    foreach (Sprite s in possibleSprites)
                    {
                        if (this == null) System.Windows.Forms.MessageBox.Show("c");
                        if (this.joints == null) System.Windows.Forms.MessageBox.Show("d");
                        if (this.bodySprites == null) System.Windows.Forms.MessageBox.Show("e");



                        if (!this.joints.Contains(s))
                        {
                            this.bodySprites.Add(s);
                        }
                    }
                }
            }
            catch { error = 3.3; }
                if (this.jointSpriteSelectionMethod.Text == "All Not Body")
                {
                    this.joints = new SpriteList();
                    foreach (Sprite s in possibleSprites)
                    {
                        if (!this.bodySprites.Contains(s))
                        {
                            this.joints.Add(s);
                        }
                    }
                }

                if (this.rootSpriteComboBox.Text != "<No Root>")
                {
                    this.root = possibleSprites.FindByName(this.rootSpriteComboBox.Text);
                }
                else
                {
                    this.root = null;
                }




            FileButtonWindow.spriteRigOptionsOK(this);
            this.Visible = false;

        }
        private void saveButtonClick(Window callingWindow)
        {
            // If a user thinks he's funny and selects AllNotJoint for BodySprites
            // and AllNotBodySprites for Joints, let the user know he has to
            // specify some criteria.
            if (this.bodySpriteSelectionMethod.Text == "All Not Joint" &&
                this.jointSpriteSelectionMethod.Text == "All Not Body")
            {
                GuiManager.ShowMessageBox(
                    "Cannot select All Not Body for Joint Selection when " +
                    "All Not Joint is selected for Body Sprite Selection.  " +
                    "Change one of the criteria and try to save again.", "Selection Error");
                return;
            }



            double     error           = 0;
            SpriteList possibleSprites = new SpriteList();

            if (this.sceneOrGroup.Text == "Entire Scene")
            {
                possibleSprites = GameData.Scene.Sprites;
            }
            else if (GameData.EditorLogic.CurrentSprites.Count != 0)
            {
                ((Sprite)GameData.EditorLogic.CurrentSprites[0].TopParent).GetAllDescendantsOneWay(possibleSprites);
            }

            #region Get rid of the Axes from the possibleSprites

            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.xAxis))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.xAxis);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.yAxis))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.yAxis);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.zAxis))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.zAxis);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.xRot))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.xRot);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.yRot))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.yRot);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.xScale))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.xScale);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.yScale))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.yScale);
            }
            if (possibleSprites.Contains(GameData.EditorLogic.EditAxes.origin))
            {
                possibleSprites.Remove(GameData.EditorLogic.EditAxes.origin);
            }
            #endregion

            if (this.bodySpriteSelectionMethod.Text == "Name Includes")
            {
                this.bodySprites = possibleSprites.FindSpritesWithNameContaining(this.bodyNameToInclude.Text);
            }
            else if (this.bodySpriteSelectionMethod.Text == "By Texture")
            {
                this.bodySprites = possibleSprites.FindSpritesWithTexture(
                    FlatRedBallServices.Load <Texture2D>(this.bodyAvailableTextures.Text, GameData.SceneContentManager));
            }
            else if (this.bodySpriteSelectionMethod.Text == "All")
            {
                this.bodySprites = possibleSprites;
            }

            if (this.jointSpriteSelectionMethod.Text == "Name Includes")
            {
                this.joints = possibleSprites.FindSpritesWithNameContaining(this.jointNameToInclude.Text);
            }
            else if (this.jointSpriteSelectionMethod.Text == "By Texture")
            {
                this.joints = possibleSprites.FindSpritesWithTexture(
                    FlatRedBallServices.Load <Texture2D>(this.jointAvailableTextures.Text, GameData.SceneContentManager));
            }
            else if (this.jointSpriteSelectionMethod.Text == "All")
            {
                this.joints = possibleSprites;
            }

            try
            {
                if (bodySpriteSelectionMethod == null)
                {
                    System.Windows.Forms.MessageBox.Show("a");
                }

                if (this.bodySpriteSelectionMethod.Text == "All Not Joint")
                {
                    this.bodySprites = new SpriteList();

                    if (possibleSprites == null)
                    {
                        System.Windows.Forms.MessageBox.Show("b");
                    }


                    foreach (Sprite s in possibleSprites)
                    {
                        if (this == null)
                        {
                            System.Windows.Forms.MessageBox.Show("c");
                        }
                        if (this.joints == null)
                        {
                            System.Windows.Forms.MessageBox.Show("d");
                        }
                        if (this.bodySprites == null)
                        {
                            System.Windows.Forms.MessageBox.Show("e");
                        }



                        if (!this.joints.Contains(s))
                        {
                            this.bodySprites.Add(s);
                        }
                    }
                }
            }
            catch { error = 3.3; }
            if (this.jointSpriteSelectionMethod.Text == "All Not Body")
            {
                this.joints = new SpriteList();
                foreach (Sprite s in possibleSprites)
                {
                    if (!this.bodySprites.Contains(s))
                    {
                        this.joints.Add(s);
                    }
                }
            }

            if (this.rootSpriteComboBox.Text != "<No Root>")
            {
                this.root = possibleSprites.FindByName(this.rootSpriteComboBox.Text);
            }
            else
            {
                this.root = null;
            }



            FileButtonWindow.spriteRigOptionsOK(this);
            this.Visible = false;
        }
        private void ControlAfterSnappingPosition()
        {
            #region initialize variables to be used for this method
            Sprite spriteGrabbed = GameData.Cursor.SpritesGrabbed[0];
            float  originalX     = spriteGrabbed.X;
            float  originalY     = spriteGrabbed.Y;

            // Modify this later to support rotation
            float scaleXAfterRotation = spriteGrabbed.X;
            float scaleYAfterRotation = spriteGrabbed.Y;

            bool snappingFound = false;

            #endregion

            if (spriteGrabbed != null)
            {
                // Get all the Sprites that are children or parents
                // of the current
                SpriteList spritesToIgnore = new SpriteList();
                spriteGrabbed.GetAllDescendantsOneWay(spritesToIgnore);
                spriteGrabbed.GetAllAncestorsOneWay(spritesToIgnore);

                float otherSpriteScaleX;
                float otherSpriteScaleY;

                mAfterSnappingPosition.X = spriteGrabbed.X;
                mAfterSnappingPosition.Y = spriteGrabbed.Y;
                mAfterSnappingPosition.Z = spriteGrabbed.Z;

                #region Loop through all of the other Sprites excluding this one to see if this one should snap anywhere
                foreach (Sprite otherSprite in GameData.Scene.Sprites)
                {
                    if (otherSprite != spriteGrabbed && spritesToIgnore.Contains(otherSprite) == false)
                    {
                        otherSpriteScaleX = otherSprite.ScaleX;
                        otherSpriteScaleY = otherSprite.ScaleY;


                        #region Check for X snapping

                        if (AreSpritesCloseOnY(spriteGrabbed, otherSprite))
                        {
                            float value = otherSprite.X - otherSprite.ScaleX - spriteGrabbed.ScaleX;

                            if (Math.Abs(value - spriteGrabbed.X) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.X = value;
                                snappingFound            = true;
                            }

                            value = otherSprite.X - otherSprite.ScaleX + spriteGrabbed.ScaleX;

                            if (Math.Abs(value - spriteGrabbed.X) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.X = value;
                                snappingFound            = true;
                            }

                            value = otherSprite.X + otherSprite.ScaleX - spriteGrabbed.ScaleX;

                            if (Math.Abs(value - spriteGrabbed.X) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.X = value;
                                snappingFound            = true;
                            }

                            value = otherSprite.X + otherSprite.ScaleX + spriteGrabbed.ScaleX;

                            if (Math.Abs(value - spriteGrabbed.X) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.X = value;
                                snappingFound            = true;
                            }
                        }

                        #endregion

                        #region Check for Y Snapping

                        if (AreSpritesCloseOnX(spriteGrabbed, otherSprite))
                        {
                            float value = otherSprite.Y - otherSprite.ScaleY - spriteGrabbed.ScaleY;

                            if (Math.Abs(value - spriteGrabbed.Y) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.Y = value;
                                snappingFound            = true;
                            }

                            value = otherSprite.Y - otherSprite.ScaleY + spriteGrabbed.ScaleY;

                            if (Math.Abs(value - spriteGrabbed.Y) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.Y = value;
                                snappingFound            = true;
                            }

                            value = otherSprite.Y + otherSprite.ScaleY - spriteGrabbed.ScaleY;

                            if (Math.Abs(value - spriteGrabbed.Y) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.Y = value;
                                snappingFound            = true;
                            }

                            value = otherSprite.Y + otherSprite.ScaleY + spriteGrabbed.ScaleY;

                            if (Math.Abs(value - spriteGrabbed.Y) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.Y = value;
                                snappingFound            = true;
                            }
                        }

                        #endregion
                    }
                }
                #endregion
            }

            if (snappingFound)
            {
                UpdateSnappingDisplayToCurrentSprite();
            }
            mAfterSnappingPosition.Visible = snappingFound;
        }
Esempio n. 5
0
        public static void DeleteCurrentSprites()
        {
            SpriteList spritesToRemove = new SpriteList();

            /*
             * May need to delete more Sprites if the selected Sprite is part of a group.  But this all depends on whether
             * we are in group or hierarchy control mode.
             */

            // need to detach the axes, cursorOverBox, targetBox
            ClearAttachedMarkers();

            #region find out which Sprites are being removed depending on alt and group/hierarchy edit mode
            if (GuiData.ToolsWindow.groupHierarchyControlButton.IsPressed) // hierarchy control
            {
                foreach (Sprite s in mEditorLogic.CurrentSprites)
                {
                    if (spritesToRemove.Contains(s) == false)
                    {
                        spritesToRemove.AddOneWay(s);
                    }

                    SpriteList tempSpriteArray = new SpriteList();

                    s.GetAllDescendantsOneWay(tempSpriteArray);

                    foreach (Sprite childSprite in tempSpriteArray)
                    {
                        if (spritesToRemove.Contains(childSprite) == false)
                        {
                            spritesToRemove.AddOneWay(childSprite);
                        }
                    }
                }
            }
            else
            {
                PositionedObjectList <Sprite> parentSprites = mEditorLogic.CurrentSprites.GetTopParents();

                foreach (Sprite s in parentSprites)
                {
                    if (spritesToRemove.Contains(s) == false)
                    {
                        spritesToRemove.AddOneWay(s);
                    }

                    SpriteList tempSpriteArray = new SpriteList();

                    s.GetAllDescendantsOneWay(tempSpriteArray);

                    foreach (Sprite childSprite in tempSpriteArray)
                    {
                        if (spritesToRemove.Contains(childSprite) == false)
                        {
                            spritesToRemove.AddOneWay(childSprite);
                        }
                    }
                }
            }
            #endregion

            DeleteSprites(spritesToRemove, InputManager.Keyboard.KeyDown(Key.LeftAlt) || InputManager.Keyboard.KeyDown(Key.Right));
        }
Esempio n. 6
0
        private void ControlAfterSnappingPosition()
        {
            

            #region initialize variables to be used for this method
            Sprite spriteGrabbed = GameData.Cursor.SpritesGrabbed[0];
            float originalX = spriteGrabbed.X;
            float originalY = spriteGrabbed.Y;

            // Modify this later to support rotation
            float scaleXAfterRotation = spriteGrabbed.X ;
            float scaleYAfterRotation = spriteGrabbed.Y ;

            bool snappingFound = false;

            #endregion

            if (spriteGrabbed != null)
            {
                // Get all the Sprites that are children or parents 
                // of the current
                SpriteList spritesToIgnore = new SpriteList();
                spriteGrabbed.GetAllDescendantsOneWay(spritesToIgnore);
                spriteGrabbed.GetAllAncestorsOneWay(spritesToIgnore);

                float otherSpriteScaleX;
                float otherSpriteScaleY;

                mAfterSnappingPosition.X = spriteGrabbed.X;
                mAfterSnappingPosition.Y = spriteGrabbed.Y;
                mAfterSnappingPosition.Z = spriteGrabbed.Z;

                #region Loop through all of the other Sprites excluding this one to see if this one should snap anywhere
                foreach (Sprite otherSprite in GameData.Scene.Sprites)
                {
                    if (otherSprite != spriteGrabbed && spritesToIgnore.Contains(otherSprite) == false)
                    {
                        otherSpriteScaleX = otherSprite.ScaleX;
                        otherSpriteScaleY = otherSprite.ScaleY;


                        #region Check for X snapping

                        if (AreSpritesCloseOnY(spriteGrabbed, otherSprite))
                        {
                            float value = otherSprite.X - otherSprite.ScaleX - spriteGrabbed.ScaleX;

                            if (Math.Abs(value - spriteGrabbed.X) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.X = value;
                                snappingFound = true;
                            }

                            value = otherSprite.X - otherSprite.ScaleX + spriteGrabbed.ScaleX;

                            if (Math.Abs(value - spriteGrabbed.X) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.X = value;
                                snappingFound = true;
                            }

                            value = otherSprite.X + otherSprite.ScaleX - spriteGrabbed.ScaleX;

                            if (Math.Abs(value - spriteGrabbed.X) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.X = value;
                                snappingFound = true;
                            }

                            value = otherSprite.X + otherSprite.ScaleX + spriteGrabbed.ScaleX;

                            if (Math.Abs(value - spriteGrabbed.X) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.X = value;
                                snappingFound = true;
                            }
                        }

                        #endregion

                        #region Check for Y Snapping

                        if (AreSpritesCloseOnX(spriteGrabbed, otherSprite))
                        {
                            float value = otherSprite.Y - otherSprite.ScaleY - spriteGrabbed.ScaleY;

                            if (Math.Abs(value - spriteGrabbed.Y) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.Y = value;
                                snappingFound = true;
                            }

                            value = otherSprite.Y - otherSprite.ScaleY + spriteGrabbed.ScaleY;

                            if (Math.Abs(value - spriteGrabbed.Y) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.Y = value;
                                snappingFound = true;
                            }

                            value = otherSprite.Y + otherSprite.ScaleY - spriteGrabbed.ScaleY;

                            if (Math.Abs(value - spriteGrabbed.Y) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.Y = value;
                                snappingFound = true;
                            }

                            value = otherSprite.Y + otherSprite.ScaleY + spriteGrabbed.ScaleY;

                            if (Math.Abs(value - spriteGrabbed.Y) < DistanceBasedBuffer)
                            {
                                mAfterSnappingPosition.Y = value;
                                snappingFound = true;
                            }
                        }

                        #endregion
                    }
                }
                #endregion
            }

            if (snappingFound)
            {
                UpdateSnappingDisplayToCurrentSprite();
            }
            mAfterSnappingPosition.Visible = snappingFound;

        }
Esempio n. 7
0
        public void ClickGrid(SpriteGrid gridClicked, Sprite spriteClicked)
        {
            #region if eyedropper is pressed, don't select the grid, just grab the texture
            if (GuiData.ToolsWindow.eyedropper.IsPressed)
            {
                GameData.Cursor.ClickSprite(spriteClicked);
            }
            #endregion

            #region Select the grid - eyedropper is not down
            else
            {
                newlySelectedCurrentSprite     = null;
                newlySelectedCurrentSpriteGrid = null;

                #region if selecting a new grid, not painting, and changes have been made
                if ((gridClicked != CurrentSpriteGrid || currentSprites.Contains(spriteClicked) == false || spriteClicked == null) &&
                    GuiData.ToolsWindow.paintButton.IsPressed == false &&
                    ShouldAskUserIfChangesShouldBeApplied(gridClicked, spriteClicked))
                {
                    // The user may have changed the texture coordinates on the
                    // selected Sprite.  This should result in the new texture coordinates
                    // being "painted" on the SpriteGrid at the given location.
                    PaintTextureCoordinatesOnCurrentSpriteInGrid();
                    newlySelectedCurrentSprite     = spriteClicked;
                    newlySelectedCurrentSpriteGrid = gridClicked;
                    AskIfChangesShouldBeApplied(null);
                }
                #endregion

                #region else, do not need to ask if changes should be applied
                else
                {
                    if (GuiData.ToolsWindow.paintButton.IsPressed == false &&
                        GameData.EditorLogic.CurrentSprites.Contains(spriteClicked) == false)
                    {
                        if (spriteClicked != null)
                        {
                            oldPosition = spriteClicked.Position;
                        }
                        else
                        {
                            oldPosition = Vector3.Empty;
                        }

                        PaintTextureCoordinatesOnCurrentSpriteInGrid();
                    }

                    if (CurrentSpriteGrid != gridClicked)
                    {
                        GameData.DeselectCurrentSprites();
                    }

                    CurrentSpriteGrid = gridClicked;

                    // attach the grid border
                    mSpriteGridBorder.AttachTo(CurrentSpriteGrid);

                    GameData.Cursor.ClickSprite(spriteClicked);

                    SpriteGridGrabbed = gridClicked;
                    mSpriteGrabbed    = spriteClicked;

                    if (gridClicked != null)
                    {
                        UndoManager.AddToWatch <Sprite>(gridClicked.Blueprint);


                        UndoManager.AddToWatch <SpriteGrid>(gridClicked);
                    }
                    GuiData.ListWindow.SpriteGridListBox.HighlightObject(gridClicked, false);
                }
                #endregion

                cursor.ObjectGrabbed = spriteClicked;

                if (gridClicked == null)
                {
                    return;
                }

                #region Change the convert to sprite grid button to "Modify Sprite Grid"
                GuiData.ToolsWindow.convertToSpriteGridButton.Enabled = true;
                GuiData.ToolsWindow.convertToSpriteGridButton.Text    = "Modify Sprite Grid";
                #endregion
            }
            #endregion
        }