1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 10:02:54 +08:00
osu-lazer/osu.Game.Rulesets.Osu/UI/Cursor/GameplayCursor.cs

190 lines
6.8 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-03-16 21:41:07 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
2017-08-11 15:11:46 +08:00
using osu.Framework.Input.Bindings;
2017-05-15 11:54:56 +08:00
using osu.Game.Beatmaps;
2017-03-16 21:41:07 +08:00
using osu.Game.Configuration;
using osu.Game.Skinning;
using OpenTK;
using OpenTK.Graphics;
2017-03-16 21:41:07 +08:00
namespace osu.Game.Rulesets.Osu.UI.Cursor
2017-03-16 21:41:07 +08:00
{
2017-08-12 18:54:07 +08:00
public class GameplayCursor : CursorContainer, IKeyBindingHandler<OsuAction>
2017-03-16 21:41:07 +08:00
{
protected override Drawable CreateCursor() => new OsuCursor();
protected override Container<Drawable> Content => fadeContainer;
private readonly Container<Drawable> fadeContainer;
2017-03-16 21:41:07 +08:00
public GameplayCursor()
{
InternalChild = fadeContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new CursorTrail { Depth = 1 }
}
};
2017-03-16 21:41:07 +08:00
}
private int downCount;
public bool OnPressed(OsuAction action)
{
switch (action)
{
case OsuAction.LeftButton:
case OsuAction.RightButton:
downCount++;
ActiveCursor.ScaleTo(1).ScaleTo(1.2f, 100, Easing.OutQuad);
break;
}
return false;
}
public bool OnReleased(OsuAction action)
{
switch (action)
{
case OsuAction.LeftButton:
case OsuAction.RightButton:
if (--downCount == 0)
ActiveCursor.ScaleTo(1, 200, Easing.OutQuad);
break;
}
return false;
}
public override bool HandleMouseInput => true; // OverlayContainer will set this false when we go hidden, but we always want to receive input.
protected override void PopIn()
{
fadeContainer.FadeTo(1, 300, Easing.OutQuint);
ActiveCursor.ScaleTo(1, 400, Easing.OutQuint);
}
protected override void PopOut()
{
fadeContainer.FadeTo(0.05f, 450, Easing.OutQuint);
ActiveCursor.ScaleTo(0.8f, 450, Easing.OutQuint);
}
2017-03-16 21:41:07 +08:00
public class OsuCursor : Container
{
private Drawable cursorContainer;
2017-05-15 11:54:56 +08:00
2017-03-16 21:41:07 +08:00
private Bindable<double> cursorScale;
2017-05-13 08:46:37 +08:00
private Bindable<bool> autoCursorScale;
2017-05-15 11:54:56 +08:00
private Bindable<WorkingBeatmap> beatmap;
2017-03-16 21:41:07 +08:00
public OsuCursor()
{
Origin = Anchor.Centre;
Size = new Vector2(42);
}
2017-05-14 15:26:52 +08:00
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, OsuGameBase game)
2017-03-16 21:41:07 +08:00
{
Child = cursorContainer = new SkinnableDrawable("cursor", _ => new CircularContainer
2017-03-16 21:41:07 +08:00
{
RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = Size.X / 6,
BorderColour = Color4.White,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Pink.Opacity(0.5f),
Radius = 5,
},
Children = new Drawable[]
2017-03-16 21:41:07 +08:00
{
new Box
2017-03-18 01:03:44 +08:00
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true,
2017-03-16 21:41:07 +08:00
},
new CircularContainer
2017-03-16 21:41:07 +08:00
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = Size.X / 3,
BorderColour = Color4.White.Opacity(0.5f),
Children = new Drawable[]
2017-03-16 21:41:07 +08:00
{
new Box
2017-03-16 21:41:07 +08:00
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true,
2017-03-16 21:41:07 +08:00
},
},
},
new CircularContainer
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Scale = new Vector2(0.1f),
Masking = true,
Children = new Drawable[]
2017-03-16 21:41:07 +08:00
{
new Box
2017-03-16 21:41:07 +08:00
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
2017-03-16 21:41:07 +08:00
},
},
},
}
}, restrictSize: false)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
2017-03-16 21:41:07 +08:00
};
2017-03-18 01:03:44 +08:00
2017-05-15 11:54:56 +08:00
beatmap = game.Beatmap.GetBoundCopy();
beatmap.ValueChanged += v => calculateScale();
2017-05-14 12:28:12 +08:00
2017-05-15 09:56:27 +08:00
cursorScale = config.GetBindable<double>(OsuSetting.GameplayCursorSize);
2017-05-15 11:54:56 +08:00
cursorScale.ValueChanged += v => calculateScale();
autoCursorScale = config.GetBindable<bool>(OsuSetting.AutoCursorSize);
2017-05-15 11:54:56 +08:00
autoCursorScale.ValueChanged += v => calculateScale();
2017-05-14 12:28:12 +08:00
2017-05-15 11:54:56 +08:00
calculateScale();
2017-05-14 12:28:12 +08:00
}
2017-05-13 08:46:37 +08:00
2017-05-14 12:28:12 +08:00
private void calculateScale()
{
2017-05-15 11:54:56 +08:00
float scale = (float)cursorScale.Value;
if (autoCursorScale && beatmap.Value != null)
{
// if we have a beatmap available, let's get its circle size to figure out an automatic cursor scale modifier.
2017-10-19 13:05:11 +08:00
scale *= (float)(1 - 0.7 * (1 + beatmap.Value.BeatmapInfo.BaseDifficulty.CircleSize - BeatmapDifficulty.DEFAULT_DIFFICULTY) / BeatmapDifficulty.DEFAULT_DIFFICULTY);
2017-05-15 11:54:56 +08:00
}
cursorContainer.Scale = new Vector2(scale);
2017-03-16 21:41:07 +08:00
}
}
}
}