1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 18:37:51 +08:00
osu-lazer/osu.Game/Overlays/Login/UserDropdown.cs

123 lines
3.9 KiB
C#
Raw Normal View History

2021-09-20 03:09:03 +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
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
2023-01-14 07:31:27 +08:00
using osu.Game.Users.Drawables;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.Login
{
2022-11-24 13:32:20 +08:00
public partial class UserDropdown : OsuEnumDropdown<UserAction>
{
protected override DropdownHeader CreateHeader() => new UserDropdownHeader();
protected override DropdownMenu CreateMenu() => new UserDropdownMenu();
public Color4 StatusColour
{
set
{
if (Header is UserDropdownHeader h)
h.StatusColour = value;
}
}
2022-11-24 13:32:20 +08:00
protected partial class UserDropdownMenu : OsuDropdownMenu
{
public UserDropdownMenu()
{
Masking = true;
CornerRadius = 5;
Margin = new MarginPadding { Bottom = 5 };
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.25f),
Radius = 4,
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = colours.Gray3;
SelectionColour = colours.Gray4;
HoverColour = colours.Gray5;
}
protected override DrawableDropdownMenuItem CreateDrawableDropdownMenuItem(MenuItem item) => new DrawableUserDropdownMenuItem(item);
2022-11-24 13:32:20 +08:00
private partial class DrawableUserDropdownMenuItem : DrawableOsuDropdownMenuItem
{
public DrawableUserDropdownMenuItem(MenuItem item)
: base(item)
{
Foreground.Padding = new MarginPadding { Top = 5, Bottom = 5, Left = 10, Right = 5 };
CornerRadius = 5;
}
protected override Drawable CreateContent() => new Content
{
Label = { Margin = new MarginPadding { Left = UserDropdownHeader.LABEL_LEFT_MARGIN - 11 } }
};
}
}
2022-11-24 13:32:20 +08:00
private partial class UserDropdownHeader : OsuDropdownHeader
{
public const float LABEL_LEFT_MARGIN = 20;
2023-01-14 07:31:27 +08:00
private readonly StatusIcon statusIcon;
public Color4 StatusColour
{
set => statusIcon.FadeColour(value, 500, Easing.OutQuint);
}
public UserDropdownHeader()
{
Foreground.Padding = new MarginPadding { Left = 10, Right = 10 };
Margin = new MarginPadding { Bottom = 5 };
Masking = true;
CornerRadius = 5;
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.25f),
Radius = 4,
};
Icon.Size = new Vector2(14);
Icon.Margin = new MarginPadding(0);
2023-01-14 07:31:27 +08:00
Foreground.Add(statusIcon = new StatusIcon
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(14),
});
Text.Margin = new MarginPadding { Left = LABEL_LEFT_MARGIN };
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = colours.Gray3;
BackgroundColourHover = colours.Gray5;
}
}
}
}