Exemplo n.º 1
0
        public static SpriteFrame AddSpriteFrame(string texture)
        {
            #region Create the new SpriteFrame ( INCLUDES EARLY OUT )

            FlatRedBall.ManagedSpriteGroups.SpriteFrame spriteFrame = null;

            try
            {
                spriteFrame = GameData.CreateSpriteFrame(texture, "");
            }
            catch (InvalidDataException)
            {
                GuiManager.ShowMessageBox("Could not read " + texture + ".  SpriteFrame not created.", "Error Creating SpriteFrame");
                return(null);
            }

            #endregion

            SpriteEditorSettings.EditingSpriteFrames = true;


            GuiData.ToolsWindow.paintButton.Unpress();
            Cursor.ClickObject <FlatRedBall.ManagedSpriteGroups.SpriteFrame>(spriteFrame,
                                                                             EditorLogic.CurrentSpriteFrames, false, true);

            ListUnlistedAnimationChains();

            // The GUI reacts to selected objects, but we want the SpriteFrame to be resized immediately
            // after being added. To do this, force a selection:
            GuiData.SpriteFramePropertyGrid.SelectedObject =
                GameData.EditorLogic.CurrentSpriteFrames[0];
            // Then resize it.


            #region Prepare newly-created SpriteFrame

            // Vic says:  Why do we set it to .4999?
            // There are two parts to this answer:
            // 1.   The most common SpriteFrame TextureBorderWidth
            //      is 0.5.  Therefore, the SpriteEditor will set a
            //      value close to this for all newly-created SpriteFrames.
            // 2.   If we set a TextureBorderWidth of .5, the center Sprite will
            //      have 0 texture coordinate "width" and "height".  This is okay
            //      in XNA, MDX, and OGL, but not in Silverlight.  Silverlight requires
            //      there be some spacing between the texture coordiantes.
            spriteFrame.TextureBorderWidth = .4999f;

            GuiData.SpriteFramePropertyGrid.MakeCurrentSpriteFramePixelPerfect();


            #endregion



            return(spriteFrame);
        }
Exemplo n.º 2
0
        public ListBoxBase(GuiSkin guiSkin, Cursor cursor)
            : base(guiSkin, cursor)
        {
            mTexts = new PositionedObjectList<Text>();
            mHighlight = new Sprite();
            mHighlight.Z = AbsoluteWorldUnitZ - .0001f *
                FlatRedBall.Math.MathFunctions.ForwardVector3.Z;
            mScrollBar = new ScrollBar(guiSkin, cursor);
            AddWindow(mScrollBar);
            Initialize();
            mScrollBar.SpriteFrame.RelativeZ = -.01f * FlatRedBall.Math.MathFunctions.ForwardVector3.Z;


            // Even though the base constructor calls SetSkin, the mTexts are not
            // created yet so their font is never set.  This set the fonts once again.

            mHighlightBar = new SpriteFrame(
                guiSkin.WindowSkin.Texture, guiSkin.WindowSkin.BorderSides);
            SpriteManager.AddSpriteFrame(mHighlightBar);
            mHighlightBar.AttachTo(SpriteFrame, false);
            mHighlightBar.RelativeZ = -HighlightBarOffset * Math.MathFunctions.ForwardVector3.Z;
            mHighlightBar.Visible = false;

            SetSkin(guiSkin);
        }
Exemplo n.º 3
0
        public void SetFrom <T>(T spriteToCreateSaveFrom) where T : PositionedObject, IColorable, ICursorSelectable, IReadOnlyScalable, IAnimationChainAnimatable
        {
            X = spriteToCreateSaveFrom.X;
            Y = spriteToCreateSaveFrom.Y;

            // Coordinates will be inverted depending on the CoordinateSystem
            // when the scene is loaded.
            Z = spriteToCreateSaveFrom.Z;

            RotationX         = spriteToCreateSaveFrom.RotationX;
            RotationY         = spriteToCreateSaveFrom.RotationY;
            RotationZ         = spriteToCreateSaveFrom.RotationZ;
            RotationZVelocity = spriteToCreateSaveFrom.RotationZVelocity;

            ScaleX = spriteToCreateSaveFrom.ScaleX;
            ScaleY = spriteToCreateSaveFrom.ScaleY;

            if (spriteToCreateSaveFrom is IScalable)
            {
                ScaleXVelocity = ((IScalable)(spriteToCreateSaveFrom)).ScaleXVelocity;
                ScaleYVelocity = ((IScalable)(spriteToCreateSaveFrom)).ScaleYVelocity;
            }

            XVelocity = spriteToCreateSaveFrom.XVelocity;
            YVelocity = spriteToCreateSaveFrom.YVelocity;
            ZVelocity = spriteToCreateSaveFrom.ZVelocity;

            XAcceleration = spriteToCreateSaveFrom.XAcceleration;
            YAcceleration = spriteToCreateSaveFrom.YAcceleration;
            ZAcceleration = spriteToCreateSaveFrom.ZAcceleration;

            RelativeX = spriteToCreateSaveFrom.RelativeX;
            RelativeY = spriteToCreateSaveFrom.RelativeY;
            RelativeZ = spriteToCreateSaveFrom.RelativeZ;

            RelativeRotationX = spriteToCreateSaveFrom.RelativeRotationX;
            RelativeRotationY = spriteToCreateSaveFrom.RelativeRotationY;
            RelativeRotationZ = spriteToCreateSaveFrom.RelativeRotationZ;

            if (spriteToCreateSaveFrom.Name != null)
            {
                Name = spriteToCreateSaveFrom.Name;
            }
            Animate = spriteToCreateSaveFrom.Animate;

            if (spriteToCreateSaveFrom.CurrentChain == null)
            {
                CurrentChain = -1;
            }
            else
            {
                CurrentChain = spriteToCreateSaveFrom.CurrentChain.IndexInLoadedAchx;

                // It's possible that the chain is just a GIF.  In that case, it would have a -1 index
                // in the loaded Achx.  But we still want this thing to play, so we'll just assume an index
                // of 0
                if (CurrentChain == -1)
                {
                    CurrentChain = 0;
                }
            }

            if (spriteToCreateSaveFrom.AnimationChains != null)
            {
                if (string.IsNullOrEmpty(spriteToCreateSaveFrom.AnimationChains.Name) && spriteToCreateSaveFrom.AnimationChains.Count != 0)
                {
                    if (!string.IsNullOrEmpty(spriteToCreateSaveFrom.AnimationChains[0].ParentAchxFileName))
                    {
                        AnimationChainsFile = spriteToCreateSaveFrom.AnimationChains[0].ParentAchxFileName;
                    }
                    else
                    {
                        AnimationChainsFile = spriteToCreateSaveFrom.AnimationChains[0].ParentGifFileName;
                    }
                }
                else
                {
                    AnimationChainsFile = spriteToCreateSaveFrom.AnimationChains.Name;
                }
            }



            if (spriteToCreateSaveFrom.Parent != null)
            {
                Parent = spriteToCreateSaveFrom.Parent.Name;
            }

            BlendOperation =
                GraphicalEnumerations.BlendOperationToFlatRedBallMdxString(spriteToCreateSaveFrom.BlendOperation);

            Fade     = (1 - spriteToCreateSaveFrom.Alpha) * 255.0f;
            FadeRate = -spriteToCreateSaveFrom.AlphaRate * 255.0f;

            TintRed   = spriteToCreateSaveFrom.Red * 255.0f;
            TintGreen = spriteToCreateSaveFrom.Green * 255.0f;
            TintBlue  = spriteToCreateSaveFrom.Blue * 255.0f;

            TintRedRate   = spriteToCreateSaveFrom.RedRate * 255.0f;
            TintGreenRate = spriteToCreateSaveFrom.GreenRate * 255.0f;
            TintBlueRate  = spriteToCreateSaveFrom.BlueRate * 255.0f;

            ColorOperation =
                GraphicalEnumerations.ColorOperationToFlatRedBallMdxString(spriteToCreateSaveFrom.ColorOperation);

            if (spriteToCreateSaveFrom is Sprite)
            {
                Sprite asSprite = spriteToCreateSaveFrom as Sprite;
                Visible = asSprite.Visible;

                if (asSprite.Texture != null)
                {
                    // Vic says:  On November 11, 2009 I found an interesting
                    // bug.  I was working on the TileEditor which created a Scene
                    // that contained animated Sprites.  These Sprites used an AnimationChain
                    // that was created by loading a .GIF.  That means that each individual texture
                    // in the AnimationChain is not its own file, but rather a Texture created from the
                    // GIF.  This means that the Name of the Texture is not a valid Name.

                    // But this makes me think - if a Sprite has an AnimationChain and it's currently Animated,
                    // why do we even need to save off the Texture?  Instead, let's just not save it at all.  This
                    // will save a little bit of space and could also prevent some loading-related bugs.
                    if (string.IsNullOrEmpty(AnimationChainsFile) || (asSprite.CurrentChain == null || !asSprite.Animate))
                    {
                        Texture = asSprite.Texture.SourceFile();
                    }
                }

                ConstantPixelSize = asSprite.PixelSize;

                TopTextureCoordinate    = asSprite.TopTextureCoordinate;
                BottomTextureCoordinate = asSprite.BottomTextureCoordinate;
                LeftTextureCoordinate   = asSprite.LeftTextureCoordinate;
                RightTextureCoordinate  = asSprite.RightTextureCoordinate;

                FlipHorizontal = asSprite.FlipHorizontal;
                FlipVertical   = asSprite.FlipVertical;

                TextureAddressMode = asSprite.TextureAddressMode;

                // If the Sprite is not part of the ZBufferedSprites, then it's ordered.
                Ordered = !asSprite.ListsBelongingTo.Contains(SpriteManager.mZBufferedSprites);
            }
            else if (spriteToCreateSaveFrom is FlatRedBall.ManagedSpriteGroups.SpriteFrame)
            {
                FlatRedBall.ManagedSpriteGroups.SpriteFrame asSpriteFrame = spriteToCreateSaveFrom as
                                                                            FlatRedBall.ManagedSpriteGroups.SpriteFrame;

                Visible = asSpriteFrame.Visible;

                Texture = asSpriteFrame.Texture.Name;
            }
        }
Exemplo n.º 4
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;
        }