mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 07:33:20 +08:00
Migrate first-run setup overlay footer content
This commit is contained in:
parent
48bf3f1385
commit
5dd822ea38
@ -11,6 +11,8 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
@ -20,6 +22,7 @@ using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.FirstRunSetup;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Footer;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
@ -28,6 +31,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
public partial class TestSceneFirstRunSetupOverlay : OsuManualInputManagerTestScene
|
||||
{
|
||||
private FirstRunSetupOverlay overlay;
|
||||
private ScreenFooter footer;
|
||||
|
||||
private readonly Mock<TestPerformerFromScreenRunner> performer = new Mock<TestPerformerFromScreenRunner>();
|
||||
|
||||
@ -60,19 +64,16 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
.Callback((Notification n) => lastNotification = n);
|
||||
});
|
||||
|
||||
AddStep("add overlay", () =>
|
||||
{
|
||||
Child = overlay = new FirstRunSetupOverlay
|
||||
{
|
||||
State = { Value = Visibility.Visible }
|
||||
};
|
||||
});
|
||||
createOverlay();
|
||||
|
||||
AddStep("show overlay", () => overlay.Show());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasic()
|
||||
{
|
||||
AddAssert("overlay visible", () => overlay.State.Value == Visibility.Visible);
|
||||
AddAssert("footer visible", () => footer.State.Value == Visibility.Visible);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -82,16 +83,13 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
AddUntilStep("step through", () =>
|
||||
{
|
||||
if (overlay.CurrentScreen?.IsLoaded != false) overlay.NextButton.TriggerClick();
|
||||
if (overlay.CurrentScreen?.IsLoaded != false) overlay.NextButton.AsNonNull().TriggerClick();
|
||||
return overlay.State.Value == Visibility.Hidden;
|
||||
});
|
||||
|
||||
AddAssert("first run false", () => !LocalConfig.Get<bool>(OsuSetting.ShowFirstRunSetup));
|
||||
|
||||
AddStep("add overlay", () =>
|
||||
{
|
||||
Child = overlay = new FirstRunSetupOverlay();
|
||||
});
|
||||
createOverlay();
|
||||
|
||||
AddWaitStep("wait some", 5);
|
||||
|
||||
@ -109,7 +107,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
if (keyboard)
|
||||
InputManager.Key(Key.Enter);
|
||||
else
|
||||
overlay.NextButton.TriggerClick();
|
||||
overlay.NextButton.AsNonNull().TriggerClick();
|
||||
}
|
||||
|
||||
return overlay.State.Value == Visibility.Hidden;
|
||||
@ -128,11 +126,9 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
[TestCase(true)]
|
||||
public void TestBackButton(bool keyboard)
|
||||
{
|
||||
AddAssert("back button disabled", () => !overlay.BackButton.Enabled.Value);
|
||||
|
||||
AddUntilStep("step to last", () =>
|
||||
{
|
||||
var nextButton = overlay.NextButton;
|
||||
var nextButton = overlay.NextButton.AsNonNull();
|
||||
|
||||
if (overlay.CurrentScreen?.IsLoaded != false)
|
||||
nextButton.TriggerClick();
|
||||
@ -142,24 +138,29 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
AddUntilStep("step back to start", () =>
|
||||
{
|
||||
if (overlay.CurrentScreen?.IsLoaded != false)
|
||||
if (overlay.CurrentScreen?.IsLoaded != false && !(overlay.CurrentScreen is ScreenWelcome))
|
||||
{
|
||||
if (keyboard)
|
||||
InputManager.Key(Key.Escape);
|
||||
else
|
||||
overlay.BackButton.TriggerClick();
|
||||
footer.BackButton.TriggerClick();
|
||||
}
|
||||
|
||||
return overlay.CurrentScreen is ScreenWelcome;
|
||||
});
|
||||
|
||||
AddAssert("back button disabled", () => !overlay.BackButton.Enabled.Value);
|
||||
AddAssert("overlay not dismissed", () => overlay.State.Value == Visibility.Visible);
|
||||
|
||||
if (keyboard)
|
||||
{
|
||||
AddStep("exit via keyboard", () => InputManager.Key(Key.Escape));
|
||||
AddAssert("overlay dismissed", () => overlay.State.Value == Visibility.Hidden);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddStep("press back button", () => footer.BackButton.TriggerClick());
|
||||
AddAssert("overlay dismissed", () => overlay.State.Value == Visibility.Hidden);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -185,7 +186,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
[Test]
|
||||
public void TestResumeViaNotification()
|
||||
{
|
||||
AddStep("step to next", () => overlay.NextButton.TriggerClick());
|
||||
AddStep("step to next", () => overlay.NextButton.AsNonNull().TriggerClick());
|
||||
|
||||
AddAssert("is at known screen", () => overlay.CurrentScreen is ScreenUIScale);
|
||||
|
||||
@ -200,6 +201,27 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddAssert("is resumed", () => overlay.CurrentScreen is ScreenUIScale);
|
||||
}
|
||||
|
||||
private void createOverlay()
|
||||
{
|
||||
AddStep("add overlay", () =>
|
||||
{
|
||||
var receptor = new ScreenFooter.BackReceptor();
|
||||
footer = new ScreenFooter(receptor);
|
||||
|
||||
Child = new DependencyProvidingContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
CachedDependencies = new[] { (typeof(ScreenFooter), (object)footer) },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
receptor,
|
||||
overlay = new FirstRunSetupOverlay(),
|
||||
footer,
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// interface mocks break hot reload, mocking this stub implementation instead works around it.
|
||||
// see: https://github.com/moq/moq4/issues/1252
|
||||
[UsedImplicitly]
|
||||
|
@ -23,6 +23,7 @@ using osu.Game.Overlays.Settings;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Footer;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Screens.Select;
|
||||
using osu.Game.Tests.Visual;
|
||||
@ -153,6 +154,7 @@ namespace osu.Game.Overlays.FirstRunSetup
|
||||
|
||||
OsuScreenStack stack;
|
||||
OsuLogo logo;
|
||||
ScreenFooter footer;
|
||||
|
||||
Padding = new MarginPadding(5);
|
||||
|
||||
@ -166,7 +168,8 @@ namespace osu.Game.Overlays.FirstRunSetup
|
||||
{
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Position = new Vector2(0.5f),
|
||||
})
|
||||
}),
|
||||
(typeof(ScreenFooter), footer = new ScreenFooter()),
|
||||
},
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
@ -178,7 +181,8 @@ namespace osu.Game.Overlays.FirstRunSetup
|
||||
Children = new Drawable[]
|
||||
{
|
||||
stack = new OsuScreenStack(),
|
||||
logo
|
||||
footer,
|
||||
logo,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ using osu.Game.Overlays.FirstRunSetup;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Footer;
|
||||
using osu.Game.Screens.Menu;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
@ -44,8 +45,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
private ScreenStack? stack;
|
||||
|
||||
public ShearedButton NextButton = null!;
|
||||
public ShearedButton BackButton = null!;
|
||||
public ShearedButton? NextButton => currentFooterContent?.NextButton;
|
||||
|
||||
private readonly Bindable<bool> showFirstRunSetup = new Bindable<bool>();
|
||||
|
||||
@ -90,7 +90,7 @@ namespace osu.Game.Overlays
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Bottom = 20, },
|
||||
Padding = new MarginPadding { Bottom = 20 },
|
||||
Child = new GridContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
@ -134,51 +134,6 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
FooterContent.Add(new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Margin = new MarginPadding { Vertical = PADDING },
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
ColumnDimensions = new[]
|
||||
{
|
||||
new Dimension(GridSizeMode.Absolute, 10),
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(),
|
||||
new Dimension(GridSizeMode.Absolute, 10),
|
||||
},
|
||||
RowDimensions = new[]
|
||||
{
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
new[]
|
||||
{
|
||||
Empty(),
|
||||
BackButton = new ShearedButton(300)
|
||||
{
|
||||
Text = CommonStrings.Back,
|
||||
Action = showPreviousStep,
|
||||
Enabled = { Value = false },
|
||||
DarkerColour = colours.Pink2,
|
||||
LighterColour = colours.Pink1,
|
||||
},
|
||||
NextButton = new ShearedButton(0)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Width = 1,
|
||||
Text = FirstRunSetupOverlayStrings.GetStarted,
|
||||
DarkerColour = ColourProvider.Colour2,
|
||||
LighterColour = ColourProvider.Colour1,
|
||||
Action = showNextStep
|
||||
},
|
||||
Empty(),
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -190,6 +145,32 @@ namespace osu.Game.Overlays
|
||||
if (showFirstRunSetup.Value) Show();
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private ScreenFooter footer { get; set; } = null!;
|
||||
|
||||
private FirstRunSetupFooterContent? currentFooterContent;
|
||||
|
||||
public override bool UseNewFooter => true;
|
||||
|
||||
public override Drawable CreateFooterContent() => currentFooterContent = new FirstRunSetupFooterContent
|
||||
{
|
||||
ShowNextStep = showNextStep,
|
||||
};
|
||||
|
||||
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)
|
||||
@ -197,19 +178,12 @@ namespace osu.Game.Overlays
|
||||
switch (e.Action)
|
||||
{
|
||||
case GlobalAction.Select:
|
||||
NextButton.TriggerClick();
|
||||
currentFooterContent?.NextButton.TriggerClick();
|
||||
return true;
|
||||
|
||||
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;
|
||||
footer.BackButton.TriggerClick();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,19 +253,6 @@ namespace osu.Game.Overlays
|
||||
showNextStep();
|
||||
}
|
||||
|
||||
private void showPreviousStep()
|
||||
{
|
||||
if (currentStepIndex == 0)
|
||||
return;
|
||||
|
||||
Debug.Assert(stack != null);
|
||||
|
||||
stack.CurrentScreen.Exit();
|
||||
currentStepIndex--;
|
||||
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
private void showNextStep()
|
||||
{
|
||||
Debug.Assert(currentStepIndex != null);
|
||||
@ -322,29 +283,61 @@ namespace osu.Game.Overlays
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
private void updateButtons()
|
||||
private void updateButtons() => currentFooterContent?.UpdateButtons(currentStepIndex, steps);
|
||||
|
||||
private partial class FirstRunSetupFooterContent : VisibilityContainer
|
||||
{
|
||||
BackButton.Enabled.Value = currentStepIndex > 0;
|
||||
NextButton.Enabled.Value = currentStepIndex != null;
|
||||
public ShearedButton NextButton { get; private set; } = null!;
|
||||
|
||||
if (currentStepIndex == null)
|
||||
return;
|
||||
public Action? ShowNextStep;
|
||||
|
||||
bool isFirstStep = currentStepIndex == 0;
|
||||
bool isLastStep = currentStepIndex == steps.Count - 1;
|
||||
|
||||
if (isFirstStep)
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider)
|
||||
{
|
||||
BackButton.Text = CommonStrings.Back;
|
||||
NextButton.Text = FirstRunSetupOverlayStrings.GetStarted;
|
||||
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(),
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
BackButton.Text = LocalisableString.Interpolate($@"{CommonStrings.Back} ({steps[currentStepIndex.Value - 1].GetLocalisableDescription()})");
|
||||
|
||||
NextButton.Text = isLastStep
|
||||
? CommonStrings.Finish
|
||||
: LocalisableString.Interpolate($@"{CommonStrings.Next} ({steps[currentStepIndex.Value + 1].GetLocalisableDescription()})");
|
||||
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()})");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
this.FadeIn();
|
||||
}
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
this.Delay(400).FadeOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user