// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.UserInterface; using osu.Framework.Testing; using osu.Framework.Utils; using osu.Game.Configuration; using osu.Game.Overlays.Settings.Sections.Audio; using osu.Game.Scoring; using osu.Game.Tests.Visual.Ranking; namespace osu.Game.Tests.Visual.Settings { public partial class TestSceneAudioOffsetAdjustControl : OsuTestScene { [Resolved] private SessionStatics statics { get; set; } = null!; [Cached] private SessionAverageHitErrorTracker tracker = new SessionAverageHitErrorTracker(); private Container content = null!; protected override Container Content => content; private OsuConfigManager localConfig = null!; private AudioOffsetAdjustControl adjustControl = null!; [BackgroundDependencyLoader] private void load() { localConfig = new OsuConfigManager(LocalStorage); Dependencies.CacheAs(localConfig); base.Content.AddRange(new Drawable[] { tracker, content = new Container { Anchor = Anchor.Centre, Origin = Anchor.Centre, Width = 400, AutoSizeAxes = Axes.Y } }); } [SetUp] public void SetUp() => Schedule(() => { Child = adjustControl = new AudioOffsetAdjustControl { Current = localConfig.GetBindable(OsuSetting.AudioOffset), }; localConfig.SetValue(OsuSetting.AudioOffset, 0.0); tracker.ClearHistory(); }); [Test] public void TestDisplay() { AddStep("set new score", () => statics.SetValue(Static.LastLocalUserScore, new ScoreInfo { HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents(RNG.NextDouble(-100, 100)), BeatmapInfo = Beatmap.Value.BeatmapInfo, })); AddStep("clear history", () => tracker.ClearHistory()); } [Test] public void TestRounding() { AddStep("set new score", () => statics.SetValue(Static.LastLocalUserScore, new ScoreInfo { HitEvents = TestSceneHitEventTimingDistributionGraph.CreateHitEvents(0.6), BeatmapInfo = Beatmap.Value.BeatmapInfo, })); checkButtonEnabled(); AddStep("click button", () => adjustControl.ChildrenOfType