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;
|
2017-07-15 00:18:12 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-10-14 17:15:06 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-03 15:47:47 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-07-28 08:36:26 +08:00
|
|
|
|
namespace osu.Game.Skinning
|
2017-03-10 11:26:46 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Uses the 'x' symbol and has a pop-out effect while rolling over.
|
|
|
|
|
/// </summary>
|
2023-12-30 10:29:18 +08:00
|
|
|
|
public abstract partial class LegacyComboCounter : CompositeDrawable, ISerialisableDrawable
|
2017-03-10 11:26:46 +08:00
|
|
|
|
{
|
2021-05-18 14:08:56 +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 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;
|
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
protected readonly LegacySpriteText PopOutCountText;
|
|
|
|
|
protected readonly LegacySpriteText DisplayedCountText;
|
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;
|
|
|
|
|
|
2021-05-18 14:08:56 +08:00
|
|
|
|
private readonly Container counterContainer;
|
|
|
|
|
|
2021-06-08 20:22:35 +08:00
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
2021-06-07 11:47:47 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
protected LegacyComboCounter()
|
2020-10-14 16:21:56 +08:00
|
|
|
|
{
|
2020-10-14 17:15:06 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
2021-12-08 13:56:38 +08:00
|
|
|
|
InternalChildren = new[]
|
2021-05-18 14:08:56 +08:00
|
|
|
|
{
|
2021-12-08 13:56:38 +08:00
|
|
|
|
counterContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
AlwaysPresent = true,
|
|
|
|
|
Children = new[]
|
2021-05-18 14:08:56 +08:00
|
|
|
|
{
|
2023-12-30 10:29:18 +08:00
|
|
|
|
PopOutCountText = new LegacySpriteText(LegacyFont.Combo)
|
2021-12-26 23:44:59 +08:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
|
BypassAutoSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2023-12-30 10:29:18 +08:00
|
|
|
|
DisplayedCountText = new LegacySpriteText(LegacyFont.Combo)
|
2021-12-08 13:56:38 +08:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
2022-03-28 22:36:37 +08:00
|
|
|
|
AlwaysPresent = true,
|
|
|
|
|
BypassAutoSizeAxes = Axes.Both,
|
2021-12-08 13:56:38 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2021-05-18 14:08:56 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
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)
|
2022-02-02 04:30:28 +08:00
|
|
|
|
onDisplayedCountRolling(value);
|
2020-10-14 17:34:51 +08:00
|
|
|
|
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]
|
2022-03-29 00:08:35 +08:00
|
|
|
|
private void load(ScoreProcessor scoreProcessor)
|
2020-10-14 17:15:06 +08:00
|
|
|
|
{
|
2021-05-03 15:47:47 +08:00
|
|
|
|
Current.BindTo(scoreProcessor.Combo);
|
2020-10-14 16:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 11:26:46 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
DisplayedCountText.Text = FormatCount(Current.Value);
|
|
|
|
|
PopOutCountText.Text = FormatCount(Current.Value);
|
2022-03-28 22:36:37 +08:00
|
|
|
|
|
2021-05-03 19:11:24 +08:00
|
|
|
|
Current.BindValueChanged(combo => updateCount(combo.NewValue == 0), true);
|
2022-03-29 00:08:35 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
counterContainer.Size = DisplayedCountText.Size;
|
2022-03-28 22:36:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void updateCount(bool rolling)
|
2017-03-10 11:26:46 +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));
|
2023-12-30 10:29:18 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
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)
|
2023-12-30 10:29:18 +08:00
|
|
|
|
OnCountIncrement();
|
2020-10-14 17:34:51 +08:00
|
|
|
|
else
|
2023-12-30 10:29:18 +08:00
|
|
|
|
OnCountChange();
|
2020-10-14 17:34:51 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-12-30 10:29:18 +08:00
|
|
|
|
OnCountRolling();
|
2020-10-14 17:34:51 +08:00
|
|
|
|
isRolling = true;
|
|
|
|
|
}
|
2017-03-10 11:26:46 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raised when the counter should display the new value with transitions.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void OnCountIncrement()
|
2017-03-10 11:26:46 +08:00
|
|
|
|
{
|
2023-12-30 10:29:18 +08:00
|
|
|
|
if (DisplayedCount < Current.Value - 1)
|
2017-03-10 11:26:46 +08:00
|
|
|
|
DisplayedCount++;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
DisplayedCount++;
|
2017-03-10 11:26:46 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raised when the counter should roll to the new combo value (usually roll back to zero).
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void OnCountRolling()
|
2017-03-10 11:26:46 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
// Hides displayed count if was increasing from 0 to 1 but didn't finish
|
2023-12-30 10:29:18 +08:00
|
|
|
|
if (DisplayedCount == 0 && Current.Value == 0)
|
|
|
|
|
DisplayedCountText.FadeOut(fade_out_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
transformRoll(DisplayedCount, Current.Value);
|
2017-03-10 11:26:46 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raised when the counter should display the new combo value without any transitions.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void OnCountChange()
|
2017-03-10 11:26:46 +08:00
|
|
|
|
{
|
2023-12-30 10:29:18 +08:00
|
|
|
|
if (Current.Value == 0)
|
|
|
|
|
DisplayedCountText.FadeOut();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
DisplayedCount = Current.Value;
|
2017-03-10 11:26:46 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-02-02 04:30:28 +08:00
|
|
|
|
private void onDisplayedCountRolling(int newValue)
|
2017-03-10 11:26:46 +08:00
|
|
|
|
{
|
2020-10-14 17:34:51 +08:00
|
|
|
|
if (newValue == 0)
|
2023-12-30 10:29:18 +08:00
|
|
|
|
DisplayedCountText.FadeOut(fade_out_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
DisplayedCountText.Text = FormatCount(newValue);
|
|
|
|
|
counterContainer.Size = DisplayedCountText.Size;
|
2017-03-10 11:26:46 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void onDisplayedCountChange(int newValue)
|
2017-03-10 11:26:46 +08:00
|
|
|
|
{
|
2023-12-30 10:29:18 +08:00
|
|
|
|
DisplayedCountText.FadeTo(newValue == 0 ? 0 : 1);
|
|
|
|
|
DisplayedCountText.Text = FormatCount(newValue);
|
|
|
|
|
|
|
|
|
|
counterContainer.Size = DisplayedCountText.Size;
|
2017-03-10 11:26:46 +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
|
|
|
|
{
|
2023-12-30 10:29:18 +08:00
|
|
|
|
DisplayedCountText.Text = FormatCount(newValue);
|
|
|
|
|
|
|
|
|
|
counterContainer.Size = DisplayedCountText.Size;
|
2020-10-14 17:15:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 17:34:51 +08:00
|
|
|
|
private void transformRoll(int currentValue, int newValue) =>
|
2021-07-05 23:52:39 +08:00
|
|
|
|
this.TransformTo(nameof(DisplayedCount), newValue, getProportionalDuration(currentValue, newValue));
|
2020-10-14 17:15:06 +08:00
|
|
|
|
|
2023-12-30 10:29:18 +08:00
|
|
|
|
protected virtual string FormatCount(int count) => $@"{count}";
|
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
|
|
|
|
}
|
2017-03-10 11:26:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|