2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2018-08-02 17:16:36 +08:00
|
|
|
|
using System.Linq;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-05-09 22:31:52 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Screens;
|
2018-05-09 22:31:52 +08:00
|
|
|
|
using osu.Framework.Threading;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-08-02 18:47:50 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Screens.Menu;
|
|
|
|
|
using osu.Game.Screens.Play.PlayerSettings;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
|
|
|
|
public class PlayerLoader : ScreenWithBeatmapBackground
|
|
|
|
|
{
|
2018-08-02 17:16:36 +08:00
|
|
|
|
private static readonly Vector2 background_blur = new Vector2(15);
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private Player player;
|
|
|
|
|
|
|
|
|
|
private BeatmapMetadataDisplay info;
|
|
|
|
|
|
2018-05-21 21:53:50 +08:00
|
|
|
|
private bool hideOverlays;
|
|
|
|
|
protected override bool HideOverlaysOnEnter => hideOverlays;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private Task loadTask;
|
|
|
|
|
|
|
|
|
|
public PlayerLoader(Player player)
|
|
|
|
|
{
|
|
|
|
|
this.player = player;
|
|
|
|
|
|
|
|
|
|
player.RestartRequested = () =>
|
|
|
|
|
{
|
2018-05-21 21:53:50 +08:00
|
|
|
|
hideOverlays = true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
ValidForResume = true;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2018-05-23 16:37:39 +08:00
|
|
|
|
Add(info = new BeatmapMetadataDisplay(Beatmap.Value)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-09 22:31:52 +08:00
|
|
|
|
Add(new FillFlowContainer<PlayerSettingsGroup>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
2018-05-09 22:31:52 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 20),
|
2018-05-21 23:57:01 +08:00
|
|
|
|
Margin = new MarginPadding(25),
|
2018-05-09 22:31:52 +08:00
|
|
|
|
Children = new PlayerSettingsGroup[]
|
|
|
|
|
{
|
2018-08-02 17:16:36 +08:00
|
|
|
|
visualSettings = new VisualSettings(),
|
2018-05-09 22:31:52 +08:00
|
|
|
|
new InputSettings()
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
2018-08-02 18:47:50 +08:00
|
|
|
|
loadTask = LoadComponentAsync(player, playerLoaded);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 18:47:50 +08:00
|
|
|
|
private void playerLoaded(Player player) => info.Loading = false;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected override void OnResuming(Screen last)
|
|
|
|
|
{
|
|
|
|
|
base.OnResuming(last);
|
|
|
|
|
|
|
|
|
|
contentIn();
|
|
|
|
|
|
2018-08-02 18:47:50 +08:00
|
|
|
|
info.Loading = true;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
//we will only be resumed if the player has requested a re-run (see ValidForResume setting above)
|
|
|
|
|
loadTask = LoadComponentAsync(player = new Player
|
|
|
|
|
{
|
|
|
|
|
RestartCount = player.RestartCount + 1,
|
|
|
|
|
RestartRequested = player.RestartRequested,
|
2018-08-02 18:47:50 +08:00
|
|
|
|
}, playerLoaded);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
this.Delay(400).Schedule(pushWhenLoaded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void contentIn()
|
|
|
|
|
{
|
|
|
|
|
Content.ScaleTo(1, 650, Easing.OutQuint);
|
|
|
|
|
Content.FadeInFromZero(400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void contentOut()
|
|
|
|
|
{
|
|
|
|
|
Content.ScaleTo(0.7f, 300, Easing.InQuint);
|
|
|
|
|
Content.FadeOut(250);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnEntering(Screen last)
|
|
|
|
|
{
|
|
|
|
|
base.OnEntering(last);
|
|
|
|
|
|
|
|
|
|
Content.ScaleTo(0.7f);
|
|
|
|
|
|
|
|
|
|
contentIn();
|
|
|
|
|
|
|
|
|
|
info.Delay(750).FadeIn(500);
|
|
|
|
|
this.Delay(1800).Schedule(pushWhenLoaded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
|
|
|
|
{
|
|
|
|
|
base.LogoArriving(logo, resuming);
|
|
|
|
|
|
|
|
|
|
logo.RelativePositionAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
logo.ScaleTo(new Vector2(0.15f), 300, Easing.In);
|
|
|
|
|
logo.MoveTo(new Vector2(0.5f), 300, Easing.In);
|
|
|
|
|
logo.FadeIn(350);
|
|
|
|
|
|
|
|
|
|
logo.Delay(resuming ? 0 : 500).MoveToOffset(new Vector2(0, -0.24f), 500, Easing.InOutExpo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScheduledDelegate pushDebounce;
|
2018-08-02 17:16:36 +08:00
|
|
|
|
private VisualSettings visualSettings;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-01 15:20:29 +08:00
|
|
|
|
private bool readyForPush => player.LoadState == LoadState.Ready && IsHovered && GetContainingInputManager()?.DraggedDrawable == null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-08-02 17:16:36 +08:00
|
|
|
|
{
|
|
|
|
|
// restore our screen defaults
|
|
|
|
|
InitializeBackgroundElements();
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnHover(e);
|
2018-08-02 17:16:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-08-02 17:16:36 +08:00
|
|
|
|
{
|
|
|
|
|
if (GetContainingInputManager().HoveredDrawables.Contains(visualSettings))
|
|
|
|
|
{
|
|
|
|
|
// show user setting preview
|
|
|
|
|
UpdateBackgroundElements();
|
|
|
|
|
}
|
2018-10-02 11:02:47 +08:00
|
|
|
|
base.OnHoverLost(e);
|
2018-08-02 17:16:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void InitializeBackgroundElements()
|
|
|
|
|
{
|
|
|
|
|
Background?.FadeTo(1, BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
|
|
|
|
Background?.BlurTo(background_blur, BACKGROUND_FADE_DURATION, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private void pushWhenLoaded()
|
|
|
|
|
{
|
|
|
|
|
if (!IsCurrentScreen) return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!readyForPush)
|
|
|
|
|
{
|
|
|
|
|
// as the pushDebounce below has a delay, we need to keep checking and cancel a future debounce
|
|
|
|
|
// if we become unready for push during the delay.
|
|
|
|
|
cancelLoad();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pushDebounce != null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pushDebounce = Scheduler.AddDelayed(() =>
|
|
|
|
|
{
|
|
|
|
|
contentOut();
|
|
|
|
|
|
|
|
|
|
this.Delay(250).Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
if (!IsCurrentScreen) return;
|
|
|
|
|
|
|
|
|
|
loadTask = null;
|
|
|
|
|
|
2018-04-20 15:52:15 +08:00
|
|
|
|
//By default, we want to load the player and never be returned to.
|
|
|
|
|
//Note that this may change if the player we load requested a re-run.
|
|
|
|
|
ValidForResume = false;
|
|
|
|
|
|
2018-04-20 16:30:27 +08:00
|
|
|
|
if (player.LoadedBeatmapSuccessfully)
|
|
|
|
|
Push(player);
|
|
|
|
|
else
|
|
|
|
|
Exit();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Schedule(pushWhenLoaded);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancelLoad()
|
|
|
|
|
{
|
|
|
|
|
pushDebounce?.Cancel();
|
|
|
|
|
pushDebounce = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnSuspending(Screen next)
|
|
|
|
|
{
|
|
|
|
|
base.OnSuspending(next);
|
|
|
|
|
cancelLoad();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnExiting(Screen next)
|
|
|
|
|
{
|
|
|
|
|
Content.ScaleTo(0.7f, 150, Easing.InQuint);
|
|
|
|
|
this.FadeOut(150);
|
|
|
|
|
cancelLoad();
|
|
|
|
|
|
|
|
|
|
return base.OnExiting(next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
2018-05-30 14:47:31 +08:00
|
|
|
|
if (isDisposing)
|
|
|
|
|
{
|
|
|
|
|
// if the player never got pushed, we should explicitly dispose it.
|
|
|
|
|
loadTask?.ContinueWith(_ => player.Dispose());
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class BeatmapMetadataDisplay : Container
|
|
|
|
|
{
|
|
|
|
|
private class MetadataLine : Container
|
|
|
|
|
{
|
|
|
|
|
public MetadataLine(string left, string right)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Margin = new MarginPadding { Right = 5 },
|
2018-08-02 17:16:36 +08:00
|
|
|
|
Colour = OsuColour.Gray(0.8f),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Text = left,
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
Margin = new MarginPadding { Left = 5 },
|
|
|
|
|
Text = string.IsNullOrEmpty(right) ? @"-" : right,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly WorkingBeatmap beatmap;
|
2018-08-02 18:47:50 +08:00
|
|
|
|
private LoadingAnimation loading;
|
|
|
|
|
private Sprite backgroundSprite;
|
|
|
|
|
|
|
|
|
|
public bool Loading
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
loading.Show();
|
|
|
|
|
backgroundSprite.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
loading.Hide();
|
|
|
|
|
backgroundSprite.FadeColour(Color4.White, 400, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public BeatmapMetadataDisplay(WorkingBeatmap beatmap)
|
|
|
|
|
{
|
|
|
|
|
this.beatmap = beatmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-09-19 13:07:46 +08:00
|
|
|
|
private void load()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
var metadata = beatmap?.BeatmapInfo?.Metadata ?? new BeatmapMetadata();
|
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2018-09-19 13:07:46 +08:00
|
|
|
|
Text = new LocalisedString((metadata.TitleUnicode, metadata.Title)),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
TextSize = 36,
|
|
|
|
|
Font = @"Exo2.0-MediumItalic",
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2018-09-19 13:07:46 +08:00
|
|
|
|
Text = new LocalisedString((metadata.ArtistUnicode, metadata.Artist)),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
TextSize = 26,
|
|
|
|
|
Font = @"Exo2.0-MediumItalic",
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(300, 60),
|
|
|
|
|
Margin = new MarginPadding(10),
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
CornerRadius = 10,
|
|
|
|
|
Masking = true,
|
2018-08-02 18:47:50 +08:00
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-08-02 18:47:50 +08:00
|
|
|
|
backgroundSprite = new Sprite
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Texture = beatmap?.Background,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
|
},
|
2018-08-02 18:47:50 +08:00
|
|
|
|
loading = new LoadingAnimation { Scale = new Vector2(1.3f) }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = beatmap?.BeatmapInfo?.Version,
|
|
|
|
|
TextSize = 26,
|
|
|
|
|
Font = @"Exo2.0-MediumItalic",
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Bottom = 40
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new MetadataLine("Source", metadata.Source)
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
},
|
|
|
|
|
new MetadataLine("Mapper", metadata.AuthorString)
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-08-02 18:47:50 +08:00
|
|
|
|
|
|
|
|
|
Loading = true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|