mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 09:23:06 +08:00
Add test coverage
This commit is contained in:
parent
ac157f6cef
commit
8dc0650ca7
62
osu.Game.Tests/Visual/Menus/TestSceneSideOverlays.cs
Normal file
62
osu.Game.Tests/Visual/Menus/TestSceneSideOverlays.cs
Normal file
@ -0,0 +1,62 @@
|
||||
// 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.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Settings.Sections.Input;
|
||||
using osu.Game.Tests.Visual.Navigation;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Menus
|
||||
{
|
||||
public class TestSceneSideOverlays : OsuGameTestScene
|
||||
{
|
||||
[SetUpSteps]
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddAssert("no screen offset applied", () => Game.ScreenOffsetContainer.X == 0f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScreenOffsettingOnSettingsOverlay()
|
||||
{
|
||||
AddStep("open settings", () => Game.Settings.Show());
|
||||
AddUntilStep("right screen offset applied", () => Game.ScreenOffsetContainer.X == SettingsPanel.WIDTH * OsuGame.SCREEN_OFFSET_RATIO);
|
||||
|
||||
AddStep("hide settings", () => Game.Settings.Hide());
|
||||
AddUntilStep("screen offset removed", () => Game.ScreenOffsetContainer.X == 0f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScreenOffsettingAccountsForKeyBindingPanel()
|
||||
{
|
||||
AddStep("open settings", () => Game.Settings.Show());
|
||||
AddStep("open key binding panel", () => Game.Settings.ChildrenOfType<KeyBindingPanel>().Single().Show());
|
||||
AddUntilStep("right screen offset applied", () => Game.ScreenOffsetContainer.X == SettingsPanel.WIDTH * OsuGame.SCREEN_OFFSET_RATIO);
|
||||
|
||||
AddStep("hide key binding", () => Game.Settings.ChildrenOfType<KeyBindingPanel>().Single().Show());
|
||||
AddUntilStep("right screen offset still applied", () => Game.ScreenOffsetContainer.X == SettingsPanel.WIDTH * OsuGame.SCREEN_OFFSET_RATIO);
|
||||
|
||||
AddStep("open key binding", () => Game.Settings.Show());
|
||||
AddUntilStep("right screen offset still applied", () => Game.ScreenOffsetContainer.X == SettingsPanel.WIDTH * OsuGame.SCREEN_OFFSET_RATIO);
|
||||
|
||||
AddStep("hide settings", () => Game.Settings.Hide());
|
||||
AddAssert("key binding panel still open", () => Game.Settings.ChildrenOfType<KeyBindingPanel>().Single().State.Value == Visibility.Visible);
|
||||
AddUntilStep("screen offset removed", () => Game.ScreenOffsetContainer.X == 0f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScreenOffsettingOnNotificationOverlay()
|
||||
{
|
||||
AddStep("open notifications", () => Game.Notifications.Show());
|
||||
AddUntilStep("right screen offset applied", () => Game.ScreenOffsetContainer.X == -NotificationOverlay.WIDTH * OsuGame.SCREEN_OFFSET_RATIO);
|
||||
|
||||
AddStep("hide notifications", () => Game.Notifications.Hide());
|
||||
AddUntilStep("screen offset removed", () => Game.ScreenOffsetContainer.X == 0f);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
@ -103,7 +104,11 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
|
||||
public new ScoreManager ScoreManager => base.ScoreManager;
|
||||
|
||||
public new SettingsPanel Settings => base.Settings;
|
||||
public new Container ScreenOffsetContainer => base.ScreenOffsetContainer;
|
||||
|
||||
public new SettingsOverlay Settings => base.Settings;
|
||||
|
||||
public new NotificationOverlay Notifications => base.Notifications;
|
||||
|
||||
public new MusicController MusicController => base.MusicController;
|
||||
|
||||
|
@ -64,6 +64,8 @@ namespace osu.Game
|
||||
/// </summary>
|
||||
public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
public const float SCREEN_OFFSET_RATIO = 0.125f;
|
||||
|
||||
public Toolbar Toolbar;
|
||||
|
||||
private ChatOverlay chatOverlay;
|
||||
@ -71,7 +73,7 @@ namespace osu.Game
|
||||
private ChannelManager channelManager;
|
||||
|
||||
[NotNull]
|
||||
private readonly NotificationOverlay notifications = new NotificationOverlay();
|
||||
protected readonly NotificationOverlay Notifications = new NotificationOverlay();
|
||||
|
||||
private BeatmapListingOverlay beatmapListing;
|
||||
|
||||
@ -97,7 +99,7 @@ namespace osu.Game
|
||||
|
||||
private ScalingContainer screenContainer;
|
||||
|
||||
private Container screenOffsetContainer;
|
||||
protected Container ScreenOffsetContainer;
|
||||
|
||||
[Resolved]
|
||||
private FrameworkConfigManager frameworkConfig { get; set; }
|
||||
@ -312,7 +314,7 @@ namespace osu.Game
|
||||
case LinkAction.OpenEditorTimestamp:
|
||||
case LinkAction.JoinMultiplayerMatch:
|
||||
case LinkAction.Spectate:
|
||||
waitForReady(() => notifications, _ => notifications.Post(new SimpleNotification
|
||||
waitForReady(() => Notifications, _ => Notifications.Post(new SimpleNotification
|
||||
{
|
||||
Text = @"This link type is not yet supported!",
|
||||
Icon = FontAwesome.Solid.LifeRing,
|
||||
@ -611,12 +613,12 @@ namespace osu.Game
|
||||
MenuCursorContainer.CanShowCursor = menuScreen?.CursorVisible ?? false;
|
||||
|
||||
// todo: all archive managers should be able to be looped here.
|
||||
SkinManager.PostNotification = n => notifications.Post(n);
|
||||
SkinManager.PostNotification = n => Notifications.Post(n);
|
||||
|
||||
BeatmapManager.PostNotification = n => notifications.Post(n);
|
||||
BeatmapManager.PostNotification = n => Notifications.Post(n);
|
||||
BeatmapManager.PresentImport = items => PresentBeatmap(items.First());
|
||||
|
||||
ScoreManager.PostNotification = n => notifications.Post(n);
|
||||
ScoreManager.PostNotification = n => Notifications.Post(n);
|
||||
ScoreManager.PresentImport = items => PresentScore(items.First());
|
||||
|
||||
// make config aware of how to lookup skins for on-screen display purposes.
|
||||
@ -655,7 +657,7 @@ namespace osu.Game
|
||||
ActionRequested = action => volume.Adjust(action),
|
||||
ScrollActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise),
|
||||
},
|
||||
screenOffsetContainer = new Container
|
||||
ScreenOffsetContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
@ -724,7 +726,7 @@ namespace osu.Game
|
||||
|
||||
loadComponentSingleFile(onScreenDisplay, Add, true);
|
||||
|
||||
loadComponentSingleFile(notifications.With(d =>
|
||||
loadComponentSingleFile(Notifications.With(d =>
|
||||
{
|
||||
d.GetToolbarHeight = () => ToolbarOffset;
|
||||
d.Anchor = Anchor.TopRight;
|
||||
@ -733,7 +735,7 @@ namespace osu.Game
|
||||
|
||||
loadComponentSingleFile(new CollectionManager(Storage)
|
||||
{
|
||||
PostNotification = n => notifications.Post(n),
|
||||
PostNotification = n => Notifications.Post(n),
|
||||
}, Add, true);
|
||||
|
||||
loadComponentSingleFile(stableImportManager, Add);
|
||||
@ -785,7 +787,7 @@ namespace osu.Game
|
||||
Add(new MusicKeyBindingHandler());
|
||||
|
||||
// side overlays which cancel each other.
|
||||
var singleDisplaySideOverlays = new OverlayContainer[] { Settings, notifications };
|
||||
var singleDisplaySideOverlays = new OverlayContainer[] { Settings, Notifications };
|
||||
|
||||
foreach (var overlay in singleDisplaySideOverlays)
|
||||
{
|
||||
@ -859,7 +861,7 @@ namespace osu.Game
|
||||
|
||||
if (recentLogCount < short_term_display_limit)
|
||||
{
|
||||
Schedule(() => notifications.Post(new SimpleErrorNotification
|
||||
Schedule(() => Notifications.Post(new SimpleErrorNotification
|
||||
{
|
||||
Icon = entry.Level == LogLevel.Important ? FontAwesome.Solid.ExclamationCircle : FontAwesome.Solid.Bomb,
|
||||
Text = entry.Message.Truncate(256) + (entry.Exception != null && IsDeployedBuild ? "\n\nThis error has been automatically reported to the devs." : string.Empty),
|
||||
@ -867,7 +869,7 @@ namespace osu.Game
|
||||
}
|
||||
else if (recentLogCount == short_term_display_limit)
|
||||
{
|
||||
Schedule(() => notifications.Post(new SimpleNotification
|
||||
Schedule(() => Notifications.Post(new SimpleNotification
|
||||
{
|
||||
Icon = FontAwesome.Solid.EllipsisH,
|
||||
Text = "Subsequent messages have been logged. Click to view log files.",
|
||||
@ -1008,11 +1010,12 @@ namespace osu.Game
|
||||
{
|
||||
base.UpdateAfterChildren();
|
||||
|
||||
screenOffsetContainer.Padding = new MarginPadding { Top = ToolbarOffset };
|
||||
ScreenOffsetContainer.Padding = new MarginPadding { Top = ToolbarOffset };
|
||||
overlayContent.Padding = new MarginPadding { Top = ToolbarOffset };
|
||||
|
||||
screenOffsetContainer.X = Settings.HorizontalScreenOffset * 0.125f +
|
||||
notifications.HorizontalScreenOffset * 0.125f;
|
||||
var settingsOffset = Settings.HorizontalScreenOffset * SCREEN_OFFSET_RATIO;
|
||||
var notificationsOffset = Notifications.HorizontalScreenOffset * SCREEN_OFFSET_RATIO;
|
||||
ScreenOffsetContainer.X = settingsOffset + notificationsOffset;
|
||||
|
||||
MenuCursorContainer.CanShowCursor = (ScreenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace osu.Game.Overlays
|
||||
public LocalisableString Title => NotificationsStrings.HeaderTitle;
|
||||
public LocalisableString Description => NotificationsStrings.HeaderDescription;
|
||||
|
||||
private const float width = 320;
|
||||
public const float WIDTH = 320;
|
||||
|
||||
public const float TRANSITION_LENGTH = 600;
|
||||
|
||||
@ -33,7 +33,7 @@ namespace osu.Game.Overlays
|
||||
/// <summary>
|
||||
/// A horizontal offset to apply to the game-wide screen.
|
||||
/// </summary>
|
||||
public float HorizontalScreenOffset => -width + X;
|
||||
public float HorizontalScreenOffset => -WIDTH + X;
|
||||
|
||||
/// <summary>
|
||||
/// Provide a source for the toolbar height.
|
||||
@ -43,7 +43,7 @@ namespace osu.Game.Overlays
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Width = width;
|
||||
Width = WIDTH;
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
|
||||
Children = new Drawable[]
|
||||
@ -157,7 +157,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
markAllRead();
|
||||
|
||||
this.MoveToX(width, TRANSITION_LENGTH, Easing.OutQuint);
|
||||
this.MoveToX(WIDTH, TRANSITION_LENGTH, Easing.OutQuint);
|
||||
this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user