Merge branch 'master' into update-OsuGameActivity

This commit is contained in:
Dean Herbert 2021-12-25 15:35:14 +09:00 committed by GitHub
commit e716e617aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 216 additions and 44 deletions

View File

@ -2,6 +2,7 @@
// 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; using System;
using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -9,47 +10,96 @@ using osuTK;
namespace osu.Game.Tests.Visual.UserInterface namespace osu.Game.Tests.Visual.UserInterface
{ {
public class TestSceneOsuAnimatedButton : OsuGridTestScene public class TestSceneOsuAnimatedButton : OsuTestScene
{ {
public TestSceneOsuAnimatedButton() [Test]
: base(3, 2) public void TestRelativeSized()
{ {
Cell(0).Add(new BaseContainer("relative sized") AddStep("add button", () => Child = new BaseContainer("relative sized")
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Action = () => { }
}); });
}
Cell(1).Add(new BaseContainer("auto sized") [Test]
public void TestAutoSized()
{
AddStep("add button", () => Child = new BaseContainer("auto sized")
{ {
AutoSizeAxes = Axes.Both AutoSizeAxes = Axes.Both,
Action = () => { }
}); });
}
Cell(2).Add(new BaseContainer("relative Y auto X") [Test]
public void TestRelativeYAutoX()
{
AddStep("add button", () => Child = new BaseContainer("relative Y auto X")
{ {
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X AutoSizeAxes = Axes.X,
Action = () => { }
}); });
}
Cell(3).Add(new BaseContainer("relative X auto Y") [Test]
public void TestRelativeXAutoY()
{
AddStep("add button", () => Child = new BaseContainer("relative X auto Y")
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y AutoSizeAxes = Axes.Y,
Action = () => { }
}); });
}
Cell(4).Add(new BaseContainer("fixed") [Test]
public void TestFixed1()
{
AddStep("add button", () => Child = new BaseContainer("fixed")
{ {
Size = new Vector2(100), Size = new Vector2(100),
Action = () => { }
}); });
}
Cell(5).Add(new BaseContainer("fixed") [Test]
public void TestFixed2()
{
AddStep("add button", () => Child = new BaseContainer("fixed")
{ {
Size = new Vector2(100, 50), Size = new Vector2(100, 50),
Action = () => { }
});
}
[Test]
public void TestToggleEnabled()
{
BaseContainer button = null;
AddStep("add button", () => Child = button = new BaseContainer("fixed")
{
Size = new Vector2(200),
}); });
AddToggleStep("toggle enabled", toggle => AddToggleStep("toggle enabled", toggle =>
{ {
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
((BaseContainer)Cell(i).Child).Action = toggle ? () => { } : (Action)null; button.Action = toggle ? () => { } : (Action)null;
});
}
[Test]
public void TestInitiallyDisabled()
{
AddStep("add disabled button", () =>
{
Child = new BaseContainer("disabled")
{
Size = new Vector2(100)
};
}); });
} }

View File

@ -0,0 +1,46 @@
// 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 NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneOsuButton : OsuTestScene
{
[Test]
public void TestToggleEnabled()
{
OsuButton button = null;
AddStep("add button", () => Child = button = new OsuButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(200),
Text = "Button"
});
AddToggleStep("toggle enabled", toggle =>
{
for (int i = 0; i < 6; i++)
button.Action = toggle ? () => { } : (Action)null;
});
}
[Test]
public void TestInitiallyDisabled()
{
AddStep("add button", () => Child = new OsuButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(200),
Text = "Button"
});
}
}
}

View File

@ -38,6 +38,9 @@ namespace osu.Game.Graphics.UserInterface
} }
} }
[Resolved]
private OsuColour colours { get; set; }
protected override Container<Drawable> Content => content; protected override Container<Drawable> Content => content;
private readonly Container content; private readonly Container content;
@ -73,17 +76,25 @@ namespace osu.Game.Graphics.UserInterface
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load()
{ {
if (AutoSizeAxes != Axes.None) if (AutoSizeAxes != Axes.None)
{ {
content.RelativeSizeAxes = (Axes.Both & ~AutoSizeAxes); content.RelativeSizeAxes = (Axes.Both & ~AutoSizeAxes);
content.AutoSizeAxes = AutoSizeAxes; content.AutoSizeAxes = AutoSizeAxes;
} }
Enabled.BindValueChanged(enabled => this.FadeColour(enabled.NewValue ? Color4.White : colours.Gray9, 200, Easing.OutQuint), true);
} }
protected override void LoadComplete()
{
base.LoadComplete();
Colour = dimColour;
Enabled.BindValueChanged(_ => this.FadeColour(dimColour, 200, Easing.OutQuint));
}
private Color4 dimColour => Enabled.Value ? Color4.White : colours.Gray9;
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
hover.FadeIn(500, Easing.OutQuint); hover.FadeIn(500, Easing.OutQuint);

View File

@ -3,7 +3,6 @@
using System.Diagnostics; using System.Diagnostics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -85,8 +84,6 @@ namespace osu.Game.Graphics.UserInterface
if (hoverSounds.HasValue) if (hoverSounds.HasValue)
AddInternal(new HoverClickSounds(hoverSounds.Value)); AddInternal(new HoverClickSounds(hoverSounds.Value));
Enabled.BindValueChanged(enabledChanged, true);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -94,11 +91,18 @@ namespace osu.Game.Graphics.UserInterface
{ {
if (backgroundColour == null) if (backgroundColour == null)
BackgroundColour = colours.BlueDark; BackgroundColour = colours.BlueDark;
Enabled.ValueChanged += enabledChanged;
Enabled.TriggerChange();
} }
protected override void LoadComplete()
{
base.LoadComplete();
Colour = dimColour;
Enabled.BindValueChanged(_ => this.FadeColour(dimColour, 200, Easing.OutQuint));
}
private Color4 dimColour => Enabled.Value ? Color4.White : Color4.Gray;
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
if (Enabled.Value) if (Enabled.Value)
@ -144,10 +148,5 @@ namespace osu.Game.Graphics.UserInterface
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Font = OsuFont.GetFont(weight: FontWeight.Bold) Font = OsuFont.GetFont(weight: FontWeight.Bold)
}; };
private void enabledChanged(ValueChangedEvent<bool> e)
{
this.FadeColour(e.NewValue ? Color4.White : Color4.Gray, 200, Easing.OutQuint);
}
} }
} }

View File

@ -15,6 +15,26 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[Resolved] [Resolved]
private MultiplayerClient client { get; set; } private MultiplayerClient client { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
client.RoomUpdated += onRoomUpdated;
onRoomUpdated();
}
private void onRoomUpdated()
{
if (client.Room == null)
return;
Debug.Assert(client.LocalUser != null);
// If the user exits gameplay before score submission completes, we'll transition to idle when results has been prepared.
if (client.LocalUser.State == MultiplayerUserState.Results && this.IsCurrentScreen())
transitionFromResults();
}
public override void OnResuming(IScreen last) public override void OnResuming(IScreen last)
{ {
base.OnResuming(last); base.OnResuming(last);
@ -22,23 +42,27 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
if (client.Room == null) if (client.Room == null)
return; return;
if (!(last is MultiplayerPlayerLoader playerLoader))
return;
// If gameplay wasn't finished, then we have a simple path back to the idle state by aborting gameplay.
if (!playerLoader.GameplayPassed)
{
client.AbortGameplay();
return;
}
// If gameplay was completed and the user went all the way to results, we'll transition to idle here.
// Otherwise, the transition will happen in onRoomUpdated().
transitionFromResults();
}
private void transitionFromResults()
{
Debug.Assert(client.LocalUser != null); Debug.Assert(client.LocalUser != null);
switch (client.LocalUser.State) if (client.LocalUser.State == MultiplayerUserState.Results)
{ client.ChangeState(MultiplayerUserState.Idle);
case MultiplayerUserState.Spectating:
break;
case MultiplayerUserState.WaitingForLoad:
case MultiplayerUserState.Loaded:
case MultiplayerUserState.Playing:
client.AbortGameplay();
break;
default:
client.ChangeState(MultiplayerUserState.Idle);
break;
}
} }
protected override string ScreenTitle => "Multiplayer"; protected override string ScreenTitle => "Multiplayer";
@ -46,5 +70,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
protected override RoomManager CreateRoomManager() => new MultiplayerRoomManager(); protected override RoomManager CreateRoomManager() => new MultiplayerRoomManager();
protected override LoungeSubScreen CreateLounge() => new MultiplayerLoungeSubScreen(); protected override LoungeSubScreen CreateLounge() => new MultiplayerLoungeSubScreen();
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (client != null)
client.RoomUpdated -= onRoomUpdated;
}
} }
} }

View File

@ -30,7 +30,6 @@ using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
using osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist; using osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist;
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants; using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate; using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
@ -478,7 +477,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
return new MultiSpectatorScreen(users.Take(PlayerGrid.MAX_PLAYERS).ToArray()); return new MultiSpectatorScreen(users.Take(PlayerGrid.MAX_PLAYERS).ToArray());
default: default:
return new PlayerLoader(() => new MultiplayerPlayer(Room, SelectedItem.Value, users)); return new MultiplayerPlayerLoader(() => new MultiplayerPlayer(Room, SelectedItem.Value, users));
} }
} }

View File

@ -0,0 +1,27 @@
// 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 osu.Framework.Screens;
using osu.Game.Screens.Play;
namespace osu.Game.Screens.OnlinePlay.Multiplayer
{
public class MultiplayerPlayerLoader : PlayerLoader
{
public bool GameplayPassed => player?.GameplayPassed == true;
private Player player;
public MultiplayerPlayerLoader(Func<Player> createPlayer)
: base(createPlayer)
{
}
public override void OnSuspending(IScreen next)
{
base.OnSuspending(next);
player = (Player)next;
}
}
}

View File

@ -66,6 +66,11 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
protected virtual bool PauseOnFocusLost => true; protected virtual bool PauseOnFocusLost => true;
/// <summary>
/// Whether gameplay has completed without the user having failed.
/// </summary>
public bool GameplayPassed { get; private set; }
public Action RestartRequested; public Action RestartRequested;
public bool HasFailed { get; private set; } public bool HasFailed { get; private set; }
@ -666,6 +671,7 @@ namespace osu.Game.Screens.Play
resultsDisplayDelegate?.Cancel(); resultsDisplayDelegate?.Cancel();
resultsDisplayDelegate = null; resultsDisplayDelegate = null;
GameplayPassed = false;
ValidForResume = true; ValidForResume = true;
skipOutroOverlay.Hide(); skipOutroOverlay.Hide();
return; return;
@ -675,6 +681,8 @@ namespace osu.Game.Screens.Play
if (HealthProcessor.HasFailed) if (HealthProcessor.HasFailed)
return; return;
GameplayPassed = true;
// Setting this early in the process means that even if something were to go wrong in the order of events following, there // Setting this early in the process means that even if something were to go wrong in the order of events following, there
// is no chance that a user could return to the (already completed) Player instance from a child screen. // is no chance that a user could return to the (already completed) Player instance from a child screen.
ValidForResume = false; ValidForResume = false;