2019-01-24 16:43:03 +08: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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 16:51:03 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-10-14 17:15:06 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-10-14 17:15:06 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-10-14 16:51:03 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Skinning;
|
2020-10-14 17:15:06 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Uses the 'x' symbol and has a pop-out effect while rolling over.
|
|
|
|
|
/// </summary>
|
2020-10-14 17:15:06 +08:00
|
|
|
|
public class LegacyComboCounter : CompositeDrawable, IComboCounter
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
public Bindable<int> Current { get; } = new BindableInt { MinValue = 0, };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private uint scheduledPopOutCurrentId;
|
|
|
|
|
|
|
|
|
|
private const double pop_out_duration = 150;
|
|
|
|
|
|
|
|
|
|
private const Easing pop_out_easing = Easing.None;
|
|
|
|
|
|
|
|
|
|
private const double fade_out_duration = 100;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Duration in milliseconds for the counter roll-up animation for each element.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const double rolling_duration = 20;
|
|
|
|
|
|
|
|
|
|
private Drawable popOutCount;
|
|
|
|
|
|
|
|
|
|
private Drawable displayedCountSpriteText;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:15:06 +08:00
|
|
|
|
private int previousValue;
|
2020-10-14 17:34:51 +08:00
|
|
|
|
|
2020-10-14 17:15:06 +08:00
|
|
|
|
private int displayedCount;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private bool isRolling;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private ISkinSource skin { get; set; }
|
|
|
|
|
|
2020-10-14 16:21:56 +08:00
|
|
|
|
public LegacyComboCounter()
|
|
|
|
|
{
|
2020-10-14 17:15:06 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
2020-10-14 16:21:56 +08:00
|
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
|
Origin = Anchor.BottomLeft;
|
|
|
|
|
|
2020-10-15 15:55:47 +08:00
|
|
|
|
Margin = new MarginPadding(10);
|
2020-10-14 17:15:06 +08:00
|
|
|
|
|
2020-10-14 18:15:52 +08:00
|
|
|
|
Scale = new Vector2(1.2f);
|
2020-10-14 16:21:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:15:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Value shown at the current moment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual int DisplayedCount
|
2020-10-14 16:51:03 +08:00
|
|
|
|
{
|
2020-10-14 17:15:06 +08:00
|
|
|
|
get => displayedCount;
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private set
|
2020-10-14 17:15:06 +08:00
|
|
|
|
{
|
|
|
|
|
if (displayedCount.Equals(value))
|
|
|
|
|
return;
|
2020-10-14 16:51:03 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
if (isRolling)
|
|
|
|
|
onDisplayedCountRolling(displayedCount, value);
|
|
|
|
|
else if (displayedCount + 1 == value)
|
|
|
|
|
onDisplayedCountIncrement(value);
|
|
|
|
|
else
|
|
|
|
|
onDisplayedCountChange(value);
|
2020-10-14 17:15:06 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
displayedCount = value;
|
|
|
|
|
}
|
2020-10-14 17:15:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
InternalChildren = new[]
|
2020-10-14 17:15:06 +08:00
|
|
|
|
{
|
2021-03-07 07:18:31 +08:00
|
|
|
|
popOutCount = new LegacySpriteText(skin, LegacyFont.Combo)
|
2020-10-14 17:15:06 +08:00
|
|
|
|
{
|
2021-03-07 07:18:31 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
Margin = new MarginPadding(0.05f),
|
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
|
},
|
|
|
|
|
displayedCountSpriteText = new LegacySpriteText(skin, LegacyFont.Combo)
|
2020-10-14 17:15:06 +08:00
|
|
|
|
{
|
2021-03-07 07:18:31 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
2020-10-14 17:15:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Current.ValueChanged += combo => updateCount(combo.NewValue == 0);
|
2020-10-14 16:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
((IHasText)displayedCountSpriteText).Text = formatCount(Current.Value);
|
2020-10-14 17:15:06 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
displayedCountSpriteText.Anchor = Anchor;
|
|
|
|
|
displayedCountSpriteText.Origin = Origin;
|
|
|
|
|
popOutCount.Origin = Origin;
|
|
|
|
|
popOutCount.Anchor = Anchor;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
updateCount(false);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void updateCount(bool rolling)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
int prev = previousValue;
|
|
|
|
|
previousValue = Current.Value;
|
|
|
|
|
|
|
|
|
|
if (!IsLoaded)
|
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
if (!rolling)
|
|
|
|
|
{
|
|
|
|
|
FinishTransforms(false, nameof(DisplayedCount));
|
|
|
|
|
isRolling = false;
|
|
|
|
|
DisplayedCount = prev;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
if (prev + 1 == Current.Value)
|
|
|
|
|
onCountIncrement(prev, Current.Value);
|
|
|
|
|
else
|
|
|
|
|
onCountChange(prev, Current.Value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
onCountRolling(displayedCount, Current.Value);
|
|
|
|
|
isRolling = true;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void transformPopOut(int newValue)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
((IHasText)popOutCount).Text = formatCount(newValue);
|
|
|
|
|
|
|
|
|
|
popOutCount.ScaleTo(1.6f);
|
|
|
|
|
popOutCount.FadeTo(0.75f);
|
|
|
|
|
popOutCount.MoveTo(Vector2.Zero);
|
|
|
|
|
|
|
|
|
|
popOutCount.ScaleTo(1, pop_out_duration, pop_out_easing);
|
|
|
|
|
popOutCount.FadeOut(pop_out_duration, pop_out_easing);
|
|
|
|
|
popOutCount.MoveTo(displayedCountSpriteText.Position, pop_out_duration, pop_out_easing);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void transformNoPopOut(int newValue)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
((IHasText)displayedCountSpriteText).Text = formatCount(newValue);
|
|
|
|
|
|
|
|
|
|
displayedCountSpriteText.ScaleTo(1);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void transformPopOutSmall(int newValue)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
((IHasText)displayedCountSpriteText).Text = formatCount(newValue);
|
|
|
|
|
displayedCountSpriteText.ScaleTo(1.1f);
|
|
|
|
|
displayedCountSpriteText.ScaleTo(1, pop_out_duration, pop_out_easing);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void scheduledPopOutSmall(uint id)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
// Too late; scheduled task invalidated
|
2020-10-14 17:34:51 +08:00
|
|
|
|
if (id != scheduledPopOutCurrentId)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
DisplayedCount++;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void onCountIncrement(int currentValue, int newValue)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
scheduledPopOutCurrentId++;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
if (DisplayedCount < currentValue)
|
|
|
|
|
DisplayedCount++;
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
displayedCountSpriteText.Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
transformPopOut(newValue);
|
|
|
|
|
|
|
|
|
|
uint newTaskId = scheduledPopOutCurrentId;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
Scheduler.AddDelayed(delegate
|
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
scheduledPopOutSmall(newTaskId);
|
|
|
|
|
}, pop_out_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void onCountRolling(int currentValue, int newValue)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
scheduledPopOutCurrentId++;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
// Hides displayed count if was increasing from 0 to 1 but didn't finish
|
|
|
|
|
if (currentValue == 0 && newValue == 0)
|
|
|
|
|
displayedCountSpriteText.FadeOut(fade_out_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
transformRoll(currentValue, newValue);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void onCountChange(int currentValue, int newValue)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
scheduledPopOutCurrentId++;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (newValue == 0)
|
2020-10-14 17:34:51 +08:00
|
|
|
|
displayedCountSpriteText.FadeOut();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
DisplayedCount = newValue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void onDisplayedCountRolling(int currentValue, int newValue)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
if (newValue == 0)
|
|
|
|
|
displayedCountSpriteText.FadeOut(fade_out_duration);
|
|
|
|
|
else
|
|
|
|
|
displayedCountSpriteText.Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
transformNoPopOut(newValue);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void onDisplayedCountChange(int newValue)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
displayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
|
|
|
|
|
transformNoPopOut(newValue);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2020-10-14 17:15:06 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void onDisplayedCountIncrement(int newValue)
|
2020-10-14 17:15:06 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
displayedCountSpriteText.Show();
|
|
|
|
|
transformPopOutSmall(newValue);
|
2020-10-14 17:15:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void transformRoll(int currentValue, int newValue) =>
|
|
|
|
|
this.TransformTo(nameof(DisplayedCount), newValue, getProportionalDuration(currentValue, newValue), Easing.None);
|
2020-10-14 17:15:06 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private string formatCount(int count) => $@"{count}x";
|
2020-10-14 17:15:06 +08:00
|
|
|
|
|
|
|
|
|
private double getProportionalDuration(int currentValue, int newValue)
|
|
|
|
|
{
|
|
|
|
|
double difference = currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
2020-10-14 17:34:51 +08:00
|
|
|
|
return difference * rolling_duration;
|
2020-10-14 17:15:06 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|