2020-02-18 04:56:35 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2021-10-17 00:33:17 +08:00
|
|
|
|
public class OsuTabDropdown<T> : OsuDropdown<T>, IHasAccentColour
|
2020-02-18 04:56:35 +08:00
|
|
|
|
{
|
2021-10-17 00:33:17 +08:00
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get => accentColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
|
|
|
|
|
2021-10-17 19:31:49 +08:00
|
|
|
|
if (IsLoaded)
|
|
|
|
|
propagateAccentColour();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-17 00:33:17 +08:00
|
|
|
|
|
2020-02-18 04:56:35 +08:00
|
|
|
|
public OsuTabDropdown()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-17 19:31:49 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
propagateAccentColour();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 04:56:35 +08:00
|
|
|
|
protected override DropdownMenu CreateMenu() => new OsuTabDropdownMenu();
|
|
|
|
|
|
|
|
|
|
protected override DropdownHeader CreateHeader() => new OsuTabDropdownHeader
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-20 11:52:38 +08:00
|
|
|
|
private void propagateAccentColour()
|
|
|
|
|
{
|
|
|
|
|
if (Menu is OsuDropdownMenu dropdownMenu)
|
|
|
|
|
{
|
|
|
|
|
dropdownMenu.HoverColour = accentColour;
|
|
|
|
|
dropdownMenu.SelectionColour = accentColour.Opacity(0.5f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Header is OsuTabDropdownHeader tabDropdownHeader)
|
|
|
|
|
tabDropdownHeader.AccentColour = accentColour;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 04:56:35 +08:00
|
|
|
|
private class OsuTabDropdownMenu : OsuDropdownMenu
|
|
|
|
|
{
|
|
|
|
|
public OsuTabDropdownMenu()
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight;
|
|
|
|
|
Origin = Anchor.TopRight;
|
|
|
|
|
|
|
|
|
|
BackgroundColour = Color4.Black.Opacity(0.7f);
|
2021-11-30 12:01:40 +08:00
|
|
|
|
MaxHeight = 200;
|
2020-02-18 04:56:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-17 00:33:17 +08:00
|
|
|
|
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new DrawableOsuTabDropdownMenuItem(item);
|
2020-02-18 04:56:35 +08:00
|
|
|
|
|
|
|
|
|
private class DrawableOsuTabDropdownMenuItem : DrawableOsuDropdownMenuItem
|
|
|
|
|
{
|
|
|
|
|
public DrawableOsuTabDropdownMenuItem(MenuItem item)
|
|
|
|
|
: base(item)
|
|
|
|
|
{
|
|
|
|
|
ForegroundColourHover = Color4.Black;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-17 00:33:17 +08:00
|
|
|
|
protected class OsuTabDropdownHeader : OsuDropdownHeader, IHasAccentColour
|
2020-02-18 04:56:35 +08:00
|
|
|
|
{
|
2021-10-17 00:33:17 +08:00
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
2020-02-18 04:56:35 +08:00
|
|
|
|
{
|
2021-10-17 00:33:17 +08:00
|
|
|
|
get => accentColour;
|
2020-02-18 04:56:35 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2021-10-17 00:33:17 +08:00
|
|
|
|
accentColour = value;
|
|
|
|
|
BackgroundColourHover = value;
|
2021-10-17 19:31:49 +08:00
|
|
|
|
updateColour();
|
2020-02-18 04:56:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OsuTabDropdownHeader()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.None;
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
BackgroundColour = Color4.Black.Opacity(0.5f);
|
|
|
|
|
|
|
|
|
|
Background.Height = 0.5f;
|
|
|
|
|
Background.CornerRadius = 5;
|
|
|
|
|
Background.Masking = true;
|
|
|
|
|
|
|
|
|
|
Foreground.RelativeSizeAxes = Axes.None;
|
|
|
|
|
Foreground.AutoSizeAxes = Axes.X;
|
|
|
|
|
Foreground.RelativeSizeAxes = Axes.Y;
|
|
|
|
|
Foreground.Margin = new MarginPadding(5);
|
|
|
|
|
|
|
|
|
|
Foreground.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.EllipsisH,
|
|
|
|
|
Size = new Vector2(14),
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Padding = new MarginPadding { Left = 5, Right = 5 };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
2021-10-17 19:31:49 +08:00
|
|
|
|
updateColour();
|
2020-02-18 04:56:35 +08:00
|
|
|
|
return base.OnHover(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
2021-10-17 19:31:49 +08:00
|
|
|
|
updateColour();
|
2020-02-18 04:56:35 +08:00
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
}
|
2021-10-17 19:31:49 +08:00
|
|
|
|
|
|
|
|
|
private void updateColour()
|
|
|
|
|
{
|
|
|
|
|
Foreground.Colour = IsHovered ? BackgroundColour : BackgroundColourHover;
|
|
|
|
|
}
|
2020-02-18 04:56:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|