osu/osu.Game/Skinning/LegacyHealthDisplay.cs

107 lines
3.0 KiB
C#
Raw Normal View History

2020-10-16 05:39:45 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2020-10-16 05:54:46 +00:00
using System;
2020-10-16 05:39:45 +00:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
2020-10-16 06:10:39 +00:00
using osu.Framework.Graphics.Textures;
2020-10-16 05:54:46 +00:00
using osu.Framework.Utils;
2020-10-16 05:39:45 +00:00
using osu.Game.Rulesets.Judgements;
using osu.Game.Screens.Play.HUD;
using osuTK;
namespace osu.Game.Skinning
{
public class LegacyHealthDisplay : CompositeDrawable, IHealthDisplay
{
private readonly Skin skin;
private Sprite fill;
private Marker marker;
2020-10-16 05:54:46 +00:00
private float maxFillWidth;
2020-10-16 06:10:39 +00:00
private Texture isNewStyle;
2020-10-16 05:39:45 +00:00
public Bindable<double> Current { get; } = new BindableDouble { MinValue = 0, MaxValue = 1 };
public LegacyHealthDisplay(Skin skin)
{
this.skin = skin;
}
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
2020-10-16 06:10:39 +00:00
isNewStyle = getTexture(skin, "marker");
2020-10-16 05:39:45 +00:00
InternalChildren = new Drawable[]
{
new Sprite
{
2020-10-16 06:10:39 +00:00
Texture = getTexture(skin, "bg")
2020-10-16 05:39:45 +00:00
},
fill = new Sprite
{
2020-10-16 06:10:39 +00:00
Texture = getTexture(skin, "colour"),
2020-10-16 05:39:45 +00:00
Position = new Vector2(7.5f, 7.8f) * 1.6f
},
marker = new Marker(skin)
{
Current = { BindTarget = Current },
}
};
2020-10-16 05:54:46 +00:00
maxFillWidth = fill.Width;
2020-10-16 05:39:45 +00:00
}
protected override void Update()
{
base.Update();
2020-10-16 05:54:46 +00:00
fill.Width = Interpolation.ValueAt(
Math.Clamp(Clock.ElapsedFrameTime, 0, 200),
fill.Width, (float)Current.Value * maxFillWidth, 0, 200, Easing.OutQuint);
2020-10-16 05:39:45 +00:00
marker.Position = fill.Position + new Vector2(fill.DrawWidth, fill.DrawHeight / 2);
}
public void Flash(JudgementResult result)
{
marker.ScaleTo(1.4f).Then().ScaleTo(1, 200, Easing.Out);
}
private class Marker : CompositeDrawable
{
public Bindable<double> Current { get; } = new Bindable<double>();
public Marker(Skin skin)
{
Origin = Anchor.Centre;
2020-10-16 06:10:39 +00:00
if (getTexture(skin, "ki") != null)
2020-10-16 05:39:45 +00:00
{
// TODO: old style (marker changes as health decreases)
}
else
{
InternalChildren = new Drawable[]
{
new Sprite
{
2020-10-16 06:10:39 +00:00
Texture = getTexture(skin, "marker"),
2020-10-16 05:39:45 +00:00
Origin = Anchor.Centre,
}
};
}
}
}
2020-10-16 06:10:39 +00:00
private static Texture getTexture(Skin skin, string name) => skin.GetTexture($"scorebar-{name}");
2020-10-16 05:39:45 +00:00
}
}