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); }
public override void Render(SpriteBatch graphics, BFBContentManager content) { base.Render(graphics, content); EntityMeta meta = _valueSelector.Compile()?.Invoke(_model); if (meta == null) { return; } Vector2 cursor = new Vector2(RenderAttributes.X, RenderAttributes.Y); int width = RenderAttributes.Width / 10; int dimension = width - 5; ushort value = _textureKey == "Mana" ? meta.Mana : meta.Health; ushort valueStep = _textureKey == "Mana" ? (ushort)(meta.MaxMana / 10) : (ushort)(meta.MaxHealth / 10); for (int i = 0; i < 10; i++) { string atlasKey; if (value - i * valueStep >= valueStep) { atlasKey = _textureKey + ":Full"; } else if (value - i * valueStep >= valueStep * 0.75f) { atlasKey = _textureKey + ":Most"; } else if (value - i * valueStep >= valueStep * 0.5f) { atlasKey = _textureKey + ":Half"; } else if (value - i * valueStep >= valueStep * 0.25f) { atlasKey = _textureKey + ":Partial"; } else { atlasKey = _textureKey + ":Empty"; } graphics.DrawAtlas(content.GetAtlasTexture(atlasKey), new Rectangle((int)cursor.X, (int)cursor.Y, dimension, dimension), Color.White); cursor.X += width; } }
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 }
public void Draw(ClientEntity entity, SpriteBatch graphics, BFBContentManager contentManager, float worldScale) { #region Draw Entity graphics.Draw(_animatedTexture.Texture, entity.Position.ToVector2(), _frameSelector, _animatedTexture.ParsedColor, entity.Rotation, entity.Origin.ToVector2() - entity.Dimensions.ToVector2() / 2, _animatedTexture.Scale * worldScale, !_currentAnimationSet.Mirror ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 1); #endregion //Holding something? if (entity.Meta?.Holding?.AtlasKey == null) { return; } AtlasTexture atlas = contentManager.GetAtlasTexture(entity.Meta.Holding.AtlasKey); float rotation = 0; float scale; int x = entity.Facing == DirectionFacing.Left ? entity.Left : entity.Right; int y = (int)(entity.Height / 1.5 + entity.Position.Y); Vector2 origin = new Vector2(atlas.Width / 2f, atlas.Height); if (System.Math.Abs(entity.Velocity.X) > 2) { if (entity.Facing == DirectionFacing.Left) { rotation = (float)(-45 * (System.Math.PI / 180)); x += 10; } else { rotation = (float)(45 * (System.Math.PI / 180)); x -= 10; } y = (int)(entity.Height / 2f + entity.Position.Y); } if (entity.Meta.Holding.ItemType == ItemType.Tool) { scale = worldScale; } else { scale = worldScale * 0.6f; } graphics.DrawAtlas(atlas, new Rectangle(x, y, (int)(atlas.Width * scale), (int)(atlas.Height * scale)), Color.White, rotation, origin); if (entity.Meta.Holding.ItemType == ItemType.Wall) { graphics.DrawAtlas( atlas, new Rectangle(x, y, (int)(atlas.Width * scale), (int)(atlas.Height * scale)), new Color(0, 0, 0, 0.4f), rotation, origin); } }