1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 19:32:58 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs

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

210 lines
6.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;
2020-12-15 06:02:33 +08:00
using JetBrains.Annotations;
using osu.Framework.Allocation;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
using osu.Game.Graphics;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects.Drawables;
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
2021-09-16 17:26:12 +08:00
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
2020-12-07 11:30:25 +08:00
using osu.Game.Rulesets.Taiko.Skinning.Default;
using osu.Game.Skinning;
using osuTK;
2018-04-13 17:19:50 +08:00
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{
public class DrawableDrumRoll : DrawableTaikoStrongableHitObject<DrumRoll, DrumRoll.StrongNestedHit>
{
/// <summary>
/// Number of rolling hits required to reach the dark/final colour.
/// </summary>
private const int rolling_hits_for_engaged_colour = 5;
2018-04-13 17:19:50 +08:00
public override Quad ScreenSpaceDrawQuad => MainPiece.Drawable.ScreenSpaceDrawQuad;
/// <summary>
2017-04-01 15:34:30 +08:00
/// Rolling number of tick hits. This increases for hits and decreases for misses.
/// </summary>
2017-04-01 15:32:31 +08:00
private int rollingHits;
2018-04-13 17:19:50 +08:00
2020-12-15 06:02:33 +08:00
private readonly Container tickContainer;
private Color4 colourIdle;
private Color4 colourEngaged;
public override bool DisplayResult => false;
2020-12-15 06:02:33 +08:00
public DrawableDrumRoll()
: this(null)
{
}
2020-12-15 06:02:33 +08:00
public DrawableDrumRoll([CanBeNull] DrumRoll drumRoll)
: base(drumRoll)
{
2020-12-15 06:02:33 +08:00
RelativeSizeAxes = Axes.Y;
Content.Add(tickContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Depth = float.MinValue
});
}
2020-12-15 06:02:33 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
colourIdle = colours.YellowDark;
colourEngaged = colours.YellowDarker;
}
protected override void LoadComplete()
{
base.LoadComplete();
OnNewResult += onNewResult;
}
protected override void RecreatePieces()
{
base.RecreatePieces();
updateColour();
}
2020-12-15 06:02:33 +08:00
protected override void OnFree()
{
base.OnFree();
rollingHits = 0;
}
protected override void AddNestedHitObject(DrawableHitObject hitObject)
{
base.AddNestedHitObject(hitObject);
2018-04-13 17:19:50 +08:00
2019-10-17 11:53:54 +08:00
switch (hitObject)
{
case DrawableDrumRollTick tick:
tickContainer.Add(tick);
break;
}
}
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
tickContainer.Clear(false);
}
2018-04-13 17:19:50 +08:00
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case DrumRollTick tick:
return new DrawableDrumRollTick(tick);
}
return base.CreateNestedHitObject(hitObject);
}
2018-04-13 17:19:50 +08:00
protected override SkinnableDrawable CreateMainPiece() => new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.DrumRollBody),
_ => new ElongatedCirclePiece());
2018-04-13 17:19:50 +08:00
2021-09-16 17:26:12 +08:00
public override bool OnPressed(KeyBindingPressEvent<TaikoAction> e) => false;
2018-04-13 17:19:50 +08:00
private void onNewResult(DrawableHitObject obj, JudgementResult result)
{
if (!(obj is DrawableDrumRollTick))
return;
2018-04-13 17:19:50 +08:00
if (result.IsHit)
2017-04-01 15:32:31 +08:00
rollingHits++;
else
2017-04-01 15:32:31 +08:00
rollingHits--;
2018-04-13 17:19:50 +08:00
rollingHits = Math.Clamp(rollingHits, 0, rolling_hits_for_engaged_colour);
2018-04-13 17:19:50 +08:00
2020-12-15 06:02:33 +08:00
updateColour(100);
}
2018-04-13 17:19:50 +08:00
protected override void CheckForResult(bool userTriggered, double timeOffset)
{
if (userTriggered)
return;
2018-04-13 17:19:50 +08:00
if (timeOffset < 0)
return;
2018-04-13 17:19:50 +08:00
2022-08-30 20:44:44 +08:00
ApplyResult(r => r.Type = r.Judgement.MaxResult);
}
2018-04-13 17:19:50 +08:00
2020-11-04 15:19:07 +08:00
protected override void UpdateHitStateTransforms(ArmedState state)
2017-03-28 15:50:06 +08:00
{
2018-01-10 18:17:43 +08:00
switch (state)
{
case ArmedState.Hit:
case ArmedState.Miss:
2020-11-04 15:19:07 +08:00
this.FadeOut(100);
2018-01-10 18:17:43 +08:00
break;
}
2017-03-28 15:50:06 +08:00
}
protected override void Update()
{
base.Update();
OriginPosition = new Vector2(DrawHeight);
Content.X = DrawHeight / 2;
}
protected override DrawableStrongNestedHit CreateStrongNestedHit(DrumRoll.StrongNestedHit hitObject) => new StrongNestedHit(hitObject);
2018-08-03 15:56:46 +08:00
2020-12-15 06:02:33 +08:00
private void updateColour(double fadeDuration = 0)
2020-04-15 17:44:12 +08:00
{
Color4 newColour = Interpolation.ValueAt((float)rollingHits / rolling_hits_for_engaged_colour, colourIdle, colourEngaged, 0, 1);
2020-12-15 06:02:33 +08:00
(MainPiece.Drawable as IHasAccentColour)?.FadeAccent(newColour, fadeDuration);
2020-04-15 17:44:12 +08:00
}
public class StrongNestedHit : DrawableStrongNestedHit
2018-08-03 15:56:46 +08:00
{
public new DrawableDrumRoll ParentHitObject => (DrawableDrumRoll)base.ParentHitObject;
public StrongNestedHit()
: this(null)
{
}
public StrongNestedHit([CanBeNull] DrumRoll.StrongNestedHit nestedHit)
: base(nestedHit)
2018-08-03 15:56:46 +08:00
{
}
protected override void CheckForResult(bool userTriggered, double timeOffset)
2018-08-03 15:56:46 +08:00
{
if (!ParentHitObject.Judged)
2018-08-03 15:56:46 +08:00
return;
ApplyResult(r => r.Type = ParentHitObject.IsHit ? r.Judgement.MaxResult : r.Judgement.MinResult);
2018-08-03 15:56:46 +08:00
}
public override void OnKilled()
{
base.OnKilled();
if (Time.Current > ParentHitObject.HitObject.GetEndTime() && !Judged)
ApplyResult(r => r.Type = r.Judgement.MinResult);
}
2021-09-16 17:26:12 +08:00
public override bool OnPressed(KeyBindingPressEvent<TaikoAction> e) => false;
2018-08-03 15:56:46 +08:00
}
}
}