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.
|
|
|
|
|
2022-04-18 15:07:30 +08:00
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
2022-04-06 16:42:10 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
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.Input.Events;
|
2022-04-18 15:07:30 +08:00
|
|
|
using osu.Framework.Localisation;
|
2022-04-06 16:42:10 +08:00
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
2022-04-18 14:20:54 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-04-18 15:07:30 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-04-06 16:42:10 +08:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Overlays.Dialog;
|
|
|
|
using osu.Game.Overlays.FirstRunSetup;
|
|
|
|
using osu.Game.Screens.Menu;
|
2022-04-18 15:07:30 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
2022-04-06 16:42:10 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
public class FirstRunSetupOverlay : OsuFocusedOverlayContainer
|
|
|
|
{
|
|
|
|
protected override bool StartHidden => true;
|
|
|
|
|
2022-04-18 14:20:54 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
2022-04-18 15:07:30 +08:00
|
|
|
private DialogOverlay? dialogOverlay { get; set; }
|
2022-04-06 16:42:10 +08:00
|
|
|
|
2022-04-18 14:20:54 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
2022-04-18 15:07:30 +08:00
|
|
|
private OsuGame? osuGame { get; set; }
|
|
|
|
|
|
|
|
private ScreenStack stack = null!;
|
|
|
|
|
2022-04-18 15:34:13 +08:00
|
|
|
public PurpleTriangleButton NextButton = null!;
|
|
|
|
public DangerousTriangleButton BackButton = null!;
|
2022-04-06 16:42:10 +08:00
|
|
|
|
2022-04-18 14:20:54 +08:00
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
2022-04-06 16:42:10 +08:00
|
|
|
|
2022-04-18 15:07:30 +08:00
|
|
|
private int? currentStepIndex;
|
|
|
|
|
2022-04-18 15:34:13 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The currently displayed screen, if any.
|
|
|
|
/// </summary>
|
|
|
|
public FirstRunSetupScreen? CurrentScreen => (FirstRunSetupScreen?)stack.CurrentScreen;
|
|
|
|
|
2022-04-18 15:07:30 +08:00
|
|
|
private readonly FirstRunStep[] steps =
|
|
|
|
{
|
|
|
|
new FirstRunStep(typeof(ScreenWelcome), "Welcome"),
|
|
|
|
new FirstRunStep(typeof(ScreenSetupUIScale), "UI Scale"),
|
|
|
|
};
|
2022-04-06 16:42:10 +08:00
|
|
|
|
2022-04-18 16:10:08 +08:00
|
|
|
private Container mainContent;
|
|
|
|
|
2022-04-06 16:42:10 +08:00
|
|
|
public FirstRunSetupOverlay()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(IAPIProvider api, OsuColour colours)
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-04-18 16:10:08 +08:00
|
|
|
mainContent = new Container
|
2022-04-06 16:42:10 +08:00
|
|
|
{
|
2022-04-06 17:11:32 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-04-18 14:20:54 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(0.95f),
|
2022-04-06 16:42:10 +08:00
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = 5,
|
|
|
|
Colour = Color4.Black.Opacity(0.2f),
|
|
|
|
},
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 10,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-04-18 14:20:54 +08:00
|
|
|
Colour = colourProvider.Background5,
|
2022-04-06 16:42:10 +08:00
|
|
|
},
|
2022-04-18 14:20:54 +08:00
|
|
|
new GridContainer
|
2022-04-06 16:42:10 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-04-18 14:20:54 +08:00
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(),
|
2022-04-18 15:07:30 +08:00
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
2022-04-18 14:20:54 +08:00
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = colourProvider.Background6,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Margin = new MarginPadding(10),
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "First run setup",
|
|
|
|
Font = OsuFont.Default.With(size: 32),
|
|
|
|
Colour = colourProvider.Content2,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
},
|
|
|
|
new OsuTextFlowContainer
|
|
|
|
{
|
|
|
|
Text = "Setup osu! to suit you",
|
|
|
|
Colour = colourProvider.Content1,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
2022-04-18 15:07:30 +08:00
|
|
|
new Container
|
2022-04-18 14:20:54 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-04-18 15:07:30 +08:00
|
|
|
Padding = new MarginPadding(20),
|
|
|
|
Child = stack = new ScreenStack
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2022-04-18 14:20:54 +08:00
|
|
|
},
|
2022-04-18 15:07:30 +08:00
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Padding = new MarginPadding(20),
|
|
|
|
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[]
|
|
|
|
{
|
2022-04-18 15:34:13 +08:00
|
|
|
BackButton = new DangerousTriangleButton
|
2022-04-18 15:07:30 +08:00
|
|
|
{
|
|
|
|
Width = 200,
|
|
|
|
Text = "Back",
|
|
|
|
Action = showLastStep,
|
|
|
|
Enabled = { Value = false },
|
|
|
|
},
|
|
|
|
Empty(),
|
2022-04-18 15:34:13 +08:00
|
|
|
NextButton = new PurpleTriangleButton
|
2022-04-18 15:07:30 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Width = 1,
|
|
|
|
Text = "Get started",
|
|
|
|
Action = showNextStep
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2022-04-18 14:20:54 +08:00
|
|
|
}
|
|
|
|
}
|
2022-04-06 16:42:10 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-04-18 14:20:54 +08:00
|
|
|
if (osuGame != null)
|
|
|
|
{
|
|
|
|
// if we are valid for display, only do so after reaching the main menu.
|
|
|
|
osuGame.PerformFromScreen(_ =>
|
|
|
|
{
|
|
|
|
Show();
|
|
|
|
}, new[] { typeof(MainMenu) });
|
|
|
|
}
|
|
|
|
else
|
2022-04-06 16:42:10 +08:00
|
|
|
{
|
|
|
|
Show();
|
2022-04-18 14:20:54 +08:00
|
|
|
}
|
2022-04-06 16:42:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
2022-04-18 16:10:08 +08:00
|
|
|
if (!mainContent.IsHovered && dialogOverlay?.CurrentDialog == null)
|
2022-04-06 16:42:10 +08:00
|
|
|
{
|
2022-04-18 14:20:54 +08:00
|
|
|
dialogOverlay?.Push(new ConfirmDialog("Are you sure you want to exit the setup process?",
|
2022-04-06 16:42:10 +08:00
|
|
|
Hide,
|
|
|
|
() => { }));
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnClick(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
{
|
|
|
|
base.PopIn();
|
|
|
|
this.FadeIn(400, Easing.OutQuint);
|
|
|
|
|
2022-04-18 15:07:30 +08:00
|
|
|
if (currentStepIndex == null)
|
|
|
|
showNextStep();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showLastStep()
|
|
|
|
{
|
|
|
|
Debug.Assert(currentStepIndex > 0);
|
|
|
|
|
|
|
|
stack.CurrentScreen.Exit();
|
|
|
|
currentStepIndex--;
|
|
|
|
|
2022-04-18 15:34:13 +08:00
|
|
|
BackButton.Enabled.Value = currentStepIndex != 0;
|
2022-04-18 15:07:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void showNextStep()
|
|
|
|
{
|
|
|
|
if (currentStepIndex == null)
|
|
|
|
currentStepIndex = 0;
|
|
|
|
else
|
|
|
|
currentStepIndex++;
|
|
|
|
|
|
|
|
Debug.Assert(currentStepIndex != null);
|
2022-04-18 15:34:13 +08:00
|
|
|
BackButton.Enabled.Value = currentStepIndex > 0;
|
2022-04-18 15:07:30 +08:00
|
|
|
|
|
|
|
if (currentStepIndex < steps.Length)
|
|
|
|
{
|
|
|
|
var nextStep = steps[currentStepIndex.Value];
|
|
|
|
stack.Push((Screen)Activator.CreateInstance(nextStep.ScreenType));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Hide();
|
|
|
|
}
|
|
|
|
|
2022-04-18 15:34:13 +08:00
|
|
|
NextButton.Text = currentStepIndex + 1 < steps.Length
|
2022-04-18 15:07:30 +08:00
|
|
|
? $"Next ({steps[currentStepIndex.Value + 1].Description})"
|
|
|
|
: "Finish";
|
2022-04-06 16:42:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
base.PopOut();
|
|
|
|
this.FadeOut(100);
|
|
|
|
}
|
2022-04-18 15:07:30 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|