1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 10:33:22 +08:00

move replay analysis settings creation point

replay analysis settings is created in the respective drawable that's adding it, instead of adding it from `DrawableRuleset`
for this, it adds a virtual method in Ruleset that uses a non-ruleset-specific `ReplayAnalysisSettings` (the osu specific one was renamed to `OsuReplayAnalysisSettings`).
This commit is contained in:
Sheppsu 2024-09-21 02:02:55 -04:00
parent 70a502771b
commit 26f1596150
10 changed files with 107 additions and 62 deletions

View File

@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Osu.Tests
public partial class TestSceneOsuAnalysisContainer : OsuTestScene
{
private TestReplayAnalysisOverlay analysisContainer = null!;
private ReplayAnalysisSettings settings = null!;
private OsuReplayAnalysisSettings settings = null!;
[Cached]
private OsuRulesetConfigManager config = new OsuRulesetConfigManager(null, new OsuRuleset().RulesetInfo);
@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Osu.Tests
{
Child = analysisContainer = new TestReplayAnalysisOverlay(fabricateReplay()),
},
settings = new ReplayAnalysisSettings(config),
settings = new TestOsuReplayAnalysisSettings(Ruleset.Value.CreateInstance(), config),
};
settings.ShowClickMarkers.Value = false;
@ -129,5 +129,26 @@ namespace osu.Game.Rulesets.Osu.Tests
public bool AimMarkersVisible => FrameMarkers?.Alpha > 0 && FrameMarkers.Entries.Any();
public bool AimLinesVisible => CursorPath?.Alpha > 0 && CursorPath.Vertices.Count > 1;
}
private partial class TestOsuReplayAnalysisSettings : OsuReplayAnalysisSettings
{
private readonly OsuRulesetConfigManager config;
public TestOsuReplayAnalysisSettings(Ruleset ruleset, OsuRulesetConfigManager config)
: base(ruleset)
{
this.config = config;
}
[BackgroundDependencyLoader]
private void load()
{
config.BindWith(OsuRulesetSetting.ReplayClickMarkersEnabled, ShowClickMarkers);
config.BindWith(OsuRulesetSetting.ReplayFrameMarkersEnabled, ShowAimMarkers);
config.BindWith(OsuRulesetSetting.ReplayCursorPathEnabled, ShowCursorPath);
config.BindWith(OsuRulesetSetting.ReplayCursorHideEnabled, HideSkinCursor);
config.BindWith(OsuRulesetSetting.ReplayAnalysisDisplayLength, DisplayLength);
}
}
}
}

View File

@ -361,5 +361,12 @@ namespace osu.Game.Rulesets.Osu
}
public override bool EditorShowScrollSpeed => false;
public override ReplayAnalysisSettings CreateReplayAnalysisSettings()
{
var settings = new OsuReplayAnalysisSettings(this);
settings.Expanded.Value = false;
return settings;
}
}
}

View File

@ -19,7 +19,6 @@ using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
using osu.Game.Screens.Play;
using osuTK;
@ -41,18 +40,12 @@ namespace osu.Game.Rulesets.Osu.UI
}
[BackgroundDependencyLoader]
private void load(Player? player, MultiSpectatorScreen? multiSpectatorScreen)
private void load(Player? player)
{
if (player is ReplayPlayer || player is SpectatorPlayer)
{
PlayfieldAdjustmentContainer.Add(new ReplayAnalysisOverlay(player.Score.Replay));
// if in multiplayer spectator mode, place the settings elsewhere
if (multiSpectatorScreen == null)
player.AddSettings(new ReplayAnalysisSettings(Config));
else if (!multiSpectatorScreen.SettingsAdded)
multiSpectatorScreen.AddSettings(() => new ReplayAnalysisSettings(Config));
cursorHideEnabled = Config.GetBindable<bool>(OsuRulesetSetting.ReplayCursorHideEnabled);
// I have little faith in this working (other things touch cursor visibility) but haven't broken it yet.

View File

@ -5,13 +5,14 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Configuration;
using osu.Game.Rulesets.Osu.Configuration;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play.PlayerSettings;
namespace osu.Game.Rulesets.Osu.UI
{
public partial class ReplayAnalysisSettings : PlayerSettingsGroup
public partial class OsuReplayAnalysisSettings : ReplayAnalysisSettings
{
private readonly OsuRulesetConfigManager config;
protected new OsuRulesetConfigManager Config => (OsuRulesetConfigManager)base.Config;
[SettingSource("Show click markers", SettingControlType = typeof(PlayerCheckbox))]
public BindableBool ShowClickMarkers { get; } = new BindableBool();
@ -34,22 +35,19 @@ namespace osu.Game.Rulesets.Osu.UI
Precision = 200,
};
public ReplayAnalysisSettings(OsuRulesetConfigManager config)
: base("Analysis Settings")
public OsuReplayAnalysisSettings(Ruleset ruleset)
: base(ruleset)
{
this.config = config;
}
[BackgroundDependencyLoader]
private void load()
{
AddRange(this.CreateSettingsControls());
config.BindWith(OsuRulesetSetting.ReplayClickMarkersEnabled, ShowClickMarkers);
config.BindWith(OsuRulesetSetting.ReplayFrameMarkersEnabled, ShowAimMarkers);
config.BindWith(OsuRulesetSetting.ReplayCursorPathEnabled, ShowCursorPath);
config.BindWith(OsuRulesetSetting.ReplayCursorHideEnabled, HideSkinCursor);
config.BindWith(OsuRulesetSetting.ReplayAnalysisDisplayLength, DisplayLength);
Config.BindWith(OsuRulesetSetting.ReplayClickMarkersEnabled, ShowClickMarkers);
Config.BindWith(OsuRulesetSetting.ReplayFrameMarkersEnabled, ShowAimMarkers);
Config.BindWith(OsuRulesetSetting.ReplayCursorPathEnabled, ShowCursorPath);
Config.BindWith(OsuRulesetSetting.ReplayCursorHideEnabled, HideSkinCursor);
Config.BindWith(OsuRulesetSetting.ReplayAnalysisDisplayLength, DisplayLength);
}
}
}

View File

@ -406,5 +406,11 @@ namespace osu.Game.Rulesets
/// Can be overridden to avoid showing scroll speed changes in the editor.
/// </summary>
public virtual bool EditorShowScrollSpeed => true;
/// <summary>
/// Creates a ruleset-specific replay analysis settings drawable
/// </summary>
/// <returns>The replay analysis settings drawable</returns>
public virtual ReplayAnalysisSettings? CreateReplayAnalysisSettings() => null;
}
}

View File

@ -0,0 +1,42 @@
// 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.
#nullable disable
using osu.Framework.Allocation;
using osu.Game.Configuration;
using osu.Game.Rulesets.Configuration;
using osu.Game.Screens.Play.PlayerSettings;
namespace osu.Game.Rulesets.UI
{
public partial class ReplayAnalysisSettings : PlayerSettingsGroup
{
private readonly Ruleset ruleset;
protected IRulesetConfigManager Config;
public ReplayAnalysisSettings(Ruleset ruleset)
: base("Analysis Settings")
{
this.ruleset = ruleset;
}
[BackgroundDependencyLoader]
private void load()
{
AddRange(this.CreateSettingsControls());
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
Config = dependencies.Get<IRulesetConfigCache>().GetConfigFor(ruleset);
if (Config is not null)
dependencies.Cache(Config);
return dependencies;
}
}
}

View File

@ -15,7 +15,6 @@ using osu.Game.Online.Rooms;
using osu.Game.Online.Spectator;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Screens.Spectate;
using osu.Game.Users;
using osuTK;
@ -25,7 +24,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// <summary>
/// A <see cref="SpectatorScreen"/> that spectates multiple users in a match.
/// </summary>
[Cached]
public partial class MultiSpectatorScreen : SpectatorScreen
{
// Isolates beatmap/ruleset to this screen.
@ -41,9 +39,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// </summary>
public bool AllPlayersLoaded => instances.All(p => p.PlayerLoaded);
public bool SettingsAdded { get; private set; }
private readonly object settingsAddedLock = new object();
protected override UserActivity InitialActivity => new UserActivity.SpectatingMultiplayerGame(Beatmap.Value.BeatmapInfo, Ruleset.Value);
[Resolved]
@ -79,30 +74,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
instances = new PlayerArea[Users.Count];
}
/// <summary>
/// Add a settings group to the bottom of the side container. Intended to be used by rulesets to add spectate-specific settings.
/// </summary>
/// <param name="createSettings">A function that returns the settings group to be shown.</param>
public void AddSettings(Func<PlayerSettingsGroup> createSettings)
{
// This function may be called by multiple drawable rulesets loading at the same time
// Without the lock, duplicate setting containers may be added
lock (settingsAddedLock)
{
if (SettingsAdded)
return;
SettingsAdded = true;
}
Schedule(() =>
{
var settings = createSettings();
settings.Expanded.Value = false;
leaderboardFlow.Insert(2, settings);
});
}
[BackgroundDependencyLoader]
private void load()
{
@ -185,6 +156,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
{
Expanded = { Value = true },
}, chat => leaderboardFlow.Insert(1, chat));
var replayAnalysisSettings = Ruleset.Value.CreateInstance().CreateReplayAnalysisSettings();
if (replayAnalysisSettings is not null)
leaderboardFlow.Insert(2, replayAnalysisSettings);
}
protected override void LoadComplete()

View File

@ -36,7 +36,6 @@ using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Scoring;
using osu.Game.Scoring.Legacy;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Screens.Ranking;
using osu.Game.Skinning;
using osu.Game.Users;
@ -172,16 +171,6 @@ namespace osu.Game.Screens.Play
Configuration = configuration ?? new PlayerConfiguration();
}
/// <summary>
/// Add a settings group to the HUD overlay. Intended to be used by rulesets to add replay/spectate-specific settings.
/// </summary>
/// <param name="settings">The settings group to be shown.</param>
public void AddSettings(PlayerSettingsGroup settings) => Schedule(() =>
{
settings.Expanded.Value = false;
HUDOverlay.PlayerSettingsOverlay.Add(settings);
});
private ScreenSuspensionHandler screenSuspension;
private DependencyContainer dependencies;
@ -1291,5 +1280,15 @@ namespace osu.Game.Screens.Play
IBindable<bool> ISamplePlaybackDisabler.SamplePlaybackDisabled => samplePlaybackDisabled;
IBindable<bool> ILocalUserPlayInfo.IsPlaying => LocalUserPlaying;
/// <summary>
/// Create and add <see cref="ReplayAnalysisSettings"/> to settings overlay.
/// </summary>
protected void AddReplayAnalysisSettings()
{
var replayAnalysisSettings = DrawableRuleset.Ruleset.CreateReplayAnalysisSettings();
if (replayAnalysisSettings is not null)
HUDOverlay.PlayerSettingsOverlay.Add(replayAnalysisSettings);
}
}
}

View File

@ -71,6 +71,8 @@ namespace osu.Game.Screens.Play
playbackSettings.UserPlaybackRate.BindTo(master.UserPlaybackRate);
HUDOverlay.PlayerSettingsOverlay.AddAtStart(playbackSettings);
AddReplayAnalysisSettings();
}
protected override void PrepareReplay()

View File

@ -50,6 +50,8 @@ namespace osu.Game.Screens.Play
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
});
AddReplayAnalysisSettings();
}
protected override void LoadComplete()