mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 17:02:57 +08:00
Abstractify performance points calculation to a base class
This commit is contained in:
parent
e1744df2b7
commit
92f455f199
91
osu.Game/Screens/Play/HUD/DefaultPerformancePointsCounter.cs
Normal file
91
osu.Game/Screens/Play/HUD/DefaultPerformancePointsCounter.cs
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Resources.Localisation.Web;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Play.HUD
|
||||||
|
{
|
||||||
|
public partial class DefaultPerformancePointsCounter : PerformancePointsCounter
|
||||||
|
{
|
||||||
|
protected override bool IsRollingProportional => true;
|
||||||
|
|
||||||
|
protected override double RollingDuration => 500;
|
||||||
|
|
||||||
|
private const float alpha_when_invalid = 0.3f;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours)
|
||||||
|
{
|
||||||
|
Colour = colours.BlueLighter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsValid
|
||||||
|
{
|
||||||
|
get => base.IsValid;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == IsValid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
base.IsValid = value;
|
||||||
|
DrawableCount.FadeTo(value ? 1 : alpha_when_invalid, 1000, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override LocalisableString FormatCount(int count) => count.ToString(@"D");
|
||||||
|
|
||||||
|
protected override IHasText CreateText() => new TextComponent
|
||||||
|
{
|
||||||
|
Alpha = alpha_when_invalid
|
||||||
|
};
|
||||||
|
|
||||||
|
private partial class TextComponent : CompositeDrawable, IHasText
|
||||||
|
{
|
||||||
|
public LocalisableString Text
|
||||||
|
{
|
||||||
|
get => text.Text;
|
||||||
|
set => text.Text = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly OsuSpriteText text;
|
||||||
|
|
||||||
|
public TextComponent()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
InternalChild = new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Spacing = new Vector2(2),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
text = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
Text = BeatmapsetsStrings.ShowScoreboardHeaderspp,
|
||||||
|
Font = OsuFont.Numeric.With(size: 8),
|
||||||
|
Padding = new MarginPadding { Bottom = 1.5f }, // align baseline better
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,16 +13,9 @@ using JetBrains.Annotations;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Localisation;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Resources.Localisation.Web;
|
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Difficulty;
|
using osu.Game.Rulesets.Difficulty;
|
||||||
using osu.Game.Rulesets.Judgements;
|
using osu.Game.Rulesets.Judgements;
|
||||||
@ -31,7 +24,6 @@ using osu.Game.Rulesets.Objects;
|
|||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osuTK;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD
|
namespace osu.Game.Screens.Play.HUD
|
||||||
{
|
{
|
||||||
@ -39,12 +31,6 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
public bool UsesFixedAnchor { get; set; }
|
public bool UsesFixedAnchor { get; set; }
|
||||||
|
|
||||||
protected override bool IsRollingProportional => true;
|
|
||||||
|
|
||||||
protected override double RollingDuration => 500;
|
|
||||||
|
|
||||||
private const float alpha_when_invalid = 0.3f;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private ScoreProcessor scoreProcessor { get; set; }
|
private ScoreProcessor scoreProcessor { get; set; }
|
||||||
|
|
||||||
@ -60,18 +46,11 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
private PerformanceCalculator performanceCalculator;
|
private PerformanceCalculator performanceCalculator;
|
||||||
private ScoreInfo scoreInfo;
|
private ScoreInfo scoreInfo;
|
||||||
|
|
||||||
public PerformancePointsCounter()
|
|
||||||
{
|
|
||||||
Current.Value = DisplayedCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Mod[] clonedMods;
|
private Mod[] clonedMods;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
|
private void load(BeatmapDifficultyCache difficultyCache)
|
||||||
{
|
{
|
||||||
Colour = colours.BlueLighter;
|
|
||||||
|
|
||||||
if (gameplayState != null)
|
if (gameplayState != null)
|
||||||
{
|
{
|
||||||
performanceCalculator = gameplayState.Ruleset.CreatePerformanceCalculator();
|
performanceCalculator = gameplayState.Ruleset.CreatePerformanceCalculator();
|
||||||
@ -107,19 +86,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
onJudgementChanged(gameplayState.LastJudgementResult.Value);
|
onJudgementChanged(gameplayState.LastJudgementResult.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isValid;
|
public virtual bool IsValid { get; set; }
|
||||||
|
|
||||||
protected bool IsValid
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == isValid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
isValid = value;
|
|
||||||
DrawableCount.FadeTo(isValid ? 1 : alpha_when_invalid, 1000, Easing.OutQuint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onJudgementChanged(JudgementResult judgement)
|
private void onJudgementChanged(JudgementResult judgement)
|
||||||
{
|
{
|
||||||
@ -151,13 +118,6 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
return timedAttributes[Math.Clamp(attribIndex, 0, timedAttributes.Count - 1)].Attributes;
|
return timedAttributes[Math.Clamp(attribIndex, 0, timedAttributes.Count - 1)].Attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override LocalisableString FormatCount(int count) => count.ToString(@"D");
|
|
||||||
|
|
||||||
protected override IHasText CreateText() => new TextComponent
|
|
||||||
{
|
|
||||||
Alpha = alpha_when_invalid
|
|
||||||
};
|
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
@ -171,45 +131,6 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
loadCancellationSource?.Cancel();
|
loadCancellationSource?.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private partial class TextComponent : CompositeDrawable, IHasText
|
|
||||||
{
|
|
||||||
public LocalisableString Text
|
|
||||||
{
|
|
||||||
get => text.Text;
|
|
||||||
set => text.Text = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly OsuSpriteText text;
|
|
||||||
|
|
||||||
public TextComponent()
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both;
|
|
||||||
|
|
||||||
InternalChild = new FillFlowContainer
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Spacing = new Vector2(2),
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
text = new OsuSpriteText
|
|
||||||
{
|
|
||||||
Anchor = Anchor.BottomLeft,
|
|
||||||
Origin = Anchor.BottomLeft,
|
|
||||||
Font = OsuFont.Numeric.With(size: 16, fixedWidth: true)
|
|
||||||
},
|
|
||||||
new OsuSpriteText
|
|
||||||
{
|
|
||||||
Anchor = Anchor.BottomLeft,
|
|
||||||
Origin = Anchor.BottomLeft,
|
|
||||||
Text = BeatmapsetsStrings.ShowScoreboardHeaderspp,
|
|
||||||
Font = OsuFont.Numeric.With(size: 8),
|
|
||||||
Padding = new MarginPadding { Bottom = 1.5f }, // align baseline better
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This class shouldn't exist, but requires breaking changes to allow DifficultyCalculator to receive an IBeatmap.
|
// TODO: This class shouldn't exist, but requires breaking changes to allow DifficultyCalculator to receive an IBeatmap.
|
||||||
private class GameplayWorkingBeatmap : WorkingBeatmap
|
private class GameplayWorkingBeatmap : WorkingBeatmap
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user