private static void TryHandlePngRefresh(FilePath fileName, List <LoadedFile> allFileObjects)
        {
            var mapLayersReferencingTexture = new List <MapDrawableBatch>();

            // see if this is referenced by any of the existing TMX's
            foreach (var tmxLoadedFile in allFileObjects.Where(item => item.FilePath.Extension == "tmx"))
            {
                var runtimeObject = tmxLoadedFile.RuntimeObject as LayeredTileMap;

                foreach (var mapLayer in runtimeObject.MapLayers)
                {
                    var referencesTexture = mapLayer.Texture.Name == fileName;

                    if (referencesTexture)
                    {
                        mapLayersReferencingTexture.Add(mapLayer);
                    }
                }
            }

            if (mapLayersReferencingTexture.Count > 0)
            {
                FlatRedBallServices.Unload(nameof(TiledRuntimeFileManager));

                var newTexture = FlatRedBallServices.Load <Texture2D>(fileName.FullPath, nameof(TiledRuntimeFileManager));
                // unload the content manager so that we can re-create the files:
                foreach (var layer in mapLayersReferencingTexture)
                {
                    layer.Texture = newTexture;
                }
                // even though we may have handled it, we don't want to return true because
                // other plugins may reload this file too
            }
        }
Пример #2
0
        public static void UnloadScene()
        {
            mLoadedScene.RemoveFromManagers();

            FlatRedBallServices.Unload(SceneContentManager);

            mLoadedScene = null;
        }
Пример #3
0
        public static void LoadScene(string fileName)
        {
            if (mScene != null)
            {
                FlatRedBallServices.Unload(ContentManagerName);
                mScene.RemoveFromManagers();
            }

            FlatRedBall.Content.SpriteEditorScene ses = FlatRedBall.Content.SpriteEditorScene.FromFile(fileName);

            EditorData.Scene = ses.ToScene(EditorData.ContentManagerName);
        }
Пример #4
0
        void CustomInitialize()
        {
            if (!ShapeManager.VisibleCircles.Contains(FileScreen.ShapeCollectionFile.Circles[0]))
            {
                throw new Exception("Static files that are part of Screens should be added to managers, but they're not.");
            }

            if (GetFile("ShapeCollectionFile") != ShapeCollectionFile)
            {
                throw new Exception("GetFile is not properly returning file references");
            }

            // We're going to grab content from here without actually calling LoadStaticContent
            FileReferencingEntity.ContentManagerName = this.ContentManagerName;
            Scene scene = FileReferencingEntity.SceneLoadedOnlyWhenReferenced;

            this.CurrentSceneFileSettingCategoryState = SceneFileSettingCategory.SetSceneFile1;
            if (this.SceneInstanceThatIsAssigned != SceneFile1)
            {
                throw new Exception("State assignment isn't working properly");
            }
            if (SpriteManager.AutomaticallyUpdatedSprites.Contains(this.SceneInstanceThatIsAssigned.Sprites[0]) == false)
            {
                throw new Exception("Setting a SourceFile does not seem to be calling AddToManagers");
            }

            if (SpriteManager.AutomaticallyUpdatedSprites.Contains(NotAddedToManagers.Sprites[0]))
            {
                throw new Exception("The NotAddedToManagers Sprite is being added to the engine, and it shouldn't be");
            }

            // Some platforms (like Android) lazy-load instead of async load content in GlobalContent if
            // GlobalContnt is set to load async.
            // Therefore, let's force access on some files:
            var bearFromContent = GlobalContent.BearContentPipeline;


            // let's test loading .achx files using the manual .achx parser. This allows PC to act the same
            // as iOS/Android:
            var old = AnimationChainListSave.ManualDeserialization;

            AnimationChainListSave.ManualDeserialization = true;
            const string tempContentManager = "TempContentManager";
            var          animationEntity    = new Entities.AnimationChainEntity(tempContentManager);

            if (animationEntity.SpriteObjectAnimationChains.Count == 0)
            {
                throw new Exception("Animation chains are not loading properly through manaul XML deserialization");
            }
            animationEntity.Destroy();
            FlatRedBallServices.Unload(tempContentManager);
            AnimationChainListSave.ManualDeserialization = old;
        }
Пример #5
0
        public virtual void Destroy()
        {
#if !FRB_MDX
            StateManager.Current.Activating   -= ActivatingAction;
            StateManager.Current.Deactivating -= DeactivatingAction;
#endif
            if (mLastLoadedScene != null)
            {
                mLastLoadedScene.Clear();
            }


            FlatRedBall.Debugging.Debugger.DestroyText();

            // It's common for users to forget to add Particle Sprites
            // to the mSprites SpriteList.  This will either create leftover
            // particles when the next screen loads or will throw an assert when
            // the ScreenManager checks if there are any leftover Sprites.  To make
            // things easier we'll just clear the Particle Sprites here.
            bool isPopup = this != ScreenManager.CurrentScreen;
            if (!isPopup)
            {
                SpriteManager.RemoveAllParticleSprites();
            }

            if (UnloadsContentManagerWhenDestroyed && mContentManagerName != FlatRedBallServices.GlobalContentManager)
            {
                FlatRedBallServices.Unload(mContentManagerName);
                FlatRedBallServices.Clean();
            }

            if (ShouldRemoveLayer && mLayer != null)
            {
                SpriteManager.RemoveLayer(mLayer);
            }
            if (IsPaused)
            {
                UnpauseThisScreen();
            }

            GuiManager.Cursor.IgnoreNextClick = true;

            if (mNumberOfThreadsBeforeAsync != -1)
            {
                FlatRedBallServices.SetNumberOfThreadsToUse(mNumberOfThreadsBeforeAsync);
            }

            if (ScreenDestroy != null)
            {
                ScreenDestroy();
            }
        }
Пример #6
0
        /// <summary>
        /// Removes the argument texture from memory, from list boxes, and from any GUI displaying the texture.
        /// </summary>
        /// <remarks>
        /// This method does not remove or retexture any objects which reference this texture.  This is handled
        /// in other methods like RemoveObjectsReferencing.
        /// </remarks>
        /// <param name="textureToDelete">The texture to remove.</param>
        #endregion
        public static void DeleteTexture(Texture2D textureToDelete)
        {
            GuiData.ListWindow.Remove(textureToDelete);

            if (GuiData.ToolsWindow.currentTextureDisplay.UpOverlayTexture == textureToDelete)
            {
                GuiData.ToolsWindow.currentTextureDisplay.SetOverlayTextures(null, null);
            }

            GuiData.TextureCoordinatesSelectionWindow.Visible = false;

            FlatRedBallServices.Unload(textureToDelete, SceneContentManager);
        }
Пример #7
0
        public virtual void Destroy()
        {
            if (mLastLoadedScene != null)
            {
                mLastLoadedScene.Clear();
            }


            FlatRedBall.Debugging.Debugger.DestroyText();

            // All of the popups should be destroyed as well
            foreach (Screen s in mPopups)
            {
                s.Destroy();
            }

            SpriteManager.RemoveSpriteList <Sprite>(mSprites);

            // It's common for users to forget to add Particle Sprites
            // to the mSprites SpriteList.  This will either create leftover
            // particles when the next screen loads or will throw an assert when
            // the ScreenManager checks if there are any leftover Sprites.  To make
            // things easier we'll just clear the Particle Sprites here.  If you don't
            // want this done (not likely), remove the following line, but only do so if
            // you really know what you're doing!
            SpriteManager.RemoveAllParticleSprites();

            // Destory all SpriteGrids that belong to this Screen
            foreach (SpriteGrid sg in mSpriteGrids)
            {
                sg.Destroy();
            }


            // Destroy all SpriteFrames that belong to this Screen
            while (mSpriteFrames.Count != 0)
            {
                SpriteManager.RemoveSpriteFrame(mSpriteFrames[0]);
            }

            if (UnloadsContentManagerWhenDestroyed && mContentManagerName != FlatRedBallServices.GlobalContentManager)
            {
                FlatRedBallServices.Unload(mContentManagerName);
            }

            if (ShouldRemoveLayer && mLayer != null)
            {
                SpriteManager.RemoveLayer(mLayer);
            }
        }
Пример #8
0
        public static void LoadScene(string fileName)
        {
            if (mScene != null)
            {
                FlatRedBallServices.Unload(ContentManagerName);
                SpriteManager.RemoveScene(mScene, true);
            }

            FlatRedBall.Content.SpriteEditorScene ses = FlatRedBall.Content.SpriteEditorScene.FromFile(fileName);

            mScene = ses.ToScene(EditorData.ContentManagerName);

            SpriteManager.AddScene(mScene);

            LastLoadedFile = fileName;
        }
Пример #9
0
        public static void MakeNewScene()
        {
            EditorWindow.LastInstance.Text = "SpriteEditor - untitled scene";

            SpriteManager.RemoveSpriteList(GameData.Scene.Sprites);

            FlatRedBallServices.Unload(GameData.SceneContentManager);

            GameData.Scene.RemoveFromManagers();

            GameData.Scene.SpriteGrids.Clear();
            SESpriteGridManager.CurrentSpriteGrid  = null;
            sesgMan.SpriteGridGrabbed              = null;
            sesgMan.newlySelectedCurrentSprite     = null;
            sesgMan.newlySelectedCurrentSpriteGrid = null;
            SESpriteGridManager.oldPosition        = Vector3.Empty;
            sesgMan.ClickGrid(null, null);


            GameData.DeselectCurrentSpriteFrames();

            GuiData.ListWindow.ClearTextures();
            mReferencedAnimationChains.Clear();

            FlatRedBallServices.Unload(GameData.SceneContentManager);

            GuiData.ToolsWindow.SnapSprite.Unpress();
            GameData.EditorProperties.ConstrainDimensions = false;
            GameData.EditorProperties.PixelSize           = 0f;
            GameData.EditorProperties.SnapToGrid          = false;

            Camera.X = 0f;
            Camera.Y = 0f;
            Camera.Z = -40f;
            GameData.EditorLogic.EditAxes.Visible = false;

            if (mShapeCollection != null)
            {
                mShapeCollection.RemoveFromManagers();
                mShapeCollection = null;
            }

            mProperties = new SpriteEditorSceneProperties();
        }
Пример #10
0
        public static void UnloadScene()
        {
            #region Delete the Scene

            if (Scene != null)
            {
                Scene.RemoveFromManagers();
            }

            SpriteManager.Camera.X = 0f;
            SpriteManager.Camera.Y = 0f;
            SpriteManager.Camera.Z = -40f;

            #endregion

            #region Remove ContentManager
            FlatRedBallServices.Unload(EditorData.ContentManagerName);
            #endregion
        }
Пример #11
0
        /// <summary>
        /// Method called by the ScreenManager which unloads all textures,
        /// Remove Sprites, destroys the GUI, Text objects, SpriteGrids,
        /// and SpriteFrames.
        /// </summary>
        #endregion
        public virtual void Destroy()
        {
            if (mLastLoadedScene != null)
            {
                mLastLoadedScene.Clear();
            }

            // All of the popups should be destroyed as well
            foreach (Screen s in mPopups)
            {
                s.Destroy();
            }

            SpriteManager.RemoveSpriteList(mSprites);

            // It's common for users to forget to add Particle Sprites
            // to the mSprites SpriteList.  This will either create leftover
            // particles when the next screen loads or will throw an assert when
            // the ScreenManager checks if there are any leftover Sprites.  To make
            // things easier we'll just clear the Particle Sprites here.  If you don't
            // want this done (not likely), remove the following line, but only do so if
            // you really know what you're doing!
            SpriteManager.RemoveAllParticleSprites();

            // Destory all SpriteGrids that belong to this Screen
            foreach (SpriteGrid sg in mSpriteGrids)
            {
                sg.Destroy();
            }


            // Destroy all SpriteFrames that belong to this Screen
            while (mSpriteFrames.Count != 0)
            {
                SpriteManager.RemoveSpriteFrame(mSpriteFrames[0]);
            }

            TextManager.RemoveText(mTexts);

            while (mPolygons.Count != 0)
            {
                ShapeManager.Remove(mPolygons[0]);
            }

            while (mLines.Count != 0)
            {
                ShapeManager.Remove(mLines[0]);
            }

            while (mAxisAlignedRectangles.Count != 0)
            {
                ShapeManager.Remove(mAxisAlignedRectangles[0]);
            }

            while (mCircles.Count != 0)
            {
                ShapeManager.Remove(mCircles[0]);
            }

            while (mPositionedModels.Count != 0)
            {
                ModelManager.RemoveModel(mPositionedModels[0]);
            }

            if (UnloadsContentManagerWhenDestroyed)
            {
                FlatRedBallServices.Unload(mContentManagerName);
            }

            if (mLayer != null)
            {
                SpriteManager.RemoveLayer(mLayer);
            }

            for (int i = 0; i < mLayers.Count; i++)
            {
                SpriteManager.RemoveLayer(mLayers[i]);
            }
        }
Пример #12
0
        public virtual void Destroy()
        {
#if !FRB_MDX
            StateManager.Current.Activating   -= ActivatingAction;
            StateManager.Current.Deactivating -= DeactivatingAction;
#endif
            if (mLastLoadedScene != null)
            {
                mLastLoadedScene.Clear();
            }


            FlatRedBall.Debugging.Debugger.DestroyText();

            // All of the popups should be destroyed as well
            foreach (Screen s in mPopups)
            {
                s.Destroy();
            }

            SpriteManager.RemoveSpriteList <Sprite>(mSprites);

            // It's common for users to forget to add Particle Sprites
            // to the mSprites SpriteList.  This will either create leftover
            // particles when the next screen loads or will throw an assert when
            // the ScreenManager checks if there are any leftover Sprites.  To make
            // things easier we'll just clear the Particle Sprites here.
            bool isPopup = this != ScreenManager.CurrentScreen;
            if (!isPopup)
            {
                SpriteManager.RemoveAllParticleSprites();
            }

            // Destory all SpriteGrids that belong to this Screen
            foreach (SpriteGrid sg in mSpriteGrids)
            {
                sg.Destroy();
            }


            // Destroy all SpriteFrames that belong to this Screen
            while (mSpriteFrames.Count != 0)
            {
                SpriteManager.RemoveSpriteFrame(mSpriteFrames[0]);
            }

            if (UnloadsContentManagerWhenDestroyed && mContentManagerName != FlatRedBallServices.GlobalContentManager)
            {
                FlatRedBallServices.Unload(mContentManagerName);
                FlatRedBallServices.Clean();
            }

            if (ShouldRemoveLayer && mLayer != null)
            {
                SpriteManager.RemoveLayer(mLayer);
            }
            if (IsPaused)
            {
                UnpauseThisScreen();
            }

            GuiManager.Cursor.IgnoreNextClick = true;
        }
Пример #13
0
 public void Unload()
 {
     mHasFinished = false;
     mCloneables  = new Dictionary <string, object>();
     FlatRedBallServices.Unload(mContentManagerName);
 }
Пример #14
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();
            }
        }