Merge pull request #26545 from frenzibyte/fix-resume-cursor-transition-abused

Fix pop-in scale transition in resume overlay affecting input area
This commit is contained in:
Bartłomiej Dach 2024-01-15 20:06:16 +01:00 committed by GitHub
commit 71d0543213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 16 deletions

View File

@ -57,17 +57,7 @@ public OsuCursor()
[BackgroundDependencyLoader]
private void load()
{
InternalChild = cursorScaleContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Child = cursorSprite = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.Cursor), _ => new DefaultCursor(), confineMode: ConfineMode.NoScaling)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
}
};
InternalChild = CreateCursorContent();
userCursorScale = config.GetBindable<float>(OsuSetting.GameplayCursorSize);
userCursorScale.ValueChanged += _ => cursorScale.Value = CalculateCursorScale();
@ -84,6 +74,18 @@ protected override void LoadComplete()
cursorScale.Value = CalculateCursorScale();
}
protected virtual Drawable CreateCursorContent() => cursorScaleContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Child = cursorSprite = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.Cursor), _ => new DefaultCursor(), confineMode: ConfineMode.NoScaling)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
},
};
protected virtual float CalculateCursorScale()
{
float scale = userCursorScale.Value;

View File

@ -65,17 +65,24 @@ public partial class OsuClickToResumeCursor : OsuCursor, IKeyBindingHandler<OsuA
public override bool HandlePositionalInput => true;
public Action ResumeRequested;
private Container scaleTransitionContainer;
public OsuClickToResumeCursor()
{
RelativePositionAxes = Axes.Both;
}
protected override float CalculateCursorScale()
protected override Container CreateCursorContent() => scaleTransitionContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Child = base.CreateCursorContent(),
};
protected override float CalculateCursorScale() =>
// Force minimum cursor size so it's easily clickable
return Math.Max(1f, base.CalculateCursorScale());
}
Math.Max(1f, base.CalculateCursorScale());
protected override bool OnHover(HoverEvent e)
{
@ -98,7 +105,7 @@ public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
if (!IsHovered)
return false;
this.ScaleTo(2, TRANSITION_TIME, Easing.OutQuint);
scaleTransitionContainer.ScaleTo(2, TRANSITION_TIME, Easing.OutQuint);
ResumeRequested?.Invoke();
return true;
@ -114,7 +121,10 @@ public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
public void Appear() => Schedule(() =>
{
updateColour();
this.ScaleTo(4).Then().ScaleTo(1, 1000, Easing.OutQuint);
// importantly, we perform the scale transition on an underlying container rather than the whole cursor
// to prevent attempts of abuse by the scale change in the cursor's hitbox (see: https://github.com/ppy/osu/issues/26477).
scaleTransitionContainer.ScaleTo(4).Then().ScaleTo(1, 1000, Easing.OutQuint);
});
private void updateColour()