Skip to content

Commit

Permalink
Merge pull request #28185 from frenzibyte/footer-v2-become-global
Browse files Browse the repository at this point in the history
Move new screen footer to `OsuGame` and add temporary `SongSelectV2` screen
  • Loading branch information
peppy authored Jun 9, 2024
2 parents daf85c3 + 6201220 commit be48377
Show file tree
Hide file tree
Showing 16 changed files with 557 additions and 77 deletions.
204 changes: 204 additions & 0 deletions osu.Game.Tests/Visual/SongSelect/TestSceneSongSelectV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// 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.

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens;
using osu.Game.Screens.Footer;
using osu.Game.Screens.Menu;
using osu.Game.Screens.SelectV2;
using osu.Game.Screens.SelectV2.Footer;
using osuTK.Input;

namespace osu.Game.Tests.Visual.SongSelect
{
public partial class TestSceneSongSelectV2 : ScreenTestScene
{
[Cached]
private readonly ScreenFooter screenScreenFooter;

[Cached]
private readonly OsuLogo logo;

public TestSceneSongSelectV2()
{
Children = new Drawable[]
{
new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Child = screenScreenFooter = new ScreenFooter
{
OnBack = () => Stack.CurrentScreen.Exit(),
},
},
logo = new OsuLogo
{
Alpha = 0f,
},
};
}

protected override void LoadComplete()
{
base.LoadComplete();

Stack.ScreenPushed += updateFooter;
Stack.ScreenExited += updateFooter;
}

[SetUpSteps]
public override void SetUpSteps()
{
base.SetUpSteps();

AddStep("load screen", () => Stack.Push(new SongSelectV2()));
AddUntilStep("wait for load", () => Stack.CurrentScreen is SongSelectV2 songSelect && songSelect.IsLoaded);
}

#region Footer

[Test]
public void TestMods()
{
AddStep("one mod", () => SelectedMods.Value = new List<Mod> { new OsuModHidden() });
AddStep("two mods", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock() });
AddStep("three mods", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime() });
AddStep("four mods", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic() });
AddStep("five mods", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic(), new OsuModDifficultyAdjust() });

AddStep("modified", () => SelectedMods.Value = new List<Mod> { new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });
AddStep("modified + one", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });
AddStep("modified + two", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });
AddStep("modified + three", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModClassic(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });
AddStep("modified + four", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModClassic(), new OsuModDifficultyAdjust(), new OsuModDoubleTime { SpeedChange = { Value = 1.2 } } });

AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
AddWaitStep("wait", 3);
AddStep("one mod", () => SelectedMods.Value = new List<Mod> { new OsuModHidden() });

AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
AddWaitStep("wait", 3);
AddStep("five mods", () => SelectedMods.Value = new List<Mod> { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime(), new OsuModClassic(), new OsuModDifficultyAdjust() });
}

[Test]
public void TestShowOptions()
{
AddStep("enable options", () =>
{
var optionsButton = this.ChildrenOfType<ScreenFooterButton>().Last();

optionsButton.Enabled.Value = true;
optionsButton.TriggerClick();
});
}

[Test]
public void TestState()
{
AddToggleStep("set options enabled state", state => this.ChildrenOfType<ScreenFooterButton>().Last().Enabled.Value = state);
}

// add these test cases when functionality is implemented.
// [Test]
// public void TestFooterRandom()
// {
// AddStep("press F2", () => InputManager.Key(Key.F2));
// AddAssert("next random invoked", () => nextRandomCalled && !previousRandomCalled);
// }
//
// [Test]
// public void TestFooterRandomViaMouse()
// {
// AddStep("click button", () =>
// {
// InputManager.MoveMouseTo(randomButton);
// InputManager.Click(MouseButton.Left);
// });
// AddAssert("next random invoked", () => nextRandomCalled && !previousRandomCalled);
// }
//
// [Test]
// public void TestFooterRewind()
// {
// AddStep("press Shift+F2", () =>
// {
// InputManager.PressKey(Key.LShift);
// InputManager.PressKey(Key.F2);
// InputManager.ReleaseKey(Key.F2);
// InputManager.ReleaseKey(Key.LShift);
// });
// AddAssert("previous random invoked", () => previousRandomCalled && !nextRandomCalled);
// }
//
// [Test]
// public void TestFooterRewindViaShiftMouseLeft()
// {
// AddStep("shift + click button", () =>
// {
// InputManager.PressKey(Key.LShift);
// InputManager.MoveMouseTo(randomButton);
// InputManager.Click(MouseButton.Left);
// InputManager.ReleaseKey(Key.LShift);
// });
// AddAssert("previous random invoked", () => previousRandomCalled && !nextRandomCalled);
// }
//
// [Test]
// public void TestFooterRewindViaMouseRight()
// {
// AddStep("right click button", () =>
// {
// InputManager.MoveMouseTo(randomButton);
// InputManager.Click(MouseButton.Right);
// });
// AddAssert("previous random invoked", () => previousRandomCalled && !nextRandomCalled);
// }

[Test]
public void TestOverlayPresent()
{
AddStep("Press F1", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<ScreenFooterButtonMods>().Single());
InputManager.Click(MouseButton.Left);
});
AddAssert("Overlay visible", () => this.ChildrenOfType<ModSelectOverlay>().Single().State.Value == Visibility.Visible);
AddStep("Hide", () => this.ChildrenOfType<ModSelectOverlay>().Single().Hide());
}

#endregion

protected override void Update()
{
base.Update();
Stack.Padding = new MarginPadding { Bottom = screenScreenFooter.DrawHeight - screenScreenFooter.Y };
}

private void updateFooter(IScreen? _, IScreen? newScreen)
{
if (newScreen is IOsuScreen osuScreen && osuScreen.ShowFooter)
{
screenScreenFooter.Show();
screenScreenFooter.SetButtons(osuScreen.CreateFooterButtons());
}
else
{
screenScreenFooter.Hide();
screenScreenFooter.SetButtons(Array.Empty<ScreenFooterButton>());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.

using System.Linq;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Screens.Menu;
using osu.Game.Screens.SelectV2;
using osuTK.Input;

namespace osu.Game.Tests.Visual.SongSelect
{
public partial class TestSceneSongSelectV2Navigation : OsuGameTestScene
{
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("press enter", () => InputManager.Key(Key.Enter));
AddWaitStep("wait", 5);
PushAndConfirm(() => new SongSelectV2());
}

[Test]
public void TestClickLogo()
{
AddStep("click", () =>
{
InputManager.MoveMouseTo(Game.ChildrenOfType<OsuLogo>().Single());
InputManager.Click(MouseButton.Left);
});
}
}
}
3 changes: 2 additions & 1 deletion osu.Game.Tests/Visual/UserInterface/TestSceneBackButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Footer;
using osuTK;
using osuTK.Graphics;

Expand All @@ -15,7 +16,7 @@ public partial class TestSceneBackButton : OsuTestScene
public TestSceneBackButton()
{
BackButton button;
BackButton.Receptor receptor = new BackButton.Receptor();
ScreenFooter.BackReceptor receptor = new ScreenFooter.BackReceptor();

Child = new Container
{
Expand Down
9 changes: 5 additions & 4 deletions osu.Game.Tests/Visual/UserInterface/TestSceneScreenFooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Testing;
Expand All @@ -19,9 +18,6 @@ public partial class TestSceneScreenFooter : OsuManualInputManagerTestScene
private ScreenFooter screenFooter = null!;
private TestModSelectOverlay overlay = null!;

[Cached]
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Aquamarine);

[SetUp]
public void SetUp() => Schedule(() =>
{
Expand Down Expand Up @@ -89,6 +85,11 @@ public void TestReplaceButtons()
private partial class TestModSelectOverlay : UserModSelectOverlay
{
protected override bool ShowPresets => true;

public TestModSelectOverlay()
: base(OverlayColourScheme.Aquamarine)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ private bool assertModsMultiplier(IEnumerable<Mod> mods)
private partial class TestModSelectOverlay : UserModSelectOverlay
{
protected override bool ShowPresets => true;

public TestModSelectOverlay()
: base(OverlayColourScheme.Aquamarine)
{
}
}

private partial class TestScreenFooterButtonMods : ScreenFooterButtonMods
Expand Down
33 changes: 4 additions & 29 deletions osu.Game/Graphics/UserInterface/BackButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
using osu.Game.Screens.Footer;

namespace osu.Game.Graphics.UserInterface
{
// todo: remove this once all screens migrate to display the new game footer and back button.
public partial class BackButton : VisibilityContainer
{
public Action Action;

private readonly TwoLayerButton button;

public BackButton(Receptor receptor = null)
public BackButton(ScreenFooter.BackReceptor receptor = null)
{
Size = TwoLayerButton.SIZE_EXTENDED;

Expand All @@ -35,7 +34,7 @@ public BackButton(Receptor receptor = null)
if (receptor == null)
{
// if a receptor wasn't provided, create our own locally.
Add(receptor = new Receptor());
Add(receptor = new ScreenFooter.BackReceptor());
}

receptor.OnBackPressed = () => button.TriggerClick();
Expand All @@ -59,29 +58,5 @@ protected override void PopOut()
button.MoveToX(-TwoLayerButton.SIZE_EXTENDED.X / 2, 400, Easing.OutQuint);
button.FadeOut(400, Easing.OutQuint);
}

public partial class Receptor : Drawable, IKeyBindingHandler<GlobalAction>
{
public Action OnBackPressed;

public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat)
return false;

switch (e.Action)
{
case GlobalAction.Back:
OnBackPressed?.Invoke();
return true;
}

return false;
}

public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
}
}
}
Loading

0 comments on commit be48377

Please sign in to comment.