1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 12:32:55 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs

118 lines
3.4 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
2021-07-21 19:15:07 +08:00
using osu.Framework.Extensions;
using osu.Framework.Extensions.LocalisationExtensions;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Localisation;
using osu.Game.Overlays;
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Beatmaps.Drawables
{
public class BeatmapSetOnlineStatusPill : CircularContainer, IHasTooltip
2018-04-13 17:19:50 +08:00
{
private BeatmapOnlineStatus status;
public BeatmapOnlineStatus Status
2018-04-13 17:19:50 +08:00
{
get => status;
2018-04-13 17:19:50 +08:00
set
{
if (status == value)
return;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
status = value;
if (IsLoaded)
updateState();
2018-04-13 17:19:50 +08:00
}
}
public float TextSize
{
get => statusText.Font.Size;
set => statusText.Font = statusText.Font.With(size: value);
}
public MarginPadding TextPadding
{
get => statusText.Padding;
set => statusText.Padding = value;
}
private readonly OsuSpriteText statusText;
private readonly Box background;
[Resolved]
private OsuColour colours { get; set; } = null!;
[Resolved(CanBeNull = true)]
private OverlayColourProvider? colourProvider { get; set; }
2020-02-05 23:31:14 +08:00
public BeatmapSetOnlineStatusPill()
2018-04-13 17:19:50 +08:00
{
Masking = true;
Children = new Drawable[]
{
2020-02-05 23:31:14 +08:00
background = new Box
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
statusText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(weight: FontWeight.Bold)
2018-04-13 17:19:50 +08:00
},
};
Status = BeatmapOnlineStatus.None;
TextPadding = new MarginPadding { Horizontal = 5, Bottom = 1 };
}
protected override void LoadComplete()
{
base.LoadComplete();
updateState();
}
private void updateState()
{
Alpha = Status == BeatmapOnlineStatus.None ? 0 : 1;
statusText.Text = Status.GetLocalisableDescription().ToUpper();
if (colourProvider != null)
statusText.Colour = status == BeatmapOnlineStatus.Graveyard ? colourProvider.Background1 : colourProvider.Background3;
else
statusText.Colour = status == BeatmapOnlineStatus.Graveyard ? colours.GreySeaFoamLight : Color4.Black;
background.Colour = OsuColour.ForBeatmapSetOnlineStatus(Status) ?? colourProvider?.Light1 ?? colours.GreySeaFoamLighter;
2018-04-13 17:19:50 +08:00
}
public LocalisableString TooltipText
{
get
{
switch (Status)
{
case BeatmapOnlineStatus.LocallyModified:
return SongSelectStrings.LocallyModifiedTooltip;
}
return string.Empty;
}
}
2018-04-13 17:19:50 +08:00
}
}