2017-02-07 04:59:30 +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
|
2016-12-06 09:56:20 +00:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-09-30 09:45:55 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using OpenTK;
|
2016-11-08 23:13:20 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-02-18 20:34:21 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2017-02-19 16:11:31 +00:00
|
|
|
|
using osu.Framework.Configuration;
|
2016-09-30 09:45:55 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
|
{
|
2017-03-23 10:22:40 +00:00
|
|
|
|
internal class ParallaxContainer : Container, IRequireHighFrequencyMousePosition
|
2016-09-30 09:45:55 +00:00
|
|
|
|
{
|
2017-02-18 21:00:07 +00:00
|
|
|
|
public float ParallaxAmount = 0.02f;
|
2017-02-18 21:26:48 +00:00
|
|
|
|
|
2017-02-19 16:11:31 +00:00
|
|
|
|
private Bindable<bool> parallaxEnabled;
|
2016-09-30 09:45:55 +00:00
|
|
|
|
|
2016-10-01 09:40:14 +00:00
|
|
|
|
public ParallaxContainer()
|
2016-09-30 09:45:55 +00:00
|
|
|
|
{
|
2016-10-01 09:40:14 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2016-11-10 22:40:42 +00:00
|
|
|
|
AddInternal(content = new Container
|
2016-11-08 23:13:20 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
|
});
|
2016-09-30 09:45:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly Container content;
|
2016-11-24 06:30:55 +00:00
|
|
|
|
private InputManager input;
|
2016-11-10 22:40:42 +00:00
|
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
2016-11-24 06:30:55 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-02-18 20:34:21 +00:00
|
|
|
|
private void load(UserInputManager input, OsuConfigManager config)
|
2016-09-30 09:45:55 +00:00
|
|
|
|
{
|
2016-11-24 06:30:55 +00:00
|
|
|
|
this.input = input;
|
2017-05-15 01:56:27 +00:00
|
|
|
|
parallaxEnabled = config.GetBindable<bool>(OsuSetting.MenuParallax);
|
2017-02-19 16:11:31 +00:00
|
|
|
|
parallaxEnabled.ValueChanged += delegate
|
2017-02-18 20:34:21 +00:00
|
|
|
|
{
|
2017-02-19 12:47:26 +00:00
|
|
|
|
if (!parallaxEnabled)
|
|
|
|
|
{
|
|
|
|
|
content.MoveTo(Vector2.Zero, firstUpdate ? 0 : 1000, EasingTypes.OutQuint);
|
2017-02-19 16:11:31 +00:00
|
|
|
|
content.Scale = new Vector2(1 + ParallaxAmount);
|
2017-02-19 12:47:26 +00:00
|
|
|
|
}
|
2017-02-18 20:34:21 +00:00
|
|
|
|
};
|
2016-09-30 09:45:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 01:59:19 +00:00
|
|
|
|
private bool firstUpdate = true;
|
2016-12-01 12:59:32 +00:00
|
|
|
|
|
2016-09-30 09:45:55 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2016-12-01 12:59:32 +00:00
|
|
|
|
|
2017-04-06 08:21:18 +00:00
|
|
|
|
if (parallaxEnabled)
|
|
|
|
|
{
|
2017-02-18 21:00:07 +00:00
|
|
|
|
Vector2 offset = input.CurrentState.Mouse == null ? Vector2.Zero : ToLocalSpace(input.CurrentState.Mouse.NativeState.Position) - DrawSize / 2;
|
|
|
|
|
content.MoveTo(offset * ParallaxAmount, firstUpdate ? 0 : 1000, EasingTypes.OutQuint);
|
|
|
|
|
content.Scale = new Vector2(1 + ParallaxAmount);
|
|
|
|
|
}
|
2016-12-01 12:59:32 +00:00
|
|
|
|
|
|
|
|
|
firstUpdate = false;
|
2016-09-30 09:45:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-08 23:46:08 +00:00
|
|
|
|
}
|