mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 14:42:56 +08:00
Simplify active mods computation
Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
This commit is contained in:
parent
2151e0a294
commit
4a4ef91bc9
@ -104,6 +104,8 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
protected virtual IReadOnlyList<Mod> ComputeNewModsFromSelection(IReadOnlyList<Mod> oldSelection, IReadOnlyList<Mod> newSelection) => newSelection;
|
||||
|
||||
protected virtual IReadOnlyList<Mod> ComputeActiveMods() => SelectedMods.Value;
|
||||
|
||||
protected virtual IEnumerable<ShearedButton> CreateFooterButtons()
|
||||
{
|
||||
if (AllowCustomisation)
|
||||
@ -321,13 +323,12 @@ namespace osu.Game.Overlays.Mods
|
||||
if (AllowCustomisation)
|
||||
((IBindable<IReadOnlyList<Mod>>)modSettingsArea.SelectedMods).BindTo(SelectedMods);
|
||||
|
||||
SelectedMods.BindValueChanged(mods =>
|
||||
SelectedMods.BindValueChanged(_ =>
|
||||
{
|
||||
var newMods = ActiveMods.Value.Except(mods.OldValue).Concat(mods.NewValue).ToList();
|
||||
ActiveMods.Value = newMods;
|
||||
|
||||
updateFromExternalSelection();
|
||||
updateCustomisation();
|
||||
|
||||
ActiveMods.Value = ComputeActiveMods();
|
||||
}, true);
|
||||
|
||||
ActiveMods.BindValueChanged(_ =>
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
@ -9,6 +10,7 @@ using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Match
|
||||
{
|
||||
@ -20,6 +22,8 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; } = null!;
|
||||
|
||||
private readonly List<Mod> roomRequiredMods = new List<Mod>();
|
||||
|
||||
public RoomModSelectOverlay()
|
||||
: base(OverlayColourScheme.Plum)
|
||||
{
|
||||
@ -31,15 +35,19 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
|
||||
selectedItem.BindValueChanged(v =>
|
||||
{
|
||||
roomRequiredMods.Clear();
|
||||
|
||||
if (v.NewValue is PlaylistItem item)
|
||||
{
|
||||
var rulesetInstance = rulesets.GetRuleset(item.RulesetID)?.CreateInstance();
|
||||
Debug.Assert(rulesetInstance != null);
|
||||
ActiveMods.Value = item.RequiredMods.Select(m => m.ToMod(rulesetInstance)).Concat(SelectedMods.Value).ToList();
|
||||
roomRequiredMods.AddRange(item.RequiredMods.Select(m => m.ToMod(rulesetInstance)));
|
||||
}
|
||||
else
|
||||
ActiveMods.Value = SelectedMods.Value;
|
||||
|
||||
ActiveMods.Value = ComputeActiveMods();
|
||||
}, true);
|
||||
}
|
||||
|
||||
protected override IReadOnlyList<Mod> ComputeActiveMods() => roomRequiredMods.Concat(base.ComputeActiveMods()).ToList();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user