1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 06:02:55 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs

68 lines
2.0 KiB
C#
Raw Normal View History

2021-07-12 14:11:07 +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 System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses;
using osuTK.Graphics;
2021-07-13 15:02:18 +08:00
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
2021-07-12 14:11:07 +08:00
{
/// <summary>
/// A pill that displays the room's current status.
/// </summary>
2021-07-12 14:18:38 +08:00
public class RoomStatusPill : OnlinePlayComposite
2021-07-12 14:11:07 +08:00
{
[Resolved]
private OsuColour colours { get; set; }
private bool firstDisplay = true;
2021-07-12 14:18:38 +08:00
private PillContainer pill;
2021-07-12 14:11:07 +08:00
private SpriteText statusText;
2021-07-12 14:18:38 +08:00
public RoomStatusPill()
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = pill = new PillContainer
{
Child = statusText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 12),
Colour = Color4.Black
}
};
}
2021-07-12 14:11:07 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
EndDate.BindValueChanged(_ => updateDisplay());
Status.BindValueChanged(_ => updateDisplay(), true);
}
private void updateDisplay()
{
RoomStatus status = EndDate.Value < DateTimeOffset.Now ? new RoomStatusEnded() : Status.Value ?? new RoomStatusOpen();
2021-07-12 14:18:38 +08:00
pill.Background.Alpha = 1;
pill.Background.FadeColour(status.GetAppropriateColour(colours), firstDisplay ? 0 : 100);
2021-07-12 14:11:07 +08:00
statusText.Text = status.Message;
firstDisplay = false;
}
}
}