1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 00:47:24 +08:00

Move application of judgements to Apply method

This commit is contained in:
Dean Herbert 2020-07-10 18:34:31 +09:00
parent 3138cc455c
commit 8aff828dfe
2 changed files with 22 additions and 29 deletions

View File

@ -111,7 +111,7 @@ namespace osu.Game.Rulesets.Osu.UI
DrawableOsuJudgement explosion = poolDictionary[result.Type].Get(doj =>
{
doj.JudgedObject = judgedObject;
doj.Apply(result, judgedObject);
// todo: move to JudgedObject property?
doj.Position = osuObject.StackedEndPosition;
@ -143,7 +143,7 @@ namespace osu.Game.Rulesets.Osu.UI
var judgement = base.CreateNewDrawable();
// just a placeholder to initialise the correct drawable hierarchy for this pool.
judgement.Result = new JudgementResult(new HitObject(), new Judgement()) { Type = result };
judgement.Apply(new JudgementResult(new HitObject(), new Judgement()) { Type = result }, null);
return judgement;
}

View File

@ -2,9 +2,9 @@
// See the LICENCE file in the repository root for full licence text.
using System.Diagnostics;
using JetBrains.Annotations;
using osuTK;
using osu.Framework.Allocation;
using osu.Framework.Caching;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -28,24 +28,8 @@ namespace osu.Game.Rulesets.Judgements
[Resolved]
private OsuColour colours { get; set; }
private readonly Cached drawableCache = new Cached();
private JudgementResult result;
public JudgementResult Result
{
get => result;
set
{
if (result?.Type == value.Type)
return;
result = value;
drawableCache.Invalidate();
}
}
public DrawableHitObject JudgedObject;
public JudgementResult Result { get; private set; }
public DrawableHitObject JudgedObject { get; private set; }
protected Container JudgementBody;
protected SpriteText JudgementText;
@ -68,8 +52,7 @@ namespace osu.Game.Rulesets.Judgements
public DrawableJudgement(JudgementResult result, DrawableHitObject judgedObject)
: this()
{
Result = result;
JudgedObject = judgedObject;
Apply(result, judgedObject);
}
public DrawableJudgement()
@ -78,6 +61,12 @@ namespace osu.Game.Rulesets.Judgements
Origin = Anchor.Centre;
}
[BackgroundDependencyLoader]
private void load()
{
prepareDrawables();
}
protected virtual void ApplyHitAnimations()
{
JudgementBody.ScaleTo(0.9f);
@ -86,10 +75,10 @@ namespace osu.Game.Rulesets.Judgements
this.Delay(FadeOutDelay).FadeOut(400);
}
[BackgroundDependencyLoader]
private void load()
public void Apply([NotNull] JudgementResult result, [CanBeNull] DrawableHitObject judgedObject)
{
prepareDrawables();
Result = result;
JudgedObject = judgedObject;
}
protected override void PrepareForUse()
@ -98,7 +87,6 @@ namespace osu.Game.Rulesets.Judgements
Debug.Assert(Result != null);
if (!drawableCache.IsValid)
prepareDrawables();
this.FadeInFromZero(FadeInDuration, Easing.OutQuint);
@ -129,10 +117,15 @@ namespace osu.Game.Rulesets.Judgements
Expire(true);
}
private HitResult? currentDrawableType;
private void prepareDrawables()
{
var type = Result?.Type ?? HitResult.Perfect; //TODO: better default type from ruleset
if (type == currentDrawableType)
return;
InternalChild = JudgementBody = new Container
{
Anchor = Anchor.Centre,
@ -147,7 +140,7 @@ namespace osu.Game.Rulesets.Judgements
}, confineMode: ConfineMode.NoScaling)
};
drawableCache.Validate();
currentDrawableType = type;
}
}
}