1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Basic smoke path implementation

This commit is contained in:
Alden Wu 2022-09-18 12:08:34 -07:00
parent 6e9031b03e
commit 493efd84a3
9 changed files with 242 additions and 1 deletions

View File

@ -80,6 +80,9 @@ namespace osu.Game.Rulesets.Osu
LeftButton,
[Description("Right button")]
RightButton
RightButton,
[Description("Smoke")]
Smoke,
}
}

View File

@ -57,6 +57,7 @@ namespace osu.Game.Rulesets.Osu
{
new KeyBinding(InputKey.Z, OsuAction.LeftButton),
new KeyBinding(InputKey.X, OsuAction.RightButton),
new KeyBinding(InputKey.C, OsuAction.Smoke),
new KeyBinding(InputKey.MouseLeft, OsuAction.LeftButton),
new KeyBinding(InputKey.MouseRight, OsuAction.RightButton),
};

View File

@ -21,6 +21,7 @@ namespace osu.Game.Rulesets.Osu
SliderBall,
SliderBody,
SpinnerBody,
Smoke,
ApproachCircle,
}
}

View File

@ -0,0 +1,14 @@
// 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.
namespace osu.Game.Rulesets.Osu.Skinning.Default
{
public class DefaultSmoke : Smoke
{
public DefaultSmoke()
{
Texture = null;
PathRadius = 2;
}
}
}

View File

@ -0,0 +1,26 @@
// 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.
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
public class LegacySmoke : Smoke
{
private ISkin skin;
public LegacySmoke(ISkin skin)
{
this.skin = skin;
PathRadius = 8;
}
protected override void LoadComplete()
{
base.LoadComplete();
Texture = skin.GetTexture("cursor-smoke");
}
}
}

View File

@ -106,6 +106,12 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
return null;
case OsuSkinComponents.Smoke:
if (GetTexture("cursor-smoke") != null)
return new LegacySmoke(this);
return null;
case OsuSkinComponents.HitCircleText:
if (!this.HasFont(LegacyFont.HitCircle))
return null;

View File

@ -0,0 +1,131 @@
// 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.
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Lines;
using osu.Game.Rulesets.Osu.UI;
using osuTK;
namespace osu.Game.Rulesets.Osu.Skinning
{
public abstract class Smoke : TexturedPath
{
protected bool IsActive { get; private set; }
protected double SmokeTimeStart { get; private set; } = double.MinValue;
protected double SmokeTimeEnd { get; private set; } = double.MinValue;
protected readonly List<Vector2> SmokeVertexPositions = new List<Vector2>();
protected readonly List<double> SmokeVertexTimes = new List<double>();
[Resolved(CanBeNull = true)]
private SmokeContainer? smokeContainer { get; set; }
protected struct SmokePoint
{
public Vector2 Position;
public double Time;
}
protected override void LoadComplete()
{
base.LoadComplete();
if (smokeContainer != null)
{
smokeContainer.SmokeMoved += guardOnSmokeMoved;
smokeContainer.SmokeEnded += guardOnSmokeEnded;
IsActive = true;
}
Anchor = Anchor.TopLeft;
Origin = Anchor.TopLeft;
SmokeTimeStart = Time.Current;
}
private void guardOnSmokeMoved(Vector2 position, double time)
{
if (IsActive)
OnSmokeMoved(position, time);
}
private void guardOnSmokeEnded(double time)
{
if (IsActive)
OnSmokeEnded(time);
}
protected virtual void OnSmokeMoved(Vector2 position, double time)
{
addSmokeVertex(position, time);
}
private void addSmokeVertex(Vector2 position, double time)
{
Debug.Assert(SmokeVertexTimes.Count == SmokeVertexPositions.Count);
if (SmokeVertexTimes.Count > 0 && SmokeVertexTimes.Last() > time)
{
int index = ~SmokeVertexTimes.BinarySearch(time, new UpperBoundComparer());
SmokeVertexTimes.RemoveRange(index, SmokeVertexTimes.Count - index);
SmokeVertexPositions.RemoveRange(index, SmokeVertexPositions.Count - index);
}
SmokeVertexTimes.Add(time);
SmokeVertexPositions.Add(position);
}
protected virtual void OnSmokeEnded(double time)
{
IsActive = false;
SmokeTimeEnd = time;
}
protected override void Update()
{
base.Update();
const double visible_duration = 8000;
const float disappear_speed = 3;
int index = 0;
if (!IsActive)
{
double cutoffTime = SmokeTimeStart + disappear_speed * (Time.Current - (SmokeTimeEnd + visible_duration));
index = ~SmokeVertexTimes.BinarySearch(cutoffTime, new UpperBoundComparer());
}
Vertices = new List<Vector2>(SmokeVertexPositions.Skip(index));
Position = -PositionInBoundingBox(Vector2.Zero);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (smokeContainer != null)
{
smokeContainer.SmokeMoved -= guardOnSmokeMoved;
smokeContainer.SmokeEnded -= guardOnSmokeEnded;
}
}
private struct UpperBoundComparer : IComparer<double>
{
public int Compare(double x, double target)
{
// By returning -1 when the target value is equal to x, guarantees that the
// element at BinarySearch's returned index will always be the first element
// larger. Since 0 is never returned, the target is never "found", so the return
// value will be the index's complement.
return x > target ? 1 : -1;
}
}
}
}

View File

@ -32,6 +32,7 @@ namespace osu.Game.Rulesets.Osu.UI
public class OsuPlayfield : Playfield
{
private readonly PlayfieldBorder playfieldBorder;
private readonly SmokeContainer smokeContainer;
private readonly ProxyContainer approachCircles;
private readonly ProxyContainer spinnerProxies;
private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer;
@ -54,6 +55,7 @@ namespace osu.Game.Rulesets.Osu.UI
InternalChildren = new Drawable[]
{
playfieldBorder = new PlayfieldBorder { RelativeSizeAxes = Axes.Both },
smokeContainer = new SmokeContainer { RelativeSizeAxes = Axes.Both },
spinnerProxies = new ProxyContainer { RelativeSizeAxes = Axes.Both },
FollowPoints = new FollowPointRenderer { RelativeSizeAxes = Axes.Both },
judgementLayer = new JudgementContainer<DrawableOsuJudgement> { RelativeSizeAxes = Axes.Both },

View File

@ -0,0 +1,57 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Osu.Skinning.Default;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Osu.UI
{
[Cached]
public class SmokeContainer : Container, IRequireHighFrequencyMousePosition, IKeyBindingHandler<OsuAction>
{
public event Action<Vector2, double>? SmokeMoved;
public event Action<double>? SmokeEnded;
private bool isSmoking = false;
public override bool ReceivePositionalInputAt(Vector2 _) => true;
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
{
if (e.Action == OsuAction.Smoke)
{
isSmoking = true;
AddInternal(new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.Smoke), _ => new DefaultSmoke()));
return true;
}
return false;
}
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
{
if (e.Action == OsuAction.Smoke)
{
isSmoking = false;
SmokeEnded?.Invoke(Time.Current);
}
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
if (isSmoking)
SmokeMoved?.Invoke(e.MousePosition, Time.Current);
return base.OnMouseMove(e);
}
}
}