1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 06:07:28 +08:00
osu-lazer/osu.Game/Screens/Ranking/ResultsScreen.cs

195 lines
6.4 KiB
C#
Raw Normal View History

2020-03-17 16:43:16 +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-18 17:28:42 +08:00
using System;
2020-05-26 16:00:41 +08:00
using System.Collections.Generic;
2020-03-17 16:43:16 +08:00
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;
2020-03-17 21:21:16 +08:00
using osu.Game.Graphics.Containers;
2020-03-17 16:43:16 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
2020-03-17 16:43:16 +08:00
using osu.Game.Scoring;
using osu.Game.Screens.Backgrounds;
2020-03-17 16:45:25 +08:00
using osu.Game.Screens.Play;
2020-03-17 16:43:16 +08:00
using osuTK;
namespace osu.Game.Screens.Ranking
{
2020-05-26 16:00:41 +08:00
public abstract class ResultsScreen : OsuScreen
2020-03-17 16:43:16 +08:00
{
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);
2020-03-17 16:45:25 +08:00
[Resolved(CanBeNull = true)]
private Player player { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
2020-03-29 22:29:46 +08:00
public readonly ScoreInfo Score;
2020-03-17 16:43:16 +08:00
private readonly bool allowRetry;
2020-03-17 16:43:16 +08:00
private Drawable bottomPanel;
private ScorePanelList panels;
2020-03-17 16:43:16 +08:00
2020-05-26 16:31:50 +08:00
protected ResultsScreen(ScoreInfo score, bool allowRetry = true)
2020-03-17 16:43:16 +08:00
{
2020-03-29 22:50:16 +08:00
Score = score;
this.allowRetry = allowRetry;
2020-03-17 16:43:16 +08:00
}
[BackgroundDependencyLoader]
private void load()
{
FillFlowContainer buttons;
InternalChild = new GridContainer
2020-03-17 16:43:16 +08:00
{
RelativeSizeAxes = Axes.Both,
Content = new[]
2020-03-17 16:43:16 +08:00
{
new Drawable[]
2020-03-17 21:21:16 +08:00
{
new ResultsScrollContainer
2020-03-17 16:43:16 +08:00
{
Child = panels = new ScorePanelList(Score)
{
RelativeSizeAxes = Axes.Both,
}
}
},
new[]
{
bottomPanel = new Container
2020-03-17 16:43:16 +08:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = TwoLayerButton.SIZE_EXTENDED.Y,
Alpha = 0,
2020-03-17 16:43:16 +08:00
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 },
}
}
2020-03-17 16:43:16 +08:00
}
}
}
},
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize)
2020-03-17 16:43:16 +08:00
}
};
2020-03-17 16:45:25 +08:00
2020-03-30 17:56:35 +08:00
if (player != null && allowRetry)
2020-03-17 16:45:25 +08:00
{
2020-03-30 17:56:35 +08:00
buttons.Add(new RetryButton { Width = 300 });
2020-03-30 17:56:35 +08:00
AddInternal(new HotkeyRetryOverlay
{
Action = () =>
2020-03-17 16:45:25 +08:00
{
2020-03-30 17:56:35 +08:00
if (!this.IsCurrentScreen()) return;
2020-03-17 16:45:25 +08:00
2020-03-30 17:56:35 +08:00
player?.Restart();
},
});
2020-03-17 16:45:25 +08:00
}
2020-03-17 16:43:16 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2020-05-26 16:00:41 +08:00
var req = FetchScores(scores => Schedule(() =>
{
2020-05-26 16:00:41 +08:00
foreach (var s in scores)
{
if (s.OnlineScoreID == Score.OnlineScoreID)
continue;
panels.AddScore(s);
}
2020-05-26 16:00:41 +08:00
}));
2020-05-26 16:00:41 +08:00
if (req != null)
api.Queue(req);
}
2020-05-26 16:00:41 +08:00
/// <summary>
/// Performs a fetch/refresh of scores to be displayed.
/// </summary>
/// <param name="scoresCallback">A callback which should be called when fetching is completed. Scheduling is not required.</param>
/// <returns>An <see cref="APIRequest"/> responsible for the fetch operation. This will be queued and performed automatically.</returns>
protected virtual APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback) => null;
2020-03-17 16:43:16 +08:00
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);
}
2020-03-17 21:21:16 +08:00
private class ResultsScrollContainer : OsuScrollContainer
{
private readonly Container content;
protected override Container<Drawable> 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 - TwoLayerButton.SIZE_EXTENDED.Y, DrawHeight);
2020-03-17 21:21:16 +08:00
}
}
2020-03-17 16:43:16 +08:00
}
}