1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 00:02: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",
});
Client.ChangeUserExtraMods(0, new Mod[]
Client.ChangeUserMods(0, new Mod[]
{
new OsuModHardRock(),
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>
Task UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability);
Task UserExtraModsChanged(int userId, IEnumerable<APIMod> mods);
Task UserModsChanged(int userId, IEnumerable<APIMod> mods);
/// <summary>
/// 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>
Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability);
Task ChangeExtraMods(IEnumerable<APIMod> newMods);
Task ChangeUserMods(IEnumerable<APIMod> newMods);
/// <summary>
/// As the host of a room, start the match.

View File

@ -4,6 +4,7 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
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.MatchStarted), ((IMultiplayerClient)this).MatchStarted);
connection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady);
connection.On<int, IEnumerable<APIMod>>(nameof(IMultiplayerClient.UserModsChanged), ((IMultiplayerClient)this).UserModsChanged);
connection.Closed += async ex =>
{
@ -182,6 +184,14 @@ namespace osu.Game.Online.Multiplayer
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()
{
if (!isConnected.Value)

View File

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

View File

@ -232,9 +232,9 @@ namespace osu.Game.Online.Multiplayer
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();
@ -384,7 +384,7 @@ namespace osu.Game.Online.Multiplayer
return Task.CompletedTask;
}
public Task UserExtraModsChanged(int userId, IEnumerable<APIMod> mods)
public Task UserModsChanged(int userId, IEnumerable<APIMod> mods)
{
if (Room == null)
return Task.CompletedTask;
@ -397,7 +397,7 @@ namespace osu.Game.Online.Multiplayer
if (user == null)
return;
user.ExtraMods = mods;
user.UserMods = mods;
RoomUpdated?.Invoke();
}, false);

View File

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

View File

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

View File

@ -36,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
[Resolved]
private RulesetStore rulesets { get; set; }
private ModDisplay extraModsDisplay;
private ModDisplay userModsDisplay;
private StateDisplay userStateDisplay;
private SpriteIcon crown;
@ -139,7 +139,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
Spacing = new Vector2(10),
Children = new Drawable[]
{
extraModsDisplay = new ModDisplay
userModsDisplay = new ModDisplay
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -174,7 +174,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID).CreateInstance();
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)
crown.FadeIn(fade_time);

View File

@ -124,18 +124,18 @@ namespace osu.Game.Tests.Visual.Multiplayer
return Task.CompletedTask;
}
public void ChangeUserExtraMods(int userId, IEnumerable<Mod> newMods)
=> ChangeUserExtraMods(userId, newMods.Select(m => new APIMod(m)).ToList());
public void ChangeUserMods(int userId, IEnumerable<Mod> newMods)
=> 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);
((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;
}