mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 09:02:58 +08:00
Add legacy implementation
This commit is contained in:
parent
e89c5c3b3c
commit
5be9e30cd0
101
osu.Game/Skinning/LegacyHealthDisplay.cs
Normal file
101
osu.Game/Skinning/LegacyHealthDisplay.cs
Normal file
@ -0,0 +1,101 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
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;
|
||||
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;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Sprite
|
||||
{
|
||||
Texture = skin.GetTexture("scorebar-bg")
|
||||
},
|
||||
fill = new Sprite
|
||||
{
|
||||
Texture = skin.GetTexture("scorebar-colour"),
|
||||
Position = new Vector2(7.5f, 7.8f) * 1.6f
|
||||
},
|
||||
marker = new Marker(skin)
|
||||
{
|
||||
Current = { BindTarget = Current },
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Current.BindValueChanged(updateHp, true);
|
||||
}
|
||||
|
||||
private void updateHp(ValueChangedEvent<double> hp)
|
||||
{
|
||||
if (fill.Texture != null)
|
||||
fill.ResizeWidthTo((float)(fill.Texture.DisplayWidth * hp.NewValue), 500, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
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;
|
||||
|
||||
if (skin.GetTexture("scorebar-ki") != null)
|
||||
{
|
||||
// TODO: old style (marker changes as health decreases)
|
||||
}
|
||||
else
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Sprite
|
||||
{
|
||||
Texture = skin.GetTexture("scorebar-marker"),
|
||||
Origin = Anchor.Centre,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -347,6 +347,9 @@ namespace osu.Game.Skinning
|
||||
|
||||
case HUDSkinComponents.AccuracyCounter:
|
||||
return new LegacyAccuracyCounter(this);
|
||||
|
||||
case HUDSkinComponents.HealthDisplay:
|
||||
return new LegacyHealthDisplay(this);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user