osu/osu.Game/Screens/Ranking/ResultsScreen.cs

245 lines
9.0 KiB
C#
Raw Normal View History

2020-03-17 08:43:16 +00: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 09:28:42 +00:00
using System;
2020-05-26 08:00:41 +00:00
using System.Collections.Generic;
2020-03-17 08:43:16 +00:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2020-03-17 08:43:16 +00: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 13:21:16 +00:00
using osu.Game.Graphics.Containers;
2020-03-17 08:43:16 +00:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
2020-03-17 08:43:16 +00:00
using osu.Game.Scoring;
using osu.Game.Screens.Backgrounds;
2020-03-17 08:45:25 +00:00
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking.Statistics;
2020-03-17 08:43:16 +00:00
using osuTK;
namespace osu.Game.Screens.Ranking
{
2020-05-26 08:00:41 +00:00
public abstract class ResultsScreen : OsuScreen
2020-03-17 08:43:16 +00:00
{
protected const float BACKGROUND_BLUR = 20;
private static readonly float screen_height = 768 - TwoLayerButton.SIZE_EXTENDED.Y;
2020-03-17 08:43:16 +00: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);
public readonly Bindable<ScoreInfo> SelectedScore = new Bindable<ScoreInfo>();
public readonly ScoreInfo Score;
private readonly bool allowRetry;
2020-03-17 08:45:25 +00:00
[Resolved(CanBeNull = true)]
private Player player { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
private StatisticsPanel statisticsPanel;
2020-03-17 08:43:16 +00:00
private Drawable bottomPanel;
private ScorePanelList scorePanelList;
2020-03-17 08:43:16 +00:00
2020-05-26 08:31:50 +00:00
protected ResultsScreen(ScoreInfo score, bool allowRetry = true)
2020-03-17 08:43:16 +00:00
{
2020-03-29 14:50:16 +00:00
Score = score;
this.allowRetry = allowRetry;
SelectedScore.Value = score;
2020-03-17 08:43:16 +00:00
}
[BackgroundDependencyLoader]
private void load()
{
FillFlowContainer buttons;
InternalChild = new GridContainer
2020-03-17 08:43:16 +00:00
{
RelativeSizeAxes = Axes.Both,
Content = new[]
2020-03-17 08:43:16 +00:00
{
new Drawable[]
2020-03-17 13:21:16 +00:00
{
2020-06-17 13:29:00 +00:00
new Container
2020-03-17 08:43:16 +00:00
{
2020-06-17 13:29:00 +00:00
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,
Child = new Container
{
RelativeSizeAxes = Axes.X,
Height = screen_height,
2020-06-17 13:29:00 +00:00
Children = new Drawable[]
{
scorePanelList = new ScorePanelList
2020-06-17 13:29:00 +00:00
{
RelativeSizeAxes = Axes.Both,
SelectedScore = { BindTarget = SelectedScore },
PostExpandAction = onExpandedPanelClicked
2020-06-17 13:29:00 +00:00
},
statisticsPanel = new StatisticsPanel
{
RelativeSizeAxes = Axes.Both,
Score = { BindTarget = SelectedScore }
}
2020-06-17 13:29:00 +00:00
}
}
2020-06-17 13:29:00 +00:00
},
}
}
},
new[]
{
bottomPanel = new Container
2020-03-17 08:43:16 +00:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = TwoLayerButton.SIZE_EXTENDED.Y,
Alpha = 0,
2020-03-17 08:43:16 +00: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(null)
{
Score = { BindTarget = SelectedScore },
Width = 300
},
}
}
2020-03-17 08:43:16 +00:00
}
}
}
},
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize)
2020-03-17 08:43:16 +00:00
}
};
2020-03-17 08:45:25 +00:00
if (Score != null)
scorePanelList.AddScore(Score);
2020-03-30 09:56:35 +00:00
if (player != null && allowRetry)
2020-03-17 08:45:25 +00:00
{
2020-03-30 09:56:35 +00:00
buttons.Add(new RetryButton { Width = 300 });
2020-03-30 09:56:35 +00:00
AddInternal(new HotkeyRetryOverlay
{
Action = () =>
2020-03-17 08:45:25 +00:00
{
2020-03-30 09:56:35 +00:00
if (!this.IsCurrentScreen()) return;
2020-03-17 08:45:25 +00:00
2020-03-30 09:56:35 +00:00
player?.Restart();
},
});
2020-03-17 08:45:25 +00:00
}
2020-03-17 08:43:16 +00:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2020-05-26 08:00:41 +00:00
var req = FetchScores(scores => Schedule(() =>
{
2020-05-26 08:00:41 +00:00
foreach (var s in scores)
scorePanelList.AddScore(s);
2020-05-26 08:00:41 +00:00
}));
2020-05-26 08:00:41 +00:00
if (req != null)
api.Queue(req);
}
2020-05-26 08:00:41 +00: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 08:43:16 +00: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 13:21:16 +00:00
private void onExpandedPanelClicked()
2020-03-17 13:21:16 +00:00
{
statisticsPanel.ToggleVisibility();
2020-03-17 13:21:16 +00:00
if (statisticsPanel.State.Value == Visibility.Hidden)
2020-03-17 13:21:16 +00:00
{
foreach (var panel in scorePanelList.Panels)
{
if (panel.State == PanelState.Contracted)
panel.FadeIn(150);
else
{
panel.MoveTo(panel.GetTrackingPosition(), 150, Easing.OutQuint).OnComplete(p =>
{
scorePanelList.HandleScroll = true;
p.Tracking = true;
});
}
}
2020-06-18 13:27:10 +00:00
Background.FadeTo(0.5f, 150);
}
else
{
foreach (var panel in scorePanelList.Panels)
{
if (panel.State == PanelState.Contracted)
panel.FadeOut(150, Easing.OutQuint);
else
{
scorePanelList.HandleScroll = false;
panel.Tracking = false;
2020-06-18 08:06:05 +00:00
panel.MoveTo(new Vector2(scorePanelList.CurrentScrollPosition + StatisticsPanel.SIDE_PADDING, panel.GetTrackingPosition().Y), 150, Easing.OutQuint);
}
}
2020-06-18 13:27:10 +00:00
Background.FadeTo(0.1f, 150);
2020-03-17 13:21:16 +00:00
}
}
2020-03-17 08:43:16 +00:00
}
}