Merge branch 'master' into Issue#9170

This commit is contained in:
Dean Herbert 2020-07-28 14:05:13 +09:00 committed by GitHub
commit fec54cc0ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 120 additions and 61 deletions

View File

@ -4,24 +4,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestSceneDrawableJudgement : OsuSkinnableTestScene
{
[Resolved]
private OsuConfigManager config { get; set; }
private readonly List<DrawablePool<TestDrawableOsuJudgement>> pools;
public TestSceneDrawableJudgement()
{
var pools = new List<DrawablePool<DrawableOsuJudgement>>();
pools = new List<DrawablePool<TestDrawableOsuJudgement>>();
foreach (HitResult result in Enum.GetValues(typeof(HitResult)).OfType<HitResult>().Skip(1))
showResult(result);
}
[Test]
public void TestHitLightingDisabled()
{
AddStep("hit lighting disabled", () => config.Set(OsuSetting.HitLighting, false));
showResult(HitResult.Great);
AddUntilStep("judgements shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any());
AddAssert("judgement body immediately visible",
() => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => judgement.JudgementBody.Alpha == 1));
AddAssert("hit lighting hidden",
() => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => judgement.Lighting.Alpha == 0));
}
[Test]
public void TestHitLightingEnabled()
{
AddStep("hit lighting enabled", () => config.Set(OsuSetting.HitLighting, true));
showResult(HitResult.Great);
AddUntilStep("judgements shown", () => this.ChildrenOfType<TestDrawableOsuJudgement>().Any());
AddAssert("judgement body not immediately visible",
() => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => judgement.JudgementBody.Alpha > 0 && judgement.JudgementBody.Alpha < 1));
AddAssert("hit lighting shown",
() => this.ChildrenOfType<TestDrawableOsuJudgement>().All(judgement => judgement.Lighting.Alpha > 0));
}
private void showResult(HitResult result)
{
AddStep("Show " + result.GetDescription(), () =>
{
@ -29,10 +71,10 @@ public TestSceneDrawableJudgement()
SetContents(() =>
{
DrawablePool<DrawableOsuJudgement> pool;
DrawablePool<TestDrawableOsuJudgement> pool;
if (poolIndex >= pools.Count)
pools.Add(pool = new DrawablePool<DrawableOsuJudgement>(1));
pools.Add(pool = new DrawablePool<TestDrawableOsuJudgement>(1));
else
{
pool = pools[poolIndex];
@ -60,6 +102,11 @@ public TestSceneDrawableJudgement()
});
});
}
private class TestDrawableOsuJudgement : DrawableOsuJudgement
{
public new SkinnableSprite Lighting => base.Lighting;
public new Container JudgementBody => base.JudgementBody;
}
}
}

View File

@ -16,9 +16,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public class DrawableOsuJudgement : DrawableJudgement
{
private SkinnableSprite lighting;
protected SkinnableSprite Lighting;
private Bindable<Color4> lightingColour;
[Resolved]
private OsuConfigManager config { get; set; }
public DrawableOsuJudgement(JudgementResult result, DrawableHitObject judgedObject)
: base(result, judgedObject)
{
@ -29,19 +33,17 @@ public DrawableOsuJudgement()
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
private void load()
{
if (config.Get<bool>(OsuSetting.HitLighting))
{
AddInternal(lighting = new SkinnableSprite("lighting")
AddInternal(Lighting = new SkinnableSprite("lighting")
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Blending = BlendingParameters.Additive,
Depth = float.MaxValue
Depth = float.MaxValue,
Alpha = 0
});
}
}
public override void Apply(JudgementResult result, DrawableHitObject judgedObject)
{
@ -60,33 +62,39 @@ protected override void PrepareForUse()
lightingColour?.UnbindAll();
if (lighting != null)
{
lighting.ResetAnimation();
Lighting.ResetAnimation();
if (JudgedObject != null)
{
lightingColour = JudgedObject.AccentColour.GetBoundCopy();
lightingColour.BindValueChanged(colour => lighting.Colour = Result.Type == HitResult.Miss ? Color4.Transparent : colour.NewValue, true);
lightingColour.BindValueChanged(colour => Lighting.Colour = Result.Type == HitResult.Miss ? Color4.Transparent : colour.NewValue, true);
}
else
{
lighting.Colour = Color4.White;
}
Lighting.Colour = Color4.White;
}
}
protected override double FadeOutDelay => lighting == null ? base.FadeOutDelay : 1400;
private double fadeOutDelay;
protected override double FadeOutDelay => fadeOutDelay;
protected override void ApplyHitAnimations()
{
if (lighting != null)
bool hitLightingEnabled = config.Get<bool>(OsuSetting.HitLighting);
if (hitLightingEnabled)
{
JudgementBody.FadeIn().Delay(FadeInDuration).FadeOut(400);
lighting.ScaleTo(0.8f).ScaleTo(1.2f, 600, Easing.Out);
lighting.FadeIn(200).Then().Delay(200).FadeOut(1000);
Lighting.ScaleTo(0.8f).ScaleTo(1.2f, 600, Easing.Out);
Lighting.FadeIn(200).Then().Delay(200).FadeOut(1000);
}
else
{
JudgementBody.Alpha = 1;
}
fadeOutDelay = hitLightingEnabled ? 1400 : base.FadeOutDelay;
JudgementText?.TransformSpacingTo(Vector2.Zero).Then().TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint);
base.ApplyHitAnimations();

View File

@ -130,7 +130,11 @@ private void prepareDrawables()
if (type == currentDrawableType)
return;
InternalChild = JudgementBody = new Container
// sub-classes might have added their own children that would be removed here if .InternalChild was used.
if (JudgementBody != null)
RemoveInternal(JudgementBody);
AddInternal(JudgementBody = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -142,7 +146,7 @@ private void prepareDrawables()
Colour = colours.ForHitResult(type),
Scale = new Vector2(0.85f, 1),
}, confineMode: ConfineMode.NoScaling)
};
});
currentDrawableType = type;
}

View File

@ -27,7 +27,7 @@
<PackageReference Include="ppy.osu.Framework" Version="2020.723.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.727.1" />
<PackageReference Include="Sentry" Version="2.1.5" />
<PackageReference Include="SharpCompress" Version="0.25.1" />
<PackageReference Include="SharpCompress" Version="0.26.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>

View File

@ -81,7 +81,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2020.723.0" />
<PackageReference Include="SharpCompress" Version="0.25.1" />
<PackageReference Include="SharpCompress" Version="0.26.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />