1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 03:42:58 +08:00

Move ready-up logic to match sub-screen

This commit is contained in:
Bartłomiej Dach 2020-12-29 07:51:46 +01:00
parent 903dca875e
commit 9ff2140232
3 changed files with 41 additions and 26 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;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -19,7 +20,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>(); public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
public Action OnReady
{
set => readyButton.OnReady = value;
}
private readonly Drawable background; private readonly Drawable background;
private readonly MultiplayerReadyButton readyButton;
public MultiplayerMatchFooter() public MultiplayerMatchFooter()
{ {
@ -29,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
InternalChildren = new[] InternalChildren = new[]
{ {
background = new Box { RelativeSizeAxes = Axes.Both }, background = new Box { RelativeSizeAxes = Axes.Both },
new MultiplayerReadyButton readyButton = new MultiplayerReadyButton
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,

View File

@ -1,15 +1,14 @@
// 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;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Extensions;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osu.Game.Online.API; using osu.Game.Online.API;
@ -24,6 +23,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
{ {
public Bindable<PlaylistItem> SelectedItem => button.SelectedItem; public Bindable<PlaylistItem> SelectedItem => button.SelectedItem;
public Action OnReady
{
set => button.Action = value;
}
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
@ -47,7 +51,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Size = Vector2.One, Size = Vector2.One,
Enabled = { Value = true }, Enabled = { Value = true },
Action = onClick
}; };
} }
@ -136,27 +139,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
} }
} }
private void onClick()
{
var localUser = Client.LocalUser;
if (localUser == null)
return;
if (localUser.State == MultiplayerUserState.Idle)
Client.ChangeState(MultiplayerUserState.Ready).CatchUnobservedExceptions(true);
else
{
if (Room?.Host?.Equals(localUser) == true)
{
gameplayStartTracker.BeginOperation();
Client.StartMatch().CatchUnobservedExceptions(true);
}
else
Client.ChangeState(MultiplayerUserState.Idle).CatchUnobservedExceptions(true);
}
}
private class ButtonWithTrianglesExposed : ReadyButton private class ButtonWithTrianglesExposed : ReadyButton
{ {
public new Triangles Triangles => base.Triangles; public new Triangles Triangles => base.Triangles;

View File

@ -9,6 +9,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Extensions;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
@ -153,7 +154,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}, },
new Drawable[] new Drawable[]
{ {
new MultiplayerMatchFooter { SelectedItem = { BindTarget = SelectedItem } } new MultiplayerMatchFooter
{
SelectedItem = { BindTarget = SelectedItem },
OnReady = onReady
}
} }
}, },
RowDimensions = new[] RowDimensions = new[]
@ -199,6 +204,27 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e) => SelectedItem.Value = Playlist.FirstOrDefault(); private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e) => SelectedItem.Value = Playlist.FirstOrDefault();
private void onReady()
{
var localUser = client.LocalUser;
if (localUser == null)
return;
if (localUser.State == MultiplayerUserState.Idle)
client.ChangeState(MultiplayerUserState.Ready).CatchUnobservedExceptions(true);
else
{
if (client.Room?.Host?.Equals(localUser) == true)
{
gameplayStartTracker.BeginOperation();
client.StartMatch().CatchUnobservedExceptions(true);
}
else
client.ChangeState(MultiplayerUserState.Idle).CatchUnobservedExceptions(true);
}
}
private void onLoadRequested() private void onLoadRequested()
{ {
Debug.Assert(client.Room != null); Debug.Assert(client.Room != null);