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-29 05:42:52 +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-29 05:42:52 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2024-02-18 09:13:57 +08:00
|
|
|
|
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-05-30 20:15:23 +08:00
|
|
|
public Bindable<PlaylistItem> SelectedItem { get; } = new Bindable<PlaylistItem>();
|
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-29 05:42:52 +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();
|
|
|
|
|
2024-05-30 20:15:23 +08:00
|
|
|
SelectedItem.BindValueChanged(v =>
|
2024-02-18 09:13:57 +08:00
|
|
|
{
|
2024-02-29 05:42:52 +08:00
|
|
|
roomRequiredMods.Clear();
|
|
|
|
|
2024-02-27 03:25:04 +08:00
|
|
|
if (v.NewValue is PlaylistItem item)
|
2024-02-20 18:57:28 +08:00
|
|
|
{
|
2024-02-23 22:30:31 +08:00
|
|
|
var rulesetInstance = rulesets.GetRuleset(item.RulesetID)?.CreateInstance();
|
2024-02-23 21:47:37 +08:00
|
|
|
Debug.Assert(rulesetInstance != null);
|
2024-02-29 05:42:52 +08:00
|
|
|
roomRequiredMods.AddRange(item.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
|
2024-02-20 18:57:28 +08:00
|
|
|
}
|
2024-02-29 05:42:52 +08:00
|
|
|
|
|
|
|
ActiveMods.Value = ComputeActiveMods();
|
2024-02-27 03:25:04 +08:00
|
|
|
}, true);
|
2024-02-18 09:13:57 +08:00
|
|
|
}
|
2024-02-29 05:42:52 +08:00
|
|
|
|
|
|
|
protected override IReadOnlyList<Mod> ComputeActiveMods() => roomRequiredMods.Concat(base.ComputeActiveMods()).ToList();
|
2024-02-18 09:13:57 +08:00
|
|
|
}
|
|
|
|
}
|