1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Move the Shake logic to a new ShakeContainer

This commit is contained in:
tgi74000 2018-07-05 15:48:54 +02:00
parent f35ea18755
commit 558b2622a7
4 changed files with 43 additions and 12 deletions

View File

@ -8,6 +8,7 @@ using System.Linq;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Skinning;
using OpenTK.Graphics;
using osu.Game.Graphics.Containers;
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
@ -15,12 +16,24 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public override bool IsPresent => base.IsPresent || State.Value == ArmedState.Idle && Time.Current >= HitObject.StartTime - HitObject.TimePreempt;
private readonly ShakeContainer shakeContainer;
protected DrawableOsuHitObject(OsuHitObject hitObject)
: base(hitObject)
{
shakeContainer = new ShakeContainer
{
RelativeSizeAxes = Axes.Both,
};
base.AddInternal(shakeContainer);
Alpha = 0;
}
// Forward all internal management to shakeContainer
protected override void AddInternal(Drawable drawable) => shakeContainer.Add(drawable);
protected override void ClearInternal(bool disposeChildren = true) => shakeContainer.Clear(disposeChildren);
protected override bool RemoveInternal(Drawable drawable) => shakeContainer.Remove(drawable);
protected sealed override void UpdateState(ArmedState state)
{
double transformTime = HitObject.StartTime - HitObject.TimePreempt;
@ -61,15 +74,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
protected void Shake()
{
const int shake_amount = 8;
const int shake_duration = 20;
this.MoveToX(Position.X + shake_amount, shake_duration).Then()
.MoveToX(Position.X - shake_amount, shake_duration).Then()
.MoveToX(Position.X + shake_amount, shake_duration).Then()
.MoveToX(Position.X - shake_amount, shake_duration).Then()
.MoveToX(Position.X + shake_amount, shake_duration).Then()
.MoveToX(Position.X, shake_duration);
shakeContainer.Shake();
}
}

View File

@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
},
ticks = new Container<DrawableSliderTick> { RelativeSizeAxes = Axes.Both },
repeatPoints = new Container<DrawableRepeatPoint> { RelativeSizeAxes = Axes.Both },
Ball = new SliderBall(s)
Ball = new SliderBall(s, this)
{
BypassAutoSizeAxes = Axes.Both,
Scale = new Vector2(s.Scale),

View File

@ -34,9 +34,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
private readonly Slider slider;
public readonly Box FollowCircle;
private readonly Box ball;
private readonly DrawableSlider drawableSlider;
public SliderBall(Slider slider)
public SliderBall(Slider slider, DrawableSlider drawableSlider = null)
{
this.drawableSlider = drawableSlider;
this.slider = slider;
Masking = true;
AutoSizeAxes = Axes.Both;
@ -136,7 +138,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
Tracking = canCurrentlyTrack
&& lastState != null
&& base.ReceiveMouseInputAt(lastState.Mouse.NativeState.Position)
&& ((Parent as DrawableSlider)?.OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
&& (drawableSlider?.OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
}
}

View File

@ -0,0 +1,24 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Graphics.Containers
{
public class ShakeContainer : Container
{
public void Shake()
{
const int shake_amount = 8;
const int shake_duration = 20;
this.MoveToX(shake_amount, shake_duration).Then()
.MoveToX(-shake_amount, shake_duration).Then()
.MoveToX(shake_amount, shake_duration).Then()
.MoveToX(-shake_amount, shake_duration).Then()
.MoveToX(shake_amount, shake_duration).Then()
.MoveToX(0, shake_duration);
}
}
}