mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 06:52:56 +08:00
Merge pull request #11410 from frenzibyte/user-beatmap-downloading-states
Add change state methods for multiplayer user beatmap availability
This commit is contained in:
commit
862cb1412c
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
@ -47,6 +48,13 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <param name="state">The new state of the user.</param>
|
||||
Task UserStateChanged(int userId, MultiplayerUserState state);
|
||||
|
||||
/// <summary>
|
||||
/// Signals that a user in this room changed their beatmap availability state.
|
||||
/// </summary>
|
||||
/// <param name="userId">The ID of the user whose beatmap availability state has changed.</param>
|
||||
/// <param name="beatmapAvailability">The new beatmap availability state of the user.</param>
|
||||
Task UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability);
|
||||
|
||||
/// <summary>
|
||||
/// Signals that a match is to be started. This will *only* be sent to clients which are to begin loading at this point.
|
||||
/// </summary>
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
@ -40,6 +41,12 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <exception cref="NotJoinedRoomException">If the user is not in a room.</exception>
|
||||
Task ChangeState(MultiplayerUserState newState);
|
||||
|
||||
/// <summary>
|
||||
/// Change the local user's availability state of the current beatmap set in joined room.
|
||||
/// </summary>
|
||||
/// <param name="newBeatmapAvailability">The proposed new beatmap availability state.</param>
|
||||
Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability);
|
||||
|
||||
/// <summary>
|
||||
/// As the host of a room, start the match.
|
||||
/// </summary>
|
||||
|
@ -14,6 +14,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
@ -173,6 +174,14 @@ namespace osu.Game.Online.Multiplayer
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeState), newState);
|
||||
}
|
||||
|
||||
public override Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability)
|
||||
{
|
||||
if (!isConnected.Value)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeBeatmapAvailability), newBeatmapAvailability);
|
||||
}
|
||||
|
||||
public override Task StartMatch()
|
||||
{
|
||||
if (!isConnected.Value)
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
@ -16,6 +17,11 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
public MultiplayerUserState State { get; set; } = MultiplayerUserState.Idle;
|
||||
|
||||
/// <summary>
|
||||
/// The availability state of the current beatmap.
|
||||
/// </summary>
|
||||
public BeatmapAvailability BeatmapAvailability { get; set; } = BeatmapAvailability.LocallyAvailable();
|
||||
|
||||
public User? User { get; set; }
|
||||
|
||||
[JsonConstructor]
|
||||
|
@ -227,6 +227,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
public abstract Task ChangeState(MultiplayerUserState newState);
|
||||
|
||||
public abstract Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability);
|
||||
|
||||
public abstract Task StartMatch();
|
||||
|
||||
Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state)
|
||||
@ -354,6 +356,27 @@ namespace osu.Game.Online.Multiplayer
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Task IMultiplayerClient.UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability)
|
||||
{
|
||||
if (Room == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
Scheduler.Add(() =>
|
||||
{
|
||||
var user = Room?.Users.SingleOrDefault(u => u.UserID == userId);
|
||||
|
||||
// errors here are not critical - beatmap availability state is mostly for display.
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
user.BeatmapAvailability = beatmapAvailability;
|
||||
|
||||
RoomUpdated?.Invoke();
|
||||
}, false);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Task IMultiplayerClient.LoadRequested()
|
||||
{
|
||||
if (Room == null)
|
||||
|
40
osu.Game/Online/Rooms/BeatmapAvailability.cs
Normal file
40
osu.Game/Online/Rooms/BeatmapAvailability.cs
Normal file
@ -0,0 +1,40 @@
|
||||
// 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 Newtonsoft.Json;
|
||||
|
||||
namespace osu.Game.Online.Rooms
|
||||
{
|
||||
/// <summary>
|
||||
/// The local availability information about a certain beatmap for the client.
|
||||
/// </summary>
|
||||
public class BeatmapAvailability : IEquatable<BeatmapAvailability>
|
||||
{
|
||||
/// <summary>
|
||||
/// The beatmap's availability state.
|
||||
/// </summary>
|
||||
public readonly DownloadState State;
|
||||
|
||||
/// <summary>
|
||||
/// The beatmap's downloading progress, null when not in <see cref="DownloadState.Downloading"/> state.
|
||||
/// </summary>
|
||||
public readonly double? DownloadProgress;
|
||||
|
||||
[JsonConstructor]
|
||||
private BeatmapAvailability(DownloadState state, double? downloadProgress = null)
|
||||
{
|
||||
State = state;
|
||||
DownloadProgress = downloadProgress;
|
||||
}
|
||||
|
||||
public static BeatmapAvailability NotDownloaded() => new BeatmapAvailability(DownloadState.NotDownloaded);
|
||||
public static BeatmapAvailability Downloading(double progress) => new BeatmapAvailability(DownloadState.Downloading, progress);
|
||||
public static BeatmapAvailability Importing() => new BeatmapAvailability(DownloadState.Importing);
|
||||
public static BeatmapAvailability LocallyAvailable() => new BeatmapAvailability(DownloadState.LocallyAvailable);
|
||||
|
||||
public bool Equals(BeatmapAvailability other) => other != null && State == other.State && DownloadProgress == other.DownloadProgress;
|
||||
|
||||
public override string ToString() => $"{string.Join(", ", State, $"{DownloadProgress:0.00%}")}";
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
@ -77,6 +78,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
});
|
||||
}
|
||||
|
||||
public void ChangeUserBeatmapAvailability(int userId, BeatmapAvailability newBeatmapAvailability)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
||||
((IMultiplayerClient)this).UserBeatmapAvailabilityChanged(userId, newBeatmapAvailability);
|
||||
}
|
||||
|
||||
protected override Task<MultiplayerRoom> JoinRoom(long roomId)
|
||||
{
|
||||
var user = new MultiplayerRoomUser(api.LocalUser.Value.Id) { User = api.LocalUser.Value };
|
||||
@ -108,6 +116,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability)
|
||||
{
|
||||
ChangeUserBeatmapAvailability(api.LocalUser.Value.Id, newBeatmapAvailability);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task StartMatch()
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
Loading…
Reference in New Issue
Block a user