Esempio n. 1
0
        public static AnimationChainList AddAnimationChainList(string fileName)
        {
            AnimationChainList sameNamedList = null;

            foreach (AnimationChainList list in mReferencedAnimationChains)
            {
                if (list.Name == fileName)
                {
                    sameNamedList = list;
                    break;
                }
            }



            if (sameNamedList == null)
            {
                AnimationChainListSave animationChainListSave = AnimationChainListSave.FromFile(fileName);

                AnimationChainList list = animationChainListSave.ToAnimationChainList(SceneContentManager);

                mReferencedAnimationChains.Add(list);

                GuiData.ListWindow.Highlight(list);

                return(list);
            }
            else
            {
                // highlight the list with the same name

                GuiData.ListWindow.Highlight(sameNamedList);
                return(sameNamedList);
            }
        }
Esempio n. 2
0
 private static bool HasSameNamedAnimationChainList(AnimationChainList listToCompareAgainst)
 {
     foreach (AnimationChainList list in mReferencedAnimationChains)
     {
         if (list.Name == listToCompareAgainst.Name)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
 public void Add(AnimationChainList animationChainArray)
 {
     if (animationChainArray != null)
     {
         foreach (AnimationChain animationChain in animationChainArray)
         {
             foreach (AnimationFrame frame in animationChain)
             {
                 this.textureListBox.AddItemUnique(FileManager.MakeRelative(frame.Texture.Name, FileManager.RelativeDirectory), frame.Texture);
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Initialization logic which is execute only one time for this Entity (unless the Entity is pooled).
        /// This method is called when the Entity is added to managers. Entities which are instantiated but not
        /// added to managers will not have this method called.
        /// </summary>
        private void CustomInitialize()
        {
            bubbles = new List <Sprite>();

            currentScreen = FlatRedBall.Screens.ScreenManager.CurrentScreen;

            CurrentBubbleEmitterType = BubbleEmitterType.Geyser;

            SpawnOffset = 0f;

            textureForBubbles = (Texture2D)GetFile("anflogaSprites");
            animations        = (AnimationChainList)GetFile("AnimationChainListFile");
        }
Esempio n. 5
0
        //private void AddAnimationChainClick(Window callingWindow)
        //{
        //    FileWindow fileWindow = GuiManager.AddFileWindow();
        //    fileWindow.SetFileType("achx");
        //    fileWindow.SetToLoad();
        //    fileWindow.OkClick += AddAnimationChainOk;
        //}

        private void AddAnimationChainOk(Window callingWindow)
        {
            string fileName = ((FileWindow)callingWindow).Results[0];

            AnimationChainList acl = GameData.AddAnimationChainList(fileName);

            foreach (AnimationChain animationChain in acl)
            {
                foreach (AnimationFrame animationFrame in animationChain)
                {
                    WarnAboutNonPowerOfTwoTexture(animationFrame.Texture);
                }
            }
        }
        public virtual void SetAnimations(AnimationChainList animations)
        {
            if (this.MainSprite != null)
            {
                string chainToSet = GetChainToSet();

                if (!string.IsNullOrEmpty(chainToSet))
                {
                    bool differs = MainSprite.CurrentChainName == null ||
                                   MainSprite.CurrentChainName != chainToSet;

                    if (differs)
                    {
                        this.MainSprite.SetAnimationChain(animations[chainToSet]);
                    }
                }
            }
        }
Esempio n. 7
0
        //public void SetSprite(TextureAtlas textureAtlas, Sprite sprite)
        //{
        //    SetSprite("", sprite);

        //    if (!string.IsNullOrEmpty(this.Texture))
        //    {
        //        var entry = textureAtlas.GetEntryFor(this.Texture);

        //        if (entry != null)
        //        {
        //            float left;
        //            float right;
        //            float top;
        //            float bottom;


        //            entry.FullToReduced(sprite.LeftTextureCoordinate, sprite.RightTextureCoordinate,
        //                sprite.TopTextureCoordinate, sprite.BottomTextureCoordinate,
        //                out left, out right, out top, out bottom);

        //            sprite.LeftTextureCoordinate = left;
        //            sprite.RightTextureCoordinate = right;
        //            sprite.TopTextureCoordinate = top;
        //            sprite.BottomTextureCoordinate = bottom;

        //            sprite.Texture = textureAtlas.Texture;

        //        }
        //    }

        //    if (!string.IsNullOrEmpty(this.AnimationChainsFile))
        //    {

        //        if (string.IsNullOrEmpty(this.AnimationChainsFile) == false)
        //        {
        //            //AnimationChains = FlatRedBall.Content.AnimationChain.AnimationChainListSave.FromFile(AnimationChainsFile);
        //            AnimationChainListSave acls = AnimationChainListSave.FromFile(this.AnimationChainsFile);
        //            sprite.AnimationChains = acls.ToAnimationChainList(textureAtlas);
        //        }

        //        if (CurrentChain != -1)
        //        {
        //            // Now using the CurrentChainName property so it works with IAnimationChainAnimatable
        //            sprite.CurrentChainName = sprite.AnimationChains[CurrentChain].Name;
        //            //sprite.SetAnimationChain();
        //        }
        //    }


        //}

        internal static void SetRuntimeAnimationChain(string contentManagerName, IAnimationChainAnimatable sprite,
                                                      AnimationChainList animationChainListInstance, int currentChain, AnimationChainListSave animationChains,
                                                      string animationChainsFile
                                                      )
        {
            if (animationChainListInstance != null)
            {
                if (animationChainListInstance != null)
                {
                    sprite.AnimationChains = animationChainListInstance;;
                }

                if (currentChain != -1)
                {
                    // Now using the CurrentChainName property so it works with IAnimationChainAnimatable
                    sprite.CurrentChainName = sprite.AnimationChains[currentChain].Name;
                    //sprite.SetAnimationChain(sprite.AnimationChains[CurrentChain]);
                }
            }
            else if (animationChains != null || string.IsNullOrEmpty(animationChainsFile) == false)
            {
                if (animationChains != null && animationChains.FileName != null && animationChains.FileName != "")
                {
                    // load the AnimationChainArray here
                    //                    AnimationChains = new AnimationChainList(saveToSetFrom.animationChains.Name);
                    sprite.AnimationChains      = animationChains.ToAnimationChainList(contentManagerName);
                    sprite.AnimationChains.Name = FlatRedBall.IO.FileManager.Standardize(animationChains.FileName);
                }
                else if (string.IsNullOrEmpty(animationChainsFile) == false)
                {
                    //AnimationChains = FlatRedBall.Content.AnimationChain.AnimationChainListSave.FromFile(AnimationChainsFile);
                    sprite.AnimationChains = FlatRedBallServices.Load <AnimationChainList>(
                        animationChainsFile, contentManagerName);
                }

                if (currentChain != -1)
                {
                    // Now using the CurrentChainName property so it works with IAnimationChainAnimatable
                    sprite.CurrentChainName = sprite.AnimationChains[currentChain].Name;
                    //sprite.SetAnimationChain();
                }
            }
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
0
 public static void UnloadStaticContent()
 {
     IsStaticContentLoaded = false;
     mHasRegisteredUnload = false;
     if (AnimationChainListFile != null)
     {
         AnimationChainListFile= null;
     }
     if (EnemySpriteScene != null)
     {
         EnemySpriteScene.RemoveFromManagers(ContentManagerName != "Global");
         EnemySpriteScene= null;
     }
 }
Esempio n. 10
0
 public static void LoadStaticContent(string contentManagerName)
 {
     ContentManagerName = contentManagerName;
     #if DEBUG
     if (contentManagerName == FlatRedBallServices.GlobalContentManager)
     {
         HasBeenLoadedWithGlobalContentManager = true;
     }
     else if (HasBeenLoadedWithGlobalContentManager)
     {
         throw new 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
     if (IsStaticContentLoaded == false)
     {
         IsStaticContentLoaded = true;
         lock (mLockObject)
         {
             if (!mHasRegisteredUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager)
             {
                 FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("EnemyStaticUnload", UnloadStaticContent);
                 mHasRegisteredUnload = true;
             }
         }
         bool registerUnload = false;
         if (!FlatRedBallServices.IsLoaded<AnimationChainList>(@"content/entities/enemy/animationchainlistfile.achx", ContentManagerName))
         {
             registerUnload = true;
         }
         AnimationChainListFile = FlatRedBallServices.Load<AnimationChainList>(@"content/entities/enemy/animationchainlistfile.achx", ContentManagerName);
         if (!FlatRedBallServices.IsLoaded<Scene>(@"content/entities/enemy/enemyspritescene.scnx", ContentManagerName))
         {
             registerUnload = true;
         }
         EnemySpriteScene = FlatRedBallServices.Load<Scene>(@"content/entities/enemy/enemyspritescene.scnx", ContentManagerName);
         if (registerUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager)
         {
             lock (mLockObject)
             {
                 if (!mHasRegisteredUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager)
                 {
                     FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("EnemyStaticUnload", UnloadStaticContent);
                     mHasRegisteredUnload = true;
                 }
             }
         }
         CustomLoadStaticContent(contentManagerName);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Initialization logic which is execute only one time for this Entity (unless the Entity is pooled).
        /// This method is called when the Entity is added to managers. Entities which are instantiated but not
        /// added to managers will not have this method called.
        /// </summary>
        private void CustomInitialize()
        {
#if DEBUG
            if (DebugVariables.ShowDebugShapes)
            {
                SelfCollisionCircle.Visible = true;

                if (CircleInstance != null)
                {
                    CircleInstance.Visible = true;
                }
                if (AxisAlignedRectangleInstance != null)
                {
                    AxisAlignedRectangleInstance.Visible = true;
                }
            }
            else
#endif
            {
                SelfCollisionCircle.Visible = false;
                if (CircleInstance != null)
                {
                    CircleInstance.Visible = false;
                }
                if (AxisAlignedRectangleInstance != null)
                {
                    AxisAlignedRectangleInstance.Visible = false;
                }
            }

            if (!_startingShadowWidth.HasValue)
            {
                _startingShadowWidth  = ShadowSprite.Width;
                _startingShadowHeight = ShadowSprite.Height;
                _startingShadowAlpha  = ShadowSprite.Alpha;

                _spriteRelativeY         = SpriteInstance.Height / 2;
                spriteAnimationChainList = SpriteInstance.AnimationChains;

                PoisonedParticles.ScaleX    = SpriteInstance.Width / 2;
                PoisonedParticles.ScaleY    = SpriteInstance.Height / 2;
                PoisonedParticles.RelativeY = SpriteInstance.Height / 2;

                FrozenParticles.ScaleX    = SpriteInstance.Width / 2;
                FrozenParticles.ScaleY    = SpriteInstance.Height / 2;
                FrozenParticles.RelativeY = SpriteInstance.Height / 2;

                SmokeParticles.ScaleX    = SpriteInstance.Width / 2;
                SmokeParticles.ScaleY    = SpriteInstance.Height / 2;
                SmokeParticles.RelativeY = SpriteInstance.Height / 2;

                StunParticles.ScaleX    = SpriteInstance.Width / 2;
                StunParticles.ScaleY    = SpriteInstance.Height / 2;
                StunParticles.RelativeY = SpriteInstance.Height / 2;

                //var healthbarWidth = (SpriteInstance.AnimationChains[0][0].RightCoordinate -
                //                      SpriteInstance.AnimationChains[0][0].LeftCoordinate) * SpriteInstance.AnimationChains[0][0].Texture.Width;


                maxFrameHeight = GetMaxFrameHeight();
            }

            HealthBar.SetWidth(150f);

            if (drowningSound == null || drowningSound.IsDisposed)
            {
                drowningSound = DrowningSound.CreateInstance();
            }

            deathAnimationFinished = false;

            //HealthBar.AttachTo(SpriteInstance, true);
            HealthBar.RelativeY = HealthBar.Height + maxFrameHeight + Altitude;

            SpriteInstance.AnimationChains = spriteAnimationChainList;

            ShadowSprite.Visible   = true;
            ShadowSprite.RelativeY = 0;

            HasReachedGoal = false;

            HealthBar.Hide();

            HealthRemaining  = MaximumHealth;
            Altitude         = 0f;
            AltitudeVelocity = 0f;

            _poisonedDurationSeconds = 0;
            _frostDurationSeconds    = 0;
            _burnDurationSeconds     = 0;
            _stunnedDurationSeconds  = 0;

            EffectiveSpeed = BaseSpeed;

            CurrentStatusState = Status.Normal;

            SetBaseAttributes();

            SetGenetics();

            UpdateSpritesRelativeY();
        }
        public virtual void SetAnimations(AnimationChainList animations)
        {
            if(this.MainSprite != null)
            {
                string chainToSet = GetChainToSet();

                if(!string.IsNullOrEmpty(chainToSet))
                {
                    bool differs = MainSprite.CurrentChainName == null ||
                        MainSprite.CurrentChainName != chainToSet;

                    if(differs)
                    {
                        this.MainSprite.SetAnimationChain(animations[chainToSet]);
                    }
                }
            }
        }