1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +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.

326 lines
10 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.
#nullable enable
using System;
using System.Diagnostics;
2022-04-06 16:42:10 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2022-04-06 16:42:10 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
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.Game.Configuration;
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;
2022-04-06 16:42:10 +08:00
using osu.Game.Screens.Menu;
using osu.Game.Screens.OnlinePlay.Match.Components;
2022-04-06 16:42:10 +08:00
namespace osu.Game.Overlays
{
[Cached]
public class FirstRunSetupOverlay : ShearedOverlayContainer
2022-04-06 16:42:10 +08:00
{
protected override OverlayColourScheme ColourScheme => OverlayColourScheme.Purple;
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;
2022-04-18 15:34:13 +08:00
public PurpleTriangleButton NextButton = null!;
public DangerousTriangleButton BackButton = null!;
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
private readonly FirstRunStep[] steps =
{
new FirstRunStep(typeof(ScreenWelcome), FirstRunSetupOverlayStrings.Welcome),
new FirstRunStep(typeof(ScreenUIScale), GraphicsSettingsStrings.UIScaling),
};
2022-04-06 16:42:10 +08:00
private Container stackContainer = null!;
private Bindable<OverlayActivation>? overlayActivationMode;
private Container content = null!;
2022-04-06 16:42:10 +08:00
[BackgroundDependencyLoader]
private void load()
2022-04-06 16:42:10 +08:00
{
Header.Title = FirstRunSetupOverlayStrings.FirstRunSetup;
Header.Description = FirstRunSetupOverlayStrings.SetupOsuToSuitYou;
MainAreaContent.AddRange(new Drawable[]
{
content = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 50 },
Child = new InputBlockingContainer
2022-04-06 16:42:10 +08:00
{
Masking = true,
CornerRadius = 14,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2022-04-06 16:42:10 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourProvider.Background6,
},
stackContainer = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
2022-04-19 15:53:41 +08:00
{
Vertical = 20,
Horizontal = 20,
},
}
},
},
},
});
FooterContent.Add(new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Width = 0.98f,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Absolute, 10),
new Dimension(),
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
new[]
{
BackButton = new DangerousTriangleButton
{
Width = 200,
Text = CommonStrings.Back,
Action = showPreviousStep,
Enabled = { Value = false },
},
Empty(),
NextButton = new PurpleTriangleButton
{
RelativeSizeAxes = Axes.X,
Width = 1,
Text = FirstRunSetupOverlayStrings.GetStarted,
Action = showNextStep
}
},
}
});
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
}
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (!e.Repeat)
{
switch (e.Action)
{
case GlobalAction.Select:
NextButton.TriggerClick();
return true;
2022-04-19 12:48:43 +08:00
case GlobalAction.Back:
if (BackButton.Enabled.Value)
{
BackButton.TriggerClick();
return true;
}
// If back button is disabled, we are at the first step.
// The base call will handle dismissal of the overlay.
break;
}
}
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 =>
{
MainMenu menu = (MainMenu)screen;
// Eventually I'd like to replace this with a better method that doesn't access the screen.
// Either this dialog would be converted to its own screen, or at very least be "hosted" by a screen pushed to the main menu.
// Alternatively, another method of disabling notifications could be added to `INotificationOverlay`.
if (menu != null)
{
overlayActivationMode = menu.OverlayActivationMode.GetBoundCopy();
overlayActivationMode.Value = OverlayActivation.UserTriggered;
}
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 (overlayActivationMode != null)
{
// If this is non-null we are guaranteed to have come from the main menu.
overlayActivationMode.Value = OverlayActivation.All;
overlayActivationMode = null;
}
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);
stackContainer.Child = stack = new ScreenStack
{
RelativeSizeAxes = Axes.Both,
};
currentStepIndex = -1;
showNextStep();
}
private void showPreviousStep()
{
if (currentStepIndex == 0)
return;
Debug.Assert(stack != null);
stack.CurrentScreen.Exit();
currentStepIndex--;
updateButtons();
}
private void showNextStep()
{
Debug.Assert(currentStepIndex != null);
Debug.Assert(stack != null);
currentStepIndex++;
if (currentStepIndex < steps.Length)
{
stack.Push((Screen)Activator.CreateInstance(steps[currentStepIndex.Value].ScreenType));
}
else
{
showFirstRunSetup.Value = false;
currentStepIndex = null;
Hide();
}
updateButtons();
}
private void updateButtons()
{
BackButton.Enabled.Value = currentStepIndex > 0;
NextButton.Enabled.Value = currentStepIndex != null;
if (currentStepIndex != null)
{
NextButton.Text = currentStepIndex + 1 < steps.Length
? FirstRunSetupOverlayStrings.Next(steps[currentStepIndex.Value + 1].Description)
: CommonStrings.Finish;
}
}
private class FirstRunStep
{
public readonly Type ScreenType;
public readonly LocalisableString Description;
public FirstRunStep(Type screenType, LocalisableString description)
{
ScreenType = screenType;
Description = description;
}
}
2022-04-06 16:42:10 +08:00
}
}