1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:42:56 +08:00

Enable NRT for DrawableHitCircle to clean up

This commit is contained in:
Dan Balasescu 2024-02-07 03:38:07 +09:00
parent 44b1515cc5
commit 9b8f206486
No known key found for this signature in database

View File

@ -1,12 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -27,34 +24,30 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
public partial class DrawableHitCircle : DrawableOsuHitObject, IHasApproachCircle public partial class DrawableHitCircle : DrawableOsuHitObject, IHasApproachCircle
{ {
public OsuAction? HitAction => HitArea?.HitAction; public OsuAction? HitAction => HitArea.HitAction;
protected virtual OsuSkinComponents CirclePieceComponent => OsuSkinComponents.HitCircle; protected virtual OsuSkinComponents CirclePieceComponent => OsuSkinComponents.HitCircle;
public SkinnableDrawable ApproachCircle { get; private set; } public SkinnableDrawable ApproachCircle { get; private set; } = null!;
public HitReceptor HitArea { get; private set; } public HitReceptor HitArea { get; private set; } = null!;
public SkinnableDrawable CirclePiece { get; private set; } public SkinnableDrawable CirclePiece { get; private set; } = null!;
protected override IEnumerable<Drawable> DimmablePieces => new[] protected override IEnumerable<Drawable> DimmablePieces => new[] { CirclePiece };
{
CirclePiece,
};
Drawable IHasApproachCircle.ApproachCircle => ApproachCircle; Drawable IHasApproachCircle.ApproachCircle => ApproachCircle;
private Container scaleContainer; private Container scaleContainer = null!;
private ShakeContainer shakeContainer = null!;
public DrawableHitCircle() public DrawableHitCircle()
: this(null) : this(null)
{ {
} }
public DrawableHitCircle([CanBeNull] HitCircle h = null) public DrawableHitCircle(HitCircle? h = null)
: base(h) : base(h)
{ {
} }
private ShakeContainer shakeContainer;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -219,8 +212,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
break; break;
case ArmedState.Idle: case ArmedState.Idle:
HitArea.ClosestPressPosition = null; HitArea.Reset();
HitArea.HitAction = null;
break; break;
case ArmedState.Miss: case ArmedState.Miss:
@ -240,11 +232,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
// IsHovered is used // IsHovered is used
public override bool HandlePositionalInput => true; public override bool HandlePositionalInput => true;
public Func<bool> CanBeHit; public required Func<bool> CanBeHit { get; set; }
public Action Hit; public required Action Hit { get; set; }
public OsuAction? HitAction; public OsuAction? HitAction { get; private set; }
public Vector2? ClosestPressPosition; public Vector2? ClosestPressPosition { get; private set; }
public HitReceptor() public HitReceptor()
{ {
@ -259,7 +251,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public bool OnPressed(KeyBindingPressEvent<OsuAction> e) public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
{ {
if (!(CanBeHit?.Invoke() ?? false)) if (CanBeHit())
return false; return false;
switch (e.Action) switch (e.Action)
@ -283,7 +275,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (IsHovered) if (IsHovered)
{ {
Hit?.Invoke(); Hit();
HitAction ??= e.Action; HitAction ??= e.Action;
return true; return true;
} }
@ -297,13 +289,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e) public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
{ {
} }
public void Reset()
{
HitAction = null;
ClosestPressPosition = null;
}
} }
private partial class ProxyableSkinnableDrawable : SkinnableDrawable private partial class ProxyableSkinnableDrawable : SkinnableDrawable
{ {
public override bool RemoveWhenNotAlive => false; public override bool RemoveWhenNotAlive => false;
public ProxyableSkinnableDrawable(ISkinComponentLookup lookup, Func<ISkinComponentLookup, Drawable> defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling) public ProxyableSkinnableDrawable(ISkinComponentLookup lookup, Func<ISkinComponentLookup, Drawable>? defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling)
: base(lookup, defaultImplementation, confineMode) : base(lookup, defaultImplementation, confineMode)
{ {
} }