From 6cd4a36c61b7a58ec1195048e4a4cbc2207d72f7 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 25 Mar 2025 16:17:54 +0900 Subject: [PATCH] Add multiplayer user mod display --- .../Multiplayer/MultiplayerMatchSubScreen.cs | 4 +- .../Multiplayer/MultiplayerUserModDisplay.cs | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerUserModDisplay.cs diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs index 2b3243e01d..6c6932f479 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs @@ -31,7 +31,6 @@ using osu.Game.Screens.OnlinePlay.Multiplayer.Match; using osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist; using osu.Game.Screens.OnlinePlay.Multiplayer.Participants; using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate; -using osu.Game.Screens.Play.HUD; using osu.Game.Users; using osuTK; using ParticipantsList = osu.Game.Screens.OnlinePlay.Multiplayer.Participants.ParticipantsList; @@ -180,11 +179,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer Text = "Select", Action = ShowUserModSelect, }, - new ModDisplay + new MultiplayerUserModDisplay { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Current = UserMods, Scale = new Vector2(0.8f), }, } diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerUserModDisplay.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerUserModDisplay.cs new file mode 100644 index 0000000000..8937feed5e --- /dev/null +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerUserModDisplay.cs @@ -0,0 +1,67 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Extensions.ObjectExtensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Online.Multiplayer; +using osu.Game.Online.Rooms; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; +using osu.Game.Screens.Play.HUD; + +namespace osu.Game.Screens.OnlinePlay.Multiplayer +{ + public partial class MultiplayerUserModDisplay : CompositeDrawable + { + [Resolved] + private MultiplayerClient client { get; set; } = null!; + + [Resolved] + private RulesetStore rulesets { get; set; } = null!; + + private ModDisplay modDisplay = null!; + + public MultiplayerUserModDisplay() + { + AutoSizeAxes = Axes.Both; + } + + [BackgroundDependencyLoader] + private void load() + { + InternalChild = modDisplay = new ModDisplay(); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + client.RoomUpdated += onRoomUpdated; + onRoomUpdated(); + } + + private void onRoomUpdated() => Scheduler.AddOnce(() => + { + if (client.Room == null || client.LocalUser == null) + return; + + MultiplayerPlaylistItem currentItem = client.Room.CurrentPlaylistItem; + Ruleset ruleset = rulesets.GetRuleset(client.LocalUser.RulesetId ?? currentItem.RulesetID)!.CreateInstance(); + Mod[] userMods = client.LocalUser.Mods.Select(m => m.ToMod(ruleset)).ToArray(); + + if (!userMods.SequenceEqual(modDisplay.Current.Value)) + modDisplay.Current.Value = userMods; + }); + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + if (client.IsNotNull()) + client.RoomUpdated -= onRoomUpdated; + } + } +}