1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 10:42:55 +08:00

Merge branch 'master' into resume-cursor-2

This commit is contained in:
Dean Herbert 2019-03-29 15:56:46 +09:00 committed by GitHub
commit 81585a8283
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 197 additions and 127 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -22,55 +23,76 @@ namespace osu.Game.Tests.Visual.Menus
public TestCaseLoaderAnimation() public TestCaseLoaderAnimation()
{ {
Add(logo = new OsuLogo { Depth = float.MinValue }); Child = logo = new OsuLogo { Depth = float.MinValue };
} }
protected override void LoadComplete() [Test]
public void TestInstantLoad()
{ {
base.LoadComplete();
bool logoVisible = false; bool logoVisible = false;
AddStep("almost instant display", () => LoadScreen(loader = new TestLoader(250)));
AddUntilStep("loaded", () =>
{
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
});
AddAssert("logo not visible", () => !logoVisible);
AddStep("short load", () => LoadScreen(loader = new TestLoader(800))); AddStep("begin loading", () =>
AddUntilStep("loaded", () => {
loader = new TestLoader();
loader.AllowLoad.Set();
LoadScreen(loader);
});
AddAssert("loaded", () =>
{ {
logoVisible = loader.Logo?.Alpha > 0; logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded; return loader.Logo != null && loader.ScreenLoaded;
}); });
AddAssert("logo visible", () => logoVisible);
AddAssert("logo was not visible", () => !logoVisible);
}
[Test]
public void TestShortLoad()
{
bool logoVisible = false;
AddStep("begin loading", () => LoadScreen(loader = new TestLoader()));
AddWaitStep("wait", 2);
AddStep("finish loading", () =>
{
logoVisible = loader.Logo?.Alpha > 0;
loader.AllowLoad.Set();
});
AddAssert("loaded", () => loader.Logo != null && loader.ScreenLoaded);
AddAssert("logo was visible", () => logoVisible);
AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0); AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0);
}
AddStep("longer load", () => LoadScreen(loader = new TestLoader(1400))); [Test]
AddUntilStep("loaded", () => public void TestLongLoad()
{
bool logoVisible = false;
AddStep("begin loading", () => LoadScreen(loader = new TestLoader()));
AddWaitStep("wait", 10);
AddStep("finish loading", () =>
{ {
logoVisible = loader.Logo?.Alpha > 0; logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded; loader.AllowLoad.Set();
}); });
AddAssert("logo visible", () => logoVisible);
AddAssert("loaded", () => loader.Logo != null && loader.ScreenLoaded);
AddAssert("logo was visible", () => logoVisible);
AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0); AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0);
} }
private class TestLoader : Loader private class TestLoader : Loader
{ {
private readonly double delay; public readonly ManualResetEventSlim AllowLoad = new ManualResetEventSlim();
public OsuLogo Logo; public OsuLogo Logo;
private TestScreen screen; private TestScreen screen;
public bool ScreenLoaded => screen.IsCurrentScreen(); public bool ScreenLoaded => screen.IsCurrentScreen();
public TestLoader(double delay)
{
this.delay = delay;
}
protected override void LogoArriving(OsuLogo logo, bool resuming) protected override void LogoArriving(OsuLogo logo, bool resuming)
{ {
Logo = logo; Logo = logo;
@ -78,25 +100,18 @@ namespace osu.Game.Tests.Visual.Menus
} }
protected override OsuScreen CreateLoadableScreen() => screen = new TestScreen(); protected override OsuScreen CreateLoadableScreen() => screen = new TestScreen();
protected override ShaderPrecompiler CreateShaderPrecompiler() => new TestShaderPrecompiler(delay); protected override ShaderPrecompiler CreateShaderPrecompiler() => new TestShaderPrecompiler(AllowLoad);
private class TestShaderPrecompiler : ShaderPrecompiler private class TestShaderPrecompiler : ShaderPrecompiler
{ {
private readonly double delay; private readonly ManualResetEventSlim allowLoad;
private double startTime;
public TestShaderPrecompiler(double delay) public TestShaderPrecompiler(ManualResetEventSlim allowLoad)
{ {
this.delay = delay; this.allowLoad = allowLoad;
} }
protected override void LoadComplete() protected override bool AllLoaded => allowLoad.IsSet;
{
base.LoadComplete();
startTime = Time.Current;
}
protected override bool AllLoaded => Time.Current > startTime + delay;
} }
private class TestScreen : OsuScreen private class TestScreen : OsuScreen

View File

@ -0,0 +1,80 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterface
{
public abstract class ScreenTitle : CompositeDrawable, IHasAccentColour
{
private readonly SpriteIcon iconSprite;
private readonly OsuSpriteText titleText, pageText;
protected IconUsage Icon
{
get => iconSprite.Icon;
set => iconSprite.Icon = value;
}
protected string Title
{
get => titleText.Text;
set => titleText.Text = value;
}
protected string Section
{
get => pageText.Text;
set => pageText.Text = value;
}
public Color4 AccentColour
{
get => pageText.Colour;
set => pageText.Colour = value;
}
protected ScreenTitle()
{
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(10, 0),
Children = new Drawable[]
{
iconSprite = new SpriteIcon
{
Size = new Vector2(25),
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(6, 0),
Children = new[]
{
titleText = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 25),
},
pageText = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 25),
}
}
}
}
},
};
}
}
}

View File

@ -62,6 +62,8 @@ namespace osu.Game
private NotificationOverlay notifications; private NotificationOverlay notifications;
private LoginOverlay loginOverlay;
private DialogOverlay dialogOverlay; private DialogOverlay dialogOverlay;
private AccountCreationOverlay accountCreation; private AccountCreationOverlay accountCreation;
@ -422,6 +424,13 @@ namespace osu.Game
loadComponentSingleFile(volume = new VolumeOverlay(), floatingOverlayContent.Add); loadComponentSingleFile(volume = new VolumeOverlay(), floatingOverlayContent.Add);
loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add); loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add);
loadComponentSingleFile(loginOverlay = new LoginOverlay
{
GetToolbarHeight = () => ToolbarOffset,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
}, floatingOverlayContent.Add);
loadComponentSingleFile(screenshotManager, Add); loadComponentSingleFile(screenshotManager, Add);
//overlay elements //overlay elements
@ -432,6 +441,7 @@ namespace osu.Game
loadComponentSingleFile(settings = new MainSettings { GetToolbarHeight = () => ToolbarOffset }, floatingOverlayContent.Add); loadComponentSingleFile(settings = new MainSettings { GetToolbarHeight = () => ToolbarOffset }, floatingOverlayContent.Add);
loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add); loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add);
loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add); loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add);
loadComponentSingleFile(notifications = new NotificationOverlay loadComponentSingleFile(notifications = new NotificationOverlay
{ {
GetToolbarHeight = () => ToolbarOffset, GetToolbarHeight = () => ToolbarOffset,
@ -463,6 +473,7 @@ namespace osu.Game
dependencies.Cache(musicController); dependencies.Cache(musicController);
dependencies.Cache(beatmapSetOverlay); dependencies.Cache(beatmapSetOverlay);
dependencies.Cache(notifications); dependencies.Cache(notifications);
dependencies.Cache(loginOverlay);
dependencies.Cache(dialogOverlay); dependencies.Cache(dialogOverlay);
dependencies.Cache(accountCreation); dependencies.Cache(accountCreation);

View File

@ -10,6 +10,7 @@ using osuTK.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using System;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
@ -19,6 +20,11 @@ namespace osu.Game.Overlays
private const float transition_time = 400; private const float transition_time = 400;
/// <summary>
/// Provide a source for the toolbar height.
/// </summary>
public Func<float> GetToolbarHeight;
public LoginOverlay() public LoginOverlay()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
@ -88,5 +94,12 @@ namespace osu.Game.Overlays
settingsSection.Bounding = false; settingsSection.Bounding = false;
this.FadeOut(transition_time); this.FadeOut(transition_time);
} }
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 };
}
} }
} }

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays.Toolbar
public Action OnHome; public Action OnHome;
private ToolbarUserArea userArea; private ToolbarUserButton userButton;
protected override bool BlockPositionalInput => false; protected override bool BlockPositionalInput => false;
@ -77,7 +77,7 @@ namespace osu.Game.Overlays.Toolbar
//{ //{
// Icon = FontAwesome.search // Icon = FontAwesome.search
//}, //},
userArea = new ToolbarUserArea(), userButton = new ToolbarUserButton(),
new ToolbarNotificationButton(), new ToolbarNotificationButton(),
} }
} }
@ -143,7 +143,7 @@ namespace osu.Game.Overlays.Toolbar
protected override void PopOut() protected override void PopOut()
{ {
userArea?.LoginOverlay.Hide(); userButton?.StateContainer.Hide();
this.MoveToY(-DrawSize.Y, transition_time, Easing.OutQuint); this.MoveToY(-DrawSize.Y, transition_time, Easing.OutQuint);
this.FadeOut(transition_time); this.FadeOut(transition_time);

View File

@ -1,42 +0,0 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osuTK;
using RectangleF = osu.Framework.Graphics.Primitives.RectangleF;
namespace osu.Game.Overlays.Toolbar
{
public class ToolbarUserArea : Container
{
public LoginOverlay LoginOverlay;
private ToolbarUserButton button;
public override RectangleF BoundingBox => button.BoundingBox;
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.Y;
AutoSizeAxes = Axes.X;
Children = new Drawable[]
{
button = new ToolbarUserButton
{
Action = () => LoginOverlay.ToggleVisibility(),
},
LoginOverlay = new LoginOverlay
{
BypassAutoSizeAxes = Axes.Both,
Position = new Vector2(0, 1),
RelativePositionAxes = Axes.Y,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
}
};
}
}
}

View File

@ -13,7 +13,7 @@ using osuTK.Graphics;
namespace osu.Game.Overlays.Toolbar namespace osu.Game.Overlays.Toolbar
{ {
public class ToolbarUserButton : ToolbarButton, IOnlineComponent public class ToolbarUserButton : ToolbarOverlayToggleButton, IOnlineComponent
{ {
private readonly UpdateableAvatar avatar; private readonly UpdateableAvatar avatar;
@ -42,10 +42,12 @@ namespace osu.Game.Overlays.Toolbar
}); });
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader(true)]
private void load(IAPIProvider api) private void load(IAPIProvider api, LoginOverlay login)
{ {
api.Register(this); api.Register(this);
StateContainer = login;
} }
public void APIStateChanged(IAPIProvider api, APIState state) public void APIStateChanged(IAPIProvider api, APIState state)

View File

@ -5,13 +5,10 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.SearchableList; using osu.Game.Overlays.SearchableList;
using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Screens.Multi namespace osu.Game.Screens.Multi
@ -20,11 +17,11 @@ namespace osu.Game.Screens.Multi
{ {
public const float HEIGHT = 121; public const float HEIGHT = 121;
private readonly OsuSpriteText screenType;
private readonly HeaderBreadcrumbControl breadcrumbs; private readonly HeaderBreadcrumbControl breadcrumbs;
public Header(ScreenStack stack) public Header(ScreenStack stack)
{ {
MultiHeaderTitle title;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Height = HEIGHT; Height = HEIGHT;
@ -41,39 +38,11 @@ namespace osu.Game.Screens.Multi
Padding = new MarginPadding { Horizontal = SearchableListOverlay.WIDTH_PADDING + OsuScreen.HORIZONTAL_OVERFLOW_PADDING }, Padding = new MarginPadding { Horizontal = SearchableListOverlay.WIDTH_PADDING + OsuScreen.HORIZONTAL_OVERFLOW_PADDING },
Children = new Drawable[] Children = new Drawable[]
{ {
new FillFlowContainer title = new MultiHeaderTitle
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Position = new Vector2(-35f, 5f), X = -35,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10f, 0f),
Children = new Drawable[]
{
new SpriteIcon
{
Size = new Vector2(25),
Icon = OsuIcon.Multi,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new[]
{
new OsuSpriteText
{
Text = "multiplayer ",
Font = OsuFont.GetFont(size: 25)
},
screenType = new OsuSpriteText
{
Font = OsuFont.GetFont(weight: FontWeight.Light, size: 25)
},
},
},
},
}, },
breadcrumbs = new HeaderBreadcrumbControl(stack) breadcrumbs = new HeaderBreadcrumbControl(stack)
{ {
@ -85,10 +54,10 @@ namespace osu.Game.Screens.Multi
}, },
}; };
breadcrumbs.Current.ValueChanged += scren => breadcrumbs.Current.ValueChanged += screen =>
{ {
if (scren.NewValue is IMultiplayerSubScreen multiScreen) if (screen.NewValue is IMultiplayerSubScreen multiScreen)
screenType.Text = multiScreen.ShortTitle.ToLowerInvariant(); title.Screen = multiScreen;
}; };
breadcrumbs.Current.TriggerChange(); breadcrumbs.Current.TriggerChange();
@ -97,10 +66,25 @@ namespace osu.Game.Screens.Multi
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
screenType.Colour = colours.Yellow;
breadcrumbs.StripColour = colours.Green; breadcrumbs.StripColour = colours.Green;
} }
private class MultiHeaderTitle : ScreenTitle
{
public IMultiplayerSubScreen Screen
{
set => Section = value.ShortTitle.ToLowerInvariant();
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Title = "multiplayer";
Icon = OsuIcon.Multi;
AccentColour = colours.Yellow;
}
}
private class HeaderBreadcrumbControl : ScreenBreadcrumbControl private class HeaderBreadcrumbControl : ScreenBreadcrumbControl
{ {
public HeaderBreadcrumbControl(ScreenStack stack) public HeaderBreadcrumbControl(ScreenStack stack)

View File

@ -1,8 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Screens; using osu.Game.Screens;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
@ -12,12 +12,19 @@ namespace osu.Game.Tests.Visual
/// </summary> /// </summary>
public abstract class ScreenTestCase : ManualInputManagerTestCase public abstract class ScreenTestCase : ManualInputManagerTestCase
{ {
private OsuScreenStack stack; private readonly OsuScreenStack stack;
[BackgroundDependencyLoader] private readonly Container content;
private void load()
protected override Container<Drawable> Content => content;
protected ScreenTestCase()
{ {
Add(stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both }); base.Content.AddRange(new Drawable[]
{
stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both },
content = new Container { RelativeSizeAxes = Axes.Both }
});
} }
protected void LoadScreen(OsuScreen screen) protected void LoadScreen(OsuScreen screen)