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;
|
2021-08-10 01:29:31 +00:00
|
|
|
using osu.Game.Utils;
|
2020-10-16 05:39:45 +00:00
|
|
|
using osuTK;
|
2020-10-16 07:45:28 +00:00
|
|
|
using osuTK.Graphics;
|
2020-10-16 05:39:45 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
2021-05-13 08:06:00 +00:00
|
|
|
public class LegacyHealthDisplay : HealthDisplay, ISkinnableDrawable
|
2020-10-16 05:39:45 +00:00
|
|
|
{
|
2020-10-16 08:24:56 +00:00
|
|
|
private const double epic_cutoff = 0.5;
|
|
|
|
|
2020-10-16 07:45:28 +00:00
|
|
|
private LegacyHealthPiece fill;
|
|
|
|
private LegacyHealthPiece marker;
|
2020-10-16 05:54:46 +00:00
|
|
|
|
|
|
|
private float maxFillWidth;
|
|
|
|
|
2020-10-16 07:18:29 +00:00
|
|
|
private bool isNewStyle;
|
2020-10-16 06:10:39 +00:00
|
|
|
|
2021-06-08 12:22:35 +00:00
|
|
|
public bool UsesFixedAnchor { get; set; }
|
2021-06-07 03:47:47 +00:00
|
|
|
|
2020-10-16 05:39:45 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2021-06-07 14:23:10 +00:00
|
|
|
private void load(ISkinSource source)
|
2020-10-16 05:39:45 +00:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
2021-06-07 14:23:10 +00:00
|
|
|
var skin = source.FindProvider(s => getTexture(s, "bg") != null);
|
2021-06-06 14:23:35 +00:00
|
|
|
|
|
|
|
// the marker lookup to decide which display style must be performed on the source of the bg, which is the most common element.
|
2020-10-16 07:18:29 +00:00
|
|
|
isNewStyle = getTexture(skin, "marker") != null;
|
|
|
|
|
|
|
|
// background implementation is the same for both versions.
|
|
|
|
AddInternal(new Sprite { Texture = getTexture(skin, "bg") });
|
2020-10-16 06:10:39 +00:00
|
|
|
|
2020-10-16 07:18:29 +00:00
|
|
|
if (isNewStyle)
|
2020-10-16 05:39:45 +00:00
|
|
|
{
|
2020-10-16 07:18:29 +00:00
|
|
|
AddRangeInternal(new[]
|
2020-10-16 05:39:45 +00:00
|
|
|
{
|
2020-10-16 07:18:29 +00:00
|
|
|
fill = new LegacyNewStyleFill(skin),
|
|
|
|
marker = new LegacyNewStyleMarker(skin),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AddRangeInternal(new[]
|
2020-10-16 05:39:45 +00:00
|
|
|
{
|
2020-10-16 07:18:29 +00:00
|
|
|
fill = new LegacyOldStyleFill(skin),
|
|
|
|
marker = new LegacyOldStyleMarker(skin),
|
|
|
|
});
|
|
|
|
}
|
2020-10-16 05:39:45 +00:00
|
|
|
|
2020-10-16 07:45:28 +00:00
|
|
|
fill.Current.BindTo(Current);
|
2020-10-16 07:18:29 +00:00
|
|
|
marker.Current.BindTo(Current);
|
2020-10-16 07:45:28 +00:00
|
|
|
|
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-11-09 07:20:19 +00:00
|
|
|
marker.Position = fill.Position + new Vector2(fill.DrawWidth, isNewStyle ? fill.DrawHeight / 2 : 0);
|
2020-10-16 05:39:45 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 07:56:24 +00:00
|
|
|
protected override void Flash(JudgementResult result) => marker.Flash(result);
|
2020-10-16 07:18:29 +00:00
|
|
|
|
2021-06-06 14:23:35 +00:00
|
|
|
private static Texture getTexture(ISkin skin, string name) => skin?.GetTexture($"scorebar-{name}");
|
2020-10-16 07:18:29 +00:00
|
|
|
|
2020-10-16 07:45:28 +00:00
|
|
|
private static Color4 getFillColour(double hp)
|
|
|
|
{
|
|
|
|
if (hp < 0.2)
|
2021-08-10 01:29:31 +00:00
|
|
|
return LegacyUtils.InterpolateNonLinear(0.2 - hp, Color4.Black, Color4.Red, 0, 0.2);
|
2020-10-16 07:45:28 +00:00
|
|
|
|
2020-10-16 08:24:56 +00:00
|
|
|
if (hp < epic_cutoff)
|
2021-08-10 01:29:31 +00:00
|
|
|
return LegacyUtils.InterpolateNonLinear(0.5 - hp, Color4.White, Color4.Black, 0, 0.5);
|
2020-10-16 07:45:28 +00:00
|
|
|
|
|
|
|
return Color4.White;
|
|
|
|
}
|
|
|
|
|
2020-10-16 08:09:00 +00:00
|
|
|
public class LegacyOldStyleMarker : LegacyMarker
|
2020-10-16 07:18:29 +00:00
|
|
|
{
|
2020-10-16 07:29:10 +00:00
|
|
|
private readonly Texture normalTexture;
|
|
|
|
private readonly Texture dangerTexture;
|
|
|
|
private readonly Texture superDangerTexture;
|
|
|
|
|
2021-06-07 14:23:10 +00:00
|
|
|
public LegacyOldStyleMarker(ISkin skin)
|
2020-10-16 07:18:29 +00:00
|
|
|
{
|
2020-10-16 07:29:10 +00:00
|
|
|
normalTexture = getTexture(skin, "ki");
|
|
|
|
dangerTexture = getTexture(skin, "kidanger");
|
|
|
|
superDangerTexture = getTexture(skin, "kidanger2");
|
2020-10-16 07:18:29 +00:00
|
|
|
}
|
2020-10-16 07:29:10 +00:00
|
|
|
|
2020-10-16 08:09:00 +00:00
|
|
|
public override Sprite CreateSprite() => new Sprite
|
|
|
|
{
|
|
|
|
Texture = normalTexture,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
};
|
|
|
|
|
2020-10-16 07:29:10 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Current.BindValueChanged(hp =>
|
|
|
|
{
|
|
|
|
if (hp.NewValue < 0.2f)
|
2020-10-16 08:09:00 +00:00
|
|
|
Main.Texture = superDangerTexture;
|
2020-10-16 08:24:56 +00:00
|
|
|
else if (hp.NewValue < epic_cutoff)
|
2020-10-16 08:09:00 +00:00
|
|
|
Main.Texture = dangerTexture;
|
2020-10-16 07:29:10 +00:00
|
|
|
else
|
2020-10-16 08:09:00 +00:00
|
|
|
Main.Texture = normalTexture;
|
2020-10-16 07:29:10 +00:00
|
|
|
});
|
|
|
|
}
|
2020-10-16 07:18:29 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 08:09:00 +00:00
|
|
|
public class LegacyNewStyleMarker : LegacyMarker
|
2020-10-16 05:39:45 +00:00
|
|
|
{
|
2021-06-07 14:23:10 +00:00
|
|
|
private readonly ISkin skin;
|
2020-10-16 07:45:28 +00:00
|
|
|
|
2021-06-07 14:23:10 +00:00
|
|
|
public LegacyNewStyleMarker(ISkin skin)
|
2020-10-16 07:18:29 +00:00
|
|
|
{
|
2020-10-16 08:09:00 +00:00
|
|
|
this.skin = skin;
|
2020-10-16 07:18:29 +00:00
|
|
|
}
|
2020-10-16 05:39:45 +00:00
|
|
|
|
2020-10-16 08:09:00 +00:00
|
|
|
public override Sprite CreateSprite() => new Sprite
|
|
|
|
{
|
|
|
|
Texture = getTexture(skin, "marker"),
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
};
|
|
|
|
|
2020-10-16 07:45:28 +00:00
|
|
|
protected override void Update()
|
2020-10-16 05:39:45 +00:00
|
|
|
{
|
2020-10-16 07:45:28 +00:00
|
|
|
base.Update();
|
|
|
|
|
2020-10-16 08:09:00 +00:00
|
|
|
Main.Colour = getFillColour(Current.Value);
|
2020-10-16 08:24:56 +00:00
|
|
|
Main.Blending = Current.Value < epic_cutoff ? BlendingParameters.Inherit : BlendingParameters.Additive;
|
2020-10-16 07:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 11:55:38 +00:00
|
|
|
internal abstract class LegacyFill : LegacyHealthPiece
|
2020-10-16 07:18:29 +00:00
|
|
|
{
|
2021-06-11 11:55:38 +00:00
|
|
|
protected LegacyFill(ISkin skin)
|
2020-10-16 07:18:29 +00:00
|
|
|
{
|
|
|
|
// required for sizing correctly..
|
|
|
|
var firstFrame = getTexture(skin, "colour-0");
|
2020-10-16 05:39:45 +00:00
|
|
|
|
2020-10-16 07:18:29 +00:00
|
|
|
if (firstFrame == null)
|
2020-10-16 05:39:45 +00:00
|
|
|
{
|
2020-10-16 07:18:29 +00:00
|
|
|
InternalChild = new Sprite { Texture = getTexture(skin, "colour") };
|
|
|
|
Size = InternalChild.Size;
|
2020-10-16 05:39:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-11 12:03:21 +00:00
|
|
|
InternalChild = skin.GetAnimation("scorebar-colour", true, true, startAtCurrentTime: false, applyConfigFrameRate: true) ?? Empty();
|
2020-10-16 07:18:29 +00:00
|
|
|
Size = new Vector2(firstFrame.DisplayWidth, firstFrame.DisplayHeight);
|
2020-10-16 05:39:45 +00:00
|
|
|
}
|
2020-10-16 07:18:29 +00:00
|
|
|
|
|
|
|
Masking = true;
|
2020-10-16 05:39:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-16 06:10:39 +00:00
|
|
|
|
2021-06-11 11:55:38 +00:00
|
|
|
internal class LegacyOldStyleFill : LegacyFill
|
2020-10-16 07:18:29 +00:00
|
|
|
{
|
2021-06-11 11:55:38 +00:00
|
|
|
public LegacyOldStyleFill(ISkin skin)
|
|
|
|
: base(skin)
|
2020-10-16 07:18:29 +00:00
|
|
|
{
|
2021-06-11 11:55:38 +00:00
|
|
|
Position = new Vector2(3, 10) * 1.6f;
|
|
|
|
}
|
|
|
|
}
|
2020-10-16 07:45:28 +00:00
|
|
|
|
2021-06-11 11:55:38 +00:00
|
|
|
internal class LegacyNewStyleFill : LegacyFill
|
|
|
|
{
|
|
|
|
public LegacyNewStyleFill(ISkin skin)
|
|
|
|
: base(skin)
|
|
|
|
{
|
2020-10-16 07:18:29 +00:00
|
|
|
Position = new Vector2(7.5f, 7.8f) * 1.6f;
|
2020-10-16 07:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
2020-10-16 08:09:00 +00:00
|
|
|
Colour = getFillColour(Current.Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract class LegacyMarker : LegacyHealthPiece
|
|
|
|
{
|
|
|
|
protected Sprite Main;
|
|
|
|
|
|
|
|
private Sprite explode;
|
|
|
|
|
|
|
|
protected LegacyMarker()
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
Main = CreateSprite(),
|
|
|
|
explode = CreateSprite().With(s =>
|
|
|
|
{
|
|
|
|
s.Alpha = 0;
|
|
|
|
s.Blending = BlendingParameters.Additive;
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract Sprite CreateSprite();
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Current.BindValueChanged(val =>
|
|
|
|
{
|
|
|
|
if (val.NewValue > val.OldValue)
|
|
|
|
bulgeMain();
|
|
|
|
});
|
2020-10-16 07:45:28 +00:00
|
|
|
}
|
2020-10-16 08:09:00 +00:00
|
|
|
|
|
|
|
public override void Flash(JudgementResult result)
|
|
|
|
{
|
|
|
|
bulgeMain();
|
|
|
|
|
2020-10-16 08:24:56 +00:00
|
|
|
bool isEpic = Current.Value >= epic_cutoff;
|
|
|
|
|
|
|
|
explode.Blending = isEpic ? BlendingParameters.Additive : BlendingParameters.Inherit;
|
|
|
|
explode.ScaleTo(1).Then().ScaleTo(isEpic ? 2 : 1.6f, 120);
|
2020-10-16 08:09:00 +00:00
|
|
|
explode.FadeOutFromOne(120);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void bulgeMain() =>
|
|
|
|
Main.ScaleTo(1.4f).Then().ScaleTo(1, 200, Easing.Out);
|
2020-10-16 07:45:28 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 07:56:24 +00:00
|
|
|
public class LegacyHealthPiece : CompositeDrawable
|
2020-10-16 07:45:28 +00:00
|
|
|
{
|
|
|
|
public Bindable<double> Current { get; } = new Bindable<double>();
|
|
|
|
|
|
|
|
public virtual void Flash(JudgementResult result)
|
|
|
|
{
|
2020-10-16 07:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-16 05:39:45 +00:00
|
|
|
}
|
|
|
|
}
|