private void DrawPlayfield() { // Draw as many playfield lines as needed from the beatmap key amount setting for (int i = 0; i < Beatmap.Settings.Difficulty.KeyAmount; i++) { int x = Skin.Settings.PlayfieldPositionX + Skin.PlayfieldLineTexture.Width * i; var destRect = new Rectangle(x, 0, Skin.PlayfieldLineTexture.Width, Settings.WindowHeight); _spriteBatch.Draw(Skin.PlayfieldLineTexture, destRect, Color.White); } // Draw buttons _spriteBatch.Draw(Skin.ButtonTexture, new Vector2(Skin.Settings.PlayfieldPositionX, Settings.WindowHeight - Skin.ButtonTexture.Height), Color.White); // Initialize health bar settings float hpX = Skin.Settings.PlayfieldPositionX + Skin.PlayfieldLineTexture.Width * Beatmap.Settings.Difficulty.KeyAmount; float hpY = _game.Services.GetService <GameSettings>().WindowHeight; float hpW = 20; // TODO: Link to GameSettings // Draw health bar background _spriteBatch.Draw(Skin.HealthBarBg, new Vector2(hpX, hpY - Skin.HealthBarBg.Height), null, Color.White, 0.0f, Vector2.One, new Vector2(1.0f, 1.0f), SpriteEffects.None, 0.0f); var curVal = FindSystem <HealthSystem>().Health; var maxVal = FindSystem <HealthSystem>().MaxHealth; var minVal = FindSystem <HealthSystem>().MinHealth; // Set source rectangle for making health bar dynamic var srcRect = new Rectangle(0, 0, (int)hpW, (int)MathHelperExtensions.InBetween(Skin.HealthBar.Height, curVal, minVal, maxVal)); // Interpolate color from Red (min health) to Green (max health) Color col = Color.Lerp(Color.Red, Color.Green, curVal / 100.0f); // Draw health bar // We should rotate the health bar by 180 degrees (PI in radians) because rectangle can't get negative height _spriteBatch.Draw(Skin.HealthBar, new Vector2(hpX, hpY), srcRect, col, (float)Math.PI, new Vector2(hpW, 0), Vector2.One, SpriteEffects.None, 0.0f); }
public override void Draw(GameTime gameTime) { _spriteBatch.Begin(); if (ShouldDrawBackground) { var posOffset = new Vector2(Position.X - 4, Position.Y - 4); var sizeOffset = new Size2(Size.Width + 8, Size.Height + 8); _spriteBatch.FillRectangle(posOffset, sizeOffset, Color.Gray); _spriteBatch.DrawRectangle(Position, Size, Color.Black); } else { _spriteBatch.DrawLine(new Vector2(Position.X, Position.Y + Size.Height), new Vector2(Position.X + Size.Width, Position.Y + Size.Height), Color.Black); } if (_nodes.Count > 0) { foreach (var node in _nodes) { var pos = new Vector2( Position.X + node.XOffset + _xOffset, Position.Y - MathHelperExtensions.InBetween(Size.Height, node.Value, MinValue, MaxValue) + Size.Height ); if (pos.X >= Position.X) { var rect = new RectangleF(pos - Vector2.UnitX * (CellSize.Width / 2), new Size2(CellSize.Width, Size.Height * node.Value / (MaxValue - MinValue))); var mousePos = Mouse.GetState().Position.ToVector2(); var mouseRect = new RectangleF(mousePos, new Size2(1, 1)); if (new RectangleF(new Point2(Position.X + node.XOffset + _xOffset, Position.Y), new Size2(CellSize.Width, Size.Height)).Intersects(mouseRect)) { if (ShouldDrawBars) { _spriteBatch.FillRectangle(rect, Color.Red); _spriteBatch.DrawRectangle(rect, Color.Green); } if (Font != null) { _spriteBatch.FillRectangle(new Vector2(pos.X, Position.Y + Size.Height), new Size2(node.Value.ToString(CultureInfo.CurrentCulture).Length * 10, 16), Color.Yellow); _spriteBatch.DrawString(Font, node.Value.ToString(), new Vector2(pos.X, Position.Y + Size.Height), Color.Black); } _spriteBatch.DrawPoint(pos, Color.Orange, 4f); } else { if (ShouldDrawBars) { _spriteBatch.FillRectangle(rect, Color.LightCyan); _spriteBatch.DrawRectangle(rect, Color.Green); } } if (node.Next != null) { var nextPos = new Vector2( Position.X + node.Next.XOffset + _xOffset, Position.Y - MathHelperExtensions.InBetween(Size.Height, node.Next.Value, MinValue, MaxValue) + Size.Height ); _spriteBatch.DrawLine(pos, nextPos, Color.White); } _spriteBatch.DrawPoint(pos, Color.Red, 2f); } } if (Font != null) { _spriteBatch.DrawString(Font, $"Avg: {_nodes.Average(n => n.Value):F1}\nMin: {MinPushedValue:F1}\nMax: {MaxPushedValue:F1}", Position + Vector2.UnitY * Size.Height, Color.Black); } } _spriteBatch.End(); base.Draw(gameTime); }