2024-02-23 21:42:58 +08:00
|
|
|
// 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.
|
|
|
|
|
2024-02-20 18:57:28 +08:00
|
|
|
using System.Collections.Generic;
|
2024-02-23 21:47:37 +08:00
|
|
|
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;
|
2024-02-23 21:42:58 +08:00
|
|
|
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;
|
|
|
|
|
2024-02-23 21:42:58 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Match
|
2024-02-18 09:13:57 +08:00
|
|
|
{
|
2024-02-23 21:42:58 +08:00
|
|
|
public partial class RoomModSelectOverlay : UserModSelectOverlay
|
2024-02-18 09:13:57 +08:00
|
|
|
{
|
2024-02-23 21:42:58 +08:00
|
|
|
public RoomModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourScheme.Plum)
|
2024-02-18 09:13:57 +08:00
|
|
|
: base(colourScheme)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[Resolved(CanBeNull = true)]
|
2024-02-23 21:42:58 +08:00
|
|
|
private IBindable<PlaylistItem>? selectedItem { get; set; }
|
2024-02-18 09:13:57 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2024-02-23 21:47:37 +08:00
|
|
|
private RulesetStore rulesets { get; set; } = null!;
|
2024-02-18 09:13:57 +08:00
|
|
|
|
2024-02-23 21:51:52 +08:00
|
|
|
private readonly List<Mod> roomMods = new List<Mod>();
|
|
|
|
|
2024-02-18 09:13:57 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2024-02-23 21:51:52 +08:00
|
|
|
selectedItem?.BindValueChanged(_ =>
|
2024-02-18 09:13:57 +08:00
|
|
|
{
|
2024-02-23 21:51:52 +08:00
|
|
|
roomMods.Clear();
|
2024-02-18 09:13:57 +08:00
|
|
|
|
2024-02-23 21:42:58 +08:00
|
|
|
if (selectedItem?.Value != null)
|
2024-02-20 18:57:28 +08:00
|
|
|
{
|
2024-02-23 21:47:37 +08:00
|
|
|
var rulesetInstance = rulesets.GetRuleset(selectedItem.Value.RulesetID)?.CreateInstance();
|
|
|
|
Debug.Assert(rulesetInstance != null);
|
2024-02-23 21:51:52 +08:00
|
|
|
roomMods.AddRange(selectedItem.Value.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
|
2024-02-20 18:57:28 +08:00
|
|
|
}
|
2024-02-18 09:13:57 +08:00
|
|
|
|
2024-02-23 21:51:52 +08:00
|
|
|
SelectedMods.TriggerChange();
|
|
|
|
});
|
2024-02-18 09:13:57 +08:00
|
|
|
}
|
2024-02-23 21:51:52 +08:00
|
|
|
|
|
|
|
protected override IEnumerable<Mod> AllSelectedMods => roomMods.Concat(base.AllSelectedMods);
|
2024-02-18 09:13:57 +08:00
|
|
|
|
2024-02-23 21:59:08 +08:00
|
|
|
protected override BeatmapAttributesDisplay CreateBeatmapAttributesDisplay() => new RoomBeatmapAttributesDisplay();
|
2024-02-23 21:47:37 +08:00
|
|
|
|
2024-02-23 21:59:08 +08:00
|
|
|
private partial class RoomBeatmapAttributesDisplay : BeatmapAttributesDisplay
|
|
|
|
{
|
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
private IBindable<PlaylistItem>? selectedItem { get; set; }
|
2024-02-18 09:13:57 +08:00
|
|
|
|
2024-02-23 21:59:08 +08:00
|
|
|
[Resolved]
|
|
|
|
private RulesetStore rulesets { get; set; } = null!;
|
2024-02-23 21:51:52 +08:00
|
|
|
|
2024-02-23 21:59:08 +08:00
|
|
|
private readonly List<Mod> roomMods = new List<Mod>();
|
2024-02-18 09:13:57 +08:00
|
|
|
|
2024-02-23 21:59:08 +08:00
|
|
|
protected override void LoadComplete()
|
2024-02-18 09:13:57 +08:00
|
|
|
{
|
2024-02-23 21:59:08 +08:00
|
|
|
base.LoadComplete();
|
2024-02-18 09:13:57 +08:00
|
|
|
|
2024-02-23 21:59:08 +08:00
|
|
|
selectedItem?.BindValueChanged(_ =>
|
2024-02-20 18:57:28 +08:00
|
|
|
{
|
2024-02-23 21:59:08 +08:00
|
|
|
roomMods.Clear();
|
2024-02-18 09:28:24 +08:00
|
|
|
|
2024-02-23 21:59:08 +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();
|
|
|
|
});
|
|
|
|
}
|
2024-02-23 21:51:52 +08:00
|
|
|
|
2024-02-23 21:59:08 +08:00
|
|
|
protected override IEnumerable<Mod> SelectedMods => roomMods.Concat(base.SelectedMods);
|
|
|
|
}
|
2024-02-18 09:13:57 +08:00
|
|
|
}
|
|
|
|
}
|