1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 18:23:04 +08:00

Isolate configuration container from analysis overlay

This commit is contained in:
Dean Herbert 2024-09-04 19:28:07 +09:00
parent 9b81deb3ac
commit 6c07b873af
No known key found for this signature in database
5 changed files with 47 additions and 45 deletions

View File

@ -5,14 +5,14 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets.Osu.Beatmaps; using osu.Game.Rulesets.Osu.Configuration;
using osu.Game.Rulesets.Osu.Replays; using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.Osu.UI; using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.UI;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
using osuTK; using osuTK;
@ -21,18 +21,20 @@ namespace osu.Game.Rulesets.Osu.Tests
public partial class TestSceneOsuAnalysisContainer : OsuTestScene public partial class TestSceneOsuAnalysisContainer : OsuTestScene
{ {
private TestReplayAnalysisOverlay analysisContainer = null!; private TestReplayAnalysisOverlay analysisContainer = null!;
private ReplayAnalysisSettings settings = null!;
[Cached]
private OsuRulesetConfigManager config = new OsuRulesetConfigManager(null, new OsuRuleset().RulesetInfo);
[SetUpSteps] [SetUpSteps]
public void SetUpSteps() public void SetUpSteps()
{ {
AddStep("create analysis container", () => AddStep("create analysis container", () =>
{ {
DrawableOsuRuleset drawableRuleset = new DrawableOsuRuleset(new OsuRuleset(), new OsuBeatmap());
Children = new Drawable[] Children = new Drawable[]
{ {
drawableRuleset, analysisContainer = new TestReplayAnalysisOverlay(fabricateReplay()),
analysisContainer = new TestReplayAnalysisOverlay(fabricateReplay(), drawableRuleset), settings = new ReplayAnalysisSettings(config),
}; };
}); });
} }
@ -40,27 +42,27 @@ namespace osu.Game.Rulesets.Osu.Tests
[Test] [Test]
public void TestHitMarkers() public void TestHitMarkers()
{ {
AddStep("enable hit markers", () => analysisContainer.Settings.HitMarkersEnabled.Value = true); AddStep("enable hit markers", () => settings.HitMarkersEnabled.Value = true);
AddAssert("hit markers visible", () => analysisContainer.HitMarkersVisible); AddAssert("hit markers visible", () => analysisContainer.HitMarkersVisible);
AddStep("disable hit markers", () => analysisContainer.Settings.HitMarkersEnabled.Value = false); AddStep("disable hit markers", () => settings.HitMarkersEnabled.Value = false);
AddAssert("hit markers not visible", () => !analysisContainer.HitMarkersVisible); AddAssert("hit markers not visible", () => !analysisContainer.HitMarkersVisible);
} }
[Test] [Test]
public void TestAimMarker() public void TestAimMarker()
{ {
AddStep("enable aim markers", () => analysisContainer.Settings.AimMarkersEnabled.Value = true); AddStep("enable aim markers", () => settings.AimMarkersEnabled.Value = true);
AddAssert("aim markers visible", () => analysisContainer.AimMarkersVisible); AddAssert("aim markers visible", () => analysisContainer.AimMarkersVisible);
AddStep("disable aim markers", () => analysisContainer.Settings.AimMarkersEnabled.Value = false); AddStep("disable aim markers", () => settings.AimMarkersEnabled.Value = false);
AddAssert("aim markers not visible", () => !analysisContainer.AimMarkersVisible); AddAssert("aim markers not visible", () => !analysisContainer.AimMarkersVisible);
} }
[Test] [Test]
public void TestAimLines() public void TestAimLines()
{ {
AddStep("enable aim lines", () => analysisContainer.Settings.AimLinesEnabled.Value = true); AddStep("enable aim lines", () => settings.AimLinesEnabled.Value = true);
AddAssert("aim lines visible", () => analysisContainer.AimLinesVisible); AddAssert("aim lines visible", () => analysisContainer.AimLinesVisible);
AddStep("disable aim lines", () => analysisContainer.Settings.AimLinesEnabled.Value = false); AddStep("disable aim lines", () => settings.AimLinesEnabled.Value = false);
AddAssert("aim lines not visible", () => !analysisContainer.AimLinesVisible); AddAssert("aim lines not visible", () => !analysisContainer.AimLinesVisible);
} }
@ -98,13 +100,11 @@ namespace osu.Game.Rulesets.Osu.Tests
private partial class TestReplayAnalysisOverlay : ReplayAnalysisOverlay private partial class TestReplayAnalysisOverlay : ReplayAnalysisOverlay
{ {
public TestReplayAnalysisOverlay(Replay replay, DrawableRuleset drawableRuleset) public TestReplayAnalysisOverlay(Replay replay)
: base(replay, drawableRuleset) : base(replay)
{ {
} }
public new ReplayAnalysisSettings Settings => base.Settings;
public bool HitMarkersVisible => HitMarkers.Alpha > 0 && HitMarkers.Entries.Any(); public bool HitMarkersVisible => HitMarkers.Alpha > 0 && HitMarkers.Entries.Any();
public bool AimMarkersVisible => AimMarkers.Alpha > 0 && AimMarkers.Entries.Any(); public bool AimMarkersVisible => AimMarkers.Alpha > 0 && AimMarkers.Entries.Any();
public bool AimLinesVisible => AimLines.Alpha > 0 && AimLines.Vertices.Count > 1; public bool AimLinesVisible => AimLines.Alpha > 0 && AimLines.Vertices.Count > 1;

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Configuration;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
@ -11,7 +9,7 @@ namespace osu.Game.Rulesets.Osu.Configuration
{ {
public class OsuRulesetConfigManager : RulesetConfigManager<OsuRulesetSetting> public class OsuRulesetConfigManager : RulesetConfigManager<OsuRulesetSetting>
{ {
public OsuRulesetConfigManager(SettingsStore settings, RulesetInfo ruleset, int? variant = null) public OsuRulesetConfigManager(SettingsStore? settings, RulesetInfo ruleset, int? variant = null)
: base(settings, ruleset, variant) : base(settings, ruleset, variant)
{ {
} }

View File

@ -5,6 +5,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Input.Handlers; using osu.Game.Input.Handlers;
@ -24,7 +26,7 @@ namespace osu.Game.Rulesets.Osu.UI
{ {
public partial class DrawableOsuRuleset : DrawableRuleset<OsuHitObject> public partial class DrawableOsuRuleset : DrawableRuleset<OsuHitObject>
{ {
protected new OsuRulesetConfigManager Config => (OsuRulesetConfigManager)base.Config; private Bindable<bool>? cursorHideEnabled;
public new OsuInputManager KeyBindingInputManager => (OsuInputManager)base.KeyBindingInputManager; public new OsuInputManager KeyBindingInputManager => (OsuInputManager)base.KeyBindingInputManager;
@ -39,7 +41,13 @@ namespace osu.Game.Rulesets.Osu.UI
private void load(ReplayPlayer? replayPlayer) private void load(ReplayPlayer? replayPlayer)
{ {
if (replayPlayer != null) if (replayPlayer != null)
PlayfieldAdjustmentContainer.Add(new ReplayAnalysisOverlay(replayPlayer.Score.Replay, this)); {
PlayfieldAdjustmentContainer.Add(new ReplayAnalysisOverlay(replayPlayer.Score.Replay));
replayPlayer.AddSettings(new ReplayAnalysisSettings((OsuRulesetConfigManager)Config));
cursorHideEnabled = ((OsuRulesetConfigManager)Config).GetBindable<bool>(OsuRulesetSetting.ReplayCursorHideEnabled);
cursorHideEnabled.BindValueChanged(enabled => Playfield.Cursor.FadeTo(enabled.NewValue ? 0 : 1), true);
}
} }
public override DrawableHitObject<OsuHitObject>? CreateDrawableRepresentation(OsuHitObject h) => null; public override DrawableHitObject<OsuHitObject>? CreateDrawableRepresentation(OsuHitObject h) => null;

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Lines; using osu.Framework.Graphics.Lines;
@ -11,10 +12,9 @@ using osu.Framework.Graphics.Performance;
using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Pooling;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets.Objects.Pooling; using osu.Game.Rulesets.Objects.Pooling;
using osu.Game.Rulesets.Osu.Configuration;
using osu.Game.Rulesets.Osu.Replays; using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.Osu.Skinning.Default; using osu.Game.Rulesets.Osu.Skinning.Default;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -22,19 +22,19 @@ namespace osu.Game.Rulesets.Osu.UI
{ {
public partial class ReplayAnalysisOverlay : CompositeDrawable public partial class ReplayAnalysisOverlay : CompositeDrawable
{ {
private BindableBool hitMarkersEnabled { get; } = new BindableBool();
private BindableBool aimMarkersEnabled { get; } = new BindableBool();
private BindableBool aimLinesEnabled { get; } = new BindableBool();
protected readonly HitMarkersContainer HitMarkers; protected readonly HitMarkersContainer HitMarkers;
protected readonly AimMarkersContainer AimMarkers; protected readonly AimMarkersContainer AimMarkers;
protected readonly AimLinesContainer AimLines; protected readonly AimLinesContainer AimLines;
protected ReplayAnalysisSettings Settings = null!;
private readonly Replay replay; private readonly Replay replay;
private readonly DrawableRuleset drawableRuleset;
public ReplayAnalysisOverlay(Replay replay, DrawableRuleset drawableRuleset) public ReplayAnalysisOverlay(Replay replay)
{ {
this.replay = replay; this.replay = replay;
this.drawableRuleset = drawableRuleset;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
@ -45,27 +45,22 @@ namespace osu.Game.Rulesets.Osu.UI
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(ReplayPlayer? replayPlayer) private void load(OsuRulesetConfigManager config)
{ {
Settings = new ReplayAnalysisSettings();
if (replayPlayer != null)
replayPlayer.AddSettings(Settings);
else
// only in test
AddInternal(Settings);
loadReplay(); loadReplay();
config.BindWith(OsuRulesetSetting.ReplayHitMarkersEnabled, hitMarkersEnabled);
config.BindWith(OsuRulesetSetting.ReplayAimMarkersEnabled, aimMarkersEnabled);
config.BindWith(OsuRulesetSetting.ReplayAimLinesEnabled, aimLinesEnabled);
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Settings.HitMarkersEnabled.BindValueChanged(enabled => HitMarkers.FadeTo(enabled.NewValue ? 1 : 0), true); hitMarkersEnabled.BindValueChanged(enabled => HitMarkers.FadeTo(enabled.NewValue ? 1 : 0), true);
Settings.AimMarkersEnabled.BindValueChanged(enabled => AimMarkers.FadeTo(enabled.NewValue ? 1 : 0), true); aimMarkersEnabled.BindValueChanged(enabled => AimMarkers.FadeTo(enabled.NewValue ? 1 : 0), true);
Settings.AimLinesEnabled.BindValueChanged(enabled => AimLines.FadeTo(enabled.NewValue ? 1 : 0), true); aimLinesEnabled.BindValueChanged(enabled => AimLines.FadeTo(enabled.NewValue ? 1 : 0), true);
Settings.CursorHideEnabled.BindValueChanged(enabled => drawableRuleset.Playfield.Cursor.FadeTo(enabled.NewValue ? 0 : 1), true);
} }
private void loadReplay() private void loadReplay()

View File

@ -11,6 +11,8 @@ namespace osu.Game.Rulesets.Osu.UI
{ {
public partial class ReplayAnalysisSettings : PlayerSettingsGroup public partial class ReplayAnalysisSettings : PlayerSettingsGroup
{ {
private readonly OsuRulesetConfigManager config;
[SettingSource("Hit markers", SettingControlType = typeof(PlayerCheckbox))] [SettingSource("Hit markers", SettingControlType = typeof(PlayerCheckbox))]
public BindableBool HitMarkersEnabled { get; } = new BindableBool(); public BindableBool HitMarkersEnabled { get; } = new BindableBool();
@ -23,18 +25,17 @@ namespace osu.Game.Rulesets.Osu.UI
[SettingSource("Hide cursor", SettingControlType = typeof(PlayerCheckbox))] [SettingSource("Hide cursor", SettingControlType = typeof(PlayerCheckbox))]
public BindableBool CursorHideEnabled { get; } = new BindableBool(); public BindableBool CursorHideEnabled { get; } = new BindableBool();
public ReplayAnalysisSettings() public ReplayAnalysisSettings(OsuRulesetConfigManager config)
: base("Analysis Settings") : base("Analysis Settings")
{ {
this.config = config;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(IRulesetConfigCache cache) private void load()
{ {
AddRange(this.CreateSettingsControls()); AddRange(this.CreateSettingsControls());
var config = (OsuRulesetConfigManager)cache.GetConfigFor(new OsuRuleset())!;
config.BindWith(OsuRulesetSetting.ReplayHitMarkersEnabled, HitMarkersEnabled); config.BindWith(OsuRulesetSetting.ReplayHitMarkersEnabled, HitMarkersEnabled);
config.BindWith(OsuRulesetSetting.ReplayAimMarkersEnabled, AimMarkersEnabled); config.BindWith(OsuRulesetSetting.ReplayAimMarkersEnabled, AimMarkersEnabled);
config.BindWith(OsuRulesetSetting.ReplayAimLinesEnabled, AimLinesEnabled); config.BindWith(OsuRulesetSetting.ReplayAimLinesEnabled, AimLinesEnabled);