2022-06-10 07:22:34 +00: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.
|
|
|
|
|
|
|
|
#nullable enable
|
2022-06-10 08:17:09 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-06-10 10:42:17 +00:00
|
|
|
using osu.Framework.Allocation;
|
2022-06-10 08:17:09 +00:00
|
|
|
using osu.Framework.Graphics;
|
2022-06-10 07:22:34 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-06-10 08:17:09 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
2022-06-10 10:33:01 +00:00
|
|
|
using osu.Framework.Input.States;
|
2022-06-10 11:21:03 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2022-06-10 08:17:09 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2022-06-10 10:33:01 +00:00
|
|
|
using osu.Game.Screens.Utility.SampleComponents;
|
2022-06-10 08:17:09 +00:00
|
|
|
using osuTK;
|
2022-06-10 07:22:34 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Utility
|
|
|
|
{
|
2022-06-10 11:04:51 +00:00
|
|
|
public class CircleGameplay : LatencySampleComponent
|
2022-06-10 07:22:34 +00:00
|
|
|
{
|
2022-06-10 08:17:09 +00:00
|
|
|
private int nextLocation;
|
|
|
|
|
|
|
|
private OsuSpriteText unstableRate = null!;
|
|
|
|
|
|
|
|
private readonly List<HitEvent> hitEvents = new List<HitEvent>();
|
|
|
|
|
2022-06-10 09:27:58 +00:00
|
|
|
private double? lastGeneratedBeatTime;
|
2022-06-10 09:18:24 +00:00
|
|
|
|
2022-06-10 11:04:51 +00:00
|
|
|
private Container circles = null!;
|
2022-06-10 09:18:24 +00:00
|
|
|
|
2022-06-10 08:17:09 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
unstableRate = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2022-06-10 09:27:58 +00:00
|
|
|
Font = OsuFont.Default.With(size: 24),
|
|
|
|
Y = -100,
|
|
|
|
},
|
2022-06-10 11:04:51 +00:00
|
|
|
circles = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2022-06-10 08:17:09 +00:00
|
|
|
};
|
2022-06-10 11:04:51 +00:00
|
|
|
|
|
|
|
SampleBPM.BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
circles.Clear();
|
|
|
|
lastGeneratedBeatTime = null;
|
|
|
|
});
|
2022-06-10 08:17:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 11:04:51 +00:00
|
|
|
protected override void UpdateAtLimitedRate(InputState inputState)
|
2022-06-10 08:17:09 +00:00
|
|
|
{
|
2022-06-10 11:04:51 +00:00
|
|
|
double beatLength = 60000 / SampleBPM.Value;
|
2022-06-10 09:27:58 +00:00
|
|
|
|
2022-06-10 11:04:51 +00:00
|
|
|
int nextBeat = (int)(Clock.CurrentTime / beatLength) + 1;
|
2022-06-10 09:27:58 +00:00
|
|
|
|
2022-06-10 11:04:51 +00:00
|
|
|
// We want to generate a few hit objects ahead of the current time (to allow them to animate).
|
|
|
|
double generateUpTo = (nextBeat + 2) * beatLength;
|
2022-06-10 09:18:24 +00:00
|
|
|
|
2022-06-10 09:27:58 +00:00
|
|
|
while (lastGeneratedBeatTime == null || lastGeneratedBeatTime < generateUpTo)
|
2022-06-10 09:18:24 +00:00
|
|
|
{
|
2022-06-10 11:04:51 +00:00
|
|
|
double time = ++nextBeat * beatLength;
|
2022-06-10 09:27:58 +00:00
|
|
|
|
|
|
|
if (time <= lastGeneratedBeatTime)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
newBeat(time);
|
|
|
|
lastGeneratedBeatTime = time;
|
2022-06-10 09:18:24 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-10 08:17:09 +00:00
|
|
|
|
2022-06-10 09:27:58 +00:00
|
|
|
private void newBeat(double time)
|
2022-06-10 09:18:24 +00:00
|
|
|
{
|
2022-06-10 08:17:09 +00:00
|
|
|
nextLocation++;
|
|
|
|
|
|
|
|
Vector2 location;
|
|
|
|
|
2022-06-10 11:21:03 +00:00
|
|
|
float adjust = SampleVisualSpacing.Value * 0.25f;
|
|
|
|
|
|
|
|
float spacingLow = 0.5f - adjust;
|
|
|
|
float spacingHigh = 0.5f + adjust;
|
2022-06-10 08:27:06 +00:00
|
|
|
|
2022-06-10 08:17:09 +00:00
|
|
|
switch (nextLocation % 4)
|
|
|
|
{
|
|
|
|
default:
|
2022-06-10 09:27:58 +00:00
|
|
|
location = new Vector2(spacingLow, spacingLow);
|
2022-06-10 08:17:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2022-06-10 09:27:58 +00:00
|
|
|
location = new Vector2(spacingHigh, spacingHigh);
|
2022-06-10 08:17:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2022-06-10 09:27:58 +00:00
|
|
|
location = new Vector2(spacingHigh, spacingLow);
|
2022-06-10 08:17:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2022-06-10 09:27:58 +00:00
|
|
|
location = new Vector2(spacingLow, spacingHigh);
|
2022-06-10 08:17:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-10 11:04:51 +00:00
|
|
|
circles.Add(new SampleHitCircle(time)
|
2022-06-10 08:17:09 +00:00
|
|
|
{
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
Position = location,
|
|
|
|
Hit = hit,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hit(HitEvent h)
|
|
|
|
{
|
|
|
|
hitEvents.Add(h);
|
2022-06-10 11:04:51 +00:00
|
|
|
unstableRate.Text = $"UR: {hitEvents.CalculateUnstableRate()}";
|
2022-06-10 08:17:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 10:33:01 +00:00
|
|
|
public class SampleHitCircle : LatencySampleComponent
|
2022-06-10 08:17:09 +00:00
|
|
|
{
|
|
|
|
public HitEvent? HitEvent;
|
|
|
|
|
|
|
|
public Action<HitEvent>? Hit { get; set; }
|
|
|
|
|
|
|
|
public readonly double HitTime;
|
|
|
|
|
2022-06-10 10:42:17 +00:00
|
|
|
private CircularContainer approach = null!;
|
|
|
|
private Circle circle = null!;
|
2022-06-10 08:17:09 +00:00
|
|
|
|
|
|
|
private const float size = 100;
|
|
|
|
|
2022-06-10 08:27:06 +00:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
|
|
|
=> circle.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
2022-06-10 08:17:09 +00:00
|
|
|
public SampleHitCircle(double hitTime)
|
|
|
|
{
|
|
|
|
HitTime = hitTime;
|
|
|
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2022-06-10 09:18:24 +00:00
|
|
|
AlwaysPresent = true;
|
2022-06-10 10:42:17 +00:00
|
|
|
}
|
2022-06-10 09:18:24 +00:00
|
|
|
|
2022-06-10 10:42:17 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2022-06-10 08:17:09 +00:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
circle = new Circle
|
|
|
|
{
|
2022-06-10 10:42:17 +00:00
|
|
|
Colour = OverlayColourProvider.Content1,
|
2022-06-10 08:17:09 +00:00
|
|
|
Size = new Vector2(size),
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
},
|
|
|
|
approach = new CircularContainer
|
|
|
|
{
|
2022-06-10 10:42:17 +00:00
|
|
|
BorderColour = OverlayColourProvider.Colour1,
|
2022-06-10 08:17:09 +00:00
|
|
|
Size = new Vector2(size),
|
|
|
|
Masking = true,
|
|
|
|
BorderThickness = 4,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Alpha = 0,
|
|
|
|
AlwaysPresent = true,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-10 10:33:01 +00:00
|
|
|
protected override bool OnHover(HoverEvent e) => true;
|
|
|
|
|
2022-06-10 08:17:09 +00:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
if (HitEvent != null)
|
|
|
|
return false;
|
|
|
|
|
2022-06-10 09:37:53 +00:00
|
|
|
if (Math.Abs(Clock.CurrentTime - HitTime) > 200)
|
|
|
|
return false;
|
|
|
|
|
2022-06-10 10:33:01 +00:00
|
|
|
attemptHit();
|
2022-06-10 08:17:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-10 10:33:01 +00:00
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2022-06-10 08:17:09 +00:00
|
|
|
{
|
2022-06-10 10:33:01 +00:00
|
|
|
if (!IsActive.Value)
|
|
|
|
return false;
|
2022-06-10 08:17:09 +00:00
|
|
|
|
2022-06-10 10:35:21 +00:00
|
|
|
if (Math.Abs(Clock.CurrentTime - HitTime) > 200)
|
|
|
|
return false;
|
|
|
|
|
2022-06-10 10:33:01 +00:00
|
|
|
if (IsHovered)
|
|
|
|
attemptHit();
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateAtLimitedRate(InputState inputState)
|
|
|
|
{
|
2022-06-10 09:37:53 +00:00
|
|
|
if (HitEvent == null)
|
|
|
|
{
|
2022-06-10 11:21:03 +00:00
|
|
|
double preempt = (float)IBeatmapDifficultyInfo.DifficultyRange(SampleApproachRate.Value, 1800, 1200, 450);
|
|
|
|
|
|
|
|
approach.Scale = new Vector2(1 + 4 * (float)MathHelper.Clamp((HitTime - Clock.CurrentTime) / preempt, 0, 100));
|
2022-06-10 09:37:53 +00:00
|
|
|
Alpha = (float)MathHelper.Clamp((Clock.CurrentTime - HitTime + 600) / 400, 0, 1);
|
2022-06-10 08:17:09 +00:00
|
|
|
|
2022-06-10 09:37:53 +00:00
|
|
|
if (Clock.CurrentTime > HitTime + 200)
|
|
|
|
Expire();
|
|
|
|
}
|
2022-06-10 08:17:09 +00:00
|
|
|
}
|
2022-06-10 10:33:01 +00:00
|
|
|
|
|
|
|
private void attemptHit() => Schedule(() =>
|
|
|
|
{
|
|
|
|
if (HitEvent != null)
|
|
|
|
return;
|
|
|
|
|
2022-06-10 10:35:21 +00:00
|
|
|
// in case it was hit outside of display range, show immediately
|
|
|
|
// so the user isn't confused.
|
|
|
|
this.FadeIn();
|
|
|
|
|
2022-06-10 10:33:01 +00:00
|
|
|
approach.Expire();
|
|
|
|
|
|
|
|
circle
|
|
|
|
.FadeOut(200)
|
|
|
|
.ScaleTo(1.5f, 200);
|
|
|
|
|
|
|
|
HitEvent = new HitEvent(Clock.CurrentTime - HitTime, HitResult.Good, new HitObject
|
|
|
|
{
|
|
|
|
HitWindows = new HitWindows(),
|
|
|
|
}, null, null);
|
|
|
|
|
|
|
|
Hit?.Invoke(HitEvent.Value);
|
|
|
|
|
|
|
|
this.Delay(200).Expire();
|
|
|
|
});
|
2022-06-10 08:17:09 +00:00
|
|
|
}
|
2022-06-10 07:22:34 +00:00
|
|
|
}
|
|
|
|
}
|