1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 07:52:56 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/OsuTabDropdown.cs

148 lines
4.3 KiB
C#
Raw Normal View History

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
{
2022-11-24 13:32:20 +08:00
public partial class OsuTabDropdown<T> : OsuDropdown<T>, IHasAccentColour
2020-02-18 04:56:35 +08:00
{
private Color4 accentColour;
public Color4 AccentColour
{
get => accentColour;
set
{
accentColour = value;
if (IsLoaded)
propagateAccentColour();
}
}
2020-02-18 04:56:35 +08:00
public OsuTabDropdown()
{
RelativeSizeAxes = Axes.X;
}
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;
}
2022-11-24 13:32:20 +08:00
private partial class OsuTabDropdownMenu : OsuDropdownMenu
2020-02-18 04:56:35 +08:00
{
public OsuTabDropdownMenu()
{
Anchor = Anchor.TopRight;
Origin = Anchor.TopRight;
BackgroundColour = Color4.Black.Opacity(0.7f);
MaxHeight = 200;
2020-02-18 04:56:35 +08:00
}
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new DrawableOsuTabDropdownMenuItem(item);
2020-02-18 04:56:35 +08:00
2022-11-24 13:32:20 +08:00
private partial class DrawableOsuTabDropdownMenuItem : DrawableOsuDropdownMenuItem
2020-02-18 04:56:35 +08:00
{
public DrawableOsuTabDropdownMenuItem(MenuItem item)
: base(item)
{
ForegroundColourHover = Color4.Black;
}
}
}
2022-11-24 13:32:20 +08:00
protected partial class OsuTabDropdownHeader : OsuDropdownHeader, IHasAccentColour
2020-02-18 04:56:35 +08:00
{
private Color4 accentColour;
public Color4 AccentColour
2020-02-18 04:56:35 +08:00
{
get => accentColour;
2020-02-18 04:56:35 +08:00
set
{
accentColour = value;
BackgroundColourHover = value;
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)
{
updateColour();
2020-02-18 04:56:35 +08:00
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateColour();
2020-02-18 04:56:35 +08:00
base.OnHoverLost(e);
}
private void updateColour()
{
Foreground.Colour = IsHovered ? BackgroundColour : BackgroundColourHover;
}
2020-02-18 04:56:35 +08:00
}
}
}