osu/osu.Game/Graphics/UserInterface/BackButton.cs

163 lines
5.8 KiB
C#
Raw Normal View History

2016-11-27 01:21:12 +00:00
// Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
2016-11-27 02:48:31 +00:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Containers;
2016-11-27 01:21:12 +00:00
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
namespace osu.Game.Graphics.UserInterface
{
// Basic back button as it was on stable (kinda). No skinning possible for now
2016-11-29 02:36:48 +00:00
public class BackButton : ClickableContainer
2016-11-27 01:21:12 +00:00
{
private TextAwesome icon;
2016-11-27 02:48:31 +00:00
2016-11-29 07:24:37 +00:00
private Container leftContainer;
private Container rightContainer;
2016-11-27 02:48:31 +00:00
2016-11-27 04:18:56 +00:00
private const double transform_time = 300.0;
2016-11-29 07:24:37 +00:00
private const int pulse_length = 250;
2016-11-29 02:36:48 +00:00
private const float shear = 0.1f;
2016-11-29 07:24:37 +00:00
private const int extend_length = 60;
private const int initial_extend_length = 40;
2016-11-29 02:36:48 +00:00
2016-11-29 07:24:37 +00:00
private const int width_extended = 140;
private const int width_retracted = 120;
2016-11-27 01:21:12 +00:00
public BackButton()
{
2016-11-29 02:36:48 +00:00
Width = width_retracted;
Height = 50; // same as bottomToolHeight in PlaySongSelect
2016-11-27 01:21:12 +00:00
Children = new Drawable[]
{
2016-11-27 03:50:36 +00:00
leftContainer = new Container
2016-11-27 02:48:31 +00:00
{
2016-11-27 03:50:36 +00:00
RelativeSizeAxes = Axes.Y,
2016-11-29 02:36:48 +00:00
Width = initial_extend_length,
2016-11-29 07:24:37 +00:00
Children = new Drawable[]
2016-11-27 03:50:36 +00:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
2016-11-29 02:36:48 +00:00
Colour = new Color4(195, 40, 140, 255),
Shear = new Vector2(shear, 0),
2016-11-27 03:50:36 +00:00
},
icon = new TextAwesome
{
Anchor = Anchor.Centre,
TextSize = 25,
Icon = FontAwesome.fa_osu_left_o
},
}
2016-11-27 02:48:31 +00:00
},
2016-11-27 03:50:36 +00:00
rightContainer = new Container
2016-11-27 02:48:31 +00:00
{
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
RelativeSizeAxes = Axes.Y,
Width = 80,
2016-11-29 02:36:48 +00:00
Position = Position + new Vector2(initial_extend_length, 0),
2016-11-27 02:48:31 +00:00
Children = new Drawable[]
{
2016-11-27 04:06:50 +00:00
new Box
2016-11-27 02:48:31 +00:00
{
2016-11-29 02:36:48 +00:00
Colour = new Color4(238, 51, 153, 255),
2016-11-27 02:48:31 +00:00
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
2016-11-29 07:24:37 +00:00
Shear = new Vector2(shear, 0),
EdgeSmoothness = new Vector2(1.5f, 0),
2016-11-27 02:48:31 +00:00
},
2016-11-27 03:50:36 +00:00
new SpriteText
2016-11-27 02:48:31 +00:00
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Text = @"Back",
}
}
2016-11-27 01:21:12 +00:00
}
};
}
protected override bool OnHover(InputState state)
{
icon.ClearTransformations();
2016-11-29 02:36:48 +00:00
rightContainer.MoveToX(Position.X + extend_length, transform_time, EasingTypes.OutElastic);
leftContainer.ResizeTo(new Vector2(extend_length, 1.0f), transform_time, EasingTypes.OutElastic);
2016-11-27 01:21:12 +00:00
2016-11-29 02:36:48 +00:00
Width = width_extended; // right container + ExtendLength
2016-11-27 01:21:12 +00:00
int duration = 0; //(int)(Game.Audio.BeatLength / 2);
2016-11-27 04:18:56 +00:00
if (duration == 0) duration = pulse_length;
2016-11-27 01:21:12 +00:00
double offset = 0; //(1 - Game.Audio.SyncBeatProgress) * duration;
double startTime = Time.Current + offset;
// basic pulse
icon.Transforms.Add(new TransformScale
{
2016-11-27 04:06:50 +00:00
StartValue = new Vector2(1.1f),
2016-11-27 01:21:12 +00:00
EndValue = Vector2.One,
StartTime = startTime,
EndTime = startTime + duration,
Easing = EasingTypes.Out,
LoopCount = -1,
LoopDelay = duration
});
2016-11-27 02:48:31 +00:00
return true;
2016-11-27 01:21:12 +00:00
}
protected override void OnHoverLost(InputState state)
{
icon.ClearTransformations();
2016-11-27 02:48:31 +00:00
2016-11-29 02:36:48 +00:00
rightContainer.MoveToX(Position.X + initial_extend_length, transform_time, EasingTypes.OutElastic);
leftContainer.ResizeTo(new Vector2(initial_extend_length, 1.0f), transform_time, EasingTypes.OutElastic);
2016-11-27 04:06:50 +00:00
2016-11-29 02:36:48 +00:00
Width = width_retracted; // right container + InitialExtendLength
2016-11-27 04:06:50 +00:00
int duration = 0; //(int)(Game.Audio.BeatLength / 2);
2016-11-27 04:18:56 +00:00
if (duration == 0) duration = pulse_length * 2;
2016-11-27 04:06:50 +00: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 02:48:31 +00:00
}
protected override bool OnClick(InputState state)
{
var flash = new Box
{
2016-11-29 02:36:48 +00:00
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(shear, 0),
2016-11-29 07:24:37 +00:00
Colour = new Color4(255, 255, 255, 128),
2016-11-27 02:48:31 +00:00
};
Add(flash);
flash.FadeOutFromOne(200);
flash.Expire();
2016-11-27 01:21:12 +00:00
2016-11-27 02:48:31 +00:00
return base.OnClick(state);
2016-11-27 01:21:12 +00:00
}
}
}