2017-02-07 04:59:30 +00: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-02-03 10:13:10 +00:00
|
|
|
|
2017-03-16 12:17:14 +00:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2017-02-03 10:13:10 +00:00
|
|
|
using OpenTK;
|
2017-02-03 10:23:14 +00:00
|
|
|
using OpenTK.Graphics;
|
2017-03-04 18:42:37 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-03-16 12:17:14 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-03-15 02:46:13 +00:00
|
|
|
using osu.Framework.Graphics.Transforms;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2017-02-03 10:13:10 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
{
|
2017-03-16 12:17:14 +00:00
|
|
|
public class OsuDropDownMenu<T> : DropDownMenu<T>
|
2017-02-03 10:13:10 +00:00
|
|
|
{
|
2017-03-16 12:17:14 +00:00
|
|
|
protected override DropDownHeader CreateHeader() => new OsuDropDownHeader { AccentColour = AccentColour };
|
2017-02-03 10:13:10 +00:00
|
|
|
|
2017-03-16 12:17:14 +00:00
|
|
|
private Color4? accentColour;
|
|
|
|
public virtual Color4 AccentColour
|
2017-02-03 10:13:10 +00:00
|
|
|
{
|
2017-03-16 12:17:14 +00:00
|
|
|
get { return accentColour.GetValueOrDefault(); }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
accentColour = value;
|
|
|
|
if (Header != null)
|
|
|
|
((OsuDropDownHeader)Header).AccentColour = value;
|
|
|
|
foreach (var item in ItemList.OfType<OsuDropDownMenuItem<T>>())
|
|
|
|
item.AccentColour = value;
|
|
|
|
}
|
2017-02-03 10:13:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 12:17:14 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
2017-02-03 10:13:10 +00:00
|
|
|
{
|
2017-03-16 12:17:14 +00:00
|
|
|
if (accentColour == null)
|
|
|
|
AccentColour = colours.PinkDarker;
|
2017-02-03 10:13:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 12:17:14 +00:00
|
|
|
public OsuDropDownMenu()
|
2017-02-03 10:13:10 +00:00
|
|
|
{
|
2017-03-16 12:17:14 +00:00
|
|
|
ContentContainer.CornerRadius = 4;
|
|
|
|
ContentBackground.Colour = Color4.Black.Opacity(0.5f);
|
|
|
|
|
|
|
|
DropDownItemsContainer.Padding = new MarginPadding(5);
|
2017-02-03 10:13:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 12:17:14 +00:00
|
|
|
protected override void AnimateOpen() => ContentContainer.FadeIn(300, EasingTypes.OutQuint);
|
|
|
|
|
|
|
|
protected override void AnimateClose() => ContentContainer.FadeOut(300, EasingTypes.OutQuint);
|
|
|
|
|
2017-02-03 10:13:10 +00:00
|
|
|
protected override void UpdateContentHeight()
|
|
|
|
{
|
2017-03-16 12:17:14 +00:00
|
|
|
var actualHeight = (RelativeSizeAxes & Axes.Y) > 0 ? 1 : ContentHeight;
|
|
|
|
ContentContainer.ResizeTo(new Vector2(1, State == DropDownMenuState.Opened ? actualHeight : 0), 300, EasingTypes.OutQuint);
|
2017-02-03 10:13:10 +00:00
|
|
|
}
|
2017-03-14 13:39:57 +00:00
|
|
|
|
2017-03-16 12:17:14 +00:00
|
|
|
protected override DropDownMenuItem<T> CreateDropDownItem(string key, T value) => new OsuDropDownMenuItem<T>(key, value) { AccentColour = AccentColour };
|
2017-02-03 10:13:10 +00:00
|
|
|
}
|
|
|
|
}
|