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-06-19 16:28:35 +08:00
|
|
|
using System.Linq;
|
2020-03-17 16:43:16 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-05-28 20:40:01 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-03-17 16:43:16 +08:00
|
|
|
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;
|
2020-05-16 18:00:20 +08:00
|
|
|
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-06-16 16:49:43 +08:00
|
|
|
using osu.Game.Screens.Ranking.Statistics;
|
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;
|
2020-06-17 18:28:40 +08:00
|
|
|
private static readonly float screen_height = 768 - TwoLayerButton.SIZE_EXTENDED.Y;
|
2020-03-17 16:43:16 +08:00
|
|
|
|
|
|
|
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-05-28 20:40:01 +08:00
|
|
|
public readonly Bindable<ScoreInfo> SelectedScore = new Bindable<ScoreInfo>();
|
|
|
|
|
|
|
|
public readonly ScoreInfo Score;
|
|
|
|
private readonly bool allowRetry;
|
|
|
|
|
2020-03-17 16:45:25 +08:00
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
private Player player { get; set; }
|
|
|
|
|
2020-05-16 18:00:20 +08:00
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
2020-06-18 15:50:45 +08:00
|
|
|
private StatisticsPanel statisticsPanel;
|
2020-03-17 16:43:16 +08:00
|
|
|
private Drawable bottomPanel;
|
2020-06-18 15:50:45 +08:00
|
|
|
private ScorePanelList scorePanelList;
|
2020-06-19 16:28:35 +08:00
|
|
|
private Container<ScorePanel> detachedPanelContainer;
|
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;
|
2020-03-29 22:52:50 +08:00
|
|
|
this.allowRetry = allowRetry;
|
2020-05-28 20:40:01 +08:00
|
|
|
|
|
|
|
SelectedScore.Value = score;
|
2020-03-17 16:43:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2020-03-29 22:52:50 +08:00
|
|
|
FillFlowContainer buttons;
|
|
|
|
|
2020-05-22 19:39:02 +08:00
|
|
|
InternalChild = new GridContainer
|
2020-03-17 16:43:16 +08:00
|
|
|
{
|
2020-05-22 19:39:02 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Content = new[]
|
2020-03-17 16:43:16 +08:00
|
|
|
{
|
2020-05-22 19:39:02 +08:00
|
|
|
new Drawable[]
|
2020-03-17 21:21:16 +08:00
|
|
|
{
|
2020-06-30 15:36:53 +08:00
|
|
|
new VerticalScrollContainer
|
2020-03-17 16:43:16 +08:00
|
|
|
{
|
2020-06-17 21:29:00 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-06-30 15:36:53 +08:00
|
|
|
ScrollbarVisible = false,
|
|
|
|
Child = new Container
|
2020-05-22 19:39:02 +08:00
|
|
|
{
|
2020-06-30 15:36:53 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
2020-06-17 18:28:40 +08:00
|
|
|
{
|
2020-06-30 15:36:53 +08:00
|
|
|
scorePanelList = new ScorePanelList
|
2020-06-17 18:28:40 +08:00
|
|
|
{
|
2020-06-30 15:36:53 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
SelectedScore = { BindTarget = SelectedScore },
|
|
|
|
PostExpandAction = () => statisticsPanel.ToggleVisibility()
|
|
|
|
},
|
|
|
|
detachedPanelContainer = new Container<ScorePanel>
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
|
|
|
statisticsPanel = new StatisticsPanel
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Score = { BindTarget = SelectedScore }
|
|
|
|
},
|
|
|
|
}
|
2020-05-22 19:39:02 +08:00
|
|
|
}
|
2020-06-30 15:36:53 +08:00
|
|
|
},
|
2020-05-22 19:39:02 +08:00
|
|
|
},
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
bottomPanel = new Container
|
2020-03-17 16:43:16 +08:00
|
|
|
{
|
2020-05-22 19:39:02 +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[]
|
|
|
|
{
|
2020-05-22 19:39:02 +08:00
|
|
|
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[]
|
|
|
|
{
|
2020-05-28 20:40:01 +08:00
|
|
|
new ReplayDownloadButton(null)
|
|
|
|
{
|
|
|
|
Score = { BindTarget = SelectedScore },
|
|
|
|
Width = 300
|
|
|
|
},
|
2020-05-22 19:39:02 +08:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 16:43:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-22 19:39:02 +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-05-28 20:40:01 +08:00
|
|
|
if (Score != null)
|
2020-06-18 15:50:45 +08:00
|
|
|
scorePanelList.AddScore(Score);
|
2020-05-28 20:40:01 +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-29 22:52:50 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-05-16 18:00:20 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-05-26 16:00:41 +08:00
|
|
|
var req = FetchScores(scores => Schedule(() =>
|
2020-05-16 18:00:20 +08:00
|
|
|
{
|
2020-05-26 16:00:41 +08:00
|
|
|
foreach (var s in scores)
|
2020-06-19 16:28:35 +08:00
|
|
|
addScore(s);
|
2020-05-26 16:00:41 +08:00
|
|
|
}));
|
2020-05-16 18:00:20 +08:00
|
|
|
|
2020-05-26 16:00:41 +08:00
|
|
|
if (req != null)
|
|
|
|
api.Queue(req);
|
2020-06-18 21:27:27 +08:00
|
|
|
|
|
|
|
statisticsPanel.State.BindValueChanged(onStatisticsStateChanged, true);
|
2020-05-16 18:00:20 +08:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2020-06-18 21:27:27 +08:00
|
|
|
if (statisticsPanel.State.Value == Visibility.Visible)
|
|
|
|
{
|
|
|
|
statisticsPanel.Hide();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-17 16:43:16 +08:00
|
|
|
Background.FadeTo(1, 250);
|
|
|
|
|
|
|
|
return base.OnExiting(next);
|
|
|
|
}
|
2020-03-17 21:21:16 +08:00
|
|
|
|
2020-06-19 16:28:35 +08:00
|
|
|
private void addScore(ScoreInfo score)
|
|
|
|
{
|
|
|
|
var panel = scorePanelList.AddScore(score);
|
|
|
|
|
|
|
|
if (detachedPanel != null)
|
|
|
|
panel.Alpha = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ScorePanel detachedPanel;
|
|
|
|
|
2020-06-18 21:27:27 +08:00
|
|
|
private void onStatisticsStateChanged(ValueChangedEvent<Visibility> state)
|
2020-03-17 21:21:16 +08:00
|
|
|
{
|
2020-06-19 16:28:35 +08:00
|
|
|
if (state.NewValue == Visibility.Visible)
|
2020-03-17 21:21:16 +08:00
|
|
|
{
|
2020-06-19 16:28:35 +08:00
|
|
|
// Detach the panel in its original location, and move into the desired location in the local container.
|
|
|
|
var expandedPanel = scorePanelList.GetPanelForScore(SelectedScore.Value);
|
|
|
|
var screenSpacePos = expandedPanel.ScreenSpaceDrawQuad.TopLeft;
|
2020-06-18 21:27:27 +08:00
|
|
|
|
2020-06-19 16:28:35 +08:00
|
|
|
// Detach and move into the local container.
|
|
|
|
scorePanelList.Detach(expandedPanel);
|
|
|
|
detachedPanelContainer.Add(expandedPanel);
|
|
|
|
|
2020-06-22 14:42:55 +08:00
|
|
|
// Move into its original location in the local container first, then to the final location.
|
2020-06-19 16:28:35 +08:00
|
|
|
var origLocation = detachedPanelContainer.ToLocalSpace(screenSpacePos);
|
2020-06-22 14:42:55 +08:00
|
|
|
expandedPanel.MoveTo(origLocation)
|
|
|
|
.Then()
|
|
|
|
.MoveTo(new Vector2(StatisticsPanel.SIDE_PADDING, origLocation.Y), 150, Easing.OutQuint);
|
2020-06-19 16:28:35 +08:00
|
|
|
|
|
|
|
// Hide contracted panels.
|
|
|
|
foreach (var contracted in scorePanelList.GetScorePanels().Where(p => p.State == PanelState.Contracted))
|
|
|
|
contracted.FadeOut(150, Easing.OutQuint);
|
|
|
|
scorePanelList.HandleInput = false;
|
|
|
|
|
|
|
|
// Dim background.
|
|
|
|
Background.FadeTo(0.1f, 150);
|
|
|
|
|
|
|
|
detachedPanel = expandedPanel;
|
2020-06-18 15:50:45 +08:00
|
|
|
}
|
2020-06-19 16:28:35 +08:00
|
|
|
else if (detachedPanel != null)
|
2020-06-18 15:50:45 +08:00
|
|
|
{
|
2020-06-19 16:28:35 +08:00
|
|
|
var screenSpacePos = detachedPanel.ScreenSpaceDrawQuad.TopLeft;
|
2020-06-18 21:27:27 +08:00
|
|
|
|
2020-06-19 16:28:35 +08:00
|
|
|
// Remove from the local container and re-attach.
|
|
|
|
detachedPanelContainer.Remove(detachedPanel);
|
|
|
|
scorePanelList.Attach(detachedPanel);
|
2020-06-18 15:50:45 +08:00
|
|
|
|
2020-06-22 14:42:55 +08:00
|
|
|
// Move into its original location in the attached container first, then to the final location.
|
2020-06-19 16:28:35 +08:00
|
|
|
var origLocation = detachedPanel.Parent.ToLocalSpace(screenSpacePos);
|
2020-06-22 14:42:55 +08:00
|
|
|
detachedPanel.MoveTo(origLocation)
|
|
|
|
.Then()
|
|
|
|
.MoveTo(new Vector2(0, origLocation.Y), 150, Easing.OutQuint);
|
2020-06-19 16:28:35 +08:00
|
|
|
|
|
|
|
// Show contracted panels.
|
|
|
|
foreach (var contracted in scorePanelList.GetScorePanels().Where(p => p.State == PanelState.Contracted))
|
|
|
|
contracted.FadeIn(150, Easing.OutQuint);
|
|
|
|
scorePanelList.HandleInput = true;
|
|
|
|
|
|
|
|
// Un-dim background.
|
|
|
|
Background.FadeTo(0.5f, 150);
|
|
|
|
|
|
|
|
detachedPanel = null;
|
2020-03-17 21:21:16 +08:00
|
|
|
}
|
|
|
|
}
|
2020-06-30 15:36:53 +08:00
|
|
|
|
|
|
|
private class VerticalScrollContainer : OsuScrollContainer
|
|
|
|
{
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
|
|
private readonly Container content;
|
|
|
|
|
|
|
|
public VerticalScrollContainer()
|
|
|
|
{
|
|
|
|
base.Content.Add(content = new Container { RelativeSizeAxes = Axes.X });
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
content.Height = Math.Max(screen_height, DrawHeight);
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 16:43:16 +08:00
|
|
|
}
|
|
|
|
}
|