mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 11:42:54 +08:00
Isolate configuration container from analysis overlay
This commit is contained in:
parent
9b81deb3ac
commit
6c07b873af
@ -5,14 +5,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Testing;
|
||||
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.UI;
|
||||
using osu.Game.Rulesets.Replays;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Tests.Visual;
|
||||
using osuTK;
|
||||
|
||||
@ -21,18 +21,20 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
public partial class TestSceneOsuAnalysisContainer : OsuTestScene
|
||||
{
|
||||
private TestReplayAnalysisOverlay analysisContainer = null!;
|
||||
private ReplayAnalysisSettings settings = null!;
|
||||
|
||||
[Cached]
|
||||
private OsuRulesetConfigManager config = new OsuRulesetConfigManager(null, new OsuRuleset().RulesetInfo);
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("create analysis container", () =>
|
||||
{
|
||||
DrawableOsuRuleset drawableRuleset = new DrawableOsuRuleset(new OsuRuleset(), new OsuBeatmap());
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
drawableRuleset,
|
||||
analysisContainer = new TestReplayAnalysisOverlay(fabricateReplay(), drawableRuleset),
|
||||
analysisContainer = new TestReplayAnalysisOverlay(fabricateReplay()),
|
||||
settings = new ReplayAnalysisSettings(config),
|
||||
};
|
||||
});
|
||||
}
|
||||
@ -40,27 +42,27 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
[Test]
|
||||
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);
|
||||
AddStep("disable hit markers", () => analysisContainer.Settings.HitMarkersEnabled.Value = false);
|
||||
AddStep("disable hit markers", () => settings.HitMarkersEnabled.Value = false);
|
||||
AddAssert("hit markers not visible", () => !analysisContainer.HitMarkersVisible);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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);
|
||||
AddStep("disable aim markers", () => analysisContainer.Settings.AimMarkersEnabled.Value = false);
|
||||
AddStep("disable aim markers", () => settings.AimMarkersEnabled.Value = false);
|
||||
AddAssert("aim markers not visible", () => !analysisContainer.AimMarkersVisible);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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);
|
||||
AddStep("disable aim lines", () => analysisContainer.Settings.AimLinesEnabled.Value = false);
|
||||
AddStep("disable aim lines", () => settings.AimLinesEnabled.Value = false);
|
||||
AddAssert("aim lines not visible", () => !analysisContainer.AimLinesVisible);
|
||||
}
|
||||
|
||||
@ -98,13 +100,11 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
|
||||
private partial class TestReplayAnalysisOverlay : ReplayAnalysisOverlay
|
||||
{
|
||||
public TestReplayAnalysisOverlay(Replay replay, DrawableRuleset drawableRuleset)
|
||||
: base(replay, drawableRuleset)
|
||||
public TestReplayAnalysisOverlay(Replay replay)
|
||||
: base(replay)
|
||||
{
|
||||
}
|
||||
|
||||
public new ReplayAnalysisSettings Settings => base.Settings;
|
||||
|
||||
public bool HitMarkersVisible => HitMarkers.Alpha > 0 && HitMarkers.Entries.Any();
|
||||
public bool AimMarkersVisible => AimMarkers.Alpha > 0 && AimMarkers.Entries.Any();
|
||||
public bool AimLinesVisible => AimLines.Alpha > 0 && AimLines.Vertices.Count > 1;
|
||||
|
@ -1,8 +1,6 @@
|
||||
// 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.Game.Configuration;
|
||||
using osu.Game.Rulesets.Configuration;
|
||||
using osu.Game.Rulesets.UI;
|
||||
@ -11,7 +9,7 @@ namespace osu.Game.Rulesets.Osu.Configuration
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Input.Handlers;
|
||||
@ -24,7 +26,7 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
{
|
||||
public partial class DrawableOsuRuleset : DrawableRuleset<OsuHitObject>
|
||||
{
|
||||
protected new OsuRulesetConfigManager Config => (OsuRulesetConfigManager)base.Config;
|
||||
private Bindable<bool>? cursorHideEnabled;
|
||||
|
||||
public new OsuInputManager KeyBindingInputManager => (OsuInputManager)base.KeyBindingInputManager;
|
||||
|
||||
@ -39,7 +41,13 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
private void load(ReplayPlayer? replayPlayer)
|
||||
{
|
||||
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;
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Lines;
|
||||
@ -11,10 +12,9 @@ using osu.Framework.Graphics.Performance;
|
||||
using osu.Framework.Graphics.Pooling;
|
||||
using osu.Game.Replays;
|
||||
using osu.Game.Rulesets.Objects.Pooling;
|
||||
using osu.Game.Rulesets.Osu.Configuration;
|
||||
using osu.Game.Rulesets.Osu.Replays;
|
||||
using osu.Game.Rulesets.Osu.Skinning.Default;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Play;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -22,19 +22,19 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
{
|
||||
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 AimMarkersContainer AimMarkers;
|
||||
protected readonly AimLinesContainer AimLines;
|
||||
|
||||
protected ReplayAnalysisSettings Settings = null!;
|
||||
|
||||
private readonly Replay replay;
|
||||
private readonly DrawableRuleset drawableRuleset;
|
||||
|
||||
public ReplayAnalysisOverlay(Replay replay, DrawableRuleset drawableRuleset)
|
||||
public ReplayAnalysisOverlay(Replay replay)
|
||||
{
|
||||
this.replay = replay;
|
||||
this.drawableRuleset = drawableRuleset;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
@ -45,27 +45,22 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
}
|
||||
|
||||
[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();
|
||||
|
||||
config.BindWith(OsuRulesetSetting.ReplayHitMarkersEnabled, hitMarkersEnabled);
|
||||
config.BindWith(OsuRulesetSetting.ReplayAimMarkersEnabled, aimMarkersEnabled);
|
||||
config.BindWith(OsuRulesetSetting.ReplayAimLinesEnabled, aimLinesEnabled);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Settings.HitMarkersEnabled.BindValueChanged(enabled => HitMarkers.FadeTo(enabled.NewValue ? 1 : 0), true);
|
||||
Settings.AimMarkersEnabled.BindValueChanged(enabled => AimMarkers.FadeTo(enabled.NewValue ? 1 : 0), true);
|
||||
Settings.AimLinesEnabled.BindValueChanged(enabled => AimLines.FadeTo(enabled.NewValue ? 1 : 0), true);
|
||||
Settings.CursorHideEnabled.BindValueChanged(enabled => drawableRuleset.Playfield.Cursor.FadeTo(enabled.NewValue ? 0 : 1), true);
|
||||
hitMarkersEnabled.BindValueChanged(enabled => HitMarkers.FadeTo(enabled.NewValue ? 1 : 0), true);
|
||||
aimMarkersEnabled.BindValueChanged(enabled => AimMarkers.FadeTo(enabled.NewValue ? 1 : 0), true);
|
||||
aimLinesEnabled.BindValueChanged(enabled => AimLines.FadeTo(enabled.NewValue ? 1 : 0), true);
|
||||
}
|
||||
|
||||
private void loadReplay()
|
||||
|
@ -11,6 +11,8 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
{
|
||||
public partial class ReplayAnalysisSettings : PlayerSettingsGroup
|
||||
{
|
||||
private readonly OsuRulesetConfigManager config;
|
||||
|
||||
[SettingSource("Hit markers", SettingControlType = typeof(PlayerCheckbox))]
|
||||
public BindableBool HitMarkersEnabled { get; } = new BindableBool();
|
||||
|
||||
@ -23,18 +25,17 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
[SettingSource("Hide cursor", SettingControlType = typeof(PlayerCheckbox))]
|
||||
public BindableBool CursorHideEnabled { get; } = new BindableBool();
|
||||
|
||||
public ReplayAnalysisSettings()
|
||||
public ReplayAnalysisSettings(OsuRulesetConfigManager config)
|
||||
: base("Analysis Settings")
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IRulesetConfigCache cache)
|
||||
private void load()
|
||||
{
|
||||
AddRange(this.CreateSettingsControls());
|
||||
|
||||
var config = (OsuRulesetConfigManager)cache.GetConfigFor(new OsuRuleset())!;
|
||||
|
||||
config.BindWith(OsuRulesetSetting.ReplayHitMarkersEnabled, HitMarkersEnabled);
|
||||
config.BindWith(OsuRulesetSetting.ReplayAimMarkersEnabled, AimMarkersEnabled);
|
||||
config.BindWith(OsuRulesetSetting.ReplayAimLinesEnabled, AimLinesEnabled);
|
||||
|
Loading…
Reference in New Issue
Block a user