/**
         * Used to render the UIComponent by default as a simple panel
         */
        public virtual void Render(SpriteBatch graphics, BFBContentManager content)
        {
            if (RenderAttributes.Position == Position.Relative)
            {
                RenderAttributes.X = RenderAttributes.OffsetX + Parent?.RenderAttributes.X ?? 0;
                RenderAttributes.Y = RenderAttributes.OffsetY + Parent?.RenderAttributes.Y ?? 0;
            }

            graphics.Draw(
                content.GetTexture(RenderAttributes.TextureKey),
                new Rectangle(
                    RenderAttributes.X,
                    RenderAttributes.Y,
                    RenderAttributes.Width,
                    RenderAttributes.Height),
                RenderAttributes.Background);

            if (!string.IsNullOrEmpty(Text))
            {
                graphics.DrawUIText(this, content);
            }

            if (RenderAttributes.BorderSize > 0)
            {
                graphics.DrawBorder(new Rectangle(
                                        RenderAttributes.X,
                                        RenderAttributes.Y,
                                        RenderAttributes.Width,
                                        RenderAttributes.Height),
                                    RenderAttributes.BorderSize,
                                    RenderAttributes.BorderColor,
                                    content.GetTexture("default"));
            }
        }
Esempio n. 2
0
        public override void Render(SpriteBatch graphics, BFBContentManager content)
        {
            base.Render(graphics, content);

            int x     = RenderAttributes.X + Padding;
            int y     = RenderAttributes.Y + RenderAttributes.Height / 2 - SliderHeight / 2;
            int width = RenderAttributes.Width - Padding * 2;

            //Draw Rail
            graphics.Draw(content.GetTexture("default"), new Rectangle(x, y, width, SliderHeight), Color.Black);

            //Draw Thumb
            graphics.Draw(content.GetTexture("default"), ThumbBounds(), new Color(169, 170, 168));

            graphics.DrawBorder(ThumbBounds(), 3, new Color(211, 212, 210), content.GetTexture("default"));
        }
        private void MapDebug(SpriteBatch graphics, WorldManager world, int xStart, int xEnd, int yStart, int yEnd)
        {
            if (Debug)
            {
                for (int y = yStart; y < yEnd; y++)
                {
                    for (int x = xStart; x < xEnd; x++)
                    {
                        int xPosition = x * _tileScale;
                        int yPosition = y * _tileScale;

                        //Block Values
                        graphics.DrawString(
                            _content.GetFont("default"),
                            (int)world.GetBlock(x, y) + "",
                            new Vector2(xPosition, yPosition),
                            Color.Black,
                            0f,
                            Vector2.Zero,
                            0.5f,
                            SpriteEffects.None,
                            1);

                        if (x % world.WorldOptions.ChunkSize == 0 && y % world.WorldOptions.ChunkSize == 0)
                        {
                            graphics.DrawBorder(
                                new Rectangle(
                                    xPosition,
                                    yPosition,
                                    world.WorldOptions.ChunkSize * _tileScale,
                                    world.WorldOptions.ChunkSize * _tileScale),
                                1,
                                Color.Red,
                                _content.GetTexture("default"));
                        }
                    }
                }
            }
        }
        public void DebugDraw(SpriteBatch graphics, BFBContentManager content, float worldScale, float tileSize)
        {
            if (EntityType != EntityType.Particle)
            {
                int topBlockY    = (int)System.Math.Floor(Top / tileSize);
                int leftBlockX   = (int)System.Math.Floor(Left / tileSize);
                int bottomBlockY = (int)System.Math.Floor((Bottom - 1) / tileSize);
                int rightBlockX  = (int)System.Math.Floor((Right - 1) / tileSize);

                //left upper
                graphics.Draw(
                    content.GetTexture("default"),
                    new Rectangle(
                        (int)(leftBlockX * tileSize),
                        (int)(topBlockY * tileSize),
                        (int)tileSize,
                        (int)tileSize),
                    new Color(0, 100, 0, 0.2f));

                //left upper
                graphics.Draw(
                    content.GetTexture("default"),
                    new Rectangle(
                        (int)(leftBlockX * tileSize),
                        (int)(bottomBlockY * tileSize),
                        (int)tileSize,
                        (int)tileSize),
                    new Color(0, 100, 0, 0.2f));

                //right lower
                graphics.Draw(
                    content.GetTexture("default"),
                    new Rectangle(
                        (int)(rightBlockX * tileSize),
                        (int)(bottomBlockY * tileSize),
                        (int)tileSize,
                        (int)tileSize),
                    new Color(0, 100, 0, 0.2f));

                //right upper
                graphics.Draw(
                    content.GetTexture("default"),
                    new Rectangle(
                        (int)(rightBlockX * tileSize),
                        (int)(topBlockY * tileSize),
                        (int)tileSize,
                        (int)tileSize),
                    new Color(0, 100, 0, 0.2f));
            }
            //entity Bounds
            graphics.DrawBorder(
                new Rectangle((int)Position.X, (int)Position.Y, (int)Dimensions.X, (int)Dimensions.Y), 1,
                Color.Black, content.GetTexture("default"));

            Draw(graphics, content, worldScale);

            if (EntityType != EntityType.Particle)
            {
                //Position
                graphics.DrawBackedText($"X: {(int) Position.X}, Y: {(int) Position.Y}",
                                        new BfbVector(Position.X, Position.Y - 15), content, 0.2f * worldScale);
            }

            //velocity vector
            graphics.DrawVector(new Vector2(Position.X + Dimensions.X / 2, Position.Y + Dimensions.Y / 2), Velocity.ToVector2() * 4 * worldScale, 1, Color.Red, content);

            //orientation vector
            graphics.DrawLine(new Vector2(Position.X + Dimensions.X / 2, Position.Y + 10),
                              Facing == DirectionFacing.Left
                    ? new Vector2((Position.X + Dimensions.X / 2) + -30, Position.Y + 10)
                    : new Vector2((Position.X + Dimensions.X / 2) + 30, Position.Y + 10), 1, Color.Green, content);
        }
Esempio n. 5
0
        public override void Render(SpriteBatch graphics, BFBContentManager content)
        {
            base.Render(graphics, content);

            #region DrawHotbarBorder

            if (_slotId == _inventory.ActiveSlot && _hotBarMode)
            {
                graphics.DrawBorder(
                    new Rectangle(
                        RenderAttributes.X - 2,
                        RenderAttributes.Y - 2,
                        RenderAttributes.Width + 2 * 2,
                        RenderAttributes.Height + 2 * 2),
                    5,
                    Color.Silver,
                    content.GetTexture("default"));
            }

            #endregion

            #region Draw Item

            if (_inventory.GetSlots().ContainsKey(_slotId))
            {
                InventorySlot slot = _inventory.GetSlots()[_slotId];

                if (string.IsNullOrEmpty(slot.TextureKey))
                {
                    return;
                }

                AtlasTexture atlas = content.GetAtlasTexture(slot.TextureKey);

                int padding = Padding;

                if (_hover)
                {
                    padding -= 3;
                }

                int maxHeight = RenderAttributes.Height - padding * 2;
                int scale     = maxHeight / atlas.Height;

                int width  = atlas.Width * scale;
                int height = atlas.Height * scale;

                int x = RenderAttributes.X + padding;
                int y = RenderAttributes.Y + padding;

                graphics.DrawAtlas(atlas, new Rectangle(x, y, width, height), Color.White);

                if (slot.ItemType == ItemType.Wall)
                {
                    graphics.DrawAtlas(atlas, new Rectangle(x, y, width, height), new Color(0, 0, 0, 0.4f));
                }

                //draw count
                if (slot.Count <= 1)
                {
                    return;
                }

                #region Draw Stack Count

                SpriteFont font = content.GetFont(RenderAttributes.FontKey);
                graphics.DrawString(
                    font,
                    slot.Count.ToString(),
                    new Vector2(
                        RenderAttributes.X + padding,
                        RenderAttributes.Y + padding),
                    Color.White,
                    0,
                    Vector2.Zero,
                    RenderAttributes.FontSize * (graphics.GraphicsDevice.Viewport.Width / 25f) / font.MeasureString(" ").Y,
                    SpriteEffects.None,
                    1);

                #endregion
            }

            #endregion
        }
        public void Draw(SpriteBatch graphics, GameTime time, WorldManager world, List <ClientEntity> entities, ClientEntity playerEntity, ControlState input, ClientSocketManager clientSocket = null)
        {
            if (!_init)
            {
                return;
            }

            float worldScale = _tileScale / GraphicsScale;

            #region graphics.Begin()
            //Start different graphics layer
            graphics.End();
            graphics.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Camera.Transform);
            #endregion

            #region DrawRanges

            int xStart = Camera.Left / _tileScale - 1;
            int xEnd   = Camera.Right / _tileScale + 2;

            int yStart = Camera.Top / _tileScale - 1;
            int yEnd   = Camera.Bottom / _tileScale + 2;

            if (xStart < 0)
            {
                xStart = 0;
            }

            if (xEnd > _blockWidth)
            {
                xEnd = _blockWidth;
            }

            if (yStart < 0)
            {
                yStart = 0;
            }
            if (yEnd > _blockHeight)
            {
                yEnd = _blockHeight;
            }

            #endregion

            #region Render Walls + Blocks

            for (int y = yStart; y < yEnd; y++)
            {
                for (int x = xStart; x < xEnd; x++)
                {
                    int xPosition = x * _tileScale;
                    int yPosition = y * _tileScale;

                    if (world.GetBlock(x, y) == WorldTile.Air)
                    {
                        WorldTile tile = (WorldTile)world.GetWall(x, y);

                        if (tile == WorldTile.Air)
                        {
                            continue;
                        }

                        graphics.DrawAtlas(
                            _content.GetAtlasTexture("Tiles:" + tile),
                            new Rectangle(xPosition, yPosition, _tileScale, _tileScale)
                            , Color.White);

                        graphics.DrawAtlas(
                            _content.GetAtlasTexture("Tiles:" + tile),
                            new Rectangle(xPosition, yPosition, _tileScale, _tileScale)
                            , new Color(0, 0, 0, 0.4f));
                    }
                    else
                    {
                        WorldTile tile = world.GetBlock(x, y);

                        if (tile == WorldTile.Leaves)
                        {
                            WorldTile wallTile = (WorldTile)world.GetWall(x, y);

                            if (wallTile != WorldTile.Air)
                            {
                                graphics.DrawAtlas(
                                    _content.GetAtlasTexture("Tiles:" + wallTile),
                                    new Rectangle(xPosition, yPosition, _tileScale, _tileScale)
                                    , Color.White);

                                graphics.DrawAtlas(
                                    _content.GetAtlasTexture("Tiles:" + wallTile),
                                    new Rectangle(xPosition, yPosition, _tileScale, _tileScale)
                                    , new Color(0, 0, 0, 0.4f));
                            }
                        }

                        if (tile != WorldTile.Air)
                        {
                            graphics.DrawAtlas(
                                _content.GetAtlasTexture("Tiles:" + tile),
                                new Rectangle(xPosition, yPosition, _tileScale, _tileScale),
                                Color.White);
                        }
                    }
                }
            }

            #endregion

            #region Mouse ToolTip


            if (playerEntity.Meta != null && playerEntity.Meta.Holding.ItemType != ItemType.Unknown)
            {
                //Get proper mouse coordinates
                BfbVector        mouse = ViewPointToMapPoint(input.Mouse);
                Tuple <int, int> block = world.BlockLocationFromPixel((int)mouse.X, (int)mouse.Y);

                //if the mouse is inside the map
                if (block != null)
                {
                    int playerX     = (int)(playerEntity.Position.X + playerEntity.Width / 2f);
                    int playerY     = (int)(playerEntity.Position.Y + playerEntity.Height / 2f);
                    int blockPixelX = block.Item1 * _tileScale; //x position of block mouse is over
                    int blockPixelY = block.Item2 * _tileScale; //y position of block mouse is over

                    int distance = (int)System.Math.Sqrt(System.Math.Pow(playerX - blockPixelX, 2) +
                                                         System.Math.Pow(playerY - blockPixelY, 2)) / _tileScale;
                    int reach = playerEntity.Meta.Holding.Reach;

                    switch (playerEntity.Meta.Holding.ItemType)
                    {
                    case ItemType.Block:

                        if (world.GetBlock(block.Item1, block.Item2) == WorldTile.Air)
                        {
                            graphics.Draw(_content.GetTexture("default"),
                                          new Rectangle(blockPixelX, blockPixelY, _tileScale, _tileScale),
                                          distance >= reach ? new Color(255, 0, 0, 0.2f) :
                                          new Color(0, 0, 0, 0.2f));
                        }
                        else
                        {
                            float progress = playerEntity.Meta.Holding.Progress;

                            if (progress < 0.05f)
                            {
                                graphics.DrawBorder(
                                    new Rectangle(blockPixelX, blockPixelY, _tileScale, _tileScale),
                                    2,
                                    new Color(0, 0, 0, 0.6f),
                                    _content.GetTexture("default"));
                            }
                            else
                            {
                                graphics.Draw(_content.GetTexture("default"),
                                              new Rectangle(blockPixelX + (int)(_tileScale * (1 - progress)) / 2, blockPixelY + (int)(_tileScale * (1 - progress)) / 2, (int)(_tileScale * progress), (int)(_tileScale * progress)),
                                              new Color(0, 0, 0, 0.4f));
                            }
                        }
                        break;

                    case ItemType.Wall:

                        if (world.GetBlock(block.Item1, block.Item2) == WorldTile.Air && (WorldTile)world.GetWall(block.Item1, block.Item2) == WorldTile.Air)
                        {
                            graphics.Draw(_content.GetTexture("default"),
                                          new Rectangle(blockPixelX, blockPixelY, _tileScale, _tileScale),
                                          distance >= reach ? new Color(255, 0, 0, 0.2f) :
                                          new Color(0, 0, 0, 0.2f));
                        }
                        else
                        {
                            float progress = playerEntity.Meta.Holding.Progress;

                            if (progress < 0.05f)
                            {
                                graphics.DrawBorder(
                                    new Rectangle(blockPixelX, blockPixelY, _tileScale, _tileScale),
                                    2,
                                    new Color(0, 0, 0, 0.6f),
                                    _content.GetTexture("default"));
                            }
                            else
                            {
                                graphics.Draw(_content.GetTexture("default"),
                                              new Rectangle(blockPixelX + (int)(_tileScale * (1 - progress)) / 2, blockPixelY + (int)(_tileScale * (1 - progress)) / 2, (int)(_tileScale * progress), (int)(_tileScale * progress)),
                                              new Color(0, 0, 0, 0.4f));
                            }
                        }

                        break;

                    case ItemType.Tool:

                        var atlas = _content.GetAtlasTexture(playerEntity.Meta.Holding.AtlasKey);

                        graphics.DrawAtlas(atlas,
                                           new Rectangle(
                                               (int)(mouse.X - atlas.Width / 2f),
                                               (int)(mouse.Y - atlas.Height / 2f),
                                               (int)(atlas.Width * worldScale),
                                               (int)(atlas.Height * worldScale)),
                                           distance > reach ?
                                           new Color(255, 0, 0, 0.1f)
                                    : new Color(255, 255, 255, 0.1f));

                        break;
                    }
                }
            }

            #endregion

            #region Map Debug

            if (Debug)
            {
                MapDebug(graphics, world, xStart, xEnd, yStart, yEnd);
            }

            #endregion

            #region Render Entities

            foreach (ClientEntity entity in entities.OrderBy(x => x.Position.Y).ThenBy(x => x.EntityType))
            {
                if (!Debug)
                {
                    entity.Draw(graphics, _content, worldScale);
                }
                else
                {
                    entity.DebugDraw(graphics, _content, worldScale, _tileScale);
                }
            }

            #endregion

            #region graphics.End()

            graphics.End();
            graphics.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);

            #endregion

            #region Debug Panel

            if (Debug)
            {
                DebugPanel(graphics, time, world, playerEntity, entities, clientSocket, input);
            }

            #endregion
        }
Esempio n. 7
0
        /**
         * Recursive method to draw the UI
         */
        private void RenderComponents(UIComponent node, SpriteBatch graphics, UILayer layer)
        {
            if (node == null || node.RenderAttributes.Width < 10 || node.RenderAttributes.Height < 10)
            {
                return;
            }

            if (node.RenderAttributes.Overflow == Overflow.Hide)
            {
                #region graphics.Begin()
                //Stop global buffer
                graphics.End();

                //indicate how we are redrawing the text
                RasterizerState r = new RasterizerState {
                    ScissorTestEnable = true
                };
                graphics.GraphicsDevice.ScissorRectangle = new Rectangle(node.RenderAttributes.X, node.RenderAttributes.Y, node.RenderAttributes.Width, node.RenderAttributes.Height);

                //Start new special buffer
                graphics.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, r);
                #endregion
            }

            node.Render(graphics, _contentManager);

            #region Debug Border
            if (layer.Debug)
            {
                graphics.DrawBorder(
                    new Rectangle(
                        node.RenderAttributes.X,
                        node.RenderAttributes.Y,
                        node.RenderAttributes.Width,
                        node.RenderAttributes.Height),
                    1,
                    Color.Black,
                    _contentManager.GetTexture("default"));
            }
            #endregion

            #region Focus Border

            if (node.Focused)
            {
                graphics.DrawBorder(
                    new Rectangle(
                        node.RenderAttributes.X,
                        node.RenderAttributes.Y,
                        node.RenderAttributes.Width,
                        node.RenderAttributes.Height),
                    3,
                    Color.Red,
                    _contentManager.GetTexture("default"));
            }

            #endregion

            foreach (UIComponent childNode in node.Children)
            {
                RenderComponents(childNode, graphics, layer);
            }

            if (node.RenderAttributes.Overflow == Overflow.Hide)
            {
                #region graphics.End()
                graphics.End();
                graphics.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
                #endregion
            }
        }