1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 05:52:54 +08:00
osu-lazer/osu.Game/Overlays/FirstRunSetupOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

349 lines
11 KiB
C#
Raw Normal View History

2022-04-06 16:42:10 +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.
using System;
2022-05-16 18:21:26 +08:00
using System.Collections.Generic;
using System.Diagnostics;
2022-04-06 16:42:10 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
2022-04-06 16:42:10 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
2022-04-06 16:42:10 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
2022-04-06 16:42:10 +08:00
using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Game.Configuration;
2022-05-16 18:21:26 +08:00
using osu.Game.Database;
2022-04-06 16:42:10 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
2022-04-06 16:42:10 +08:00
using osu.Game.Overlays.FirstRunSetup;
using osu.Game.Overlays.Mods;
using osu.Game.Overlays.Notifications;
2022-04-18 17:58:14 +08:00
using osu.Game.Screens;
using osu.Game.Screens.Footer;
2022-04-06 16:42:10 +08:00
using osu.Game.Screens.Menu;
namespace osu.Game.Overlays
{
[Cached]
public partial class FirstRunSetupOverlay : ShearedOverlayContainer
2022-04-06 16:42:10 +08:00
{
2022-04-18 17:58:14 +08:00
[Resolved]
private IPerformFromScreenRunner performer { get; set; } = null!;
[Resolved]
private INotificationOverlay notificationOverlay { get; set; } = null!;
[Resolved]
private OsuConfigManager config { get; set; } = null!;
2022-04-19 12:48:43 +08:00
private ScreenStack? stack;
public ShearedButton? NextButton => DisplayedFooterContent?.NextButton;
2022-04-06 16:42:10 +08:00
private readonly Bindable<bool> showFirstRunSetup = new Bindable<bool>();
private int? currentStepIndex;
2022-04-18 15:34:13 +08:00
/// <summary>
/// The currently displayed screen, if any.
/// </summary>
2022-04-19 12:48:43 +08:00
public FirstRunSetupScreen? CurrentScreen => (FirstRunSetupScreen?)stack?.CurrentScreen;
2022-04-18 15:34:13 +08:00
2022-05-16 18:21:26 +08:00
private readonly List<Type> steps = new List<Type>();
2022-04-06 16:42:10 +08:00
private Container screenContent = null!;
private Container content = null!;
2022-04-06 16:42:10 +08:00
private LoadingSpinner loading = null!;
private ScheduledDelegate? loadingShowDelegate;
public FirstRunSetupOverlay()
: base(OverlayColourScheme.Purple)
{
}
2022-05-16 18:21:26 +08:00
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, LegacyImportManager? legacyImportManager)
2022-04-06 16:42:10 +08:00
{
2022-05-16 18:21:26 +08:00
steps.Add(typeof(ScreenWelcome));
steps.Add(typeof(ScreenUIScale));
2022-05-16 18:21:26 +08:00
steps.Add(typeof(ScreenBeatmaps));
if (legacyImportManager?.SupportsImportFromStable == true)
steps.Add(typeof(ScreenImportFromStable));
steps.Add(typeof(ScreenBehaviour));
Header.Title = FirstRunSetupOverlayStrings.FirstRunSetupTitle;
Header.Description = FirstRunSetupOverlayStrings.FirstRunSetupDescription;
MainAreaContent.AddRange(new Drawable[]
{
content = new PopoverContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Bottom = 20 },
2022-05-10 18:56:21 +08:00
Child = new GridContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
2022-04-06 16:42:10 +08:00
{
new Dimension(),
new Dimension(minSize: 640, maxSize: 800),
new Dimension(),
},
Content = new[]
{
new[]
{
Empty(),
new InputBlockingContainer
2022-04-19 15:53:41 +08:00
{
Masking = true,
CornerRadius = 14,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourProvider.Background6,
},
loading = new LoadingSpinner(),
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Vertical = 20 },
Child = screenContent = new Container { RelativeSizeAxes = Axes.Both, },
},
},
},
Empty(),
},
}
}
},
});
2022-04-06 16:42:10 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
config.BindWith(OsuSetting.ShowFirstRunSetup, showFirstRunSetup);
if (showFirstRunSetup.Value) Show();
2022-04-06 16:42:10 +08:00
}
[Resolved]
private ScreenFooter footer { get; set; } = null!;
public new FirstRunSetupFooterContent? DisplayedFooterContent => base.DisplayedFooterContent as FirstRunSetupFooterContent;
public override VisibilityContainer CreateFooterContent()
{
var footerContent = new FirstRunSetupFooterContent
{
ShowNextStep = showNextStep,
};
footerContent.OnLoadComplete += _ => updateButtons();
return footerContent;
}
public override bool OnBackButton()
{
if (currentStepIndex == 0)
return false;
Debug.Assert(stack != null);
stack.CurrentScreen.Exit();
currentStepIndex--;
updateButtons();
return true;
}
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (!e.Repeat)
{
switch (e.Action)
{
case GlobalAction.Select:
DisplayedFooterContent?.NextButton.TriggerClick();
return true;
2022-04-19 12:48:43 +08:00
case GlobalAction.Back:
footer.BackButton.TriggerClick();
return false;
}
}
2022-04-06 16:42:10 +08:00
return base.OnPressed(e);
}
public override void Show()
{
// if we are valid for display, only do so after reaching the main menu.
performer.PerformFromScreen(screen =>
{
// Hides the toolbar for us.
if (screen is MainMenu menu)
menu.ReturnToOsuLogo();
base.Show();
}, new[] { typeof(MainMenu) });
}
protected override void PopIn()
{
base.PopIn();
content.ScaleTo(0.99f)
.ScaleTo(1, 400, Easing.OutQuint);
if (currentStepIndex == null)
showFirstStep();
}
2022-04-06 16:42:10 +08:00
protected override void PopOut()
{
base.PopOut();
content.ScaleTo(0.99f, 400, Easing.OutQuint);
if (currentStepIndex != null)
{
notificationOverlay.Post(new SimpleNotification
{
Text = FirstRunSetupOverlayStrings.ClickToResumeFirstRunSetupAtAnyPoint,
Icon = FontAwesome.Solid.Redo,
Activated = () =>
{
Show();
return true;
},
});
}
else
{
2022-04-19 12:48:43 +08:00
stack?.FadeOut(100)
.Expire();
}
2022-04-06 16:42:10 +08:00
}
private void showFirstStep()
{
Debug.Assert(currentStepIndex == null);
screenContent.Child = stack = new ScreenStack
{
RelativeSizeAxes = Axes.Both,
};
currentStepIndex = -1;
showNextStep();
}
private void showNextStep()
{
Debug.Assert(currentStepIndex != null);
Debug.Assert(stack != null);
currentStepIndex++;
2022-05-16 18:21:26 +08:00
if (currentStepIndex < steps.Count)
{
var nextScreen = (Screen)Activator.CreateInstance(steps[currentStepIndex.Value])!;
loadingShowDelegate = Scheduler.AddDelayed(() => loading.Show(), 200);
nextScreen.OnLoadComplete += _ =>
{
loadingShowDelegate?.Cancel();
loading.Hide();
};
stack.Push(nextScreen);
}
else
{
showFirstRunSetup.Value = false;
currentStepIndex = null;
Hide();
}
updateButtons();
}
private void updateButtons() => DisplayedFooterContent?.UpdateButtons(currentStepIndex, steps);
public partial class FirstRunSetupFooterContent : VisibilityContainer
{
public ShearedButton NextButton { get; private set; } = null!;
public Action? ShowNextStep;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
RelativeSizeAxes = Axes.Both;
InternalChild = NextButton = new ShearedButton(0)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Margin = new MarginPadding { Right = 12f },
RelativeSizeAxes = Axes.X,
Width = 1,
Text = FirstRunSetupOverlayStrings.GetStarted,
DarkerColour = colourProvider.Colour2,
LighterColour = colourProvider.Colour1,
Action = () => ShowNextStep?.Invoke(),
};
}
2022-04-26 15:03:15 +08:00
public void UpdateButtons(int? currentStep, IReadOnlyList<Type> steps)
{
NextButton.Enabled.Value = currentStep != null;
if (currentStep == null)
return;
bool isFirstStep = currentStep == 0;
bool isLastStep = currentStep == steps.Count - 1;
if (isFirstStep)
NextButton.Text = FirstRunSetupOverlayStrings.GetStarted;
else
{
NextButton.Text = isLastStep
? CommonStrings.Finish
: LocalisableString.Interpolate($@"{CommonStrings.Next} ({steps[currentStep.Value + 1].GetLocalisableDescription()})");
}
2022-04-26 15:03:15 +08:00
}
protected override void PopIn()
2022-04-26 15:03:15 +08:00
{
this.FadeIn();
}
2022-04-26 15:03:15 +08:00
protected override void PopOut()
{
this.Delay(400).FadeOut();
}
}
2022-04-06 16:42:10 +08:00
}
}