Ejemplo n.º 1
0
        public void PopulateAndAddGridToEngine(SpriteGrid gridToAdd, Sprite spriteToUseAsPopulationSource)
        {
            #region select the base point for population and populate the grid
            if (gridToAdd.GridPlane == SpriteGrid.Plane.XY)
            {
                gridToAdd.PopulateGrid(camera.X,
                                       camera.Y,
                                       spriteToUseAsPopulationSource.Z);
            }
            else
            {
                gridToAdd.PopulateGrid(camera.X,
                                       spriteToUseAsPopulationSource.Y,
                                       spriteToUseAsPopulationSource.Z);
            }
            #endregion

            GameData.Scene.SpriteGrids.Add(gridToAdd);



            /* When converting a Sprite to a SpriteGrid, the editGrids is not pressed
             * (yet) when this method is called.  Therefore, if the editGrids button
             * is not pressed, then the grid was created from the currentSprite, so
             * the currentSprite should be deleted.
             *
             * If it is pressed, the Grid has been created from a CTRL+C command
             * (copying a SpriteGrid).  In that case, no deleting of currentSprites
             * should be executed.
             */
            if (!SpriteEditorSettings.EditingSpriteGrids && spriteToUseAsPopulationSource != null)
            {
                SpriteManager.RemoveSprite(spriteToUseAsPopulationSource);
            }

            this.ClickGrid(gridToAdd, null);
        }
Ejemplo n.º 2
0
        public void PopulateAndAddGridToEngine(SpriteGrid gridToAdd, Sprite spriteToUseAsPopulationSource)
        {
            #region select the base point for population and populate the grid
            if (gridToAdd.GridPlane == SpriteGrid.Plane.XY)
            {
                gridToAdd.PopulateGrid(camera.X,
                    camera.Y,
                    spriteToUseAsPopulationSource.Z);
            }
            else
            {
                gridToAdd.PopulateGrid(camera.X,
                    spriteToUseAsPopulationSource.Y,
                    spriteToUseAsPopulationSource.Z);
            }
            #endregion

            GameData.Scene.SpriteGrids.Add(gridToAdd);



            /* When converting a Sprite to a SpriteGrid, the editGrids is not pressed
             * (yet) when this method is called.  Therefore, if the editGrids button
             * is not pressed, then the grid was created from the currentSprite, so
             * the currentSprite should be deleted.
             * 
             * If it is pressed, the Grid has been created from a CTRL+C command
             * (copying a SpriteGrid).  In that case, no deleting of currentSprites
             * should be executed.
             */
            if ( !SpriteEditorSettings.EditingSpriteGrids && spriteToUseAsPopulationSource != null)
            {
                SpriteManager.RemoveSprite(spriteToUseAsPopulationSource);
            }

            this.ClickGrid(gridToAdd, null);

        }
Ejemplo n.º 3
0
        public void PerformLoadScn(string fileName, bool replace)
        {
            // This method is public because this method is called if the user drags a
            // .scnx onto the SpriteEditor

            #region Mark how many objects before loading in case there is an insertion.
            // If there is an insertion, only the newly-added objects should have post load
            // logic performed on them

            int numSpritesBefore         = GameData.Scene.Sprites.Count;
            int numOfSGsBefore           = GameData.Scene.SpriteGrids.Count;
            int numOfSpriteFramesBefore  = GameData.Scene.SpriteFrames.Count;
            int numberOfPositionedModels = GameData.Scene.PositionedModels.Count;

            #endregion

            SpriteEditorScene tempSES = SpriteEditorScene.FromFile(fileName);

            #region See if there are any Models that reference files that aren't on disk

            string sceneDirectory = FileManager.GetDirectory(fileName);
            for (int i = 0; i < tempSES.PositionedModelSaveList.Count; i++)
            {
                PositionedModelSave modelSave = tempSES.PositionedModelSaveList[i];

                if (!FileManager.FileExists(modelSave.ModelFileName))
                {
                    // See if there's a .x with that name

                    if (FileManager.FileExists(sceneDirectory + modelSave.ModelFileName + ".x"))
                    {
                        modelSave.ModelFileName = modelSave.ModelFileName + ".x";
                    }
                }
            }
            #endregion

            #region Now, see if there are any other files that haven't been found and create the error window

            List <string> texturesNotFound = tempSES.GetMissingFiles();
            if (texturesNotFound.Count != 0)
            {
                OkListWindow okListWindow = new OkListWindow(
                    "There are files that the .scnx references which cannot be located.",
                    "Error loading .scnx");

                foreach (string file in texturesNotFound)
                {
                    okListWindow.AddItem(file);
                }

                return;
            }
            #endregion

            #region if replacing, clear the old scene out
            if (replace)
            {
                SpriteManager.RemoveScene(GameData.Scene, true);
                FlatRedBallServices.Unload(GameData.SceneContentManager);

                tempSES.SetCamera(GameData.Camera);

#if FRB_MDX
                if (tempSES.CoordinateSystem == FlatRedBall.Math.CoordinateSystem.RightHanded)
                {
                    GameData.Camera.Z *= -1;
                }
#endif

                GameData.EditorProperties.PixelSize = tempSES.PixelSize;

                GuiData.EditorPropertiesGrid.Refresh();

                // 4/16/2011:  The following line of code
                // was causing errors when saving the .scnx
                // file through CTRL+S.  Taking it out because
                // I don't see why we need this anyway.
                // GameData.FileName = FileManager.RemoveExtension(fileName);
                GameData.FileName = fileName;
                FlatRedBallServices.Owner.Text = "SpriteEditor - Currently editing " + GameData.FileName;

                GuiData.MenuStrip.LastFileTypeLoaded = FileManager.GetExtension(fileName);
            }
            #endregion


            Scene newlyLoadedScene = tempSES.ToScene <EditorSprite>(GameData.SceneContentManager);

            GameData.Scene.AddToThis(newlyLoadedScene);
            // This caused
            // a double-add.
            // Not sure why we're
            // adding GameData.Scene.
            //GameData.Scene.AddToManagers();
            newlyLoadedScene.AddToManagers();

            GuiData.ListWindow.RefreshListsShown();

            #region Add the used Textures to the texture ListBox

            for (int i = numSpritesBefore; i < GameData.Scene.Sprites.Count; i++)
            {
                GuiData.ListWindow.Add(GameData.Scene.Sprites[i].Texture);
                GuiData.ListWindow.Add(GameData.Scene.Sprites[i].AnimationChains);
            }

            for (int i = numOfSpriteFramesBefore; i < GameData.Scene.SpriteFrames.Count; i++)
            {
                GuiData.ListWindow.Add(GameData.Scene.SpriteFrames[i].Texture);
                GuiData.ListWindow.Add(GameData.Scene.SpriteFrames[i].AnimationChains);
            }

            for (int i = numOfSGsBefore; i < GameData.Scene.SpriteGrids.Count; i++)
            {
                SpriteGrid sg = GameData.Scene.SpriteGrids[i];
                sg.PopulateGrid(GameData.Camera.X, GameData.Camera.Y, 0f);

                sg.RefreshPaint();
                List <Texture2D> texturesToAdd = sg.GetUsedTextures();
                foreach (Texture2D tex in texturesToAdd)
                {
                    GuiData.ListWindow.Add(tex);
                }
            }
            #endregion

            CheckForExtraFiles(FileManager.RemoveExtension(fileName));
            GameData.Scene.Sprites.SortZInsertionDescending();


            if (tempSES.AssetsRelativeToSceneFile)
            {
                FileManager.ResetRelativeToCurrentDirectory();
            }
        }
Ejemplo n.º 4
0
        private void RepopulateSpriteGrid(object spriteGrid)
        {
            SpriteGrid asSpriteGrid = spriteGrid as SpriteGrid;

            asSpriteGrid.PopulateGrid();
        }