Refactor BeatmapDetails to use GridContainer to keep a consistent layout

This commit is contained in:
Dean Herbert
2021-04-06 16:17:38 +09:00
parent 933c4010da
commit dafa8bbe4e

View File

@ -8,8 +8,8 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using System.Linq; using System.Linq;
using osu.Framework.Bindables;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Framework.Threading;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Game.Screens.Select.Details; using osu.Game.Screens.Select.Details;
@ -28,11 +28,8 @@ namespace osu.Game.Screens.Select
private const float spacing = 10; private const float spacing = 10;
private const float transition_duration = 250; private const float transition_duration = 250;
private readonly FillFlowContainer top, statsFlow;
private readonly AdvancedStats advanced; private readonly AdvancedStats advanced;
private readonly DetailBox ratingsContainer;
private readonly UserRatings ratings; private readonly UserRatings ratings;
private readonly OsuScrollContainer metadataScroll;
private readonly MetadataSection description, source, tags; private readonly MetadataSection description, source, tags;
private readonly Container failRetryContainer; private readonly Container failRetryContainer;
private readonly FailRetryGraph failRetryGraph; private readonly FailRetryGraph failRetryGraph;
@ -41,8 +38,6 @@ namespace osu.Game.Screens.Select
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
private ScheduledDelegate pendingBeatmapSwitch;
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private RulesetStore rulesets { get; set; }
@ -57,8 +52,7 @@ namespace osu.Game.Screens.Select
beatmap = value; beatmap = value;
pendingBeatmapSwitch?.Cancel(); Scheduler.AddOnce(updateStatistics);
pendingBeatmapSwitch = Schedule(updateStatistics);
} }
} }
@ -75,16 +69,26 @@ namespace osu.Game.Screens.Select
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = spacing }, Padding = new MarginPadding { Horizontal = spacing },
Children = new Drawable[] Child = new GridContainer
{ {
top = new FillFlowContainer RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension()
},
Content = new[]
{
new Drawable[]
{
new FillFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Children = new Drawable[] Children = new Drawable[]
{ {
statsFlow = new FillFlowContainer new FillFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
@ -93,29 +97,27 @@ namespace osu.Game.Screens.Select
Padding = new MarginPadding { Right = spacing / 2 }, Padding = new MarginPadding { Right = spacing / 2 },
Children = new[] Children = new[]
{ {
new DetailBox new DetailBox().WithChild(advanced = new AdvancedStats
{
Child = advanced = new AdvancedStats
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = spacing, Top = spacing * 2, Bottom = spacing }, Padding = new MarginPadding { Horizontal = spacing, Top = spacing * 2, Bottom = spacing },
}, }),
}, new DetailBox().WithChild(new OnlineViewContainer(string.Empty)
ratingsContainer = new DetailBox
{
Child = ratings = new UserRatings
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 134, Height = 134,
Padding = new MarginPadding { Horizontal = spacing, Top = spacing }, Padding = new MarginPadding { Horizontal = spacing, Top = spacing },
}, Child = ratings = new UserRatings
},
},
},
metadataScroll = new OsuScrollContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
},
}),
},
},
new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
Width = 0.5f, Width = 0.5f,
ScrollbarVisible = false, ScrollbarVisible = false,
Padding = new MarginPadding { Left = spacing / 2 }, Padding = new MarginPadding { Left = spacing / 2 },
@ -137,11 +139,12 @@ namespace osu.Game.Screens.Select
}, },
}, },
}, },
},
new Drawable[]
{
failRetryContainer = new OnlineViewContainer("Sign in to view more details") failRetryContainer = new OnlineViewContainer("Sign in to view more details")
{ {
Anchor = Anchor.BottomLeft, RelativeSizeAxes = Axes.Both,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Children = new Drawable[] Children = new Drawable[]
{ {
new OsuSpriteText new OsuSpriteText
@ -157,17 +160,24 @@ namespace osu.Game.Screens.Select
loading = new LoadingLayer(true) loading = new LoadingLayer(true)
}, },
}, },
}, }
}
}
}, },
}; };
} }
protected override void UpdateAfterChildren() private IBindable<APIState> apiOnlineState;
{
base.UpdateAfterChildren();
metadataScroll.Height = statsFlow.DrawHeight; protected override void LoadComplete()
failRetryContainer.Height = DrawHeight - Padding.TotalVertical - (top.DrawHeight + spacing / 2); {
base.LoadComplete();
apiOnlineState = api.State.GetBoundCopy();
apiOnlineState.BindValueChanged(state =>
{
Scheduler.AddOnce(updateStatistics);
});
} }
private void updateStatistics() private void updateStatistics()
@ -185,7 +195,7 @@ namespace osu.Game.Screens.Select
} }
// for now, let's early abort if an OnlineBeatmapID is not present (should have been populated at import time). // for now, let's early abort if an OnlineBeatmapID is not present (should have been populated at import time).
if (Beatmap?.OnlineBeatmapID == null) if (Beatmap?.OnlineBeatmapID == null || apiOnlineState.Value != APIState.Online)
{ {
updateMetrics(); updateMetrics();
return; return;
@ -237,17 +247,16 @@ namespace osu.Game.Screens.Select
var hasRatings = beatmap?.BeatmapSet?.Metrics?.Ratings?.Any() ?? false; var hasRatings = beatmap?.BeatmapSet?.Metrics?.Ratings?.Any() ?? false;
var hasRetriesFails = (beatmap?.Metrics?.Retries?.Any() ?? false) || (beatmap?.Metrics?.Fails?.Any() ?? false); var hasRetriesFails = (beatmap?.Metrics?.Retries?.Any() ?? false) || (beatmap?.Metrics?.Fails?.Any() ?? false);
bool isOnline = api.State.Value == APIState.Online; if (hasRatings)
if (hasRatings && isOnline)
{ {
ratings.Metrics = beatmap.BeatmapSet.Metrics; ratings.Metrics = beatmap.BeatmapSet.Metrics;
ratingsContainer.FadeIn(transition_duration); ratings.FadeIn(transition_duration);
} }
else else
{ {
// loading or just has no data server-side.
ratings.Metrics = new BeatmapSetMetrics { Ratings = new int[10] }; ratings.Metrics = new BeatmapSetMetrics { Ratings = new int[10] };
ratingsContainer.FadeTo(isOnline ? 0.25f : 0, transition_duration); ratings.FadeTo(0.25f, transition_duration);
} }
if (hasRetriesFails) if (hasRetriesFails)