1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-31 00:02:56 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Match/RoomModSelectOverlay.cs

54 lines
1.6 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2024-02-18 09:13:57 +08:00
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Diagnostics;
2024-02-18 09:13:57 +08:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
2024-02-18 09:13:57 +08:00
namespace osu.Game.Screens.OnlinePlay.Match
2024-02-18 09:13:57 +08:00
{
public partial class RoomModSelectOverlay : UserModSelectOverlay
2024-02-18 09:13:57 +08:00
{
2024-02-23 22:30:31 +08:00
[Resolved]
private IBindable<PlaylistItem> selectedItem { get; set; } = null!;
2024-02-18 09:13:57 +08:00
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
2024-02-18 09:13:57 +08:00
private readonly List<Mod> roomRequiredMods = new List<Mod>();
2024-02-23 22:30:31 +08:00
public RoomModSelectOverlay()
: base(OverlayColourScheme.Plum)
{
}
2024-02-18 09:13:57 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
selectedItem.BindValueChanged(v =>
2024-02-18 09:13:57 +08:00
{
roomRequiredMods.Clear();
if (v.NewValue is PlaylistItem item)
{
2024-02-23 22:30:31 +08:00
var rulesetInstance = rulesets.GetRuleset(item.RulesetID)?.CreateInstance();
Debug.Assert(rulesetInstance != null);
roomRequiredMods.AddRange(item.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
}
ActiveMods.Value = ComputeActiveMods();
}, true);
2024-02-18 09:13:57 +08:00
}
protected override IReadOnlyList<Mod> ComputeActiveMods() => roomRequiredMods.Concat(base.ComputeActiveMods()).ToList();
2024-02-18 09:13:57 +08:00
}
}