mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 18:07:25 +08:00
Rewrite mods flow and remove RoomBeatmapAttributesDisplay
This commit is contained in:
parent
323d7f8e2d
commit
9ce07a96b2
@ -13,7 +13,6 @@ using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Drawables;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -39,15 +38,10 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
public Bindable<IBeatmapInfo?> BeatmapInfo { get; } = new Bindable<IBeatmapInfo?>();
|
||||
|
||||
[Resolved]
|
||||
protected Bindable<IReadOnlyList<Mod>> Mods { get; private set; } = null!;
|
||||
|
||||
protected virtual IEnumerable<Mod> SelectedMods => Mods.Value;
|
||||
public Bindable<IReadOnlyList<Mod>> Mods { get; } = new Bindable<IReadOnlyList<Mod>>();
|
||||
|
||||
public BindableBool Collapsed { get; } = new BindableBool(true);
|
||||
|
||||
private ModSettingChangeTracker? modSettingChangeTracker;
|
||||
|
||||
[Resolved]
|
||||
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
|
||||
|
||||
@ -102,15 +96,8 @@ namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Mods.BindValueChanged(_ =>
|
||||
{
|
||||
modSettingChangeTracker?.Dispose();
|
||||
modSettingChangeTracker = new ModSettingChangeTracker(Mods.Value);
|
||||
modSettingChangeTracker.SettingChanged += _ => updateValues();
|
||||
updateValues();
|
||||
}, true);
|
||||
|
||||
BeatmapInfo.BindValueChanged(_ => updateValues(), true);
|
||||
Mods.BindValueChanged(_ => updateValues());
|
||||
BeatmapInfo.BindValueChanged(_ => updateValues());
|
||||
|
||||
Collapsed.BindValueChanged(_ =>
|
||||
{
|
||||
@ -122,8 +109,9 @@ namespace osu.Game.Overlays.Mods
|
||||
GameRuleset = game.Ruleset.GetBoundCopy();
|
||||
GameRuleset.BindValueChanged(_ => updateValues());
|
||||
|
||||
BeatmapInfo.BindValueChanged(_ => updateValues(), true);
|
||||
BeatmapInfo.BindValueChanged(_ => updateValues());
|
||||
|
||||
updateValues();
|
||||
updateCollapsedState();
|
||||
}
|
||||
|
||||
@ -167,14 +155,14 @@ namespace osu.Game.Overlays.Mods
|
||||
});
|
||||
|
||||
double rate = 1;
|
||||
foreach (var mod in SelectedMods.OfType<IApplicableToRate>())
|
||||
foreach (var mod in Mods.Value.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
|
||||
bpmDisplay.Current.Value = BeatmapInfo.Value.BPM * rate;
|
||||
|
||||
BeatmapDifficulty originalDifficulty = new BeatmapDifficulty(BeatmapInfo.Value.Difficulty);
|
||||
|
||||
foreach (var mod in SelectedMods.OfType<IApplicableToDifficulty>())
|
||||
foreach (var mod in Mods.Value.OfType<IApplicableToDifficulty>())
|
||||
mod.ApplyToDifficulty(originalDifficulty);
|
||||
|
||||
Ruleset ruleset = GameRuleset.Value.CreateInstance();
|
||||
|
@ -114,8 +114,6 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
public IEnumerable<ModState> AllAvailableMods => AvailableMods.Value.SelectMany(pair => pair.Value);
|
||||
|
||||
protected virtual IEnumerable<Mod> AllSelectedMods => SelectedMods.Value;
|
||||
|
||||
private readonly BindableBool customisationVisible = new BindableBool();
|
||||
private Bindable<bool> textSearchStartsActive = null!;
|
||||
|
||||
@ -319,7 +317,7 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
SelectedMods.BindValueChanged(_ =>
|
||||
{
|
||||
updateRankingInformation();
|
||||
UpdateOverlayInformation(SelectedMods.Value);
|
||||
updateFromExternalSelection();
|
||||
updateCustomisation();
|
||||
|
||||
@ -332,7 +330,7 @@ namespace osu.Game.Overlays.Mods
|
||||
//
|
||||
// See https://github.com/ppy/osu/pull/23284#issuecomment-1529056988
|
||||
modSettingChangeTracker = new ModSettingChangeTracker(SelectedMods.Value);
|
||||
modSettingChangeTracker.SettingChanged += _ => updateRankingInformation();
|
||||
modSettingChangeTracker.SettingChanged += _ => UpdateOverlayInformation(SelectedMods.Value);
|
||||
}
|
||||
}, true);
|
||||
|
||||
@ -454,18 +452,30 @@ namespace osu.Game.Overlays.Mods
|
||||
modState.ValidForSelection.Value = modState.Mod.Type != ModType.System && modState.Mod.HasImplementation && IsValidMod.Invoke(modState.Mod);
|
||||
}
|
||||
|
||||
private void updateRankingInformation()
|
||||
/// <summary>
|
||||
/// Updates any information displayed on the overlay regarding the effects of the selected mods.
|
||||
/// </summary>
|
||||
/// <param name="mods">The list of mods to show effect from. This can be overriden to include effect of mods that are not part of the <see cref="SelectedMods"/> bindable (e.g. room mods in multiplayer/playlists).</param>
|
||||
protected virtual void UpdateOverlayInformation(IReadOnlyList<Mod> mods)
|
||||
{
|
||||
if (rankingInformationDisplay == null)
|
||||
return;
|
||||
if (rankingInformationDisplay != null)
|
||||
{
|
||||
double multiplier = 1.0;
|
||||
|
||||
double multiplier = 1.0;
|
||||
foreach (var mod in mods)
|
||||
multiplier *= mod.ScoreMultiplier;
|
||||
|
||||
foreach (var mod in AllSelectedMods)
|
||||
multiplier *= mod.ScoreMultiplier;
|
||||
rankingInformationDisplay.ModMultiplier.Value = multiplier;
|
||||
rankingInformationDisplay.Ranked.Value = mods.All(m => m.Ranked);
|
||||
}
|
||||
|
||||
rankingInformationDisplay.ModMultiplier.Value = multiplier;
|
||||
rankingInformationDisplay.Ranked.Value = AllSelectedMods.All(m => m.Ranked);
|
||||
if (beatmapAttributesDisplay != null)
|
||||
{
|
||||
if (!ReferenceEquals(beatmapAttributesDisplay.Mods.Value, mods))
|
||||
beatmapAttributesDisplay.Mods.Value = mods;
|
||||
else
|
||||
beatmapAttributesDisplay.Mods.TriggerChange(); // mods list may be same but a mod setting has changed, trigger change in that case.
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCustomisation()
|
||||
|
@ -48,40 +48,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
});
|
||||
}
|
||||
|
||||
protected override IEnumerable<Mod> AllSelectedMods => roomMods.Concat(base.AllSelectedMods);
|
||||
|
||||
protected override BeatmapAttributesDisplay CreateBeatmapAttributesDisplay() => new RoomBeatmapAttributesDisplay();
|
||||
|
||||
private partial class RoomBeatmapAttributesDisplay : BeatmapAttributesDisplay
|
||||
{
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IBindable<PlaylistItem>? selectedItem { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; } = null!;
|
||||
|
||||
private readonly List<Mod> roomMods = new List<Mod>();
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
selectedItem?.BindValueChanged(_ =>
|
||||
{
|
||||
roomMods.Clear();
|
||||
|
||||
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);
|
||||
}
|
||||
protected override void UpdateOverlayInformation(IReadOnlyList<Mod> mods)
|
||||
=> base.UpdateOverlayInformation(roomMods.Concat(mods).ToList());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user