コード例 #1
0
        public static void DrawBackedText(this SpriteBatch graphics, string text, BfbVector position, BFBContentManager content, float scale = 1f)
        {
            SpriteFont font    = content.GetFont("default");
            Texture2D  texture = content.GetTexture("default");

            (float width, float height) = font.MeasureString(text);

            width  *= scale;
            height *= scale;

            //Background
            graphics.Draw(
                texture,
                new Rectangle((int)position.X - 2, (int)position.Y - 2, (int)width + 4, (int)height + 2),
                new Color(0, 0, 0, 0.5f));

            graphics.DrawString(
                font,
                text,
                position.ToVector2(),
                Color.White,
                0f,
                Vector2.Zero,
                scale,
                SpriteEffects.None,
                1);
        }
コード例 #2
0
        public override void Draw(SpriteBatch graphics, BFBContentManager content)
        {
            InventorySlot slot = ClientDataRegistry.GetInstance()?.Client?.Meta?.MouseSlot;

            if (slot == null)
            {
                return;
            }

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

            int maxHeight = RootUI.RenderAttributes.Height / 10;
            int scale     = maxHeight / atlas.Height;

            int w = atlas.Width * scale;
            int h = atlas.Height * scale;


            int x = (int)Mouse.X - w / 2;
            int y = (int)Mouse.Y - h / 2;

            graphics.DrawAtlas(
                atlas,
                new Rectangle(
                    x,
                    y,
                    w,
                    h
                    ),
                Color.White);

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

            SpriteFont font = content.GetFont("default");

            (float width, float height) = font.MeasureString(slot.Count.ToString()) * 0.6f;
            graphics.DrawString(
                font,
                slot.Count.ToString(),
                new Vector2(Mouse.X - width + 3, Mouse.Y - height + 3),
                Color.White,
                0,
                Vector2.Zero,
                0.6f,
                SpriteEffects.None,
                1);
        }
コード例 #3
0
        public override void Render(SpriteBatch graphics, BFBContentManager content)
        {
            base.Render(graphics, content);

            string text = _selector.Compile().Invoke(_model);

            _tick++;
            if (Focused && _tick % 30 == 0)
            {
                _showCursor = !_showCursor;
            }

            if (Focused)
            {
                if (_showCursor)
                {
                    text += "  ";
                }
                else
                {
                    text += "_";
                }
            }

            #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(RenderAttributes.X, RenderAttributes.Y, RenderAttributes.Width, RenderAttributes.Height);

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

            var font = content.GetFont(RenderAttributes.FontKey);
            //Draw our text
            DrawString(graphics, font, text, new Rectangle(RenderAttributes.X, RenderAttributes.Y, RenderAttributes.Width, RenderAttributes.Height));

            #region graphics.End()

            //Begin next drawing after ending the special buffer
            graphics.End();
            graphics.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);

            #endregion
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="yOffset"></param>
        /// <param name="message"></param>
        /// <param name="container"></param>
        /// <param name="content"></param>
        /// <returns>The bounds of the area the message took</returns>
        public static int DrawChatText(this SpriteBatch graphics, int yOffset, ChatMessage message, UIComponent container, BFBContentManager content)
        {
            #region InitDimensions
            Rectangle bounds = new Rectangle
            {
                X      = container.RenderAttributes.X,
                Y      = container.RenderAttributes.Y + yOffset,
                Width  = container.RenderAttributes.Width,
                Height = message.Height
            };

            message.Width = container.RenderAttributes.Width;
            #endregion

            SpriteFont font    = content.GetFont(container.RenderAttributes.FontKey);
            Texture2D  texture = content.GetTexture(container.RenderAttributes.TextureKey);

            #region Line Height and scale

            int   lineHeight = (int)(content.GraphicsDevice.Viewport.Width / 25f * container.RenderAttributes.FontSize);
            float scale      = lineHeight / font.MeasureString(" ").Y;

            #endregion

            #region Draw Background

            graphics.Draw(texture, bounds, BackgroundColors[(int)message.BackgroundColor]);

            #endregion

            Vector2 cursor         = new Vector2(bounds.X, bounds.Y);
            float   startingHeight = cursor.Y;
            int     spaceWidth     = (int)(font.MeasureString(" ").X *scale);

            cursor = graphics.DrawColoredText(font, cursor, message.Header.Text, bounds, message.Header.ForegroundColor, scale);

            foreach (ChatText chatText in message.Body)
            {
                cursor = graphics.DrawColoredText(font, cursor, chatText.Text, bounds, chatText.ForegroundColor, scale);
            }

            message.Height = (int)(cursor.Y - startingHeight) + lineHeight;

            return((int)(cursor.Y - startingHeight) + lineHeight);
        }
コード例 #5
0
        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"));
                        }
                    }
                }
            }
        }
コード例 #6
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
        }
コード例 #7
0
        public static void DrawUIText(this SpriteBatch graphics, UIComponent component, BFBContentManager content)
        {
            SpriteFont font = content.GetFont(component.RenderAttributes.FontKey);

            float   scale    = 1f;
            string  text     = component.Text;
            Vector2 position = new Vector2();

            (float iWidth, float iHeight) = font.MeasureString(text);

            #region Scale Text

            //Decide how to scale the text
            if (component.RenderAttributes.FontScaleMode == FontScaleMode.ContainerFitScale)
            {
                scale  = System.Math.Min(component.RenderAttributes.Width / iWidth, component.RenderAttributes.Height / iHeight);
                scale *= 8f / 10f;
            }
            else if (component.RenderAttributes.FontScaleMode == FontScaleMode.FontSizeScale)
            {
                int pixelHeight = (int)(content.GraphicsDevice.Viewport.Width / 25f * component.RenderAttributes.FontSize);
                scale = pixelHeight / iHeight;
            }

            #endregion

            #region Wrap Text

            if (component.RenderAttributes.TextWrap == TextWrap.Wrap)
            {
                text = WrapUIComponentText(font, component.Text, component, scale);
            }

            #endregion

            #region Justify text
            if (component.RenderAttributes.JustifyText == JustifyText.Center)
            {
                position.X = component.RenderAttributes.X - (int)(iWidth * scale / 2) + component.RenderAttributes.Width / 2;
            }
            else if (component.RenderAttributes.JustifyText == JustifyText.End)
            {
                position.X = component.RenderAttributes.X + component.RenderAttributes.Width - iWidth * scale;
            }
            else if (component.RenderAttributes.JustifyText == JustifyText.Start)
            {
                position.X = component.RenderAttributes.X;
            }
            #endregion

            #region Vertical Align Text

            //Vertical align text
            if (component.RenderAttributes.VerticalAlignText == VerticalAlignText.Center)
            {
                position.Y = component.RenderAttributes.Y - (int)(iHeight * scale / 2) + component.RenderAttributes.Height / 2;
            }
            else if (component.RenderAttributes.VerticalAlignText == VerticalAlignText.End)
            {
                position.Y = component.RenderAttributes.Y + component.RenderAttributes.Height - iHeight * scale;
            }
            else if (component.RenderAttributes.VerticalAlignText == VerticalAlignText.Start)
            {
                position.Y = component.RenderAttributes.Y;
            }

            #endregion

            graphics.DrawString(
                font,
                text,
                position,
                component.RenderAttributes.Color,
                0,
                Vector2.Zero,
                scale,
                SpriteEffects.None,
                0);
        }