public override bool TryHandleRefreshFile(FilePath filePath, List <LoadedFile> loadedFiles, List <LoadedFile> addedFiles) { var shouldRefresh = false; var extension = filePath.Extension; var isGumFile = extension == Gum.DataTypes.GumProjectSave.ScreenExtension || extension == Gum.DataTypes.GumProjectSave.ComponentExtension || extension == Gum.DataTypes.GumProjectSave.StandardExtension; if (isGumFile) { // For now we only refresh if it's a gum file. Eventually // we may want to refresh if any referenced file is changed. if (gumIdb != null) { string fullFileName = GetGumIdbFullFileName(); shouldRefresh = fullFileName == filePath; if (!shouldRefresh) { // See if the file is referenced by the GumIDB var referencedFiles = Gum.Managers.ObjectFinder.Self .GetFilesReferencedBy(gumIdb.Element.ElementSave) .Select(item => new FilePath(item)); shouldRefresh = referencedFiles.Any(item => item == filePath); } } if (shouldRefresh) { gumIdb.Destroy(); loadedFiles.RemoveAll(item => item.RuntimeObject == gumIdb); string fullFileName = GetGumIdbFullFileName(); var existingLoadedFile = loadedFiles.FirstOrDefault(item => item.FilePath == fullFileName); object gumIdbAsObject; object dataModel; Load(fullFileName, out gumIdbAsObject, out dataModel); gumIdb = gumIdbAsObject as GumIdb; gumIdb?.Element.AddToManagers(); if (existingLoadedFile != null) { existingLoadedFile.RuntimeObject = gumIdb; } } } return(shouldRefresh); }
public override bool DestroyRuntimeObject(object runtimeObject) { if (runtimeObject is GumIdb) { if (runtimeObject == gumIdb) { gumIdb = null; } ((GumIdb)runtimeObject).Destroy(); return(false); } return(true); }
public override void RemoveFromManagers(ICollection <LoadedFile> allFileObjects) { foreach (var fileObject in allFileObjects) { if (fileObject.RuntimeObject is GumIdb) { var gumIdb = fileObject.RuntimeObject as GumIdb; FlatRedBall.SpriteManager.RemoveDrawableBatch(gumIdb); gumIdb.Element.RemoveFromManagers(); } } gumIdb = null; }
protected override void Load(FilePath referencedFilePath, out object runtimeObjects, out object dataModel) { var extension = referencedFilePath.Extension; if (extension == "gusx") { var gumReferencedFile = GlueViewState.Self .GetAllReferencedFiles() .FirstOrDefault(item => item.Name.ToLowerInvariant().EndsWith(".gumx")); var absoluteGumxFileName = GlueViewCommands.Self.FileCommands.GetAbsoluteFileName(gumReferencedFile); GumIdb.StaticInitialize(absoluteGumxFileName.FullPath); var contentManagerWrapper = new FlatRedBall.Gum.ContentManagerWrapper(); contentManagerWrapper.ContentManagerName = "test"; RenderingLibrary.Content.LoaderManager.Self.ContentLoader = contentManagerWrapper; gumIdb = new GumIdb(); string elementFileName = referencedFilePath.Standardized; gumIdb.LoadFromFile(elementFileName); gumIdb.AssignReferences(); gumIdb.Element.UpdateLayout(); // Handled in StaticInit //SpriteManager.AddDrawableBatch(gumIdb); runtimeObjects = gumIdb; dataModel = gumIdb.Element; } else { runtimeObjects = null; dataModel = null; } }
public static void StaticInitialize(string projectFileName) { if (mManagers == null) { mManagers = new SystemManagers(); mManagers.Initialize(FlatRedBallServices.GraphicsDevice); mManagers.Renderer.Camera.AbsoluteLeft = 0; mManagers.Renderer.Camera.AbsoluteTop = 0; var viewport = mManagers.Renderer.GraphicsDevice.Viewport; viewport.Width = FlatRedBall.Math.MathFunctions.RoundToInt(FlatRedBall.Camera.Main.DestinationRectangle.Width); viewport.Height = FlatRedBall.Math.MathFunctions.RoundToInt(FlatRedBall.Camera.Main.DestinationRectangle.Height); mManagers.Renderer.GraphicsDevice.Viewport = viewport; if (FlatRedBall.Camera.Main.Orthogonal) { GraphicalUiElement.CanvasHeight = FlatRedBall.Camera.Main.OrthogonalHeight; GraphicalUiElement.CanvasWidth = FlatRedBall.Camera.Main.OrthogonalWidth; } else { GraphicalUiElement.CanvasHeight = FlatRedBall.Camera.Main.DestinationRectangle.Height; GraphicalUiElement.CanvasWidth = FlatRedBall.Camera.Main.DestinationRectangle.Width; } // Need to do the zoom here in response to the FRB camera vs. the Gum camera mManagers.Renderer.Camera.Zoom = viewport.Height / (float)GraphicalUiElement.CanvasHeight; mManagers.Renderer.Camera.CameraCenterOnScreen = CameraCenterOnScreen.TopLeft; mManagers.Renderer.Camera.X = 0; mManagers.Renderer.Camera.Y = 0; SystemManagers.Default = mManagers; FlatRedBallServices.AddManager(RenderingLibrary.SystemManagers.Default); RenderingLibrary.Graphics.Text.RenderBoundaryDefault = false; // FlatRedBall uses premult alpha. RenderingLibrary.Graphics.Renderer.NormalBlendState = Microsoft.Xna.Framework.Graphics.BlendState.AlphaBlend; var idb = new GumIdb(); // We don't want the UI to be at Z=0 because it will render // at the same Z along with FRB entities and environments so UI might // be hidden. The proper way to solve this is to use Layers, but // this shouldn't be creating new Layers, that's up to the user. // Let's make it have a positive Z so it draws in more things at once idb.Z = 10; // This could be called on a secondary thread, like if called by GlobalContent, so we // want this to happen on the primary thread: Action primaryThreadAction = () => { FlatRedBall.SpriteManager.AddDrawableBatch(idb); FlatRedBall.Screens.ScreenManager.PersistentDrawableBatches.Add(idb); }; var instruction = new FlatRedBall.Instructions.DelegateInstruction(primaryThreadAction); FlatRedBall.Instructions.InstructionManager.Add(instruction); } if (projectFileName == null) { throw new Exception("The GumIDB must be initialized with a valid (non-null) project file."); } string errors; mProjectFileName = projectFileName; if (FlatRedBall.IO.FileManager.IsRelative(mProjectFileName)) { mProjectFileName = FlatRedBall.IO.FileManager.RelativeDirectory + mProjectFileName; } // First let's set the relative directory to the file manager's relative directory so we can load // the file normally... ToolsUtilities.FileManager.RelativeDirectory = FlatRedBall.IO.FileManager.RelativeDirectory; GumLoadResult result; ObjectFinder.Self.GumProjectSave = GumProjectSave.Load(mProjectFileName, out result); #if DEBUG if(ObjectFinder.Self.GumProjectSave == null) { throw new Exception("Could not find Gum project at " + mProjectFileName); } if(!string.IsNullOrEmpty(result.ErrorMessage)) { throw new Exception(result.ErrorMessage); } if(result.MissingFiles.Count != 0) { throw new Exception("Missing files starting with " + result.MissingFiles[0]); } #endif // Now we can set the directory to Gum's root: ToolsUtilities.FileManager.RelativeDirectory = ToolsUtilities.FileManager.GetDirectory(mProjectFileName); // The Gum tool does a lot more init than this, but we're going to only do a subset //of initialization for performance // reasons: foreach (var item in ObjectFinder.Self.GumProjectSave.Screens) { // Only initialize using the default state if (item.DefaultState != null) { item.Initialize(item.DefaultState); } } foreach (var item in ObjectFinder.Self.GumProjectSave.Components) { // Only initialize using the default state if (item.DefaultState != null) { item.Initialize(item.DefaultState); } } foreach (var item in ObjectFinder.Self.GumProjectSave.StandardElements) { // Only initialize using the default state if (item.DefaultState != null) { item.Initialize(item.DefaultState); } //for atlased colored rectangles if (item.Name == "ColoredRectangle") RenderingLibrary.Graphics.SolidRectangle.AtlasedTextureName = "..\\Graphics\\Misc\\ColoredRectangle.png"; } StandardElementsManager.Self.Initialize(); }