1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 06:42:54 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/Panel.cs

126 lines
3.3 KiB
C#
Raw Normal View History

//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
2016-11-05 19:00:14 +08:00
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Graphics;
2016-11-23 10:59:50 +08:00
namespace osu.Game.Beatmaps.Drawables
{
class Panel : Container, IStateful<PanelSelectedState>
{
public const float MAX_HEIGHT = 80;
2016-11-25 17:14:56 +08:00
public override bool RemoveWhenNotAlive => false;
2016-11-26 16:20:34 +08:00
public bool IsOnScreen;
2016-11-25 17:14:56 +08:00
2016-11-26 16:20:34 +08:00
public override bool IsAlive => IsOnScreen && base.IsAlive;
private Container nestedContainer;
2016-11-23 10:59:50 +08:00
protected override Container<Drawable> Content => nestedContainer;
2016-11-23 10:59:50 +08:00
protected Panel()
{
Height = MAX_HEIGHT;
RelativeSizeAxes = Axes.X;
AddInternal(nestedContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = 10,
BorderColour = new Color4(221, 255, 255, 255),
});
}
public void SetMultiplicativeAlpha(float alpha)
{
nestedContainer.Alpha = alpha;
}
protected override void LoadComplete()
{
base.LoadComplete();
applyState();
}
private void applyState()
{
switch (state)
{
case PanelSelectedState.Hidden:
case PanelSelectedState.NotSelected:
Deselected();
break;
case PanelSelectedState.Selected:
Selected();
break;
}
if (state == PanelSelectedState.Hidden)
FadeOut(300, EasingTypes.OutQuint);
else
FadeIn(250);
}
private PanelSelectedState state = PanelSelectedState.NotSelected;
public PanelSelectedState State
{
get { return state; }
set
{
if (state == value) return;
state = value;
applyState();
}
}
protected virtual void Selected()
{
nestedContainer.BorderThickness = 2.5f;
nestedContainer.EdgeEffect = new EdgeEffect
2016-11-02 05:57:11 +08:00
{
Type = EdgeEffectType.Glow,
Colour = new Color4(130, 204, 255, 150),
2016-11-02 05:57:11 +08:00
Radius = 20,
Roundness = 10,
};
}
protected virtual void Deselected()
{
nestedContainer.BorderThickness = 0;
nestedContainer.EdgeEffect = new EdgeEffect
2016-11-05 19:00:14 +08:00
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(1),
Radius = 10,
Colour = Color4.Black.Opacity(100),
2016-11-05 19:00:14 +08:00
};
}
2016-11-02 05:57:11 +08:00
protected override bool OnClick(InputState state)
{
State = PanelSelectedState.Selected;
return true;
}
}
enum PanelSelectedState
{
Hidden,
NotSelected,
Selected
}
}