1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 16:27:43 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Match/RoomModSelectOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.9 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;
2024-02-18 09:13:57 +08:00
using osu.Game.Rulesets.Mods;
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
{
public RoomModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourScheme.Plum)
2024-02-18 09:13:57 +08:00
: base(colourScheme)
{
}
[Resolved(CanBeNull = true)]
private IBindable<PlaylistItem>? selectedItem { get; set; }
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> roomMods = new List<Mod>();
2024-02-18 09:13:57 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
selectedItem?.BindValueChanged(_ =>
2024-02-18 09:13:57 +08:00
{
roomMods.Clear();
2024-02-18 09:13:57 +08:00
if (selectedItem?.Value != null)
{
var rulesetInstance = rulesets.GetRuleset(selectedItem.Value.RulesetID)?.CreateInstance();
Debug.Assert(rulesetInstance != null);
roomMods.AddRange(selectedItem.Value.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
}
2024-02-18 09:13:57 +08:00
SelectedMods.TriggerChange();
});
2024-02-18 09:13:57 +08:00
}
protected override IEnumerable<Mod> AllSelectedMods => roomMods.Concat(base.AllSelectedMods);
2024-02-18 09:13:57 +08:00
protected override BeatmapAttributesDisplay CreateBeatmapAttributesDisplay() => new RoomBeatmapAttributesDisplay();
private partial class RoomBeatmapAttributesDisplay : BeatmapAttributesDisplay
{
[Resolved(CanBeNull = true)]
private IBindable<PlaylistItem>? selectedItem { get; set; }
2024-02-18 09:13:57 +08:00
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
private readonly List<Mod> roomMods = new List<Mod>();
2024-02-18 09:13:57 +08:00
protected override void LoadComplete()
2024-02-18 09:13:57 +08:00
{
base.LoadComplete();
2024-02-18 09:13:57 +08:00
selectedItem?.BindValueChanged(_ =>
{
roomMods.Clear();
2024-02-18 09:28:24 +08:00
if (selectedItem?.Value != null)
{
var rulesetInstance = rulesets.GetRuleset(selectedItem.Value.RulesetID)?.CreateInstance();
Debug.Assert(rulesetInstance != null);
roomMods.AddRange(selectedItem.Value.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
}
Mods.TriggerChange();
});
}
protected override IEnumerable<Mod> SelectedMods => roomMods.Concat(base.SelectedMods);
}
2024-02-18 09:13:57 +08:00
}
}