2020-10-30 13:23:24 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-10-30 13:23:24 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2023-09-22 13:40:10 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2020-10-30 13:23:24 +08:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
using osu.Framework.Graphics;
|
2023-04-03 14:37:10 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Testing;
|
2020-10-30 13:23:24 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-05-03 15:47:47 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-10-30 13:23:24 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2023-03-07 15:28:54 +08:00
|
|
|
using osu.Game.Screens.Play.HUD;
|
2023-06-16 23:24:40 +08:00
|
|
|
using osu.Game.Skinning;
|
2022-05-28 20:55:57 +08:00
|
|
|
using osu.Game.Tests.Gameplay;
|
2020-10-30 13:23:24 +08:00
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneSkinnableHUDOverlay : SkinnableTestScene
|
2020-10-30 13:23:24 +08:00
|
|
|
{
|
|
|
|
private HUDOverlay hudOverlay;
|
|
|
|
|
2023-05-25 15:38:22 +08:00
|
|
|
[Cached(typeof(ScoreProcessor))]
|
2023-07-20 21:30:48 +08:00
|
|
|
private ScoreProcessor scoreProcessor { get; set; }
|
2021-05-03 15:47:47 +08:00
|
|
|
|
2021-05-07 16:47:38 +08:00
|
|
|
[Cached(typeof(HealthProcessor))]
|
|
|
|
private HealthProcessor healthProcessor = new DrainingHealthProcessor(0);
|
|
|
|
|
2022-03-15 21:55:47 +08:00
|
|
|
[Cached]
|
2022-05-28 20:55:57 +08:00
|
|
|
private GameplayState gameplayState = TestGameplayState.Create(new OsuRuleset());
|
2022-03-15 21:55:47 +08:00
|
|
|
|
2022-08-15 16:36:18 +08:00
|
|
|
[Cached(typeof(IGameplayClock))]
|
2023-09-22 13:40:10 +08:00
|
|
|
private readonly IGameplayClock gameplayClock = new GameplayClockContainer(new TrackVirtual(60000), false, false);
|
2022-03-18 04:22:07 +08:00
|
|
|
|
2020-10-30 13:23:24 +08:00
|
|
|
private IEnumerable<HUDOverlay> hudOverlays => CreatedDrawables.OfType<HUDOverlay>();
|
|
|
|
|
|
|
|
// best way to check without exposing.
|
2023-06-16 23:24:40 +08:00
|
|
|
private Drawable hideTarget => hudOverlay.ChildrenOfType<SkinComponentsContainer>().First();
|
2023-06-14 19:25:24 +08:00
|
|
|
private Drawable keyCounterFlow => hudOverlay.ChildrenOfType<KeyCounterDisplay>().First().ChildrenOfType<FillFlowContainer<KeyCounter>>().Single();
|
2020-10-30 13:23:24 +08:00
|
|
|
|
2023-07-20 21:30:48 +08:00
|
|
|
public TestSceneSkinnableHUDOverlay()
|
|
|
|
{
|
|
|
|
scoreProcessor = gameplayState.ScoreProcessor;
|
|
|
|
}
|
|
|
|
|
2020-10-30 13:23:24 +08:00
|
|
|
[Test]
|
|
|
|
public void TestComboCounterIncrementing()
|
|
|
|
{
|
|
|
|
createNew();
|
|
|
|
|
2021-05-03 15:47:47 +08:00
|
|
|
AddRepeatStep("increase combo", () => scoreProcessor.Combo.Value++, 10);
|
2020-10-30 13:23:24 +08:00
|
|
|
|
2021-05-03 15:47:47 +08:00
|
|
|
AddStep("reset combo", () => scoreProcessor.Combo.Value = 0);
|
2020-10-30 13:23:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestFadesInOnLoadComplete()
|
|
|
|
{
|
|
|
|
float? initialAlpha = null;
|
|
|
|
|
|
|
|
createNew(h => h.OnLoadComplete += _ => initialAlpha = hideTarget.Alpha);
|
|
|
|
AddAssert("initial alpha was less than 1", () => initialAlpha < 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestHideExternally()
|
|
|
|
{
|
|
|
|
createNew();
|
|
|
|
|
|
|
|
AddStep("set showhud false", () => hudOverlays.ForEach(h => h.ShowHud.Value = false));
|
|
|
|
|
2023-06-16 23:24:40 +08:00
|
|
|
AddUntilStep("hidetarget is hidden", () => hideTarget.Alpha, () => Is.LessThanOrEqualTo(0));
|
2020-10-30 13:23:24 +08:00
|
|
|
AddAssert("pause button is still visible", () => hudOverlay.HoldToQuit.IsPresent);
|
|
|
|
|
|
|
|
// Key counter flow container should not be affected by this, only the key counter display will be hidden as checked above.
|
|
|
|
AddAssert("key counter flow not affected", () => keyCounterFlow.IsPresent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createNew(Action<HUDOverlay> action = null)
|
|
|
|
{
|
|
|
|
AddStep("create overlay", () =>
|
|
|
|
{
|
2021-06-02 15:04:53 +08:00
|
|
|
SetContents(_ =>
|
2020-10-30 13:23:24 +08:00
|
|
|
{
|
2021-05-07 16:27:34 +08:00
|
|
|
hudOverlay = new HUDOverlay(null, Array.Empty<Mod>());
|
2020-10-30 13:23:24 +08:00
|
|
|
|
|
|
|
// Add any key just to display the key counter visually.
|
2023-06-27 01:27:42 +08:00
|
|
|
hudOverlay.InputCountController.Add(new KeyCounterKeyboardTrigger(Key.Space));
|
2020-10-30 13:23:24 +08:00
|
|
|
|
|
|
|
action?.Invoke(hudOverlay);
|
|
|
|
|
|
|
|
return hudOverlay;
|
|
|
|
});
|
|
|
|
});
|
2023-06-28 03:20:59 +08:00
|
|
|
AddUntilStep("HUD overlay loaded", () => hudOverlay.IsAlive);
|
|
|
|
AddUntilStep("components container loaded",
|
|
|
|
() => hudOverlay.ChildrenOfType<SkinComponentsContainer>().Any(scc => scc.ComponentsLoaded));
|
2020-10-30 13:23:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
|
|
|
|
}
|
|
|
|
}
|