mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 04:42:55 +08:00
Packed changes into separate class
This commit is contained in:
parent
ed819fde15
commit
2df5787dc7
@ -46,10 +46,7 @@ namespace osu.Game.Overlays.Mods
|
||||
public bool AccountForMultiplayerMods = false;
|
||||
|
||||
[Resolved]
|
||||
private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IBindable<PlaylistItem>? multiplayerRoomItem { get; set; }
|
||||
protected Bindable<IReadOnlyList<Mod>> Mods { get; private set; } = null!;
|
||||
|
||||
public BindableBool Collapsed { get; } = new BindableBool(true);
|
||||
|
||||
@ -61,7 +58,7 @@ namespace osu.Game.Overlays.Mods
|
||||
[Resolved]
|
||||
private OsuGameBase game { get; set; } = null!;
|
||||
|
||||
private IBindable<RulesetInfo> gameRuleset = null!;
|
||||
protected IBindable<RulesetInfo> GameRuleset = null!;
|
||||
|
||||
private CancellationTokenSource? cancellationSource;
|
||||
private IBindable<StarDifficulty?> starDifficulty = null!;
|
||||
@ -109,16 +106,14 @@ namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
mods.BindValueChanged(_ =>
|
||||
Mods.BindValueChanged(_ =>
|
||||
{
|
||||
modSettingChangeTracker?.Dispose();
|
||||
modSettingChangeTracker = new ModSettingChangeTracker(mods.Value);
|
||||
modSettingChangeTracker = new ModSettingChangeTracker(Mods.Value);
|
||||
modSettingChangeTracker.SettingChanged += _ => updateValues();
|
||||
updateValues();
|
||||
}, true);
|
||||
|
||||
multiplayerRoomItem?.BindValueChanged(_ => mods.TriggerChange());
|
||||
|
||||
BeatmapInfo.BindValueChanged(_ => updateValues(), true);
|
||||
|
||||
Collapsed.BindValueChanged(_ =>
|
||||
@ -128,8 +123,8 @@ namespace osu.Game.Overlays.Mods
|
||||
updateCollapsedState();
|
||||
});
|
||||
|
||||
gameRuleset = game.Ruleset.GetBoundCopy();
|
||||
gameRuleset.BindValueChanged(_ => updateValues());
|
||||
GameRuleset = game.Ruleset.GetBoundCopy();
|
||||
GameRuleset.BindValueChanged(_ => updateValues());
|
||||
|
||||
BeatmapInfo.BindValueChanged(_ => updateValues(), true);
|
||||
|
||||
@ -159,6 +154,23 @@ namespace osu.Game.Overlays.Mods
|
||||
LeftContent.AutoSizeDuration = Content.AutoSizeDuration = transition_duration;
|
||||
}
|
||||
|
||||
protected virtual double GetRate()
|
||||
{
|
||||
double rate = 1;
|
||||
foreach (var mod in Mods.Value.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
return rate;
|
||||
}
|
||||
|
||||
protected virtual BeatmapDifficulty GetDifficulty()
|
||||
{
|
||||
BeatmapDifficulty originalDifficulty = new BeatmapDifficulty(BeatmapInfo.Value!.Difficulty);
|
||||
|
||||
foreach (var mod in Mods.Value.OfType<IApplicableToDifficulty>())
|
||||
mod.ApplyToDifficulty(originalDifficulty);
|
||||
|
||||
return originalDifficulty;
|
||||
}
|
||||
private void updateValues() => Scheduler.AddOnce(() =>
|
||||
{
|
||||
if (BeatmapInfo.Value == null)
|
||||
@ -175,28 +187,10 @@ namespace osu.Game.Overlays.Mods
|
||||
starRatingDisplay.FinishTransforms(true);
|
||||
});
|
||||
|
||||
Ruleset ruleset = gameRuleset.Value.CreateInstance();
|
||||
|
||||
double rate = 1;
|
||||
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
|
||||
BeatmapDifficulty originalDifficulty = new BeatmapDifficulty(BeatmapInfo.Value.Difficulty);
|
||||
|
||||
foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
|
||||
mod.ApplyToDifficulty(originalDifficulty);
|
||||
|
||||
if (AccountForMultiplayerMods && multiplayerRoomItem != null && multiplayerRoomItem.Value != null)
|
||||
{
|
||||
var multiplayerRoomMods = multiplayerRoomItem.Value.RequiredMods.Select(m => m.ToMod(ruleset));
|
||||
|
||||
foreach (var mod in multiplayerRoomMods.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
|
||||
foreach (var mod in multiplayerRoomMods.OfType<IApplicableToDifficulty>())
|
||||
mod.ApplyToDifficulty(originalDifficulty);
|
||||
}
|
||||
double rate = GetRate();
|
||||
BeatmapDifficulty originalDifficulty = GetDifficulty();
|
||||
|
||||
Ruleset ruleset = GameRuleset.Value.CreateInstance();
|
||||
BeatmapDifficulty adjustedDifficulty = ruleset.GetRateAdjustedDisplayDifficulty(originalDifficulty, rate);
|
||||
|
||||
bpmDisplay.Current.Value = BeatmapInfo.Value.BPM * rate;
|
||||
|
@ -25,9 +25,7 @@ using osu.Game.Graphics.Cursor;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
@ -44,11 +42,6 @@ namespace osu.Game.Overlays.Mods
|
||||
[Cached]
|
||||
public Bindable<IReadOnlyList<Mod>> SelectedMods { get; private set; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IBindable<PlaylistItem>? multiplayerRoomItem { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuGameBase game { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Contains a dictionary with the current <see cref="ModState"/> of all mods applicable for the current ruleset.
|
||||
@ -100,11 +93,6 @@ namespace osu.Game.Overlays.Mods
|
||||
/// </summary>
|
||||
protected virtual bool ShowPresets => false;
|
||||
|
||||
/// <summary>
|
||||
/// Should overlay account for the multiplayer room global mods.
|
||||
/// </summary>
|
||||
public bool AccountForMultiplayerMods = false;
|
||||
|
||||
protected virtual ModColumn CreateModColumn(ModType modType) => new ModColumn(modType, false);
|
||||
|
||||
protected virtual IReadOnlyList<Mod> ComputeNewModsFromSelection(IReadOnlyList<Mod> oldSelection, IReadOnlyList<Mod> newSelection) => newSelection;
|
||||
@ -138,8 +126,14 @@ namespace osu.Game.Overlays.Mods
|
||||
private DeselectAllModsButton deselectAllModsButton = null!;
|
||||
|
||||
private Container aboveColumnsContent = null!;
|
||||
private RankingInformationDisplay? rankingInformationDisplay;
|
||||
private BeatmapAttributesDisplay? beatmapAttributesDisplay;
|
||||
protected RankingInformationDisplay? RankingInformationDisplay;
|
||||
protected BeatmapAttributesDisplay? BeatmapAttributesDisplay;
|
||||
protected virtual BeatmapAttributesDisplay GetBeatmapAttributesDisplay => new BeatmapAttributesDisplay
|
||||
{
|
||||
Anchor = Anchor.BottomRight,
|
||||
Origin = Anchor.BottomRight,
|
||||
BeatmapInfo = { Value = Beatmap?.BeatmapInfo }
|
||||
};
|
||||
|
||||
protected ShearedButton BackButton { get; private set; } = null!;
|
||||
protected ShearedToggleButton? CustomisationButton { get; private set; }
|
||||
@ -159,8 +153,8 @@ namespace osu.Game.Overlays.Mods
|
||||
if (beatmap == value) return;
|
||||
|
||||
beatmap = value;
|
||||
if (IsLoaded && beatmapAttributesDisplay != null)
|
||||
beatmapAttributesDisplay.BeatmapInfo.Value = beatmap?.BeatmapInfo;
|
||||
if (IsLoaded && BeatmapAttributesDisplay != null)
|
||||
BeatmapAttributesDisplay.BeatmapInfo.Value = beatmap?.BeatmapInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,18 +276,12 @@ namespace osu.Game.Overlays.Mods
|
||||
},
|
||||
Children = new Drawable[]
|
||||
{
|
||||
rankingInformationDisplay = new RankingInformationDisplay
|
||||
RankingInformationDisplay = new RankingInformationDisplay
|
||||
{
|
||||
Anchor = Anchor.BottomRight,
|
||||
Origin = Anchor.BottomRight
|
||||
},
|
||||
beatmapAttributesDisplay = new BeatmapAttributesDisplay
|
||||
{
|
||||
Anchor = Anchor.BottomRight,
|
||||
Origin = Anchor.BottomRight,
|
||||
BeatmapInfo = { Value = beatmap?.BeatmapInfo },
|
||||
AccountForMultiplayerMods = AccountForMultiplayerMods
|
||||
},
|
||||
BeatmapAttributesDisplay = GetBeatmapAttributesDisplay
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -329,7 +317,7 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
SelectedMods.BindValueChanged(_ =>
|
||||
{
|
||||
updateRankingInformation();
|
||||
UpdateRankingInformation();
|
||||
updateFromExternalSelection();
|
||||
updateCustomisation();
|
||||
|
||||
@ -342,12 +330,10 @@ 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 += _ => UpdateRankingInformation();
|
||||
}
|
||||
}, true);
|
||||
|
||||
multiplayerRoomItem?.BindValueChanged(_ => SelectedMods.TriggerChange());
|
||||
|
||||
customisationVisible.BindValueChanged(_ => updateCustomisationVisualState(), true);
|
||||
|
||||
SearchTextBox.Current.BindValueChanged(query =>
|
||||
@ -371,7 +357,7 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
SearchTextBox.PlaceholderText = SearchTextBox.HasFocus ? Resources.Localisation.Web.CommonStrings.InputSearch : ModSelectOverlayStrings.TabToSearch;
|
||||
|
||||
if (beatmapAttributesDisplay != null)
|
||||
if (BeatmapAttributesDisplay != null)
|
||||
{
|
||||
float rightEdgeOfLastButton = footerButtonFlow.Last().ScreenSpaceDrawQuad.TopRight.X;
|
||||
|
||||
@ -383,7 +369,7 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
// only update preview panel's collapsed state after we are fully visible, to ensure all the buttons are where we expect them to be.
|
||||
if (Alpha == 1)
|
||||
beatmapAttributesDisplay.Collapsed.Value = screenIsntWideEnough;
|
||||
BeatmapAttributesDisplay.Collapsed.Value = screenIsntWideEnough;
|
||||
|
||||
footerContentFlow.LayoutDuration = 200;
|
||||
footerContentFlow.LayoutEasing = Easing.OutQuint;
|
||||
@ -466,9 +452,9 @@ namespace osu.Game.Overlays.Mods
|
||||
modState.ValidForSelection.Value = modState.Mod.Type != ModType.System && modState.Mod.HasImplementation && IsValidMod.Invoke(modState.Mod);
|
||||
}
|
||||
|
||||
private void updateRankingInformation()
|
||||
protected virtual void UpdateRankingInformation()
|
||||
{
|
||||
if (rankingInformationDisplay == null)
|
||||
if (RankingInformationDisplay == null)
|
||||
return;
|
||||
|
||||
double multiplier = 1.0;
|
||||
@ -476,20 +462,8 @@ namespace osu.Game.Overlays.Mods
|
||||
foreach (var mod in SelectedMods.Value)
|
||||
multiplier *= mod.ScoreMultiplier;
|
||||
|
||||
rankingInformationDisplay.Ranked.Value = SelectedMods.Value.All(m => m.Ranked);
|
||||
|
||||
if (AccountForMultiplayerMods && multiplayerRoomItem != null && multiplayerRoomItem.Value != null)
|
||||
{
|
||||
Ruleset ruleset = game.Ruleset.Value.CreateInstance();
|
||||
var multiplayerRoomMods = multiplayerRoomItem.Value.RequiredMods.Select(m => m.ToMod(ruleset));
|
||||
|
||||
foreach (var mod in multiplayerRoomMods)
|
||||
multiplier *= mod.ScoreMultiplier;
|
||||
|
||||
rankingInformationDisplay.Ranked.Value = rankingInformationDisplay.Ranked.Value && multiplayerRoomMods.All(m => m.Ranked);
|
||||
}
|
||||
|
||||
rankingInformationDisplay.ModMultiplier.Value = multiplier;
|
||||
RankingInformationDisplay.Ranked.Value = SelectedMods.Value.All(m => m.Ranked);
|
||||
RankingInformationDisplay.ModMultiplier.Value = multiplier;
|
||||
}
|
||||
|
||||
private void updateCustomisation()
|
||||
|
118
osu.Game/Overlays/Mods/MultiplayerModSelectOverlay.cs
Normal file
118
osu.Game/Overlays/Mods/MultiplayerModSelectOverlay.cs
Normal file
@ -0,0 +1,118 @@
|
||||
// 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.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
public partial class MultiplayerModSelectOverlay : UserModSelectOverlay
|
||||
{
|
||||
public MultiplayerModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourScheme.Plum)
|
||||
: base(colourScheme)
|
||||
{
|
||||
}
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IBindable<PlaylistItem>? multiplayerRoomItem { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuGameBase game { get; set; } = null!;
|
||||
|
||||
protected override BeatmapAttributesDisplay GetBeatmapAttributesDisplay => new MultiplayerBeatmapAttributesDisplay
|
||||
{
|
||||
Anchor = Anchor.BottomRight,
|
||||
Origin = Anchor.BottomRight,
|
||||
BeatmapInfo = { Value = Beatmap?.BeatmapInfo },
|
||||
AccountForMultiplayerMods = true
|
||||
};
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
multiplayerRoomItem?.BindValueChanged(_ => SelectedMods.TriggerChange());
|
||||
}
|
||||
|
||||
protected override void UpdateRankingInformation()
|
||||
{
|
||||
if (RankingInformationDisplay == null)
|
||||
return;
|
||||
|
||||
double multiplier = 1.0;
|
||||
|
||||
foreach (var mod in SelectedMods.Value)
|
||||
multiplier *= mod.ScoreMultiplier;
|
||||
|
||||
RankingInformationDisplay.Ranked.Value = SelectedMods.Value.All(m => m.Ranked);
|
||||
|
||||
if (multiplayerRoomItem != null && multiplayerRoomItem.Value != null)
|
||||
{
|
||||
Ruleset ruleset = game.Ruleset.Value.CreateInstance();
|
||||
var multiplayerRoomMods = multiplayerRoomItem.Value.RequiredMods.Select(m => m.ToMod(ruleset));
|
||||
|
||||
foreach (var mod in multiplayerRoomMods)
|
||||
multiplier *= mod.ScoreMultiplier;
|
||||
|
||||
RankingInformationDisplay.Ranked.Value = RankingInformationDisplay.Ranked.Value && multiplayerRoomMods.All(m => m.Ranked);
|
||||
}
|
||||
|
||||
RankingInformationDisplay.ModMultiplier.Value = multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class MultiplayerBeatmapAttributesDisplay : BeatmapAttributesDisplay
|
||||
{
|
||||
public MultiplayerBeatmapAttributesDisplay()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IBindable<PlaylistItem>? multiplayerRoomItem { get; set; }
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
multiplayerRoomItem?.BindValueChanged(_ => Mods.TriggerChange());
|
||||
}
|
||||
|
||||
protected override double GetRate()
|
||||
{
|
||||
double rate = base.GetRate();
|
||||
Ruleset ruleset = GameRuleset.Value.CreateInstance();
|
||||
|
||||
if (AccountForMultiplayerMods && multiplayerRoomItem != null && multiplayerRoomItem.Value != null)
|
||||
{
|
||||
var multiplayerRoomMods = multiplayerRoomItem.Value.RequiredMods.Select(m => m.ToMod(ruleset));
|
||||
|
||||
foreach (var mod in multiplayerRoomMods.OfType<IApplicableToRate>())
|
||||
rate = mod.ApplyToRate(0, rate);
|
||||
}
|
||||
|
||||
return rate;
|
||||
}
|
||||
|
||||
protected override BeatmapDifficulty GetDifficulty()
|
||||
{
|
||||
BeatmapDifficulty originalDifficulty = base.GetDifficulty();
|
||||
Ruleset ruleset = GameRuleset.Value.CreateInstance();
|
||||
|
||||
if (multiplayerRoomItem != null && multiplayerRoomItem.Value != null)
|
||||
{
|
||||
var multiplayerRoomMods = multiplayerRoomItem.Value.RequiredMods.Select(m => m.ToMod(ruleset));
|
||||
|
||||
foreach (var mod in multiplayerRoomMods.OfType<IApplicableToDifficulty>())
|
||||
mod.ApplyToDifficulty(originalDifficulty);
|
||||
}
|
||||
|
||||
return originalDifficulty;
|
||||
}
|
||||
}
|
||||
}
|
@ -241,11 +241,10 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
}
|
||||
};
|
||||
|
||||
LoadComponent(UserModsSelectOverlay = new UserModSelectOverlay(OverlayColourScheme.Plum)
|
||||
LoadComponent(UserModsSelectOverlay = new MultiplayerModSelectOverlay()
|
||||
{
|
||||
SelectedMods = { BindTarget = UserMods },
|
||||
IsValidMod = _ => false,
|
||||
AccountForMultiplayerMods = true
|
||||
IsValidMod = _ => false
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user