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

259 lines
11 KiB
C#
Raw Normal View History

2020-03-17 15:59:34 +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.
2020-03-17 16:25:24 +08:00
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2020-03-17 16:25:24 +08:00
using osu.Framework.Graphics;
2020-03-17 15:59:34 +08:00
using osu.Framework.Graphics.Containers;
2020-03-17 16:25:24 +08:00
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
2020-03-17 16:25:24 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Scoring;
2020-03-17 15:59:34 +08:00
using osu.Game.Scoring;
2020-03-17 16:25:24 +08:00
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Ranking.Expanded.Accuracy;
using osu.Game.Screens.Ranking.Expanded.Statistics;
using osuTK;
2020-03-17 15:59:34 +08:00
namespace osu.Game.Screens.Ranking.Expanded
{
2020-03-17 16:34:16 +08:00
/// <summary>
/// The content that appears in the middle section of the <see cref="ScorePanel"/>.
/// </summary>
2020-03-17 15:59:34 +08:00
public class ExpandedPanelMiddleContent : CompositeDrawable
{
2020-03-17 16:25:24 +08:00
private readonly ScoreInfo score;
private readonly List<StatisticDisplay> statisticDisplays = new List<StatisticDisplay>();
private FillFlowContainer starAndModDisplay;
2020-03-17 16:25:24 +08:00
private RollingCounter<long> scoreCounter;
private const float padding = 10;
2020-03-17 16:34:16 +08:00
/// <summary>
/// Creates a new <see cref="ExpandedPanelMiddleContent"/>.
/// </summary>
/// <param name="score">The score to display.</param>
2020-03-17 15:59:34 +08:00
public ExpandedPanelMiddleContent(ScoreInfo score)
{
2020-03-17 16:25:24 +08:00
this.score = score;
RelativeSizeAxes = Axes.Both;
Masking = true;
Padding = new MarginPadding(padding);
2020-03-17 16:25:24 +08:00
}
[BackgroundDependencyLoader]
private void load(Bindable<WorkingBeatmap> working)
2020-03-17 16:25:24 +08:00
{
var beatmap = working.Value.BeatmapInfo;
var metadata = beatmap.Metadata;
2020-03-18 02:24:58 +08:00
var creator = metadata.Author?.Username;
2020-03-17 16:25:24 +08:00
var topStatistics = new List<StatisticDisplay>
{
new AccuracyStatistic(score.Accuracy),
2020-03-18 14:49:24 +08:00
new ComboStatistic(score.MaxCombo, !score.Statistics.TryGetValue(HitResult.Miss, out var missCount) || missCount == 0),
2020-03-17 16:25:24 +08:00
new CounterStatistic("pp", (int)(score.PP ?? 0)),
};
var bottomStatistics = new List<StatisticDisplay>();
foreach (var stat in score.SortedStatistics)
2020-03-18 16:21:57 +08:00
bottomStatistics.Add(new HitResultStatistic(stat.Key, stat.Value));
2020-03-17 16:25:24 +08:00
statisticDisplays.AddRange(topStatistics);
statisticDisplays.AddRange(bottomStatistics);
InternalChild = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(20),
Children = new Drawable[]
{
new FillFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = new LocalisedString((metadata.TitleUnicode, metadata.Title)),
2020-03-17 16:25:24 +08:00
Font = OsuFont.Torus.With(size: 20, weight: FontWeight.SemiBold),
MaxWidth = ScorePanel.EXPANDED_WIDTH - padding * 2,
Truncate = true,
2020-03-17 16:25:24 +08:00
},
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = new LocalisedString((metadata.ArtistUnicode, metadata.Artist)),
Font = OsuFont.Torus.With(size: 14, weight: FontWeight.SemiBold),
MaxWidth = ScorePanel.EXPANDED_WIDTH - padding * 2,
Truncate = true,
2020-03-17 16:25:24 +08:00
},
new Container
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Margin = new MarginPadding { Top = 40 },
RelativeSizeAxes = Axes.X,
Height = 230,
Child = new AccuracyCircle(score)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
}
},
scoreCounter = new TotalScoreCounter
{
Margin = new MarginPadding { Top = 0, Bottom = 5 },
Current = { Value = 0 },
Alpha = 0,
AlwaysPresent = true
},
starAndModDisplay = new FillFlowContainer
2020-03-17 16:25:24 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(5, 0),
2020-03-17 16:25:24 +08:00
Children = new Drawable[]
{
new StarRatingDisplay(beatmap)
2020-03-17 16:25:24 +08:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
}
},
new FillFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = beatmap.Version,
2020-03-17 16:25:24 +08:00
Font = OsuFont.Torus.With(size: 16, weight: FontWeight.SemiBold),
},
new OsuTextFlowContainer(s => s.Font = OsuFont.Torus.With(size: 12))
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
2020-03-17 16:25:24 +08:00
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
}.With(t =>
{
2020-03-18 01:15:43 +08:00
if (!string.IsNullOrEmpty(creator))
{
t.AddText("mapped by ");
t.AddText(creator, s => s.Font = s.Font.With(weight: FontWeight.SemiBold));
}
2020-03-17 16:25:24 +08:00
})
}
},
}
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
Children = new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Content = new[] { topStatistics.Cast<Drawable>().ToArray() },
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
}
},
new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Content = new[] { bottomStatistics.Cast<Drawable>().ToArray() },
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
}
}
}
2020-03-18 16:59:44 +08:00
},
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold),
2020-06-04 20:33:38 +08:00
Text = $"Played on {score.Date.ToLocalTime():d MMMM yyyy HH:mm}"
2020-03-17 16:25:24 +08:00
}
}
};
if (score.Mods.Any())
{
starAndModDisplay.Add(new ModDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
DisplayUnrankedText = false,
ExpansionMode = ExpansionMode.AlwaysExpanded,
Scale = new Vector2(0.5f),
Current = { Value = score.Mods }
});
}
2020-03-17 16:25:24 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
// Score counter value setting must be scheduled so it isn't transferred instantaneously
ScheduleAfterChildren(() =>
{
using (BeginDelayedSequence(AccuracyCircle.ACCURACY_TRANSFORM_DELAY, true))
{
scoreCounter.FadeIn();
scoreCounter.Current.Value = score.TotalScore;
double delay = 0;
foreach (var stat in statisticDisplays)
{
using (BeginDelayedSequence(delay, true))
stat.Appear();
delay += 200;
}
}
});
2020-03-17 15:59:34 +08:00
}
}
}