1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 17:42:54 +08:00
osu-lazer/osu.Game/Overlays/Mods/MultiplayerModSelectOverlay.cs

89 lines
2.8 KiB
C#
Raw Normal View History

2024-02-18 09:13:57 +08:00
// 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.Collections.Generic;
2024-02-18 09:13:57 +08:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Overlays.Mods
{
public partial class MultiplayerModSelectOverlay : UserModSelectOverlay
{
public MultiplayerModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourScheme.Plum)
: base(colourScheme)
{
}
[Resolved(CanBeNull = true)]
private IBindable<PlaylistItem>? multiplayerRoomItem { get; set; }
[Resolved]
private OsuGameBase game { get; set; } = null!;
protected override BeatmapAttributesDisplay GetBeatmapAttributesDisplay => new MultiplayerBeatmapAttributesDisplay
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
2024-02-18 09:15:53 +08:00
BeatmapInfo = { Value = Beatmap?.BeatmapInfo }
2024-02-18 09:13:57 +08:00
};
protected override void LoadComplete()
{
base.LoadComplete();
multiplayerRoomItem?.BindValueChanged(_ => SelectedMods.TriggerChange());
}
protected override IEnumerable<Mod> AllSelectedMods
2024-02-18 09:13:57 +08:00
{
get
2024-02-18 09:13:57 +08:00
{
IEnumerable<Mod> allMods = SelectedMods.Value;
2024-02-18 09:13:57 +08:00
if (multiplayerRoomItem?.Value != null)
{
Ruleset ruleset = game.Ruleset.Value.CreateInstance();
var multiplayerRoomMods = multiplayerRoomItem.Value.RequiredMods.Select(m => m.ToMod(ruleset));
allMods = allMods.Concat(multiplayerRoomMods);
}
2024-02-18 09:13:57 +08:00
return allMods;
2024-02-18 09:13:57 +08:00
}
}
}
public partial class MultiplayerBeatmapAttributesDisplay : BeatmapAttributesDisplay
{
[Resolved(CanBeNull = true)]
private IBindable<PlaylistItem>? multiplayerRoomItem { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
multiplayerRoomItem?.BindValueChanged(_ => Mods.TriggerChange());
}
protected override IEnumerable<Mod> SelectedMods
2024-02-18 09:13:57 +08:00
{
get
2024-02-18 09:13:57 +08:00
{
IEnumerable<Mod> selectedMods = Mods.Value;
2024-02-18 09:13:57 +08:00
if (multiplayerRoomItem?.Value != null)
{
Ruleset ruleset = GameRuleset.Value.CreateInstance();
var multiplayerRoomMods = multiplayerRoomItem.Value.RequiredMods.Select(m => m.ToMod(ruleset));
selectedMods = selectedMods.Concat(multiplayerRoomMods);
}
2024-02-18 09:28:24 +08:00
return selectedMods;
2024-02-18 09:13:57 +08:00
}
}
}
}