1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 07:22:54 +08:00

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

@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Gameplay
};
Add(score);
ComboCounter comboCounter = new StandardComboCounter
ComboCounter comboCounter = new LegacyComboCounter
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,

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

@ -4,26 +4,46 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Play.HUD;
using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Graphics.UserInterface
namespace osu.Game.Screens.Play.HUD
{
/// <summary>
/// Used as an accuracy counter. Represented visually as a percentage.
/// </summary>
public class SimpleComboCounter : RollingCounter<int>, IComboCounter
public class DefaultComboCounter : RollingCounter<int>, IComboCounter
{
private readonly Vector2 offset = new Vector2(20, 5);
protected override double RollingDuration => 750;
public SimpleComboCounter()
[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";

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(),

View File

@ -18,6 +18,7 @@ using osu.Game.Audio;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD;
using osuTK.Graphics;
namespace osu.Game.Skinning
@ -327,6 +328,17 @@ namespace osu.Game.Skinning
{
switch (component)
{
case HUDSkinComponent hudComponent:
{
switch (hudComponent.Component)
{
case HUDSkinComponents.ComboCounter:
return new LegacyComboCounter();
}
return null;
}
case GameplaySkinComponent<HitResult> resultComponent:
switch (resultComponent.Component)
{