osu/osu.Game/Overlays/FirstRunSetupOverlay.cs

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

373 lines
13 KiB
C#
Raw Normal View History

2022-04-06 08:42:10 +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.
#nullable enable
using System;
using System.Diagnostics;
2022-04-06 08:42:10 +00:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2022-04-06 08:42:10 +00:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
2022-04-06 08:42:10 +00:00
using osu.Framework.Screens;
using osu.Game.Configuration;
2022-04-06 08:42:10 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
2022-04-06 08:42:10 +00:00
using osu.Game.Overlays.FirstRunSetup;
using osu.Game.Overlays.Notifications;
2022-04-18 09:58:14 +00:00
using osu.Game.Screens;
2022-04-06 08:42:10 +00:00
using osu.Game.Screens.Menu;
using osu.Game.Screens.OnlinePlay.Match.Components;
2022-04-06 08:42:10 +00:00
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays
{
[Cached]
public class FirstRunSetupOverlay : OsuFocusedOverlayContainer
{
protected override bool StartHidden => true;
2022-04-18 09:58:14 +00: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 04:48:43 +00:00
private ScreenStack? stack;
2022-04-18 07:34:13 +00:00
public PurpleTriangleButton NextButton = null!;
public DangerousTriangleButton BackButton = null!;
2022-04-06 08:42:10 +00:00
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
2022-04-06 08:42:10 +00:00
private readonly Bindable<bool> showFirstRunSetup = new Bindable<bool>();
private int? currentStepIndex;
private const float scale_when_hidden = 0.9f;
2022-04-18 07:34:13 +00:00
/// <summary>
/// The currently displayed screen, if any.
/// </summary>
2022-04-19 04:48:43 +00:00
public FirstRunSetupScreen? CurrentScreen => (FirstRunSetupScreen?)stack?.CurrentScreen;
2022-04-18 07:34:13 +00:00
private readonly FirstRunStep[] steps =
{
new FirstRunStep(typeof(ScreenWelcome), FirstRunSetupOverlayStrings.Welcome),
new FirstRunStep(typeof(ScreenUIScale), GraphicsSettingsStrings.UIScaling),
};
2022-04-06 08:42:10 +00:00
private Container stackContainer = null!;
2022-04-06 08:42:10 +00:00
public FirstRunSetupOverlay()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
2022-04-06 08:42:10 +00:00
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
Size = new Vector2(0.95f);
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Radius = 5,
Colour = Color4.Black.Opacity(0.2f),
};
Masking = true;
CornerRadius = 10;
2022-04-06 08:42:10 +00:00
Children = new Drawable[]
{
new Box
2022-04-06 08:42:10 +00:00
{
2022-04-06 09:11:32 +00:00
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background6,
},
new GridContainer
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
2022-04-06 08:42:10 +00:00
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
2022-04-06 08:42:10 +00:00
},
Content = new[]
2022-04-06 08:42:10 +00:00
{
new Drawable[]
2022-04-06 08:42:10 +00:00
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Box
{
Colour = colourProvider.Background5,
RelativeSizeAxes = Axes.Both,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding(10),
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = FirstRunSetupOverlayStrings.FirstRunSetup,
Font = OsuFont.Default.With(size: 32),
Colour = colourProvider.Content2,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
new OsuTextFlowContainer
{
Text = FirstRunSetupOverlayStrings.SetupOsuToSuitYou,
Colour = colourProvider.Content1,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
},
}
},
}
},
},
new Drawable[]
{
stackContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(20),
},
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2022-04-19 07:53:41 +00:00
Padding = new MarginPadding(20)
{
Top = 0 // provided by the stack container above.
},
Child = new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
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 = showLastStep,
Enabled = { Value = false },
},
Empty(),
NextButton = new PurpleTriangleButton
{
RelativeSizeAxes = Axes.X,
Width = 1,
Text = FirstRunSetupOverlayStrings.GetStarted,
Action = showNextStep
}
},
}
},
}
}
2022-04-06 08:42:10 +00:00
}
},
2022-04-06 08:42:10 +00:00
};
}
protected override void LoadComplete()
{
base.LoadComplete();
config.BindWith(OsuSetting.ShowFirstRunSetup, showFirstRunSetup);
if (showFirstRunSetup.Value)
{
// if we are valid for display, only do so after reaching the main menu.
performer.PerformFromScreen(_ => { Show(); }, new[] { typeof(MainMenu) });
}
2022-04-06 08:42:10 +00:00
}
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (!e.Repeat)
{
switch (e.Action)
{
case GlobalAction.Select:
NextButton.TriggerClick();
return true;
2022-04-19 04:48:43 +00: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 08:42:10 +00:00
return base.OnPressed(e);
}
protected override void PopIn()
{
base.PopIn();
this.ScaleTo(scale_when_hidden)
.ScaleTo(1, 400, Easing.OutElasticHalf);
this.FadeIn(400, Easing.OutQuint);
if (currentStepIndex == null)
showFirstStep();
}
2022-04-06 08:42:10 +00:00
protected override void PopOut()
{
if (currentStepIndex != null)
{
notificationOverlay.Post(new SimpleNotification
{
Text = FirstRunSetupOverlayStrings.ClickToResumeFirstRunSetupAtAnyPoint,
Icon = FontAwesome.Solid.Horse,
Activated = () =>
{
Show();
return true;
},
});
}
else
{
2022-04-19 04:48:43 +00:00
stack?.FadeOut(100)
.Expire();
}
2022-04-06 08:42:10 +00:00
base.PopOut();
this.ScaleTo(0.96f, 400, Easing.OutQuint);
this.FadeOut(200, Easing.OutQuint);
2022-04-06 08:42:10 +00:00
}
private void showFirstStep()
{
Debug.Assert(currentStepIndex == null);
stackContainer.Child = stack = new ScreenStack
{
RelativeSizeAxes = Axes.Both,
};
currentStepIndex = -1;
showNextStep();
}
private void showLastStep()
{
if (currentStepIndex == 0)
return;
Debug.Assert(stack != null);
stack.CurrentScreen.Exit();
currentStepIndex--;
BackButton.Enabled.Value = currentStepIndex != 0;
updateButtonText();
}
private void showNextStep()
{
Debug.Assert(currentStepIndex != null);
Debug.Assert(stack != null);
currentStepIndex++;
BackButton.Enabled.Value = currentStepIndex > 0;
if (currentStepIndex < steps.Length)
{
stack.Push((Screen)Activator.CreateInstance(steps[currentStepIndex.Value].ScreenType));
updateButtonText();
}
else
{
showFirstRunSetup.Value = false;
currentStepIndex = null;
Hide();
}
}
private void updateButtonText()
{
Debug.Assert(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 08:42:10 +00:00
}
}