mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 11:47:18 +08:00
Refactor BeatmapDetails to use GridContainer to keep a consistent layout
This commit is contained in:
parent
933c4010da
commit
dafa8bbe4e
@ -8,8 +8,8 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Game.Screens.Select.Details;
|
||||
@ -28,11 +28,8 @@ namespace osu.Game.Screens.Select
|
||||
private const float spacing = 10;
|
||||
private const float transition_duration = 250;
|
||||
|
||||
private readonly FillFlowContainer top, statsFlow;
|
||||
private readonly AdvancedStats advanced;
|
||||
private readonly DetailBox ratingsContainer;
|
||||
private readonly UserRatings ratings;
|
||||
private readonly OsuScrollContainer metadataScroll;
|
||||
private readonly MetadataSection description, source, tags;
|
||||
private readonly Container failRetryContainer;
|
||||
private readonly FailRetryGraph failRetryGraph;
|
||||
@ -41,8 +38,6 @@ namespace osu.Game.Screens.Select
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
private ScheduledDelegate pendingBeatmapSwitch;
|
||||
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; }
|
||||
|
||||
@ -57,8 +52,7 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
beatmap = value;
|
||||
|
||||
pendingBeatmapSwitch?.Cancel();
|
||||
pendingBeatmapSwitch = Schedule(updateStatistics);
|
||||
Scheduler.AddOnce(updateStatistics);
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,99 +69,115 @@ namespace osu.Game.Screens.Select
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Horizontal = spacing },
|
||||
Children = new Drawable[]
|
||||
Child = new GridContainer
|
||||
{
|
||||
top = new FillFlowContainer
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RowDimensions = new[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new Drawable[]
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension()
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
statsFlow = new FillFlowContainer
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Width = 0.5f,
|
||||
Spacing = new Vector2(spacing),
|
||||
Padding = new MarginPadding { Right = spacing / 2 },
|
||||
Children = new[]
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new DetailBox
|
||||
new FillFlowContainer
|
||||
{
|
||||
Child = advanced = new AdvancedStats
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Width = 0.5f,
|
||||
Spacing = new Vector2(spacing),
|
||||
Padding = new MarginPadding { Right = spacing / 2 },
|
||||
Children = new[]
|
||||
{
|
||||
new DetailBox().WithChild(advanced = new AdvancedStats
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Horizontal = spacing, Top = spacing * 2, Bottom = spacing },
|
||||
}),
|
||||
new DetailBox().WithChild(new OnlineViewContainer(string.Empty)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 134,
|
||||
Padding = new MarginPadding { Horizontal = spacing, Top = spacing },
|
||||
Child = ratings = new UserRatings
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
new OsuScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Width = 0.5f,
|
||||
ScrollbarVisible = false,
|
||||
Padding = new MarginPadding { Left = spacing / 2 },
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Horizontal = spacing, Top = spacing * 2, Bottom = spacing },
|
||||
LayoutDuration = transition_duration,
|
||||
LayoutEasing = Easing.OutQuad,
|
||||
Spacing = new Vector2(spacing * 2),
|
||||
Margin = new MarginPadding { Top = spacing * 2 },
|
||||
Children = new[]
|
||||
{
|
||||
description = new MetadataSection("Description"),
|
||||
source = new MetadataSection("Source"),
|
||||
tags = new MetadataSection("Tags"),
|
||||
},
|
||||
},
|
||||
},
|
||||
ratingsContainer = new DetailBox
|
||||
{
|
||||
Child = ratings = new UserRatings
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 134,
|
||||
Padding = new MarginPadding { Horizontal = spacing, Top = spacing },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
metadataScroll = new OsuScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Width = 0.5f,
|
||||
ScrollbarVisible = false,
|
||||
Padding = new MarginPadding { Left = spacing / 2 },
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
LayoutDuration = transition_duration,
|
||||
LayoutEasing = Easing.OutQuad,
|
||||
Spacing = new Vector2(spacing * 2),
|
||||
Margin = new MarginPadding { Top = spacing * 2 },
|
||||
Children = new[]
|
||||
{
|
||||
description = new MetadataSection("Description"),
|
||||
source = new MetadataSection("Source"),
|
||||
tags = new MetadataSection("Tags"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
failRetryContainer = new OnlineViewContainer("Sign in to view more details")
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Children = new Drawable[]
|
||||
new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = "Points of Failure",
|
||||
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
|
||||
},
|
||||
failRetryGraph = new FailRetryGraph
|
||||
failRetryContainer = new OnlineViewContainer("Sign in to view more details")
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Top = 14 + spacing / 2 },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = "Points of Failure",
|
||||
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
|
||||
},
|
||||
failRetryGraph = new FailRetryGraph
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Top = 14 + spacing / 2 },
|
||||
},
|
||||
loading = new LoadingLayer(true)
|
||||
},
|
||||
},
|
||||
loading = new LoadingLayer(true)
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
protected override void UpdateAfterChildren()
|
||||
{
|
||||
base.UpdateAfterChildren();
|
||||
private IBindable<APIState> apiOnlineState;
|
||||
|
||||
metadataScroll.Height = statsFlow.DrawHeight;
|
||||
failRetryContainer.Height = DrawHeight - Padding.TotalVertical - (top.DrawHeight + spacing / 2);
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
apiOnlineState = api.State.GetBoundCopy();
|
||||
apiOnlineState.BindValueChanged(state =>
|
||||
{
|
||||
Scheduler.AddOnce(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).
|
||||
if (Beatmap?.OnlineBeatmapID == null)
|
||||
if (Beatmap?.OnlineBeatmapID == null || apiOnlineState.Value != APIState.Online)
|
||||
{
|
||||
updateMetrics();
|
||||
return;
|
||||
@ -237,17 +247,16 @@ namespace osu.Game.Screens.Select
|
||||
var hasRatings = beatmap?.BeatmapSet?.Metrics?.Ratings?.Any() ?? false;
|
||||
var hasRetriesFails = (beatmap?.Metrics?.Retries?.Any() ?? false) || (beatmap?.Metrics?.Fails?.Any() ?? false);
|
||||
|
||||
bool isOnline = api.State.Value == APIState.Online;
|
||||
|
||||
if (hasRatings && isOnline)
|
||||
if (hasRatings)
|
||||
{
|
||||
ratings.Metrics = beatmap.BeatmapSet.Metrics;
|
||||
ratingsContainer.FadeIn(transition_duration);
|
||||
ratings.FadeIn(transition_duration);
|
||||
}
|
||||
else
|
||||
{
|
||||
// loading or just has no data server-side.
|
||||
ratings.Metrics = new BeatmapSetMetrics { Ratings = new int[10] };
|
||||
ratingsContainer.FadeTo(isOnline ? 0.25f : 0, transition_duration);
|
||||
ratings.FadeTo(0.25f, transition_duration);
|
||||
}
|
||||
|
||||
if (hasRetriesFails)
|
||||
|
Loading…
x
Reference in New Issue
Block a user