2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-01-27 20:57:22 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-02-03 12:16:45 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-05-24 21:05:24 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
|
using osu.Framework.Audio.Track;
|
|
|
|
|
using System;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-01-27 20:57:22 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2017-06-27 20:05:49 +08:00
|
|
|
|
public class TwoLayerButton : OsuClickableContainer
|
2017-01-27 20:57:22 +08:00
|
|
|
|
{
|
2017-05-26 18:46:44 +08:00
|
|
|
|
private readonly BouncingIcon bouncingIcon;
|
2017-01-27 20:57:22 +08:00
|
|
|
|
|
|
|
|
|
public Box IconLayer;
|
|
|
|
|
public Box TextLayer;
|
|
|
|
|
|
|
|
|
|
private const int transform_time = 600;
|
|
|
|
|
private const int pulse_length = 250;
|
|
|
|
|
|
|
|
|
|
private const float shear = 0.1f;
|
|
|
|
|
|
|
|
|
|
public static readonly Vector2 SIZE_EXTENDED = new Vector2(140, 50);
|
|
|
|
|
public static readonly Vector2 SIZE_RETRACTED = new Vector2(100, 50);
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly SpriteText text;
|
2017-01-27 20:57:22 +08:00
|
|
|
|
|
|
|
|
|
public Color4 HoverColour;
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Container c1;
|
|
|
|
|
private readonly Container c2;
|
2017-01-27 20:57:22 +08:00
|
|
|
|
|
2017-02-24 05:33:37 +08:00
|
|
|
|
public Color4 BackgroundColour
|
2017-01-27 20:57:22 +08:00
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
TextLayer.Colour = value;
|
|
|
|
|
IconLayer.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Anchor Origin
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return base.Origin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.Origin = value;
|
|
|
|
|
c1.Origin = c1.Anchor = (value & Anchor.x2) > 0 ? Anchor.TopLeft : Anchor.TopRight;
|
|
|
|
|
c2.Origin = c2.Anchor = (value & Anchor.x2) > 0 ? Anchor.TopRight : Anchor.TopLeft;
|
|
|
|
|
|
2017-03-03 02:16:31 +08:00
|
|
|
|
X = (value & Anchor.x2) > 0 ? SIZE_RETRACTED.X * shear * 0.5f : 0;
|
2017-01-27 20:57:22 +08:00
|
|
|
|
|
2017-06-19 06:50:26 +08:00
|
|
|
|
Remove(c1);
|
|
|
|
|
Remove(c2);
|
2017-01-27 20:57:22 +08:00
|
|
|
|
c1.Depth = (value & Anchor.x2) > 0 ? 0 : 1;
|
|
|
|
|
c2.Depth = (value & Anchor.x2) > 0 ? 1 : 0;
|
2017-06-19 06:50:26 +08:00
|
|
|
|
Add(c1);
|
|
|
|
|
Add(c2);
|
2017-01-27 20:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TwoLayerButton()
|
|
|
|
|
{
|
|
|
|
|
Size = SIZE_RETRACTED;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
c2 = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.4f,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-06-12 11:48:47 +08:00
|
|
|
|
new Container
|
|
|
|
|
{
|
2017-01-27 20:57:22 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Shear = new Vector2(shear, 0),
|
|
|
|
|
Masking = true,
|
2017-02-04 18:06:26 +08:00
|
|
|
|
MaskingSmoothness = 2,
|
2017-06-12 11:48:47 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
2017-01-27 20:57:22 +08:00
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.2f),
|
|
|
|
|
Offset = new Vector2(2, 0),
|
|
|
|
|
Radius = 2,
|
|
|
|
|
},
|
2017-06-12 11:48:47 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-01-27 20:57:22 +08:00
|
|
|
|
IconLayer = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-04 18:06:26 +08:00
|
|
|
|
EdgeSmoothness = new Vector2(2, 0),
|
2017-01-27 20:57:22 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-05-26 18:46:44 +08:00
|
|
|
|
bouncingIcon = new BouncingIcon
|
2017-01-27 20:57:22 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-06 16:06:48 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2017-01-27 20:57:22 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
c1 = new Container
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.6f,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-06-12 11:48:47 +08:00
|
|
|
|
new Container
|
|
|
|
|
{
|
2017-01-27 20:57:22 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Shear = new Vector2(shear, 0),
|
|
|
|
|
Masking = true,
|
2017-02-04 18:06:26 +08:00
|
|
|
|
MaskingSmoothness = 2,
|
2017-06-12 11:48:47 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
2017-01-27 20:57:22 +08:00
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.2f),
|
|
|
|
|
Offset = new Vector2(2, 0),
|
|
|
|
|
Radius = 2,
|
|
|
|
|
},
|
2017-06-12 11:48:47 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-01-27 20:57:22 +08:00
|
|
|
|
TextLayer = new Box
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-04 18:06:26 +08:00
|
|
|
|
EdgeSmoothness = new Vector2(2, 0),
|
2017-01-27 20:57:22 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-02-03 12:16:07 +08:00
|
|
|
|
text = new OsuSpriteText
|
2017-01-27 20:57:22 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FontAwesome Icon
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-05-26 18:46:44 +08:00
|
|
|
|
bouncingIcon.Icon = value;
|
2017-01-27 20:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
text.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-30 14:54:03 +08:00
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => IconLayer.ReceiveMouseInputAt(screenSpacePos) || TextLayer.ReceiveMouseInputAt(screenSpacePos);
|
2017-01-27 20:57:22 +08:00
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
this.ResizeTo(SIZE_EXTENDED, transform_time, Easing.OutElastic);
|
|
|
|
|
IconLayer.FadeColour(HoverColour, transform_time, Easing.OutElastic);
|
2017-01-27 20:57:22 +08:00
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
bouncingIcon.ScaleTo(1.1f, transform_time, Easing.OutElastic);
|
2017-05-26 19:29:45 +08:00
|
|
|
|
|
2017-01-27 20:57:22 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
this.ResizeTo(SIZE_RETRACTED, transform_time, Easing.OutElastic);
|
|
|
|
|
IconLayer.FadeColour(TextLayer.Colour, transform_time, Easing.OutElastic);
|
2017-05-26 19:29:45 +08:00
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
bouncingIcon.ScaleTo(1, transform_time, Easing.OutElastic);
|
2017-01-27 20:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 16:57:40 +08:00
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-27 20:57:22 +08:00
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
|
|
|
|
var flash = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Shear = new Vector2(shear, 0),
|
|
|
|
|
Colour = Color4.White.Opacity(0.5f),
|
|
|
|
|
};
|
|
|
|
|
Add(flash);
|
|
|
|
|
|
|
|
|
|
flash.Alpha = 1;
|
2017-07-23 02:50:25 +08:00
|
|
|
|
flash.FadeOut(500, Easing.OutQuint);
|
2017-01-27 20:57:22 +08:00
|
|
|
|
flash.Expire();
|
|
|
|
|
|
|
|
|
|
return base.OnClick(state);
|
|
|
|
|
}
|
2017-05-24 21:05:24 +08:00
|
|
|
|
|
2017-05-26 18:46:44 +08:00
|
|
|
|
private class BouncingIcon : BeatSyncedContainer
|
2017-05-24 21:05:24 +08:00
|
|
|
|
{
|
|
|
|
|
private const double beat_in_time = 60;
|
|
|
|
|
|
2017-08-03 13:36:21 +08:00
|
|
|
|
private readonly SpriteIcon icon;
|
2017-05-24 21:05:24 +08:00
|
|
|
|
|
|
|
|
|
public FontAwesome Icon { set { icon.Icon = value; } }
|
|
|
|
|
|
2017-05-26 18:46:44 +08:00
|
|
|
|
public BouncingIcon()
|
2017-05-24 21:05:24 +08:00
|
|
|
|
{
|
|
|
|
|
EarlyActivationMilliseconds = beat_in_time;
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
|
icon = new SpriteIcon
|
2017-05-24 21:05:24 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Size = new Vector2(25),
|
2017-05-26 18:46:44 +08:00
|
|
|
|
}
|
2017-05-24 21:05:24 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
|
|
|
|
|
{
|
|
|
|
|
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
|
|
|
|
|
|
|
|
|
|
var beatLength = timingPoint.BeatLength;
|
|
|
|
|
|
|
|
|
|
float amplitudeAdjust = Math.Min(1, 0.4f + amplitudes.Maximum);
|
|
|
|
|
|
|
|
|
|
if (beatIndex < 0) return;
|
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
icon.ScaleTo(1 - 0.1f * amplitudeAdjust, beat_in_time, Easing.Out)
|
2017-07-16 23:28:20 +08:00
|
|
|
|
.Then()
|
2017-07-23 02:50:25 +08:00
|
|
|
|
.ScaleTo(1, beatLength * 2, Easing.OutQuint);
|
2017-05-24 21:05:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-27 20:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|