osu/osu.Game/Overlays/WaveOverlayContainer.cs

202 lines
5.9 KiB
C#
Raw Normal View History

2017-02-23 02:16:23 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework;
using OpenTK.Graphics;
2017-02-23 02:16:23 +00:00
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using OpenTK;
2017-02-28 06:25:38 +00:00
using osu.Framework.Graphics.Transforms;
2017-02-23 02:16:23 +00:00
namespace osu.Game.Overlays
{
public abstract class WaveOverlayContainer : FocusedOverlayContainer
2017-02-23 02:16:23 +00:00
{
protected const float APPEAR_DURATION = 800;
protected const float DISAPPEAR_DURATION = 500;
2017-02-23 03:42:31 +00:00
private const EasingTypes easing_show = EasingTypes.OutSine;
private const EasingTypes easing_hide = EasingTypes.InSine;
2017-02-23 02:16:23 +00:00
private Wave firstWave, secondWave, thirdWave, fourthWave;
private Container<Wave> wavesContainer;
2017-02-23 02:16:23 +00:00
private readonly Container contentContainer;
2017-02-23 03:42:31 +00:00
2017-02-23 02:16:23 +00:00
protected override Container<Drawable> Content => contentContainer;
2017-02-23 03:48:24 +00:00
protected Color4 FirstWaveColour
2017-02-23 02:16:23 +00:00
{
get
{
return firstWave.Colour;
2017-02-23 02:16:23 +00:00
}
set
{
if (firstWave.Colour == value) return;
2017-02-23 02:16:23 +00:00
firstWave.Colour = value;
}
}
2017-02-23 03:48:24 +00:00
protected Color4 SecondWaveColour
2017-02-23 02:16:23 +00:00
{
get
{
return secondWave.Colour;
2017-02-23 02:16:23 +00:00
}
set
{
if (secondWave.Colour == value) return;
2017-02-23 02:16:23 +00:00
secondWave.Colour = value;
}
}
2017-02-23 03:48:24 +00:00
protected Color4 ThirdWaveColour
2017-02-23 02:16:23 +00:00
{
get
{
return thirdWave.Colour;
2017-02-23 02:16:23 +00:00
}
set
{
if (thirdWave.Colour == value) return;
2017-02-23 02:16:23 +00:00
thirdWave.Colour = value;
}
}
2017-02-23 03:48:24 +00:00
protected Color4 FourthWaveColour
2017-02-23 02:16:23 +00:00
{
get
{
return fourthWave.Colour;
2017-02-23 02:16:23 +00:00
}
set
{
if (fourthWave.Colour == value) return;
2017-02-23 02:16:23 +00:00
fourthWave.Colour = value;
}
}
2017-02-23 03:48:24 +00:00
protected WaveOverlayContainer()
2017-02-23 02:16:23 +00:00
{
Masking = true;
AddInternal(wavesContainer = new Container<Wave>
2017-02-23 02:16:23 +00:00
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Children = new[]
2017-02-23 02:16:23 +00:00
{
2017-02-23 02:22:01 +00:00
firstWave = new Wave
2017-02-23 02:16:23 +00:00
{
Rotation = 13,
2017-02-23 03:42:31 +00:00
FinalPosition = -930,
2017-02-23 02:16:23 +00:00
},
2017-02-23 02:22:01 +00:00
secondWave = new Wave
2017-02-23 02:16:23 +00:00
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Rotation = -7,
2017-02-23 03:42:31 +00:00
FinalPosition = -560,
2017-02-23 02:16:23 +00:00
},
2017-02-23 02:22:01 +00:00
thirdWave = new Wave
2017-02-23 02:16:23 +00:00
{
Rotation = 4,
2017-02-23 03:42:31 +00:00
FinalPosition = -390,
2017-02-23 02:16:23 +00:00
},
2017-02-23 02:22:01 +00:00
fourthWave = new Wave
2017-02-23 02:16:23 +00:00
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Rotation = -2,
2017-02-23 03:42:31 +00:00
FinalPosition = -220,
2017-02-23 02:16:23 +00:00
},
},
});
AddInternal(contentContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
});
2017-02-23 02:22:01 +00:00
}
2017-02-23 03:42:31 +00:00
protected override void PopIn()
{
2017-03-03 22:05:43 +00:00
base.PopIn();
2017-02-23 03:42:31 +00:00
foreach (var w in wavesContainer.Children)
w.State = Visibility.Visible;
contentContainer.FadeIn(APPEAR_DURATION, EasingTypes.OutQuint);
contentContainer.MoveToY(0, APPEAR_DURATION, EasingTypes.OutQuint);
FadeIn(100, EasingTypes.OutQuint);
2017-02-23 03:42:31 +00:00
}
protected override void PopOut()
{
2017-03-03 22:05:43 +00:00
base.PopOut();
contentContainer.FadeOut(DISAPPEAR_DURATION, EasingTypes.In);
contentContainer.MoveToY(DrawHeight * 2f, DISAPPEAR_DURATION, EasingTypes.In);
2017-02-23 03:42:31 +00:00
foreach (var w in wavesContainer.Children)
w.State = Visibility.Hidden;
FadeOut(DISAPPEAR_DURATION, EasingTypes.InQuint);
2017-02-23 03:42:31 +00:00
}
2017-02-23 03:48:24 +00:00
private class Wave : Container, IStateful<Visibility>
2017-02-23 02:22:01 +00:00
{
public float FinalPosition;
2017-02-23 02:22:01 +00:00
public Wave()
{
RelativeSizeAxes = Axes.Both;
Size = new Vector2(1.5f);
Masking = true;
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(50),
Radius = 20f,
};
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
},
};
}
private Visibility state;
public Visibility State
{
get { return state; }
set
{
state = value;
switch (value)
{
case Visibility.Hidden:
MoveToY(DrawHeight / Height, DISAPPEAR_DURATION, easing_hide);
break;
case Visibility.Visible:
MoveToY(FinalPosition, APPEAR_DURATION, easing_show);
break;
}
}
}
2017-02-23 02:16:23 +00:00
}
}
}