public static void LoadScene(string fileName) { if (mScene != null) { mScene.RemoveFromManagers(); mScene.Clear(); } SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName); mScene = ses.ToScene(AppState.Self.PermanentContentManager); mScene.AddToManagers(); FileMenuWindow.AttemptEmitterAttachment(fileName); }
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(); } }