// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Screens; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Rulesets; using osu.Game.Scoring; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Play; using osuTK; namespace osu.Game.Screens.Ranking { public class ResultsScreen : OsuScreen { protected const float BACKGROUND_BLUR = 20; public override bool DisallowExternalBeatmapRulesetChanges => true; // Temporary for now to stop dual transitions. Should respect the current toolbar mode, but there's no way to do so currently. public override bool HideOverlaysOnEnter => true; protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value); [Resolved(CanBeNull = true)] private Player player { get; set; } [Resolved] private IAPIProvider api { get; set; } [Resolved] private RulesetStore rulesets { get; set; } public readonly ScoreInfo Score; private readonly bool allowRetry; private Drawable bottomPanel; private ScorePanelList panels; public ResultsScreen(ScoreInfo score, bool allowRetry = true) { Score = score; this.allowRetry = allowRetry; } [BackgroundDependencyLoader] private void load() { FillFlowContainer buttons; InternalChildren = new[] { new ResultsScrollContainer { Child = panels = new ScorePanelList(Score) { RelativeSizeAxes = Axes.Both, } }, bottomPanel = new Container { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, RelativeSizeAxes = Axes.X, Height = TwoLayerButton.SIZE_EXTENDED.Y, Alpha = 0, Children = new Drawable[] { new Box { RelativeSizeAxes = Axes.Both, Colour = Color4Extensions.FromHex("#333") }, buttons = new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, AutoSizeAxes = Axes.Both, Spacing = new Vector2(5), Direction = FillDirection.Horizontal, Children = new Drawable[] { new ReplayDownloadButton(Score) { Width = 300 }, } } } } }; if (player != null && allowRetry) { buttons.Add(new RetryButton { Width = 300 }); AddInternal(new HotkeyRetryOverlay { Action = () => { if (!this.IsCurrentScreen()) return; player?.Restart(); }, }); } } protected override void LoadComplete() { base.LoadComplete(); var req = new GetScoresRequest(Score.Beatmap, Score.Ruleset); req.Success += r => Schedule(() => { foreach (var s in r.Scores.Select(s => s.CreateScoreInfo(rulesets))) { if (s.OnlineScoreID == Score.OnlineScoreID) continue; panels.AddScore(s); } }); api.Queue(req); } public override void OnEntering(IScreen last) { base.OnEntering(last); ((BackgroundScreenBeatmap)Background).BlurAmount.Value = BACKGROUND_BLUR; Background.FadeTo(0.5f, 250); bottomPanel.FadeTo(1, 250); } public override bool OnExiting(IScreen next) { Background.FadeTo(1, 250); return base.OnExiting(next); } private class ResultsScrollContainer : OsuScrollContainer { private readonly Container content; protected override Container Content => content; public ResultsScrollContainer() { base.Content.Add(content = new Container { RelativeSizeAxes = Axes.X }); RelativeSizeAxes = Axes.Both; ScrollbarVisible = false; } protected override void Update() { base.Update(); content.Height = Math.Max(768, DrawHeight); } } } }