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
|
2016-10-27 18:52:48 +08:00
|
|
|
|
|
2017-09-04 08:10:04 +08:00
|
|
|
|
using System;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
using osu.Framework;
|
2017-11-26 03:16:36 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2017-11-26 03:16:36 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input;
|
2016-11-05 19:00:14 +08:00
|
|
|
|
using OpenTK;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-11-26 03:16:36 +08:00
|
|
|
|
using osu.Framework.MathUtils;
|
2017-11-26 03:16:36 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
|
2016-11-23 10:59:50 +08:00
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
2016-10-27 18:52:48 +08:00
|
|
|
|
{
|
2017-03-17 18:54:51 +08:00
|
|
|
|
public class Panel : Container, IStateful<PanelSelectedState>
|
2016-10-27 18:52:48 +08:00
|
|
|
|
{
|
2016-11-23 04:40:47 +08:00
|
|
|
|
public const float MAX_HEIGHT = 80;
|
|
|
|
|
|
2017-09-04 08:10:04 +08:00
|
|
|
|
public event Action<PanelSelectedState> StateChanged;
|
|
|
|
|
|
2016-11-25 17:14:56 +08:00
|
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Container nestedContainer;
|
2016-11-23 04:40:47 +08:00
|
|
|
|
|
2017-11-26 03:16:36 +08:00
|
|
|
|
private readonly Container borderContainer;
|
|
|
|
|
|
|
|
|
|
private readonly Box hoverLayer;
|
|
|
|
|
|
2016-11-23 10:59:50 +08:00
|
|
|
|
protected override Container<Drawable> Content => nestedContainer;
|
2016-11-23 04:40:47 +08:00
|
|
|
|
|
2016-11-23 10:59:50 +08:00
|
|
|
|
protected Panel()
|
2016-10-27 18:52:48 +08:00
|
|
|
|
{
|
2016-11-23 04:40:47 +08:00
|
|
|
|
Height = MAX_HEIGHT;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2016-11-23 04:40:47 +08:00
|
|
|
|
|
2017-11-26 03:16:36 +08:00
|
|
|
|
AddInternal(borderContainer = new Container
|
2016-11-23 04:40:47 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-11-23 04:58:46 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 10,
|
2017-01-13 05:38:27 +08:00
|
|
|
|
BorderColour = new Color4(221, 255, 255, 255),
|
2017-11-26 03:16:36 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
nestedContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
hoverLayer = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0,
|
2017-11-27 09:01:44 +08:00
|
|
|
|
Blending = BlendingMode.Additive,
|
2017-11-26 03:16:36 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2016-11-23 04:40:47 +08:00
|
|
|
|
});
|
2017-02-22 20:53:20 +08:00
|
|
|
|
|
|
|
|
|
Alpha = 0;
|
2016-11-23 04:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-26 03:16:36 +08:00
|
|
|
|
private SampleChannel sampleHover;
|
|
|
|
|
|
2017-11-27 16:59:24 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio, OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
sampleHover = audio.Sample.Get($@"SongSelect/song-ping-variation-{RNG.Next(1, 5)}");
|
|
|
|
|
hoverLayer.Colour = colours.Blue.Opacity(0.1f);
|
|
|
|
|
}
|
2017-11-26 03:16:36 +08:00
|
|
|
|
|
2017-11-26 03:16:36 +08:00
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
sampleHover?.Play();
|
2017-11-26 03:16:36 +08:00
|
|
|
|
|
2017-11-27 16:59:24 +08:00
|
|
|
|
hoverLayer.FadeIn(100, Easing.OutQuint);
|
2017-11-26 03:16:36 +08:00
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-26 03:16:36 +08:00
|
|
|
|
protected override void OnHoverLost(InputState state)
|
2017-11-26 03:16:36 +08:00
|
|
|
|
{
|
2017-11-26 03:16:36 +08:00
|
|
|
|
hoverLayer.FadeOut(1000, Easing.OutQuint);
|
|
|
|
|
base.OnHoverLost(state);
|
2017-11-26 03:16:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 04:40:47 +08:00
|
|
|
|
public void SetMultiplicativeAlpha(float alpha)
|
|
|
|
|
{
|
2017-11-26 03:16:36 +08:00
|
|
|
|
borderContainer.Alpha = alpha;
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2017-02-24 18:30:04 +08:00
|
|
|
|
ApplyState();
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
2016-11-05 19:24:15 +08:00
|
|
|
|
|
2017-02-24 18:30:04 +08:00
|
|
|
|
protected virtual void ApplyState(PanelSelectedState last = PanelSelectedState.Hidden)
|
2016-11-21 03:34:16 +08:00
|
|
|
|
{
|
2017-03-17 13:56:12 +08:00
|
|
|
|
if (!IsLoaded) return;
|
|
|
|
|
|
2016-11-21 03:34:16 +08:00
|
|
|
|
switch (state)
|
|
|
|
|
{
|
2017-02-02 16:33:39 +08:00
|
|
|
|
case PanelSelectedState.Hidden:
|
2016-11-21 03:34:16 +08:00
|
|
|
|
case PanelSelectedState.NotSelected:
|
|
|
|
|
Deselected();
|
|
|
|
|
break;
|
|
|
|
|
case PanelSelectedState.Selected:
|
|
|
|
|
Selected();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-02-02 16:33:39 +08:00
|
|
|
|
|
|
|
|
|
if (state == PanelSelectedState.Hidden)
|
2017-07-23 02:50:25 +08:00
|
|
|
|
this.FadeOut(300, Easing.OutQuint);
|
2017-02-02 16:33:39 +08:00
|
|
|
|
else
|
2017-07-15 00:18:12 +08:00
|
|
|
|
this.FadeIn(250);
|
2016-10-27 18:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-05 19:24:15 +08:00
|
|
|
|
private PanelSelectedState state = PanelSelectedState.NotSelected;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
|
|
|
|
|
public PanelSelectedState State
|
|
|
|
|
{
|
|
|
|
|
get { return state; }
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-09-04 08:10:04 +08:00
|
|
|
|
if (state == value)
|
|
|
|
|
return;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
|
2017-02-24 18:30:04 +08:00
|
|
|
|
var last = state;
|
|
|
|
|
state = value;
|
2017-09-04 08:10:04 +08:00
|
|
|
|
|
2017-02-24 18:30:04 +08:00
|
|
|
|
ApplyState(last);
|
2017-09-04 08:10:04 +08:00
|
|
|
|
|
|
|
|
|
StateChanged?.Invoke(State);
|
2016-10-27 18:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Selected()
|
|
|
|
|
{
|
2017-11-26 03:16:36 +08:00
|
|
|
|
borderContainer.BorderThickness = 2.5f;
|
|
|
|
|
borderContainer.EdgeEffect = new EdgeEffectParameters
|
2016-11-02 05:57:11 +08:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
2017-01-13 05:38:27 +08:00
|
|
|
|
Colour = new Color4(130, 204, 255, 150),
|
2016-11-02 05:57:11 +08:00
|
|
|
|
Radius = 20,
|
|
|
|
|
Roundness = 10,
|
|
|
|
|
};
|
2016-10-27 18:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Deselected()
|
|
|
|
|
{
|
2017-11-26 03:16:36 +08:00
|
|
|
|
borderContainer.BorderThickness = 0;
|
|
|
|
|
borderContainer.EdgeEffect = new EdgeEffectParameters
|
2016-11-05 19:00:14 +08:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Offset = new Vector2(1),
|
|
|
|
|
Radius = 10,
|
2017-01-13 05:38:27 +08:00
|
|
|
|
Colour = Color4.Black.Opacity(100),
|
2016-11-05 19:00:14 +08:00
|
|
|
|
};
|
2016-10-27 18:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 05:57:11 +08:00
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
|
|
|
|
State = PanelSelectedState.Selected;
|
|
|
|
|
return true;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 18:54:51 +08:00
|
|
|
|
public enum PanelSelectedState
|
2016-10-27 18:52:48 +08:00
|
|
|
|
{
|
2017-02-02 16:33:39 +08:00
|
|
|
|
Hidden,
|
2016-10-27 18:52:48 +08:00
|
|
|
|
NotSelected,
|
|
|
|
|
Selected
|
|
|
|
|
}
|
|
|
|
|
}
|