1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 02:03:51 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/BackButton.cs

167 lines
5.6 KiB
C#
Raw Normal View History

2016-12-06 17:56:20 +08:00
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-11-27 09:21:12 +08:00
2016-12-05 20:09:41 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
2016-11-27 09:21:12 +08:00
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
2016-11-27 10:48:31 +08:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Containers;
2016-11-27 09:21:12 +08:00
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
2016-11-27 09:21:12 +08:00
namespace osu.Game.Graphics.UserInterface
{
// Basic back button as it was on stable (kinda). No skinning possible for now
2016-11-29 10:36:48 +08:00
public class BackButton : ClickableContainer
2016-11-27 09:21:12 +08:00
{
private TextAwesome icon;
2016-11-27 10:48:31 +08:00
private Box leftBox;
private Box rightBox;
private const double transform_time = 600;
2016-11-29 15:24:37 +08:00
private const int pulse_length = 250;
2016-11-29 10:36:48 +08:00
2017-01-30 14:28:47 +08:00
private const float shear = 0.15f;
2016-11-29 10:36:48 +08:00
public static readonly Vector2 SIZE_EXTENDED = new Vector2(140, 50);
public static readonly Vector2 SIZE_RETRACTED = new Vector2(100, 50);
2016-12-05 20:09:41 +08:00
private AudioSample sampleClick;
2016-11-27 09:21:12 +08:00
public BackButton()
{
Size = SIZE_RETRACTED;
2016-11-27 09:21:12 +08:00
}
public override bool Contains(Vector2 screenSpacePos) => leftBox.Contains(screenSpacePos) || rightBox.Contains(screenSpacePos);
2016-11-27 09:21:12 +08:00
protected override bool OnHover(InputState state)
{
icon.ClearTransformations();
ResizeTo(SIZE_EXTENDED, transform_time, EasingTypes.OutElastic);
2016-11-27 09:21:12 +08:00
int duration = 0; //(int)(Game.Audio.BeatLength / 2);
2016-11-27 12:18:56 +08:00
if (duration == 0) duration = pulse_length;
2016-11-27 09:21:12 +08:00
double offset = 0; //(1 - Game.Audio.SyncBeatProgress) * duration;
double startTime = Time.Current + offset;
// basic pulse
icon.Transforms.Add(new TransformScale
{
2016-11-27 12:06:50 +08:00
StartValue = new Vector2(1.1f),
2016-11-27 09:21:12 +08:00
EndValue = Vector2.One,
StartTime = startTime,
EndTime = startTime + duration,
Easing = EasingTypes.Out,
LoopCount = -1,
LoopDelay = duration
});
2016-11-27 10:48:31 +08:00
return true;
2016-11-27 09:21:12 +08:00
}
protected override void OnHoverLost(InputState state)
{
icon.ClearTransformations();
2016-11-27 10:48:31 +08:00
ResizeTo(SIZE_RETRACTED, transform_time, EasingTypes.OutElastic);
2016-11-27 12:06:50 +08:00
2016-11-30 01:27:59 +08:00
int duration = 0; //(int)(Game.Audio.BeatLength);
2016-11-27 12:18:56 +08:00
if (duration == 0) duration = pulse_length * 2;
2016-11-27 12:06:50 +08:00
double offset = 0; //(1 - Game.Audio.SyncBeatProgress) * duration;
double startTime = Time.Current + offset;
// slow pulse
icon.Transforms.Add(new TransformScale
{
StartValue = new Vector2(1.1f),
EndValue = Vector2.One,
StartTime = startTime,
EndTime = startTime + duration,
Easing = EasingTypes.Out,
LoopCount = -1,
LoopDelay = duration
});
2016-11-27 10:48:31 +08:00
}
2016-12-05 20:09:41 +08:00
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours)
2016-12-05 20:09:41 +08:00
{
sampleClick = audio.Sample.Get(@"Menu/menuback");
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Width = 0.4f,
Children = new Drawable[]
{
leftBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.PinkDark,
Shear = new Vector2(shear, 0),
},
icon = new TextAwesome
{
Anchor = Anchor.Centre,
TextSize = 25,
Icon = FontAwesome.fa_osu_left_o
},
}
},
new Container
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Width = 0.6f,
Children = new Drawable[]
{
rightBox = new Box
{
Colour = colours.Pink,
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(shear, 0),
EdgeSmoothness = new Vector2(1.5f, 0),
},
new OsuSpriteText
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Text = @"Back",
}
}
}
};
2016-12-05 20:09:41 +08:00
}
2016-11-27 10:48:31 +08:00
protected override bool OnClick(InputState state)
{
var flash = new Box
{
2016-11-29 10:36:48 +08:00
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(shear, 0),
2017-01-11 02:44:40 +08:00
Colour = Color4.White.Opacity(0.5f),
2016-11-27 10:48:31 +08:00
};
Add(flash);
flash.FadeOutFromOne(200);
flash.Expire();
2016-11-27 09:21:12 +08:00
2016-12-05 20:09:41 +08:00
sampleClick.Play();
2016-11-27 10:48:31 +08:00
return base.OnClick(state);
2016-11-27 09:21:12 +08:00
}
}
}