Example #1
0
        public void SaveSceneClick(string fileName)
        {
            if (!string.IsNullOrEmpty(fileName))
            {
                mLastFileName = fileName;
            }
            List <string> stringArray = new List <string>();

            namesToChange = new SpriteList();
            foreach (Sprite s in GameData.Scene.Sprites)
            {
                if (stringArray.Contains(s.Name))
                {
                    namesToChange.AddOneWay(s);
                }
                else
                {
                    stringArray.Add(s.Name);
                }
            }

            if (AskQuestionsAndDelaySaveIfNecessary(SaveSceneClick))
            {
                if (namesToChange.Count != 0)
                {
                    MultiButtonMessageBox mbmb = GuiManager.AddMultiButtonMessageBox();
                    mbmb.Name = "Duplicate Sprite names found";
                    mbmb.Text = "Duplicate names found in scene.  Duplicate names can alter attachment information.  What would you like to do?";
                    mbmb.AddButton("Leave names as they are and save.", new GuiMessage(OpenFileWindowSaveScene));
                    mbmb.AddButton("Automatically change Sprite names and save.", new GuiMessage(ChangeNamesAndSave));
                    mbmb.AddButton("Cancel save.", null);
                }
                else
                {
                    if (string.IsNullOrEmpty(fileName))
                    {
                        OpenFileWindowSaveScene(null);
                    }
                    else
                    {
                        SaveSceneFileWindowOk(null);
                    }
                }



                ShowWarningsAndMessagesBeforeSaving();
            }
        }
Example #2
0
        public void SaveSceneClick(string fileName)
        {


            if (!string.IsNullOrEmpty(fileName))
            {
                mLastFileName = fileName;
            }
            List<string> stringArray = new List<string>();
            namesToChange = new SpriteList();
            foreach (Sprite s in GameData.Scene.Sprites)
            {
                if (stringArray.Contains(s.Name))
                {
                    namesToChange.AddOneWay(s);
                }
                else
                {
                    stringArray.Add(s.Name);
                }
            }

            if (AskQuestionsAndDelaySaveIfNecessary(SaveSceneClick))
            {

                if (namesToChange.Count != 0)
                {
                    MultiButtonMessageBox mbmb = GuiManager.AddMultiButtonMessageBox();
                    mbmb.Name = "Duplicate Sprite names found";
                    mbmb.Text = "Duplicate names found in scene.  Duplicate names can alter attachment information.  What would you like to do?";
                    mbmb.AddButton("Leave names as they are and save.", new GuiMessage(OpenFileWindowSaveScene));
                    mbmb.AddButton("Automatically change Sprite names and save.", new GuiMessage(ChangeNamesAndSave));
                    mbmb.AddButton("Cancel save.", null);
                }
                else
                {
                    if (string.IsNullOrEmpty(fileName))
                    {
                        OpenFileWindowSaveScene(null);
                    }
                    else
                    {
                        SaveSceneFileWindowOk(null);
                    }

                }



                ShowWarningsAndMessagesBeforeSaving();
            }
        }
Example #3
0
        public static void LoadSpriteRigOk(Window callingWindow)
        {
            #region Load the SpriteRig

            EditorSprite es;
            string fileName = ((FileWindow)callingWindow).Results[0];

            SpriteRigSave srs = SpriteRigSave.FromFile(fileName);
            SpriteList loadedSprites = new SpriteList();

            SpriteRig spriteRig = srs.ToSpriteRig(GameData.SceneContentManager);

            #endregion

            #region Play some Pose so that the SpriteRig has a proper pose and texture coordinates

            // Play and stop an animation to get the texture coordinates set up in case
            // the SpriteRig has texture coords defined in its AnimationChains
            if (spriteRig.PoseChains.Count != 0)
            {
                spriteRig.SetPoseChain(spriteRig.PoseChains[0]);
                spriteRig.Animate = true;
                spriteRig.SetPositionAtTimeFromAnimationStart(0);
                spriteRig.Animate = false;

            }
            #endregion

            GuiData.srSaveOptions.joints = new SpriteList();
            GuiData.srSaveOptions.bodySprites = new SpriteList();
            GuiData.srSaveOptions.joints.Clear();
            GuiData.srSaveOptions.bodySprites.Clear();

            string oldRelativeDirectory = FileManager.RelativeDirectory;
            FileManager.RelativeDirectory = FileManager.GetDirectory(fileName);


            foreach (Sprite regularSprite in spriteRig.Joints)
            {
                es = new EditorSprite();

                es.SetFromRegularSprite(regularSprite);
                GameData.Scene.Sprites.Add(es);
                SpriteManager.AddSprite(es);
                loadedSprites.AddOneWay(es);
                GuiData.srSaveOptions.joints.Add(es);
            }
            foreach (Sprite regularSprite in spriteRig.BodySprites)
            {
                es = new EditorSprite();
                es.SetFromRegularSprite(regularSprite);
                GameData.Scene.Sprites.Add(es);
                SpriteManager.AddSprite(es);
                loadedSprites.AddOneWay(es);
                GuiData.srSaveOptions.bodySprites.Add(es);
            }

            // The root is not part of the body Sprites, but it should be
            if (spriteRig.Root != null && GameData.Scene.Sprites.Contains(spriteRig.Root) == false)
            {
                es = new EditorSprite();
                es.SetFromRegularSprite(spriteRig.Root);
                GameData.Scene.Sprites.Add(es);
                SpriteManager.AddSprite(es);
                loadedSprites.AddOneWay(es);
                GuiData.srSaveOptions.bodySprites.Add(es);

            }

            if (spriteRig.Root != null)
            {
                GuiData.srSaveOptions.root = GuiData.srSaveOptions.bodySprites.FindByName(spriteRig.Root.Name);
                GuiData.srSaveOptions.bodySprites.Remove(GuiData.srSaveOptions.root);
            }
            GuiData.srSaveOptions.poseChains = spriteRig.PoseChains;
            if (srs.JointsVisible)
            {
                GuiData.srSaveOptions.jointsVisible.Press();
            }
            else
            {
                GuiData.srSaveOptions.jointsVisible.Unpress();
            }
            if (srs.RootVisible)
            {
                GuiData.srSaveOptions.rootVisible.Press();
            }
            else
            {
                GuiData.srSaveOptions.rootVisible.Unpress();
            }

            FileManager.RelativeDirectory = oldRelativeDirectory;

            string oldRelative = FileManager.RelativeDirectory;
            if (srs.AssetsRelativeToFile)
            {
                FileManager.RelativeDirectory = FileManager.GetDirectory(fileName);
            }

            FileManager.RelativeDirectory = oldRelative;
            foreach (SpriteSave ss in srs.Joints)
            {
                srs.BodySprites.Add(ss);
            }


            for (int i = 0; i < loadedSprites.Count; i++)
            {

                if (loadedSprites[i].PixelSize > 0f)
                {
                    ((EditorSprite)loadedSprites[i]).ConstantPixelSizeExempt = false;
                }
                else
                {
                    ((EditorSprite)loadedSprites[i]).ConstantPixelSizeExempt = true;
                }

                if (loadedSprites[i].Texture.texture != null)
                {
                    GuiData.ListWindow.Add(loadedSprites[i].Texture);
                }

                string parentName = "";

                Sprite matchingSprite = spriteRig.BodySprites.FindByName(loadedSprites[i].Name);

                if (matchingSprite == null)
                {
                    matchingSprite = spriteRig.Joints.FindByName(loadedSprites[i].Name);
                }
                // parent may be null if there is no root
                if (matchingSprite != null && matchingSprite.Parent != null)
                {
                    parentName = matchingSprite.Parent.Name;

                    loadedSprites[i].AttachTo(loadedSprites.FindByName(parentName), false);
                }
            }
            GameData.Scene.Sprites.SortZInsertionDescending();




            AskToSearchForReplacements(((FileWindow)callingWindow).Results[0]);
        }
Example #4
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));
        }
Example #5
0
        public static Sprite copySpriteHierarchy(Sprite spriteToCopy, Sprite parentSprite, float pixelSize,
                                                 SpriteList newSpritesOneWay, Dictionary <string, int> appendedNumbers)
        {
            // Create the new Sprite by cloning the spriteToCopy
            Sprite newSprite = null;

            if (spriteToCopy is EditorSprite)
            {
                newSprite = spriteToCopy.Clone <EditorSprite>();
            }
            else
            {
                newSprite = spriteToCopy.Clone <Sprite>();
            }


            newSpritesOneWay.AddOneWay(newSprite);

            // Add the new Sprite to the SpriteManager
            if (SpriteManager.OrderedSprites.Contains(spriteToCopy))
            {
                SpriteManager.AddSprite(newSprite);
            }
            else
            {
                SpriteManager.AddSprite(newSprite);
                SpriteManager.ConvertToZBufferedSprite(newSprite);
            }

            #region Fix the new Sprite's name
            // Take the number off of the end and see if it exists in the appendedNumbers.
            string nameWithoutNumbers = StringFunctions.RemoveNumberAtEnd(spriteToCopy.Name);

            // if it's there, then use the number associated with the name to assign the name
            if (appendedNumbers.ContainsKey(nameWithoutNumbers))
            {
                newSprite.Name = GetUniqueNameForObject(
                    nameWithoutNumbers + appendedNumbers[nameWithoutNumbers], (Sprite)null);

                appendedNumbers[nameWithoutNumbers] =
                    StringFunctions.GetIntAfter(nameWithoutNumbers, newSprite.Name);
            }
            else
            {
                // there is no entry for the nameWithoutNumbers, so find the name and add it with the appropriate number
                newSprite.Name = GetUniqueNameForObject(spriteToCopy.Name, (Sprite)null);

                if (StringFunctions.HasNumberAtEnd(newSprite.Name))
                {
                    // we know that the newSprite.name already exists so save a little work next time if there is another Sprite
                    // to copy by simply incrementing the number.
                    appendedNumbers.Add(nameWithoutNumbers, 1 + StringFunctions.GetIntAfter(nameWithoutNumbers, newSprite.Name));
                }
            }
            #endregion

            SetStoredAddToSE(newSprite as ISpriteEditorObject, pixelSize);

            if (parentSprite != null)
            {
                newSprite.Detach();
                newSprite.AttachTo(parentSprite, false);
            }

            for (int i = 0; i < spriteToCopy.Children.Count; i++)
            {
                copySpriteHierarchy(spriteToCopy.Children[i] as Sprite, newSprite, pixelSize, newSpritesOneWay, appendedNumbers);
            }
            return(newSprite);
        }
Example #6
0
        public static void LoadSpriteRigOk(Window callingWindow)
        {
            #region Load the SpriteRig

            EditorSprite es;
            string       fileName = ((FileWindow)callingWindow).Results[0];

            SpriteRigSave srs           = SpriteRigSave.FromFile(fileName);
            SpriteList    loadedSprites = new SpriteList();

            SpriteRig spriteRig = srs.ToSpriteRig(GameData.SceneContentManager);

            #endregion

            #region Play some Pose so that the SpriteRig has a proper pose and texture coordinates

            // Play and stop an animation to get the texture coordinates set up in case
            // the SpriteRig has texture coords defined in its AnimationChains
            if (spriteRig.PoseChains.Count != 0)
            {
                spriteRig.SetPoseChain(spriteRig.PoseChains[0]);
                spriteRig.Animate = true;
                spriteRig.SetPositionAtTimeFromAnimationStart(0);
                spriteRig.Animate = false;
            }
            #endregion

            GuiData.srSaveOptions.joints      = new SpriteList();
            GuiData.srSaveOptions.bodySprites = new SpriteList();
            GuiData.srSaveOptions.joints.Clear();
            GuiData.srSaveOptions.bodySprites.Clear();

            string oldRelativeDirectory = FileManager.RelativeDirectory;
            FileManager.RelativeDirectory = FileManager.GetDirectory(fileName);


            foreach (Sprite regularSprite in spriteRig.Joints)
            {
                es = new EditorSprite();

                es.SetFromRegularSprite(regularSprite);
                GameData.Scene.Sprites.Add(es);
                SpriteManager.AddSprite(es);
                loadedSprites.AddOneWay(es);
                GuiData.srSaveOptions.joints.Add(es);
            }
            foreach (Sprite regularSprite in spriteRig.BodySprites)
            {
                es = new EditorSprite();
                es.SetFromRegularSprite(regularSprite);
                GameData.Scene.Sprites.Add(es);
                SpriteManager.AddSprite(es);
                loadedSprites.AddOneWay(es);
                GuiData.srSaveOptions.bodySprites.Add(es);
            }

            // The root is not part of the body Sprites, but it should be
            if (spriteRig.Root != null && GameData.Scene.Sprites.Contains(spriteRig.Root) == false)
            {
                es = new EditorSprite();
                es.SetFromRegularSprite(spriteRig.Root);
                GameData.Scene.Sprites.Add(es);
                SpriteManager.AddSprite(es);
                loadedSprites.AddOneWay(es);
                GuiData.srSaveOptions.bodySprites.Add(es);
            }

            if (spriteRig.Root != null)
            {
                GuiData.srSaveOptions.root = GuiData.srSaveOptions.bodySprites.FindByName(spriteRig.Root.Name);
                GuiData.srSaveOptions.bodySprites.Remove(GuiData.srSaveOptions.root);
            }
            GuiData.srSaveOptions.poseChains = spriteRig.PoseChains;
            if (srs.JointsVisible)
            {
                GuiData.srSaveOptions.jointsVisible.Press();
            }
            else
            {
                GuiData.srSaveOptions.jointsVisible.Unpress();
            }
            if (srs.RootVisible)
            {
                GuiData.srSaveOptions.rootVisible.Press();
            }
            else
            {
                GuiData.srSaveOptions.rootVisible.Unpress();
            }

            FileManager.RelativeDirectory = oldRelativeDirectory;

            string oldRelative = FileManager.RelativeDirectory;
            if (srs.AssetsRelativeToFile)
            {
                FileManager.RelativeDirectory = FileManager.GetDirectory(fileName);
            }

            FileManager.RelativeDirectory = oldRelative;
            foreach (SpriteSave ss in srs.Joints)
            {
                srs.BodySprites.Add(ss);
            }


            for (int i = 0; i < loadedSprites.Count; i++)
            {
                if (loadedSprites[i].PixelSize > 0f)
                {
                    ((EditorSprite)loadedSprites[i]).ConstantPixelSizeExempt = false;
                }
                else
                {
                    ((EditorSprite)loadedSprites[i]).ConstantPixelSizeExempt = true;
                }

                if (loadedSprites[i].Texture.texture != null)
                {
                    GuiData.ListWindow.Add(loadedSprites[i].Texture);
                }

                string parentName = "";

                Sprite matchingSprite = spriteRig.BodySprites.FindByName(loadedSprites[i].Name);

                if (matchingSprite == null)
                {
                    matchingSprite = spriteRig.Joints.FindByName(loadedSprites[i].Name);
                }
                // parent may be null if there is no root
                if (matchingSprite != null && matchingSprite.Parent != null)
                {
                    parentName = matchingSprite.Parent.Name;

                    loadedSprites[i].AttachTo(loadedSprites.FindByName(parentName), false);
                }
            }
            GameData.Scene.Sprites.SortZInsertionDescending();



            AskToSearchForReplacements(((FileWindow)callingWindow).Results[0]);
        }
Example #7
0
 /// <summary>
 /// Directly adds a sprite to the sprite list for this layer.
 /// This is faster than using the SpriteManager.AddToLayer method
 /// but does no automatic updating and performs a one way add.
 /// </summary>
 /// <param name="spriteToAdd">The sprite to be added.</param>
 public void AddManualSpriteOneWay(Sprite spriteToAdd)
 {
     mSprites.AddOneWay(spriteToAdd);
 }