2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-06-25 14:47:32 +08:00
|
|
|
|
using System;
|
2019-04-04 16:09:11 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
2017-03-16 21:41:07 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-09-09 16:53:51 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2017-08-11 15:11:46 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-09-16 17:26:12 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-10-09 01:39:54 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Configuration;
|
2019-04-04 16:09:11 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Configuration;
|
2019-03-25 19:25:16 +08:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2020-02-14 11:30:11 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2019-09-09 16:53:51 +08:00
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-10 17:37:41 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.UI.Cursor
|
2017-03-16 21:41:07 +08:00
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class OsuCursorContainer : GameplayCursorContainer, IKeyBindingHandler<OsuAction>
|
2017-03-16 21:41:07 +08:00
|
|
|
|
{
|
|
|
|
|
protected override Drawable CreateCursor() => new OsuCursor();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-05 19:06:08 +08:00
|
|
|
|
protected override Container<Drawable> Content => fadeContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-05 19:06:08 +08:00
|
|
|
|
private readonly Container<Drawable> fadeContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-04-04 16:09:11 +08:00
|
|
|
|
private readonly Bindable<bool> showTrail = new Bindable<bool>(true);
|
|
|
|
|
|
2019-09-09 16:53:51 +08:00
|
|
|
|
private readonly Drawable cursorTrail;
|
2019-04-04 16:09:11 +08:00
|
|
|
|
|
2020-07-10 13:43:30 +08:00
|
|
|
|
public IBindable<float> CursorScale => cursorScale;
|
|
|
|
|
|
|
|
|
|
private readonly Bindable<float> cursorScale = new BindableFloat(1);
|
2020-02-14 14:59:59 +08:00
|
|
|
|
|
2019-10-16 02:12:08 +08:00
|
|
|
|
private Bindable<float> userCursorScale;
|
2019-10-09 01:39:54 +08:00
|
|
|
|
private Bindable<bool> autoCursorScale;
|
|
|
|
|
|
2019-03-25 19:25:16 +08:00
|
|
|
|
public OsuCursorContainer()
|
2017-03-16 21:41:07 +08:00
|
|
|
|
{
|
2019-01-10 13:20:44 +08:00
|
|
|
|
InternalChild = fadeContainer = new Container
|
2018-03-05 19:06:08 +08:00
|
|
|
|
{
|
2019-01-10 13:20:44 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-09-10 05:18:19 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2022-11-09 15:04:56 +08:00
|
|
|
|
cursorTrail = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.CursorTrail), _ => new DefaultCursorTrail(), confineMode: ConfineMode.NoScaling),
|
|
|
|
|
new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.CursorParticles), confineMode: ConfineMode.NoScaling),
|
2021-09-10 05:18:19 +08:00
|
|
|
|
}
|
2018-03-05 19:06:08 +08:00
|
|
|
|
};
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-14 11:30:11 +08:00
|
|
|
|
[Resolved(canBeNull: true)]
|
2021-10-02 01:22:23 +08:00
|
|
|
|
private GameplayState state { get; set; }
|
2020-02-14 11:30:11 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
|
|
2019-04-04 16:09:11 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2022-01-15 08:06:39 +08:00
|
|
|
|
private void load(OsuRulesetConfigManager rulesetConfig)
|
2019-04-04 16:09:11 +08:00
|
|
|
|
{
|
2019-10-09 01:39:54 +08:00
|
|
|
|
rulesetConfig?.BindWith(OsuRulesetSetting.ShowCursorTrail, showTrail);
|
2020-02-14 11:30:11 +08:00
|
|
|
|
}
|
2019-10-09 01:39:54 +08:00
|
|
|
|
|
2020-02-14 11:30:11 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2020-02-14 14:59:59 +08:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2020-02-14 11:30:11 +08:00
|
|
|
|
showTrail.BindValueChanged(v => cursorTrail.FadeTo(v.NewValue ? 1 : 0, 200), true);
|
2019-10-09 01:39:54 +08:00
|
|
|
|
|
2019-10-16 02:12:08 +08:00
|
|
|
|
userCursorScale = config.GetBindable<float>(OsuSetting.GameplayCursorSize);
|
|
|
|
|
userCursorScale.ValueChanged += _ => calculateScale();
|
2019-10-09 01:39:54 +08:00
|
|
|
|
|
|
|
|
|
autoCursorScale = config.GetBindable<bool>(OsuSetting.AutoCursorSize);
|
|
|
|
|
autoCursorScale.ValueChanged += _ => calculateScale();
|
|
|
|
|
|
2020-07-10 13:43:30 +08:00
|
|
|
|
CursorScale.BindValueChanged(e =>
|
2020-02-14 11:30:11 +08:00
|
|
|
|
{
|
|
|
|
|
var newScale = new Vector2(e.NewValue);
|
|
|
|
|
|
|
|
|
|
ActiveCursor.Scale = newScale;
|
|
|
|
|
cursorTrail.Scale = newScale;
|
2020-07-10 13:43:30 +08:00
|
|
|
|
}, true);
|
2019-10-12 17:51:14 +08:00
|
|
|
|
|
2019-10-09 01:39:54 +08:00
|
|
|
|
calculateScale();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 11:30:11 +08:00
|
|
|
|
/// <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;
|
|
|
|
|
|
2019-10-09 01:39:54 +08:00
|
|
|
|
private void calculateScale()
|
|
|
|
|
{
|
2019-10-16 02:12:08 +08:00
|
|
|
|
float scale = userCursorScale.Value;
|
2019-10-09 01:39:54 +08:00
|
|
|
|
|
2021-10-02 01:22:23 +08:00
|
|
|
|
if (autoCursorScale.Value && state != null)
|
2019-10-09 01:39:54 +08:00
|
|
|
|
{
|
|
|
|
|
// if we have a beatmap available, let's get its circle size to figure out an automatic cursor scale modifier.
|
2021-10-02 11:34:29 +08:00
|
|
|
|
scale *= GetScaleForCircleSize(state.Beatmap.Difficulty.CircleSize);
|
2019-10-09 01:39:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 13:43:30 +08:00
|
|
|
|
cursorScale.Value = scale;
|
2019-09-27 13:46:49 +08:00
|
|
|
|
|
2020-02-14 11:30:11 +08:00
|
|
|
|
var newScale = new Vector2(scale);
|
2019-04-04 16:09:11 +08:00
|
|
|
|
|
2020-02-14 11:30:11 +08:00
|
|
|
|
ActiveCursor.ScaleTo(newScale, 400, Easing.OutQuint);
|
|
|
|
|
cursorTrail.Scale = newScale;
|
2019-04-04 16:09:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 17:37:41 +08:00
|
|
|
|
private int downCount;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-01-07 17:28:22 +08:00
|
|
|
|
private void updateExpandedState()
|
|
|
|
|
{
|
|
|
|
|
if (downCount > 0)
|
|
|
|
|
(ActiveCursor as OsuCursor)?.Expand();
|
|
|
|
|
else
|
|
|
|
|
(ActiveCursor as OsuCursor)?.Contract();
|
|
|
|
|
}
|
2018-07-10 13:41:07 +08:00
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
|
2018-03-05 19:06:08 +08:00
|
|
|
|
{
|
2021-09-16 17:26:12 +08:00
|
|
|
|
switch (e.Action)
|
2018-12-12 04:02:12 +08:00
|
|
|
|
{
|
|
|
|
|
case OsuAction.LeftButton:
|
|
|
|
|
case OsuAction.RightButton:
|
|
|
|
|
downCount++;
|
2019-01-07 17:28:22 +08:00
|
|
|
|
updateExpandedState();
|
2018-12-12 04:02:12 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-05 19:06:08 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
|
2018-03-05 19:06:08 +08:00
|
|
|
|
{
|
2021-09-16 17:26:12 +08:00
|
|
|
|
switch (e.Action)
|
2018-12-11 07:38:03 +08:00
|
|
|
|
{
|
|
|
|
|
case OsuAction.LeftButton:
|
|
|
|
|
case OsuAction.RightButton:
|
2019-06-25 14:47:32 +08:00
|
|
|
|
// Todo: Math.Max() is required as a temporary measure to address https://github.com/ppy/osu-framework/issues/2576
|
|
|
|
|
downCount = Math.Max(0, downCount - 1);
|
|
|
|
|
|
|
|
|
|
if (downCount == 0)
|
2019-01-07 17:28:22 +08:00
|
|
|
|
updateExpandedState();
|
2018-12-11 07:38:03 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-03-05 19:06:08 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool HandlePositionalInput => true; // OverlayContainer will set this false when we go hidden, but we always want to receive input.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-05 19:06:08 +08:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
fadeContainer.FadeTo(1, 300, Easing.OutQuint);
|
2019-10-19 18:15:31 +08:00
|
|
|
|
ActiveCursor.ScaleTo(CursorScale.Value, 400, Easing.OutQuint);
|
2018-03-05 19:06:08 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-05 19:06:08 +08:00
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
fadeContainer.FadeTo(0.05f, 450, Easing.OutQuint);
|
2019-10-19 18:15:31 +08:00
|
|
|
|
ActiveCursor.ScaleTo(CursorScale.Value * 0.8f, 450, Easing.OutQuint);
|
2018-03-05 19:06:08 +08:00
|
|
|
|
}
|
2019-09-09 16:53:51 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class DefaultCursorTrail : CursorTrail
|
2019-09-09 16:53:51 +08:00
|
|
|
|
{
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore textures)
|
|
|
|
|
{
|
|
|
|
|
Texture = textures.Get(@"Cursor/cursortrail");
|
|
|
|
|
Scale = new Vector2(1 / Texture.ScaleAdjust);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-12 01:06:41 +08:00
|
|
|
|
}
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|