1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 23:02:59 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/OsuTabDropdown.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

150 lines
4.4 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-02-18 04:56:35 +08:00
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
{
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;
}
2020-02-18 04:56:35 +08:00
private partial class OsuTabDropdownMenu : OsuDropdownMenu
{
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
private partial class DrawableOsuTabDropdownMenuItem : DrawableOsuDropdownMenuItem
{
public DrawableOsuTabDropdownMenuItem(MenuItem item)
: base(item)
{
ForegroundColourHover = Color4.Black;
}
}
}
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
}
}
}