Exemplo n.º 1
0
    /// <summary>
    /// Constructs the pane with all the sprites.
    /// </summary>
    public DemoSpriteSimple()
    {
        // Create the basics
        sprites = new SpriteList();
        viewport = new SpriteViewport(sprites);
        viewport.BackgroundColor = new Color(0, 0, 50);

        // Load in a basic sprite
        IDrawable drawable = DemoSprites.PixbufFactory.Create("blue-sphere");
        sprite = new DrawableSprite(drawable);
        sprite.X = 10;
        sprite.Y = 10;
        sprite.Width = sprite.Height = 64;
        sprites.Add(sprite);

        // Load the second sprite
        drawable = DemoSprites.PixbufFactory.Create("green-sphere");
        sprite2 = new DrawableSprite(drawable);
        sprite2.X = 10;
        sprite2.Y = 300;
        sprite2.Width = sprite2.Height = 128;
        sprites.Add(sprite2);

        // Load in just a red sphere
        drawable = DemoSprites.TilesetFactory.Create("red-sphere");
        ISprite s = new DrawableSprite(drawable);
        s.X = 400;
        s.Y = 10;
        s.Width = s.Height = 256;
        sprites.Add(s);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Constructs the pane with all the sprites.
    /// </summary>
    public DemoSpriteSimple()
    {
        // Create the basics
        sprites  = new SpriteList();
        viewport = new SpriteViewport(sprites);
        viewport.BackgroundColor = new Color(0, 0, 50);

        // Load in a basic sprite
        IDrawable drawable = DemoSprites.PixbufFactory.Create("blue-sphere");

        sprite       = new DrawableSprite(drawable);
        sprite.X     = 10;
        sprite.Y     = 10;
        sprite.Width = sprite.Height = 64;
        sprites.Add(sprite);

        // Load the second sprite
        drawable      = DemoSprites.PixbufFactory.Create("green-sphere");
        sprite2       = new DrawableSprite(drawable);
        sprite2.X     = 10;
        sprite2.Y     = 300;
        sprite2.Width = sprite2.Height = 128;
        sprites.Add(sprite2);

        // Load in just a red sphere
        drawable = DemoSprites.TilesetFactory.Create("red-sphere");
        ISprite s = new DrawableSprite(drawable);

        s.X     = 400;
        s.Y     = 10;
        s.Width = s.Height = 256;
        sprites.Add(s);
    }
Exemplo n.º 3
0
        /// <summary>
        /// Triggered when a token is added to the board.
        /// </summary>
        public void OnTokenAdded(
            object sender,
            TokenArgs args)
        {
            // Create a new token
            TokenSprite     ts = new TokenSprite(this, args.Token);
            ContainerSprite ms = new ContainerSprite(ts);

            sprites.Add(ms);

            // Move the sprite over
            ms.RateX = 100;
            ms.RateY = 100;
            ms.X     = ms.DesiredX = TileSize * args.Token.Column;
            ms.Y     = ms.DesiredY = TileSize * args.Token.Row;
            ms.Y    -= TileSize;

            // Check the state
            if (Game.State == GameState.InProgress &&
                args.Token.Type == TokenType.Flooded && args.Token.Value == ' ')
            {
                // Flooded tokens show up in place, but with a special
                // animation
                ms.Y = ms.DesiredY;
                ms.X = ms.DesiredX;
                ts.DrawableState.Frame = TokenSprite.FloodedStart;
            }

            // We need to sort the list again
            sortNext = true;
            QueueDraw();
            log.Debug(
                "TokenAdded: {0} sprits {1} state {2}", ts, sprites.Count, Game.State);
        }
Exemplo n.º 4
0
        public EditorHandles()
        {
            spritesAlreadyChanged = new PositionedObjectList <PositionedObject>();

            Layer axisLayer = SpriteManager.AddLayer();

            origin = SpriteManager.AddSprite(
                FlatRedBallServices.Load <Texture2D>("Content/EditorHandles/Origin.png", GuiManager.InternalGuiContentManagerName), axisLayer);
            origin.Name = "OriginOfEditAxes";
            editAxisSpriteArray.Add(origin);

            xAxis = SpriteManager.AddSprite(
                FlatRedBallServices.Load <Texture2D>("Content/EditorHandles/MoveX.png", GuiManager.InternalGuiContentManagerName), axisLayer);

            editAxisSpriteArray.Add(xAxis);

            yAxis = SpriteManager.AddSprite(
                FlatRedBallServices.Load <Texture2D>("Content/EditorHandles/MoveY.png", GuiManager.InternalGuiContentManagerName), axisLayer);
            editAxisSpriteArray.Add(yAxis);

            zAxis = SpriteManager.AddSprite(
                FlatRedBallServices.Load <Texture2D>("Content/EditorHandles/MoveZ.png", GuiManager.InternalGuiContentManagerName), axisLayer);
            editAxisSpriteArray.Add(zAxis);

            xScale = SpriteManager.AddSprite(
                FlatRedBallServices.Load <Texture2D>("Content/EditorHandles/ScaleX.png", GuiManager.InternalGuiContentManagerName), axisLayer);
            editAxisSpriteArray.Add(xScale);

            yScale = SpriteManager.AddSprite(
                FlatRedBallServices.Load <Texture2D>("Content/EditorHandles/ScaleY.png", GuiManager.InternalGuiContentManagerName), axisLayer);
            editAxisSpriteArray.Add(yScale);

            xRot = SpriteManager.AddSprite(
                FlatRedBallServices.Load <Texture2D>("Content/EditorHandles/RotateX.png", GuiManager.InternalGuiContentManagerName), axisLayer);

            editAxisSpriteArray.Add(xRot);

            yRot = SpriteManager.AddSprite(
                FlatRedBallServices.Load <Texture2D>("Content/EditorHandles/RotateY.png", GuiManager.InternalGuiContentManagerName), axisLayer);



            editAxisSpriteArray.Add(yRot);

            xAxis.AttachTo(origin, true);
            yAxis.AttachTo(origin, true);
            zAxis.AttachTo(origin, true);
            xScale.AttachTo(origin, true);
            yScale.AttachTo(origin, true);
            xRot.AttachTo(origin, true);
            yRot.AttachTo(origin, true);

            Scale = 1;

            editAxisSpriteArray.Visible = false;
            mCursorOverAxis             = false;
            mVisible = false;
        }
Exemplo n.º 5
0
        public float Fire()
        {
            if (CooldownCounter != Cooldown)
            {
                return(0f);
            }

            SoundEffectInstance?.Play();

            var middleLength = Length - Start.Texture.Width - End.Texture.Width;

            MiddleLength = middleLength;

            var tempRect = Start.Rectangle;

            tempRect.Width  = Start.Texture.Width;
            tempRect.Height = Start.Texture.Height;
            Start.Rectangle = tempRect;

            var tempRect2 = Middle.Rectangle;

            tempRect2.Width  = Convert.ToInt16(middleLength);
            Middle.Rectangle = tempRect2;

            var tempRect3 = End.Rectangle;

            tempRect3.Width  = End.Texture.Width;
            tempRect3.Height = End.Texture.Height;
            End.Rectangle    = tempRect3;

            Start.Position = Position;
            Start.Rotation = Rotation;

            var tempPos = Middle.Position;

            tempPos.X       = (int)Math.Cos(Rotation) * Start.Texture.Width + Position.X;
            tempPos.Y       = (int)Math.Sin(Rotation) * Start.Texture.Width + Position.Y;
            Middle.Position = tempPos;

            Middle.Rotation = Rotation;

            var tempPos2 = End.Position;

            tempPos.X    = (int)Math.Cos(Rotation) * Middle.Rectangle.Width + Middle.Position.X;
            tempPos.Y    = (int)Math.Sin(Rotation) * Middle.Rectangle.Width + Middle.Position.Y;
            End.Position = tempPos2;
            End.Rotation = Rotation;

            SpriteList.Add(Start);
            SpriteList.Add(Middle);
            SpriteList.Add(End);

            CooldownCounter  = 0f;
            _durationCounter = Duration;
            IsFiring         = true;
            TurnRate         = BaseTurnrate * 0.1f;

            return(EnergyCost);
        }
Exemplo n.º 6
0
    /// <summary>
    /// Constructs the pane with all the sprites.
    /// </summary>
    public DemoSpriteMoving()
    {
        // Create the basics
        sprites  = new SpriteList();
        viewport = new SpriteViewport(sprites);
        viewport.BackgroundColor = new Color(0, 0, 50);

        // Load in the static green sphere
        IDrawable      drawable = DemoSprites.TilesetFactory.Create("red-sphere");
        DrawableSprite sprite1  = new DrawableSprite(drawable);

        sprite = new MovingSprite(sprite1);
        sprite.StoppedMoving += OnStoppedMoving;
        sprite.Height         = sprite.Width = 64;
        sprite.X              = sprite.Y = 10;
        sprites.Add(sprite);

        // Create the target
        drawable      = DemoSprites.TilesetFactory.Create("green-sphere");
        target        = new DrawableSprite(drawable);
        target.Height = target.Width = 32;
        sprites.Add(target);

        // Load in the static green sphere
        drawable = DemoSprites.TilesetFactory.Create("red-sphere2");
        DrawableSprite sprite2a = new DrawableSprite(drawable);

        sprite2        = new MovingSprite(sprite2a);
        sprite2.Height = sprite2.Width = 64;
        sprite2.X      = sprite2.Y = 10;
        sprites.Add(sprite2);

        // Create the target
        drawable       = DemoSprites.TilesetFactory.Create("green-sphere");
        target2        = new DrawableSprite(drawable);
        target2.Height = target2.Width = 32;
        sprites.Add(target2);
        sprite2.DesiredX = Entropy.Next(0, viewport.Width - sprite.Width);
        sprite2.DesiredY = Entropy.Next(0, viewport.Height - sprite.Height);
        target2.X        = sprite2.DesiredX + 16;
        target2.Y        = sprite2.DesiredY + 16;

        // Start our timer
        Timeout.Add(1000, OnNewLocation2);
    }
Exemplo n.º 7
0
    /// <summary>
    /// Constructs the pane with all the sprites.
    /// </summary>
    public DemoSpriteMoving()
    {
        // Create the basics
        sprites = new SpriteList();
        viewport = new SpriteViewport(sprites);
        viewport.BackgroundColor = new Color(0, 0, 50);

        // Load in the static green sphere
        IDrawable drawable = DemoSprites.TilesetFactory.Create("red-sphere");
        DrawableSprite sprite1 = new DrawableSprite(drawable);
        sprite = new MovingSprite(sprite1);
        sprite.StoppedMoving += OnStoppedMoving;
        sprite.Height = sprite.Width = 64;
        sprite.X = sprite.Y = 10;
        sprites.Add(sprite);

        // Create the target
        drawable = DemoSprites.TilesetFactory.Create("green-sphere");
        target = new DrawableSprite(drawable);
        target.Height = target.Width = 32;
        sprites.Add(target);

        // Load in the static green sphere
        drawable = DemoSprites.TilesetFactory.Create("red-sphere2");
        DrawableSprite sprite2a = new DrawableSprite(drawable);
        sprite2 = new MovingSprite(sprite2a);
        sprite2.Height = sprite2.Width = 64;
        sprite2.X = sprite2.Y = 10;
        sprites.Add(sprite2);

        // Create the target
        drawable = DemoSprites.TilesetFactory.Create("green-sphere");
        target2 = new DrawableSprite(drawable);
        target2.Height = target2.Width = 32;
        sprites.Add(target2);
        sprite2.DesiredX = Entropy.Next(0, viewport.Width - sprite.Width);
        sprite2.DesiredY = Entropy.Next(0, viewport.Height - sprite.Height);
        target2.X = sprite2.DesiredX + 16;
        target2.Y = sprite2.DesiredY + 16;

        // Start our timer
        Timeout.Add(1000, OnNewLocation2);
    }
Exemplo n.º 8
0
    /// <summary>
    /// Constructs the pane with all the sprites.
    /// </summary>
    public DemoSpriteTileset()
    {
        // Create the basics
        sprites  = new SpriteList();
        viewport = new SpriteViewport(sprites);
        viewport.BackgroundColor = new Color(0, 0, 50);

        // Load in the static green sphere
        IDrawable      drawable = DemoSprites.TilesetFactory.Create("green-sphere");
        DrawableSprite sprite   = new DrawableSprite(drawable);

        sprite.Height = sprite.Width = 64;
        sprite.X      = sprite.Y = 10;
        sprites.Add(sprite);

        // Load in the animated red sphere
        int rows = 6;
        int cols = 6;

        for (int i = 0; i < cols; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                if (i == j)
                {
                    drawable = DemoSprites.TilesetFactory.Create("red-sphere2");
                }
                else
                {
                    drawable = DemoSprites.TilesetFactory.Create("red-sphere");
                }

                sprite        = new DrawableSprite(drawable);
                sprite.Height = sprite.Width = 64;
                sprite.X      = 100 + i * 100;
                sprite.Y      = 10 + j * 100;
                sprite.Randomize();
                sprites.Add(sprite);
            }
        }
    }
Exemplo n.º 9
0
        void CustomInitialize()
        {
            for (int i = 0; i < 3; i++)
            {
                var sprite = new Sprite();
                SpriteList.Add(sprite);
                SpriteManager.AddToLayer(sprite, LayerInstance);
            }

            SpriteList[0].Y = 0;
            SpriteList[1].Y = -10;
            SpriteList[2].Y = 10;
        }
Exemplo n.º 10
0
 public PartyGUIMember(SpritedBattlePokemon pkmn, SpriteList sprites)
 {
     _usePartyPkmn = false;
     _battlePkmn   = pkmn;
     _color        = GetColor();
     _mini         = new Sprite()
     {
         Image    = pkmn.Mini,
         Y        = Sprite_BounceDefY,
         Callback = Sprite_Bounce,
         Data     = new Sprite_BounceData()
     };
     sprites.Add(_mini);
     _background = new Image((UI.Program.RenderWidth / 2) - (UI.Program.RenderWidth / 20), (UI.Program.RenderHeight / 4) - (UI.Program.RenderHeight / 20));
     UpdateBackground();
 }
Exemplo n.º 11
0
 public PartyGUIMember(PartyPokemon pkmn, SpriteList sprites)
 {
     _usePartyPkmn = true;
     _partyPkmn    = pkmn;
     _color        = GetColor();
     _mini         = new Sprite()
     {
         Image    = PokemonImageUtils.GetMini(pkmn.Species, pkmn.Form, pkmn.Gender, pkmn.Shiny, pkmn.IsEgg),
         Y        = Sprite_BounceDefY,
         Callback = Sprite_Bounce,
         Data     = new Sprite_BounceData()
     };
     sprites.Add(_mini);
     _background = new Image((UI.Program.RenderWidth / 2) - (UI.Program.RenderWidth / 20), (UI.Program.RenderHeight / 4) - (UI.Program.RenderHeight / 20));
     UpdateBackground();
 }
Exemplo n.º 12
0
    /// <summary>
    /// Constructs the pane with all the sprites.
    /// </summary>
    public DemoSpriteBounce()
    {
        // Create the basics
        sprites = new SpriteList();
        viewport = new SpriteViewport(sprites);
        viewport.BackgroundColor = new Color(0, 0, 50);

        // Load in a basic drawable
        IDrawable drawable = DemoSprites.PixbufFactory.Create("green-sphere");

        // Create the sprites
        for (int i = 0; i < 20; i++)
        {
            Bounce sprite = new Bounce(drawable);
            sprite.Width = sprite.Height = 64;
            sprites.Add(sprite);
        }
    }
Exemplo n.º 13
0
    /// <summary>
    /// Constructs the pane with all the sprites.
    /// </summary>
    public DemoSpriteBounce()
    {
        // Create the basics
        sprites  = new SpriteList();
        viewport = new SpriteViewport(sprites);
        viewport.BackgroundColor = new Color(0, 0, 50);

        // Load in a basic drawable
        IDrawable drawable = DemoSprites.PixbufFactory.Create("green-sphere");

        // Create the sprites
        for (int i = 0; i < 20; i++)
        {
            Bounce sprite = new Bounce(drawable);
            sprite.Width = sprite.Height = 64;
            sprites.Add(sprite);
        }
    }
Exemplo n.º 14
0
    /// <summary>
    /// Constructs the pane with all the sprites.
    /// </summary>
    public DemoSpriteTileset()
    {
        // Create the basics
        sprites = new SpriteList();
        viewport = new SpriteViewport(sprites);
        viewport.BackgroundColor = new Color(0, 0, 50);

        // Load in the static green sphere
        IDrawable drawable = DemoSprites.TilesetFactory.Create("green-sphere");
        DrawableSprite sprite = new DrawableSprite(drawable);
        sprite.Height = sprite.Width = 64;
        sprite.X = sprite.Y = 10;
        sprites.Add(sprite);

        // Load in the animated red sphere
        int rows = 6;
        int cols = 6;

        for (int i = 0; i < cols; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                if (i == j)
                {
                    drawable = DemoSprites.TilesetFactory.Create("red-sphere2");
                }
                else
                {
                    drawable = DemoSprites.TilesetFactory.Create("red-sphere");
                }

                sprite = new DrawableSprite(drawable);
                sprite.Height = sprite.Width = 64;
                sprite.X = 100 + i * 100;
                sprite.Y = 10 + j * 100;
                sprite.Randomize();
                sprites.Add(sprite);
            }
        }
    }
Exemplo n.º 15
0
        /// <summary>
        /// Removes all Sprites and SpriteFrames referencing the argument Texture2D.  Sets all
        /// SpriteGrid TextureLocationArray references to the argument texture back to the base texture or removes the
        /// SpriteGrid if the base texture is the same as the argument.
        /// </summary>
        /// <param name="texture">The texture being removed.</param>
        #endregion
        public static void RemoveObjectsReferencing(Texture2D texture)
        {
            SpriteList spritesToRemove = new SpriteList();

            // will need to store all removed objects for undo
            foreach (Sprite s in mScene.Sprites)
            {
                if (s.Texture == texture)
                {
                    spritesToRemove.Add(s);
                }
            }
            DeleteSprites(spritesToRemove, false);

            for (int i = GameData.Scene.SpriteGrids.Count - 1; i > -1; i--)
            {
                if (GameData.Scene.SpriteGrids[i].Blueprint.Texture == texture)
                {
                    /* The blueprint texture matches the texture being removed.  Remove the
                     * SpriteGrid from the SE.
                     */
                    sesgMan.DeleteGrid(GameData.Scene.SpriteGrids[i]);
                }
                else
                {
                    GameData.Scene.SpriteGrids[i].ReplaceTexture(
                        texture,
                        GameData.Scene.SpriteGrids[i].Blueprint.Texture);
                }
            }


            for (int i = Scene.SpriteFrames.Count - 1; i > -1; i--)
            {
                if (Scene.SpriteFrames[i].Texture == texture)
                {
                    DeleteSpriteFrame(Scene.SpriteFrames[i], true);
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Generate an image for each font character
        /// </summary>
        /// <param name="list">input list of characters</param>
        /// <param name="font">the font to use</param>
        /// <returns>maximum dimensions among the rendered chars</returns>
        static Size CreateCharSprites(char[] list, Font font)
        {
            Size dim = FindMaxDim(list, font);

            Log.Debug("dim = [" + dim.Width + "x" + dim.Height + "]");

            for (int ci = 0; ci < list.Length; ci++)
            {
                char c = list[ci];
                //Log.Debug("Spriting "+c);
                var img = RenderCharSprite(c, font, dim);
                //#if DEBUG
                //using (var fs = File.OpenWrite("sprite-"+((int)c)+".png")) {
                //	img.SaveAsPng(fs);
                //}
                //#endif
                SpriteList.Add(img);
                double avg = Helpers.FindAverageGray(img);
                //Log.Debug("Spriting avg = "+avg);
            }
            return(dim);
        }
Exemplo n.º 17
0
        internal void Add(Sprite sprite)
        {
            if (sprite.mOrdered)
            {
#if DEBUG
                if (mSprites.Contains(sprite))
                {
                    throw new InvalidOperationException("Can't add the Sprite to this layer because it's already added");
                }
#endif
                mSprites.Add(sprite);
            }
            else
            {
#if DEBUG
                if (mZBufferedSprites.Contains(sprite))
                {
                    throw new InvalidOperationException("Can't add the Sprite to this layer because it's already added");
                }
#endif
                mZBufferedSprites.Add(sprite);
            }
        }
Exemplo n.º 18
0
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Title           = "Select data.win to open",
                CheckPathExists = true,
                CheckFileExists = true,
                Filter          = "Game Maker .win files|*.win",
                FilterIndex     = 0,
                Multiselect     = false
            };

            Stream fs = null;

            if (dialog.ShowDialog() == true)
            {
                fs = dialog.OpenFile();
            }
            else
            {
                return;
            }

            using (BinaryReader br = new BinaryReader(fs))
            {
                GEN8.Load(br);
                //GEN8 g = GEN8.Instance;
                //Console.WriteLine(string.Format("Filename: {0}\nName: {1}\nDisplayName: {2}\nSteamAppID: {3}", g.Filename, g.Name, g.DisplayName, g.SteamAppID));

                TXTR.Load(br);
                SPRT.Load(br);
                BGND.Load(br);
            }

            List <Sprite> sprites = SPRT.Instance.Contents;

            SpriteList.Clear();

            for (int i = 0; i < sprites.Count; i++)
            {
                Sprite spr = sprites[i];
                if (spr.GetFrames().Length < 1)
                {
                    continue;
                }

                AssetItem ai = new AssetItem(spr.Name, spr);
                SpriteList.Add(ai);
            }

            List <Background> backgrounds = BGND.Instance.Contents;

            BackgroundList.Clear();

            for (int i = 0; i < backgrounds.Count; i++)
            {
                AssetItem ai = new AssetItem(backgrounds[i].Name, backgrounds[i]);
                BackgroundList.Add(ai);
            }

            GEN8 g = GEN8.Instance;

            GameInfoText.Inlines.Clear();
            GameInfoText.Inlines.Add(new Bold(new Run("Name: ")));
            GameInfoText.Inlines.Add(new Run(g.DisplayName + "\n"));
            GameInfoText.Inlines.Add(new Bold(new Run("Development Name: ")));
            GameInfoText.Inlines.Add(new Run(g.Name + "\n"));
            GameInfoText.Inlines.Add(new Bold(new Run("Version: ")));
            GameInfoText.Inlines.Add(new Run(string.Format("{0}.{1}\n", g.MajorVersion, g.MinorVersion)));
            GameInfoText.Inlines.Add(new Bold(new Run("Build Version: ")));
            GameInfoText.Inlines.Add(new Run(g.BuildVersion + "\n"));
            GameInfoText.Inlines.Add(new Bold(new Run("Release Version: ")));
            GameInfoText.Inlines.Add(new Run(g.ReleaseVersion + "\n"));
        }
Exemplo n.º 19
0
 /// <summary>
 /// Adds a sprite to a batch to be rendered to the output image.
 /// </summary>
 /// <param name="sprite">The graphic sprite.</param>
 /// <param name="X">The location of the sprite (in 8x8 tiles).</param>
 /// <param name="Y">The location of the sprite (int 8x8 tiles).</param>
 /// <param name="paletteIndex">The count of the paletteIndex to render with.</param>
 public void AddSprite(SpriteDefinition sprite, int X, int Y, byte paletteIndex)
 {
     _sprites.Add(new SpriteListItem(sprite, paletteIndex, new Point(X, Y)));
 }
Exemplo n.º 20
0
        public void Render(SpriteList spriteList, Vector2 area, HAlignment hAlign, VAlignment vAlign, int maxCharacters = -1)
        {
            if (overflowMode == TextOverflowMode.Minify)
            {
                FitTextInsideArea(area);
            }
            List <int> lines;
            float      totalHeight;
            float      longestLineWidth;

            PrepareWordsAndLines(area.X, area.Y, out lines, out totalHeight, out longestLineWidth);
            // Draw all lines.
            int   b = 0;
            float y = 0;
            int   c = 0;

            foreach (int count in lines)
            {
                // Calculate height and width of line in pixels.
                float maxHeight  = 0;
                float totalWidth = 0;
                for (int j = 0; j < count; j++)
                {
                    var word  = fittedWords[b + j];
                    var style = Styles[word.Style];
                    maxHeight = Math.Max(maxHeight, ScaleSize(style.Size + style.SpaceAfter));
                    if (word.IsTagBegin)
                    {
                        maxHeight = Math.Max(maxHeight, ScaleSize(style.ImageSize.Y + style.SpaceAfter));
                    }
                    totalWidth += word.Width;
                }
                // Calculate offset for horizontal alignment.
                var offset = new Vector2();
                if (hAlign == HAlignment.Right)
                {
                    offset.X = area.X - totalWidth;
                }
                else if (hAlign == HAlignment.Center)
                {
                    offset.X = ((area.X - totalWidth) * 0.5f).Round();
                }
                // Calculate offset for vertical alignment.
                if (vAlign == VAlignment.Bottom)
                {
                    offset.Y = area.Y - totalHeight;
                }
                else if (vAlign == VAlignment.Center)
                {
                    offset.Y = ((area.Y - totalHeight) * 0.5f).Round();
                }
                // Draw string.
                for (int j = 0; j < count; j++)
                {
                    var       word     = fittedWords[b + j];
                    var       t        = texts[word.TextIndex];
                    TextStyle style    = Styles[word.Style];
                    Vector2   position = new Vector2(word.X, y) + offset;
                    if (IsBullet(word) && style.ImageTexture != null)
                    {
                        if (maxCharacters >= 0 && c >= maxCharacters)
                        {
                            break;
                        }
                        var sz = style.ImageSize * scaleFactor;
                        spriteList.Add(
                            style.ImageTexture, Color4.White, position + new Vector2(0, (maxHeight - sz.Y) * 0.5f),
                            sz, Vector2.Zero, Vector2.One, tag: word.Style);
                        position.X += sz.X;
                        c++;
                    }
                    var yOffset = new Vector2(0, (maxHeight - ScaleSize(style.Size)) * 0.5f);
                    var font    = style.Font;
                    if (style.CastShadow)
                    {
                        for (int k = 0; k < (style.Bold ? 2 : 1); k++)
                        {
                            Renderer.DrawTextLine(
                                font, position + style.ShadowOffset + yOffset, t, style.ShadowColor, ScaleSize(style.Size),
                                word.Start, word.Length, style.LetterSpacing, spriteList, tag: word.Style);
                        }
                    }
                    int wordLength = word.Length;
                    if (maxCharacters >= 0)
                    {
                        if (c >= maxCharacters)
                        {
                            break;
                        }
                        wordLength = wordLength.Min(maxCharacters - c);
                    }
                    for (int k = 0; k < (style.Bold ? 2 : 1); k++)
                    {
                        Renderer.DrawTextLine(
                            font, position + yOffset, t, style.TextColor, ScaleSize(style.Size),
                            word.Start, wordLength, style.LetterSpacing, spriteList, tag: word.Style);
                    }
                    c += wordLength;
                }
                // Draw overlays
                for (int j = 0; j < count; j++)
                {
                    var       word  = fittedWords[b + j];
                    TextStyle style = Styles[word.Style];
                    if (style.ImageUsage == TextStyle.ImageUsageEnum.Overlay)
                    {
                        int k = j + 1;
                        for (; k < count; k++)
                        {
                            if (fittedWords[b + k].IsTagBegin)
                            {
                                break;
                            }
                        }
                        k -= 1;
                        Vector2 lt      = new Vector2(fittedWords[b + j].X, y) + offset;
                        Vector2 rb      = new Vector2(fittedWords[b + k].X + fittedWords[b + k].Width, y) + offset;
                        float   yOffset = (maxHeight - ScaleSize(style.ImageSize.Y)) * 0.5f;
                        spriteList.Add(style.ImageTexture, Color4.White, lt + new Vector2(0, yOffset),
                                       rb - lt + new Vector2(0, style.ImageSize.Y),
                                       Vector2.Zero, Vector2.One, tag: word.Style);
                        j = k;
                    }
                }
                y += maxHeight;
                b += count;
            }
        }
Exemplo n.º 21
0
        /*
         *  This is the LoadContent class for MonoGame.
         * This class does a number of different things.
         * Primarily, it loads the SQLite/Data files, and then organizes that data.
         * It also set's up the graphics display.
         */
        protected override void LoadContent()
        {
            graphics.IsFullScreen = true;
            graphics.PreferredBackBufferHeight = 1080;
            graphics.PreferredBackBufferWidth  = 1920;
            this.IsMouseVisible = true;
            graphics.ApplyChanges();
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            baseFont = Content.Load <SpriteFont>("BaseText");

            using (SQLiteConnection conn = new SQLiteConnection("Data Source=greyflare.db"))
            {
                conn.Open();
                SQLiteCommand cmd = conn.CreateCommand();

                try
                {
                    cmd.CommandText = "SELECT 1 FROM Skills";
                    cmd.ExecuteScalar();
                }
                catch (Exception ex)
                {
                    cmd.CommandText = "CREATE TABLE Skills (id INTEGER PRIMARY KEY AUTOINCREMENT, skillname LONGTEXT, lvl INTEGER, xp INTEGER)";
                    cmd.ExecuteNonQuery();
                }
                try
                {
                    cmd.CommandText = "SELECT 1 FROM Quests";
                    cmd.ExecuteScalar();
                }
                catch (Exception ex)
                {
                    cmd.CommandText = "CREATE TABLE Quests (id INTEGER PRIMARY KEY AUTOINCREMENT, questname LONGTEXT, questtext LONGTEXT, reqquests LONGTEXT, reqskills LONGTEXT, reqitems LONGTEXT, rwd LONGTEXT, iscomp LONGTEXT)";
                    cmd.ExecuteNonQuery();
                }
            }

            string[] filelist = Directory.GetFiles(@"C:\Users\Alex\source\repos\GreyFlare\GreyFlare\Content\PlayerSprites", "*.png");
            foreach (string s in filelist)
            {
                string sz     = s.Substring(s.LastIndexOf("\\")).Replace("\\", "");
                string TName  = sz.Split('.')[0];
                string TNameB = TName.Replace("_", "");
                SpriteList.Add(TNameB, Content.Load <Texture2D>(@"PlayerSprites\" + TName));
            }
            filelist = Directory.GetFiles(@"C:\Users\Alex\source\repos\FlareEdit\FlareEdit\Content", "*.png");
            foreach (string s in filelist)
            {
                string sz     = s.Substring(s.LastIndexOf("\\")).Replace("\\", "");
                string TName  = sz.Split('.')[0];
                string TNameB = TName.Replace("_", "");
                TextureList.Add(TNameB, Content.Load <Texture2D>(TName));
            }
            string[] fileobjlist = Directory.GetFiles(@"C:\Users\Alex\source\repos\FlareEdit\FlareEdit\Content\WO", "*.png");
            foreach (string s in fileobjlist)
            {
                string sz     = s.Substring(s.LastIndexOf("\\")).Replace("\\", "");
                string TName  = sz.Split('.')[0];
                string TNameB = TName.Replace("_", "");
                ObjTextureList.Add(TNameB, Content.Load <Texture2D>(@"WO\" + TName));
            }
            string[] npcfile = Directory.GetFiles(@"C:\Users\Alex\source\repos\GreyFlare\GreyFlare\Content\NPC", "*.png");
            foreach (string s in npcfile)
            {
                string sz     = s.Substring(s.LastIndexOf("\\")).Replace("\\", "");
                string TName  = sz.Split('.')[0];
                string TNameB = TName.Replace("_", "");
                NpcSpriteList.Add(TNameB, Content.Load <Texture2D>(@"NPC\" + TName));
            }
            LoadQuests();
            LoadMap();
            LoadNPC();

            using (SQLiteConnection conn = new SQLiteConnection("Data Source=GreyPlayer.db"))
            {
                conn.Open();
                SQLiteCommand cmd = conn.CreateCommand();
                object        rn  = null;
                try
                {
                    cmd.CommandText = "SELECT * FROM Players";
                    rn = cmd.ExecuteScalar().ToString();
                } catch (Exception ex)
                {
                }
                if (rn != null)
                {
                    cmd.CommandText = "SELECT * FROM Players";
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            Player pA = new Player(rdr[1].ToString(), SpriteList[rdr[2].ToString()], SpriteList[rdr[3].ToString()], float.Parse(rdr[4].ToString()), float.Parse(rdr[5].ToString()), Int32.Parse(rdr[6].ToString()));

                            PlayerList.Add(pA);
                        }
                    }
                }
            }

            if (PlayerList.Count < 1)
            {
                using (SQLiteConnection conn = new SQLiteConnection("Data Source=GreyPlayer.db"))
                {
                    conn.Open();
                    try
                    {
                        SQLiteCommand cmd = conn.CreateCommand();
                        cmd.CommandText = "CREATE TABLE Players (id INTEGER PRIMARY KEY AUTOINCREMENT, name LONGTEXT, head LONGTEXT, body LONGTEXT, x LONGTEXT, y LONGTEXT, currency INTEGER)";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "CREATE TABLE Player_Quests (id INTEGER PRIMARY KEY AUTOINCREMENT, questname LONGTEXT, iscomp LONGTEXT)";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "CREATE TABLE Player_Inv (id INTEGER PRIMARY KEY AUTOINCREMENT, item LONGTEXT)";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "CREATE TABLE Player_Skills (id INTEGER PRIMARY KEY AUTOINCREMENT, skill LONGTEXT, xp LONGTEXT, lvl LONGTEXT)";
                        cmd.ExecuteNonQuery();

                        cmd.CommandText = "INSERT INTO Players (name, head, body, x, y, currency) VALUES (@n, @h, @b, @x, @y, @c)";
                        cmd.Parameters.AddWithValue("@n", "Test");
                        cmd.Parameters.AddWithValue("@h", "LeatherHead");
                        cmd.Parameters.AddWithValue("@b", "MageBody1");
                        cmd.Parameters.AddWithValue("@x", "0");
                        cmd.Parameters.AddWithValue("@y", "0");
                        cmd.Parameters.AddWithValue("@c", "25");
                        cmd.ExecuteNonQuery();
                        PlayerList.Add(new Player("Test", SpriteList["LeatherHead"], SpriteList["MageBody1"], 10, 10, 25));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
            p    = PlayerList[0];
            CamX = PlayerList[0].PlayerX;
            CamY = PlayerList[0].PlayerY;
        }
Exemplo n.º 22
0
        private void InitUI()
        {
            var listlable = new CCLabel("佣兵列表", StringManager.GetText("GlobalFont"), 14)
            {
                Position = new CCPoint(100, 420),
                Color    = CCColor3B.White
            };

            FollowerList = PlayerObject.Instance.Self.AllFollower;
            Page         = (FollowerList.Followers.Count + 8) / 9;

            AddChild(listlable, 100);

            foreach (var obj in FollowerList.Followers)
            {
                var fs = new FollowerSprite(obj, true);
                this.AddChild(fs);
                SpriteList.Add(fs);
            }

            var listview = new CozySampleListView()
            {
                ContentSize = new CCSize(600, 330),
                HasBorder   = true,
                Position    = new CCPoint(100, 60)
            };

            this.AddChild(listview);

            InnerList = new CozySampleListView[3];
            for (int i = 0; i < 3; ++i)
            {
                InnerList[i] = new CozySampleListView()
                {
                    ContentSize = new CCSize(200, 330),
                    Orientation = Public.Controls.Enum.ControlOrientation.Vertical,
                };
                listview.AddItem(new CozySampleListViewItem(InnerList[i]));
            }

            int fight = PlayerObject.Instance.Self.FightFollower.Followers.Count;

            AllFollower = new CCLabel("总数" + fight + "/" + FollowerList.Followers.Count, StringManager.GetText("GlobalFont"), 14)
            {
                Position = new CCPoint(92, 37),
                Color    = CCColor3B.White,
            };
            AddChild(AllFollower, 100);

            PageNumber = new CCLabel((CurPage + 1) + "/" + Page, StringManager.GetText("GlobalFont"), 14)
            {
                Position = new CCPoint(389, 37),
                Color    = CCColor3B.White
            };
            AddChild(PageNumber, 100);

            ShowDetail = new FollowerDetailSprite()
            {
                Position    = new CCPoint(100, 100),
                AnchorPoint = CCPoint.Zero,
                Visible     = false,
                FightStatusChangeCallback = new Action <Follower>(OnStatusChange),
            };
            this.AddChild(ShowDetail, 201);

            LastPageButton = new CozySampleButton(473, 17, 78, 36)
            {
                Text     = "上一页",
                FontSize = 14,
                OnClick  = () => PrevPage(),
            };
            NextPageButton = new CozySampleButton(585, 17, 78, 36)
            {
                Text     = "下一页",
                FontSize = 14,
                OnClick  = () => NextPage(),
            };
            AddChild(NextPageButton, 100);
            AddChild(LastPageButton, 100);
            uidispatcher.Add(NextPageButton);
            uidispatcher.Add(LastPageButton);

            var backButton = new CozySampleButton(650, 17, 78, 36)
            {
                Text     = "返回",
                FontSize = 14,
                OnClick  = () =>
                {
                    AppDelegate.SharedWindow.DefaultDirector.PopScene();
                }
            };

            AddChild(backButton, 100);
            uidispatcher.Add(backButton);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Emits particles as specified by the Emitter class
        /// </summary>
        /// <remarks>
        /// This method initiates one emission of particles.  The number of particles emitted
        /// depends on the numberPerEmission variable.  This method does not consider emission timing, and the time
        /// is not recorded for emission timing.
        ///
        /// The argument SpriteList stores all Sprites which were emitted
        /// during the call.  The Sprites are added regularly, rather than in a one way relationship.  This enables
        /// modification of emitted particles after the method ends.  null can be passed as an argument
        /// if specific action is not needed for emitted particles.  Particles are automatically created
        /// through the SpriteManager as Particle Sprites.
        /// <seealso cref="FlatRedBall.Graphics.Particle.Emitter.TimedEmit()"/>
        /// <seealso cref="FlatRedBall.SpriteManager.AddParticleSprite"/>
        ///
        /// </remarks>
        /// <param name="spriteList">The list of Sprites (which can be null) to add all Sprites created
        /// by this call.</param>
        public void Emit(SpriteList spriteList)
        {
            UpdateDependencies(TimeManager.CurrentTime);
            if (mBoundedEmission && mEmissionBoundary != null)
            {
                float cameraDistance;
#if FRB_MDX
                cameraDistance = -SpriteManager.Camera.Z;
#else
                cameraDistance = SpriteManager.Camera.Z;
#endif
                if (cameraDistance < 0)
                {
                    return;                     // skip check bounding if camera is behind z = 0 plain
                }
                cameraRectangle.Position = new Vector3(SpriteManager.Camera.X, SpriteManager.Camera.Y, 0);
                cameraRectangle.ScaleY   = SpriteManager.Camera.YEdge * cameraDistance / 100;
                cameraRectangle.ScaleX   = cameraRectangle.ScaleY * SpriteManager.Camera.AspectRatio;
                if (!mEmissionBoundary.CollideAgainst(cameraRectangle))
                {
                    return;
                }
            }

            #region loop through creating NumberPerEmission particles

            for (int i = 0; i < NumberPerEmission; i++)
            {
                #region Create the tempParticle (the Sprite instance)

                Sprite tempParticle = null;

                if (mEmitsAutomaticallyUpdatedSprites)
                {
                    tempParticle = SpriteManager.AddParticleSprite(EmissionSettings.Texture);
                }
                else
                {
                    tempParticle = SpriteManager.AddManualParticleSprite(EmissionSettings.Texture);
                }

                #endregion

                #region Removal events
                switch ((int)this.RemovalEvent)
                {
                case (int)RemovalEventType.Alpha0:
                    SpriteManager.mRemoveWhenAlphaIs0.Add(tempParticle);
                    break;

                case (int)RemovalEventType.OutOfScreen:
                    tempParticle.CustomBehavior += FlatRedBall.Utilities.CustomBehaviorFunctions.RemoveWhenOutsideOfScreen;

                    break;

                case (int)RemovalEventType.Timed:

#if FRB_MDX
                    tempParticle.Instructions.Add(
                        new FlatRedBall.Instructions.StaticMethodInstruction(
                            sSpriteManagerRemoveSprite,
                            new object[] { tempParticle },
                            TimeManager.CurrentTime + (mSecondsLasting * mSecondsModifier)));
#else
                    // August 28, 2012
                    // The following code
                    // was added during Sentient
                    // to fix some issue with particles
                    // not being removed when paused.  Not
                    // sure what the problem was, but this bug
                    // causes particles to be immediately removed
                    // if they are spawned when the game is paused -
                    // at least most of the time.  The reason is because
                    // when the game is paused, then the CurrentTime is 0
                    // which means the particle is told to be removed at a
                    // time very close to 0.  Usually this is in the past so
                    // any particles spawned when the game is paused will immediately
                    // be removed.  Not sure what the intent was here...
                    //double isEnginePaused = 1.0;
                    //if( InstructionManager.IsEnginePaused )
                    //{
                    //    isEnginePaused = 0.0;
                    //}
                    SpriteManager.mTimedRemovalList.InsertSorted(tempParticle,
                                                                 TimeManager.CurrentTime + (mSecondsLasting * mSecondsModifier));
#endif



                    //                        SpriteManager.RemoveSpriteInstruction(tempParticle, TimeManager.CurrentTimeAfterXSeconds(SecondsLasting));
                    break;
                }
                #endregion

                if (tempParticle == null)
                {
                    // do something here with the SpriteManager.  Probably call some event
                }

                #region Sprite-specific stuff (not stuff that other types can do, which are handled below)
                // manually inlined for speed:

                //tempParticle.LeftTextureCoordinate = 0;
                tempParticle.mVertices[0].TextureCoordinate.X = 0;
                tempParticle.mVertices[3].TextureCoordinate.X = 0;

                //tempParticle.RightTextureCoordinate = 1;
                tempParticle.mVertices[1].TextureCoordinate.X = 1;
                tempParticle.mVertices[2].TextureCoordinate.X = 1;

                //tempParticle.TopTextureCoordinate = 0;
                tempParticle.mVertices[0].TextureCoordinate.Y = 0;
                tempParticle.mVertices[1].TextureCoordinate.Y = 0;

                // Use the setter here to call UpdateScale
                tempParticle.BottomTextureCoordinate = 1;

                // Justin Johnson, 04/2015 - retiring particle blueprints
                // Use the animation chain from the
                // emission settings instead of setting
                // the animation based on chains and chain name
                if (EmissionSettings.AnimationChains != null)
                {
                    tempParticle.AnimationChains = EmissionSettings.AnimationChains;
                }
                tempParticle.SetAnimationChain(EmissionSettings.AnimationChain);
                tempParticle.CurrentFrameIndex = 0;
                tempParticle.Animate           = EmissionSettings.Animate;

                //tempParticle.AnimationChains = mParticleBlueprint.AnimationChains;
                //if (!string.IsNullOrEmpty(mParticleBlueprint.CurrentChainName ))
                //{

                //    tempParticle.CurrentChainName = mParticleBlueprint.CurrentChainName;
                //    tempParticle.Animate = mParticleBlueprint.Animate;
                //    tempParticle.CurrentFrameIndex = 0;
                //    //                return;
                //}

                if (EmissionSettings.Billboarded)
                {
                    SpriteManager.Camera.AddSpriteToBillboard(tempParticle);
                }


                if (spriteList != null)
                {
                    spriteList.Add(tempParticle);
                }

                if (mLayerToEmitOn != null)
                {
                    SpriteManager.AddToLayer(tempParticle, mLayerToEmitOn);
                }
                #endregion


                SetPositionedObjectProperties(tempParticle);
                //SetScalableProperties(tempParticle);
                SetSpriteScaleProperties(tempParticle);


                SetColorableProperties(tempParticle);


                // this sets the CustomBehavior to null so be sure not to call this after
                // setting any CustomBehavior.
                // Update on March 7, 2011:  CustomBehaviors are falling
                // out of style.  Particles no longer support them.
                // tempParticle.CopyCustomBehaviorFrom(mParticleBlueprint);
            }

            #endregion
        }
Exemplo n.º 24
0
        public void CopyCurrentObjects(Window callingWindow)
        {
            if ((GameData.EditorLogic.CurrentSprites.Count != 0) ||
                (GameData.EditorLogic.CurrentSpriteFrames.Count != 0) ||
                (GameData.EditorLogic.CurrentPositionedModels.Count != 0) ||
                (GameData.EditorLogic.CurrentTexts.Count != 0))
            {
                int instructionNum = 0;

                #region Copy Sprites

                if (SpriteEditorSettings.EditingSprites)
                {

                    // remove the in-screen markers and axes so they don't get touched by the copying
                    GameData.EditorLogic.EditAxes.CurrentObject = null;

                    Sprite topSpriteAdded = null;
                    AttachableList<Sprite> oldestParents = AttachableList<Sprite>.GetTopParents<Sprite, Sprite>(GameData.EditorLogic.CurrentSprites);
                    SpriteList addedSprites = new SpriteList();

                    // The appendedNumbers variable is used for improving performance when copying large groups.  When a Sprite
                    // is copied, it is given a number at the end of its name or if there is already a number present,
                    // it is incremented.  However, copying large groups can result in a lot of string checking which
                    // can hurt performance.
                    // Consider copying 100 Sprites with the same texture.  Their names will likely be redball1, redball2,
                    // redball3, ... redball100.  Let's say redball1 gets copied first.  The SpriteEditor increments the
                    // number at the end to redball2, then checks to see if there is already a Sprite with that name.  If
                    // there is, it increments to redball3 and so on.  This must be conducted on average 10,000 times and each
                    // iteration requires string copying, concatenation, and parsing for integers.  To cut this down, the 
                    // appendedNumbers variable associates a given name (in this case redball) with the last integer appended
                    // to that particular name.  Therefore, when the first Sprite is created, it will loop through 1 - 100 and
                    // eventually end up at redball101.  It will then associate the number 101 with the name redball.  The next
                    // Sprite (named redball2) will know to begin at redball101.  This increases the performance of
                    // copying large groups from O(n^2) to O(n).

                    Dictionary<string, int> appendedNumbers = new Dictionary<string, int>();

                    foreach (Sprite s in oldestParents)
                    {
                        if (s is ISpriteEditorObject)
                        {
                            if (GuiData.ToolsWindow.groupHierarchyControlButton.IsPressed)
                            {
                                topSpriteAdded =
                                    GameData.copySpriteHierarchy(
                                        s, s.Parent as Sprite, GameData.EditorProperties.PixelSize, addedSprites, appendedNumbers);
                            }
                            else
                            {
                                topSpriteAdded =
                                    GameData.copySpriteHierarchy(
                                        s.TopParent as Sprite, null, GameData.EditorProperties.PixelSize, addedSprites, appendedNumbers);
                            }
                        }
                        SpriteList tempSpriteArray = new SpriteList();
                        topSpriteAdded.GetAllDescendantsOneWay(tempSpriteArray);
                        tempSpriteArray.Add(topSpriteAdded);

                    }

                    GameData.EditorLogic.EditAxes.CurrentObject =
                        GameData.EditorLogic.CurrentSprites[0];

                    GameData.Cursor.ClickSprite(null);
                    foreach (Sprite s in AttachableList<Sprite>.GetTopParents<Sprite, Sprite>(addedSprites))
                    {
                        // the 2nd true forces selection of all Sprites
                        GameData.Cursor.ClickObject<Sprite>(s, GameData.EditorLogic.CurrentSprites, true, true);
                    }

                    GameData.Cursor.VerifyAndUpdateGrabbedAgainstCurrent();
                }
                #endregion

                #region Copy SpriteGrids
                else if (SpriteEditorSettings.EditingSpriteGrids)
                {
                    SpriteGrid sg = SESpriteGridManager.CurrentSpriteGrid.Clone();


                    FlatRedBall.Utilities.StringFunctions.MakeNameUnique<SpriteGrid>(sg, GameData.Scene.SpriteGrids);


                    this.sesgMan.PopulateAndAddGridToEngine(sg, GameData.EditorLogic.CurrentSprites[0]);

                    sg.RefreshPaint();
                }
                #endregion

                #region Copy SpriteFrames
                else if (SpriteEditorSettings.EditingSpriteFrames)
                {
                    GameData.EditorLogic.EditAxes.CurrentObject = null;

                    AttachableList<SpriteFrame> oldestParents =
                        AttachableList<SpriteFrame>.GetTopParents<SpriteFrame, SpriteFrame>(GameData.EditorLogic.CurrentSpriteFrames);
                    foreach (SpriteFrame sf in oldestParents)
                    {
                        SpriteFrame topSpriteFrameAdded = GameData.CopySpriteFrameHierarchy(sf, null, GameData.EditorProperties.PixelSize);
                        GameData.Cursor.ClickSpriteFrame(topSpriteFrameAdded);
                    }
                }
                #endregion

                #region Copy Models

                else if (SpriteEditorSettings.EditingModels)
                {
                    GameData.EditorLogic.EditAxes.CurrentObject = null;

                    AttachableList<PositionedModel> oldestParents =
                        AttachableList<PositionedModel>.GetTopParents<PositionedModel, PositionedModel>(GameData.EditorLogic.CurrentPositionedModels);
                    foreach (PositionedModel model in oldestParents)
                    {

                        PositionedModel topSpriteFrameAdded =
                            GameData.CopyModelHierarchy(model, null, GameData.EditorProperties.PixelSize);

                        //         GameData.cursor.ClickSpriteFrame(topSpriteFrameAdded);
                    }
                }

                #endregion

                #region Copy Texts

                else if (SpriteEditorSettings.EditingTexts)
                {
                    GameData.EditorLogic.EditAxes.CurrentObject = null;

                    AttachableList<Text> oldestParents =
                        AttachableList<Text>.GetTopParents<Text, Text>(GameData.EditorLogic.CurrentTexts);
                    foreach (Text text in oldestParents)
                    {

                        Text topText =
                            GameData.CopyTextHierarchy(text, null, GameData.EditorProperties.PixelSize);

                        //         GameData.cursor.ClickSpriteFrame(topSpriteFrameAdded);
                    }

                }

                #endregion

            }
        }
Exemplo n.º 25
0
        private void SplitSpriteClick(Window callingWindow)
        {
            if (ObjectDisplaying != null)
            {
                float textureWidth = ObjectDisplaying.RightTextureCoordinate - ObjectDisplaying.LeftTextureCoordinate;
                int   wide         = (int)(.5 +
                                           Math.Ceiling(textureWidth));

                float textureHeight = ObjectDisplaying.BottomTextureCoordinate - ObjectDisplaying.TopTextureCoordinate;
                int   height        = (int)(.5 +
                                            Math.Ceiling(textureHeight));

                float scaleXOverTextureWidth = ObjectDisplaying.ScaleX / textureWidth;

                float scaleYOverTextureHeight = ObjectDisplaying.ScaleY / textureHeight;

                float currentLeftTextureCoordinate   = ObjectDisplaying.LeftTextureCoordinate;
                float currentRightTextureCoordinate  = Math.Min(ObjectDisplaying.RightTextureCoordinate, 1);
                float currentTopTextureCoordinate    = ObjectDisplaying.TopTextureCoordinate;
                float currentBottomTextureCoordinate = Math.Min(ObjectDisplaying.BottomTextureCoordinate, 1);
                float maxRightTextureCoordinate      = ObjectDisplaying.RightTextureCoordinate;
                float maxBottomTextureCoordinate     = ObjectDisplaying.BottomTextureCoordinate;

                float startLeft = ObjectDisplaying.X - ObjectDisplaying.ScaleX;
                float startTop  = ObjectDisplaying.Y + ObjectDisplaying.ScaleY;

                for (int x = 0; x < wide; x++)
                {
                    currentTopTextureCoordinate    = ObjectDisplaying.TopTextureCoordinate;
                    currentBottomTextureCoordinate = Math.Min(ObjectDisplaying.BottomTextureCoordinate, 1);

                    for (int y = 0; y < height; y++)
                    {
                        Sprite newSprite = null;
                        if (x == 0 && y == 0)
                        {
                            newSprite = ObjectDisplaying;
                        }
                        else
                        {
                            newSprite = ObjectDisplaying.Clone();
                            SpriteManager.AddSprite(newSprite);
                            mSpriteList.Add(newSprite);

                            FlatRedBall.Utilities.StringFunctions.MakeNameUnique <Sprite>(
                                newSprite, mSpriteList);
                        }

                        newSprite.LeftTextureCoordinate   = currentLeftTextureCoordinate;
                        newSprite.RightTextureCoordinate  = currentRightTextureCoordinate;
                        newSprite.TopTextureCoordinate    = currentTopTextureCoordinate;
                        newSprite.BottomTextureCoordinate = currentBottomTextureCoordinate;

                        newSprite.ScaleX = scaleXOverTextureWidth * (newSprite.RightTextureCoordinate - newSprite.LeftTextureCoordinate);
                        newSprite.ScaleY = scaleYOverTextureHeight * (newSprite.BottomTextureCoordinate - newSprite.TopTextureCoordinate);

                        newSprite.X = startLeft +
                                      2 * scaleXOverTextureWidth * (newSprite.LeftTextureCoordinate - ObjectDisplaying.LeftTextureCoordinate) +
                                      newSprite.ScaleX;

                        newSprite.Y = startTop -
                                      2 * scaleYOverTextureHeight * (newSprite.TopTextureCoordinate - ObjectDisplaying.TopTextureCoordinate) -
                                      newSprite.ScaleY;

                        currentTopTextureCoordinate    = currentBottomTextureCoordinate;
                        currentBottomTextureCoordinate = currentTopTextureCoordinate + 1;

                        // Since FSB only allows texture coordinates between 0 and 1, let's make sure that we're not exceeding that.
                        if (newSprite.LeftTextureCoordinate >= 1)
                        {
                            int leftInt = (int)newSprite.LeftTextureCoordinate;
                            newSprite.LeftTextureCoordinate  -= leftInt;
                            newSprite.RightTextureCoordinate -= leftInt;
                        }

                        if (newSprite.TopTextureCoordinate >= 1)
                        {
                            int topInt = (int)newSprite.TopTextureCoordinate;
                            newSprite.TopTextureCoordinate    -= topInt;
                            newSprite.BottomTextureCoordinate -= topInt;
                        }
                    }

                    currentLeftTextureCoordinate  = currentRightTextureCoordinate;
                    currentRightTextureCoordinate = currentLeftTextureCoordinate + 1;
                }

                //// let's just add 3 new Sprites.
                //Sprite sprite = SpriteManager.AddSprite("redball.bmp");
                //mSpriteList.Add(sprite);
                //sprite.XVelocity = 1;
                //sprite.Name = "test";
            }
        }
Exemplo n.º 26
0
        public void CopyCurrentObjects(Window callingWindow)
        {
            if ((GameData.EditorLogic.CurrentSprites.Count != 0) ||
                (GameData.EditorLogic.CurrentSpriteFrames.Count != 0) ||
                (GameData.EditorLogic.CurrentPositionedModels.Count != 0) ||
                (GameData.EditorLogic.CurrentTexts.Count != 0))
            {
                int instructionNum = 0;

                #region Copy Sprites

                if (SpriteEditorSettings.EditingSprites)
                {
                    // remove the in-screen markers and axes so they don't get touched by the copying
                    GameData.EditorLogic.EditAxes.CurrentObject = null;

                    Sprite topSpriteAdded = null;
                    AttachableList <Sprite> oldestParents = AttachableList <Sprite> .GetTopParents <Sprite, Sprite>(GameData.EditorLogic.CurrentSprites);

                    SpriteList addedSprites = new SpriteList();

                    // The appendedNumbers variable is used for improving performance when copying large groups.  When a Sprite
                    // is copied, it is given a number at the end of its name or if there is already a number present,
                    // it is incremented.  However, copying large groups can result in a lot of string checking which
                    // can hurt performance.
                    // Consider copying 100 Sprites with the same texture.  Their names will likely be redball1, redball2,
                    // redball3, ... redball100.  Let's say redball1 gets copied first.  The SpriteEditor increments the
                    // number at the end to redball2, then checks to see if there is already a Sprite with that name.  If
                    // there is, it increments to redball3 and so on.  This must be conducted on average 10,000 times and each
                    // iteration requires string copying, concatenation, and parsing for integers.  To cut this down, the
                    // appendedNumbers variable associates a given name (in this case redball) with the last integer appended
                    // to that particular name.  Therefore, when the first Sprite is created, it will loop through 1 - 100 and
                    // eventually end up at redball101.  It will then associate the number 101 with the name redball.  The next
                    // Sprite (named redball2) will know to begin at redball101.  This increases the performance of
                    // copying large groups from O(n^2) to O(n).

                    Dictionary <string, int> appendedNumbers = new Dictionary <string, int>();

                    foreach (Sprite s in oldestParents)
                    {
                        if (s is ISpriteEditorObject)
                        {
                            if (GuiData.ToolsWindow.groupHierarchyControlButton.IsPressed)
                            {
                                topSpriteAdded =
                                    GameData.copySpriteHierarchy(
                                        s, s.Parent as Sprite, GameData.EditorProperties.PixelSize, addedSprites, appendedNumbers);
                            }
                            else
                            {
                                topSpriteAdded =
                                    GameData.copySpriteHierarchy(
                                        s.TopParent as Sprite, null, GameData.EditorProperties.PixelSize, addedSprites, appendedNumbers);
                            }
                        }
                        SpriteList tempSpriteArray = new SpriteList();
                        topSpriteAdded.GetAllDescendantsOneWay(tempSpriteArray);
                        tempSpriteArray.Add(topSpriteAdded);
                    }

                    GameData.EditorLogic.EditAxes.CurrentObject =
                        GameData.EditorLogic.CurrentSprites[0];

                    GameData.Cursor.ClickSprite(null);
                    foreach (Sprite s in AttachableList <Sprite> .GetTopParents <Sprite, Sprite>(addedSprites))
                    {
                        // the 2nd true forces selection of all Sprites
                        GameData.Cursor.ClickObject <Sprite>(s, GameData.EditorLogic.CurrentSprites, true, true);
                    }

                    GameData.Cursor.VerifyAndUpdateGrabbedAgainstCurrent();
                }
                #endregion

                #region Copy SpriteGrids
                else if (SpriteEditorSettings.EditingSpriteGrids)
                {
                    SpriteGrid sg = SESpriteGridManager.CurrentSpriteGrid.Clone();


                    FlatRedBall.Utilities.StringFunctions.MakeNameUnique <SpriteGrid>(sg, GameData.Scene.SpriteGrids);


                    this.sesgMan.PopulateAndAddGridToEngine(sg, GameData.EditorLogic.CurrentSprites[0]);

                    sg.RefreshPaint();
                }
                #endregion

                #region Copy SpriteFrames
                else if (SpriteEditorSettings.EditingSpriteFrames)
                {
                    GameData.EditorLogic.EditAxes.CurrentObject = null;

                    AttachableList <SpriteFrame> oldestParents =
                        AttachableList <SpriteFrame> .GetTopParents <SpriteFrame, SpriteFrame>(GameData.EditorLogic.CurrentSpriteFrames);

                    foreach (SpriteFrame sf in oldestParents)
                    {
                        SpriteFrame topSpriteFrameAdded = GameData.CopySpriteFrameHierarchy(sf, null, GameData.EditorProperties.PixelSize);
                        GameData.Cursor.ClickSpriteFrame(topSpriteFrameAdded);
                    }
                }
                #endregion

                #region Copy Models

                else if (SpriteEditorSettings.EditingModels)
                {
                    GameData.EditorLogic.EditAxes.CurrentObject = null;

                    AttachableList <PositionedModel> oldestParents =
                        AttachableList <PositionedModel> .GetTopParents <PositionedModel, PositionedModel>(GameData.EditorLogic.CurrentPositionedModels);

                    foreach (PositionedModel model in oldestParents)
                    {
                        PositionedModel topSpriteFrameAdded =
                            GameData.CopyModelHierarchy(model, null, GameData.EditorProperties.PixelSize);

                        //         GameData.cursor.ClickSpriteFrame(topSpriteFrameAdded);
                    }
                }

                #endregion

                #region Copy Texts

                else if (SpriteEditorSettings.EditingTexts)
                {
                    GameData.EditorLogic.EditAxes.CurrentObject = null;

                    AttachableList <Text> oldestParents =
                        AttachableList <Text> .GetTopParents <Text, Text>(GameData.EditorLogic.CurrentTexts);

                    foreach (Text text in oldestParents)
                    {
                        Text topText =
                            GameData.CopyTextHierarchy(text, null, GameData.EditorProperties.PixelSize);

                        //         GameData.cursor.ClickSpriteFrame(topSpriteFrameAdded);
                    }
                }

                #endregion
            }
        }