Convert to using sheared overlay container

Add better click-to-dismiss logic for sheader overlays
This commit is contained in:
Dean Herbert 2022-04-20 16:51:26 +09:00
parent 5c21a55e00
commit 0b81ae9de2
2 changed files with 75 additions and 148 deletions

View File

@ -165,7 +165,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("click outside content", () => AddStep("click outside content", () =>
{ {
InputManager.MoveMouseTo(overlay.ScreenSpaceDrawQuad.TopLeft - new Vector2(1)); InputManager.MoveMouseTo(new Vector2(overlay.ScreenSpaceDrawQuad.TopLeft.X, overlay.ScreenSpaceDrawQuad.Centre.Y));
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });

View File

@ -7,10 +7,8 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
@ -18,25 +16,22 @@ using osu.Framework.Localisation;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Overlays.FirstRunSetup; using osu.Game.Overlays.FirstRunSetup;
using osu.Game.Overlays.Mods;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osu.Game.Screens.OnlinePlay.Match.Components; using osu.Game.Screens.OnlinePlay.Match.Components;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
[Cached] [Cached]
public class FirstRunSetupOverlay : OsuFocusedOverlayContainer public class FirstRunSetupOverlay : ShearedOverlayContainer
{ {
protected override bool StartHidden => true; protected override OverlayColourScheme ColourScheme => OverlayColourScheme.Purple;
[Resolved] [Resolved]
private IPerformFromScreenRunner performer { get; set; } = null!; private IPerformFromScreenRunner performer { get; set; } = null!;
@ -52,15 +47,10 @@ namespace osu.Game.Overlays
public PurpleTriangleButton NextButton = null!; public PurpleTriangleButton NextButton = null!;
public DangerousTriangleButton BackButton = null!; public DangerousTriangleButton BackButton = null!;
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
private readonly Bindable<bool> showFirstRunSetup = new Bindable<bool>(); private readonly Bindable<bool> showFirstRunSetup = new Bindable<bool>();
private int? currentStepIndex; private int? currentStepIndex;
private const float scale_when_hidden = 0.9f;
/// <summary> /// <summary>
/// The currently displayed screen, if any. /// The currently displayed screen, if any.
/// </summary> /// </summary>
@ -76,112 +66,57 @@ namespace osu.Game.Overlays
private Bindable<OverlayActivation>? overlayActivationMode; private Bindable<OverlayActivation>? overlayActivationMode;
public FirstRunSetupOverlay() private Container content = null!;
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Anchor = Anchor.Centre; Header.Title = FirstRunSetupOverlayStrings.FirstRunSetup;
Origin = Anchor.Centre; Header.Description = FirstRunSetupOverlayStrings.SetupOsuToSuitYou;
RelativeSizeAxes = Axes.Both; MainAreaContent.AddRange(new Drawable[]
Size = new Vector2(0.95f);
EdgeEffect = new EdgeEffectParameters
{ {
Type = EdgeEffectType.Shadow, content = new Container
Radius = 5, {
Colour = Color4.Black.Opacity(0.2f), Anchor = Anchor.Centre,
}; Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true; Padding = new MarginPadding { Horizontal = 50 },
CornerRadius = 10; Child = new InputBlockingContainer
{
Masking = true,
CornerRadius = 14,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background6, Colour = ColourProvider.Background6,
}, },
new GridContainer
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
new Drawable[]
{
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.Content1,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
new OsuTextFlowContainer
{
Text = FirstRunSetupOverlayStrings.SetupOsuToSuitYou,
Colour = colourProvider.Content2,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
},
}
},
}
},
},
new Drawable[]
{
stackContainer = new Container stackContainer = new Container
{ {
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(20), Padding = new MarginPadding
},
},
new Drawable[]
{ {
new Container Vertical = 20,
{ Horizontal = 20,
RelativeSizeAxes = Axes.X, },
AutoSizeAxes = Axes.Y, }
Padding = new MarginPadding(20) },
{ },
Top = 0 // provided by the stack container above. },
}, });
Child = new GridContainer
FooterContent.Add(new GridContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Width = 0.98f,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
ColumnDimensions = new[] ColumnDimensions = new[]
{ {
new Dimension(GridSizeMode.AutoSize), new Dimension(GridSizeMode.AutoSize),
@ -213,12 +148,7 @@ namespace osu.Game.Overlays
} }
}, },
} }
}, });
}
}
}
},
};
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -280,10 +210,8 @@ namespace osu.Game.Overlays
{ {
base.PopIn(); base.PopIn();
this.ScaleTo(scale_when_hidden) content.ScaleTo(0.99f)
.ScaleTo(1, 400, Easing.OutElasticHalf); .ScaleTo(1, 400, Easing.OutQuint);
this.FadeIn(400, Easing.OutQuint);
if (currentStepIndex == null) if (currentStepIndex == null)
showFirstStep(); showFirstStep();
@ -291,6 +219,10 @@ namespace osu.Game.Overlays
protected override void PopOut() protected override void PopOut()
{ {
base.PopOut();
content.ScaleTo(0.99f, 400, Easing.OutQuint);
if (overlayActivationMode != null) if (overlayActivationMode != null)
{ {
// If this is non-null we are guaranteed to have come from the main menu. // If this is non-null we are guaranteed to have come from the main menu.
@ -316,11 +248,6 @@ namespace osu.Game.Overlays
stack?.FadeOut(100) stack?.FadeOut(100)
.Expire(); .Expire();
} }
base.PopOut();
this.ScaleTo(0.96f, 400, Easing.OutQuint);
this.FadeOut(200, Easing.OutQuint);
} }
private void showFirstStep() private void showFirstStep()