1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 23:32:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableHitCircle.cs

149 lines
4.9 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
2016-11-02 11:22:29 +08:00
using OpenTK;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Scoring;
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public class DrawableHitCircle : DrawableOsuHitObject, IDrawableHitObjectWithProxiedApproach
{
public ApproachCircle ApproachCircle;
private readonly CirclePiece circle;
private readonly RingPiece ring;
private readonly FlashPiece flash;
private readonly ExplodePiece explode;
private readonly NumberPiece number;
private readonly GlowPiece glow;
public DrawableHitCircle(HitCircle h) : base(h)
{
Origin = Anchor.Centre;
Position = HitObject.StackedPosition;
2018-01-01 18:55:24 +08:00
Scale = new Vector2(h.Scale);
2016-11-14 17:54:24 +08:00
Children = new Drawable[]
{
glow = new GlowPiece
{
Colour = AccentColour
},
circle = new CirclePiece
{
Colour = AccentColour,
Hit = () =>
{
if (AllJudged)
return false;
UpdateJudgement(true);
return true;
},
},
2017-03-07 09:59:19 +08:00
number = new NumberPiece
2017-02-15 22:23:55 +08:00
{
2018-01-03 14:12:27 +08:00
Text = (HitObject.IndexInCurrentCombo + 1).ToString(),
2017-02-15 22:23:55 +08:00
},
ring = new RingPiece(),
flash = new FlashPiece(),
explode = new ExplodePiece
{
Colour = AccentColour,
},
2017-03-07 09:59:19 +08:00
ApproachCircle = new ApproachCircle
{
Alpha = 0,
Scale = new Vector2(4),
Colour = AccentColour,
}
};
2016-11-28 11:40:24 +08:00
//may not be so correct
Size = circle.DrawSize;
2018-03-09 22:12:34 +08:00
HitObject.PositionChanged += _ => Position = HitObject.StackedPosition;
}
protected override void CheckForJudgements(bool userTriggered, double timeOffset)
{
if (!userTriggered)
{
2018-02-02 19:31:39 +08:00
if (!HitObject.HitWindows.CanBeHit(timeOffset))
AddJudgement(new OsuJudgement { Result = HitResult.Miss });
return;
}
2018-02-02 19:31:39 +08:00
var result = HitObject.HitWindows.ResultFor(timeOffset);
2018-02-08 13:25:59 +08:00
if (result == HitResult.None)
2018-02-02 19:31:39 +08:00
return;
AddJudgement(new OsuJudgement
{
2018-02-08 13:25:59 +08:00
Result = result,
PositionOffset = Vector2.Zero //todo: set to correct value
});
}
protected override void UpdatePreemptState()
{
base.UpdatePreemptState();
2018-01-01 00:30:58 +08:00
ApproachCircle.FadeIn(Math.Min(HitObject.TimeFadein * 2, HitObject.TimePreempt));
2018-01-01 00:15:14 +08:00
ApproachCircle.ScaleTo(1.1f, HitObject.TimePreempt);
}
protected override void UpdateCurrentState(ArmedState state)
{
glow.FadeOut(400);
switch (state)
{
case ArmedState.Idle:
2018-01-01 00:15:14 +08:00
this.Delay(HitObject.TimePreempt).FadeOut(500);
Expire(true);
// override lifetime end as FadeIn may have been changed externally, causing out expiration to be too early.
2018-02-02 19:31:39 +08:00
LifetimeEnd = HitObject.StartTime + HitObject.HitWindows.HalfWindowFor(HitResult.Miss);
break;
case ArmedState.Miss:
ApproachCircle.FadeOut(50);
this.FadeOut(100);
Expire();
break;
case ArmedState.Hit:
ApproachCircle.FadeOut(50);
const double flash_in = 40;
2017-07-16 23:28:20 +08:00
flash.FadeTo(0.8f, flash_in)
.Then()
.FadeOut(100);
explode.FadeIn(flash_in);
2017-07-16 23:28:20 +08:00
using (BeginDelayedSequence(flash_in, true))
{
//after the flash, we can hide some elements that were behind it
ring.FadeOut();
circle.FadeOut();
number.FadeOut();
this.FadeOut(800)
2017-07-23 02:50:25 +08:00
.ScaleTo(Scale * 1.5f, 400, Easing.OutQuad);
2017-07-16 23:28:20 +08:00
}
Expire();
break;
}
}
public Drawable ProxiedLayer => ApproachCircle;
}
}