1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 20:32:55 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3.1 KiB
C#
Raw Normal View History

// 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
using System;
2021-05-12 15:35:05 +08:00
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Mania.Objects.Drawables
{
2017-05-24 20:57:38 +08:00
/// <summary>
/// Visualises a <see cref="HoldNoteTick"/> hit object.
/// </summary>
public partial class DrawableHoldNoteTick : DrawableManiaHitObject<HoldNoteTick>
{
2017-05-24 20:57:38 +08:00
/// <summary>
/// References the time at which the user started holding the hold note.
/// </summary>
2021-05-12 15:35:05 +08:00
private Func<double?> holdStartTime;
private Container glowContainer;
public DrawableHoldNoteTick()
: this(null)
{
}
2018-04-13 17:19:50 +08:00
public DrawableHoldNoteTick(HoldNoteTick hitObject)
2017-05-24 20:25:01 +08:00
: base(hitObject)
{
Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre;
2018-04-13 17:19:50 +08:00
RelativeSizeAxes = Axes.X;
2021-05-12 15:35:05 +08:00
}
2018-04-13 17:19:50 +08:00
2021-05-12 15:35:05 +08:00
[BackgroundDependencyLoader]
private void load()
{
2021-05-12 15:40:46 +08:00
AddInternal(glowContainer = new CircularContainer
{
2021-05-12 15:40:46 +08:00
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new[]
{
2021-05-12 15:40:46 +08:00
new Box
{
2021-05-12 15:40:46 +08:00
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
}
}
2021-05-12 15:40:46 +08:00
});
2021-05-12 15:35:05 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2018-04-13 17:19:50 +08:00
2019-07-22 13:45:25 +08:00
AccentColour.BindValueChanged(colour =>
{
2017-06-12 11:48:47 +08:00
glowContainer.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Radius = 2f,
Roundness = 15f,
2019-07-22 13:45:25 +08:00
Colour = colour.NewValue.Opacity(0.3f)
};
2019-07-22 13:45:25 +08:00
}, true);
}
2018-04-13 17:19:50 +08:00
2021-05-12 15:35:05 +08:00
protected override void OnApply()
{
base.OnApply();
Debug.Assert(ParentHitObject != null);
var holdNote = (DrawableHoldNote)ParentHitObject;
holdStartTime = () => holdNote.HoldStartTime;
}
protected override void OnFree()
{
base.OnFree();
holdStartTime = null;
}
protected override void CheckForResult(bool userTriggered, double timeOffset)
{
if (Time.Current < HitObject.StartTime)
return;
2018-04-13 17:19:50 +08:00
double? startTime = holdStartTime?.Invoke();
2018-04-13 17:19:50 +08:00
if (startTime == null || startTime > HitObject.StartTime)
2020-09-29 13:29:43 +08:00
ApplyResult(r => r.Type = r.Judgement.MinResult);
else
2020-09-29 13:29:43 +08:00
ApplyResult(r => r.Type = r.Judgement.MaxResult);
}
}
}