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

Move cursor scale application within OsuCursor

Doing so takes down two birds with one stone.
 1. `ResumeOverlay` having to manually apply cursor scale to its "resume
cursor".
 2. Resume cursor input handling scaling up with the gameplay setting. Now, only the sprite itself gets scaled.
This commit is contained in:
Salman Ahmed 2023-11-06 18:28:51 +03:00
parent 915feeffb0
commit 75fbbb35ad
3 changed files with 68 additions and 72 deletions

View File

@ -4,12 +4,16 @@
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets.Osu.Skinning;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
@ -20,12 +24,29 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
{
private const float size = 28;
private const float pressed_scale = 1.2f;
private const float released_scale = 1f;
private bool cursorExpand;
private SkinnableDrawable cursorSprite;
private Container cursorScaleContainer = null!;
private Drawable expandTarget => (cursorSprite.Drawable as OsuCursorSprite)?.ExpandTarget ?? cursorSprite;
public IBindable<float> CursorScale => cursorScale;
private readonly Bindable<float> cursorScale = new BindableFloat(1);
private Bindable<float> userCursorScale = null!;
private Bindable<bool> autoCursorScale = null!;
[Resolved(canBeNull: true)]
private GameplayState state { get; set; }
[Resolved]
private OsuConfigManager config { get; set; }
public OsuCursor()
{
Origin = Anchor.Centre;
@ -33,15 +54,10 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
Size = new Vector2(size);
}
protected override void SkinChanged(ISkinSource skin)
{
cursorExpand = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.CursorExpand)?.Value ?? true;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new Container
InternalChild = cursorScaleContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre,
@ -52,10 +68,45 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
Anchor = Anchor.Centre,
}
};
userCursorScale = config.GetBindable<float>(OsuSetting.GameplayCursorSize);
userCursorScale.ValueChanged += _ => calculateCursorScale();
autoCursorScale = config.GetBindable<bool>(OsuSetting.AutoCursorSize);
autoCursorScale.ValueChanged += _ => calculateCursorScale();
cursorScale.BindValueChanged(e => cursorScaleContainer.Scale = new Vector2(e.NewValue), true);
}
private const float pressed_scale = 1.2f;
private const float released_scale = 1f;
protected override void LoadComplete()
{
base.LoadComplete();
calculateCursorScale();
}
/// <summary>
/// Get the scale applicable to the ActiveCursor based on a beatmap's circle size.
/// </summary>
public static float GetScaleForCircleSize(float circleSize) =>
1f - 0.7f * (1f + circleSize - BeatmapDifficulty.DEFAULT_DIFFICULTY) / BeatmapDifficulty.DEFAULT_DIFFICULTY;
private void calculateCursorScale()
{
float scale = userCursorScale.Value;
if (autoCursorScale.Value && state != null)
{
// if we have a beatmap available, let's get its circle size to figure out an automatic cursor scale modifier.
scale *= GetScaleForCircleSize(state.Beatmap.Difficulty.CircleSize);
}
cursorScale.Value = scale;
}
protected override void SkinChanged(ISkinSource skin)
{
cursorExpand = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.CursorExpand)?.Value ?? true;
}
public void Expand()
{

View File

@ -11,11 +11,8 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets.Osu.Configuration;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
using osuTK;
@ -23,6 +20,8 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
{
public partial class OsuCursorContainer : GameplayCursorContainer, IKeyBindingHandler<OsuAction>
{
public new OsuCursor ActiveCursor => (OsuCursor)base.ActiveCursor;
protected override Drawable CreateCursor() => new OsuCursor();
protected override Container<Drawable> Content => fadeContainer;
@ -33,13 +32,6 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
private readonly Drawable cursorTrail;
public IBindable<float> CursorScale => cursorScale;
private readonly Bindable<float> cursorScale = new BindableFloat(1);
private Bindable<float> userCursorScale;
private Bindable<bool> autoCursorScale;
private readonly CursorRippleVisualiser rippleVisualiser;
public OsuCursorContainer()
@ -56,12 +48,6 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
};
}
[Resolved(canBeNull: true)]
private GameplayState state { get; set; }
[Resolved]
private OsuConfigManager config { get; set; }
[BackgroundDependencyLoader(true)]
private void load(OsuRulesetConfigManager rulesetConfig)
{
@ -74,46 +60,13 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
showTrail.BindValueChanged(v => cursorTrail.FadeTo(v.NewValue ? 1 : 0, 200), true);
userCursorScale = config.GetBindable<float>(OsuSetting.GameplayCursorSize);
userCursorScale.ValueChanged += _ => calculateScale();
autoCursorScale = config.GetBindable<bool>(OsuSetting.AutoCursorSize);
autoCursorScale.ValueChanged += _ => calculateScale();
CursorScale.BindValueChanged(e =>
ActiveCursor.CursorScale.BindValueChanged(e =>
{
var newScale = new Vector2(e.NewValue);
ActiveCursor.Scale = newScale;
rippleVisualiser.CursorScale = newScale;
cursorTrail.Scale = newScale;
}, true);
calculateScale();
}
/// <summary>
/// Get the scale applicable to the ActiveCursor based on a beatmap's circle size.
/// </summary>
public static float GetScaleForCircleSize(float circleSize) =>
1f - 0.7f * (1f + circleSize - BeatmapDifficulty.DEFAULT_DIFFICULTY) / BeatmapDifficulty.DEFAULT_DIFFICULTY;
private void calculateScale()
{
float scale = userCursorScale.Value;
if (autoCursorScale.Value && state != null)
{
// if we have a beatmap available, let's get its circle size to figure out an automatic cursor scale modifier.
scale *= GetScaleForCircleSize(state.Beatmap.Difficulty.CircleSize);
}
cursorScale.Value = scale;
var newScale = new Vector2(scale);
ActiveCursor.ScaleTo(newScale, 400, Easing.OutQuint);
cursorTrail.Scale = newScale;
}
private int downCount;
@ -121,9 +74,9 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
private void updateExpandedState()
{
if (downCount > 0)
(ActiveCursor as OsuCursor)?.Expand();
ActiveCursor.Expand();
else
(ActiveCursor as OsuCursor)?.Contract();
ActiveCursor.Contract();
}
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
@ -160,13 +113,13 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
protected override void PopIn()
{
fadeContainer.FadeTo(1, 300, Easing.OutQuint);
ActiveCursor.ScaleTo(CursorScale.Value, 400, Easing.OutQuint);
ActiveCursor.ScaleTo(1f, 400, Easing.OutQuint);
}
protected override void PopOut()
{
fadeContainer.FadeTo(0.05f, 450, Easing.OutQuint);
ActiveCursor.ScaleTo(CursorScale.Value * 0.8f, 450, Easing.OutQuint);
ActiveCursor.ScaleTo(0.8f, 450, Easing.OutQuint);
}
private partial class DefaultCursorTrail : CursorTrail

View File

@ -5,7 +5,6 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
@ -14,7 +13,6 @@ using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Screens.Play;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.UI
@ -25,7 +23,6 @@ namespace osu.Game.Rulesets.Osu.UI
private OsuClickToResumeCursor clickToResumeCursor;
private OsuCursorContainer localCursorContainer;
private IBindable<float> localCursorScale;
public override CursorContainer LocalCursor => State.Value == Visibility.Visible ? localCursorContainer : null;
@ -49,13 +46,7 @@ namespace osu.Game.Rulesets.Osu.UI
clickToResumeCursor.Appear();
if (localCursorContainer == null)
{
Add(localCursorContainer = new OsuCursorContainer());
localCursorScale = new BindableFloat();
localCursorScale.BindTo(localCursorContainer.CursorScale);
localCursorScale.BindValueChanged(scale => cursorScaleContainer.Scale = new Vector2(scale.NewValue), true);
}
}
protected override void PopOut()
@ -98,7 +89,8 @@ namespace osu.Game.Rulesets.Osu.UI
{
case OsuAction.LeftButton:
case OsuAction.RightButton:
if (!IsHovered) return false;
if (!IsHovered)
return false;
this.ScaleTo(2, TRANSITION_TIME, Easing.OutQuint);