1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 21:42:55 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/JudgementCounter/JudgementCounter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
3.1 KiB
C#
Raw Normal View History

2022-12-12 06:47:17 +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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
2022-12-12 06:47:17 +08:00
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Screens.Play.HUD.JudgementCounter
{
2023-01-17 17:30:50 +08:00
public partial class JudgementCounter : VisibilityContainer
2022-12-12 06:47:17 +08:00
{
public BindableBool ShowName = new BindableBool();
public Bindable<FillDirection> Direction = new Bindable<FillDirection>();
public readonly JudgementCountController.JudgementCount Result;
2022-12-12 06:47:17 +08:00
public JudgementCounter(JudgementCountController.JudgementCount result) => Result = result;
2022-12-12 06:47:17 +08:00
public OsuSpriteText ResultName = null!;
2022-12-12 06:47:17 +08:00
private FillFlowContainer flowContainer = null!;
private JudgementRollingCounter counter = null!;
[BackgroundDependencyLoader]
private void load(OsuColour colours, IBindable<RulesetInfo> ruleset)
2022-12-12 06:47:17 +08:00
{
AutoSizeAxes = Axes.Both;
2023-01-17 17:30:50 +08:00
2022-12-12 06:47:17 +08:00
InternalChild = flowContainer = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
counter = new JudgementRollingCounter
{
Current = Result.ResultCount
},
ResultName = new OsuSpriteText
2022-12-12 06:47:17 +08:00
{
Alpha = 0,
2022-12-12 06:47:17 +08:00
Font = OsuFont.Numeric.With(size: 8),
Text = ruleset.Value.CreateInstance().GetDisplayNameForHitResult(Result.Type)
2022-12-12 06:47:17 +08:00
}
}
};
var result = Result.Type;
2022-12-12 06:47:17 +08:00
2022-12-17 00:40:39 +08:00
Colour = result.IsBasic() ? colours.ForHitResult(Result.Type) : !result.IsBonus() ? colours.PurpleLight : colours.PurpleLighter;
2022-12-12 06:47:17 +08:00
}
protected override void LoadComplete()
{
ShowName.BindValueChanged(value =>
2022-12-17 00:40:39 +08:00
ResultName.FadeTo(value.NewValue ? 1 : 0, JudgementCounterDisplay.TRANSFORM_DURATION, Easing.OutQuint), true);
2022-12-12 06:47:17 +08:00
Direction.BindValueChanged(direction =>
{
flowContainer.Direction = direction.NewValue;
2022-12-17 00:40:39 +08:00
changeAnchor(direction.NewValue == FillDirection.Vertical ? Anchor.TopLeft : Anchor.BottomLeft);
2022-12-12 06:47:17 +08:00
void changeAnchor(Anchor anchor) => counter.Anchor = ResultName.Anchor = counter.Origin = ResultName.Origin = anchor;
2022-12-12 06:47:17 +08:00
}, true);
base.LoadComplete();
}
2022-12-17 00:40:39 +08:00
protected override void PopIn() => this.FadeIn(JudgementCounterDisplay.TRANSFORM_DURATION, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(100);
2022-12-12 06:47:17 +08:00
private sealed partial class JudgementRollingCounter : RollingCounter<int>
{
protected override OsuSpriteText CreateSpriteText()
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(fixedWidth: true, size: 16));
}
}
}