Add basic legacy combo counter and updating positioning logic

This commit is contained in:
Dean Herbert
2020-10-14 17:21:56 +09:00
parent 6eb3176776
commit 2fce064e32
7 changed files with 54 additions and 41 deletions

View File

@ -9,9 +9,9 @@ using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Play.HUD
{
public abstract class ComboCounter : Container
public abstract class ComboCounter : Container, IComboCounter
{
public BindableInt Current = new BindableInt
public Bindable<int> Current { get; } = new BindableInt
{
MinValue = 0,
};

View File

@ -0,0 +1,60 @@
// 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 System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Screens.Play.HUD
{
public class DefaultComboCounter : RollingCounter<int>, IComboCounter
{
private readonly Vector2 offset = new Vector2(20, 5);
protected override double RollingDuration => 750;
[Resolved(canBeNull: true)]
private HUDOverlay hud { get; set; }
public DefaultComboCounter()
{
Current.Value = DisplayedCount = 0;
Anchor = Anchor.TopCentre;
Origin = Anchor.TopLeft;
Position = offset;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours) => Colour = colours.BlueLighter;
protected override void Update()
{
base.Update();
if (hud != null)
{
// for now align with the score counter. eventually this will be user customisable.
Position += ToLocalSpace(hud.ScoreCounter.ScreenSpaceDrawQuad.TopRight) + offset;
}
}
protected override string FormatCount(int count)
{
return $@"{count}x";
}
protected override double GetProportionalDuration(int currentValue, int newValue)
{
return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f;
}
protected override OsuSpriteText CreateSpriteText()
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(size: 20f));
}
}

View File

@ -9,7 +9,7 @@ namespace osu.Game.Screens.Play.HUD
/// <summary>
/// Uses the 'x' symbol and has a pop-out effect while rolling over.
/// </summary>
public class StandardComboCounter : ComboCounter
public class LegacyComboCounter : ComboCounter
{
protected uint ScheduledPopOutCurrentId;
@ -18,6 +18,14 @@ namespace osu.Game.Screens.Play.HUD
public new Vector2 PopOutScale = new Vector2(1.6f);
public LegacyComboCounter()
{
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
Margin = new MarginPadding { Top = 5, Left = 20 };
}
protected override void LoadComplete()
{
base.LoadComplete();

View File

@ -3,9 +3,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Skinning;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD
{
@ -21,39 +19,14 @@ namespace osu.Game.Screens.Play.HUD
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
{
// todo: unnecessary?
if (skinnedCounter != null)
{
Current.UnbindFrom(skinnedCounter.Current);
}
base.SkinChanged(skin, allowFallback);
// temporary layout code, will eventually be replaced by the skin layout system.
if (Drawable is SimpleComboCounter)
{
Drawable.BypassAutoSizeAxes = Axes.X;
Drawable.Anchor = Anchor.TopRight;
Drawable.Origin = Anchor.TopLeft;
Drawable.Margin = new MarginPadding { Top = 5, Left = 20 };
}
else
{
Drawable.BypassAutoSizeAxes = Axes.X;
Drawable.Anchor = Anchor.BottomLeft;
Drawable.Origin = Anchor.BottomLeft;
Drawable.Margin = new MarginPadding { Top = 5, Left = 20 };
}
skinnedCounter = (IComboCounter)Drawable;
Current.BindTo(skinnedCounter.Current);
skinnedCounter.Current.BindTo(Current);
}
private static Drawable createDefault(ISkinComponent skinComponent) => new SimpleComboCounter();
private static Drawable createDefault(ISkinComponent skinComponent) => new DefaultComboCounter();
public Bindable<int> Current { get; } = new Bindable<int>();
public void UpdateCombo(int combo, Color4? hitObjectColour = null) => Current.Value = combo;
}
}

View File

@ -22,6 +22,7 @@ using osuTK.Input;
namespace osu.Game.Screens.Play
{
[Cached]
public class HUDOverlay : Container
{
private const float fade_duration = 400;
@ -104,7 +105,6 @@ namespace osu.Game.Screens.Play
{
AccuracyCounter = CreateAccuracyCounter(),
ScoreCounter = CreateScoreCounter(),
ComboCounter = CreateComboCounter(),
},
},
ComboCounter = CreateComboCounter(),