2019-02-26 15:10:06 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using System.Linq;
|
2021-04-06 15:17:38 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Game.Screens.Select.Details;
|
|
|
|
|
using osu.Game.Beatmaps;
|
2019-02-12 12:04:46 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2020-02-21 14:31:40 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-06-13 15:57:19 +08:00
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
|
using osu.Game.Rulesets;
|
2021-04-02 20:14:31 +08:00
|
|
|
|
using osu.Game.Online;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
|
|
|
|
public class BeatmapDetails : Container
|
|
|
|
|
{
|
|
|
|
|
private const float spacing = 10;
|
|
|
|
|
private const float transition_duration = 250;
|
|
|
|
|
|
|
|
|
|
private readonly AdvancedStats advanced;
|
|
|
|
|
private readonly UserRatings ratings;
|
|
|
|
|
private readonly MetadataSection description, source, tags;
|
|
|
|
|
private readonly Container failRetryContainer;
|
|
|
|
|
private readonly FailRetryGraph failRetryGraph;
|
2020-02-21 14:31:40 +08:00
|
|
|
|
private readonly LoadingLayer loading;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-14 21:14:00 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-13 15:57:19 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private RulesetStore rulesets { get; set; }
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private BeatmapInfo beatmap;
|
2019-02-27 20:07:17 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public BeatmapInfo Beatmap
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => beatmap;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == beatmap) return;
|
2019-02-27 20:07:17 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
beatmap = value;
|
|
|
|
|
|
2021-04-06 15:17:38 +08:00
|
|
|
|
Scheduler.AddOnce(updateStatistics);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BeatmapDetails()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.5f),
|
|
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
|
new Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = spacing },
|
2021-04-06 15:17:38 +08:00
|
|
|
|
Child = new GridContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension()
|
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
new FillFlowContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-04-06 15:17:38 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
new FillFlowContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Width = 0.5f,
|
|
|
|
|
Spacing = new Vector2(spacing),
|
|
|
|
|
Padding = new MarginPadding { Right = spacing / 2 },
|
|
|
|
|
Children = new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
}),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2021-04-06 15:17:38 +08:00
|
|
|
|
new OsuScrollContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.5f,
|
|
|
|
|
ScrollbarVisible = false,
|
|
|
|
|
Padding = new MarginPadding { Left = spacing / 2 },
|
|
|
|
|
Child = new FillFlowContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2021-04-06 15:17:38 +08:00
|
|
|
|
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"),
|
|
|
|
|
},
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-04-06 15:17:38 +08:00
|
|
|
|
},
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
failRetryContainer = new OnlineViewContainer("Sign in to view more details")
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
new OsuSpriteText
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
Text = "Points of Failure",
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2021-04-06 15:17:38 +08:00
|
|
|
|
failRetryGraph = new FailRetryGraph
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Top = 14 + spacing / 2 },
|
|
|
|
|
},
|
|
|
|
|
loading = new LoadingLayer(true)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2021-04-06 15:17:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 15:17:38 +08:00
|
|
|
|
private IBindable<APIState> apiOnlineState;
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
base.LoadComplete();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-04-06 15:17:38 +08:00
|
|
|
|
apiOnlineState = api.State.GetBoundCopy();
|
|
|
|
|
apiOnlineState.BindValueChanged(state =>
|
|
|
|
|
{
|
|
|
|
|
Scheduler.AddOnce(updateStatistics);
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateStatistics()
|
|
|
|
|
{
|
2019-03-08 17:44:35 +08:00
|
|
|
|
advanced.Beatmap = Beatmap;
|
|
|
|
|
description.Text = Beatmap?.Version;
|
|
|
|
|
source.Text = Beatmap?.Metadata?.Source;
|
|
|
|
|
tags.Text = Beatmap?.Metadata?.Tags;
|
|
|
|
|
|
2019-03-13 18:57:45 +08:00
|
|
|
|
// metrics may have been previously fetched
|
2019-06-13 16:10:09 +08:00
|
|
|
|
if (Beatmap?.BeatmapSet?.Metrics != null && Beatmap?.Metrics != null)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-15 13:45:51 +08:00
|
|
|
|
updateMetrics();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
// for now, let's early abort if an OnlineBeatmapID is not present (should have been populated at import time).
|
2021-04-06 15:17:38 +08:00
|
|
|
|
if (Beatmap?.OnlineBeatmapID == null || apiOnlineState.Value != APIState.Online)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-15 13:45:51 +08:00
|
|
|
|
updateMetrics();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var requestedBeatmap = Beatmap;
|
|
|
|
|
|
|
|
|
|
var lookup = new GetBeatmapRequest(requestedBeatmap);
|
2019-06-13 16:10:09 +08:00
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
lookup.Success += res =>
|
|
|
|
|
{
|
|
|
|
|
Schedule(() =>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (beatmap != requestedBeatmap)
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// the beatmap has been changed since we started the lookup.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2019-06-13 15:57:19 +08:00
|
|
|
|
var b = res.ToBeatmap(rulesets);
|
|
|
|
|
|
2019-06-13 16:10:09 +08:00
|
|
|
|
if (requestedBeatmap.BeatmapSet == null)
|
|
|
|
|
requestedBeatmap.BeatmapSet = b.BeatmapSet;
|
|
|
|
|
else
|
|
|
|
|
requestedBeatmap.BeatmapSet.Metrics = b.BeatmapSet.Metrics;
|
|
|
|
|
|
2019-06-13 15:57:19 +08:00
|
|
|
|
requestedBeatmap.Metrics = b.Metrics;
|
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
updateMetrics();
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-06-13 16:10:09 +08:00
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
lookup.Failure += e =>
|
|
|
|
|
{
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
if (beatmap != requestedBeatmap)
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// the beatmap has been changed since we started the lookup.
|
2019-06-15 13:45:51 +08:00
|
|
|
|
return;
|
2021-04-02 21:15:28 +08:00
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
updateMetrics();
|
|
|
|
|
});
|
|
|
|
|
};
|
2021-04-02 21:15:28 +08:00
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
api.Queue(lookup);
|
|
|
|
|
loading.Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-15 13:45:51 +08:00
|
|
|
|
private void updateMetrics()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-15 13:45:51 +08:00
|
|
|
|
var hasRatings = beatmap?.BeatmapSet?.Metrics?.Ratings?.Any() ?? false;
|
2020-08-25 02:41:50 +08:00
|
|
|
|
var hasRetriesFails = (beatmap?.Metrics?.Retries?.Any() ?? false) || (beatmap?.Metrics?.Fails?.Any() ?? false);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-04-06 15:17:38 +08:00
|
|
|
|
if (hasRatings)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-15 13:45:51 +08:00
|
|
|
|
ratings.Metrics = beatmap.BeatmapSet.Metrics;
|
2021-04-06 15:17:38 +08:00
|
|
|
|
ratings.FadeIn(transition_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2019-03-08 17:44:35 +08:00
|
|
|
|
else
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-04-06 15:17:38 +08:00
|
|
|
|
// loading or just has no data server-side.
|
2019-06-13 15:52:49 +08:00
|
|
|
|
ratings.Metrics = new BeatmapSetMetrics { Ratings = new int[10] };
|
2021-04-06 15:17:38 +08:00
|
|
|
|
ratings.FadeTo(0.25f, transition_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasRetriesFails)
|
|
|
|
|
{
|
2019-06-15 13:45:51 +08:00
|
|
|
|
failRetryGraph.Metrics = beatmap.Metrics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
failRetryContainer.FadeIn(transition_duration);
|
|
|
|
|
}
|
2019-03-08 17:44:35 +08:00
|
|
|
|
else
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
failRetryGraph.Metrics = new BeatmapMetrics
|
|
|
|
|
{
|
|
|
|
|
Fails = new int[100],
|
|
|
|
|
Retries = new int[100],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loading.Hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class DetailBox : Container
|
|
|
|
|
{
|
|
|
|
|
private readonly Container content;
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
|
|
|
|
public DetailBox()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.5f),
|
|
|
|
|
},
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class MetadataSection : Container
|
|
|
|
|
{
|
|
|
|
|
private readonly FillFlowContainer textContainer;
|
|
|
|
|
private TextFlowContainer textFlow;
|
|
|
|
|
|
|
|
|
|
public MetadataSection(string title)
|
|
|
|
|
{
|
2020-10-30 20:03:57 +08:00
|
|
|
|
Alpha = 0;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
InternalChild = textContainer = new FillFlowContainer
|
|
|
|
|
{
|
2018-10-26 19:35:51 +08:00
|
|
|
|
Alpha = 0,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Spacing = new Vector2(spacing / 2),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Child = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = title,
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
|
{
|
2019-02-26 15:10:06 +08:00
|
|
|
|
this.FadeOut(transition_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-26 14:48:34 +08:00
|
|
|
|
|
2019-02-26 15:10:06 +08:00
|
|
|
|
this.FadeIn(transition_duration);
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
setTextAsync(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setTextAsync(string text)
|
|
|
|
|
{
|
2019-02-20 18:32:30 +08:00
|
|
|
|
LoadComponentAsync(new OsuTextFlowContainer(s => s.Font = s.Font.With(size: 14))
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2018-06-04 08:41:34 +08:00
|
|
|
|
Colour = Color4.White.Opacity(0.75f),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Text = text
|
|
|
|
|
}, loaded =>
|
|
|
|
|
{
|
|
|
|
|
textFlow?.Expire();
|
|
|
|
|
textContainer.Add(textFlow = loaded);
|
|
|
|
|
|
|
|
|
|
// fade in if we haven't yet.
|
2018-10-26 19:35:51 +08:00
|
|
|
|
textContainer.FadeIn(transition_duration);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|