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

load analysis settings synchronously

specifically in multiplayer spectating
This commit is contained in:
Sheppsu 2024-09-06 06:46:12 -04:00
parent b223f5ea74
commit f2c98dd064
2 changed files with 20 additions and 16 deletions

View File

@ -52,6 +52,8 @@ namespace osu.Game.Rulesets.Osu.UI
if (multiSpectatorScreen == null)
player.AddSettings(new ReplayAnalysisSettings(Config));
else if (!multiSpectatorScreen.SettingsAdded)
multiSpectatorScreen.AddSettings(() => new ReplayAnalysisSettings(Config));
cursorHideEnabled = Config.GetBindable<bool>(OsuRulesetSetting.ReplayCursorHideEnabled);
@ -61,14 +63,6 @@ namespace osu.Game.Rulesets.Osu.UI
}
}
protected override void LoadComplete()
{
base.LoadComplete();
if (multiSpectatorScreen != null && !multiSpectatorScreen.SettingsAdded)
multiSpectatorScreen.AddSettingsAsync(new ReplayAnalysisSettings(Config));
}
public override DrawableHitObject<OsuHitObject>? CreateDrawableRepresentation(OsuHitObject h) => null;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true; // always show the gameplay cursor

View File

@ -41,7 +41,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// </summary>
public bool AllPlayersLoaded => instances.All(p => p.PlayerLoaded);
public bool SettingsAdded { get; private set; } = false;
public bool SettingsAdded { get; private set; }
private readonly object settingsAddedLock = new object();
protected override UserActivity InitialActivity => new UserActivity.SpectatingMultiplayerGame(Beatmap.Value.BeatmapInfo, Ruleset.Value);
@ -81,15 +82,24 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// <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="settings">The settings group to be shown.</param>
public void AddSettingsAsync(PlayerSettingsGroup settings)
/// <param name="createSettings">A function that returns the settings group to be shown.</param>
public void AddSettings(Func<PlayerSettingsGroup> createSettings)
{
SettingsAdded = true;
LoadComponentAsync(settings, (loadedSettings) =>
// 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)
{
loadedSettings.Expanded.Value = false;
leaderboardFlow.Insert(2, loadedSettings);
if (SettingsAdded)
return;
SettingsAdded = true;
}
Schedule(() =>
{
var settings = createSettings();
settings.Expanded.Value = false;
leaderboardFlow.Insert(2, settings);
});
}