2017-03-22 06:51:26 +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-08-29 17:17:01 +08:00
|
|
|
using System.Linq;
|
2017-03-22 06:51:26 +08:00
|
|
|
using OpenTK.Graphics;
|
|
|
|
using osu.Framework.Allocation;
|
2017-03-23 07:44:52 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-03-22 06:51:26 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2017-03-23 07:44:52 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-08-03 13:36:21 +08:00
|
|
|
using OpenTK;
|
2017-03-22 06:51:26 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
{
|
2017-08-29 17:17:01 +08:00
|
|
|
public class OsuDropdown<T> : Dropdown<T>, IHasAccentColour
|
2017-03-22 06:51:26 +08:00
|
|
|
{
|
2017-08-29 17:17:01 +08:00
|
|
|
private Color4 accentColour;
|
|
|
|
public Color4 AccentColour
|
|
|
|
{
|
|
|
|
get { return accentColour; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
accentColour = value;
|
|
|
|
updateAccentColour();
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 06:51:26 +08:00
|
|
|
|
2017-08-25 14:58:21 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
2017-03-22 06:51:26 +08:00
|
|
|
{
|
2017-08-29 17:17:01 +08:00
|
|
|
if (accentColour == default(Color4))
|
|
|
|
accentColour = colours.PinkDarker;
|
|
|
|
updateAccentColour();
|
2017-03-22 06:51:26 +08:00
|
|
|
}
|
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
private void updateAccentColour()
|
2017-03-22 06:51:26 +08:00
|
|
|
{
|
2017-08-29 17:17:01 +08:00
|
|
|
var header = Header as IHasAccentColour;
|
|
|
|
if (header != null) header.AccentColour = accentColour;
|
2017-08-25 14:58:21 +08:00
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
var menu = Menu as IHasAccentColour;
|
|
|
|
if (menu != null) menu.AccentColour = accentColour;
|
2017-03-22 06:51:26 +08:00
|
|
|
}
|
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
protected override DropdownHeader CreateHeader() => new OsuDropdownHeader();
|
2017-08-25 14:58:21 +08:00
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
protected override DropdownMenu CreateMenu() => new OsuDropdownMenu();
|
2017-03-23 07:44:52 +08:00
|
|
|
|
2017-08-25 14:58:21 +08:00
|
|
|
#region OsuDropdownMenu
|
2017-08-29 17:17:01 +08:00
|
|
|
protected class OsuDropdownMenu : DropdownMenu, IHasAccentColour
|
2017-03-23 07:44:52 +08:00
|
|
|
{
|
2017-08-25 17:41:12 +08:00
|
|
|
// todo: this uses the same styling as OsuMenu. hopefully we can just use OsuMenu in the future with some refactoring
|
|
|
|
public OsuDropdownMenu()
|
|
|
|
{
|
|
|
|
CornerRadius = 4;
|
|
|
|
BackgroundColour = Color4.Black.Opacity(0.5f);
|
2017-09-04 08:10:04 +08:00
|
|
|
|
|
|
|
// todo: this uses the same styling as OsuMenu. hopefully we can just use OsuMenu in the future with some refactoring
|
|
|
|
ItemsContainer.Padding = new MarginPadding(5);
|
2017-08-25 17:41:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// todo: this uses the same styling as OsuMenu. hopefully we can just use OsuMenu in the future with some refactoring
|
|
|
|
protected override void AnimateOpen() => this.FadeIn(300, Easing.OutQuint);
|
|
|
|
protected override void AnimateClose() => this.FadeOut(300, Easing.OutQuint);
|
|
|
|
|
|
|
|
// todo: this uses the same styling as OsuMenu. hopefully we can just use OsuMenu in the future with some refactoring
|
2017-09-04 08:32:44 +08:00
|
|
|
protected override void UpdateSize(Vector2 newSize)
|
|
|
|
{
|
|
|
|
if (Direction == Direction.Vertical)
|
|
|
|
{
|
|
|
|
Width = newSize.X;
|
|
|
|
this.ResizeHeightTo(newSize.Y, 300, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Height = newSize.Y;
|
|
|
|
this.ResizeWidthTo(newSize.X, 300, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
2017-08-25 17:41:12 +08:00
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
private Color4 accentColour;
|
|
|
|
public Color4 AccentColour
|
2017-08-25 14:58:21 +08:00
|
|
|
{
|
2017-08-29 17:17:01 +08:00
|
|
|
get { return accentColour; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
accentColour = value;
|
|
|
|
foreach (var c in Children.OfType<IHasAccentColour>())
|
|
|
|
c.AccentColour = value;
|
|
|
|
}
|
2017-08-25 14:58:21 +08:00
|
|
|
}
|
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableOsuDropdownMenuItem(item) { AccentColour = accentColour };
|
|
|
|
|
2017-08-25 17:41:12 +08:00
|
|
|
#region DrawableOsuDropdownMenuItem
|
2017-09-06 22:34:21 +08:00
|
|
|
public class DrawableOsuDropdownMenuItem : DrawableDropdownMenuItem, IHasAccentColour
|
2017-03-23 07:44:52 +08:00
|
|
|
{
|
2017-08-29 17:17:01 +08:00
|
|
|
private Color4? accentColour;
|
|
|
|
public Color4 AccentColour
|
|
|
|
{
|
|
|
|
get { return accentColour ?? nonAccentSelectedColour; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
accentColour = value;
|
|
|
|
updateColours();
|
|
|
|
}
|
|
|
|
}
|
2017-08-25 14:58:21 +08:00
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
private void updateColours()
|
|
|
|
{
|
|
|
|
BackgroundColourHover = accentColour ?? nonAccentHoverColour;
|
|
|
|
BackgroundColourSelected = accentColour ?? nonAccentSelectedColour;
|
|
|
|
UpdateBackgroundColour();
|
|
|
|
UpdateForegroundColour();
|
|
|
|
}
|
2017-08-25 14:58:21 +08:00
|
|
|
|
|
|
|
private Color4 nonAccentHoverColour;
|
|
|
|
private Color4 nonAccentSelectedColour;
|
|
|
|
|
2017-08-28 13:42:52 +08:00
|
|
|
public DrawableOsuDropdownMenuItem(MenuItem item)
|
2017-08-25 17:41:12 +08:00
|
|
|
: base(item)
|
2017-08-25 14:58:21 +08:00
|
|
|
{
|
|
|
|
Foreground.Padding = new MarginPadding(2);
|
|
|
|
|
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
BackgroundColour = Color4.Transparent;
|
2017-08-29 17:17:01 +08:00
|
|
|
|
2017-08-25 14:58:21 +08:00
|
|
|
nonAccentHoverColour = colours.PinkDarker;
|
|
|
|
nonAccentSelectedColour = Color4.Black.Opacity(0.5f);
|
2017-08-29 17:17:01 +08:00
|
|
|
updateColours();
|
2017-11-26 01:41:18 +08:00
|
|
|
|
|
|
|
AddInternal(new HoverClickSounds(HoverSampleSet.Soft));
|
2017-08-25 14:58:21 +08:00
|
|
|
}
|
2017-03-23 07:44:52 +08:00
|
|
|
|
2017-08-25 17:41:12 +08:00
|
|
|
protected override void UpdateForegroundColour()
|
2017-03-23 07:44:52 +08:00
|
|
|
{
|
2017-08-25 17:41:12 +08:00
|
|
|
base.UpdateForegroundColour();
|
2017-08-28 11:33:31 +08:00
|
|
|
|
2017-08-29 17:31:51 +08:00
|
|
|
var content = Foreground.Children.FirstOrDefault() as Content;
|
2017-08-29 17:17:01 +08:00
|
|
|
if (content != null) content.Chevron.Alpha = IsHovered ? 1 : 0;
|
2017-08-25 14:58:21 +08:00
|
|
|
}
|
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
protected override Drawable CreateContent() => new Content();
|
2017-08-28 11:33:31 +08:00
|
|
|
|
2017-09-04 08:10:04 +08:00
|
|
|
protected new class Content : FillFlowContainer, IHasText
|
2017-03-23 07:44:52 +08:00
|
|
|
{
|
2017-08-28 11:33:31 +08:00
|
|
|
public string Text
|
2017-03-23 07:44:52 +08:00
|
|
|
{
|
2017-08-28 11:33:31 +08:00
|
|
|
get { return Label.Text; }
|
|
|
|
set { Label.Text = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public readonly OsuSpriteText Label;
|
|
|
|
public readonly SpriteIcon Chevron;
|
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
public Content()
|
2017-08-28 11:33:31 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
Direction = FillDirection.Horizontal;
|
|
|
|
|
2017-08-28 10:01:53 +08:00
|
|
|
Children = new Drawable[]
|
2017-03-23 07:44:52 +08:00
|
|
|
{
|
2017-08-28 11:33:31 +08:00
|
|
|
Chevron = new SpriteIcon
|
2017-08-28 10:01:53 +08:00
|
|
|
{
|
|
|
|
AlwaysPresent = true,
|
|
|
|
Icon = FontAwesome.fa_chevron_right,
|
|
|
|
Colour = Color4.Black,
|
|
|
|
Alpha = 0.5f,
|
|
|
|
Size = new Vector2(8),
|
|
|
|
Margin = new MarginPadding { Left = 3, Right = 3 },
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
},
|
|
|
|
Label = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
2017-11-26 01:41:18 +08:00
|
|
|
},
|
2017-08-28 11:33:31 +08:00
|
|
|
};
|
|
|
|
}
|
2017-08-28 10:01:53 +08:00
|
|
|
}
|
2017-03-23 07:44:52 +08:00
|
|
|
}
|
2017-08-25 14:58:21 +08:00
|
|
|
#endregion
|
2017-03-23 07:44:52 +08:00
|
|
|
}
|
2017-08-25 14:58:21 +08:00
|
|
|
#endregion
|
2017-03-23 07:44:52 +08:00
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
public class OsuDropdownHeader : DropdownHeader, IHasAccentColour
|
2017-03-23 07:44:52 +08:00
|
|
|
{
|
2017-05-25 06:44:48 +08:00
|
|
|
protected readonly SpriteText Text;
|
2017-03-23 07:44:52 +08:00
|
|
|
protected override string Label
|
|
|
|
{
|
2017-05-25 06:44:48 +08:00
|
|
|
get { return Text.Text; }
|
|
|
|
set { Text.Text = value; }
|
2017-03-23 07:44:52 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 13:36:21 +08:00
|
|
|
protected readonly SpriteIcon Icon;
|
2017-03-24 16:59:26 +08:00
|
|
|
|
2017-08-29 17:17:01 +08:00
|
|
|
private Color4 accentColour;
|
|
|
|
public virtual Color4 AccentColour
|
|
|
|
{
|
|
|
|
get { return accentColour; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
accentColour = value;
|
|
|
|
BackgroundColourHover = accentColour;
|
|
|
|
}
|
|
|
|
}
|
2017-03-23 07:44:52 +08:00
|
|
|
|
|
|
|
public OsuDropdownHeader()
|
2017-05-19 04:43:39 +08:00
|
|
|
{
|
2017-03-23 07:44:52 +08:00
|
|
|
Foreground.Padding = new MarginPadding(4);
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.None;
|
|
|
|
Margin = new MarginPadding { Bottom = 4 };
|
|
|
|
CornerRadius = 4;
|
|
|
|
Height = 40;
|
|
|
|
|
|
|
|
Foreground.Children = new Drawable[]
|
|
|
|
{
|
2017-05-25 06:44:48 +08:00
|
|
|
Text = new OsuSpriteText
|
2017-03-24 16:59:26 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
},
|
2017-08-03 13:36:21 +08:00
|
|
|
Icon = new SpriteIcon
|
2017-03-24 16:59:26 +08:00
|
|
|
{
|
|
|
|
Icon = FontAwesome.fa_chevron_down,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Margin = new MarginPadding { Right = 4 },
|
2017-08-03 13:36:21 +08:00
|
|
|
Size = new Vector2(20),
|
2017-11-26 01:41:18 +08:00
|
|
|
},
|
2017-03-23 07:44:52 +08:00
|
|
|
};
|
2017-11-26 01:41:18 +08:00
|
|
|
|
|
|
|
AddInternal(new HoverClickSounds());
|
2017-03-23 07:44:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
BackgroundColour = Color4.Black.Opacity(0.5f);
|
2017-08-29 17:17:01 +08:00
|
|
|
BackgroundColourHover = colours.PinkDarker;
|
2017-03-23 07:44:52 +08:00
|
|
|
}
|
|
|
|
}
|
2017-03-22 06:51:26 +08:00
|
|
|
}
|
2017-05-31 12:57:32 +08:00
|
|
|
}
|