using System; using GladiatorIdle.Gfx; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using D = GladiatorIdle.Gfx.Draw; namespace GladiatorIdle.Arena { /// /// Fähigkeiten-Leiste unten (Q, W, E): Bronze-Unterlage, Medaillons mit Tasten-Abzeichen, /// Abklingzeit als Uhrzeiger-Schatten mit Sekunden, Leuchten und Aufblitzen wenn bereit. /// Nicht gelernte Fähigkeiten sind als dunkle Fassung zu sehen. /// internal sealed class AbilityBar { public sealed class Slot { public string Key = "", Name = ""; public Texture2D? Icon; public double Cooldown, Total = 1; public bool Learned = true, Usable = true; public Color Glow = D.Gold; internal float ReadyFlash; internal bool WasCooling; } public readonly Slot[] Slots = { new(), new(), new() }; const float SIZE = 118, GAP = 64; readonly Texture2D? _bar = Assets.Sprite("hud_bar"); BasicEffect? _flat; readonly VertexPositionColor[] _fan = new VertexPositionColor[3 * 64]; double _t; public void Update(float dt) { _t += dt; foreach (var s in Slots) { bool cooling = s.Cooldown > 0; if (s.WasCooling && !cooling) s.ReadyFlash = 1; // gerade bereit geworden s.WasCooling = cooling; s.ReadyFlash = MathF.Max(0, s.ReadyFlash - dt * 2.2f); } } Vector2 Badge(int i) => Center(i) + new Vector2(-SIZE * 0.40f, -SIZE * 0.40f); Vector2 Center(int i) => new(Camera.W / 2 + (i - 1) * (SIZE + GAP), Camera.H - 112); public void Draw(GraphicsDevice gd, SpriteBatch sb, Matrix ui) { _flat ??= new BasicEffect(gd) { VertexColorEnabled = true, TextureEnabled = false, World = Matrix.Identity }; _flat.View = ui; _flat.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1); // Unterlage und Medaillons sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui); if (_bar != null) { float w = 3 * SIZE + 2 * GAP + 190, h = w * _bar.Height / _bar.Width; sb.Draw(_bar, new Vector2(Camera.W / 2, Camera.H - 112), null, Color.White * 0.95f, 0, new Vector2(_bar.Width / 2f, _bar.Height / 2f), w / _bar.Width, SpriteEffects.None, 0); } else D.Glow(sb, new Vector2(Camera.W / 2, Camera.H - 112), new Vector2(760, 240), Color.Black * 0.7f); for (int i = 0; i < 3; i++) { var s = Slots[i]; var c = Center(i); D.Glow(sb, c + new Vector2(0, 8), new Vector2(SIZE * 1.25f), Color.Black * 0.7f); // Schatten if (s.Icon != null) { var tint = !s.Learned ? new Color(40, 34, 28) : s.Cooldown > 0 ? new Color(150, 140, 125) : !s.Usable ? new Color(200, 120, 110) : Color.White; float pop = 1 + 0.12f * s.ReadyFlash; sb.Draw(s.Icon, c, null, tint, 0, new Vector2(s.Icon.Width / 2f, s.Icon.Height / 2f), SIZE * pop / s.Icon.Width, SpriteEffects.None, 0); } } sb.End(); // Abklingzeit: dunkler Uhrzeiger-Schatten über dem Rest gd.BlendState = BlendState.AlphaBlend; gd.RasterizerState = RasterizerState.CullNone; for (int i = 0; i < 3; i++) { var s = Slots[i]; if (!s.Learned || s.Cooldown <= 0) continue; Pie(gd, Center(i), SIZE * 0.47f, (float)Math.Clamp(s.Cooldown / s.Total, 0, 1), Color.Black * 0.62f); } // Tasten-Abzeichen: Münze mit farbigem Rand for (int i = 0; i < 3; i++) { var s = Slots[i]; var badge = Badge(i); Pie(gd, badge, 25, 1, Color.Black * 0.8f); Pie(gd, badge, 21, 1, s.Learned ? s.Glow : D.Border); Pie(gd, badge, 17.5f, 1, new Color(22, 16, 10)); } // Leuchten wenn bereit (additiv) sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui); for (int i = 0; i < 3; i++) { var s = Slots[i]; var c = Center(i); if (!s.Learned) continue; if (s.Cooldown <= 0 && s.Usable) { float pulse = 0.22f + 0.1f * MathF.Sin((float)_t * 3 + i); D.Glow(sb, c, new Vector2(SIZE * 1.55f), s.Glow * pulse); } if (s.ReadyFlash > 0) D.Glow(sb, c, new Vector2(SIZE * (1.4f + 1.2f * (1 - s.ReadyFlash))), Color.White * (0.8f * s.ReadyFlash)); } sb.End(); // Tasten-Abzeichen, Sekunden, Namen sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui); for (int i = 0; i < 3; i++) { var s = Slots[i]; var c = Center(i); var badge = Badge(i); D.Text(sb, Assets.SansBold, 22, s.Key, badge + new Vector2(0, 1), s.Learned ? Color.White : D.Dim, Align.Center, 1, false); if (s.Learned && s.Cooldown > 0) D.Text(sb, Assets.SansBold, 38, Math.Ceiling(s.Cooldown).ToString(NumberFormat.Culture), c, Color.White, Align.Center); if (s.Learned) D.Text(sb, Assets.SansBold, 17, s.Name.ToUpperInvariant(), c + new Vector2(0, SIZE * 0.57f), s.Cooldown <= 0 ? D.Sand : D.Dim, Align.Center); } sb.End(); } /// Kreisausschnitt ab 12 Uhr im Uhrzeigersinn über des Kreises. void Pie(GraphicsDevice gd, Vector2 c, float r, float frac, Color color) { const int SEG = 64; int n = Math.Max(1, (int)MathF.Ceiling(SEG * frac)); float start = -MathF.PI / 2, sweep = MathF.Tau * frac; int v = 0; for (int k = 0; k < n; k++) { float a0 = start + sweep * k / n, a1 = start + sweep * (k + 1) / n; _fan[v++] = new VertexPositionColor(new Vector3(c, 0), color); _fan[v++] = new VertexPositionColor(new Vector3(c + new Vector2(MathF.Cos(a0), MathF.Sin(a0)) * r, 0), color); _fan[v++] = new VertexPositionColor(new Vector3(c + new Vector2(MathF.Cos(a1), MathF.Sin(a1)) * r, 0), color); } foreach (var pass in _flat!.CurrentTechnique.Passes) { pass.Apply(); gd.DrawUserPrimitives(PrimitiveType.TriangleList, _fan, 0, n); } } } }