mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 10:23:03 +08:00
Move the Shake logic to a new ShakeContainer
This commit is contained in:
parent
f35ea18755
commit
558b2622a7
@ -8,6 +8,7 @@ using System.Linq;
|
|||||||
using osu.Game.Rulesets.Objects.Types;
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
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;
|
public override bool IsPresent => base.IsPresent || State.Value == ArmedState.Idle && Time.Current >= HitObject.StartTime - HitObject.TimePreempt;
|
||||||
|
|
||||||
|
private readonly ShakeContainer shakeContainer;
|
||||||
|
|
||||||
protected DrawableOsuHitObject(OsuHitObject hitObject)
|
protected DrawableOsuHitObject(OsuHitObject hitObject)
|
||||||
: base(hitObject)
|
: base(hitObject)
|
||||||
{
|
{
|
||||||
|
shakeContainer = new ShakeContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
};
|
||||||
|
base.AddInternal(shakeContainer);
|
||||||
Alpha = 0;
|
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)
|
protected sealed override void UpdateState(ArmedState state)
|
||||||
{
|
{
|
||||||
double transformTime = HitObject.StartTime - HitObject.TimePreempt;
|
double transformTime = HitObject.StartTime - HitObject.TimePreempt;
|
||||||
@ -61,15 +74,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
|
|
||||||
protected void Shake()
|
protected void Shake()
|
||||||
{
|
{
|
||||||
const int shake_amount = 8;
|
shakeContainer.Shake();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
},
|
},
|
||||||
ticks = new Container<DrawableSliderTick> { RelativeSizeAxes = Axes.Both },
|
ticks = new Container<DrawableSliderTick> { RelativeSizeAxes = Axes.Both },
|
||||||
repeatPoints = new Container<DrawableRepeatPoint> { RelativeSizeAxes = Axes.Both },
|
repeatPoints = new Container<DrawableRepeatPoint> { RelativeSizeAxes = Axes.Both },
|
||||||
Ball = new SliderBall(s)
|
Ball = new SliderBall(s, this)
|
||||||
{
|
{
|
||||||
BypassAutoSizeAxes = Axes.Both,
|
BypassAutoSizeAxes = Axes.Both,
|
||||||
Scale = new Vector2(s.Scale),
|
Scale = new Vector2(s.Scale),
|
||||||
|
@ -34,9 +34,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
private readonly Slider slider;
|
private readonly Slider slider;
|
||||||
public readonly Box FollowCircle;
|
public readonly Box FollowCircle;
|
||||||
private readonly Box ball;
|
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;
|
this.slider = slider;
|
||||||
Masking = true;
|
Masking = true;
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
@ -136,7 +138,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
Tracking = canCurrentlyTrack
|
Tracking = canCurrentlyTrack
|
||||||
&& lastState != null
|
&& lastState != null
|
||||||
&& base.ReceiveMouseInputAt(lastState.Mouse.NativeState.Position)
|
&& 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
osu.Game/Graphics/Containers/ShakeContainer.cs
Normal file
24
osu.Game/Graphics/Containers/ShakeContainer.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user