Ejemplo n.º 1
0
        protected virtual void DrawText(SpriteBatch spriteBatch)
        {
            if (Assetmanager.GetFont(font) == null)
            {
                return;
            }

            if (sprite is SlicedSprite)
            {
                if (root is IRenderDelegator)
                {
                    ((IRenderDelegator)root).Delegate(new DelegatableFont()
                    {
                        FontName = font
                    }, new FontSettings()
                    {
                        Color = hover ? foregroundHover : foreground, Position = textLocation, Text = text
                    });
                }
            }
            else
            {
                spriteBatch.DrawString(Assetmanager.GetFont(font), text, textLocation, hover ? foregroundHover : foreground);
            }
        }
Ejemplo n.º 2
0
        public void Generate(int textureID, Point frame, float threshold)
        {
            threshold = MathHelper.Clamp(threshold, 0, 1);

            Texture2D texture = Assetmanager.GetTexture(textureID);

            Color[] data = new Color[tilesize * tilesize];
            texture.GetData(0, new Rectangle(frame.X, frame.Y, tilesize, tilesize), data, 0, data.Length);
            float[,] translation = new float[tilesize, tilesize];
            for (int y = 0; y < tilesize; y++)
            {
                for (int x = 0; x < tilesize; x++)
                {
                    translation[x, y] = data[x + y * tilesize].A / 255f;
                }
            }

            bool[] collides = new bool[16];
            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    collides[x + y * 4] = translation.SubArray(x * quarterTileSize, quarterTileSize, y * quarterTileSize, quarterTileSize).Median() > threshold;
                }
            }

            for (int i = 0; i < collides.Length; i++)
            {
                if (collides[i])
                {
                    value = value | Parts[i];
                }
            }
            Recalculate();
        }
Ejemplo n.º 3
0
        protected override void DrawText(SpriteBatch spriteBatch)
        {
            if (Assetmanager.GetFont(font) == null)
            {
                return;
            }

            spriteBatch.DrawString(Assetmanager.GetFont(font), text, new Vector2(bounds.Right + labelDistance, textLocation.Y), hover ? foregroundHover : foreground);
        }
Ejemplo n.º 4
0
 protected virtual void MeasureString()
 {
     if (text == null)
     {
         text = string.Empty;
     }
     textDimension = Assetmanager.GetFont(font).MeasureString(text);
     textLocation  = new Vector2(bounds.Center.X, bounds.Center.Y) - textDimension * 0.5f;
 }
Ejemplo n.º 5
0
        private void DrawText(SpriteBatch spriteBatch)
        {
            if (Assetmanager.GetFont(font) == null)
            {
                return;
            }

            spriteBatch.DrawString(Assetmanager.GetFont(font), text, position, foreground);
        }
Ejemplo n.º 6
0
 public void Draw(SpriteBatch spriteBatch)
 {
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             Tile t = tiles[y * width + x];
             spriteBatch.Draw(Assetmanager.GetTexture(t.Texture), new Rectangle(x * tileSize.X, y * tileSize.Y, tileSize.X, tileSize.Y), t.Frame, Color.White);
         }
     }
 }
Ejemplo n.º 7
0
        public void Draw(SpriteBatch spriteBatch, IDelegateDrawSettings settings)
        {
            if (!(settings is FontSettings))
            {
                return;
            }

            FontSettings f = (FontSettings)settings;

            spriteBatch.DrawString(Assetmanager.GetFont(font), f.Text, f.Position, f.Color);
        }
Ejemplo n.º 8
0
        private void MeasureBounds()
        {
            SpriteFont font = Assetmanager.GetFont(this.font);

            if (font == null)
            {
                return;
            }

            Vector2 dimension = font.MeasureString(text);

            bounds.X      = (int)position.X;
            bounds.Y      = (int)position.Y;
            bounds.Width  = (int)dimension.X;
            bounds.Height = (int)dimension.Y;
        }
Ejemplo n.º 9
0
        public MainMenu(string name, StateMachine statemachine) : base(name, statemachine)
        {
            ui = new UIManager();
            Localizer.CultureChanged += Localizer_CultureChanged;
            buttonSprite              = new SlicedSprite("button_texture", "Textures/UI/Button");
            buttonSprite.Top          = 18;
            buttonSprite.Left         = 18;
            buttonSprite.Right        = 46;
            buttonSprite.Bottom       = 46;

            Assetmanager.AquireFont("Fonts/default");
            btnQuit           = new Button(ui, ui);
            btnQuit.Sprite    = buttonSprite;
            btnQuit.Font      = "Fonts/default";
            btnQuit.Position  = new Vector2(Game1.Graphics.PreferredBackBufferWidth / 2 - 100, 400);
            btnQuit.Dimension = new Point(200, 100);
            btnQuit.Click    += BtnQuit_Click;

            RefreshLocalization();
        }
Ejemplo n.º 10
0
        public override void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color color)
        {
            int width  = (bounds.Width < this.bounds.Width) ? this.bounds.Width : bounds.Width;
            int height = (bounds.Height < this.bounds.Height) ? this.bounds.Height : bounds.Height;

            int centerWidth  = width - left - rightWidth;
            int centerHeight = height - top - bottomHeight;

            Texture2D tex = Assetmanager.GetTexture(texture);

            spriteBatch.Draw(tex, new Rectangle(bounds.Left, bounds.Top, left, top), source[(int)Handle.TopLeft], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left, bounds.Top, centerWidth, top), source[(int)Handle.TopCenter], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left + centerWidth, bounds.Top, rightWidth, top), source[(int)Handle.TopRight], color);

            spriteBatch.Draw(tex, new Rectangle(bounds.Left, bounds.Top + top, left, centerHeight), source[(int)Handle.MiddleLeft], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left, bounds.Top + top, centerWidth, centerHeight), source[(int)Handle.Center], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left + centerWidth, bounds.Top + top, rightWidth, centerHeight), source[(int)Handle.MiddleRight], color);

            spriteBatch.Draw(tex, new Rectangle(bounds.Left, bounds.Top + top + centerHeight, left, bottomHeight), source[(int)Handle.BottomLeft], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left, bounds.Top + top + centerHeight, centerWidth, bottomHeight), source[(int)Handle.BottomCenter], color);
            spriteBatch.Draw(tex, new Rectangle(bounds.Left + left + centerWidth, bounds.Top + top + centerHeight, rightWidth, bottomHeight), source[(int)Handle.BottomRight], color);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Draws the sprite in a given area and with a given frame
 /// </summary>
 /// <param name="spriteBatch">allows rendering the sprite to the screen</param>
 /// <param name="bounds">the rendered area</param>
 /// <param name="color">the color of the sprite</param>
 /// <param name="frame">the frame that should be rendered (defaults to 0)</param>
 public void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color color, int frame = 0)
 {
     spriteBatch.Draw(Assetmanager.GetTexture(texture), bounds, frames[frame], color, rotation, origin, SpriteEffects.None, 0);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Draws the sprite at a given location and with a given frame
 /// </summary>
 /// <param name="spriteBatch">allows rendering the sprite to the screen</param>
 /// <param name="position">the position of the sprite</param>
 /// <param name="color">the color of the sprite</param>
 /// <param name="frame">the frame that should be rendered (defaults to 0)</param>
 public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, int frame = 0)
 {
     spriteBatch.Draw(Assetmanager.GetTexture(texture), position, frames[frame], Color.White, rotation, origin, 1, SpriteEffects.None, 0);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a new Sprite with the given values.
 /// </summary>
 /// <param name="name">The name of the sprite. Used to retrieve other data from memory.</param>
 /// <param name="texture">The name of the Texture2D that can be processed via the ContentManager.</param>
 /// <param name="frameSize">The size of one single frame within a spritesheet.</param>
 public Sprite(string name, string texture)
 {
     this.name    = name;
     this.texture = Assetmanager.AquireTexture(texture);
     bounds       = Assetmanager.GetTexture(this.texture).Bounds;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Draws the sprite in a given area
 /// </summary>
 /// <param name="spriteBatch">allows rendering the sprite to the screen</param>
 /// <param name="bounds">the rendered area</param>
 /// <param name="color">the color of the sprite</param>
 public virtual void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color color)
 {
     spriteBatch.Draw(Assetmanager.GetTexture(texture), bounds, null, color, rotation, origin, SpriteEffects.None, 0);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Draws the sprite at a given location
 /// </summary>
 /// <param name="spriteBatch">allows rendering the sprite to the screen</param>
 /// <param name="position">the position of the sprite</param>
 /// <param name="color">the color of the sprite</param>
 public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color)
 {
     spriteBatch.Draw(Assetmanager.GetTexture(texture), new Rectangle((int)position.X, (int)position.Y, bounds.Width, bounds.Height), null, color, rotation, origin, SpriteEffects.None, 0);
 }