mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 09:32:55 +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 NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
@ -20,6 +22,7 @@ using osu.Game.Overlays;
|
|||||||
using osu.Game.Overlays.FirstRunSetup;
|
using osu.Game.Overlays.FirstRunSetup;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
using osu.Game.Screens;
|
using osu.Game.Screens;
|
||||||
|
using osu.Game.Screens.Footer;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
@ -28,6 +31,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
public partial class TestSceneFirstRunSetupOverlay : OsuManualInputManagerTestScene
|
public partial class TestSceneFirstRunSetupOverlay : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
private FirstRunSetupOverlay overlay;
|
private FirstRunSetupOverlay overlay;
|
||||||
|
private ScreenFooter footer;
|
||||||
|
|
||||||
private readonly Mock<TestPerformerFromScreenRunner> performer = new Mock<TestPerformerFromScreenRunner>();
|
private readonly Mock<TestPerformerFromScreenRunner> performer = new Mock<TestPerformerFromScreenRunner>();
|
||||||
|
|
||||||
@ -60,19 +64,16 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
.Callback((Notification n) => lastNotification = n);
|
.Callback((Notification n) => lastNotification = n);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("add overlay", () =>
|
createOverlay();
|
||||||
{
|
|
||||||
Child = overlay = new FirstRunSetupOverlay
|
AddStep("show overlay", () => overlay.Show());
|
||||||
{
|
|
||||||
State = { Value = Visibility.Visible }
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBasic()
|
public void TestBasic()
|
||||||
{
|
{
|
||||||
AddAssert("overlay visible", () => overlay.State.Value == Visibility.Visible);
|
AddAssert("overlay visible", () => overlay.State.Value == Visibility.Visible);
|
||||||
|
AddAssert("footer visible", () => footer.State.Value == Visibility.Visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -82,16 +83,13 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
AddUntilStep("step through", () =>
|
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;
|
return overlay.State.Value == Visibility.Hidden;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("first run false", () => !LocalConfig.Get<bool>(OsuSetting.ShowFirstRunSetup));
|
AddAssert("first run false", () => !LocalConfig.Get<bool>(OsuSetting.ShowFirstRunSetup));
|
||||||
|
|
||||||
AddStep("add overlay", () =>
|
createOverlay();
|
||||||
{
|
|
||||||
Child = overlay = new FirstRunSetupOverlay();
|
|
||||||
});
|
|
||||||
|
|
||||||
AddWaitStep("wait some", 5);
|
AddWaitStep("wait some", 5);
|
||||||
|
|
||||||
@ -109,7 +107,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
if (keyboard)
|
if (keyboard)
|
||||||
InputManager.Key(Key.Enter);
|
InputManager.Key(Key.Enter);
|
||||||
else
|
else
|
||||||
overlay.NextButton.TriggerClick();
|
overlay.NextButton.AsNonNull().TriggerClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
return overlay.State.Value == Visibility.Hidden;
|
return overlay.State.Value == Visibility.Hidden;
|
||||||
@ -128,11 +126,9 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[TestCase(true)]
|
[TestCase(true)]
|
||||||
public void TestBackButton(bool keyboard)
|
public void TestBackButton(bool keyboard)
|
||||||
{
|
{
|
||||||
AddAssert("back button disabled", () => !overlay.BackButton.Enabled.Value);
|
|
||||||
|
|
||||||
AddUntilStep("step to last", () =>
|
AddUntilStep("step to last", () =>
|
||||||
{
|
{
|
||||||
var nextButton = overlay.NextButton;
|
var nextButton = overlay.NextButton.AsNonNull();
|
||||||
|
|
||||||
if (overlay.CurrentScreen?.IsLoaded != false)
|
if (overlay.CurrentScreen?.IsLoaded != false)
|
||||||
nextButton.TriggerClick();
|
nextButton.TriggerClick();
|
||||||
@ -142,24 +138,29 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
AddUntilStep("step back to start", () =>
|
AddUntilStep("step back to start", () =>
|
||||||
{
|
{
|
||||||
if (overlay.CurrentScreen?.IsLoaded != false)
|
if (overlay.CurrentScreen?.IsLoaded != false && !(overlay.CurrentScreen is ScreenWelcome))
|
||||||
{
|
{
|
||||||
if (keyboard)
|
if (keyboard)
|
||||||
InputManager.Key(Key.Escape);
|
InputManager.Key(Key.Escape);
|
||||||
else
|
else
|
||||||
overlay.BackButton.TriggerClick();
|
footer.BackButton.TriggerClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
return overlay.CurrentScreen is ScreenWelcome;
|
return overlay.CurrentScreen is ScreenWelcome;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("back button disabled", () => !overlay.BackButton.Enabled.Value);
|
AddAssert("overlay not dismissed", () => overlay.State.Value == Visibility.Visible);
|
||||||
|
|
||||||
if (keyboard)
|
if (keyboard)
|
||||||
{
|
{
|
||||||
AddStep("exit via keyboard", () => InputManager.Key(Key.Escape));
|
AddStep("exit via keyboard", () => InputManager.Key(Key.Escape));
|
||||||
AddAssert("overlay dismissed", () => overlay.State.Value == Visibility.Hidden);
|
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]
|
[Test]
|
||||||
@ -185,7 +186,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestResumeViaNotification()
|
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);
|
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);
|
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.
|
// interface mocks break hot reload, mocking this stub implementation instead works around it.
|
||||||
// see: https://github.com/moq/moq4/issues/1252
|
// see: https://github.com/moq/moq4/issues/1252
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
|
@ -23,6 +23,7 @@ using osu.Game.Overlays.Settings;
|
|||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Screens;
|
using osu.Game.Screens;
|
||||||
|
using osu.Game.Screens.Footer;
|
||||||
using osu.Game.Screens.Menu;
|
using osu.Game.Screens.Menu;
|
||||||
using osu.Game.Screens.Select;
|
using osu.Game.Screens.Select;
|
||||||
using osu.Game.Tests.Visual;
|
using osu.Game.Tests.Visual;
|
||||||
@ -153,6 +154,7 @@ namespace osu.Game.Overlays.FirstRunSetup
|
|||||||
|
|
||||||
OsuScreenStack stack;
|
OsuScreenStack stack;
|
||||||
OsuLogo logo;
|
OsuLogo logo;
|
||||||
|
ScreenFooter footer;
|
||||||
|
|
||||||
Padding = new MarginPadding(5);
|
Padding = new MarginPadding(5);
|
||||||
|
|
||||||
@ -166,7 +168,8 @@ namespace osu.Game.Overlays.FirstRunSetup
|
|||||||
{
|
{
|
||||||
RelativePositionAxes = Axes.Both,
|
RelativePositionAxes = Axes.Both,
|
||||||
Position = new Vector2(0.5f),
|
Position = new Vector2(0.5f),
|
||||||
})
|
}),
|
||||||
|
(typeof(ScreenFooter), footer = new ScreenFooter()),
|
||||||
},
|
},
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -178,7 +181,8 @@ namespace osu.Game.Overlays.FirstRunSetup
|
|||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
stack = new OsuScreenStack(),
|
stack = new OsuScreenStack(),
|
||||||
logo
|
footer,
|
||||||
|
logo,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ using osu.Game.Overlays.FirstRunSetup;
|
|||||||
using osu.Game.Overlays.Mods;
|
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.Footer;
|
||||||
using osu.Game.Screens.Menu;
|
using osu.Game.Screens.Menu;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
@ -44,8 +45,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private ScreenStack? stack;
|
private ScreenStack? stack;
|
||||||
|
|
||||||
public ShearedButton NextButton = null!;
|
public ShearedButton? NextButton => currentFooterContent?.NextButton;
|
||||||
public ShearedButton BackButton = null!;
|
|
||||||
|
|
||||||
private readonly Bindable<bool> showFirstRunSetup = new Bindable<bool>();
|
private readonly Bindable<bool> showFirstRunSetup = new Bindable<bool>();
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ namespace osu.Game.Overlays
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Padding = new MarginPadding { Bottom = 20, },
|
Padding = new MarginPadding { Bottom = 20 },
|
||||||
Child = new GridContainer
|
Child = new GridContainer
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
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()
|
protected override void LoadComplete()
|
||||||
@ -190,6 +145,32 @@ namespace osu.Game.Overlays
|
|||||||
if (showFirstRunSetup.Value) Show();
|
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)
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
||||||
{
|
{
|
||||||
if (!e.Repeat)
|
if (!e.Repeat)
|
||||||
@ -197,19 +178,12 @@ namespace osu.Game.Overlays
|
|||||||
switch (e.Action)
|
switch (e.Action)
|
||||||
{
|
{
|
||||||
case GlobalAction.Select:
|
case GlobalAction.Select:
|
||||||
NextButton.TriggerClick();
|
currentFooterContent?.NextButton.TriggerClick();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case GlobalAction.Back:
|
case GlobalAction.Back:
|
||||||
if (BackButton.Enabled.Value)
|
footer.BackButton.TriggerClick();
|
||||||
{
|
return false;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,19 +253,6 @@ namespace osu.Game.Overlays
|
|||||||
showNextStep();
|
showNextStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPreviousStep()
|
|
||||||
{
|
|
||||||
if (currentStepIndex == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Debug.Assert(stack != null);
|
|
||||||
|
|
||||||
stack.CurrentScreen.Exit();
|
|
||||||
currentStepIndex--;
|
|
||||||
|
|
||||||
updateButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showNextStep()
|
private void showNextStep()
|
||||||
{
|
{
|
||||||
Debug.Assert(currentStepIndex != null);
|
Debug.Assert(currentStepIndex != null);
|
||||||
@ -322,29 +283,61 @@ namespace osu.Game.Overlays
|
|||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateButtons()
|
private void updateButtons() => currentFooterContent?.UpdateButtons(currentStepIndex, steps);
|
||||||
|
|
||||||
|
private partial class FirstRunSetupFooterContent : VisibilityContainer
|
||||||
{
|
{
|
||||||
BackButton.Enabled.Value = currentStepIndex > 0;
|
public ShearedButton NextButton { get; private set; } = null!;
|
||||||
NextButton.Enabled.Value = currentStepIndex != null;
|
|
||||||
|
|
||||||
if (currentStepIndex == null)
|
public Action? ShowNextStep;
|
||||||
return;
|
|
||||||
|
|
||||||
bool isFirstStep = currentStepIndex == 0;
|
[BackgroundDependencyLoader]
|
||||||
bool isLastStep = currentStepIndex == steps.Count - 1;
|
private void load(OverlayColourProvider colourProvider)
|
||||||
|
|
||||||
if (isFirstStep)
|
|
||||||
{
|
{
|
||||||
BackButton.Text = CommonStrings.Back;
|
RelativeSizeAxes = Axes.Both;
|
||||||
NextButton.Text = FirstRunSetupOverlayStrings.GetStarted;
|
|
||||||
|
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
|
public void UpdateButtons(int? currentStep, IReadOnlyList<Type> steps)
|
||||||
? CommonStrings.Finish
|
{
|
||||||
: LocalisableString.Interpolate($@"{CommonStrings.Next} ({steps[currentStepIndex.Value + 1].GetLocalisableDescription()})");
|
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