mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Combine LegacyComboCounter and ComboCounter classes
This commit is contained in:
@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
};
|
};
|
||||||
Add(score);
|
Add(score);
|
||||||
|
|
||||||
ComboCounter comboCounter = new LegacyComboCounter
|
LegacyComboCounter comboCounter = new LegacyComboCounter
|
||||||
{
|
{
|
||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
|
@ -1,191 +0,0 @@
|
|||||||
// 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.Graphics.Sprites;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD
|
|
||||||
{
|
|
||||||
public abstract class ComboCounter : Container, IComboCounter
|
|
||||||
{
|
|
||||||
public Bindable<int> Current { get; } = new BindableInt
|
|
||||||
{
|
|
||||||
MinValue = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
public bool IsRolling { get; protected set; }
|
|
||||||
|
|
||||||
protected Drawable PopOutCount;
|
|
||||||
|
|
||||||
protected virtual double PopOutDuration => 150;
|
|
||||||
protected virtual float PopOutScale => 2.0f;
|
|
||||||
protected virtual Easing PopOutEasing => Easing.None;
|
|
||||||
protected virtual float PopOutInitialAlpha => 0.75f;
|
|
||||||
|
|
||||||
protected virtual double FadeOutDuration => 100;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Duration in milliseconds for the counter roll-up animation for each element.
|
|
||||||
/// </summary>
|
|
||||||
protected virtual double RollingDuration => 20;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Easing for the counter rollover animation.
|
|
||||||
/// </summary>
|
|
||||||
protected Easing RollingEasing => Easing.None;
|
|
||||||
|
|
||||||
protected Drawable DisplayedCountSpriteText;
|
|
||||||
|
|
||||||
private int previousValue;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Base of all combo counters.
|
|
||||||
/// </summary>
|
|
||||||
protected ComboCounter()
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
DisplayedCountSpriteText = CreateSpriteText().With(s =>
|
|
||||||
{
|
|
||||||
s.Alpha = 0;
|
|
||||||
}),
|
|
||||||
PopOutCount = CreateSpriteText().With(s =>
|
|
||||||
{
|
|
||||||
s.Alpha = 0;
|
|
||||||
s.Margin = new MarginPadding(0.05f);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
Current.ValueChanged += combo => updateCount(combo.NewValue == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual Drawable CreateSpriteText() => new OsuSpriteText();
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
((IHasText)DisplayedCountSpriteText).Text = FormatCount(Current.Value);
|
|
||||||
DisplayedCountSpriteText.Anchor = Anchor;
|
|
||||||
DisplayedCountSpriteText.Origin = Origin;
|
|
||||||
|
|
||||||
StopRolling();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int displayedCount;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Value shown at the current moment.
|
|
||||||
/// </summary>
|
|
||||||
public virtual int DisplayedCount
|
|
||||||
{
|
|
||||||
get => displayedCount;
|
|
||||||
protected set
|
|
||||||
{
|
|
||||||
if (displayedCount.Equals(value))
|
|
||||||
return;
|
|
||||||
|
|
||||||
updateDisplayedCount(displayedCount, value, IsRolling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Increments the combo by an amount.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount"></param>
|
|
||||||
public void Increment(int amount = 1)
|
|
||||||
{
|
|
||||||
Current.Value += amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Stops rollover animation, forcing the displayed count to be the actual count.
|
|
||||||
/// </summary>
|
|
||||||
public void StopRolling()
|
|
||||||
{
|
|
||||||
updateCount(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual string FormatCount(int count)
|
|
||||||
{
|
|
||||||
return count.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnCountRolling(int currentValue, int newValue)
|
|
||||||
{
|
|
||||||
transformRoll(currentValue, newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnCountIncrement(int currentValue, int newValue)
|
|
||||||
{
|
|
||||||
DisplayedCount = newValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnCountChange(int currentValue, int newValue)
|
|
||||||
{
|
|
||||||
DisplayedCount = newValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double getProportionalDuration(int currentValue, int newValue)
|
|
||||||
{
|
|
||||||
double difference = currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
|
||||||
return difference * RollingDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDisplayedCount(int currentValue, int newValue, bool rolling)
|
|
||||||
{
|
|
||||||
displayedCount = newValue;
|
|
||||||
if (rolling)
|
|
||||||
OnDisplayedCountRolling(currentValue, newValue);
|
|
||||||
else if (currentValue + 1 == newValue)
|
|
||||||
OnDisplayedCountIncrement(newValue);
|
|
||||||
else
|
|
||||||
OnDisplayedCountChange(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCount(bool rolling)
|
|
||||||
{
|
|
||||||
int prev = previousValue;
|
|
||||||
previousValue = Current.Value;
|
|
||||||
|
|
||||||
if (!IsLoaded)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!rolling)
|
|
||||||
{
|
|
||||||
FinishTransforms(false, nameof(DisplayedCount));
|
|
||||||
IsRolling = false;
|
|
||||||
DisplayedCount = prev;
|
|
||||||
|
|
||||||
if (prev + 1 == Current.Value)
|
|
||||||
OnCountIncrement(prev, Current.Value);
|
|
||||||
else
|
|
||||||
OnCountChange(prev, Current.Value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OnCountRolling(displayedCount, Current.Value);
|
|
||||||
IsRolling = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void transformRoll(int currentValue, int newValue)
|
|
||||||
{
|
|
||||||
this.TransformTo(nameof(DisplayedCount), newValue, getProportionalDuration(currentValue, newValue), RollingEasing);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void OnDisplayedCountRolling(int currentValue, int newValue);
|
|
||||||
protected abstract void OnDisplayedCountIncrement(int newValue);
|
|
||||||
protected abstract void OnDisplayedCountChange(int newValue);
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,62 +2,124 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osuTK;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD
|
namespace osu.Game.Screens.Play.HUD
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Uses the 'x' symbol and has a pop-out effect while rolling over.
|
/// Uses the 'x' symbol and has a pop-out effect while rolling over.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LegacyComboCounter : ComboCounter
|
public class LegacyComboCounter : CompositeDrawable, IComboCounter
|
||||||
{
|
{
|
||||||
protected uint ScheduledPopOutCurrentId;
|
protected uint ScheduledPopOutCurrentId;
|
||||||
|
|
||||||
protected virtual float PopOutSmallScale => 1.1f;
|
protected virtual float PopOutSmallScale => 1.1f;
|
||||||
protected virtual bool CanPopOutWhileRolling => false;
|
protected virtual bool CanPopOutWhileRolling => false;
|
||||||
|
|
||||||
public new Vector2 PopOutScale = new Vector2(1.6f);
|
protected Drawable PopOutCount;
|
||||||
|
protected Drawable DisplayedCountSpriteText;
|
||||||
|
private int previousValue;
|
||||||
|
private int displayedCount;
|
||||||
|
|
||||||
public LegacyComboCounter()
|
public LegacyComboCounter()
|
||||||
{
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
Anchor = Anchor.BottomLeft;
|
Anchor = Anchor.BottomLeft;
|
||||||
Origin = Anchor.BottomLeft;
|
Origin = Anchor.BottomLeft;
|
||||||
|
|
||||||
Margin = new MarginPadding { Top = 5, Left = 20 };
|
Margin = new MarginPadding { Bottom = 20, Left = 20 };
|
||||||
|
|
||||||
|
Scale = new Vector2(1.6f);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private ISkinSource skin { get; set; }
|
private ISkinSource skin { get; set; }
|
||||||
|
|
||||||
protected override Drawable CreateSpriteText()
|
public Bindable<int> Current { get; } = new BindableInt
|
||||||
{
|
{
|
||||||
return skin?.GetDrawableComponent(new HUDSkinComponent(HUDSkinComponents.ScoreText)) ?? new OsuSpriteText();
|
MinValue = 0,
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
public bool IsRolling { get; protected set; }
|
||||||
new OsuSpriteText
|
protected virtual double PopOutDuration => 150;
|
||||||
|
protected virtual float PopOutScale => 1.6f;
|
||||||
|
protected virtual Easing PopOutEasing => Easing.None;
|
||||||
|
protected virtual float PopOutInitialAlpha => 0.75f;
|
||||||
|
protected virtual double FadeOutDuration => 100;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Duration in milliseconds for the counter roll-up animation for each element.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual double RollingDuration => 20;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Easing for the counter rollover animation.
|
||||||
|
/// </summary>
|
||||||
|
protected Easing RollingEasing => Easing.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Value shown at the current moment.
|
||||||
|
/// </summary>
|
||||||
|
public virtual int DisplayedCount
|
||||||
|
{
|
||||||
|
get => displayedCount;
|
||||||
|
protected set
|
||||||
|
{
|
||||||
|
if (displayedCount.Equals(value))
|
||||||
|
return;
|
||||||
|
|
||||||
|
updateDisplayedCount(displayedCount, value, IsRolling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Drawable CreateSpriteText()
|
||||||
|
{
|
||||||
|
return skin?.GetDrawableComponent(new HUDSkinComponent(HUDSkinComponents.ScoreText)) ?? new OsuSpriteText
|
||||||
{
|
{
|
||||||
Font = OsuFont.Numeric.With(size: 40),
|
Font = OsuFont.Numeric.With(size: 40),
|
||||||
UseFullGlyphHeight = false,
|
UseFullGlyphHeight = false,
|
||||||
});
|
};
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
InternalChildren = new Drawable[]
|
||||||
|
{
|
||||||
|
DisplayedCountSpriteText = CreateSpriteText().With(s =>
|
||||||
|
{
|
||||||
|
s.Alpha = 0;
|
||||||
|
}),
|
||||||
|
PopOutCount = CreateSpriteText().With(s =>
|
||||||
|
{
|
||||||
|
s.Alpha = 0;
|
||||||
|
s.Margin = new MarginPadding(0.05f);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
Current.ValueChanged += combo => updateCount(combo.NewValue == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
((IHasText)DisplayedCountSpriteText).Text = FormatCount(Current.Value);
|
||||||
|
|
||||||
|
DisplayedCountSpriteText.Anchor = Anchor;
|
||||||
|
DisplayedCountSpriteText.Origin = Origin;
|
||||||
PopOutCount.Origin = Origin;
|
PopOutCount.Origin = Origin;
|
||||||
PopOutCount.Anchor = Anchor;
|
PopOutCount.Anchor = Anchor;
|
||||||
}
|
|
||||||
|
|
||||||
protected override string FormatCount(int count)
|
StopRolling();
|
||||||
{
|
|
||||||
return $@"{count}x";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void TransformPopOut(int newValue)
|
protected virtual void TransformPopOut(int newValue)
|
||||||
@ -101,7 +163,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
DisplayedCount++;
|
DisplayedCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnCountRolling(int currentValue, int newValue)
|
protected void OnCountRolling(int currentValue, int newValue)
|
||||||
{
|
{
|
||||||
ScheduledPopOutCurrentId++;
|
ScheduledPopOutCurrentId++;
|
||||||
|
|
||||||
@ -109,10 +171,10 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
if (currentValue == 0 && newValue == 0)
|
if (currentValue == 0 && newValue == 0)
|
||||||
DisplayedCountSpriteText.FadeOut(FadeOutDuration);
|
DisplayedCountSpriteText.FadeOut(FadeOutDuration);
|
||||||
|
|
||||||
base.OnCountRolling(currentValue, newValue);
|
transformRoll(currentValue, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnCountIncrement(int currentValue, int newValue)
|
protected void OnCountIncrement(int currentValue, int newValue)
|
||||||
{
|
{
|
||||||
ScheduledPopOutCurrentId++;
|
ScheduledPopOutCurrentId++;
|
||||||
|
|
||||||
@ -130,17 +192,17 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
}, PopOutDuration);
|
}, PopOutDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnCountChange(int currentValue, int newValue)
|
protected void OnCountChange(int currentValue, int newValue)
|
||||||
{
|
{
|
||||||
ScheduledPopOutCurrentId++;
|
ScheduledPopOutCurrentId++;
|
||||||
|
|
||||||
if (newValue == 0)
|
if (newValue == 0)
|
||||||
DisplayedCountSpriteText.FadeOut();
|
DisplayedCountSpriteText.FadeOut();
|
||||||
|
|
||||||
base.OnCountChange(currentValue, newValue);
|
DisplayedCount = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDisplayedCountRolling(int currentValue, int newValue)
|
protected void OnDisplayedCountRolling(int currentValue, int newValue)
|
||||||
{
|
{
|
||||||
if (newValue == 0)
|
if (newValue == 0)
|
||||||
DisplayedCountSpriteText.FadeOut(FadeOutDuration);
|
DisplayedCountSpriteText.FadeOut(FadeOutDuration);
|
||||||
@ -153,18 +215,88 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
TransformNoPopOut(newValue);
|
TransformNoPopOut(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDisplayedCountChange(int newValue)
|
protected void OnDisplayedCountChange(int newValue)
|
||||||
{
|
{
|
||||||
DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
|
DisplayedCountSpriteText.FadeTo(newValue == 0 ? 0 : 1);
|
||||||
|
|
||||||
TransformNoPopOut(newValue);
|
TransformNoPopOut(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDisplayedCountIncrement(int newValue)
|
protected void OnDisplayedCountIncrement(int newValue)
|
||||||
{
|
{
|
||||||
DisplayedCountSpriteText.Show();
|
DisplayedCountSpriteText.Show();
|
||||||
|
|
||||||
TransformPopOutSmall(newValue);
|
TransformPopOutSmall(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Increments the combo by an amount.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="amount"></param>
|
||||||
|
public void Increment(int amount = 1)
|
||||||
|
{
|
||||||
|
Current.Value += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops rollover animation, forcing the displayed count to be the actual count.
|
||||||
|
/// </summary>
|
||||||
|
public void StopRolling()
|
||||||
|
{
|
||||||
|
updateCount(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string FormatCount(int count)
|
||||||
|
{
|
||||||
|
return $@"{count}x";
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getProportionalDuration(int currentValue, int newValue)
|
||||||
|
{
|
||||||
|
double difference = currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||||
|
return difference * RollingDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDisplayedCount(int currentValue, int newValue, bool rolling)
|
||||||
|
{
|
||||||
|
displayedCount = newValue;
|
||||||
|
if (rolling)
|
||||||
|
OnDisplayedCountRolling(currentValue, newValue);
|
||||||
|
else if (currentValue + 1 == newValue)
|
||||||
|
OnDisplayedCountIncrement(newValue);
|
||||||
|
else
|
||||||
|
OnDisplayedCountChange(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCount(bool rolling)
|
||||||
|
{
|
||||||
|
int prev = previousValue;
|
||||||
|
previousValue = Current.Value;
|
||||||
|
|
||||||
|
if (!IsLoaded)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!rolling)
|
||||||
|
{
|
||||||
|
FinishTransforms(false, nameof(DisplayedCount));
|
||||||
|
IsRolling = false;
|
||||||
|
DisplayedCount = prev;
|
||||||
|
|
||||||
|
if (prev + 1 == Current.Value)
|
||||||
|
OnCountIncrement(prev, Current.Value);
|
||||||
|
else
|
||||||
|
OnCountChange(prev, Current.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OnCountRolling(displayedCount, Current.Value);
|
||||||
|
IsRolling = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transformRoll(int currentValue, int newValue)
|
||||||
|
{
|
||||||
|
this.TransformTo<LegacyComboCounter, int>(nameof(DisplayedCount), newValue, getProportionalDuration(currentValue, newValue), RollingEasing);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ using osu.Game.Beatmaps.Formats;
|
|||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Screens.Play.HUD;
|
using osu.Game.Screens.Play.HUD;
|
||||||
using osuTK;
|
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Skinning
|
namespace osu.Game.Skinning
|
||||||
|
Reference in New Issue
Block a user