2022-09-19 03:08:34 +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.
|
|
|
|
|
|
2022-10-06 10:13:06 +08:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
2022-09-19 03:08:34 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Framework.Input.Events;
|
2022-10-05 17:37:09 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Skinning;
|
2022-09-19 03:08:34 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.UI
|
|
|
|
|
{
|
2022-10-05 17:27:51 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Manages smoke trails generated from user input.
|
|
|
|
|
/// </summary>
|
2022-09-19 03:08:34 +08:00
|
|
|
|
public class SmokeContainer : Container, IRequireHighFrequencyMousePosition, IKeyBindingHandler<OsuAction>
|
|
|
|
|
{
|
2022-10-06 10:13:06 +08:00
|
|
|
|
private SmokeSkinnableDrawable? currentSegmentSkinnable;
|
2022-09-20 01:16:05 +08:00
|
|
|
|
|
2022-10-05 17:51:02 +08:00
|
|
|
|
private Vector2 lastMousePosition;
|
2022-09-19 03:08:34 +08:00
|
|
|
|
|
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 _) => true;
|
|
|
|
|
|
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Action == OsuAction.Smoke)
|
|
|
|
|
{
|
2022-10-06 10:13:06 +08:00
|
|
|
|
AddInternal(currentSegmentSkinnable = new SmokeSkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.CursorSmoke), _ => new DefaultSmokeSegment()));
|
2022-10-05 17:51:02 +08:00
|
|
|
|
|
|
|
|
|
// Add initial position immediately.
|
|
|
|
|
addPosition();
|
2022-09-19 03:08:34 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Action == OsuAction.Smoke)
|
|
|
|
|
{
|
2022-10-05 17:51:02 +08:00
|
|
|
|
if (currentSegmentSkinnable?.Drawable is SmokeSegment segment)
|
2022-10-04 10:20:51 +08:00
|
|
|
|
{
|
2022-10-05 17:51:02 +08:00
|
|
|
|
segment.FinishDrawing(Time.Current);
|
|
|
|
|
currentSegmentSkinnable = null;
|
2022-10-04 10:20:51 +08:00
|
|
|
|
}
|
2022-09-19 03:08:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
|
|
|
|
{
|
2022-10-05 17:51:02 +08:00
|
|
|
|
lastMousePosition = e.MousePosition;
|
|
|
|
|
addPosition();
|
2022-09-19 03:08:34 +08:00
|
|
|
|
|
|
|
|
|
return base.OnMouseMove(e);
|
|
|
|
|
}
|
2022-10-05 17:51:02 +08:00
|
|
|
|
|
|
|
|
|
private void addPosition() => (currentSegmentSkinnable?.Drawable as SmokeSegment)?.AddPosition(lastMousePosition, Time.Current);
|
2022-10-06 10:13:06 +08:00
|
|
|
|
|
|
|
|
|
private class SmokeSkinnableDrawable : SkinnableDrawable
|
|
|
|
|
{
|
|
|
|
|
public override bool RemoveWhenNotAlive => true;
|
|
|
|
|
|
|
|
|
|
public override double LifetimeStart => Drawable.LifetimeStart;
|
|
|
|
|
public override double LifetimeEnd => Drawable.LifetimeEnd;
|
|
|
|
|
|
|
|
|
|
public SmokeSkinnableDrawable(ISkinComponent component, Func<ISkinComponent, Drawable>? defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling)
|
|
|
|
|
: base(component, defaultImplementation, confineMode)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-19 03:08:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|