1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 09:22:54 +08:00

Extra mods -> user mods

This commit is contained in:
smoogipoo 2021-02-01 17:57:32 +09:00
parent ac2a995041
commit f538963607
10 changed files with 50 additions and 40 deletions

View File

@ -139,7 +139,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
}); });
Client.ChangeUserExtraMods(0, new Mod[] Client.ChangeUserMods(0, new Mod[]
{ {
new OsuModHardRock(), new OsuModHardRock(),
new OsuModDifficultyAdjust { ApproachRate = { Value = 1 } } new OsuModDifficultyAdjust { ApproachRate = { Value = 1 } }

View File

@ -57,7 +57,7 @@ namespace osu.Game.Online.Multiplayer
/// <param name="beatmapAvailability">The new beatmap availability state of the user.</param> /// <param name="beatmapAvailability">The new beatmap availability state of the user.</param>
Task UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability); Task UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability);
Task UserExtraModsChanged(int userId, IEnumerable<APIMod> mods); Task UserModsChanged(int userId, IEnumerable<APIMod> mods);
/// <summary> /// <summary>
/// Signals that a match is to be started. This will *only* be sent to clients which are to begin loading at this point. /// Signals that a match is to be started. This will *only* be sent to clients which are to begin loading at this point.

View File

@ -49,7 +49,7 @@ namespace osu.Game.Online.Multiplayer
/// <param name="newBeatmapAvailability">The proposed new beatmap availability state.</param> /// <param name="newBeatmapAvailability">The proposed new beatmap availability state.</param>
Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability); Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability);
Task ChangeExtraMods(IEnumerable<APIMod> newMods); Task ChangeUserMods(IEnumerable<APIMod> newMods);
/// <summary> /// <summary>
/// As the host of a room, start the match. /// As the host of a room, start the match.

View File

@ -4,6 +4,7 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -84,6 +85,7 @@ namespace osu.Game.Online.Multiplayer
connection.On(nameof(IMultiplayerClient.LoadRequested), ((IMultiplayerClient)this).LoadRequested); connection.On(nameof(IMultiplayerClient.LoadRequested), ((IMultiplayerClient)this).LoadRequested);
connection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted); connection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted);
connection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady); connection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady);
connection.On<int, IEnumerable<APIMod>>(nameof(IMultiplayerClient.UserModsChanged), ((IMultiplayerClient)this).UserModsChanged);
connection.Closed += async ex => connection.Closed += async ex =>
{ {
@ -182,6 +184,14 @@ namespace osu.Game.Online.Multiplayer
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeBeatmapAvailability), newBeatmapAvailability); return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeBeatmapAvailability), newBeatmapAvailability);
} }
public override Task ChangeUserMods(IEnumerable<APIMod> newMods)
{
if (!isConnected.Value)
return Task.CompletedTask;
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeUserMods), newMods);
}
public override Task StartMatch() public override Task StartMatch()
{ {
if (!isConnected.Value) if (!isConnected.Value)

View File

@ -27,7 +27,7 @@ namespace osu.Game.Online.Multiplayer
public BeatmapAvailability BeatmapAvailability { get; set; } = BeatmapAvailability.LocallyAvailable(); public BeatmapAvailability BeatmapAvailability { get; set; } = BeatmapAvailability.LocallyAvailable();
[NotNull] [NotNull]
public IEnumerable<APIMod> ExtraMods { get; set; } = Enumerable.Empty<APIMod>(); public IEnumerable<APIMod> UserMods { get; set; } = Enumerable.Empty<APIMod>();
public User? User { get; set; } public User? User { get; set; }

View File

@ -232,9 +232,9 @@ namespace osu.Game.Online.Multiplayer
public abstract Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability); public abstract Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability);
public Task ChangeExtraMods(IEnumerable<Mod> newMods) => ChangeExtraMods(newMods.Select(m => new APIMod(m)).ToList()); public Task ChangeUserMods(IEnumerable<Mod> newMods) => ChangeUserMods(newMods.Select(m => new APIMod(m)).ToList());
public abstract Task ChangeExtraMods(IEnumerable<APIMod> newMods); public abstract Task ChangeUserMods(IEnumerable<APIMod> newMods);
public abstract Task StartMatch(); public abstract Task StartMatch();
@ -384,7 +384,7 @@ namespace osu.Game.Online.Multiplayer
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task UserExtraModsChanged(int userId, IEnumerable<APIMod> mods) public Task UserModsChanged(int userId, IEnumerable<APIMod> mods)
{ {
if (Room == null) if (Room == null)
return Task.CompletedTask; return Task.CompletedTask;
@ -397,7 +397,7 @@ namespace osu.Game.Online.Multiplayer
if (user == null) if (user == null)
return; return;
user.ExtraMods = mods; user.UserMods = mods;
RoomUpdated?.Invoke(); RoomUpdated?.Invoke();
}, false); }, false);

View File

@ -33,7 +33,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
/// <summary> /// <summary>
/// Any mods applied by/to the local user. /// Any mods applied by/to the local user.
/// </summary> /// </summary>
protected readonly Bindable<IReadOnlyList<Mod>> ExtraMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>()); protected readonly Bindable<IReadOnlyList<Mod>> UserMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
[Resolved] [Resolved]
private MusicController music { get; set; } private MusicController music { get; set; }
@ -62,7 +62,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
managerUpdated = beatmapManager.ItemUpdated.GetBoundCopy(); managerUpdated = beatmapManager.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated); managerUpdated.BindValueChanged(beatmapUpdated);
ExtraMods.BindValueChanged(_ => updateMods()); UserMods.BindValueChanged(_ => updateMods());
} }
public override void OnEntering(IScreen last) public override void OnEntering(IScreen last)
@ -108,9 +108,9 @@ namespace osu.Game.Screens.OnlinePlay.Match
return; return;
// Remove any extra mods that are no longer allowed. // Remove any extra mods that are no longer allowed.
ExtraMods.Value = ExtraMods.Value UserMods.Value = UserMods.Value
.Where(m => SelectedItem.Value.AllowedMods.Any(a => m.GetType() == a.GetType())) .Where(m => SelectedItem.Value.AllowedMods.Any(a => m.GetType() == a.GetType()))
.ToList(); .ToList();
updateMods(); updateMods();
@ -134,7 +134,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
if (SelectedItem.Value == null) if (SelectedItem.Value == null)
return; return;
Mods.Value = ExtraMods.Value.Concat(SelectedItem.Value.RequiredMods).ToList(); Mods.Value = UserMods.Value.Concat(SelectedItem.Value.RequiredMods).ToList();
} }
private void beginHandlingTrack() private void beginHandlingTrack()

View File

@ -42,9 +42,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[Resolved] [Resolved]
private OngoingOperationTracker ongoingOperationTracker { get; set; } private OngoingOperationTracker ongoingOperationTracker { get; set; }
private ModSelectOverlay extraModSelectOverlay; private ModSelectOverlay userModsSelectOverlay;
private MultiplayerMatchSettingsOverlay settingsOverlay; private MultiplayerMatchSettingsOverlay settingsOverlay;
private Drawable extraModsSection; private Drawable userModsSection;
private IBindable<bool> isConnected; private IBindable<bool> isConnected;
@ -149,7 +149,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
new BeatmapSelectionControl { RelativeSizeAxes = Axes.X } new BeatmapSelectionControl { RelativeSizeAxes = Axes.X }
} }
}, },
extraModsSection = new FillFlowContainer userModsSection = new FillFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
@ -159,13 +159,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
new ModDisplay new ModDisplay
{ {
DisplayUnrankedText = false, DisplayUnrankedText = false,
Current = ExtraMods Current = UserMods
}, },
new PurpleTriangleButton new PurpleTriangleButton
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Text = "Select", Text = "Select",
Action = () => extraModSelectOverlay.Show() Action = () => userModsSelectOverlay.Show()
} }
} }
} }
@ -210,9 +210,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
new Dimension(GridSizeMode.AutoSize), new Dimension(GridSizeMode.AutoSize),
} }
}, },
extraModSelectOverlay = new SoloModSelectOverlay userModsSelectOverlay = new SoloModSelectOverlay
{ {
SelectedMods = { BindTarget = ExtraMods }, SelectedMods = { BindTarget = UserMods },
Stacked = false, Stacked = false,
IsValidMod = _ => false IsValidMod = _ => false
}, },
@ -242,7 +242,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
base.LoadComplete(); base.LoadComplete();
Playlist.BindCollectionChanged(onPlaylistChanged, true); Playlist.BindCollectionChanged(onPlaylistChanged, true);
ExtraMods.BindValueChanged(onExtraModsChanged); UserMods.BindValueChanged(onUserModsChanged);
client.LoadRequested += onLoadRequested; client.LoadRequested += onLoadRequested;
@ -262,9 +262,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
return true; return true;
} }
if (extraModSelectOverlay.State.Value == Visibility.Visible) if (userModsSelectOverlay.State.Value == Visibility.Visible)
{ {
extraModSelectOverlay.Hide(); userModsSelectOverlay.Hide();
return true; return true;
} }
@ -277,23 +277,23 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
if (SelectedItem.Value?.AllowedMods.Any() != true) if (SelectedItem.Value?.AllowedMods.Any() != true)
{ {
extraModsSection.Hide(); userModsSection.Hide();
extraModSelectOverlay.Hide(); userModsSelectOverlay.Hide();
extraModSelectOverlay.IsValidMod = _ => false; userModsSelectOverlay.IsValidMod = _ => false;
} }
else else
{ {
extraModsSection.Show(); userModsSection.Show();
extraModSelectOverlay.IsValidMod = m => SelectedItem.Value.AllowedMods.Any(a => a.GetType() == m.GetType()); userModsSelectOverlay.IsValidMod = m => SelectedItem.Value.AllowedMods.Any(a => a.GetType() == m.GetType());
} }
} }
private void onExtraModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> extraMods) private void onUserModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
{ {
if (client.Room == null) if (client.Room == null)
return; return;
client.ChangeExtraMods(extraMods.NewValue).CatchUnobservedExceptions(); client.ChangeUserMods(mods.NewValue).CatchUnobservedExceptions();
} }
private void onReadyClick() private void onReadyClick()

View File

@ -36,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private RulesetStore rulesets { get; set; }
private ModDisplay extraModsDisplay; private ModDisplay userModsDisplay;
private StateDisplay userStateDisplay; private StateDisplay userStateDisplay;
private SpriteIcon crown; private SpriteIcon crown;
@ -139,7 +139,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
Spacing = new Vector2(10), Spacing = new Vector2(10),
Children = new Drawable[] Children = new Drawable[]
{ {
extraModsDisplay = new ModDisplay userModsDisplay = new ModDisplay
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -174,7 +174,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID).CreateInstance(); var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID).CreateInstance();
userStateDisplay.Status = User.State; userStateDisplay.Status = User.State;
extraModsDisplay.Current.Value = User.ExtraMods.Select(m => m.ToMod(ruleset)).ToList(); userModsDisplay.Current.Value = User.UserMods.Select(m => m.ToMod(ruleset)).ToList();
if (Room.Host?.Equals(User) == true) if (Room.Host?.Equals(User) == true)
crown.FadeIn(fade_time); crown.FadeIn(fade_time);

View File

@ -124,18 +124,18 @@ namespace osu.Game.Tests.Visual.Multiplayer
return Task.CompletedTask; return Task.CompletedTask;
} }
public void ChangeUserExtraMods(int userId, IEnumerable<Mod> newMods) public void ChangeUserMods(int userId, IEnumerable<Mod> newMods)
=> ChangeUserExtraMods(userId, newMods.Select(m => new APIMod(m)).ToList()); => ChangeUserMods(userId, newMods.Select(m => new APIMod(m)).ToList());
public void ChangeUserExtraMods(int userId, IEnumerable<APIMod> newMods) public void ChangeUserMods(int userId, IEnumerable<APIMod> newMods)
{ {
Debug.Assert(Room != null); Debug.Assert(Room != null);
((IMultiplayerClient)this).UserExtraModsChanged(userId, newMods.ToList()); ((IMultiplayerClient)this).UserModsChanged(userId, newMods.ToList());
} }
public override Task ChangeExtraMods(IEnumerable<APIMod> newMods) public override Task ChangeUserMods(IEnumerable<APIMod> newMods)
{ {
ChangeUserExtraMods(api.LocalUser.Value.Id, newMods); ChangeUserMods(api.LocalUser.Value.Id, newMods);
return Task.CompletedTask; return Task.CompletedTask;
} }