2019-07-31 19:55:56 +00: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.
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-07-13 11:55:55 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-08-20 08:47:24 +00:00
|
|
|
|
using System.Linq;
|
2020-07-14 20:51:30 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-07-31 19:55:56 +00:00
|
|
|
|
using osu.Framework.Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
2020-07-13 11:55:55 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Pooling;
|
2020-07-14 20:51:30 +00:00
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Game.Configuration;
|
2019-07-31 19:55:56 +00:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2019-09-02 07:28:14 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2019-07-31 19:55:56 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-07-14 20:51:30 +00:00
|
|
|
|
using osu.Game.Skinning;
|
2019-07-31 19:55:56 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
|
{
|
2020-04-07 06:38:29 +00:00
|
|
|
|
public class TestSceneDrawableJudgement : OsuSkinnableTestScene
|
2019-07-31 19:55:56 +00:00
|
|
|
|
{
|
2020-07-14 20:51:30 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
|
|
|
|
|
|
private readonly List<DrawablePool<TestDrawableOsuJudgement>> pools;
|
|
|
|
|
|
2019-07-31 19:55:56 +00:00
|
|
|
|
public TestSceneDrawableJudgement()
|
|
|
|
|
{
|
2020-07-14 20:51:30 +00:00
|
|
|
|
pools = new List<DrawablePool<TestDrawableOsuJudgement>>();
|
2020-07-13 11:55:55 +00:00
|
|
|
|
|
2019-08-20 08:47:24 +00:00
|
|
|
|
foreach (HitResult result in Enum.GetValues(typeof(HitResult)).OfType<HitResult>().Skip(1))
|
2020-07-14 20:51:30 +00:00
|
|
|
|
showResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestHitLightingDisabled()
|
|
|
|
|
{
|
2021-03-17 07:10:16 +00:00
|
|
|
|
AddStep("hit lighting disabled", () => config.SetValue(OsuSetting.HitLighting, false));
|
2020-07-14 20:51:30 +00:00
|
|
|
|
|
|
|
|
|
showResult(HitResult.Great);
|
|
|
|
|
|
|
|
|
|
AddUntilStep("judgements shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any());
|
2020-11-19 05:10:07 +00:00
|
|
|
|
AddAssert("hit lighting has no transforms", () => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => !judgement.Lighting.Transforms.Any()));
|
|
|
|
|
AddAssert("hit lighting hidden", () => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => judgement.Lighting.Alpha == 0));
|
2020-07-14 20:51:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestHitLightingEnabled()
|
|
|
|
|
{
|
2021-03-17 07:10:16 +00:00
|
|
|
|
AddStep("hit lighting enabled", () => config.SetValue(OsuSetting.HitLighting, true));
|
2020-07-14 20:51:30 +00:00
|
|
|
|
|
|
|
|
|
showResult(HitResult.Great);
|
|
|
|
|
|
|
|
|
|
AddUntilStep("judgements shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any());
|
2020-11-19 05:10:07 +00:00
|
|
|
|
AddUntilStep("hit lighting shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any(judgement => judgement.Lighting.Alpha > 0));
|
2020-07-14 20:51:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showResult(HitResult result)
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show " + result.GetDescription(), () =>
|
2019-11-11 11:53:22 +00:00
|
|
|
|
{
|
2020-07-14 20:51:30 +00:00
|
|
|
|
int poolIndex = 0;
|
|
|
|
|
|
2021-06-02 07:04:53 +00:00
|
|
|
|
SetContents(_ =>
|
2020-07-13 11:55:55 +00:00
|
|
|
|
{
|
2020-07-14 20:51:30 +00:00
|
|
|
|
DrawablePool<TestDrawableOsuJudgement> pool;
|
2020-07-13 11:55:55 +00:00
|
|
|
|
|
2020-07-14 20:51:30 +00:00
|
|
|
|
if (poolIndex >= pools.Count)
|
|
|
|
|
pools.Add(pool = new DrawablePool<TestDrawableOsuJudgement>(1));
|
|
|
|
|
else
|
2019-08-20 08:47:24 +00:00
|
|
|
|
{
|
2020-07-14 20:51:30 +00:00
|
|
|
|
pool = pools[poolIndex];
|
2020-07-13 11:55:55 +00:00
|
|
|
|
|
2020-07-14 20:51:30 +00:00
|
|
|
|
// We need to make sure neither the pool nor the judgement get disposed when new content is set, and they both share the same parent.
|
|
|
|
|
((Container)pool.Parent).Clear(false);
|
|
|
|
|
}
|
2020-07-13 11:55:55 +00:00
|
|
|
|
|
2020-07-14 20:51:30 +00:00
|
|
|
|
var container = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
2020-07-13 11:55:55 +00:00
|
|
|
|
{
|
2020-07-14 20:51:30 +00:00
|
|
|
|
pool,
|
2020-11-18 07:09:51 +00:00
|
|
|
|
pool.Get(j => j.Apply(new JudgementResult(new HitObject
|
|
|
|
|
{
|
|
|
|
|
StartTime = Time.Current
|
|
|
|
|
}, new Judgement())
|
|
|
|
|
{
|
|
|
|
|
Type = result,
|
|
|
|
|
}, null)).With(j =>
|
2020-07-13 11:55:55 +00:00
|
|
|
|
{
|
2020-07-14 20:51:30 +00:00
|
|
|
|
j.Anchor = Anchor.Centre;
|
|
|
|
|
j.Origin = Anchor.Centre;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
poolIndex++;
|
|
|
|
|
return container;
|
2020-07-13 11:55:55 +00:00
|
|
|
|
});
|
2020-07-14 20:51:30 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestDrawableOsuJudgement : DrawableOsuJudgement
|
|
|
|
|
{
|
|
|
|
|
public new SkinnableSprite Lighting => base.Lighting;
|
2020-11-18 10:34:27 +00:00
|
|
|
|
public new SkinnableDrawable JudgementBody => base.JudgementBody;
|
2019-07-31 19:55:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|