Пример #1
0
        private void CreateSprites <SpriteType>(string contentManagerName, FlatRedBall.Scene scene, SceneSettingOptions options) where SpriteType : Sprite, new()
        {
            bool hasFlag = (options & SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids) == SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids;

            if (!hasFlag)
            {
                // Create the Sprites
                foreach (SpriteSave spriteSave in SpriteList)
                {
                    Sprite newSprite = null;

                    newSprite = spriteSave.ToSprite <SpriteType>(contentManagerName);

                    scene.Sprites.Add(newSprite);
                }

                // Attach the Sprites
                foreach (SpriteSave spriteSave in SpriteList)
                {
                    if (string.IsNullOrEmpty(spriteSave.Parent) == false)
                    {
                        scene.Sprites.FindByName(spriteSave.Name).AttachTo(
                            scene.Sprites.FindByName(spriteSave.Parent), false);
                    }
                }
            }
        }
Пример #2
0
        public static void SetFromScene(FlatRedBall.Scene scene, SpriteEditorScene spriteEditorScene)
        {
            foreach (Sprite sprite in scene.Sprites)
            {
                spriteEditorScene.SpriteList.Add(SpriteSave.FromSprite(sprite));
            }

            foreach (FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid in scene.SpriteGrids)
            {
                spriteEditorScene.SpriteGridList.Add(
                    FlatRedBall.Content.SpriteGrid.SpriteGridSave.FromSpriteGrid(spriteGrid));
            }

            foreach (FlatRedBall.ManagedSpriteGroups.SpriteFrame spriteFrame in scene.SpriteFrames)
            {
                spriteEditorScene.SpriteFrameSaveList.Add(
                    SpriteFrameSave.FromSpriteFrame(spriteFrame));
            }

            foreach (Text text in scene.Texts)
            {
                spriteEditorScene.TextSaveList.Add(
                    TextSave.FromText(text));
            }
        }
Пример #3
0
        public static SpriteEditorScene FromScene(FlatRedBall.Scene scene)
        {
            SpriteEditorScene spriteEditorScene = new SpriteEditorScene();

            SetFromScene(scene, spriteEditorScene);

            return(spriteEditorScene);
        }
Пример #4
0
        //public FlatRedBall.Scene ToScene(TextureAtlas textureAtlas)
        //{
        //    FlatRedBall.Scene scene = new FlatRedBall.Scene();

        //    SetScene<Sprite>(null, scene, SceneSettingOptions.None, textureAtlas);

        //    return scene;
        //}

        public FlatRedBall.Scene ToScene <SpriteType>
            (string contentManagerName) where SpriteType : Sprite, new()
        {
            FlatRedBall.Scene scene = new FlatRedBall.Scene();

            SetScene <SpriteType>(contentManagerName, scene);

            return(scene);
        }
Пример #5
0
        public List <InstructionSet> ToInstructionSetList(FlatRedBall.Scene scene)
        {
            List <InstructionSet> instructionSetList = new List <InstructionSet>(InstructionSetSaves.Count);

            foreach (InstructionSetSave instructionSetSave in InstructionSetSaves)
            {
                instructionSetList.Add(instructionSetSave.ToInstructionSet(scene));
            }

            return(instructionSetList);
        }
        public static SceneSave FromLayer(Layer layer)
        {
            FlatRedBall.Scene scene = new FlatRedBall.Scene();
            scene.Sprites.AddRange(layer.Sprites);
            scene.Texts.AddRange(layer.Texts);
            scene.Sprites.AddRange(layer.ZBufferedSprites);

            SceneSave toReturn = new SceneSave();
            SpriteEditorScene.SetFromScene( scene, toReturn);

            return toReturn;

        }
Пример #7
0
        public static SceneSave FromLayer(Layer layer)
        {
            FlatRedBall.Scene scene = new FlatRedBall.Scene();
            scene.Sprites.AddRange(layer.Sprites);
            scene.Texts.AddRange(layer.Texts);
            scene.Sprites.AddRange(layer.ZBufferedSprites);

            SceneSave toReturn = new SceneSave();

            SpriteEditorScene.SetFromScene(scene, toReturn);

            return(toReturn);
        }
Пример #8
0
        private void AddSpriteGridsToScene(string contentManagerName, FlatRedBall.Scene scene, SceneSettingOptions options)
        {
            foreach (SpriteGridSave spriteGridSave in SpriteGridList)
            {
                // for now just use the default camera and create a new Random - not sure if user ever needs
                // to specify the Random to use - perhaps for multiplayer games and SpriteGrids which are using AnimationChains
                FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid = spriteGridSave.ToSpriteGrid(
                    SpriteManager.Camera, contentManagerName);

                scene.SpriteGrids.Add(spriteGrid);
            }
            bool hasFlag = (options & SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids) == SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids;

            if (hasFlag)
            {
                Dictionary <int, FlatRedBall.ManagedSpriteGroups.SpriteGrid> spriteGrids = new Dictionary <int, FlatRedBall.ManagedSpriteGroups.SpriteGrid>();

                foreach (SpriteSave spriteSave in this.SpriteList)
                {
                    FloatRectangle floatRectangle = new FloatRectangle();
                    int            zAsInt         = MathFunctions.RoundToInt(spriteSave.Z);

                    if (spriteGrids.ContainsKey(zAsInt) == false)
                    {
                        var newGrid = new ManagedSpriteGroups.SpriteGrid(SpriteManager.Camera, ManagedSpriteGroups.SpriteGrid.Plane.XY, spriteSave.ToSprite(contentManagerName));
                        spriteGrids.Add(zAsInt, newGrid);
                        scene.SpriteGrids.Add(newGrid);
                    }

                    var spriteGrid = spriteGrids[zAsInt];

                    spriteGrid.XLeftBound   = System.Math.Min(spriteGrid.XLeftBound, spriteSave.X - spriteSave.ScaleX * 2);
                    spriteGrid.YBottomBound = System.Math.Min(spriteGrid.YBottomBound, spriteSave.Y - spriteSave.ScaleY * 2);

                    spriteGrid.XRightBound = System.Math.Max(spriteGrid.XRightBound, spriteSave.X + spriteSave.ScaleX * 2);
                    spriteGrid.YTopBound   = System.Math.Max(spriteGrid.YTopBound, spriteSave.Y + spriteSave.ScaleY * 2);

                    spriteGrid.PaintSprite(spriteSave.X, spriteSave.Y, spriteSave.Z,
                                           FlatRedBallServices.Load <Texture2D>(spriteSave.Texture));

                    floatRectangle.Left   = spriteSave.LeftTextureCoordinate;
                    floatRectangle.Right  = spriteSave.RightTextureCoordinate;
                    floatRectangle.Top    = spriteSave.TopTextureCoordinate;
                    floatRectangle.Bottom = spriteSave.BottomTextureCoordinate;


                    spriteGrid.PaintSpriteDisplayRegion(spriteSave.X, spriteSave.Y, spriteSave.Z,
                                                        ref floatRectangle);
                }
            }
        }
Пример #9
0
        public InstructionSet ToInstructionSet(FlatRedBall.Scene scene)
        {
            InstructionSet instructionSet = new InstructionSet();

            instructionSet.Name = this.Target;

            INameable nameable = null;


            foreach (KeyframeListSave keyframeList in Instructions)
            {
                KeyframeList keyframes = new KeyframeList();
                keyframes.Name = keyframeList.Name;

                instructionSet.Add(keyframes);
                foreach (KeyframeSave keyframe in keyframeList.SceneKeyframes)
                {
                    InstructionList list = new InstructionList();
                    list.Name = keyframe.Name;
                    keyframes.Add(list);

                    foreach (InstructionSave instructionSave in keyframe.InstructionSaves)
                    {
                        if (nameable == null || nameable.Name != instructionSave.TargetName)
                        {
                            // We don't have a nameable yet, or the current instruction is
                            // not modifying the one referenced by nameable.
                            nameable = scene.Sprites.FindByName(instructionSave.TargetName);

                            if (nameable == null)
                            {
                                nameable = scene.SpriteFrames.FindByName(instructionSave.TargetName);
                            }
                        }

                        if (nameable == null)
                        {
                            throw new NullReferenceException("Could not find an object of instance " + instructionSave.Type + " with the name " + instructionSave.TargetName);
                        }

                        list.Add(instructionSave.ToInstruction(nameable));
                    }
                }
            }

            return(instructionSet);
        }
Пример #10
0
		public static void UnloadStaticContent ()
		{
			if (LoadedContentManagers.Count != 0)
			{
				LoadedContentManagers.RemoveAt(0);
				mRegisteredUnloads.RemoveAt(0);
			}
			if (LoadedContentManagers.Count == 0)
			{
				if (AnimacionOrden != null)
				{
					AnimacionOrden= null;
				}
				if (SceneFile != null)
				{
					SceneFile.RemoveFromManagers(ContentManagerName != "Global");
					SceneFile= null;
				}
			}
		}
Пример #11
0
		public static void LoadStaticContent (string contentManagerName)
		{
			if (string.IsNullOrEmpty(contentManagerName))
			{
				throw new System.ArgumentException("contentManagerName cannot be empty or null");
			}
			ContentManagerName = contentManagerName;
			#if DEBUG
			if (contentManagerName == FlatRedBall.FlatRedBallServices.GlobalContentManager)
			{
				HasBeenLoadedWithGlobalContentManager = true;
			}
			else if (HasBeenLoadedWithGlobalContentManager)
			{
				throw new System.Exception("This type has been loaded with a Global content manager, then loaded with a non-global.  This can lead to a lot of bugs");
			}
			#endif
			bool registerUnload = false;
			if (LoadedContentManagers.Contains(contentManagerName) == false)
			{
				LoadedContentManagers.Add(contentManagerName);
				lock (mLockObject)
				{
					if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBall.FlatRedBallServices.GlobalContentManager)
					{
						FlatRedBall.FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("BarraSensorialStaticUnload", UnloadStaticContent);
						mRegisteredUnloads.Add(ContentManagerName);
					}
				}
				if (!FlatRedBall.FlatRedBallServices.IsLoaded<FlatRedBall.Graphics.Animation.AnimationChainList>(@"content/entities/barrasensorial/animacionorden.achx", ContentManagerName))
				{
					registerUnload = true;
				}
				AnimacionOrden = FlatRedBall.FlatRedBallServices.Load<FlatRedBall.Graphics.Animation.AnimationChainList>(@"content/entities/barrasensorial/animacionorden.achx", ContentManagerName);
				if (!FlatRedBall.FlatRedBallServices.IsLoaded<FlatRedBall.Scene>(@"content/entities/barrasensorial/scenefile.scnx", ContentManagerName))
				{
					registerUnload = true;
				}
				SceneFile = FlatRedBall.FlatRedBallServices.Load<FlatRedBall.Scene>(@"content/entities/barrasensorial/scenefile.scnx", ContentManagerName);
			}
			if (registerUnload && ContentManagerName != FlatRedBall.FlatRedBallServices.GlobalContentManager)
			{
				lock (mLockObject)
				{
					if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBall.FlatRedBallServices.GlobalContentManager)
					{
						FlatRedBall.FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("BarraSensorialStaticUnload", UnloadStaticContent);
						mRegisteredUnloads.Add(ContentManagerName);
					}
				}
			}
			CustomLoadStaticContent(contentManagerName);
		}
Пример #12
0
        public T LoadFromFile <T>(string assetName)
        {
            string extension = FileManager.GetExtension(assetName);

            if (FileManager.IsRelative(assetName))
            {
                // get the absolute path using the current relative directory
                assetName = FileManager.RelativeDirectory + assetName;
            }



            string fullNameWithType = assetName + typeof(T).Name;


            // get the dictionary by the contentManagerName.  If it doesn't exist, GetDisposableDictionaryByName
            // will create it.

            if (mDisposableDictionary.ContainsKey(fullNameWithType))
            {
#if PROFILE
                mHistory.Add(new ContentLoadHistory(
                                 TimeManager.CurrentTime, typeof(T).Name, fullNameWithType, ContentLoadDetail.Cached));
#endif

                return((T)mDisposableDictionary[fullNameWithType]);
            }
            else if (mNonDisposableDictionary.ContainsKey(fullNameWithType))
            {
                return((T)mNonDisposableDictionary[fullNameWithType]);
            }
            else
            {
#if PROFILE
                mHistory.Add(new ContentLoadHistory(
                                 TimeManager.CurrentTime,
                                 typeof(T).Name,
                                 fullNameWithType,
                                 ContentLoadDetail.HddFromFile));
#endif
#if DEBUG
                // The ThrowExceptionIfFileDoesntExist
                // call used to be done before the checks
                // in the dictionaries.  But whatever is held
                // in there may not really be a file so let's check
                // if the file exists after we check the dictionaries.
                FileManager.ThrowExceptionIfFileDoesntExist(assetName);
#endif

                IDisposable loadedAsset = null;

                if (typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Microsoft.Xna.Framework.Graphics.Texture2D))
                {
                    // for now we'll create it here, eventually have it in a dictionary:
                    loadedAsset = textureContentLoader.Load(assetName);
                }

                #region Scene

                else if (typeof(T) == typeof(FlatRedBall.Scene))
                {
                    FlatRedBall.Scene scene = FlatRedBall.Content.Scene.SceneSave.FromFile(assetName).ToScene(mName);

                    object sceneAsObject = scene;

                    lock (mNonDisposableDictionary)
                    {
                        if (!mNonDisposableDictionary.ContainsKey(fullNameWithType))
                        {
                            mNonDisposableDictionary.Add(fullNameWithType, scene);
                        }
                    }
                    return((T)sceneAsObject);
                }

                #endregion

                #region EmitterList

                else if (typeof(T) == typeof(EmitterList))
                {
                    EmitterList emitterList = EmitterSaveList.FromFile(assetName).ToEmitterList(mName);


                    mNonDisposableDictionary.Add(fullNameWithType, emitterList);


                    return((T)((object)emitterList));
                }

                #endregion

                #region Image
#if !MONOGAME
                else if (typeof(T) == typeof(Image))
                {
                    switch (extension.ToLowerInvariant())
                    {
                    case "gif":
                        Image image = Image.FromFile(assetName);
                        loadedAsset = image;
                        break;
                    }
                }
#endif
                #endregion

                #region BitmapList
#if !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !MONOGAME
                else if (typeof(T) == typeof(BitmapList))
                {
                    loadedAsset = BitmapList.FromFile(assetName);
                }
#endif

                #endregion

                #region NodeNetwork
                else if (typeof(T) == typeof(NodeNetwork))
                {
                    NodeNetwork nodeNetwork = NodeNetworkSave.FromFile(assetName).ToNodeNetwork();

                    mNonDisposableDictionary.Add(fullNameWithType, nodeNetwork);

                    return((T)((object)nodeNetwork));
                }
                #endregion

                #region ShapeCollection

                else if (typeof(T) == typeof(ShapeCollection))
                {
                    ShapeCollection shapeCollection =
                        ShapeCollectionSave.FromFile(assetName).ToShapeCollection();

                    mNonDisposableDictionary.Add(fullNameWithType, shapeCollection);

                    return((T)((object)shapeCollection));
                }
                #endregion

                #region PositionedObjectList<Polygon>

                else if (typeof(T) == typeof(PositionedObjectList <FlatRedBall.Math.Geometry.Polygon>))
                {
                    PositionedObjectList <FlatRedBall.Math.Geometry.Polygon> polygons =
                        PolygonSaveList.FromFile(assetName).ToPolygonList();
                    mNonDisposableDictionary.Add(fullNameWithType, polygons);
                    return((T)((object)polygons));
                }

                #endregion

                #region AnimationChainList

                else if (typeof(T) == typeof(AnimationChainList))
                {
                    if (assetName.EndsWith("gif"))
                    {
#if WINDOWS_8 || UWP || DESKTOP_GL
                        throw new NotImplementedException();
#else
                        AnimationChainList acl = new AnimationChainList();
                        acl.Add(FlatRedBall.Graphics.Animation.AnimationChain.FromGif(assetName, this.mName));
                        acl[0].ParentGifFileName = assetName;
                        loadedAsset = acl;
#endif
                    }
                    else
                    {
                        loadedAsset =
                            AnimationChainListSave.FromFile(assetName).ToAnimationChainList(mName);
                    }

                    mNonDisposableDictionary.Add(fullNameWithType, loadedAsset);
                }

                #endregion

                else if (typeof(T) == typeof(Song))
                {
                    var loader = new SongLoader();
                    return((T)(object)loader.Load(assetName));
                }
#if MONOGAME
                else if (typeof(T) == typeof(SoundEffect))
                {
                    T soundEffect;

                    if (assetName.StartsWith(@".\") || assetName.StartsWith(@"./"))
                    {
                        soundEffect = base.Load <T>(assetName.Substring(2));
                    }
                    else
                    {
                        soundEffect = base.Load <T>(assetName);
                    }

                    return(soundEffect);
                }
#endif

                #region RuntimeCsvRepresentation

#if !SILVERLIGHT
                else if (typeof(T) == typeof(RuntimeCsvRepresentation))
                {
#if XBOX360
                    throw new NotImplementedException("Can't load CSV from file.  Try instead to use the content pipeline.");
#else
                    return((T)((object)CsvFileManager.CsvDeserializeToRuntime(assetName)));
#endif
                }
#endif


                #endregion

                #region SplineList

                else if (typeof(T) == typeof(List <Spline>))
                {
                    List <Spline> splineList = SplineSaveList.FromFile(assetName).ToSplineList();
                    mNonDisposableDictionary.Add(fullNameWithType, splineList);
                    object asObject = splineList;

                    return((T)asObject);
                }

                else if (typeof(T) == typeof(SplineList))
                {
                    SplineList splineList = SplineSaveList.FromFile(assetName).ToSplineList();
                    mNonDisposableDictionary.Add(fullNameWithType, splineList);
                    object asObject = splineList;

                    return((T)asObject);
                }

                #endregion

                #region BitmapFont

                else if (typeof(T) == typeof(BitmapFont))
                {
                    // We used to assume the texture is named the same as the font file
                    // But now FRB understands the .fnt file and gets the PNG from the font file
                    //string pngFile = FileManager.RemoveExtension(assetName) + ".png";
                    string fntFile = FileManager.RemoveExtension(assetName) + ".fnt";

                    BitmapFont bitmapFont = new BitmapFont(fntFile, this.mName);

                    object bitmapFontAsObject = bitmapFont;

                    return((T)bitmapFontAsObject);
                }

                #endregion


                #region Text

                else if (typeof(T) == typeof(string))
                {
                    return((T)((object)FileManager.FromFileText(assetName)));
                }

                #endregion

                #region Catch mistakes

#if DEBUG
                else if (typeof(T) == typeof(Spline))
                {
                    throw new Exception("Cannot load Splines.  Try using the List<Spline> type instead.");
                }
                else if (typeof(T) == typeof(Emitter))
                {
                    throw new Exception("Cannot load Emitters.  Try using the EmitterList type instead.");
                }
#endif

                #endregion

                #region else, exception!

                else
                {
                    throw new NotImplementedException("Cannot load content of type " +
                                                      typeof(T).AssemblyQualifiedName + " from file.  If you are loading " +
                                                      "through the content pipeline be sure to remove the extension of the file " +
                                                      "name.");
                }

                #endregion

                if (loadedAsset != null)
                {
                    lock (mDisposableDictionary)
                    {
                        // Multiple threads could try to load this content simultaneously
                        if (!mDisposableDictionary.ContainsKey(fullNameWithType))
                        {
                            mDisposableDictionary.Add(fullNameWithType, loadedAsset);
                        }
                    }
                }

                return((T)loadedAsset);
            }
        }
Пример #13
0
        public void SetScene <SpriteType>(string contentManagerName, FlatRedBall.Scene scene, SceneSettingOptions options) where SpriteType : Sprite, new()
        {
            #region Set the FileManager.RelativeDirectory if necessary

            string oldRelativeDirectory = FileManager.RelativeDirectory;
            if (AssetsRelativeToSceneFile && mSceneDirectory != null)
            {
                FileManager.RelativeDirectory = mSceneDirectory;
            }

            #endregion

            CreateSprites <SpriteType>(contentManagerName, scene, options);

            AddSpriteGridsToScene(contentManagerName, scene, options);

            #region Create the SpriteFrames

            foreach (SpriteFrameSave spriteFrameSave in SpriteFrameSaveList)
            {
                FlatRedBall.ManagedSpriteGroups.SpriteFrame spriteFrame =
                    spriteFrameSave.ToSpriteFrame(contentManagerName);

                scene.SpriteFrames.Add(spriteFrame);
            }

            // TODO:  Attach the SpriteFrames

            #endregion

            #region Create the Texts
            foreach (TextSave textSave in TextSaveList)
            {
                Text text = textSave.ToText(contentManagerName);

                scene.Texts.Add(text);
            }
            #endregion

            #region Invert Z if necessary
#if FRB_MDX
            if (CoordinateSystem == FlatRedBall.Math.CoordinateSystem.RightHanded)
            {
                scene.InvertHandedness();
            }
#else
            if (CoordinateSystem == FlatRedBall.Math.CoordinateSystem.LeftHanded)
            {
                scene.InvertHandedness();
            }
#endif
            #endregion

            FileManager.RelativeDirectory = oldRelativeDirectory;

            // Set the name of the scene to the file name

            // Vic says - not sure why this is being made relative.
            // It should be like a Texture - storing its full path name so it
            // can be re-saved easily.
            //if (!(string.IsNullOrEmpty(mFileName)))  //asdffdsa
            //    scene.Name = FileManager.RemovePath(this.mFileName);
            scene.Name = this.mFileName;
        }
Пример #14
0
 public void SetScene <SpriteType>(string contentManagerName, FlatRedBall.Scene scene) where SpriteType : Sprite, new()
 {
     SetScene <SpriteType>(contentManagerName, scene, SceneSettingOptions.None);
 }
Пример #15
0
 public FlatRedBall.Scene ToScene(string contentManagerName)
 {
     FlatRedBall.Scene scene = ToScene <Sprite>(contentManagerName);
     return(scene);
 }