mirror of
https://github.com/ppy/osu.git
synced 2024-11-14 16:37:26 +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.Framework.Localisation;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Drawables;
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Configuration;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
@ -39,15 +38,10 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
public Bindable<IBeatmapInfo?> BeatmapInfo { get; } = new Bindable<IBeatmapInfo?>();
|
public Bindable<IBeatmapInfo?> BeatmapInfo { get; } = new Bindable<IBeatmapInfo?>();
|
||||||
|
|
||||||
[Resolved]
|
public Bindable<IReadOnlyList<Mod>> Mods { get; } = new Bindable<IReadOnlyList<Mod>>();
|
||||||
protected Bindable<IReadOnlyList<Mod>> Mods { get; private set; } = null!;
|
|
||||||
|
|
||||||
protected virtual IEnumerable<Mod> SelectedMods => Mods.Value;
|
|
||||||
|
|
||||||
public BindableBool Collapsed { get; } = new BindableBool(true);
|
public BindableBool Collapsed { get; } = new BindableBool(true);
|
||||||
|
|
||||||
private ModSettingChangeTracker? modSettingChangeTracker;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
|
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
|
||||||
|
|
||||||
@ -102,15 +96,8 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
Mods.BindValueChanged(_ =>
|
Mods.BindValueChanged(_ => updateValues());
|
||||||
{
|
BeatmapInfo.BindValueChanged(_ => updateValues());
|
||||||
modSettingChangeTracker?.Dispose();
|
|
||||||
modSettingChangeTracker = new ModSettingChangeTracker(Mods.Value);
|
|
||||||
modSettingChangeTracker.SettingChanged += _ => updateValues();
|
|
||||||
updateValues();
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
BeatmapInfo.BindValueChanged(_ => updateValues(), true);
|
|
||||||
|
|
||||||
Collapsed.BindValueChanged(_ =>
|
Collapsed.BindValueChanged(_ =>
|
||||||
{
|
{
|
||||||
@ -122,8 +109,9 @@ namespace osu.Game.Overlays.Mods
|
|||||||
GameRuleset = game.Ruleset.GetBoundCopy();
|
GameRuleset = game.Ruleset.GetBoundCopy();
|
||||||
GameRuleset.BindValueChanged(_ => updateValues());
|
GameRuleset.BindValueChanged(_ => updateValues());
|
||||||
|
|
||||||
BeatmapInfo.BindValueChanged(_ => updateValues(), true);
|
BeatmapInfo.BindValueChanged(_ => updateValues());
|
||||||
|
|
||||||
|
updateValues();
|
||||||
updateCollapsedState();
|
updateCollapsedState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,14 +155,14 @@ namespace osu.Game.Overlays.Mods
|
|||||||
});
|
});
|
||||||
|
|
||||||
double rate = 1;
|
double rate = 1;
|
||||||
foreach (var mod in SelectedMods.OfType<IApplicableToRate>())
|
foreach (var mod in Mods.Value.OfType<IApplicableToRate>())
|
||||||
rate = mod.ApplyToRate(0, rate);
|
rate = mod.ApplyToRate(0, rate);
|
||||||
|
|
||||||
bpmDisplay.Current.Value = BeatmapInfo.Value.BPM * rate;
|
bpmDisplay.Current.Value = BeatmapInfo.Value.BPM * rate;
|
||||||
|
|
||||||
BeatmapDifficulty originalDifficulty = new BeatmapDifficulty(BeatmapInfo.Value.Difficulty);
|
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);
|
mod.ApplyToDifficulty(originalDifficulty);
|
||||||
|
|
||||||
Ruleset ruleset = GameRuleset.Value.CreateInstance();
|
Ruleset ruleset = GameRuleset.Value.CreateInstance();
|
||||||
|
@ -114,8 +114,6 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
public IEnumerable<ModState> AllAvailableMods => AvailableMods.Value.SelectMany(pair => pair.Value);
|
public IEnumerable<ModState> AllAvailableMods => AvailableMods.Value.SelectMany(pair => pair.Value);
|
||||||
|
|
||||||
protected virtual IEnumerable<Mod> AllSelectedMods => SelectedMods.Value;
|
|
||||||
|
|
||||||
private readonly BindableBool customisationVisible = new BindableBool();
|
private readonly BindableBool customisationVisible = new BindableBool();
|
||||||
private Bindable<bool> textSearchStartsActive = null!;
|
private Bindable<bool> textSearchStartsActive = null!;
|
||||||
|
|
||||||
@ -319,7 +317,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
SelectedMods.BindValueChanged(_ =>
|
SelectedMods.BindValueChanged(_ =>
|
||||||
{
|
{
|
||||||
updateRankingInformation();
|
UpdateOverlayInformation(SelectedMods.Value);
|
||||||
updateFromExternalSelection();
|
updateFromExternalSelection();
|
||||||
updateCustomisation();
|
updateCustomisation();
|
||||||
|
|
||||||
@ -332,7 +330,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
//
|
//
|
||||||
// See https://github.com/ppy/osu/pull/23284#issuecomment-1529056988
|
// See https://github.com/ppy/osu/pull/23284#issuecomment-1529056988
|
||||||
modSettingChangeTracker = new ModSettingChangeTracker(SelectedMods.Value);
|
modSettingChangeTracker = new ModSettingChangeTracker(SelectedMods.Value);
|
||||||
modSettingChangeTracker.SettingChanged += _ => updateRankingInformation();
|
modSettingChangeTracker.SettingChanged += _ => UpdateOverlayInformation(SelectedMods.Value);
|
||||||
}
|
}
|
||||||
}, true);
|
}, 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);
|
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)
|
if (rankingInformationDisplay != null)
|
||||||
return;
|
{
|
||||||
|
double multiplier = 1.0;
|
||||||
|
|
||||||
double multiplier = 1.0;
|
foreach (var mod in mods)
|
||||||
|
multiplier *= mod.ScoreMultiplier;
|
||||||
|
|
||||||
foreach (var mod in AllSelectedMods)
|
rankingInformationDisplay.ModMultiplier.Value = multiplier;
|
||||||
multiplier *= mod.ScoreMultiplier;
|
rankingInformationDisplay.Ranked.Value = mods.All(m => m.Ranked);
|
||||||
|
}
|
||||||
|
|
||||||
rankingInformationDisplay.ModMultiplier.Value = multiplier;
|
if (beatmapAttributesDisplay != null)
|
||||||
rankingInformationDisplay.Ranked.Value = AllSelectedMods.All(m => m.Ranked);
|
{
|
||||||
|
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()
|
private void updateCustomisation()
|
||||||
|
@ -48,40 +48,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<Mod> AllSelectedMods => roomMods.Concat(base.AllSelectedMods);
|
protected override void UpdateOverlayInformation(IReadOnlyList<Mod> mods)
|
||||||
|
=> base.UpdateOverlayInformation(roomMods.Concat(mods).ToList());
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user